package com.mosty.sjzx.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.mosty.base.model.dto.sjzx.TbJqYjbjDto;
import com.mosty.base.model.entity.lzother.VLz110Txj;
import com.mosty.base.model.entity.sjzx.TbJqCjdb;
import com.mosty.base.model.entity.xinzhi.GxCjdb;
import com.mosty.base.model.entity.xinzhi.Jjdb;
import com.mosty.base.model.query.sjzx.TbJqCjdbQuery;
import com.mosty.base.model.query.sjzx.XftjQuery;
import com.mosty.base.model.vo.xinzhi.GxAlarmAllVo;
import com.mosty.common.base.domain.BaseController;
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.base.model.entity.sjzx.TbJq;
import com.mosty.base.model.query.sjzx.TbJqListQuery;
import com.mosty.base.model.query.sjzx.TbJqPageListQuery;
import com.mosty.base.model.vo.sjzx.GeohashQuery;
import com.mosty.base.model.vo.sjzx.TbJqVo;
import com.mosty.sjzx.service.TbJqService;
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.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraintvalidation.SupportedValidationTarget;
import java.util.List;
import java.util.Map;

/**
 * 警情表(TbJq)表控制层
 *
 * @author zhangHaiJun
 * @since 2022-07-13 20:44:48
 */
@AllArgsConstructor
@RestController
@Api(tags = "警情相关接口")
@RequestMapping("/tbJq")
public class TbJqController extends BaseController {

    private final TbJqService tbJqService;


    @GetMapping("/getPageListLz")
    @ApiOperation(value = "查询警情数据泸州分页")
    @JwtSysUser
    public ResponseResult<IPage<TbJqVo>> getPageListLz(TbJqPageListQuery dto) {
        return ResponseResult.success(this.tbJqService.getPageListLz(dto));
    }


    @GetMapping("/getPageList")
    @ApiOperation(value = "查询警情数据分页")
    @JwtSysUser
    public ResponseResult<IPage<TbJqVo>> selectPageList(TbJqPageListQuery dto) {
        return ResponseResult.success(this.tbJqService.selectPageList(dto));
    }

    @GetMapping("/getListCjd")
    @ApiOperation(value = "查询处警单表")
    @JwtSysUser
    @Log(title = "查询处警单表", businessType = BusinessType.OTHER)
    public ResponseResult<List<TbJqCjdb>> getListCjd(String jjdbh) {
        return ResponseResult.success(this.tbJqService.getListCjd(jjdbh));
    }


    @GetMapping("/getList")
    @ApiOperation(value = "查询警情数据不分页")
    @JwtSysUser
    public ResponseResult<List<TbJqVo>> getList(TbJqListQuery dto) {
        return ResponseResult.success(this.tbJqService.getList(dto));
    }

    @ApiOperation(value = "查询单条数据")
    @GetMapping("{id}")
    public ResponseResult<TbJqVo> queryById(@PathVariable("id") String id) {
        return ResponseResult.success(this.tbJqService.queryById(id));
    }

    @ApiOperation("新增警情数据")
    @PostMapping
    @JwtSysUser
    public ResponseResult<TbJq> add(@RequestBody TbJq tbJq) {
        this.tbJqService.insert(tbJq);
        return ResponseResult.success();
    }

    @ApiOperation("修改警情数据")
    @PutMapping
    @JwtSysUser
    public ResponseResult<TbJq> edit(@RequestBody TbJq tbJq) {
        this.tbJqService.update(tbJq);
        return ResponseResult.success();
    }

    @ApiOperation("删除警情数据")
    @DeleteMapping
    @JwtSysUser
    public ResponseResult<Boolean> deleteById(String id) {
        return ResponseResult.success(this.tbJqService.deleteById(id));
    }

    @ApiOperation("获取警情坐标（热力图使用）")
    @GetMapping("getJqHotMap")
    @JwtSysUser
    public ResponseResult<List<Map<String, Object>>> getJqHotMap(TbJqListQuery dto) {
        return ResponseResult.success(this.tbJqService.getJqHotMap(dto));
    }


    @GetMapping("/getJqCount")
    @ApiOperation(value = "根据时间获取警情数量")
    @JwtSysUser
    public ResponseResult<Integer> getJqCount(TbJqListQuery dto) {
        return ResponseResult.success(this.tbJqService.getJqCount(dto));
    }

