|
@@ -634,6 +634,73 @@ public class FlowTaskServiceImpl extends FlowServiceFactory implements IFlowTask
|
634
|
634
|
*/
|
635
|
635
|
@Override
|
636
|
636
|
public AjaxResult revokeProcess(FlowTaskVo flowTaskVo) {
|
|
637
|
+// if (taskService.createTaskQuery().taskId(flowTaskVo.getTaskId()).singleResult().isSuspended()) {
|
|
638
|
+// throw new CustomException("任务处于挂起状态");
|
|
639
|
+// }
|
|
640
|
+// // 当前任务 task
|
|
641
|
+// Task task = taskService.createTaskQuery().taskId(flowTaskVo.getTaskId()).singleResult();
|
|
642
|
+// // 获取流程定义信息
|
|
643
|
+// ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionId(task.getProcessDefinitionId()).singleResult();
|
|
644
|
+// // 获取所有节点信息
|
|
645
|
+// Process process = repositoryService.getBpmnModel(processDefinition.getId()).getProcesses().get(0);
|
|
646
|
+// // 获取全部节点列表,包含子节点
|
|
647
|
+// Collection<FlowElement> allElements = FlowableUtils.getAllElements(process.getFlowElements(), null);
|
|
648
|
+// // 获取当前任务节点元素
|
|
649
|
+// FlowElement source = null;
|
|
650
|
+// // 获取跳转的节点元素
|
|
651
|
+// FlowElement target = null;
|
|
652
|
+// if (allElements != null) {
|
|
653
|
+// for (FlowElement flowElement : allElements) {
|
|
654
|
+// // 当前任务节点元素
|
|
655
|
+// if (flowElement.getId().equals(task.getTaskDefinitionKey())) {
|
|
656
|
+// source = flowElement;
|
|
657
|
+// }
|
|
658
|
+// // 跳转的节点元素
|
|
659
|
+// if (flowElement.getId().equals(flowTaskVo.getTargetKey())) {
|
|
660
|
+// target = flowElement;
|
|
661
|
+// }
|
|
662
|
+// }
|
|
663
|
+// }
|
|
664
|
+//
|
|
665
|
+// // 从当前节点向前扫描
|
|
666
|
+// // 如果存在路线上不存在目标节点,说明目标节点是在网关上或非同一路线上,不可跳转
|
|
667
|
+// // 否则目标节点相对于当前节点,属于串行
|
|
668
|
+// Boolean isSequential = FlowableUtils.iteratorCheckSequentialReferTarget(source, flowTaskVo.getTargetKey(), null, null);
|
|
669
|
+// if (!isSequential) {
|
|
670
|
+// throw new CustomException("当前节点相对于目标节点,不属于串行关系,无法回退");
|
|
671
|
+// }
|
|
672
|
+//
|
|
673
|
+//
|
|
674
|
+// // 获取所有正常进行的任务节点 Key,这些任务不能直接使用,需要找出其中需要撤回的任务
|
|
675
|
+// List<Task> runTaskList = taskService.createTaskQuery().processInstanceId(task.getProcessInstanceId()).list();
|
|
676
|
+// List<String> runTaskKeyList = new ArrayList<>();
|
|
677
|
+// runTaskList.forEach(item -> runTaskKeyList.add(item.getTaskDefinitionKey()));
|
|
678
|
+// // 需退回任务列表
|
|
679
|
+// List<String> currentIds = new ArrayList<>();
|
|
680
|
+// // 通过父级网关的出口连线,结合 runTaskList 比对,获取需要撤回的任务
|
|
681
|
+// List<UserTask> currentUserTaskList = FlowableUtils.iteratorFindChildUserTasks(target, runTaskKeyList, null, null);
|
|
682
|
+// currentUserTaskList.forEach(item -> currentIds.add(item.getId()));
|
|
683
|
+//
|
|
684
|
+// // 循环获取那些需要被撤回的节点的ID,用来设置驳回原因
|
|
685
|
+// List<String> currentTaskIds = new ArrayList<>();
|
|
686
|
+// currentIds.forEach(currentId -> runTaskList.forEach(runTask -> {
|
|
687
|
+// if (currentId.equals(runTask.getTaskDefinitionKey())) {
|
|
688
|
+// currentTaskIds.add(runTask.getId());
|
|
689
|
+// }
|
|
690
|
+// }));
|
|
691
|
+// // 设置回退意见
|
|
692
|
+// currentTaskIds.forEach(currentTaskId -> taskService.addComment(currentTaskId, task.getProcessInstanceId(), FlowComment.REBACK.getType(), flowTaskVo.getComment()));
|
|
693
|
+//
|
|
694
|
+// try {
|
|
695
|
+// // 1 对 1 或 多 对 1 情况,currentIds 当前要跳转的节点列表(1或多),targetKey 跳转到的节点(1)
|
|
696
|
+// runtimeService.createChangeActivityStateBuilder()
|
|
697
|
+// .processInstanceId(task.getProcessInstanceId())
|
|
698
|
+// .moveActivityIdsToSingleActivityId(currentIds, flowTaskVo.getTargetKey()).changeState();
|
|
699
|
+// } catch (FlowableObjectNotFoundException e) {
|
|
700
|
+// throw new CustomException("未找到流程实例,流程可能已发生变化");
|
|
701
|
+// } catch (FlowableException e) {
|
|
702
|
+// throw new CustomException("无法取消或开始活动");
|
|
703
|
+// }
|
637
|
704
|
Task task = taskService.createTaskQuery().processInstanceId(flowTaskVo.getInstanceId()).singleResult();
|
638
|
705
|
if (task == null) {
|
639
|
706
|
throw new CustomException("流程未启动或已执行完成,无法撤回");
|
|
@@ -646,11 +713,9 @@ public class FlowTaskServiceImpl extends FlowServiceFactory implements IFlowTask
|
646
|
713
|
.asc()
|
647
|
714
|
.list();
|
648
|
715
|
String myTaskId = null;
|
649
|
|
- HistoricTaskInstance myTask = null;
|
650
|
716
|
for (HistoricTaskInstance hti : htiList) {
|
651
|
717
|
if (loginUser.getUserId().toString().equals(hti.getAssignee())) {
|
652
|
718
|
myTaskId = hti.getId();
|
653
|
|
- myTask = hti;
|
654
|
719
|
break;
|
655
|
720
|
}
|
656
|
721
|
}
|
|
@@ -658,28 +723,79 @@ public class FlowTaskServiceImpl extends FlowServiceFactory implements IFlowTask
|
658
|
723
|
throw new CustomException("该任务非当前用户提交,无法撤回");
|
659
|
724
|
}
|
660
|
725
|
|
661
|
|
- String processDefinitionId = myTask.getProcessDefinitionId();
|
662
|
|
- BpmnModel bpmnModel = repositoryService.getBpmnModel(processDefinitionId);
|
|
726
|
+ // 获取流程定义信息
|
|
727
|
+ ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionId(task.getProcessDefinitionId()).singleResult();
|
|
728
|
+ // 获取所有节点信息
|
|
729
|
+ Process process = repositoryService.getBpmnModel(processDefinition.getId()).getProcesses().get(0);
|
|
730
|
+ // 获取全部节点列表,包含子节点
|
|
731
|
+ Collection<FlowElement> allElements = FlowableUtils.getAllElements(process.getFlowElements(), null);
|
|
732
|
+ // 获取当前任务节点元素
|
|
733
|
+ FlowElement source = null;
|
|
734
|
+ // 获取跳转的节点元素
|
|
735
|
+ FlowElement target = null;
|
|
736
|
+ if (allElements != null) {
|
|
737
|
+ for (FlowElement flowElement : allElements) {
|
|
738
|
+ // 当前任务节点元素
|
|
739
|
+ if (flowElement.getId().equals(task.getTaskDefinitionKey())) {
|
|
740
|
+ source = flowElement;
|
|
741
|
+ }
|
|
742
|
+ }
|
|
743
|
+ }
|
663
|
744
|
|
664
|
|
- //变量
|
665
|
|
-// Map<String, VariableInstance> variables = runtimeService.getVariableInstances(currentTask.getExecutionId());
|
666
|
|
- String myActivityId = null;
|
667
|
|
- List<HistoricActivityInstance> haiList = historyService.createHistoricActivityInstanceQuery()
|
668
|
|
- .executionId(myTask.getExecutionId()).finished().list();
|
669
|
|
- for (HistoricActivityInstance hai : haiList) {
|
670
|
|
- if (myTaskId.equals(hai.getTaskId())) {
|
671
|
|
- myActivityId = hai.getActivityId();
|
672
|
|
- break;
|
|
745
|
+ List<UserTask> parentUserTaskList = FlowableUtils.iteratorFindParentUserTasks(source, null, null);
|
|
746
|
+ //仅考虑撤回到其中一个用户任务节点,在没有会签、并行等情况下可以用
|
|
747
|
+ String targetTaskDefinitionId = parentUserTaskList.get(0).getId();
|
|
748
|
+ if (allElements != null) {
|
|
749
|
+ for (FlowElement flowElement : allElements) {
|
|
750
|
+ // 跳转的节点元素
|
|
751
|
+ if (flowElement.getId().equals(targetTaskDefinitionId)) {
|
|
752
|
+ target = flowElement;
|
|
753
|
+ }
|
673
|
754
|
}
|
674
|
755
|
}
|
675
|
|
- FlowNode myFlowNode = (FlowNode) bpmnModel.getMainProcess().getFlowElement(myActivityId);
|
676
|
756
|
|
677
|
|
- Execution execution = runtimeService.createExecutionQuery().executionId(task.getExecutionId()).singleResult();
|
678
|
|
- String activityId = execution.getActivityId();
|
679
|
|
- FlowNode flowNode = (FlowNode) bpmnModel.getMainProcess().getFlowElement(activityId);
|
|
757
|
+ // 获取所有正常进行的任务节点 Key,这些任务不能直接使用,需要找出其中需要撤回的任务
|
|
758
|
+ List<Task> runTaskList = taskService.createTaskQuery().processInstanceId(task.getProcessInstanceId()).list();
|
|
759
|
+ List<String> runTaskKeyList = new ArrayList<>();
|
|
760
|
+ runTaskList.forEach(item -> runTaskKeyList.add(item.getTaskDefinitionKey()));
|
|
761
|
+ // 需退回任务列表
|
|
762
|
+ List<String> currentIds = new ArrayList<>();
|
|
763
|
+ // 通过父级网关的出口连线,结合 runTaskList 比对,获取需要撤回的任务
|
|
764
|
+ List<UserTask> currentUserTaskList = FlowableUtils.iteratorFindChildUserTasks(target, runTaskKeyList, null, null);
|
|
765
|
+ currentUserTaskList.forEach(item -> currentIds.add(item.getId()));
|
680
|
766
|
|
681
|
|
- //记录原活动方向
|
682
|
|
- List<SequenceFlow> oriSequenceFlows = new ArrayList<>(flowNode.getOutgoingFlows());
|
|
767
|
+ try {
|
|
768
|
+ // 1 对 1 或 多 对 1 情况,currentIds 当前要跳转的节点列表(1或多),targetKey 跳转到的节点(1)
|
|
769
|
+ runtimeService.createChangeActivityStateBuilder()
|
|
770
|
+ .processInstanceId(task.getProcessInstanceId())
|
|
771
|
+ .moveActivityIdsToSingleActivityId(currentIds, targetTaskDefinitionId).changeState();
|
|
772
|
+ } catch (FlowableObjectNotFoundException e) {
|
|
773
|
+ throw new CustomException("未找到流程实例,流程可能已发生变化");
|
|
774
|
+ } catch (FlowableException e) {
|
|
775
|
+ throw new CustomException("无法取消或开始活动");
|
|
776
|
+ }
|
|
777
|
+// String processDefinitionId = myTask.getProcessDefinitionId();
|
|
778
|
+// BpmnModel bpmnModel = repositoryService.getBpmnModel(processDefinitionId);
|
|
779
|
+//
|
|
780
|
+// //变量
|
|
781
|
+//// Map<String, VariableInstance> variables = runtimeService.getVariableInstances(currentTask.getExecutionId());
|
|
782
|
+// String myActivityId = null;
|
|
783
|
+// List<HistoricActivityInstance> haiList = historyService.createHistoricActivityInstanceQuery()
|
|
784
|
+// .executionId(myTask.getExecutionId()).finished().list();
|
|
785
|
+// for (HistoricActivityInstance hai : haiList) {
|
|
786
|
+// if (myTaskId.equals(hai.getTaskId())) {
|
|
787
|
+// myActivityId = hai.getActivityId();
|
|
788
|
+// break;
|
|
789
|
+// }
|
|
790
|
+// }
|
|
791
|
+// FlowNode myFlowNode = (FlowNode) bpmnModel.getMainProcess().getFlowElement(myActivityId);
|
|
792
|
+//
|
|
793
|
+// Execution execution = runtimeService.createExecutionQuery().executionId(task.getExecutionId()).singleResult();
|
|
794
|
+// String activityId = execution.getActivityId();
|
|
795
|
+// FlowNode flowNode = (FlowNode) bpmnModel.getMainProcess().getFlowElement(activityId);
|
|
796
|
+//
|
|
797
|
+// //记录原活动方向
|
|
798
|
+// List<SequenceFlow> oriSequenceFlows = new ArrayList<>(flowNode.getOutgoingFlows());
|
683
|
799
|
|
684
|
800
|
|
685
|
801
|
return AjaxResult.success();
|