当前位置:   article > 正文

SpringBoot系列——Activiti7工作流引擎(二)_activiti7 activityimpl

activiti7 activityimpl

  流程图工具类ActivitiUtils

  1. package com.mypro.activiti.utils;
  2. import java.util.ArrayList;
  3. import java.util.List;
  4. import org.activiti.bpmn.model.BpmnModel;
  5. import org.activiti.bpmn.model.FlowNode;
  6. import org.activiti.bpmn.model.SequenceFlow;
  7. import org.activiti.engine.history.HistoricActivityInstance;
  8. import org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity;
  9. /**
  10. <p>Activiti工作流工具类</p>
  11. @author FRH
  12. @time 20181210日上午11:26:02
  13. @version 1.0
  14. */
  15. public class ActivitiUtils {
  16. /**
  17. <p>获取流程走过的线</p>
  18. @param bpmnModel 流程对象模型
  19. @param processDefinitionEntity 流程定义对象
  20. @param historicActivityInstances 历史流程已经执行的节点,并已经按执行的先后顺序排序
  21. @return List<String> 流程走过的线
  22. @author FRH
  23. @time 20181210日上午11:26:19
  24. @version 1.0
  25. */
  26. public static List<String> getHighLightedFlows(BpmnModel bpmnModel, ProcessDefinitionEntity processDefinitionEntity, List<HistoricActivityInstance> historicActivityInstances) {
  27. // 用以保存高亮的线flowId
  28. List<String> highFlows = new ArrayList<String>();
  29. if(historicActivityInstances == null || historicActivityInstances.size() == 0) return highFlows;
  30. // 遍历历史节点
  31. for (int i = 0; i < historicActivityInstances.size() - 1; i++) {
  32. // 取出已执行的节点
  33. HistoricActivityInstance activityImpl_ = historicActivityInstances.get(i);
  34. <span class="hljs-comment"><span class="hljs-comment"><span class="hljs-comment"><span class="hljs-comment">// 用以保存后续开始时间相同的节点</span></span></span></span>
  35. List<FlowNode> sameStartTimeNodes = <span class="hljs-keyword"><span class="hljs-keyword"><span class="hljs-keyword"><span class="hljs-keyword">new</span></span></span></span> ArrayList<FlowNode>();
  36. <span class="hljs-comment"><span class="hljs-comment"><span class="hljs-comment"><span class="hljs-comment">// 获取下一个节点(用于连线)</span></span></span></span>
  37. FlowNode sameActivityImpl = getNextFlowNode(bpmnModel, historicActivityInstances, i, activityImpl_);
  38. // FlowNode sameActivityImpl = (FlowNode) bpmnModel.getMainProcess().getFlowElement(historicActivityInstances.get(i + 1).getActivityId());
  39. <span class="hljs-comment"><span class="hljs-comment"><span class="hljs-comment"><span class="hljs-comment">// 将后面第一个节点放在时间相同节点的集合里</span></span></span></span>
  40. <span class="hljs-keyword"><span class="hljs-keyword"><span class="hljs-keyword"><span class="hljs-keyword">if</span></span></span></span>(sameActivityImpl != <span class="hljs-keyword"><span class="hljs-keyword"><span class="hljs-keyword"><span class="hljs-keyword">null</span></span></span></span>) sameStartTimeNodes.add(sameActivityImpl);
  41. <span class="hljs-comment"><span class="hljs-comment"><span class="hljs-comment"><span class="hljs-comment">// 循环后面节点,看是否有与此后继节点开始时间相同的节点,有则添加到后继节点集合</span></span></span></span>
  42. <span class="hljs-keyword"><span class="hljs-keyword"><span class="hljs-keyword"><span class="hljs-keyword">for</span></span></span></span> (<span class="hljs-keyword"><span class="hljs-keyword"><span class="hljs-keyword"><span class="hljs-keyword">int</span></span></span></span> j = i + <span class="hljs-number"><span class="hljs-number"><span class="hljs-number"><span class="hljs-number">1</span></span></span></span>; j < historicActivityInstances.size() - <span class="hljs-number"><span class="hljs-number"><span class="hljs-number"><span class="hljs-number">1</span></span></span></span>; j++) {
  43. HistoricActivityInstance activityImpl1 = historicActivityInstances.get(j);<span class="hljs-comment"><span class="hljs-comment"><span class="hljs-comment"><span class="hljs-comment">// 后续第一个节点</span></span></span></span>
  44. HistoricActivityInstance activityImpl2 = historicActivityInstances.get(j + <span class="hljs-number"><span class="hljs-number"><span class="hljs-number"><span class="hljs-number">1</span></span></span></span>);<span class="hljs-comment"><span class="hljs-comment"><span class="hljs-comment"><span class="hljs-comment">// 后续第二个节点</span></span></span></span>
  45. <span class="hljs-keyword"><span class="hljs-keyword"><span class="hljs-keyword"><span class="hljs-keyword">if</span></span></span></span> (activityImpl1.getStartTime().getTime() != activityImpl2.getStartTime().getTime()) <span class="hljs-keyword"><span class="hljs-keyword"><span class="hljs-keyword"><span class="hljs-keyword">break</span></span></span></span>;
  46. <span class="hljs-comment"><span class="hljs-comment"><span class="hljs-comment"><span class="hljs-comment">// 如果第一个节点和第二个节点开始时间相同保存</span></span></span></span>
  47. FlowNode sameActivityImpl2 = (FlowNode) bpmnModel.getMainProcess().getFlowElement(activityImpl2.getActivityId());
  48. sameStartTimeNodes.add(sameActivityImpl2);
  49. }
  50. <span class="hljs-comment"><span class="hljs-comment"><span class="hljs-comment"><span class="hljs-comment">// 得到节点定义的详细信息</span></span></span></span>
  51. FlowNode activityImpl = (FlowNode) bpmnModel.getMainProcess().getFlowElement(historicActivityInstances.get(i).getActivityId());
  52. <span class="hljs-comment"><span class="hljs-comment"><span class="hljs-comment"><span class="hljs-comment">// 取出节点的所有出去的线,对所有的线进行遍历</span></span></span></span>
  53. List<SequenceFlow> pvmTransitions = activityImpl.getOutgoingFlows();
  54. <span class="hljs-keyword"><span class="hljs-keyword"><span class="hljs-keyword"><span class="hljs-keyword">for</span></span></span></span> (SequenceFlow pvmTransition : pvmTransitions) {
  55. <span class="hljs-comment"><span class="hljs-comment"><span class="hljs-comment"><span class="hljs-comment">// 获取节点</span></span></span></span>
  56. FlowNode pvmActivityImpl = (FlowNode) bpmnModel.getMainProcess().getFlowElement(pvmTransition.getTargetRef());
  57. <span class="hljs-comment"><span class="hljs-comment"><span class="hljs-comment"><span class="hljs-comment">// 不是后继节点</span></span></span></span>
  58. <span class="hljs-keyword"><span class="hljs-keyword"><span class="hljs-keyword"><span class="hljs-keyword">if</span></span></span></span>(!sameStartTimeNodes.contains(pvmActivityImpl)) <span class="hljs-keyword"><span class="hljs-keyword"><span class="hljs-keyword"><span class="hljs-keyword">continue</span></span></span></span>;
  59. <span class="hljs-comment"><span class="hljs-comment"><span class="hljs-comment"><span class="hljs-comment">// 如果取出的线的目标节点存在时间相同的节点里,保存该线的id,进行高亮显示</span></span></span></span>
  60. highFlows.add(pvmTransition.getId());
  61. }
  62. }
  63. <span class="hljs-comment"><span class="hljs-comment"><span class="hljs-comment"><span class="hljs-comment">//返回高亮的线</span></span></span></span>
  64. <span class="hljs-keyword"><span class="hljs-keyword"><span class="hljs-keyword"><span class="hljs-keyword">return</span></span></span></span> highFlows;
  65. }
  66. <span class="hljs-comment"><span class="hljs-comment"><span class="hljs-comment"><span class="hljs-comment">/**
  67. * <p>获取下一个节点信息</p>
  68. * </span></span></span><span class="hljs-doctag"><span class="hljs-comment"><span class="hljs-doctag"><span class="hljs-comment"><span class="hljs-doctag"><span class="hljs-comment"><span class="hljs-doctag">@param</span></span></span></span></span></span></span><span class="hljs-comment"><span class="hljs-comment"><span class="hljs-comment"> bpmnModel 流程模型
  69. * </span></span></span><span class="hljs-doctag"><span class="hljs-comment"><span class="hljs-doctag"><span class="hljs-comment"><span class="hljs-doctag"><span class="hljs-comment"><span class="hljs-doctag">@param</span></span></span></span></span></span></span><span class="hljs-comment"><span class="hljs-comment"><span class="hljs-comment"> historicActivityInstances 历史节点
  70. * </span></span></span><span class="hljs-doctag"><span class="hljs-comment"><span class="hljs-doctag"><span class="hljs-comment"><span class="hljs-doctag"><span class="hljs-comment"><span class="hljs-doctag">@param</span></span></span></span></span></span></span><span class="hljs-comment"><span class="hljs-comment"><span class="hljs-comment"> i 当前已经遍历到的历史节点索引(找下一个节点从此节点后)
  71. * </span></span></span><span class="hljs-doctag"><span class="hljs-comment"><span class="hljs-doctag"><span class="hljs-comment"><span class="hljs-doctag"><span class="hljs-comment"><span class="hljs-doctag">@param</span></span></span></span></span></span></span><span class="hljs-comment"><span class="hljs-comment"><span class="hljs-comment"> activityImpl_ 当前遍历到的历史节点实例
  72. * </span></span></span><span class="hljs-doctag"><span class="hljs-comment"><span class="hljs-doctag"><span class="hljs-comment"><span class="hljs-doctag"><span class="hljs-comment"><span class="hljs-doctag">@return</span></span></span></span></span></span></span><span class="hljs-comment"><span class="hljs-comment"><span class="hljs-comment"> FlowNode 下一个节点信息
  73. * </span></span></span><span class="hljs-doctag"><span class="hljs-comment"><span class="hljs-doctag"><span class="hljs-comment"><span class="hljs-doctag"><span class="hljs-comment"><span class="hljs-doctag">@author</span></span></span></span></span></span></span><span class="hljs-comment"><span class="hljs-comment"><span class="hljs-comment"> FRH
  74. * </span></span></span><span class="hljs-doctag"><span class="hljs-comment"><span class="hljs-doctag"><span class="hljs-comment"><span class="hljs-doctag"><span class="hljs-comment"><span class="hljs-doctag">@time</span></span></span></span></span></span></span><span class="hljs-comment"><span class="hljs-comment"><span class="hljs-comment"> 2018年12月10日上午11:26:55
  75. * </span></span></span><span class="hljs-doctag"><span class="hljs-comment"><span class="hljs-doctag"><span class="hljs-comment"><span class="hljs-doctag"><span class="hljs-comment"><span class="hljs-doctag">@version</span></span></span></span></span></span></span><span class="hljs-comment"><span class="hljs-comment"><span class="hljs-comment"> 1.0
  76. */</span></span></span></span>
  77. <span class="hljs-function"><span class="hljs-keyword"><span class="hljs-function"><span class="hljs-keyword"><span class="hljs-function"><span class="hljs-keyword"><span class="hljs-function"><span class="hljs-keyword">private</span></span></span></span></span></span></span><span class="hljs-function"><span class="hljs-function"><span class="hljs-function"> </span></span></span><span class="hljs-keyword"><span class="hljs-function"><span class="hljs-keyword"><span class="hljs-function"><span class="hljs-keyword"><span class="hljs-function"><span class="hljs-keyword">static</span></span></span></span></span></span></span><span class="hljs-function"><span class="hljs-function"><span class="hljs-function"> FlowNode </span></span></span><span class="hljs-title"><span class="hljs-function"><span class="hljs-title"><span class="hljs-function"><span class="hljs-title"><span class="hljs-function"><span class="hljs-title">getNextFlowNode</span></span></span></span></span></span></span><span class="hljs-params"><span class="hljs-function"><span class="hljs-params"><span class="hljs-function"><span class="hljs-params"><span class="hljs-function"><span class="hljs-params">(BpmnModel bpmnModel, List<HistoricActivityInstance> historicActivityInstances, </span></span></span></span></span></span><span class="hljs-keyword"><span class="hljs-function"><span class="hljs-params"><span class="hljs-keyword"><span class="hljs-function"><span class="hljs-params"><span class="hljs-keyword"><span class="hljs-function"><span class="hljs-params"><span class="hljs-keyword">int</span></span></span></span></span></span></span></span></span></span><span class="hljs-function"><span class="hljs-params"><span class="hljs-function"><span class="hljs-params"><span class="hljs-function"><span class="hljs-params"> i, HistoricActivityInstance activityImpl_)</span></span></span></span></span></span></span><span class="hljs-function"><span class="hljs-function"><span class="hljs-function"> </span></span></span></span>{
  78. <span class="hljs-comment"><span class="hljs-comment"><span class="hljs-comment"><span class="hljs-comment">// 保存后一个节点</span></span></span></span>
  79. FlowNode sameActivityImpl = <span class="hljs-keyword"><span class="hljs-keyword"><span class="hljs-keyword"><span class="hljs-keyword">null</span></span></span></span>;
  80. <span class="hljs-comment"><span class="hljs-comment"><span class="hljs-comment"><span class="hljs-comment">// 如果当前节点不是用户任务节点,则取排序的下一个节点为后续节点</span></span></span></span>
  81. <span class="hljs-keyword"><span class="hljs-keyword"><span class="hljs-keyword"><span class="hljs-keyword">if</span></span></span></span>(!<span class="hljs-string"><span class="hljs-string"><span class="hljs-string"><span class="hljs-string">"userTask"</span></span></span></span>.equals(activityImpl_.getActivityType())) {
  82. <span class="hljs-comment"><span class="hljs-comment"><span class="hljs-comment"><span class="hljs-comment">// 是最后一个节点,没有下一个节点</span></span></span></span>
  83. <span class="hljs-keyword"><span class="hljs-keyword"><span class="hljs-keyword"><span class="hljs-keyword">if</span></span></span></span>(i == historicActivityInstances.size()) <span class="hljs-keyword"><span class="hljs-keyword"><span class="hljs-keyword"><span class="hljs-keyword">return</span></span></span></span> sameActivityImpl;
  84. <span class="hljs-comment"><span class="hljs-comment"><span class="hljs-comment"><span class="hljs-comment">// 不是最后一个节点,取下一个节点为后继节点</span></span></span></span>
  85. sameActivityImpl = (FlowNode) bpmnModel.getMainProcess().getFlowElement(historicActivityInstances.get(i + <span class="hljs-number"><span class="hljs-number"><span class="hljs-number"><span class="hljs-number">1</span></span></span></span>).getActivityId());<span class="hljs-comment"><span class="hljs-comment"><span class="hljs-comment"><span class="hljs-comment">// 找到紧跟在后面的一个节点</span></span></span></span>
  86. <span class="hljs-comment"><span class="hljs-comment"><span class="hljs-comment"><span class="hljs-comment">// 返回</span></span></span></span>
  87. <span class="hljs-keyword"><span class="hljs-keyword"><span class="hljs-keyword"><span class="hljs-keyword">return</span></span></span></span> sameActivityImpl;
  88. }
  89. <span class="hljs-comment"><span class="hljs-comment"><span class="hljs-comment"><span class="hljs-comment">// 遍历后续节点,获取当前节点后续节点</span></span></span></span>
  90. <span class="hljs-keyword"><span class="hljs-keyword"><span class="hljs-keyword"><span class="hljs-keyword">for</span></span></span></span> (<span class="hljs-keyword"><span class="hljs-keyword"><span class="hljs-keyword"><span class="hljs-keyword">int</span></span></span></span> k = i + <span class="hljs-number"><span class="hljs-number"><span class="hljs-number"><span class="hljs-number">1</span></span></span></span>; k <= historicActivityInstances.size() - <span class="hljs-number"><span class="hljs-number"><span class="hljs-number"><span class="hljs-number">1</span></span></span></span>; k++) {
  91. <span class="hljs-comment"><span class="hljs-comment"><span class="hljs-comment"><span class="hljs-comment">// 后续节点</span></span></span></span>
  92. HistoricActivityInstance activityImp2_ = historicActivityInstances.get(k);
  93. <span class="hljs-comment"><span class="hljs-comment"><span class="hljs-comment"><span class="hljs-comment">// 都是userTask,且主节点与后续节点的开始时间相同,说明不是真实的后继节点</span></span></span></span>
  94. <span class="hljs-keyword"><span class="hljs-keyword"><span class="hljs-keyword"><span class="hljs-keyword">if</span></span></span></span>(<span class="hljs-string"><span class="hljs-string"><span class="hljs-string"><span class="hljs-string">"userTask"</span></span></span></span>.equals(activityImp2_.getActivityType()) && activityImpl_.getStartTime().getTime() == activityImp2_.getStartTime().getTime()) <span class="hljs-keyword"><span class="hljs-keyword"><span class="hljs-keyword"><span class="hljs-keyword">continue</span></span></span></span>;
  95. <span class="hljs-comment"><span class="hljs-comment"><span class="hljs-comment"><span class="hljs-comment">// 找到紧跟在后面的一个节点</span></span></span></span>
  96. sameActivityImpl = (FlowNode) bpmnModel.getMainProcess().getFlowElement(historicActivityInstances.get(k).getActivityId());
  97. <span class="hljs-keyword"><span class="hljs-keyword"><span class="hljs-keyword"><span class="hljs-keyword">break</span></span></span></span>;
  98. }
  99. <span class="hljs-keyword"><span class="hljs-keyword"><span class="hljs-keyword"><span class="hljs-keyword">return</span></span></span></span> sameActivityImpl;
  100. }
  101. }
  102. <span class="hljs-comment"><span class="hljs-comment"><span class="hljs-comment"><span class="hljs-comment">// 用以保存后续开始时间相同的节点</span></span></span></span>
  103. List<FlowNode> sameStartTimeNodes = <span class="hljs-keyword"><span class="hljs-keyword"><span class="hljs-keyword"><span class="hljs-keyword">new</span></span></span></span> ArrayList<FlowNode>();
  104. <span class="hljs-comment"><span class="hljs-comment"><span class="hljs-comment"><span class="hljs-comment">// 获取下一个节点(用于连线)</span></span></span></span>
  105. FlowNode sameActivityImpl = getNextFlowNode(bpmnModel, historicActivityInstances, i, activityImpl_);
  106. <span class="hljs-comment"><span class="hljs-comment"><span class="hljs-comment"><span class="hljs-comment">// 将后面第一个节点放在时间相同节点的集合里</span></span></span></span>
  107. <span class="hljs-keyword"><span class="hljs-keyword"><span class="hljs-keyword"><span class="hljs-keyword">if</span></span></span></span>(sameActivityImpl != <span class="hljs-keyword"><span class="hljs-keyword"><span class="hljs-keyword"><span class="hljs-keyword">null</span></span></span></span>) sameStartTimeNodes.add(sameActivityImpl);
  108. <span class="hljs-comment"><span class="hljs-comment"><span class="hljs-comment"><span class="hljs-comment">// 循环后面节点,看是否有与此后继节点开始时间相同的节点,有则添加到后继节点集合</span></span></span></span>
  109. <span class="hljs-keyword"><span class="hljs-keyword"><span class="hljs-keyword"><span class="hljs-keyword">for</span></span></span></span> (<span class="hljs-keyword"><span class="hljs-keyword"><span class="hljs-keyword"><span class="hljs-keyword">int</span></span></span></span> j = i + <span class="hljs-number"><span class="hljs-number"><span class="hljs-number"><span class="hljs-number">1</span></span></span></span>; j < historicActivityInstances.size() - <span class="hljs-number"><span class="hljs-number"><span class="hljs-number"><span class="hljs-number">1</span></span></span></span>; j++) {
  110. HistoricActivityInstance activityImpl1 = historicActivityInstances.get(j);<span class="hljs-comment"><span class="hljs-comment"><span class="hljs-comment"><span class="hljs-comment">// 后续第一个节点</span></span></span></span>
  111. HistoricActivityInstance activityImpl2 = historicActivityInstances.get(j + <span class="hljs-number"><span class="hljs-number"><span class="hljs-number"><span class="hljs-number">1</span></span></span></span>);<span class="hljs-comment"><span class="hljs-comment"><span class="hljs-comment"><span class="hljs-comment">// 后续第二个节点</span></span></span></span>
  112. <span class="hljs-keyword"><span class="hljs-keyword"><span class="hljs-keyword"><span class="hljs-keyword">if</span></span></span></span> (activityImpl1.getStartTime().getTime() != activityImpl2.getStartTime().getTime()) <span class="hljs-keyword"><span class="hljs-keyword"><span class="hljs-keyword"><span class="hljs-keyword">break</span></span></span></span>;
  113. <span class="hljs-comment"><span class="hljs-comment"><span class="hljs-comment"><span class="hljs-comment">// 如果第一个节点和第二个节点开始时间相同保存</span></span></span></span>
  114. FlowNode sameActivityImpl2 = (FlowNode) bpmnModel.getMainProcess().getFlowElement(activityImpl2.getActivityId());
  115. sameStartTimeNodes.add(sameActivityImpl2);
  116. }
  117. <span class="hljs-comment"><span class="hljs-comment"><span class="hljs-comment"><span class="hljs-comment">// 得到节点定义的详细信息</span></span></span></span>
  118. FlowNode activityImpl = (FlowNode) bpmnModel.getMainProcess().getFlowElement(historicActivityInstances.get(i).getActivityId());
  119. <span class="hljs-comment"><span class="hljs-comment"><span class="hljs-comment"><span class="hljs-comment">// 取出节点的所有出去的线,对所有的线进行遍历</span></span></span></span>
  120. List<SequenceFlow> pvmTransitions = activityImpl.getOutgoingFlows();
  121. <span class="hljs-keyword"><span class="hljs-keyword"><span class="hljs-keyword"><span class="hljs-keyword">for</span></span></span></span> (SequenceFlow pvmTransition : pvmTransitions) {
  122. <span class="hljs-comment"><span class="hljs-comment"><span class="hljs-comment"><span class="hljs-comment">// 获取节点</span></span></span></span>
  123. FlowNode pvmActivityImpl = (FlowNode) bpmnModel.getMainProcess().getFlowElement(pvmTransition.getTargetRef());
  124. <span class="hljs-comment"><span class="hljs-comment"><span class="hljs-comment"><span class="hljs-comment">// 不是后继节点</span></span></span></span>
  125. <span class="hljs-keyword"><span class="hljs-keyword"><span class="hljs-keyword"><span class="hljs-keyword">if</span></span></span></span>(!sameStartTimeNodes.contains(pvmActivityImpl)) <span class="hljs-keyword"><span class="hljs-keyword"><span class="hljs-keyword"><span class="hljs-keyword">continue</span></span></span></span>;
  126. <span class="hljs-comment"><span class="hljs-comment"><span class="hljs-comment"><span class="hljs-comment">// 如果取出的线的目标节点存在时间相同的节点里,保存该线的id,进行高亮显示</span></span></span></span>
  127. highFlows.add(pvmTransition.getId());
  128. }
  129. }
  130. <span class="hljs-comment"><span class="hljs-comment"><span class="hljs-comment"><span class="hljs-comment">//返回高亮的线</span></span></span></span>
  131. <span class="hljs-keyword"><span class="hljs-keyword"><span class="hljs-keyword"><span class="hljs-keyword">return</span></span></span></span> highFlows;
  132. }
  133. <span class="hljs-comment"><span class="hljs-comment"><span class="hljs-comment"><span class="hljs-comment">/**
  134. * <p>获取下一个节点信息</p>
  135. * </span></span></span><span class="hljs-doctag"><span class="hljs-comment"><span class="hljs-doctag"><span class="hljs-comment"><span class="hljs-doctag"><span class="hljs-comment"><span class="hljs-doctag">@param</span></span></span></span></span></span></span><span class="hljs-comment"><span class="hljs-comment"><span class="hljs-comment"> bpmnModel 流程模型
  136. * </span></span></span><span class="hljs-doctag"><span class="hljs-comment"><span class=
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小蓝xlanll/article/detail/408131
推荐阅读
相关标签
  

闽ICP备14008679号