    @GetMapping("/getJqBy24h")
    @ApiOperation(value = "今日警情数量走势")
    @JwtSysUser
    public ResponseResult<Object> getJqBy24h(String ssbmdm) {
        return ResponseResult.success(this.tbJqService.getJqBy24h(ssbmdm));
    }

    @GetMapping("/getZfgkList")
    @ApiOperation(value = "查询租房管控信息列表")
    @JwtSysUser
    public ResponseResult<IPage<TbJqVo>> getZfgkList(TbJqPageListQuery dto) {
        return ResponseResult.success(this.tbJqService.getZfgkList(dto));
    }

    @GetMapping("/getjrjqczfx")
    @ApiOperation(value = "今日警情处置分析")
    @JwtSysUser
    public ResponseResult<Object> getjrjqczfx(String ssbmdm) {
        return ResponseResult.success(this.tbJqService.getjrjqczfx(ssbmdm));
    }

    @PostMapping("/addXzjq")
    @ApiOperation(value = "添加高新新稚警情信息到数据库中")
    public ResponseResult<Integer> addXzjq(@RequestBody GxAlarmAllVo entity) {
        return ResponseResult.success(this.tbJqService.addXzjq(entity));
    }

    @PostMapping("/addRsJq")
    @ApiOperation(value = "添加仁寿警情信息到数据库中")
    public ResponseResult<Integer> addRsJq(@RequestBody TbJq entity) {
        return ResponseResult.success(this.tbJqService.addRsJq(entity));
    }

    @PostMapping("/addXzJqCjdb")
    @ApiOperation(value = "添加新稚警情-处警单表到数据库中")
    public ResponseResult<Integer> addXzJqCjdb(@RequestBody GxCjdb cjdb) {
        return ResponseResult.success(this.tbJqService.addXzJqCjdb(cjdb));
    }

    @PostMapping("/getStatistics")
    @ApiOperation(value = "APP警情统计")
    public ResponseResult<Map<String, Object>> getStatistics(@RequestBody TbJqListQuery dto) {
        return ResponseResult.success(this.tbJqService.getStatistics(dto));
    }

    @GetMapping("/getAllStatistics")
    @ApiOperation(value = "APP首页-所有警情统计")
    public ResponseResult<Map<String, Object>> getAllStatistics() {
        return ResponseResult.success(this.tbJqService.getAllStatistics());
    }

    @GetMapping("/getJmjqStatistics")
    @ApiOperation(value = "APP首页-街面警情统计")
    public ResponseResult<Map<String, Object>> getJmjqStatistics() {
        return ResponseResult.success(this.tbJqService.getJmjqStatistics());
    }

    @GetMapping("/getWffzStatistics")
    @ApiOperation(value = "APP首页-违法犯罪警情统计")
    public ResponseResult<Map<String, Object>> getWffzStatistics() {
        return ResponseResult.success(this.tbJqService.getWffzStatistics());
    }

    @GetMapping("/getDqscStatistics")
    @ApiOperation(value = "APP首页-盗抢三车警情统计")
    public ResponseResult<Map<String, Object>> getDqscStatistics() {
        return ResponseResult.success(this.tbJqService.getDqscStatistics());
    }

