package com.ruoyi.web.controller.doubleDefense;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.doubledefense.dto.CheckTaskDTO;
import com.ruoyi.doubledefense.dto.res.CheckTaskResultDTO;
import com.ruoyi.doubledefense.service.ICheckTaskService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

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

/**
 * 隐患排查任务Controller
 *
 * @author ruoyi
 * @date 2023-08-03
 */
@Api(tags = "排查任务要求")
@RestController
@RequestMapping("/doubledefense/task")
public class CheckTaskController extends BaseController {
    @Autowired
    private ICheckTaskService checkTaskService;

    /**
     * 查询隐患排查任务列表
     */
    @ApiOperation("查询隐患排查任务列表")
    //TODO 20230920PreAuthorize("@ss.hasPermi('doubledefense:task:list')")
    @GetMapping("/list")
    public TableDataInfo list(CheckTaskDTO checkTask) {
        startPage();
        List<CheckTaskResultDTO> list = checkTaskService.selectCheckTaskList(checkTask);
        return getDataTable(list);
    }

    /**
     * 导出隐患排查任务列表
     */
    @ApiOperation("导出隐患排查任务列表")
    //TODO 20230920PreAuthorize("@ss.hasPermi('doubledefense:task:export')")
    @Log(title = "隐患排查任务", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CheckTaskDTO checkTask) {
        List<CheckTaskResultDTO> list = checkTaskService.selectCheckTaskList(checkTask);
        ExcelUtil<CheckTaskResultDTO> util = new ExcelUtil<CheckTaskResultDTO>(CheckTaskResultDTO.class);
        util.exportExcel(response, list, "隐患排查任务数据");
    }

    /**
     * 获取隐患排查任务详细信息
     */
    @ApiOperation("获取隐患排查任务详细信息")
    //TODO 20230920PreAuthorize("@ss.hasPermi('doubledefense:task:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(checkTaskService.selectCheckTaskById(id));
    }

    /**
     * 新增隐患排查任务
     */
    @ApiOperation("新增隐患排查任务")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "riskMeasureId", value = "所属管控措施UUID", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "troubleshootContent", value = "隐患排查内容", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "checkType", value = "巡查类型：1日常排查，2综合排查，3专业性排查，4季节性排查，5重点时段及节假日前排查，6事故类比排查，7复产复工前排查，8外聘专家诊断式排查，9管控措施失效，10其它", dataType = "Long", dataTypeClass = Long.class),
            @ApiImplicitParam(name = "checkCycle", value = "巡查周期", dataType = "Long", dataTypeClass = Long.class),
            @ApiImplicitParam(name = "checkCycleUnit", value = "巡查周期单位：小时，天，月，年", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "startDate", value = "任务开始时间", dataType = "Date", dataTypeClass = Date.class),
            @ApiImplicitParam(name = "endDate", value = "任务结束时间", dataType = "Date", dataTypeClass = Date.class),
            @ApiImplicitParam(name = "troubleshootLevel", value = "隐患级别：0一般隐患，1重大隐患", dataType = "Long", dataTypeClass = Long.class),
//            @ApiImplicitParam(name = "postIdList", value = "岗位Id列表", dataType = "List", dataTypeClass = List.class)
            @ApiImplicitParam(name = "postId", value = "岗位Id（修改为单选了）", dataType = "List", dataTypeClass = List.class)
    })
    //TODO 20230920PreAuthorize("@ss.hasPermi('doubledefense:task:add')")
    @Log(title = "新增隐患排查任务", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CheckTaskDTO checkTask) {
        return toAjax(checkTaskService.insertCheckTask(checkTask));
    }

    /**
     * 修改隐患排查任务
     */
    @ApiOperation("修改隐患排查任务")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "排查任务ID", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "riskMeasureId", value = "所属管控措施UUID", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "troubleshootContent", value = "隐患排查内容", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "checkType", value = "巡查类型：1日常排查，2综合排查，3专业性排查，4季节性排查，5重点时段及节假日前排查，6事故类比排查，7复产复工前排查，8外聘专家诊断式排查，9管控措施失效，10其它", dataType = "Long", dataTypeClass = Long.class),
            @ApiImplicitParam(name = "checkCycle", value = "巡查周期", dataType = "Long", dataTypeClass = Long.class),
            @ApiImplicitParam(name = "checkCycleUnit", value = "巡查周期单位：小时，天，月，年", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "startDate", value = "任务开始时间", dataType = "Date", dataTypeClass = Date.class),
            @ApiImplicitParam(name = "endDate", value = "任务结束时间", dataType = "Date", dataTypeClass = Date.class),
            @ApiImplicitParam(name = "troubleshootLevel", value = "隐患级别：0一般隐患，1重大隐患", dataType = "Long", dataTypeClass = Long.class),
            @ApiImplicitParam(name = "postIdList", value = "岗位Id列表", dataType = "List", dataTypeClass = List.class)
    })
    //TODO 20230920PreAuthorize("@ss.hasPermi('doubledefense:task:edit')")
    @Log(title = "修改隐患排查任务", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CheckTaskDTO checkTask) {
        return toAjax(checkTaskService.updateCheckTask(checkTask));
    }

    /**
     * 删除隐患排查任务
     */
    @ApiOperation("删除风险分析对象列表")
    //TODO 20230920PreAuthorize("@ss.hasPermi('doubledefense:task:remove')")
    @Log(title = "隐患排查任务", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(checkTaskService.deleteCheckTaskByIds(ids));
    }
}
