package com.mosty.qwzx.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.mosty.base.model.dto.qwzx.TbQwXfpbZqDto;
import com.mosty.base.model.entity.qwzx.TbQwZbpbZq;
import com.mosty.base.model.vo.qwzx.TbQwXfpbZqMyVo;
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.dto.qwzx.TbQwXfpbAddAndEditDto;
import com.mosty.base.model.dto.qwzx.TbQwXzSearchDto;
import com.mosty.base.model.entity.qwzx.TbQwXfpbZq;
import com.mosty.base.model.query.qwzx.TbQwXfpbQuery;
import com.mosty.base.model.query.qwzx.TbQwXfpbSearchMyQuery;
import com.mosty.base.model.vo.qwzx.TbQwXfpbZqVo;
import com.mosty.qwzx.service.TbQwXfpbService;
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 java.util.List;
import java.util.Map;

/**
 * @author dw
 * @since 2022/8/3
 **/
@Api(tags = "巡防排班接口")
@AllArgsConstructor
@RestController
@RequestMapping("/tbQwXfpb")
public class TbQwXfpbController {

    private TbQwXfpbService tbQwXfpbService;

    @ApiOperation("巡防排班新增")
    @JwtSysUser
    @PostMapping
    @Log(title = "巡防排班新增", businessType = BusinessType.INSERT)
    public ResponseResult<Integer> addEntity(@RequestBody TbQwXfpbAddAndEditDto dto) {
        return ResponseResult.success(this.tbQwXfpbService.addEntity(dto));
    }

    @ApiOperation("巡防排班修改")
    @JwtSysUser
    @PutMapping
    @Log(title = "巡防排班修改", businessType = BusinessType.UPDATE)
    public ResponseResult<Integer> editEntity(@RequestBody TbQwXfpbAddAndEditDto dto) {
        return ResponseResult.success(this.tbQwXfpbService.editEntity(dto));
    }

    @ApiOperation("删除单条巡防排班")
    @JwtSysUser
    @DeleteMapping("{id}")
    @Log(title = "删除单条巡防排班", businessType = BusinessType.DELETE)
    public ResponseResult<Integer> delEntity(@PathVariable("id") String id) {
        return ResponseResult.success(this.tbQwXfpbService.delEntity(id));
    }

    @ApiOperation("批量删除巡防排班")
    @JwtSysUser
    @DeleteMapping
    @Log(title = "批量删除巡防排班", businessType = BusinessType.DELETE)
    public ResponseResult<Void> delBatch(@RequestBody List<String> ids) {
        this.tbQwXfpbService.delBatch(ids);
        return ResponseResult.success();
    }

    @ApiOperation("分页查询巡防排班")
    @JwtSysUser
    @GetMapping
    public ResponseResult<IPage<TbQwXfpbAddAndEditDto>> getPageList(TbQwXfpbQuery dto) {
        return ResponseResult.success(this.tbQwXfpbService.getPageList(dto));
    }

    @ApiOperation("查询巡防排班详细信息")
    @JwtSysUser
    @GetMapping("{id}")
    public ResponseResult<TbQwXfpbAddAndEditDto> getInfo(@PathVariable("id") String id) {
        return ResponseResult.success(this.tbQwXfpbService.getInfo(id));
    }

    @ApiOperation("分页查询我的巡防排班")
    @JwtSysUser
    @GetMapping("getMyXfpb")
    public ResponseResult<IPage<TbQwXfpbAddAndEditDto>> getMyXfpb(TbQwXfpbSearchMyQuery dto) {
        return ResponseResult.success(this.tbQwXfpbService.getMyXfpb(dto));
    }

    @ApiOperation("APP获取我的排班信息")
    @JwtSysUser
    @GetMapping("getMyXfpbToday")
    public ResponseResult<TbQwXfpbZqMyVo> getMyXfpbToday() {
        return ResponseResult.success(this.tbQwXfpbService.getMyXfpbToday());
    }

    @ApiOperation("查询本月的巡防排班信息")
    @JwtSysUser
    @GetMapping("getThisMonthPbList")
    public ResponseResult<IPage<TbQwXfpbZqVo>> getThisMonthPbList(TbQwXzSearchDto dto) {
        return ResponseResult.success(this.tbQwXfpbService.getThisMonthPbList(dto));
    }

    @ApiOperation("查询当前时间的巡防排班情况，发送消息提醒报备（定时任务）")
    @JwtSysUser
    @GetMapping("checkThisTimeXfpb")
    public ResponseResult<IPage<TbQwXfpbZqVo>> checkThisTimeXfpb() {
        this.tbQwXfpbService.checkThisTimeXfpb();
        return ResponseResult.success();
    }

    @ApiOperation("根据周期Id查询排班信息")
    @JwtSysUser
    @GetMapping("getPbZq")
    public ResponseResult<TbQwXfpbZqMyVo> getPbZq(String id, String time) {
        return ResponseResult.success(this.tbQwXfpbService.getPbZq(id, time));
    }

    @ApiOperation("每月一日添加本月的每日警力（定时任务）")
    @JwtSysUser
    @GetMapping("addMrjl")
    public ResponseResult<Void> addMrjl() {
        this.tbQwXfpbService.addMrjl();
        return ResponseResult.success();
    }

    @ApiOperation("根据时间查询月份排班、报备情况")
    @JwtSysUser
    @GetMapping("getPbbbByMonth")
    public ResponseResult<List<Map<String, Object>>> getPbbbByMonth(String time) {
        return ResponseResult.success(this.tbQwXfpbService.getPbbbByMonth(time));
    }

    @ApiOperation("根据时间部门月份巡防排班、巡防报备情况")
    @JwtSysUser
    @GetMapping("getXfbbByMonth")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "time", value = "月份yyyy-MM", required = true, dataType = "String")
    })
    public ResponseResult<List<Map<String, Object>>> getXfbbByMonth(String time) {
        return ResponseResult.success(this.tbQwXfpbService.getXfbbByMonth(time));
    }


    @ApiOperation("根据时间查询部门月份排班、报备情况")
    @JwtSysUser
    @GetMapping("getPbbbByMonthBm")
    public ResponseResult<List<Map<String, Object>>> getPbbbByMonthBm(String time,String ssbmdm) {
        return ResponseResult.success(this.tbQwXfpbService.getPbbbByMonthBm(time, ssbmdm));
    }

}

