package ink.wgink.module.activiti.controller.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.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

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_SYSTEM_PREFIX + "oa管理")
@RestController
@RequestMapping(ISystemConstant.API_PREFIX + "/oa")
public class OaController extends DefaultBaseController {

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

    @ApiOperation(value = "流程定义分页列表", notes = "流程定义分页列表接口")
    @ApiImplicitParams({
            @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("list-procdef")
    public List<OaProcdefDTO> listProcdef() {
        return oaService.listProcdef();
    }

    @ApiOperation(value = "流程定义分页列表", notes = "流程定义分页列表接口")
    @ApiImplicitParams({
            @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(ListPage page) {
        return oaService.listPageProcdef(page.getPage(), page.getRows());
    }

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


    @ApiOperation(value = "我的任务（待办）分页列表", notes = "我的任务（待办）分页列表接口")
    @ApiImplicitParams({
            @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(ListPage page) {
        return oaService.listPageTaskOfMine(page.getPage(), page.getRows());
    }

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

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


    @ApiOperation(value = "我的历史任务（已办）分页列表", notes = "我的历史任务（已办）分页列表接口")
    @ApiImplicitParams({
            @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(ListPage page) {
        return oaService.listPageHistoryTaskOfMine(page.getPage(), page.getRows());
    }

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

    @ApiOperation(value = "我的待阅分页列表", notes = "我的待阅分页列表接口")
    @ApiImplicitParams({
            @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(ListPage page) {
        Map<String, Object> requestParams = requestParams();
        requestParams.put("sort", "gmtCreate");
        requestParams.put("order", "desc");
        page.setParams(requestParams);
        return oaCcService.listPageOfMineByIsRead(0, page);
    }

    @ApiOperation(value = "我的已阅分页列表", notes = "我的已阅分页列表接口")
    @ApiImplicitParams({
            @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(ListPage page) {
        Map<String, Object> requestParams = requestParams();
        requestParams.put("sort", "gmtModified");
        requestParams.put("order", "desc");
        page.setParams(requestParams);
        return oaCcService.listPageOfMineByIsRead(1, page);
    }

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

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


    @ApiOperation(value = "我的发起分页列表", notes = "我的发起分页列表接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "当前页码", paramType = "query", dataType = "int", defaultValue = "1"),
            @ApiImplicitParam(name = "rows", value = "显示数量", paramType = "query", dataType = "int", defaultValue = "20"),
    })
    @GetMapping("listpage-start-of-mine")
    public SuccessResultList<List<OaStartedInstanceDTO>> listPageStartOfMine(ListPage page) {
        Map<String, Object> requestParams = requestParams();
        page.setParams(requestParams);
        return oaCcService.listPageStartOfMine(page);
    }

}
