package ink.wgink.module.activiti.controller.app.api.oa;

import ink.wgink.common.base.DefaultBaseController;
import ink.wgink.interfaces.consts.ISystemConstant;
import ink.wgink.module.activiti.pojo.dtos.oa.*;
import ink.wgink.module.activiti.service.oa.IOaCcService;
import ink.wgink.module.activiti.service.oa.IOaService;
import ink.wgink.pojo.ListPage;
import ink.wgink.pojo.result.ErrorResult;
import ink.wgink.pojo.result.SuccessResultData;
import ink.wgink.pojo.result.SuccessResultList;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

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

/**
 * @ClassName: OaController
 * @Description: Oa管理
 * @Author: wanggeng
 * @Date: 2022/3/23 09:54
 * @Version: 1.0
 */
@Api(tags = ISystemConstant.API_TAGS_APP_PREFIX + "oa管理")
@RestController
@RequestMapping(ISystemConstant.APP_PREFIX + "/oa")
public class OaAppController extends DefaultBaseController {

    @Autowired
    private IOaService oaService;
    @Autowired
    private IOaCcService oaCcService;

    @ApiOperation(value = "流程定义分页列表", notes = "流程定义分页列表接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "token", paramType = "header"),
            @ApiImplicitParam(name = "page", value = "当前页码", paramType = "query", dataType = "int", defaultValue = "1"),
            @ApiImplicitParam(name = "rows", value = "显示数量", paramType = "query", dataType = "int", defaultValue = "20"),
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @GetMapping("listpage-procdef")
    public SuccessResultList<List<OaProcdefDTO>> listPageProcdef(@RequestHeader("token") String token, ListPage page) {
        return oaService.listPageProcdef(page.getPage(), page.getRows());
    }

    @ApiOperation(value = "我的任务（待办）列表", notes = "我的任务（待办）列表接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "token", paramType = "header"),
    })
    @GetMapping("list-task-of-mine")
    public List<OaTaskDTO> listTaskOfMine(@RequestHeader("token") String token) {
        return oaService.listTaskOfMine(token);
    }


    @ApiOperation(value = "我的任务（待办）分页列表", notes = "我的任务（待办）分页列表接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "token", paramType = "header"),
            @ApiImplicitParam(name = "page", value = "当前页码", paramType = "query", dataType = "int", defaultValue = "1"),
            @ApiImplicitParam(name = "rows", value = "显示数量", paramType = "query", dataType = "int", defaultValue = "20"),
    })
    @GetMapping("listpage-task-of-mine")
    public SuccessResultList<List<OaTaskDTO>> listPageTaskOfMine(@RequestHeader("token") String token, ListPage page) {
        return oaService.listPageTaskOfMine(token, page.getPage(), page.getRows());
    }

    @ApiOperation(value = "我的任务（待办）总数", notes = "我的任务（待办）总数接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "token", paramType = "header"),
    })
    @GetMapping("count-task-of-mine")
    public SuccessResultData<Long> countTaskOfMine(@RequestHeader("token") String token) {
        Long count = oaService.countTaskOfMine(token);
        return new SuccessResultData<>(count);
    }

    @ApiOperation(value = "我的历史任务（已办）列表", notes = "我的历史任务（已办）列表接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "token", paramType = "header"),
    })
    @GetMapping("list-history-task-of-mine")
    public List<OaHistoryTaskDTO> listHistoryTaskOfMine(@RequestHeader("token") String token) {
        return oaService.listHistoryTaskOfMine(token);
    }


    @ApiOperation(value = "我的历史任务（已办）分页列表", notes = "我的历史任务（已办）分页列表接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "token", paramType = "header"),
            @ApiImplicitParam(name = "page", value = "当前页码", paramType = "query", dataType = "int", defaultValue = "1"),
            @ApiImplicitParam(name = "rows", value = "显示数量", paramType = "query", dataType = "int", defaultValue = "20"),
    })
    @GetMapping("listpage-history-task-of-mine")
    public SuccessResultList<List<OaHistoryTaskDTO>> listPageHistoryTaskOfMine(@RequestHeader("token") String token, ListPage page) {
        return oaService.listPageHistoryTaskOfMine(token, page.getPage(), page.getRows());
    }

    @GetMapping("list-process-log/process-instance-id/{processInstanceId}")
    public List<OaProcessLogDTO> listProcessLog(@RequestHeader("token") String token, @PathVariable("processInstanceId") String processInstanceId) {
        return oaService.listProcessLog(processInstanceId);
    }

    @ApiOperation(value = "我的待阅分页列表", notes = "我的待阅分页列表接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "token", paramType = "header"),
            @ApiImplicitParam(name = "page", value = "当前页码", paramType = "query", dataType = "int", defaultValue = "1"),
            @ApiImplicitParam(name = "rows", value = "显示数量", paramType = "query", dataType = "int", defaultValue = "20"),
    })
    @GetMapping("listpage-unread-of-mine")
    public SuccessResultList<List<OaCcDTO>> listPageUnReadOfMine(@RequestHeader("token") String token, ListPage page) {
        Map<String, Object> requestParams = requestParams();
        requestParams.put("sort", "gmtCreate");
        requestParams.put("order", "desc");
        page.setParams(requestParams);
        return oaCcService.listPageOfMineByIsRead(token, 0, page);
    }

    @ApiOperation(value = "我的已阅分页列表", notes = "我的已阅分页列表接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "token", paramType = "header"),
            @ApiImplicitParam(name = "page", value = "当前页码", paramType = "query", dataType = "int", defaultValue = "1"),
            @ApiImplicitParam(name = "rows", value = "显示数量", paramType = "query", dataType = "int", defaultValue = "20"),
    })
    @GetMapping("listpage-read-of-mine")
    public SuccessResultList<List<OaCcDTO>> listPageReadOfMine(@RequestHeader("token") String token, ListPage page) {
        Map<String, Object> requestParams = requestParams();
        requestParams.put("sort", "gmtModified");
        requestParams.put("order", "desc");
        page.setParams(requestParams);
        return oaCcService.listPageOfMineByIsRead(token, 1, page);
    }

    @ApiOperation(value = "我的待阅总数", notes = "我的待阅总数接口")
    @GetMapping("count-unread-of-mine")
    public SuccessResultData<Integer> countUnReadOfMine(@RequestHeader("token") String token) {
        Integer count = oaCcService.countReadOfMine(token, 0);
        return new SuccessResultData<>(count);
    }

    @ApiOperation(value = "我的已读总数", notes = "我的已读总数接口")
    @GetMapping("count-read-of-mine")
    public SuccessResultData<Integer> countReadOfMine(@RequestHeader("token") String token) {
        Integer count = oaCcService.countReadOfMine(token, 1);
        return new SuccessResultData<>(count);
    }

}
