package com.mosty.rwzx.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.mosty.base.model.dto.rwzx.*;
import com.mosty.base.model.entity.rwzx.TbRwTask;
import com.mosty.base.model.entity.rwzx.TbRwTaskUser;
import com.mosty.base.model.entity.rwzx.TbRwTaskUserAll;
import com.mosty.base.model.entity.yjzl.TbZlxx;
import com.mosty.base.model.query.rwzx.*;
import com.mosty.base.model.vo.rwzx.*;
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.rwzx.service.TbRwTaskInnerService;
import com.mosty.rwzx.service.TbRwTaskService;
import io.swagger.annotations.Api;
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/9/19
 **/
@Api(tags = "任务中心相关接口--内部接口")
@RestController
@AllArgsConstructor
@RequestMapping("/tbRwTask/inner")
public class TbRwTaskInnerController {

    private final TbRwTaskInnerService tbRwTaskInnerService;
    private final TbRwTaskService tbRwTaskService;

    @ApiOperation("添加任务信息")
    @JwtSysUser
    @PostMapping("addRw")
    @Log(title = "添加任务信息", businessType = BusinessType.INSERT)
    public ResponseResult<Integer> addRw(@RequestBody TbRwTaskInnerDto dto) {
        return ResponseResult.success(this.tbRwTaskInnerService.addRw(dto));
    }

    @ApiOperation("查询任务列表")
    @JwtSysUser
    @GetMapping("selectPage")
    public ResponseResult<IPage<TbRwTaskVo>> selectPage(TbRwTaskInnerQuery dto) {
        return ResponseResult.success(this.tbRwTaskInnerService.selectPage(dto));
    }

    @ApiOperation("APP统计我的任务数量")
    @JwtSysUser
    @GetMapping("myRwCount")
    public ResponseResult<List<Map<String, Object>>> myRwCount() {
        return ResponseResult.success(this.tbRwTaskInnerService.myRwCount());
    }

    @ApiOperation("APP统计任务列表的数量")
    @JwtSysUser
    @GetMapping("rwCountByState")
    public ResponseResult<List<Map<String, Object>>> rwCountByState(TbRwTaskInnerQuery dto) {
        return ResponseResult.success(this.tbRwTaskInnerService.rwCountByState(dto));
    }

    @ApiOperation("查询我的任务列表")
    @JwtSysUser
    @GetMapping("selectMyPage")
    public ResponseResult<IPage<TbRwTaskUser>> selectMyPage(TbRwTaskMyInnerQuery dto) {
        return ResponseResult.success(this.tbRwTaskInnerService.selectMyPage(dto));
    }

    @ApiOperation("通过任务Id查询任务详情信息")
    @JwtSysUser
    @GetMapping("getTaskInfo/{id}")
    public ResponseResult<TbRwTaskVo> getTaskInfo(@PathVariable("id") String id) {
        return ResponseResult.success(this.tbRwTaskService.getTaskInfo(id));
    }

    @ApiOperation("查询任务是否是登录人的任务")
    @JwtSysUser
    @GetMapping("checkMyTask/{id}")
    public ResponseResult<Boolean> checkMyTask(@PathVariable("id") String id) {
        return ResponseResult.success(this.tbRwTaskService.checkMyTask(id));
    }

    @ApiOperation("查询任务接收人列表")
    @JwtSysUser
    @GetMapping("getTaskUserList")
    public ResponseResult<IPage<TbRwTaskUserVo>> getTaskUserList(TbRwTaskUserQuery dto) {
        return ResponseResult.success(this.tbRwTaskService.getTaskUserList(dto));
    }

    @ApiOperation("查询任务日志列表")
    @JwtSysUser
    @GetMapping("getTaskLogList")
    public ResponseResult<IPage<TbRwTaskLogVo>> getTaskLogList(TbRwTaskLogQuery dto) {
        return ResponseResult.success(this.tbRwTaskService.getTaskLogList(dto));
    }

    @ApiOperation("修改个人任务状态")
    @JwtSysUser
    @PostMapping("changeGrrwState")
    @Log(title = "修改个人任务状态", businessType = BusinessType.UPDATE)
    public ResponseResult<Void> changeGrrwState(@RequestBody TbRwTaskGrChangeStateInnerDto dto) {
        this.tbRwTaskInnerService.changeGrrwState(dto);
        return ResponseResult.success();
    }

