package com.njcn.process.controller.flowable;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.common.utils.HttpResultUtil;
import com.njcn.process.pojo.dto.flowable.FlowTaskDto;
import com.njcn.process.pojo.vo.flowable.FlowQueryVo;
import com.njcn.process.pojo.vo.flowable.FlowTaskVo;
import com.njcn.process.service.flowable.IFlowTaskService;
import com.njcn.web.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>工作流任务管理<p>
 *
 * @author Tony
 * @date 2021-04-03
 */
@Slf4j
@Api(tags = "工作流流程任务管理")
@RestController
@RequestMapping("/flowable/task")
@RequiredArgsConstructor
public class FlowTaskController extends BaseController {


    private final IFlowTaskService flowTaskService;





    @ApiOperation(value = "工作流_审批任务")
    @PostMapping(value = "/complete")
    public HttpResult complete(@RequestBody FlowTaskVo flowTaskVo) {
        boolean res = flowTaskService.complete(flowTaskVo);
        return null;
    }

    @ApiOperation(value = "工作流_流转")
    @PostMapping(value = "/toNextTaskUser")
    public HttpResult toNextTaskUser(@RequestBody FlowTaskVo flowTaskVo) {
        flowTaskService.toNextTaskUser(flowTaskVo);
        return null;
    }



    /**
     * 流程节点信息
     *
     * @param procInsId 流程实例id
     * @return
     */
    @GetMapping("/flowXmlAndNode")
    @ApiOperation(value = "工作流_流程节点信息")
    public HttpResult flowXmlAndNode(@RequestParam(value = "procInsId", required = false) String procInsId,
                                     @RequestParam(value = "deployId", required = false) String deployId) {
        String methodDescribe = getMethodDescribe("flowXmlAndNode");

        Map<String, Object> res = flowTaskService.flowXmlAndNode(procInsId, deployId);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, res, methodDescribe);
    }


    @ApiOperation(value = "我发起的流程", response = HttpResult.class)
    @GetMapping(value = "/myProcess")
    public HttpResult<Page<FlowTaskDto>> myProcess(FlowQueryVo queryVo) {
        String methodDescribe = getMethodDescribe("myProcess");

        Page<FlowTaskDto> page =  flowTaskService.myProcess(queryVo);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, page, methodDescribe);
    }

    @ApiOperation(value = "获取已办任务", response = FlowTaskDto.class)
    @GetMapping(value = "/finishedList")
    public HttpResult<Page<FlowTaskDto>> finishedList(FlowQueryVo queryVo) {
        String methodDescribe = getMethodDescribe("finishedList");
        Page<FlowTaskDto> page =  flowTaskService.finishedList(queryVo);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, page, methodDescribe);
    }


    @ApiOperation(value = "获取待办列表", response = FlowTaskDto.class)
    @GetMapping(value = "/todoList")
    public HttpResult<Page<FlowTaskDto>> todoList(FlowQueryVo queryVo) {
        String methodDescribe = getMethodDescribe("todoList");
        Page<FlowTaskDto> page =  flowTaskService.todoList(queryVo);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, page, methodDescribe);
    }


    @ApiOperation(value = "获取流程变量", response = FlowTaskDto.class)
    @GetMapping(value = "/processVariables/{taskId}")
    public HttpResult<Map<String,Object>> processVariables(@ApiParam(value = "流程任务Id") @PathVariable(value = "taskId") String taskId) {
        String methodDescribe = getMethodDescribe("processVariables");
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, flowTaskService.processVariables(taskId), methodDescribe);

    }

    @ApiOperation(value = "流程历史流转记录", response = FlowTaskDto.class)
    @GetMapping(value = "/flowRecord")
    public HttpResult<Map<String, Object>> flowRecord(String procInsId, String deployId) {
        String methodDescribe = getMethodDescribe("flowRecord");
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, flowTaskService.flowRecord(procInsId, deployId), methodDescribe);
    }

    @ApiOperation(value = "取消申请", response = FlowTaskDto.class)
    @PostMapping(value = "/stopProcess")
    public HttpResult<Object> stopProcess(@RequestBody FlowTaskVo flowTaskVo) {
        String methodDescribe = getMethodDescribe("stopProcess");
        flowTaskService.stopProcess(flowTaskVo);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS,true, methodDescribe);
    }


    @ApiOperation(value = "驳回任务")
    @PostMapping(value = "/reject")
    public HttpResult taskReject(@RequestBody FlowTaskVo flowTaskVo) {
        String methodDescribe = getMethodDescribe("taskReject");
        flowTaskService.taskReject(flowTaskVo);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS,true, methodDescribe);

    }


}
