/*
 * Author: wangjian
 * 生成controller
 */
package com.tofly.dispatch.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tofly.common.core.entity.ResultRespone;
import com.tofly.common.log.annotation.ToFlyAppLog;
import com.tofly.dispatch.common.BaseController;
import com.tofly.dispatch.common.FlowConstant;
import com.tofly.dispatch.dto.EmergencyDTO;
import com.tofly.dispatch.dto.EmergencyQuery;
import com.tofly.dispatch.service.EmergencyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
import java.util.Set;

/**
 * 应急事件（处置预案、事件分析）
 *
 * @author xqf
 * @date Mon Apr 25 00:00:00 CST 2022
 */
@RestController
@AllArgsConstructor
@RequestMapping("/emergency")
@Api(tags="应急预案-接口")
public class EmergencyController extends BaseController {

    private final  EmergencyService emergencyService;

    @ToFlyAppLog(title = "应急预案新增")
    @PostMapping
    @ApiOperation(value = "应急预案新增")
    public  ResultRespone insert(@Validated EmergencyDTO emergencyDto,
                                 @ApiParam("文件附件列表") List<MultipartFile> fileList){
        emergencyService.insert(emergencyDto,fileList);
        return decide(FlowConstant.ADD_SUCCESS);
    }

    @ToFlyAppLog(title = "应急预案修改")
    @PutMapping
    @ApiOperation(value = "应急预案修改")
    public  ResultRespone edit(@Validated EmergencyDTO emergencyDto,
                               @ApiParam("文件附件列表") List<MultipartFile> fileList){
        emergencyService.edit(emergencyDto,fileList);
        return decide(FlowConstant.UPDATE_SUCCESS);
    }

    @ToFlyAppLog(title = "应急预案删除")
    @ApiOperation(value = "应急预案批量删除")
    @DeleteMapping
    public ResultRespone delete(@ApiParam(value ="多个ID以数组形式进行传入") @RequestBody Set<Long> ids){
        emergencyService.delete(ids);
        return decide(FlowConstant.DELETE_SUCCESS);
    }

    @ToFlyAppLog(title = "应急预案-分页查询")
    @ApiOperation(value = "应急预案-分页查询")
    @GetMapping("/list")
    public ResultRespone pageList(Page page, EmergencyQuery query){
        return decide(emergencyService.pageList(page,query));
    }

    @ToFlyAppLog(title = "应急预案模糊-查询所有")
    @ApiOperation(value = "应急预案模糊-查询所有")
    @PostMapping("/all")
    public ResultRespone all(EmergencyQuery query){
        return decide(emergencyService.all(query));
    }

    @ToFlyAppLog(title = "应急预案根据ID查询")
    @ApiOperation(value = "应急预案根据ID查询")
    @GetMapping("/get")
    public ResultRespone get(@ApiParam(value = "应急事件（处置预案、事件分析）ID") @RequestParam Long id){
        return decide(emergencyService.get(id));
    }
}
