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.IncidentTaskPersonVo;
import com.ruoyi.zhdd.domain.bo.IncidentTaskPersonBo;
import com.ruoyi.zhdd.service.IIncidentTaskPersonService;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 事件处置方案人员Controller
 *
 * @author xintong
 * @date 2021-11-27
 */
@Validated
@Api(value = "事件处置方案人员控制器", tags = {"事件处置方案人员管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/zhdd/incidentTaskPerson")
public class IncidentTaskPersonController extends BaseController {

    private final IIncidentTaskPersonService iIncidentTaskPersonService;

    /**
     * 查询事件处置方案人员列表
     */
    @ApiOperation("查询事件处置方案人员列表")
    @PreAuthorize("@ss.hasPermi('zhdd:incidentTaskPerson:list')")
    @GetMapping("/list")
    public TableDataInfo<IncidentTaskPersonVo> list(@Validated(QueryGroup.class) IncidentTaskPersonBo bo) {
        return iIncidentTaskPersonService.queryPageList(bo);
    }

    /**
     * 导出事件处置方案人员列表
     */
    @ApiOperation("导出事件处置方案人员列表")
    @PreAuthorize("@ss.hasPermi('zhdd:incidentTaskPerson:export')")
    @Log(title = "事件处置方案人员", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public void export(@Validated IncidentTaskPersonBo bo, HttpServletResponse response) {
        List<IncidentTaskPersonVo> list = iIncidentTaskPersonService.queryList(bo);
        ExcelUtil.exportExcel(list, "事件处置方案人员", IncidentTaskPersonVo.class, response);
    }

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

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

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

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