package com.mosty.qwzx.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.mosty.base.model.dto.qwzx.TbQwXfbbStartOrEndBbDto;
import com.mosty.base.model.dto.qwzx.TbQwZbpbZqDto;
import com.mosty.base.model.entity.qwzx.TbQwXfbb;
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.TbQwZbbb;
import com.mosty.base.model.query.qwzx.TbQwZbbbQuery;
import com.mosty.base.model.vo.qwzx.TbQwZbbbVo;
import com.mosty.qwzx.service.TbQwZbbbService;
import io.swagger.annotations.*;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

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

/**
 * @author dw
 * @since 2022-10-09
 */
@Api(tags = "值班报备接口")
@AllArgsConstructor
@RestController
@RequestMapping("/tbQwZbbb")
public class TbQwZbbbController {

    public static final String 根据时间部门查询警力情况 = "根据时间部门查询警力情况";
    private final TbQwZbbbService tbQwZbbbService;

    @ApiOperation("值班报备新增")
    @JwtSysUser
    @PostMapping
    @Log(title = "值班报备新增", businessType = BusinessType.INSERT)
    public ResponseResult<String> add(@RequestBody TbQwZbbbVo zb) {
        return ResponseResult.success(tbQwZbbbService.addQwzb(zb));
    }

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

    @ApiOperation("分页查询值班报备列表")
    @JwtSysUser
    @GetMapping
    public ResponseResult<IPage<TbQwZbbbVo>> paginQuery(TbQwZbbbQuery dto) {
        return ResponseResult.success(tbQwZbbbService.queryPage(dto));
    }

    @ApiOperation("值班报备批量删除")
    @DeleteMapping("/batch")
    @JwtSysUser
    @Log(title = "值班报备批量删除", businessType = BusinessType.DELETE)
    public ResponseResult<Boolean> deleteByIds(@RequestParam List<String> ids) {
        return ResponseResult.success(tbQwZbbbService.deleteBatch(ids));
    }

    @ApiOperation("APP获取我当前的报备信息")
    @GetMapping("/getMyBbInfoToday")
    @JwtSysUser
    public ResponseResult<TbQwZbbb> getMyBbInfoToday() {
        return ResponseResult.success(tbQwZbbbService.getMyBbInfoToday());
    }

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

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

    @ApiOperation("APP根据时间统计报备数量")
    @PostMapping("/getBbCountByDept")
    @JwtSysUser
    @ApiImplicitParam(name = "time", value = "查询日期", required = true, dataType = "String")
    public ResponseResult<Map<String,Object>> getBbCountByDept(String time) {
        return ResponseResult.success(this.tbQwZbbbService.getBbCountByDept(time));
    }

    @ApiOperation("APP根据时间统计报备列表")
    @PostMapping("/getBbListByDept")
    @JwtSysUser
    @ApiImplicitParam(name = "time", value = "查询日期", required = true, dataType = "String")
    public ResponseResult<List<Map<String,Object>>> getBbListByDept(String time) {
        return ResponseResult.success(this.tbQwZbbbService.getBbListByDept(time));
    }

    @ApiOperation("查询值班领导")
    @PostMapping("/getZbld")
    @JwtSysUser
    public ResponseResult<Map<String,Object>> getZbld() {
        return ResponseResult.success(this.tbQwZbbbService.getZbld());
    }


    @ApiOperation("根据时间部门查询警力情况")
    @GetMapping("getJlByBm")
    @JwtSysUser
    public ResponseResult<Map<String,Object>> getJlByBm(String time, String ssbmdm) {
        return ResponseResult.success(this.tbQwZbbbService.getJlByBm(time,ssbmdm));
    }

}

