package com.mosty.yjzl.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.mosty.base.model.dto.qwzx.TbQwXfbbVo;
import com.mosty.base.model.dto.yjzl.*;
import com.mosty.base.model.entity.trs.VwAlermYjgl;
import com.mosty.base.model.entity.trs.VwAlermYjzl;
import com.mosty.base.model.entity.yjzl.TbZlYjRy;
import com.mosty.base.model.entity.yjzl.TbZlxx;
import com.mosty.base.model.query.afjcsj.VwSyrkJzgjGxListQuery;
import com.mosty.base.model.query.yjzl.TbZlxxQuery;
import com.mosty.base.model.vo.trs.VwAlermYjzlVo;
import com.mosty.base.model.vo.yjzl.*;
import com.mosty.common.base.domain.ResponseResult;
import com.mosty.common.base.entity.log.BusinessType;
import com.mosty.common.base.entity.log.Log;
import com.mosty.common.token.JwtSysUser;
import com.mosty.yjzl.service.TbZlxxService;
import com.mosty.yjzl.service.TbZlxxZxjlService;
import io.swagger.annotations.*;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Api(tags = "指令信息相关接口")
@RestController
@AllArgsConstructor
@CrossOrigin
@RequestMapping("/tbZl")
public class TbZlxxController {

    private final TbZlxxService tbZlxxService;
    private final TbZlxxZxjlService tbZlxxZxjlService;

    @ApiOperation("根据时间查询指令执行情况")
    @GetMapping("/selectInstructCount")
    @JwtSysUser
    @ApiImplicitParams({
            @ApiImplicitParam(value = "查询开始时间（默认查询当天）", name = "startTime", dataType = "String"),
            @ApiImplicitParam(value = "查询结束时间（默认查询当天）", name = "endTime", dataType = "String")
    })
    public ResponseResult<Map<String, Object>> selectInstructCount(String startTime, String endTime) {
        return ResponseResult.success(this.tbZlxxService.selectInstructCount(startTime, endTime));
    }


    @ApiOperation("大屏-查询指令列表-分页")
    @PostMapping(value = "/selectInstructList")
    @JwtSysUser
    public ResponseResult<IPage<TbZlxxVo>> selectInstructList(@RequestBody TbZlxxQuery dto) {
        return ResponseResult.success(this.tbZlxxService.selectInstructList(dto));
    }

    @ApiOperation("添加指令信息")
    @PostMapping(value = "/addZl")
    @Log(title = "添加指令信息", businessType = BusinessType.INSERT)
    @JwtSysUser
    public ResponseResult<Void> addZl(@RequestBody TbZlxxInsertDto dto) {
        this.tbZlxxService.addZl(dto);
        return ResponseResult.success();
    }

    @ApiOperation("修改指令信息")
    @PostMapping(value = "/updateZl")
    @Log(title = "修改指令信息", businessType = BusinessType.UPDATE)
    @JwtSysUser
    public ResponseResult<Void> updateZl(@RequestBody TbZlxxInsertDto dto) {
        this.tbZlxxService.updateZl(dto);
        return ResponseResult.success();
    }

    @ApiOperation("查询事件的参与警力")
    @GetMapping(value = "/getCyjlList")
    @JwtSysUser
    public ResponseResult<List<Map<String, Object>>> getCyjlList(CyjlSearchDto dto) {
        return ResponseResult.success(this.tbZlxxZxjlService.getCyjlList(dto));
    }

    @ApiOperation("查询事件的现场装备")
    @GetMapping(value = "/getXczbList")
    @JwtSysUser
    public ResponseResult<List<TbQwXfbbVo>> getXczbList(String sjid) {
        return ResponseResult.success(this.tbZlxxZxjlService.getXczbList(sjid));
    }

    @ApiOperation("APP获取我的指令数量")
    @GetMapping(value = "/getMyZlCount")
    @JwtSysUser
    public ResponseResult<List<Map<String, Object>>> getMyZlCount() {
        return ResponseResult.success(this.tbZlxxZxjlService.getMyZlCount());
    }

    @ApiOperation("APP获取我的指令列表")
    @GetMapping(value = "/getMyZlList")
    @JwtSysUser
    public ResponseResult<IPage<TbZlxxZxrVo>> getMyZlList(MyZlSearchDto dto) {
        return ResponseResult.success(this.tbZlxxZxjlService.getMyZlList(dto));
    }

    @ApiOperation("查询指令处置流程以及最新记录")
    @GetMapping(value = "/getZxjlList")
    @JwtSysUser
    public ResponseResult<List<TbZlxxZxjlVo>> getNewZxjl(NewZxjlSearchDto dto) {
        return ResponseResult.success(this.tbZlxxZxjlService.getNewZxjl(dto));
    }

    @ApiOperation("指令到期状态修改")
    @PostMapping(value = "/changeZlGqzt")
    @JwtSysUser
    public ResponseResult<Void> changeZlGqzt() {
        this.tbZlxxService.changeZlGqzt();
        return ResponseResult.success();
    }

    @ApiOperation("指令处置流程")
    @PostMapping(value = "/zlHandle")
    @Log(title = "指令处置流程", businessType = BusinessType.UPDATE)
    @JwtSysUser
    public ResponseResult<Void> zlHandle(@RequestBody TbZlxxZtChangeDto dto) {
        this.tbZlxxService.zlHandle(dto);
        return ResponseResult.success();
    }

