package com.ruoyi.web.controller.zhdd;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
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.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.zhdd.domain.vo.IncidentProcessVo;
import com.ruoyi.zhdd.domain.bo.IncidentProcessBo;
import com.ruoyi.zhdd.service.IIncidentProcessService;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 事件处置流程Controller
 *
 * @author xitong
 * @date 2021-09-28
 */
@Validated
@Api(value = "事件处置流程控制器", tags = {"事件处置流程管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/zhdd/incidentProcess")
public class IncidentProcessController extends BaseController {

    private final IIncidentProcessService iIncidentProcessService;

    /**
     * 查询事件处置流程列表
     */
    @ApiOperation("查询事件处置流程列表")
//    @PreAuthorize("@ss.hasPermi('zhdd:incidentProcess:list')")
    @GetMapping("/list")
    public TableDataInfo<IncidentProcessVo> list(@Validated(QueryGroup.class) IncidentProcessBo bo) {
        return iIncidentProcessService.queryPageList(bo);
    }

    /**
     * 导出事件处置流程列表
     */
    @ApiOperation("导出事件处置流程列表")
//    @PreAuthorize("@ss.hasPermi('zhdd:incidentProcess:export')")
    @Log(title = "事件处置流程", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public void export(@Validated IncidentProcessBo bo, HttpServletResponse response) {
        List<IncidentProcessVo> list = iIncidentProcessService.queryList(bo);
        ExcelUtil.exportExcel(list, "事件处置流程", IncidentProcessVo.class, response);
    }

    /**
     * 获取事件处置流程详细信息
     */
    @ApiOperation("获取事件处置流程详细信息")
//    @PreAuthorize("@ss.hasPermi('zhdd:incidentProcess:query')")
    @GetMapping("/{id}")
    public AjaxResult<IncidentProcessVo> getInfo(@NotNull(message = "主键不能为空")
                                                  @PathVariable("id") String id) {
        return AjaxResult.success(iIncidentProcessService.queryById(id));
    }

    /**
     * 新增事件处置流程
     */
    @ApiOperation("新增事件处置流程")
//    @PreAuthorize("@ss.hasPermi('zhdd:incidentProcess:add')")
    @Log(title = "事件处置流程", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public AjaxResult<Void> add(@Validated(AddGroup.class) @RequestBody IncidentProcessBo bo) {
        return toAjax(iIncidentProcessService.insertByBo(bo) ? 1 : 0);
    }

    /**
     * 修改事件处置流程
     */
    @ApiOperation("修改事件处置流程")
//    @PreAuthorize("@ss.hasPermi('zhdd:incidentProcess:edit')")
    @Log(title = "事件处置流程", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public AjaxResult<Void> edit(@Validated(EditGroup.class) @RequestBody IncidentProcessBo bo) {
        return toAjax(iIncidentProcessService.updateByBo(bo) ? 1 : 0);
    }

    /**
     * 删除事件处置流程
     */
    @ApiOperation("删除事件处置流程")
//    @PreAuthorize("@ss.hasPermi('zhdd:incidentProcess:remove')")
    @Log(title = "事件处置流程" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
                                       @PathVariable String[] ids) {
        return toAjax(iIncidentProcessService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
