package com.ruoyi.web.controller.system.check;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TdCheck;
import com.ruoyi.system.service.ITdCheckService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 检查报告管理Controller
 * 
 * @author ruoyi
 * @date 2024-05-06
 */
@Controller
@RequestMapping("/system/check")
public class TdCheckController extends BaseController
{
    private String prefix = "system/check";

    @Autowired
    private ITdCheckService tdCheckService;

    @RequiresPermissions("system:check:view")
    @GetMapping()
    public String check()
    {
        return prefix + "/check";
    }

    /**
     * 查询检查报告管理列表
     */
    @RequiresPermissions("system:check:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TdCheck tdCheck)
    {
        startPage();
        List<TdCheck> list = tdCheckService.selectTdCheckList(tdCheck);
        return getDataTable(list);
    }

    /**
     * 导出检查报告管理列表
     */
    @RequiresPermissions("system:check:export")
    @Log(title = "检查报告管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TdCheck tdCheck)
    {
        List<TdCheck> list = tdCheckService.selectTdCheckList(tdCheck);
        ExcelUtil<TdCheck> util = new ExcelUtil<TdCheck>(TdCheck.class);
        return util.exportExcel(list, "检查报告管理数据");
    }

    /**
     * 新增检查报告管理
     */
    @GetMapping("/add")
    public String add(ModelMap mmap)
    {
        mmap.put("user", getSysUser());
        return prefix + "/add";
    }

    /**
     * 新增保存检查报告管理
     */
    @RequiresPermissions("system:check:add")
    @Log(title = "检查报告管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TdCheck tdCheck)
    {
        return toAjax(tdCheckService.insertTdCheck(tdCheck));
    }

    /**
     * 修改检查报告管理
     */
    @RequiresPermissions("system:check:edit")
    @GetMapping("/edit/{checkId}")
    public String edit(@PathVariable("checkId") Long checkId, ModelMap mmap)
    {
        TdCheck tdCheck = tdCheckService.selectTdCheckByCheckId(checkId);
        mmap.put("tdCheck", tdCheck);
        return prefix + "/edit";
    }

    /**
     * 修改保存检查报告管理
     */
    @RequiresPermissions("system:check:edit")
    @Log(title = "检查报告管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TdCheck tdCheck)
    {
        return toAjax(tdCheckService.updateTdCheck(tdCheck));
    }

    /**
     * 删除检查报告管理
     */
    @RequiresPermissions("system:check:remove")
    @Log(title = "检查报告管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tdCheckService.deleteTdCheckByCheckIds(ids));
    }

    /**
     * 自行检查 报告管理
     */
    @RequiresPermissions("system:check:selfcheck")
    @GetMapping("/selfcheck/{checkId}")
    public String selfcheck(@PathVariable("checkId") Long checkId, ModelMap mmap)
    {
        TdCheck tdCheck = tdCheckService.selectTdCheckByCheckId(checkId);
        mmap.put("tdCheck", tdCheck);
        return prefix + "/selfcheck";
    }

    /**
     * 保存自行检查报告结果
     */
    @RequiresPermissions("system:check:selfcheck")
    @Log(title = "检查报告管理", businessType = BusinessType.CHECK)
    @PostMapping("/selfcheck")
    @ResponseBody
    public AjaxResult selfcheckSave(TdCheck tdCheck)
    {
        return toAjax(tdCheckService.updateTdCheck(tdCheck));
    }

    /**
     * 详情操作 报告管理
     */
    @RequiresPermissions("system:check:detail")
    @GetMapping("/detail/{checkId}")
    public String detail(@PathVariable("checkId") Long checkId, ModelMap mmap)
    {
        TdCheck tdCheck = tdCheckService.selectTdCheckByCheckId(checkId);
        mmap.put("tdCheck", tdCheck);
        return prefix + "/detail";
    }

    /**
     * 打印操作
     */
    @RequiresPermissions("system:check:print")
    @GetMapping("/checkprint/{checkId}")
    public String checkPrint(@PathVariable("checkId") Long checkId, ModelMap mmap)
    {
        TdCheck tdCheck = tdCheckService.selectTdCheckByCheckId(checkId);
        mmap.put("tdCheck", tdCheck);
        return prefix + "/checkprint";
    }

}