    @ApiOperation("根据任务ID修改任务状态")
    @JwtSysUser
    @PostMapping("changeRwState")
    @Log(title = "修改任务状态", businessType = BusinessType.UPDATE)
    public ResponseResult<Void> changeRwState(@RequestBody TbRwTaskChangeStateInnerDto dto) {
        this.tbRwTaskInnerService.changeRwState(dto);
        return ResponseResult.success();
    }

    @ApiOperation("根据业务ID和业务类型修改任务状态")
    @JwtSysUser
    @PostMapping("changeStateByYwid")
    @Log(title = "根据业务ID和业务类型修改任务状态", businessType = BusinessType.UPDATE)
    public ResponseResult<Void> changeStateByYwid(@RequestBody TbRwTaskChangeStateByYwidDto dto) {
        this.tbRwTaskInnerService.changeStateByYwid(dto);
        return ResponseResult.success();
    }

    @ApiOperation("任务中心首页数量统计接口")
    @JwtSysUser
    @GetMapping("getDataStatistics")
    public ResponseResult<TbRwTaskStatisticsVo> getDataStatistics(TbRwTaskStatisticsDto dto) {
        return ResponseResult.success(this.tbRwTaskService.getDataStatistics(dto));
    }

    @ApiOperation("任务中心首页任务类型数量统计接口")
    @JwtSysUser
    @GetMapping("getRWLXDataStatistics")
    @Log(title = "任务中心首页任务类型数量统计接口", businessType = BusinessType.OTHER)
    public ResponseResult<List<TbRwTaskLXStatisticsVo>> getRWLXDataStatistics(TbRwTaskStatisticsDto dto) {
        return ResponseResult.success(this.tbRwTaskService.getRWLXDataStatistics(dto));
    }

    @ApiOperation("任务中心首页人员任务完成情况排名接口")
    @JwtSysUser
    @GetMapping("getTaskRanking")
    public ResponseResult<List<TbRwTaskRankingVo>> getTaskRanking(TbRwTaskStatisticsDto dto) {
        return ResponseResult.success(this.tbRwTaskService.getTaskRanking(dto));
    }

    @ApiOperation("任务中心首页部门任务完成情况排名接口")
    @JwtSysUser
    @GetMapping("getTaskByDept")
    public ResponseResult<List<TbRwTaskRankingVo>> getTaskByDept() {
        return ResponseResult.success(this.tbRwTaskService.getTaskByDept());
    }

    @ApiOperation("根据任务类型和业务Id查询任务是否存在")
    @JwtSysUser
    @PostMapping("getRwByYwid")
    public ResponseResult<TbRwTask> getRwByYwid(@RequestBody TbRwTaskByYwidQuery dto) {
        return ResponseResult.success(this.tbRwTaskService.getRwByYwid(dto));
    }

    @ApiOperation("检查任务是否过期")
    @JwtSysUser
    @PostMapping("changeState")
    public ResponseResult<Void> changeState() {
        this.tbRwTaskService.changeState();
        return ResponseResult.success();
    }

    @ApiOperation("修改指令任务状态为未完成")
    @JwtSysUser
    @PostMapping("changeTaskStateByZlid")
    public ResponseResult<Void> changeTaskStateByZlid(@RequestBody TbZlxx zl) {
        this.tbRwTaskService.changeTaskStateByZlid(zl);
        return ResponseResult.success();
    }

    @ApiOperation("查询登录用户的已处理的任务数量")
    @JwtSysUser
    @GetMapping("getYclTask")
    public ResponseResult<Integer> getYclTask() {
        return ResponseResult.success(this.tbRwTaskService.getYclTask());
    }

    @ApiOperation("查询登录用户的已处理的任务列表")
    @JwtSysUser
    @PostMapping("getYclTaskList")
    public ResponseResult<IPage<TbRwTaskUserAll>> getYclTaskList(@RequestBody TbRwTaskMyInnerQuery dto) {
        return ResponseResult.success(this.tbRwTaskService.getYclTaskList(dto));
    }

    @ApiOperation("查询是否有新的任务")
    @JwtSysUser
    @GetMapping("checkHasNewTask")
    public ResponseResult<Boolean> checkHasNewTask(String sfzh) {
        return ResponseResult.success(this.tbRwTaskService.checkHasNewTask(sfzh));
    }
}
