package com.mortals.xhx.feign.flowable;

import com.mortals.framework.exception.AppException;
import com.mortals.xhx.common.pdu.api.ApiRespPdu;
import com.mortals.xhx.common.pdu.sms.SmsSendReq;
import com.mortals.xhx.feign.IFeign;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;

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

/**
 * 工作流api
 */
@FeignClient(name = "${application.register.service-name:workflow-engine}")
public interface IApiFlowFeign extends IFeign {


    /**
     * 流程部署
     *
     * @param modelId 流程ID，来自 ACT_DE_MODEL
     * @return
     * @throws AppException
     */
    @PostMapping(value = "/flowable/api/deploy")
    ApiRespPdu<String> deploy(@RequestParam("modelId") String modelId) throws AppException;

    /**
     * 启动流程
     *
     * @param deployId 部署的流程 Id，来自 ACT_RE_PROCDEF
     * @param userId   用户 Id
     * @param dataKey  数据 Key，业务键，一般为表单数据的 ID，仅作为表单数据与流程实例关联的依据
     * @return
     * @throws AppException
     */
    @PostMapping(value = "/flowable/api/start")
    ApiRespPdu<String> start(@RequestParam(value = "deployId") String deployId, @RequestParam(value = "userId") String userId, @RequestParam(value = "dataKey") String dataKey);


    /**
     * 设置任务参数
     *
     * @param taskId 任务ID
     * @param map    用户列表
     * @return
     */
    @RequestMapping(value = "/flowable/api/setVariables", method = RequestMethod.POST)
    ApiRespPdu<String> setVariables(@RequestParam(value = "taskId") String taskId, @RequestBody Map<String, Object> map);


    /**
     * 设置任务参数
     *
     * @param taskId 任务ID
     * @param key    键
     * @param value  值
     * @return
     */
    @RequestMapping(value = "/setVariable", method = RequestMethod.POST)
    ApiRespPdu<String> setVariable(@RequestParam(value = "taskId") String taskId,
                                   @RequestParam(value = "key") String key,
                                   @RequestParam(value = "value") Object value);


    /**
     * 设置任务参数，List 使用
     *
     * @param taskId 任务ID
     * @param key    键
     * @param value  值
     * @return
     */
    @RequestMapping(value = "/flowable/api/setListVariable", method = RequestMethod.POST)
    ApiRespPdu<String> setListVariable(@RequestParam(value = "taskId") String taskId,
                                       @RequestParam(value = "key") String key,
                                       @RequestParam(value = "value") List<String> value);


    /**
     * 任务处理1
     *
     * @param taskId 任务 Id，来自 ACT_RU_TASK
     * @return
     */
    @RequestMapping(value = "/flowable/api/task", method = RequestMethod.POST)
    ApiRespPdu<String> task(@RequestParam(value = "taskId") String taskId);


    /**
     * 任务处理
     *
     * @param taskId   任务 Id，来自 ACT_RU_TASK
     * @param assignee 设置审核人，替换
     * @param map      完成任务需要的条件参数
     * @return
     */
    @RequestMapping(value = "/flowable/api/taskByAssignee", method = RequestMethod.POST)
    ApiRespPdu<String> taskByAssignee(@RequestParam(value = "taskId") String taskId,
                                      @RequestParam(value = "assignee") String assignee,
                                      @RequestBody Map<String, Object> map);


    /**
     * 中止流程
     *
     * @param processId 流程ID
     * @return
     */
    @RequestMapping(value = "/flowable/api/deleteProcess", method = RequestMethod.POST)
    ApiRespPdu<String> deleteProcess(@RequestParam(value = "processId") String processId);


    /**
     * 获取正在运行的数据 Id 列表
     *
     * @return
     */
    @RequestMapping(value = "/flowable/api/getRuntimeDataId", method = RequestMethod.POST)
    ApiRespPdu<List<String>> getRuntimeDataId();


    /**
     * 根据用户，获取需要审核的业务键 business_key 列表
     *
     * @param userId 用户 Id
     * @return
     */
    @RequestMapping(value = "/flowable/api/getRuntimeBusinessKeyByUser", method = RequestMethod.POST)
    ApiRespPdu<List<Map<String, Object>>> getRuntimeBusinessKeyByUser(@RequestParam(value = "userId") String userId);


    /**
     * 获取组，获取需要审核的业务键 business_key 列表
     *
     * @param groupIds 组 Id
     * @return
     */
    @RequestMapping(value = "/flowable/api/getRuntimeBusinessKeyByGroup", method = RequestMethod.POST)
    ApiRespPdu<List<Map<String, Object>>> getRuntimeBusinessKeyByGroup(@RequestBody List<String> groupIds);


    /**
     * 获取用户审核历史
     *
     * @param userId 发起人 Id
     * @return
     */
    @RequestMapping(value = "/flowable/api/getHistoryByUser", method = RequestMethod.POST)
    ApiRespPdu<List<Map<String, Object>>> getHistoryByUser(@RequestParam(value = "userId") String userId);


    /**
     * 通过流程实例 Id，判断流程是否结束
     *
     * @param processInstanceId 流程实例 Id
     * @return true 结束，false 未结束
     */
    @RequestMapping(value = "/flowable/api/checkProcessInstanceFinish", method = RequestMethod.POST)
    ApiRespPdu<Boolean> checkProcessInstanceFinish(@RequestParam(value = "processInstanceId") String processInstanceId);


    /**
     * 根据任务节点获取流程实例 Id
     *
     * @param taskId 任务节点 Id
     * @return
     */
    @RequestMapping(value = "/flowable/api/getTaskInfo", method = RequestMethod.POST)
    ApiRespPdu<String> getTaskInfo(@RequestParam(value = "taskId") String taskId);

    /**
     * 根据流程实例 ID 获取任务进度流程图
     *
     * @param processInstanceId 流程实例id
     * @return base64图片数据
     * @throws AppException
     */
    @RequestMapping(value = "/flowable/api/getProcessDiagram", method = RequestMethod.POST)
    String getProcessDiagram(@RequestParam("processInstanceId") String processInstanceId);


    /**
     * 根据任务 ID 获取任务进度流程图
     *
     * @param taskId 任务节点 Id
     * @return
     */
    @RequestMapping(value = "/flowable/api/getTaskProcessDiagram", method = RequestMethod.POST)
    ApiRespPdu<String> getTaskProcessDiagram(@RequestParam(value = "taskId") String taskId);
}

