介绍
方式一: 前端通过ajax调用后端接口,发起或者启动一个流程;备注:http://网关(nginx)/je/workflow/button/operate url前缀,请求网关(nginx)
方式二:通过业务代码调用rpc接口发起流程,也可通过流程节点事件发起。
详细步骤
方式一:
1. 调用getInfo接口获取可发起流程信息
rul:/je/workflow/processInfo/getInfo
参数 | 说明 | 示例 |
---|---|---|
funcCode | 功能编码 | TEST_PTLC |
tableCode | 表code | TEST_PTLC |
beanId | 主键id | 4d2fdf33681840b6ba8cd7f76c4a4f17 |
prod | 产品标识 | test |
获取接口返回按钮信息
2. 调用getSubmitOutGoingNode接口获取可提交节点信息
rul:/je/workflow/processInfo/getSubmitOutGoingNode
参数 | 说明 | 示例 |
---|---|---|
pdid | 流程版本id | (上个接口获取的pdid)C4cNyWKzdcFYyKSSLZj:1:2b9774d2-c715-11ed-9757-0242f87b94e8 |
beanId | 主键 | 4d2fdf33681840b6ba8cd7f76c4a4f17 |
tableCode | 表code | TEST_PTLC |
prod | 产品标识 | test |
3.调用operate发起流程,具体的接口信息查看api接口文档中的流程模块
rul:/je/workflow/button/operate
参数 | 说明 | 示例 |
---|---|---|
assignee | 处理人信息 | [{“nodeId”:”taskdMJDSDD5YMskXhlkKpa”,”nodeName”:”回签节点”,”assignee”:”d07890fa093a4a4c90d050a9f9751838”,”assigneeName”:”于春辉”}] |
comment | 提交意见 | 同意 |
target | 线id | 上个接口获取target |
sequentials | 多人节点,手动指定顺序或者并须执行,可以为空 | |
isJump | 是否跳跃 0否 1是 | 0 |
pdid | 流程版本id | 第一个接口获取pdid |
operationId | 操作id | processEmptySponsorOperation发起id 其他id请查看接口文档 |
tableCode | 表code | TEST_PTLC |
funcCode | 功能code | TEST_PTLC |
funcId | 功能id | U8ymbZqVoKTdMMdE5Ss |
prod | 产品标识 | test |
beanId | 主键id | 4d2fdf33681840b6ba8cd7f76c4a4f17 |
方式二:
注意!!!
如果是定时任务发起流程,需要设置当前登录人相关信息
//deptId 用户账号部门的唯一Id (账号部门视图)
//code 用户code
//name 用户name
//realUserId 用户真实Id (用户表Id)
AccountVo account = new AccountVo.Builder().deptId("").code("").name("").realUserId("").build();
1.获取表单流程按钮和表单控制信息,获取到要发起的流程的pdid
List<Map<String, Object>> buttons = processInfoRpcService.getButtons(buttonsVo);
2.获取提交的节点信息和人员信息,获取目标节点ID 、NAME, 目标顺序流
List<ProcessNextNodeInfoVo> submitOutGoingNode = processInfoRpcService.getSubmitOutGoingNode(submitOutGoingNodeVo);
3.执行流程按钮操作
processInfoRpcService.operate(buttonOperateVo);
package com.je.business.controller;
import com.je.workflow.model.*;
import com.je.workflow.rpc.dictionary.WorkFlowExecuteCustomMethodService;
import com.je.workflow.rpc.workflow.ProcessInfoRpcService;
import org.apache.servicecomb.provider.pojo.RpcSchema;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@RpcSchema(schemaId = "testMyWorkFlowMethodService")
public class TestMyWorkFlowMethodServiceImpl implements WorkFlowExecuteCustomMethodService {
//注入ProcessInfoRpcService rpc接口
@Autowired
private ProcessInfoRpcService processInfoRpcService;
private static final Logger logger = LoggerFactory.getLogger(TestMyWorkFlowMethodServiceImpl.class);
@Override
public void executeCustomMethod(EventSubmitDTO eventSubmitDTO) {
//处理自己的业务逻辑
StringBuffer stringBuffer = new StringBuffer();
stringBuffer.append(String.format("taskId:%s , ", eventSubmitDTO.getTaskId()));
stringBuffer.append(String.format("currentTaskName:%s , ", eventSubmitDTO.getCurrentTaskName()));
stringBuffer.append(String.format("targetTaskName:%s , ", eventSubmitDTO.getTargetTaskName()));
stringBuffer.append(String.format("targetTransition:%s , ", eventSubmitDTO.getTargetTransition()));
stringBuffer.append(String.format("operatorEnum:%s , ", eventSubmitDTO.getOperatorEnum().toString()));
stringBuffer.append(String.format("submitComment:%s , ", eventSubmitDTO.getSubmitComment()));
stringBuffer.append(String.format("assignees:%s , ", eventSubmitDTO.getAssignees()));
stringBuffer.append(String.format("funcCode:%s , ", eventSubmitDTO.getFuncCode()));
stringBuffer.append(String.format("dynaBean:%s , ", eventSubmitDTO.getDynaBean().toString()));
logger.info(stringBuffer.toString());
System.out.println(eventSubmitDTO);
//1.获取表单流程按钮和表单控制信息
ButtonsVo buttonsVo = new ButtonsVo.Builder().prod("test").funcCode("JE_LCSP_JBSQ").tableCode("JE_LCSP_JBSQ").beanId("4b5e1b2b36ae44bb8ca05a215a811c52").build();
List<Map<String, Object>> buttons = processInfoRpcService.getButtons(buttonsVo);
//获取想要调用的流程的pdid
ArrayList<Map<String, Object>> arrayList = (ArrayList) buttons.get(0).get("buttonList");
String pdid = arrayList.get(0).get("pdid").toString();
//2.获取提交的节点信息和人员信息
SubmitOutGoingNodeVo submitOutGoingNodeVo = new SubmitOutGoingNodeVo.Builder().taskId("").pdid(pdid).prod("test").beanId("4b5e1b2b36ae44bb8ca05a215a811c52").tableCode("JE_LCSP_JBSQ").build();
List<ProcessNextNodeInfoVo> submitOutGoingNode = processInfoRpcService.getSubmitOutGoingNode(submitOutGoingNodeVo);
//获取流转的目标节点ID name 目标顺序流
String target = submitOutGoingNode.get(0).getTarget();
String nodeId = submitOutGoingNode.get(0).getNodeId();
String nodeName = submitOutGoingNode.get(0).getNodeName();
//3.执行流程按钮操作
Map<String, Object> operationCustomerParam = new HashMap<>();
//设置节点,人员信息
operationCustomerParam.put("assignee", "[{\"nodeId\":\""+nodeId+"\",\"nodeName\":\""+nodeName+"\",\"assignee\":\"33ff53e1e64f491d855adebdc2bb0973\",\"assigneeName\":\"王超\"}]");
//设置目标信息
operationCustomerParam.put("target", target);
operationCustomerParam.put("taskId", "");
operationCustomerParam.put("piid", "");
//具体操作类型
operationCustomerParam.put("opinionType", "");
//审批意见
operationCustomerParam.put("comment", "同意");
operationCustomerParam.put("sequentials", "");
operationCustomerParam.put("isJump","0");
ButtonOperateVo buttonOperateVo = new ButtonOperateVo.Builder().operationId("processEmptySponsorOperation").prod("test").funcCode("JE_LCSP_JBSQ").pdid(pdid).beanId("4b5e1b2b36ae44bb8ca05a215a811c52").tableCode("JE_LCSP_JBSQ").funcId("").operationCustomerParam(operationCustomerParam).build();
processInfoRpcService.operate(buttonOperateVo);
}
}
定时任务demo
package com.je.business.controller;
import com.je.common.auth.impl.RealOrganizationUser;
import com.je.common.auth.impl.account.Account;
import com.je.common.base.util.SecurityUserHolder;
import com.je.workflow.model.*;
import com.je.workflow.rpc.dictionary.WorkFlowExecuteCustomMethodService;
import com.je.workflow.rpc.workflow.ProcessInfoRpcService;
import com.xxl.job.core.handler.annotation.XxlJob;
import org.apache.servicecomb.provider.pojo.RpcSchema;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.core.task.TaskExecutor;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@RpcSchema(schemaId = "testMyWorkFlowMethodService")
public class TestMyWorkFlowMethodServiceImpl implements WorkFlowExecuteCustomMethodService {
@Autowired
private ProcessInfoRpcService processInfoRpcService;
private static final Logger logger = LoggerFactory.getLogger(TestMyWorkFlowMethodServiceImpl.class);
@Qualifier("taskExecutor")
@Autowired
private TaskExecutor taskExecutor;
@Override
@XxlJob("testMyWorkFlowMethodServiceTask")
public void executeCustomMethod(EventSubmitDTO eventSubmitDTO) {
System.out.println("----------------------------------------------------定时任务执行--------------------------------------------------");
taskExecutor.execute(() -> {
AccountVo account = new AccountVo.Builder().deptId("33ff53e1e64f491d855adebdc2bb0973").code("wangchaowy").name("王超").realUserId("933bbf6a47d34a5cad9b710da9a570a7").build();
//1.获取表单流程按钮和表单控制信息
ButtonsVo buttonsVo = new ButtonsVo.Builder().prod("test").funcCode("JE_LCSP_JBSQ").tableCode("JE_LCSP_JBSQ").beanId("4b5e1b2b36ae44bb8ca05a215a811c52").account(account).build();
List<Map<String, Object>> buttons = processInfoRpcService.getButtons(buttonsVo);
//获取流程pdid
ArrayList<Map<String, Object>> arrayList = (ArrayList) buttons.get(0).get("buttonList");
String pdid = arrayList.get(0).get("pdid").toString();
//2.获取提交的节点信息和人员信息
SubmitOutGoingNodeVo submitOutGoingNodeVo = new SubmitOutGoingNodeVo.Builder().taskId("").pdid(pdid).prod("test").beanId("4b5e1b2b36ae44bb8ca05a215a811c52").tableCode("JE_LCSP_JBSQ").account(account).build();
List<ProcessNextNodeInfoVo> submitOutGoingNode = processInfoRpcService.getSubmitOutGoingNode(submitOutGoingNodeVo);
//获取目标节点ID name 目标
String target = submitOutGoingNode.get(0).getTarget();
String nodeId = submitOutGoingNode.get(0).getNodeId();
String nodeName = submitOutGoingNode.get(0).getNodeName();
//3.执行流程按钮操作
Map<String, Object> operationCustomerParam = new HashMap<>();
//设置节点,人员信息
operationCustomerParam.put("assignee", "[{\"nodeId\":\"" + nodeId + "\",\"nodeName\":\"" + nodeName + "\",\"assignee\":\"33ff53e1e64f491d855adebdc2bb0973\",\"assigneeName\":\"王超\"}]");
operationCustomerParam.put("target", target);
operationCustomerParam.put("taskId", "");
operationCustomerParam.put("piid", "");
//具体操作类型
operationCustomerParam.put("opinionType", "");
//审批意见
operationCustomerParam.put("comment", "同意");
operationCustomerParam.put("sequentials", "");
operationCustomerParam.put("isJump", "0");
ButtonOperateVo buttonOperateVo = new ButtonOperateVo.Builder().operationId("processEmptySponsorOperation").prod("test").funcCode("JE_LCSP_JBSQ").pdid(pdid).beanId("4b5e1b2b36ae44bb8ca05a215a811c52").tableCode("JE_LCSP_JBSQ").funcId("").operationCustomerParam(operationCustomerParam).account(account).build();
processInfoRpcService.operate(buttonOperateVo);
});
System.out.println("-----------------------------------------------定时任务执行结束-------------------------------------------------------");
}
}
最后编辑: 王超 文档更新时间: 2024-08-29 09:50 作者:于春辉