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 com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import cn.iocoder.yudao.module.core.controller.BaseController;
import cn.iocoder.yudao.module.inspection.entity.InspectionCategoryTemplate;
import cn.iocoder.yudao.module.inspection.service.IInspectionCategoryTemplateService;

/**
 * 分类模版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 CommonResult list(InspectionCategoryTemplate inspectionCategoryTemplate,
                             @RequestParam(value = "pageNum" ,required = false ,defaultValue = "1") Integer pageNum,
                             @RequestParam(value ="pageSize" ,required = false ,defaultValue = "10") Integer pageSize)
    {
        Page<InspectionCategoryTemplate> page = new Page<>(pageNum, pageSize);
        IPage<InspectionCategoryTemplate> list = inspectionCategoryTemplateService.selectInspectionCategoryTemplateList(page,inspectionCategoryTemplate);
        return success(list);
    }

    /**
     * 导出分类模版列表
     */
    @PreAuthorize("@ss.hasPermi('inspection:template:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, InspectionCategoryTemplate inspectionCategoryTemplate,
                       @RequestParam(value = "pageNum" ,required = false ,defaultValue = "1") Integer pageNum,
                       @RequestParam(value ="pageSize" ,required = false ,defaultValue = "10") Integer pageSize)
    {
        Page<InspectionCategoryTemplate> page = new Page<>(pageNum, pageSize);
        IPage<InspectionCategoryTemplate> list = inspectionCategoryTemplateService.selectInspectionCategoryTemplateList(page,inspectionCategoryTemplate);
        ExcelUtil<InspectionCategoryTemplate> util = new ExcelUtil<InspectionCategoryTemplate>(InspectionCategoryTemplate.class);
        util.exportExcel(response, list.getRecords(), "分类模版数据");
    }

    /**
     * 获取分类模版详细信息
     */
    @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));
    }
}
