首页 技术 正文
技术 2022年11月10日
0 收藏 362 点赞 2,662 浏览 2317 个字

在我的开发任务中,突然给我提出了一个待办任务需要获取当前任务节点上以任务节点的表单信息,刚开始搞得我有点措手不及,后来仔细是靠后,灵感一下,直接操作流程的bpmn信息就可以获取到节点信息嘛,顺着这个思路,我整理出了自己的思路:

(1)将节点大体分为两类,一类是网关节点,另外一类就是用户任务节点,使用List集合,将网关与用户任务进行分类

(2)获取上一节点,我们就需要从bpmn的连线信息入手,固定连线的targtaetRef,辨别sourceRef节点的类型,当是用户任务时,放进 List frontNodeIdlist = new ArrayList<>();,当是GateWay节点时,将targtaetRef设为网关的,继续遍历上一节点,就是跳过网关节点,只要用户任务节点

 /**
* 获取当前节点上一节点id【可能多个节点id】
* @param task
* @return
*/
private List<String> getFrontUserTaskIds(Task task){
String nodeId=task.getTaskDefinitionKey();
//网关集合
List<Gateway> gateways = new ArrayList<>();
//用户任务集合
List<UserTask> userTasks = new ArrayList<>(); //网关节点id
List<String> gatewayNodelIdList = new ArrayList<>();
//用户任务节点id
List<String> usertaskNodelIdList = new ArrayList<>();// ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(task.getProcessInstanceId()).singleResult();
// String processDefinitionId = processInstance.getProcessDefinitionId();
String processDefinitionId = task.getProcessDefinitionId();
// ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionId(processDefinitionId).singleResult();
BpmnModel bpmnModel = repositoryService.getBpmnModel(processDefinitionId);
List<Process> processes = bpmnModel.getProcesses();
Process process = processes.get(0);
Collection<FlowElement> flowElements = process.getFlowElements();
flowElements.forEach(flowElement -> {
if(flowElement instanceof Gateway){
gatewayNodelIdList.add(flowElement.getId());
gateways.add((Gateway) flowElement);
}
if(flowElement instanceof UserTask){
usertaskNodelIdList.add(flowElement.getId());
userTasks.add((UserTask) flowElement);
}
}); List<String> frontNodeIdlist = new ArrayList<>();
for (UserTask userTask : userTasks) {
List<SequenceFlow> incomingFlows = userTask.getIncomingFlows();
for (SequenceFlow incomingFlow : incomingFlows) {
String sourceRef = incomingFlow.getSourceRef();
String targetRef = incomingFlow.getTargetRef();
if(nodeId.equals(targtaetRef)){
//当前任务的上一节点是网关
if (gatewayNodelIdList.contains(sourceRef)) {
for (Gateway gateway : gateways) {
List<SequenceFlow> incomingFlowsGateWay = gateway.getIncomingFlows();
for (SequenceFlow sequenceFlow : incomingFlowsGateWay) {
String sourceRefGateWay = sequenceFlow.getSourceRef();
String targetRefGateWay = sequenceFlow.getTargetRef();
if(sourceRef.equals(targetRefGateWay)){
frontNodeIdlist.add(sourceRefGateWay);
} }
}
}else{
frontNodeIdlist.add(sourceRef);
}
}
}
}
return frontNodeIdlist;
}
上一篇: 010 JVM类加载
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,492
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,907
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,740
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,494
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,132
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,295