package com.mosty.qwzx.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.mosty.base.model.dto.qwzx.*;
import com.mosty.base.model.entity.qwzx.TbQwJl;
import com.mosty.base.model.entity.qwzx.TbQwxfbbDk;
import com.mosty.base.model.query.qwzx.TbQwJmxzSearchDto;
import com.mosty.base.model.query.sjzx.XfbbQuery;
import com.mosty.base.model.query.sjzx.XfbbTjQuery;
import com.mosty.base.model.query.sjzx.XftjQuery;
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.qwzx.TbQwXfbb;
import com.mosty.base.model.entity.qwzx.TbQwXfpbZq;
import com.mosty.base.model.query.qwzx.TbQwXfbbJmxzQuery;
import com.mosty.base.model.query.qwzx.TbQwXfbbQuery;
import com.mosty.qwzx.service.TbQwXfbbService;
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 java.util.List;
import java.util.Map;

/**
 * @author zengbo
 * @since 2022-06-27
 * 巡防报备表 前端控制器
 */
@Api(tags = "巡防报备接口")
@AllArgsConstructor
@RestController
@RequestMapping("/tbQwXfbb")
public class TbQwXfbbController {

    @Resource
    private TbQwXfbbService tbQwXfbbService;

    @ApiOperation("通过ID查询单条数据")
    @JwtSysUser
    @GetMapping("{id}")
    @Log(title = "巡防报备数据", businessType = BusinessType.OTHER)
    @ApiImplicitParam(name = "id", value = "报备ID", paramType = "path", required = true, dataType = "String")
    public ResponseResult<TbQwXfbbVo> queryById(@PathVariable String id) {
        return ResponseResult.success(tbQwXfbbService.selectById(id));
    }

    @ApiOperation("通过ID查询单条数据")
    @JwtSysUser
    @GetMapping("getBbxxInfo")
    public ResponseResult<TbQwXfbb> getBbxxInfo(String id) {
        return ResponseResult.success(tbQwXfbbService.getBbxxInfo(id));
    }

    @ApiOperation("分页查询")
    @JwtSysUser
    @GetMapping
    public ResponseResult<IPage<TbQwXfbbVo>> paginQuery(TbQwXfbbQuery tbQwXfbbQuery) {
        return ResponseResult.success(tbQwXfbbService.queryPage(tbQwXfbbQuery));
    }

    @ApiOperation("新增数据")
    @JwtSysUser
    @PostMapping
    @Log(title = "巡防报备新增", businessType = BusinessType.INSERT)
    public ResponseResult<String> add(@RequestBody TbQwXfbbVo xfbb) {
        return ResponseResult.success(tbQwXfbbService.addXfbb(xfbb));
    }

    @ApiOperation("通过主键删除数据")
    @DeleteMapping("{id}")
    @Log(title = "巡防报备删除", businessType = BusinessType.UPDATE)
    @ApiImplicitParam(name = "id", value = "标签主键", paramType = "path", required = true, dataType = "String")
    public ResponseResult<Boolean> deleteById(@PathVariable("id") String id) {
        return ResponseResult.success(tbQwXfbbService.deleteById(id));
    }

    @ApiOperation("通过主键删除数据")
    @DeleteMapping("/bacth")
    @Log(title = "巡防报备删除", businessType = BusinessType.UPDATE)
    @ApiImplicitParam(name = "id", value = "标签主键", paramType = "path", required = true, dataType = "String")
    public ResponseResult<Boolean> deleteByIds(@RequestParam List<String> id) {
        return ResponseResult.success(tbQwXfbbService.deleteBatch(id));
    }

    @ApiOperation("查询街面巡组,力量,时长,里程")
    @GetMapping("/selectDeck")
    @JwtSysUser
    public ResponseResult<Map<String, Integer>> selectDeck() {
        return ResponseResult.success(tbQwXfbbService.selectDeck());
    }

    @ApiOperation("大屏-计划街面巡组列表-分页")
    @GetMapping("/selectJhjmxzList")
    @JwtSysUser
    public ResponseResult<IPage<TbQwXfpbZq>> selectJhjmxzList(TbQwXzSearchDto dto) {
        return ResponseResult.success(tbQwXfbbService.selectJhjmxzList(dto));
    }

    @ApiOperation("大屏-实际街面巡组列表-分页")
    @GetMapping("/selectSjjmxzList")
    @JwtSysUser
    public ResponseResult<IPage<TbQwXfbb>> selectSjjmxzList(TbQwXzSearchDto dto) {
        return ResponseResult.success(tbQwXfbbService.selectSjjmxzList(dto));
    }

    @ApiOperation("大屏-街面力量-分页")
    @GetMapping("/selectJmllList")
    @JwtSysUser
    public ResponseResult<IPage<TbQwJl>> selectJmllList(TbQwJmllSearchDto dto) {
        return ResponseResult.success(tbQwXfbbService.selectJmllList(dto));
    }

    @ApiOperation("大屏-查询街面巡组列表,附近警组")
    @GetMapping("/selectDeckList")
    @JwtSysUser
    public ResponseResult<IPage<TbQwXfbb>> selectDeckList(TbQwXfbbJmxzQuery dto) {
        return ResponseResult.success(tbQwXfbbService.selectDeckList(dto));
    }