    @ApiOperation("指令处置流程（人员管控）")
    @PostMapping(value = "/zlHandleRygk")
    @Log(title = "指令处置流程（人员管控）", businessType = BusinessType.UPDATE)
    @JwtSysUser
    public ResponseResult<Void> zlHandleRygk(@RequestBody TbZlxxZtChangeRygkDto dto) {
        this.tbZlxxService.zlHandleRygk(dto);
        return ResponseResult.success();
    }

    @ApiOperation("查询指令详细信息")
    @GetMapping(value = "{id}")
    @JwtSysUser
    public ResponseResult<TbZlxxInfoVo> getInfo(@PathVariable("id") String id) {
        return ResponseResult.success(this.tbZlxxService.getInfo(id));
    }

    @ApiOperation("添加指令执行记录")
    @PostMapping(value = "/addZxjl")
    @Log(title = "添加指令执行记录", businessType = BusinessType.INSERT)
    @JwtSysUser
    public ResponseResult<Void> addZxjl(@RequestBody TbZlxxZxjlInsertDto dto) {
        this.tbZlxxService.addZxjl(dto);
        return ResponseResult.success();
    }

    @ApiOperation("添加指令盘查人车的记录")
    @PostMapping(value = "/addPcrycl")
    @Log(title = "添加指令盘查人车的记录", businessType = BusinessType.INSERT)
    @JwtSysUser
    public ResponseResult<Void> addPcrycl(@RequestBody TbZlxxPcryclInsertDto dto) {
        this.tbZlxxService.addPcrycl(dto);
        return ResponseResult.success();
    }

    @ApiOperation("获取托尔斯预警指令信息添加")
    @PostMapping(value = "/addTrsZl")
    public ResponseResult<Void> addTrsZl(@RequestBody VwAlermYjzlVo vo) {
        this.tbZlxxService.addTrsZl(vo);
        return ResponseResult.success();
    }

    @ApiOperation("获取托尔斯预警信息添加")
    @PostMapping(value = "/addTrsYj")
    public ResponseResult<Void> addTrsYj(@RequestBody VwAlermYjgl vo) {
        this.tbZlxxService.addTrsYj(vo);
        return ResponseResult.success();
    }

    @ApiOperation("获取最后一条TRS推送的指令信息")
    @PostMapping(value = "/getLastZlxx")
    public ResponseResult<TbZlxx> getLastZlxx() {
        return ResponseResult.success(this.tbZlxxService.getLastZlxx());
    }

    @ApiOperation("查询实有人口指令信息")
    @GetMapping(value = "/getSyrkZlxx")
    public ResponseResult<IPage<TbZlYjRyVo>> getSyrkZlxx(VwSyrkJzgjGxListQuery dto) {
        return ResponseResult.success(this.tbZlxxService.getSyrkZlxx(dto));
    }

    @ApiOperation("APP指令统计--指令类型")
    @GetMapping(value = "/getTjOfZllx")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "type", value = "1.今日 2.近7日 3.近30日 4.近90日", dataType = "String", required = true)
    })
    @JwtSysUser
    public ResponseResult<List<Map<String, Object>>> getTjOfZllx(String type) {
        return ResponseResult.success(this.tbZlxxService.getTjOfZllx(type));
    }

    @ApiOperation("根据完成情况统计指令数量")
    @JwtSysUser
    @GetMapping(value = "/getStatisticsByStatus")
    public ResponseResult<Map<String, Object>> getStatisticsByStatus() {
        return ResponseResult.success(this.tbZlxxService.getStatisticsByStatus());
    }

    @ApiOperation("查询我发送的指令")
    @JwtSysUser
    @GetMapping(value = "/getMySendZlList")
    public ResponseResult<IPage<TbZlxxVo>> getMySendZlList(MyZlSearchDto dto) {
        return ResponseResult.success(this.tbZlxxService.getMySendZlList(dto));
    }

    @ApiOperation("查询我发送的指令")
    @JwtSysUser
    @GetMapping(value = "/getZlCount")
    public ResponseResult<Integer> getZlCount(String ssbmdm, String time, String zlzxzt) {
        return ResponseResult.success(this.tbZlxxService.getZlCount(ssbmdm, time, zlzxzt));
    }

    @ApiOperation("大屏预警统计")
    @JwtSysUser
    @PostMapping(value = "/yjzlTj")
    public ResponseResult<Map<String,Integer>> yjzlTj() {
        return ResponseResult.success(this.tbZlxxService.yjzlTj());
    }



    @ApiOperation("警情转指令")
    @JwtSysUser
    @GetMapping(value = "/andJqZl")
    public ResponseResult<Void> andJqZl(String ssbmid,String jqid, String bbids, String zlxflx) {
        this.tbZlxxService.andJqZl(ssbmid,jqid, bbids,zlxflx);
        return ResponseResult.success();
    }


    @ApiOperation("预警转指令")
    @JwtSysUser
    @GetMapping(value = "/andYjZl")
    public ResponseResult<Void> andYjZl(String yjid, String bbids) {
        this.tbZlxxService.andYjZl(yjid, bbids);
        return ResponseResult.success();
    }




}
