package com.mosty.qwzx.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.mosty.base.model.dto.qwzx.TbQwZbpbZqDto;
import com.mosty.base.model.entity.qwzx.TbQwZbpbZq;
import com.mosty.base.model.vo.qwzx.TbQwXfpbZqMyVo;
import com.mosty.base.model.vo.qwzx.TbQwZbpbZqMyVo;
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.TbQwZbpbInsertOrUpdateDto;
import com.mosty.base.model.query.qwzx.TbQwZbpbQuery;
import com.mosty.base.model.query.qwzx.TbQwZbpbSearchMyQuery;
import com.mosty.qwzx.service.TbQwZbpbService;
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 dw
 * @since 2022/8/3
 **/
@Api(tags = "值班排班相关接口（新）")
@RestController
@AllArgsConstructor
@RequestMapping("/tbQwZbpb")
public class TbQwZbpbController {

    @Resource
    private TbQwZbpbService tbQwZbpbService;

    @ApiOperation("新增值班排班信息")
    @JwtSysUser
    @PostMapping
    @Log(title = "新增值班排班信息", businessType = BusinessType.INSERT)
    public ResponseResult<Integer> addEntity(@RequestBody TbQwZbpbInsertOrUpdateDto dto) {
        return ResponseResult.success(this.tbQwZbpbService.addEntity(dto));
    }

    @ApiOperation("修改值班排班信息")
    @JwtSysUser
    @PutMapping
    @Log(title = "修改值班排班信息", businessType = BusinessType.UPDATE)
    public ResponseResult<Integer> updateEntity(@RequestBody TbQwZbpbInsertOrUpdateDto dto) {
        return ResponseResult.success(this.tbQwZbpbService.updateEntity(dto));
    }

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

    @ApiOperation("删除单条值班排班信息")
    @JwtSysUser
    @DeleteMapping("{id}")
    @Log(title = "删除单条值班排班信息", businessType = BusinessType.DELETE)
    public ResponseResult<Void> deleteEntity(@PathVariable("id") String id) {
        this.tbQwZbpbService.deleteEntity(id);
        return ResponseResult.success();
    }

    @ApiOperation("查询值班排班列表信息--分页")
    @JwtSysUser
    @GetMapping
    public ResponseResult<IPage<TbQwZbpbInsertOrUpdateDto>> selectPage(TbQwZbpbQuery dto) {
        return ResponseResult.success(this.tbQwZbpbService.selectPage(dto));
    }

    @ApiOperation("查询值班排班详情信息")
    @JwtSysUser
    @GetMapping("{id}")
    public ResponseResult<TbQwZbpbInsertOrUpdateDto> getInfo(@PathVariable("id") String id) {
        return ResponseResult.success(this.tbQwZbpbService.getInfo(id));
    }

    @ApiOperation("分页查询我的值班排班")
    @JwtSysUser
    @GetMapping("getMyZbpb")
    public ResponseResult<IPage<TbQwZbpbInsertOrUpdateDto>> getMyZbpb(TbQwZbpbSearchMyQuery dto) {
        return ResponseResult.success(this.tbQwZbpbService.getMyZbpb(dto));
    }

    @ApiOperation("查询当前时间的值班排班情况，发送定时任务(定时任务)")
    @JwtSysUser
    @GetMapping("checkThisTimeZbpb")
    public ResponseResult<Void> checkThisTimeZbpb() {
        this.tbQwZbpbService.checkThisTimeZbpb();
        return ResponseResult.success();
    }

    @ApiOperation("APP获取我的值班排班信息")
    @JwtSysUser
    @GetMapping("getMyZbpbToday")
    public ResponseResult<TbQwZbpbZqMyVo> getMyZbpbToday() {
        return ResponseResult.success(this.tbQwZbpbService.getMyZbpbToday());
    }

    @ApiOperation("根据周期ID查询周期详细信息")
    @GetMapping("/getZbpbZqInfo/{id}")
    public ResponseResult<TbQwZbpbZqDto> getZbpbZqInfo(@PathVariable("id") String id) {
        return ResponseResult.success(this.tbQwZbpbService.getZbpbZqInfo(id));
    }

    @ApiOperation("根据月份导出值班排班表情况")
    @JwtSysUser
    @GetMapping("exportData")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "time", value = "月份yyyy-MM", required = true, dataType="String"),
            @ApiImplicitParam(name = "pbid", value = "排班ID", required = true, dataType="String")
    })
    public ResponseResult<List<Map<String,Object>>> exportData(String time,String pbid) {
        return ResponseResult.success(this.tbQwZbpbService.exportData(time,pbid));
    }

    @ApiOperation("查询部门月排班情况")
    @JwtSysUser
    @GetMapping("getDeptByMonth")
    @ApiImplicitParams({
       @ApiImplicitParam(name = "time", value = "月份yyyy-MM", required = true, dataType="String")
    })
    public ResponseResult<List<Map<String,Object>>> getDeptByMonth(String time) {
        return ResponseResult.success(this.tbQwZbpbService.getDeptByMonth(time));
    }

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