    @ApiOperation("查询巡组信息第三方")
    @GetMapping("/other/selectDeckList")
    @JwtSysUser
    public ResponseResult<IPage<TbQwXfbb>> selectDeckListOther(TbQwXfbbJmxzQuery dto) {
        return ResponseResult.success(tbQwXfbbService.selectDeckListOther(dto));
    }

    @ApiOperation("查询街面巡组")
    @GetMapping("/selectJmxz")
    @JwtSysUser
    public ResponseResult<IPage<TbQwXfbb>> selectJmxz(TbQwJmxzSearchDto dto) {
        return ResponseResult.success(tbQwXfbbService.selectJmxz(dto));
    }

    @ApiOperation("大屏-巡组气泡-查询周边巡组")
    @PostMapping("/selectNearbyDeck")
    @Log(title = "大屏-巡组气泡-查询周边巡组", businessType = BusinessType.OTHER)
    public ResponseResult<List<TbQwXfbb>> selectNearbyDeck(@RequestBody TbQwXfbb tbQwXfbb) {
        return ResponseResult.success(tbQwXfbbService.selectNearbyDeck(tbQwXfbb));
    }

    @ApiOperation("开始、结束报备")
    @PostMapping("/startOrEndBb")
    @JwtSysUser
    @Log(title = "开始、结束报备", businessType = BusinessType.UPDATE)
    public ResponseResult<Integer> startOrEndBb(@RequestBody TbQwXfbbStartOrEndBbDto dto) {
        return ResponseResult.success(tbQwXfbbService.startOrEndBb(dto));
    }

    @ApiOperation("查询我今天的报备new")
    @GetMapping("/getMybbTodayNew")
    @JwtSysUser
    public ResponseResult<TbQwXfbb> getMybbTodayNew(String bblx) {
        return ResponseResult.success(tbQwXfbbService.getMybbTodayNew(bblx));
    }

    @ApiOperation("判断派出所、巡防区范围内是否有巡组")
    @GetMapping("/getFjbbByYsId")
    @JwtSysUser
    public ResponseResult<List<TbQwXfbb>> getFjbbByYsId(String ysid) {
        return ResponseResult.success(tbQwXfbbService.getFjbbByYsId(ysid));
    }

    @ApiOperation("根据身份证号获取最后一次报备的数据 进行显示")
    @GetMapping("/getMybbLastBySfzh")
    @JwtSysUser
    public ResponseResult<TbQwXfbb> getMybbLastBySfzh(String sfzh) {
        return ResponseResult.success(tbQwXfbbService.getMybbLastBySfzh(sfzh));
    }

    @ApiOperation("自动结束报备")
    @GetMapping("/authJsbb")
    @JwtSysUser
    public ResponseResult<Void> authJsbb() {
        tbQwXfbbService.authJsbb();
        return ResponseResult.success();
    }

    @ApiOperation("根据报备ID查询巡组下的人员列表")
    @GetMapping("/getJlxxByBbid/{id}")
    public ResponseResult<List<TbQwJlDto>> getJlxxByBbid(@PathVariable("id") String id) {
        return ResponseResult.success(tbQwXfbbService.getJlxxByBbid(id));
    }


    @ApiOperation("查询范围内的最近的巡组信息")
    @PostMapping("/getBbxxByJi")
    public ResponseResult<TbQwXfbb> getBbxxByJi(@RequestBody TbQwXfbbQueryByJlDto dto) {
        return ResponseResult.success(tbQwXfbbService.getBbxxByJi(dto));
    }

    @ApiOperation("app查询界面警力民警辅警数量")
    @GetMapping("/selectMfjCount")
    @JwtSysUser
    @ApiImplicitParam(name = "bbrq", value = "查询日期", required = true, dataType = "String")
    public ResponseResult<Map<String, Object>> selectMfjCount(String bbrq) {
        return ResponseResult.success(tbQwXfbbService.selectMfjCount(bbrq));
    }

    @ApiOperation("根据设备ID查询该设备所在的巡组")
    @PostMapping("/getBbList/{sbid}")
    @JwtSysUser
    @ApiImplicitParam(name = "sbid", value = "设备ID", required = true, dataType = "String")
    public ResponseResult<List<TbQwXfbb>> getBbList(@PathVariable("sbid") String sbid) {
        return ResponseResult.success(tbQwXfbbService.getBbList(sbid));
    }

    @ApiOperation("根据设备ID查询该设备所在的巡组")
    @PostMapping("/getClBbList/{gpsId}")
    @JwtSysUser
    @ApiImplicitParam(name = "pgsId", value = "车辆gpsiID", required = true, dataType = "String")
    public ResponseResult<List<TbQwXfbb>> getClBbList(@PathVariable("gpsId") String gpsId) {
        return ResponseResult.success(tbQwXfbbService.getClBbList(gpsId));
    }

