package com.tofly.xrtygis.custom.controller.gs;

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.xrtygis.custom.entity.gs.Emergency;
import com.tofly.xrtygis.custom.service.EmergencyService;
import com.tofly.xrtygis.entity.Rxyjfw;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;

/**
 * @author FlashWJL
 * @date 2021/4/1 17:18
 */
@RestController
@AllArgsConstructor
@RequestMapping("/emergency")
@Api(tags = "热线--热线应急服务")
public class EmergencyController {

    private final EmergencyService emergencyService;

    /**
     * 新增热线应急服务管理表
     *
     * @param rxyjfw 热线应急服务管理表
     * @return ResultRespone , HttpServletRequest request
     */
    //(title = "新增热线应急服务管理表")
    @ApiOperation(value = "新增热线应急服务管理表")
    @PostMapping(value = "/emer")
    @ToFlyAppLog(title = "新增热线应急服务管理表")
    public ResultRespone saveEmer(@RequestBody Rxyjfw rxyjfw) {
        if("1".equals(rxyjfw.getIsSms())&&!"1".equals(rxyjfw.getIsReview())){
            return ResultRespone.failed("应急服务发生短信必须审批!");
        }
        if("1".equals(rxyjfw.getIsReview())&&(rxyjfw.getShry()==null|| StringUtils.isEmpty(rxyjfw.getSmsObject()))){
            return ResultRespone.failed("应急服务必须审批,审核人不能为空或接收对象不能为空!");
        }

        return ResultRespone.success(emergencyService.saveEmer(rxyjfw));
    }
    @ApiOperation(value = "新增应急服务记录--系统新增（根据流量预警数添加）")
    @PostMapping(value = "/emerBySys")
    @ToFlyAppLog(title = "新增应急服务记录--系统新增（根据流量预警数添加）")
    public void saveEmerSys(Long flowNum) {
        emergencyService.saveEmerSys(flowNum);
    }

    @ApiOperation(value = "新增应急服务记录--系统新增（根据未接通预警数添加）")
    @PostMapping(value = "/emerBySys2")
    @ToFlyAppLog(title = "新增应急服务记录--系统新增（根据未接通预警数添加）")
    public void saveEmerSys2(Long blockCallNum) {
        emergencyService.saveEmerSys2(blockCallNum);
    }


    /**
     * 分页查询
     *
     * @param page   分页对象
     * @param emergency 热线应急服务管理表
     * @return
     */
    @GetMapping("/emer")
    @ApiOperation(value = "应急服务列表")
    @ToFlyAppLog(title = "应急服务列表")
    public ResultRespone getEmer(Page page, Emergency emergency) {
        return ResultRespone.success(emergencyService.getEmer(page, emergency));
    }


    @GetMapping("/remind")
    @ApiOperation(value = "应急服务提醒列表",notes = "根据前端轮训和当前人角色实现，提醒相应的工作人员")
    @ToFlyAppLog(title = "应急服务提醒列表")
    public ResultRespone remind(Page page) {
        return ResultRespone.success(emergencyService.remind(page));
    }

    /**
     * 通过id批量删除热线应急服务管理表
     * @param ids id
     * @return ResultRespone
     */
    //(title="通过id批量删除热线应急服务管理表" )
    @ApiOperation(value = "通过ID批量删除热线应急服务管理表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ids", value = "批量删除，多个id以逗号隔开", required = true, dataType = "String")
    })
    @GetMapping("/emer1" )
    @ToFlyAppLog(title = "通过ID批量删除热线应急服务管理表")
    public ResultRespone delEmer(String ids) {

        return ResultRespone.success(emergencyService.delEmer(Arrays.asList(ids.split(","))));
    }


    /**
     * 修改热线应急服务管理表
     *
     * @param rxyjfw 热线应急服务管理表
     * @return ResultRespone
     */
//    //(title = "修改热线应急服务管理表")
//    @ApiOperation(value = "修改热线应急服务管理表")
//    @PutMapping(value = "/emer", headers = "content-type=multipart/form-data")
    public ResultRespone updateEmer(Rxyjfw rxyjfw, HttpServletRequest request) {
        return ResultRespone.success(emergencyService.updateEmer(rxyjfw, request));
    }

    /**
     * 应急服务审核
     * @param rxyjfw
     * @return
     */
    //(title = "应急服务审核")
    @ApiOperation(value = "应急服务审核")
    @PostMapping(value = "/audit")
    @ToFlyAppLog(title = "应急服务审核")
    public ResultRespone audit(@RequestBody Rxyjfw rxyjfw) {

        String str = emergencyService.checkData(rxyjfw);
        if(StringUtils.isNotEmpty(str)){
            return ResultRespone.failed(str);
        }
        return ResultRespone.success(emergencyService.audit(rxyjfw));
    }






}
