package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TemplateTable;
import com.ruoyi.system.service.ITemplateTableService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 证书模板Controller
 * 
 * @author ruoyi
 * @date 2022-12-07
 */
@RestController
@RequestMapping("/system/temp")
public class TemplateTableController extends BaseController
{
    @Autowired
    private ITemplateTableService templateTableService;

    /**
     * 查询证书模板列表
     */
    @PreAuthorize("@ss.hasPermi('system:temp:list')")
    @GetMapping("/list")
    public TableDataInfo list(TemplateTable templateTable)
    {
        startPage();
        List<TemplateTable> list = templateTableService.selectTemplateTableList(templateTable);
        return getDataTable(list);
    }

    /**
     * 导出证书模板列表
     */
    @PreAuthorize("@ss.hasPermi('system:temp:export')")
    @Log(title = "证书模板", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TemplateTable templateTable)
    {
        List<TemplateTable> list = templateTableService.selectTemplateTableList(templateTable);
        ExcelUtil<TemplateTable> util = new ExcelUtil<TemplateTable>(TemplateTable.class);
        util.exportExcel(response, list, "证书模板数据");
    }

    /**
     * 获取证书模板详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:temp:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(templateTableService.selectTemplateTableById(id));
    }

    /**
     * 新增证书模板
     */
    @PreAuthorize("@ss.hasPermi('system:temp:add')")
    @Log(title = "证书模板", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TemplateTable templateTable)
    {
        return toAjax(templateTableService.insertTemplateTable(templateTable));
    }

    /**
     * 修改证书模板
     */
    @PreAuthorize("@ss.hasPermi('system:temp:edit')")
    @Log(title = "证书模板", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TemplateTable templateTable)
    {
        return toAjax(templateTableService.updateTemplateTable(templateTable));
    }

    /**
     * 删除证书模板
     */
    @PreAuthorize("@ss.hasPermi('system:temp:remove')")
    @Log(title = "证书模板", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(templateTableService.deleteTemplateTableByIds(ids));
    }
}