    @ApiOperation("新增巡防报备打卡")
    @PostMapping("/addXfbbDk")
    @JwtSysUser
    @Log(title = "新增巡防报备打卡", businessType = BusinessType.INSERT)
    public ResponseResult<Void> addXfbbDk(@RequestBody TbQwXfbbDkDto dto) {
        tbQwXfbbService.addXfbbDk(dto);
        return ResponseResult.success();
    }

    @ApiOperation("判断当前位置是否再报备的巡防区内")
    @PostMapping("/isDdWz")
    @JwtSysUser
    public ResponseResult<Boolean> isDdWz(@RequestBody TbQwXfbbDkWzDto dto) {
        return ResponseResult.success(tbQwXfbbService.isDdWz(dto));
    }

    @ApiOperation("高新领导段-查询街面警力数量")
    @PostMapping("/getJmjlCount")
    @JwtSysUser
    public ResponseResult<Map<String, Object>> getJmjlCount() {
        return ResponseResult.success(tbQwXfbbService.getJmjlCount());
    }

    // 泸州态势统计-各区县巡防时长和里程
    @ApiOperation("泸州态势统计-各区县巡防时长和里程")
    @PostMapping("/getXfscAndLc")
    @JwtSysUser
    public ResponseResult<Map<String, Object>> getXfscAndLcTj(XfbbQuery dto) {
        return ResponseResult.success(tbQwXfbbService.getXfscAndLc(dto));
    }

    // 查询部门的报备的数量
    @ApiOperation("查询部门的报备的数量")
    @PostMapping("/getBbCount")
    @JwtSysUser
    public ResponseResult<Integer> getBbCount(@RequestParam("ssbmdm") String ssbmdm,
                                              @RequestParam("time") String time) {
        return ResponseResult.success(tbQwXfbbService.getBbCount(ssbmdm, time));
    }

    // 查询部门时长、里程
    @ApiOperation("查询部门时长、里程")
    @PostMapping("/getScLc")
    @JwtSysUser
    public ResponseResult<Map<String, Integer>> getScLc(@RequestParam("ssbmdm") String ssbmdm,
                                                        @RequestParam("time") String time) {
        return ResponseResult.success(tbQwXfbbService.getScLc(ssbmdm, time));
    }

    // 查询部门的报备的数量
    @ApiOperation("修改巡逻状态数据")
    @PostMapping("/updateXfzt")
    @JwtSysUser
    @Log(title = "修改巡逻状态数据", businessType = BusinessType.UPDATE)
    public ResponseResult<Void> updateXfzt() {
        tbQwXfbbService.updateXfzt();
        return ResponseResult.success();
    }

    // 大屏巡防报备统计
    @ApiOperation("大屏巡防报备统计")
    @PostMapping("/xfbbTj")
    @JwtSysUser
    public ResponseResult<Map<String, Integer>> xfbbTj() {
        return ResponseResult.success(tbQwXfbbService.xfbbTj());
    }

    // 部门统计
    @ApiOperation("部门统计")
    @PostMapping("/bmtj")
    @JwtSysUser
    @Log(title = "部门统计", businessType = BusinessType.OTHER)
    public ResponseResult<IPage<Object>> bmtj(@RequestBody XfbbTjQuery query) {
        return ResponseResult.success(tbQwXfbbService.bmtj(query));
    }

    @ApiOperation("部门统计All")
    @PostMapping("/bmtjAll")
    @JwtSysUser
    @Log(title = "部门统计All", businessType = BusinessType.OTHER)
    public ResponseResult<Object> bmtjAll(@RequestBody XfbbTjQuery query) {
        return ResponseResult.success(tbQwXfbbService.bmtjAll(query));
    }

    @ApiOperation("巡区统计")
    @PostMapping("/xqtj")
    @JwtSysUser
    @Log(title = "巡区统计", businessType = BusinessType.OTHER)
    public ResponseResult<IPage<Object>> xqtj(@RequestBody XfbbTjQuery query) {
        return ResponseResult.success(tbQwXfbbService.xqtj(query));
    }


    @ApiOperation("个人统计")
    @PostMapping("/grtj")
    @JwtSysUser
    @Log(title = "个人统计", businessType = BusinessType.OTHER)
    public ResponseResult<IPage<Object>> grtj(@RequestBody XfbbTjQuery query) {
        return ResponseResult.success(tbQwXfbbService.grtj(query));
    }


    @ApiOperation("根据巡区获取报备id")
    @GetMapping("/getBbidByXq")
    @JwtSysUser
    public ResponseResult<List<TbQwXfbb>> getBbidByXq(String xqid) {
        return ResponseResult.success(tbQwXfbbService.getBbidByXq(xqid));
    }

    @ApiOperation("删除reidsxfwz")
    @GetMapping("/delRedisXfwz")
    @JwtSysUser
    public ResponseResult<Void> delRedisXfwz() {
        tbQwXfbbService.delRedisXfwz();
        return ResponseResult.success();
    }

    @ApiOperation("更新巡防里程")
    @GetMapping("/updateXflc")
    @JwtSysUser
    public ResponseResult<Integer> updateXflc(String bbid) {
        return ResponseResult.success(tbQwXfbbService.updateXflc(bbid));
    }

}

