package com.ruoyi.web.controller.doubleDefense;

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

import com.ruoyi.doubledefense.dto.RiskEventDTO;
import com.ruoyi.doubledefense.dto.res.RiskEventResultDTO;
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.RiskEvent;
import com.ruoyi.doubledefense.service.IRiskEventService;
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/event")
public class RiskEventController extends BaseController
{
    @Autowired
    private IRiskEventService riskEventService;

    /**
     * 查询风险事件列表
     */
    @ApiOperation("查询风险分析对象列表")
    //TODO 20230920PreAuthorize("@ss.hasPermi('doubledefense:event:list')")
    @GetMapping("/list")
    public TableDataInfo list(RiskEventDTO riskEvent)
    {
        startPage();
        List<RiskEventResultDTO> list = riskEventService.selectRiskEventList(riskEvent);
        return getDataTable(list);
    }

    /**
     * 导出风险事件列表
     */
    @ApiOperation("导出风险事件列表")
    //TODO 20230920PreAuthorize("@ss.hasPermi('doubledefense:event:export')")
    @Log(title = "风险事件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RiskEventDTO riskEvent)
    {
        List<RiskEventResultDTO> list = riskEventService.selectRiskEventList(riskEvent);
        ExcelUtil<RiskEventResultDTO> util = new ExcelUtil<RiskEventResultDTO>(RiskEventResultDTO.class);
        util.exportExcel(response, list, "风险事件数据");
    }

    /**
     * 获取风险事件详细信息
     */
    @ApiOperation("获取风险事件详细信息")
    //TODO 20230920PreAuthorize("@ss.hasPermi('doubledefense:event:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(riskEventService.selectRiskEventById(id));
    }

    /**
     * 新增风险事件
     */
    @ApiOperation("新增风险事件")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "riskEventName", value = "风险事件名称", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "riskUnitId", value = "所属风险单元UUID", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "riskEventContent", value = "风险事件内容", dataType = "String", dataTypeClass = String.class)
    })
    //TODO 20230920PreAuthorize("@ss.hasPermi('doubledefense:event:add')")
    @Log(title = "风险事件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RiskEventDTO riskEvent)
    {
        return toAjax(riskEventService.insertRiskEvent(riskEvent));
    }

    /**
     * 修改风险事件
     */
    @ApiOperation("修改风险事件")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "风险分析事件ID", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "riskEventName", value = "风险事件名称", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "riskUnitId", value = "所属风险单元UUID", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "riskEventContent", value = "风险事件内容", dataType = "String", dataTypeClass = String.class)
    })
    //TODO 20230920PreAuthorize("@ss.hasPermi('doubledefense:event:edit')")
    @Log(title = "风险事件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RiskEventDTO riskEvent)
    {
        return toAjax(riskEventService.updateRiskEvent(riskEvent));
    }

    /**
     * 删除风险事件
     */
    @ApiOperation("删除风险事件")
    //TODO 20230920PreAuthorize("@ss.hasPermi('doubledefense:event:remove')")
    @Log(title = "风险事件", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(riskEventService.deleteRiskEventByIds(ids));
    }
}
