perf(办公管理): 优化 退回任务限制只能退回串行节点

This commit is contained in:
konbai
2023-04-22 22:33:47 +08:00
parent 227edcf152
commit f5c4095ecb
3 changed files with 91 additions and 51 deletions

View File

@@ -1,7 +1,7 @@
package com.ruoyi.workflow.service;
import com.ruoyi.workflow.domain.bo.WfTaskBo;
import org.flowable.bpmn.model.UserTask;
import org.flowable.bpmn.model.FlowElement;
import org.flowable.engine.runtime.ProcessInstance;
import java.io.InputStream;
@@ -42,7 +42,7 @@ public interface IWfTaskService {
* @param bo
* @return
*/
List<UserTask> findReturnTaskList(WfTaskBo bo);
List<FlowElement> findReturnTaskList(WfTaskBo bo);
/**
* 删除任务

View File

@@ -167,36 +167,18 @@ public class WfTaskServiceImpl extends FlowServiceFactory implements IWfTaskServ
}
// 获取流程定义信息
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionId(task.getProcessDefinitionId()).singleResult();
// 获取所有节点信息
Process process = repositoryService.getBpmnModel(processDefinition.getId()).getProcesses().get(0);
// 获取全部节点列表,包含子节点
Collection<FlowElement> allElements = FlowableUtils.getAllElements(process.getFlowElements(), null);
// 获取流程模型信息
BpmnModel bpmnModel = repositoryService.getBpmnModel(processDefinition.getId());
// 获取当前任务节点元素
FlowElement source = null;
FlowElement source = ModelUtils.getFlowElementById(bpmnModel, task.getTaskDefinitionKey());
// 获取跳转的节点元素
FlowElement target = null;
if (allElements != null) {
for (FlowElement flowElement : allElements) {
// 当前任务节点元素
if (flowElement.getId().equals(task.getTaskDefinitionKey())) {
source = flowElement;
}
// 跳转的节点元素
if (flowElement.getId().equals(bo.getTargetKey())) {
target = flowElement;
}
}
}
// 从当前节点向前扫描
// 如果存在路线上不存在目标节点,说明目标节点是在网关上或非同一路线上,不可跳转
// 否则目标节点相对于当前节点,属于串行
Boolean isSequential = FlowableUtils.iteratorCheckSequentialReferTarget(source, bo.getTargetKey(), null, null);
FlowElement target = ModelUtils.getFlowElementById(bpmnModel, bo.getTargetKey());
// 从当前节点向前扫描,判断当前节点与目标节点是否属于串行,若目标节点是在并行网关上或非同一路线上,不可跳转
boolean isSequential = ModelUtils.isSequentialReachable(source, target, new HashSet<>());
if (!isSequential) {
throw new RuntimeException("当前节点相对于目标节点,不属于串行关系,无法回退");
}
// 获取所有正常进行的任务节点 Key这些任务不能直接使用需要找出其中需要撤回的任务
List<Task> runTaskList = taskService.createTaskQuery().processInstanceId(task.getProcessInstanceId()).list();
List<String> runTaskKeyList = new ArrayList<>();
@@ -245,38 +227,36 @@ public class WfTaskServiceImpl extends FlowServiceFactory implements IWfTaskServ
* @return
*/
@Override
public List<UserTask> findReturnTaskList(WfTaskBo bo) {
public List<FlowElement> findReturnTaskList(WfTaskBo bo) {
// 当前任务 task
Task task = taskService.createTaskQuery().taskId(bo.getTaskId()).singleResult();
// 获取流程定义信息
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionId(task.getProcessDefinitionId()).singleResult();
// 获取所有节点信息,暂不考虑子流程情况
Process process = repositoryService.getBpmnModel(processDefinition.getId()).getProcesses().get(0);
Collection<FlowElement> flowElements = process.getFlowElements();
// 获取流程模型信息
BpmnModel bpmnModel = repositoryService.getBpmnModel(processDefinition.getId());
// 查询历史节点实例
List<HistoricActivityInstance> activityInstanceList = historyService.createHistoricActivityInstanceQuery()
.processInstanceId(task.getProcessInstanceId())
.activityType(BpmnXMLConstants.ELEMENT_TASK_USER)
.finished()
.orderByHistoricActivityInstanceEndTime().asc()
.list();
List<String> activityIdList = activityInstanceList.stream()
.map(HistoricActivityInstance::getActivityId)
.filter(activityId -> !StringUtils.equals(activityId, task.getTaskDefinitionKey()))
.distinct()
.collect(Collectors.toList());
// 获取当前任务节点元素
UserTask source = null;
if (flowElements != null) {
for (FlowElement flowElement : flowElements) {
// 类型为用户节点
if (flowElement.getId().equals(task.getTaskDefinitionKey())) {
source = (UserTask) flowElement;
}
FlowElement source = ModelUtils.getFlowElementById(bpmnModel, task.getTaskDefinitionKey());
List<FlowElement> elementList = new ArrayList<>();
for (String activityId : activityIdList) {
FlowElement target = ModelUtils.getFlowElementById(bpmnModel, activityId);
boolean isSequential = ModelUtils.isSequentialReachable(source, target, new HashSet<>());
if (isSequential) {
elementList.add(target);
}
}
// 获取节点的所有路线
List<List<UserTask>> roads = FlowableUtils.findRoad(source, null, null, null);
// 可回退的节点列表
List<UserTask> userTaskList = new ArrayList<>();
for (List<UserTask> road : roads) {
if (userTaskList.size() == 0) {
// 还没有可回退节点直接添加
userTaskList = road;
} else {
// 如果已有回退节点,则比对取交集部分
userTaskList.retainAll(road);
}
}
return userTaskList;
return elementList;
}
/**