package cn.iocoder.yudao.module.inspection.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.util.ExcelUtil;
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 cn.iocoder.yudao.module.core.controller.BaseController;
import cn.iocoder.yudao.module.inspection.entity.InspectionCategoryTemplate;
import cn.iocoder.yudao.module.inspection.service.IInspectionCategoryTemplateService;

import cn.iocoder.yudao.module.core.page.TableDataInfo;

/**
 * 分类模版Controller
 *
 * @author ruoyi
 * @date 2023-09-07
 */
@RestController
@RequestMapping("/admin-api/inspection/template")
public class InspectionCategoryTemplateController extends BaseController
{
    @Autowired
    private IInspectionCategoryTemplateService inspectionCategoryTemplateService;

    /**
     * 查询分类模版列表
     */
    @PreAuthorize("@ss.hasPermi('inspection:template:list')")
    @GetMapping("/list")
    public TableDataInfo list(InspectionCategoryTemplate inspectionCategoryTemplate)
    {
        startPage();
        List<InspectionCategoryTemplate> list = inspectionCategoryTemplateService.selectInspectionCategoryTemplateList(inspectionCategoryTemplate);
        return getDataTable(list);
    }

    /**
     * 导出分类模版列表
     */
    @PreAuthorize("@ss.hasPermi('inspection:template:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, InspectionCategoryTemplate inspectionCategoryTemplate)
    {
        List<InspectionCategoryTemplate> list = inspectionCategoryTemplateService.selectInspectionCategoryTemplateList(inspectionCategoryTemplate);
        ExcelUtil<InspectionCategoryTemplate> util = new ExcelUtil<InspectionCategoryTemplate>(InspectionCategoryTemplate.class);
        util.exportExcel(response, list, "分类模版数据");
    }

    /**
     * 获取分类模版详细信息
     */
    @PreAuthorize("@ss.hasPermi('inspection:template:query')")
    @GetMapping(value = "/{id}")
    public CommonResult getInfo(@PathVariable("id") Long id)
    {
        return success(inspectionCategoryTemplateService.selectInspectionCategoryTemplateById(id));
    }

    /**
     * 新增分类模版
     */
    @PreAuthorize("@ss.hasPermi('inspection:template:add')")
    @PostMapping
    public CommonResult add(@RequestBody InspectionCategoryTemplate inspectionCategoryTemplate)
    {
        return toAjax(inspectionCategoryTemplateService.insertInspectionCategoryTemplate(inspectionCategoryTemplate));
    }

    /**
     * 修改分类模版
     */
    @PreAuthorize("@ss.hasPermi('inspection:template:edit')")
    @PutMapping
    public CommonResult edit(@RequestBody InspectionCategoryTemplate inspectionCategoryTemplate)
    {
        return toAjax(inspectionCategoryTemplateService.updateInspectionCategoryTemplate(inspectionCategoryTemplate));
    }

    /**
     * 删除分类模版
     */
    @PreAuthorize("@ss.hasPermi('inspection:template:remove')")
	@DeleteMapping("/{ids}")
    public CommonResult remove(@PathVariable Long[] ids)
    {
        return toAjax(inspectionCategoryTemplateService.deleteInspectionCategoryTemplateByIds(ids));
    }
}
