package com.ruoyi.web.controller.doubleDefense;

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

import com.ruoyi.doubledefense.dto.RiskMeasureDTO;
import com.ruoyi.doubledefense.dto.res.RiskMeasureResultDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
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.doubledefense.domain.RiskMeasure;
import com.ruoyi.doubledefense.service.IRiskMeasureService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 风险管控措施Controller
 *
 * @author ruoyi
 * @date 2023-08-03
 */
@Api(tags = "风险管控措施")
@RestController
@RequestMapping("/doubledefense/measure")
public class RiskMeasureController extends BaseController
{
    @Autowired
    private IRiskMeasureService riskMeasureService;

    /**
     * 查询风险管控措施列表
     */
    @ApiOperation("查询风险管控措施列表")
    //TODO 20230920PreAuthorize("@("@ss.hasPermi('doubledefense:measure:list')")
    @GetMapping("/list")
    public TableDataInfo list(RiskMeasureDTO riskMeasure)
    {
        startPage();
        List<RiskMeasureResultDTO> list = riskMeasureService.selectRiskMeasureList(riskMeasure);
        return getDataTable(list);
    }

    /**
     * 导出风险管控措施列表
     */
    @ApiOperation("风险管控措施导出")
    //TODO 20230920PreAuthorize("@("@ss.hasPermi('doubledefense:measure:export')")
    @Log(title = "风险管控措施", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RiskMeasureDTO riskMeasure)
    {
        List<RiskMeasureResultDTO> list = riskMeasureService.selectRiskMeasureList(riskMeasure);
        ExcelUtil<RiskMeasureResultDTO> util = new ExcelUtil<RiskMeasureResultDTO>(RiskMeasureResultDTO.class);
        util.exportExcel(response, list, "风险管控措施数据");
    }

    /**
     * 获取风险管控措施详细信息
     */
    @ApiOperation("获取风险管控措施详细信息")
    @ApiImplicitParam(name = "id", value = "管控措施ID", required = true, dataType = "String", paramType = "path", dataTypeClass = String.class)
    //TODO 20230920PreAuthorize("@("@ss.hasPermi('doubledefense:measure:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(riskMeasureService.selectRiskMeasureById(id));
    }

    /**
     * 新增风险管控措施
     */
    @ApiOperation("新增风险管控措施")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "riskMeasureDesc", value = "管控措施描述", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "riskEventId", value = "所属风险事件UUID", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "dataSrc", value = "管控方式：1自动化管控，2隐患排查", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "trainingPlanClassificationId1", value = "管控措施分类1：1工程技术，2维护保养，3操作行为，4应急措施", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "trainingPlanClassificationId2", value = "管控措施分类2：1-1工艺控制，1-2关键设备/部件，1-3安全附件，1-4安全仪表，1-5其它，2-1动设备，2-2静设备，2-3其它，3-1人员资质，3-2操作记录，3-3交接班，3-4其它，4-1应急设施，4-2个体防护，4-3消防设施，4-4应急预案，4-5其它", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "item", value = "管控项", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "troubleshootContent", value = "隐患排查内容", dataType = "String", dataTypeClass = String.class),
    })
    //TODO 20230920PreAuthorize("@("@ss.hasPermi('doubledefense:measure:add')")
    @Log(title = "风险管控措施", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RiskMeasureDTO riskMeasure)
    {
        return toAjax(riskMeasureService.insertRiskMeasure(riskMeasure));
    }

    /**
     * 修改风险管控措施
     */
    @ApiOperation("修改风险管控措施")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "风险分析事件ID", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "riskMeasureDesc", value = "管控措施描述", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "riskEventId", value = "所属风险事件UUID", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "dataSrc", value = "管控方式：1自动化管控，2隐患排查", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "trainingPlanClassificationId1", value = "管控措施分类1：1工程技术，2维护保养，3操作行为，4应急措施", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "trainingPlanClassificationId2", value = "管控措施分类2：1-1工艺控制，1-2关键设备/部件，1-3安全附件，1-4安全仪表，1-5其它，2-1动设备，2-2静设备，2-3其它，3-1人员资质，3-2操作记录，3-3交接班，3-4其它，4-1应急设施，4-2个体防护，4-3消防设施，4-4应急预案，4-5其它", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "item", value = "管控项", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "troubleshootContent", value = "隐患排查内容", dataType = "String", dataTypeClass = String.class),
    })
    //TODO 20230920PreAuthorize("@("@ss.hasPermi('doubledefense:measure:edit')")
    @Log(title = "风险管控措施", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RiskMeasureDTO riskMeasure)
    {
        return toAjax(riskMeasureService.updateRiskMeasure(riskMeasure));
    }

    /**
     * 删除风险管控措施
     */
    @ApiOperation("删除风险管控措施")
    @ApiImplicitParam(name = "ids", value = "管控措施ID集合", required = true, dataType = "List", paramType = "path", dataTypeClass = List.class)
    //TODO 20230920PreAuthorize("@("@ss.hasPermi('doubledefense:measure:remove')")
    @Log(title = "风险管控措施", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(riskMeasureService.deleteRiskMeasureByIds(ids));
    }
}