    @GetMapping("/jqtjDbFjjqzs")
    @ApiOperation(value = "APP警情分析-对比分析-分局警情走势图")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "查询类型 1.今日 2.近一周 3.近一月 4.近三月", name = "type", dataType = "String"),
            @ApiImplicitParam(value = "分局代码", name = "ssfjdm", dataType = "String"),
            @ApiImplicitParam(value = "警情类型 1.总警情 2.街面警情 3.违法犯罪", name = "jqType", dataType = "String"),
    })
    public ResponseResult<Object> jqtjDbFjjqzs(String type, String ssfjdm, String jqType) {
        return ResponseResult.success(this.tbJqService.jqtjDbFjjqzs(type, ssfjdm, jqType));
    }

    @GetMapping("/jqtjDbCqfjhb")
    @ApiOperation(value = "APP警情分析-对比分析-城区分局警情环比")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "查询类型 1.今日 2.近一周 3.近一月 4.近三月", name = "type", dataType = "String"),
            @ApiImplicitParam(value = "警情类型 1.总警情 2.街面警情 3.违法犯罪", name = "jqType", dataType = "String"),
    })
    public ResponseResult<Object> jqtjDbCqfjhb(String type, String jqType) {
        return ResponseResult.success(this.tbJqService.jqtjDbCqfjhb(type, jqType));
    }

    @GetMapping("/jqtjDbCqfjhbTable")
    @ApiOperation(value = "APP警情分析-对比分析-城区分局警情环比-列表")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "查询类型 1.今日 2.近一周 3.近一月 4.近三月", name = "type", dataType = "String"),
            @ApiImplicitParam(value = "分局代码", name = "ssfjdm", dataType = "String"),
            @ApiImplicitParam(value = "警情类型 1.总警情 2.街面警情 3.违法犯罪", name = "jqType", dataType = "String"),
    })
    public ResponseResult<Object> jqtjDbCqfjhbTable(String type, String ssfjdm, String jqType) {
        return ResponseResult.success(this.tbJqService.jqtjDbCqfjhbTable(type, ssfjdm, jqType));
    }

    @GetMapping("/jqtjDbPcsHb")
    @ApiOperation(value = "APP警情分析-对比分析-派出所总警情环比")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "查询类型 1.今日 2.近一周 3.近一月 4.近三月", name = "type", dataType = "String"),
            @ApiImplicitParam(value = "分局代码", name = "ssfjdm", dataType = "String"),
            @ApiImplicitParam(value = "警情类型 1.总警情 2.街面警情 3.违法犯罪", name = "jqType", dataType = "String"),
    })
    public ResponseResult<Object> jqtjDbPcsHb(String type, String ssfjdm, String jqType) {
        return ResponseResult.success(this.tbJqService.jqtjDbPcsHb(type, ssfjdm, jqType));
    }

    @GetMapping("/jqtjDbPcsHbTable")
    @ApiOperation(value = "APP警情分析-对比分析-派出所总警情环比-表格")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "查询类型 1.今日 2.近一周 3.近一月 4.近三月", name = "type", dataType = "String"),
            @ApiImplicitParam(value = "分局代码", name = "ssfjdm", dataType = "String"),
            @ApiImplicitParam(value = "警情类型 1.总警情 2.街面警情 3.违法犯罪", name = "jqType", dataType = "String"),
    })
    public ResponseResult<Object> jqtjDbPcsHbTable(String type, String ssfjdm, String jqType) {
        return ResponseResult.success(this.tbJqService.jqtjDbPcsHbTable(type, ssfjdm, jqType));
    }

    @GetMapping("/jqtjSgFirst")
    @ApiOperation(value = "APP警情分析-四高分析-第一个统计图")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "查询类型 1.今日 2.近一周 3.近一月 4.近三月", name = "type", dataType = "String"),
            @ApiImplicitParam(value = "分局代码", name = "ssfjdm", dataType = "String"),
            @ApiImplicitParam(value = "警情类型 1.总警情 2.街面警情 3.违法犯罪", name = "jqType", dataType = "String"),
            @ApiImplicitParam(value = "时段类型 3，4，6，8", name = "sdlx", dataType = "String"),
    })
    public ResponseResult<Object> jqtjSgFirst(String type, String ssfjdm, String jqType, String sdlx) {
        return ResponseResult.success(this.tbJqService.jqtjSgFirst(type, ssfjdm, jqType, sdlx));
    }

    @GetMapping("/getGljq")
    @ApiOperation(value = "APP首页-获取关联警情")
    public ResponseResult<List<TbJqVo>> getGljq(String jjdbh) {
        return ResponseResult.success(this.tbJqService.getGljq(jjdbh));
    }

    @GetMapping("/getCjList")
    @ApiOperation(value = "APP获取警情的处警数据")
    public ResponseResult<IPage<TbJqCjdb>> getCjList(TbJqCjdbQuery dto) {
        return ResponseResult.success(this.tbJqService.getCjList(dto));
    }

    @GetMapping("/getLastJq")
    @ApiOperation(value = "APP获取警情的处警数据")
    public ResponseResult<TbJqVo> getLastJq() {
        return ResponseResult.success(this.tbJqService.getLastJq());
    }

    @GetMapping("/getLastJqCjdb")
    @ApiOperation(value = "获取最新的一条处警单的数据")
    public ResponseResult<TbJqCjdb> getLastJqCjdb() {
        return ResponseResult.success(this.tbJqService.getLastJqCjdb());
    }

    @PostMapping("/addRsCjdb")
    @ApiOperation(value = "添加仁寿处警单数据")
    public ResponseResult<Void> addRsCjdb(@RequestBody TbJqCjdb cjdb) {
        this.tbJqService.addRsCjdb(cjdb);
        return ResponseResult.success();
    }

    @GetMapping("/situation")
    @ApiOperation(value = "转新稚警情接口（实发案）警情概况")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "开始时间（yyyy-MM-dd HH:mm:ss）", name = "startTime", dataType = "String"),
            @ApiImplicitParam(value = "结束时间（yyyy-MM-dd HH:mm:ss）", name = "endTime", dataType = "String"),
    })
    public ResponseResult<JSONObject> situation(String startTime, String endTime) {
        return ResponseResult.success(this.tbJqService.situation(startTime, endTime));
    }

    @GetMapping("/alarmSituation")
    @ApiOperation(value = "转新稚警情接口--警请态势")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "开始时间（yyyy-MM-dd HH:mm:ss）", name = "startTime", dataType = "String"),
            @ApiImplicitParam(value = "结束时间（yyyy-MM-dd HH:mm:ss）", name = "endTime", dataType = "String"),
    })
    public ResponseResult<JSONObject> alarmSituation(String startTime, String endTime) {
        return ResponseResult.success(this.tbJqService.alarmSituation(startTime, endTime));
    }

    @PostMapping("/addLzJq")
    @ApiOperation(value = "添加泸州警情信息到数据库中")
    public ResponseResult<Void> addLzJq(@RequestBody VLz110Txj lz110) {
        this.tbJqService.addLzJq(lz110);
        return ResponseResult.success();
    }


    @PostMapping("/addLzHndJq")
    @ApiOperation(value = "添加泸州海能达警情信息到数据库中")
    public ResponseResult<Void> addLzHndJq(@RequestBody Jjdb jjdb) {
        System.out.println("添加泸州警情信息到数据库中--->" + JSONArray.toJSONString(jjdb));
        this.tbJqService.addYbJq(jjdb);
        return ResponseResult.success();
    }

    @PostMapping("/addYbJq")
    @ApiOperation(value = "添加宜宾警情信息到数据库中")
    public ResponseResult<Void> addYbJq(@RequestBody Jjdb jjdb) {
        this.tbJqService.addYbJq(jjdb);
        return ResponseResult.success();
    }

    @ApiOperation("泸州态势统计-警情与巡防工作对比分析")
    @PostMapping("/getJqAndXfTj")
    @JwtSysUser
    public ResponseResult<Map<String, Object>> getJqAndXfTj(XftjQuery dto) {
        return ResponseResult.success(tbJqService.getJqAndXfTj(dto));
    }

    @ApiOperation("泸州态势统计-警情与盘查工作对比分析")
    @PostMapping("/getJqAndPcTj")
    @JwtSysUser
    public ResponseResult<Map<String, Object>> getJqAndPcTj(XftjQuery dto) {
        return ResponseResult.success(tbJqService.getJqAndPcTj(dto));
    }


    @ApiOperation("APP一键报警添加接口")
    @PostMapping("/addYjbj")
    @JwtSysUser
    public ResponseResult<Void> addYjbj(@RequestBody TbJqYjbjDto dto) {
        tbJqService.addYjbj(dto);
        return ResponseResult.success();
    }

    @ApiOperation("修改警情处置状态")
    @PostMapping("/updateJqCzzt")
    public ResponseResult<Void> updateJqCzzt(@RequestParam("id") String id, @RequestParam("czzt") String czzt) {
        tbJqService.updateJqCzzt(id, czzt);
        return ResponseResult.success();
    }

    @ApiOperation("查询没得经纬度的接警单编号")
    @GetMapping("/selectJjdbh")
    public ResponseResult<List<String>> selectJjdbh() {
        return ResponseResult.success(this.tbJqService.selectJjdbh());
    }


    @ApiOperation("修改警情经纬度")
    @PostMapping("/updateJqJwd")
    public ResponseResult<Void> updateJqJwd(@RequestBody Jjdb jjdb) {
        System.out.println("修改警情经纬度--->" + JSONArray.toJSONString(jjdb));
        this.tbJqService.updateJqJwd(jjdb);
        return ResponseResult.success();
    }

    @ApiOperation("同步接警单号到reids")
    @GetMapping("/tbJjdhToRedis")
    public ResponseResult<Void> tbJjdhToRedis() {
        this.tbJqService.tbJjdhToRedis();
        return ResponseResult.success();
    }


}


