Forráskód Böngészése

feat: 一些优化和问题修复

wuwenyi 1 hete
szülő
commit
3bab445ad6

+ 2 - 1
src/main/java/com/qqflow/engine/domain/flow/mapper/ProcessInstanceMapper.java

@@ -14,7 +14,8 @@ public interface ProcessInstanceMapper extends BaseMapper<ProcessInstance> {
             @Param("status") Integer status,
             @Param("definitionName") String definitionName,
             @Param("currentNodeName") String currentNodeName,
-            @Param("applicantName") String applicantName);
+            @Param("applicantName") String applicantName,
+            @Param("processDefinitionId") Long processDefinitionId);
 
     com.baomidou.mybatisplus.extension.plugins.pagination.Page<ProcessInstance> selectParticipatedList(
             com.baomidou.mybatisplus.extension.plugins.pagination.Page<ProcessInstance> page,

+ 8 - 0
src/main/java/com/qqflow/engine/domain/flow/service/impl/FlowEngineServiceImpl.java

@@ -362,6 +362,14 @@ public class FlowEngineServiceImpl implements FlowEngineService {
             nextNodes = Collections.singletonList(targetNode);
         } else {
             nextNodes = this.getNextNodes(model, lockedTask.getNodeId(), instance);
+            // 如果不带条件表达式存在多分支(非 start/end),需要手动选择
+            List<FlowNode> allDownstream = this.getNextNodes(model, lockedTask.getNodeId());
+            long nonStartEnd = allDownstream.stream()
+                    .filter(n -> !NodeType.START.getCode().equals(n.getType()) && !NodeType.END.getCode().equals(n.getType()))
+                    .count();
+            if (nonStartEnd > 1) {
+                throw new BusinessException("当前节点存在多个下游分支,请指定目标节点");
+            }
         }
         if (this.isEndNode(nextNodes)) {
             this.completeInstance(instance);

+ 2 - 8
src/main/java/com/qqflow/engine/domain/flow/service/impl/ProcessInstanceServiceImpl.java

@@ -111,7 +111,7 @@ public class ProcessInstanceServiceImpl implements ProcessInstanceService {
     @Override
     public PageResult<ProcessInstanceDTO> list(Long applicantId, Integer status, String definitionName, String currentNodeName, String applicantName, Integer pageNum, Integer pageSize) {
         Page<ProcessInstance> page = new Page<>(pageNum, pageSize);
-        this.processInstanceMapper.selectInstanceList(page, applicantId, status, definitionName, currentNodeName, applicantName);
+        this.processInstanceMapper.selectInstanceList(page, applicantId, status, definitionName, currentNodeName, applicantName, null);
         List<ProcessInstanceDTO> records = this.enrichInstanceDtos(page.getRecords());
         if (currentNodeName != null && !currentNodeName.isBlank()) {
             records = records.stream()
@@ -595,10 +595,7 @@ public class ProcessInstanceServiceImpl implements ProcessInstanceService {
         ProcessDefinition oldDef = this.processDefinitionMapper.selectById(oldDefinitionId);
         ProcessDefinition newDef = this.processDefinitionMapper.selectById(targetDefinitionId);
         if (oldDef == null || newDef == null) throw new BusinessException("流程定义不存在");
-        if (!Objects.equals(oldDef.getProcessCode(), newDef.getProcessCode())) {
-            throw new BusinessException("只能迁移到同一流程编码的不同版本");
-        }
-        // 匹配当前节点在新定义中的位置(按节点名称)
+        // 按节点名称匹配(不限制 process_code)
         FlowModel oldModel = this.flowEngineService.parseModel(oldDef.getModelJson());
         FlowModel newModel = this.flowEngineService.parseModel(newDef.getModelJson());
         String currentNodeId = instance.getCurrentNodeId();
@@ -637,9 +634,6 @@ public class ProcessInstanceServiceImpl implements ProcessInstanceService {
         ProcessDefinition oldDef = this.processDefinitionMapper.selectById(fromDefinitionId);
         ProcessDefinition newDef = this.processDefinitionMapper.selectById(toDefinitionId);
         if (oldDef == null || newDef == null) throw new BusinessException("流程定义不存在");
-        if (!Objects.equals(oldDef.getProcessCode(), newDef.getProcessCode())) {
-            throw new BusinessException("只能迁移到同一流程编码的不同版本");
-        }
         FlowModel oldModel = this.flowEngineService.parseModel(oldDef.getModelJson());
         FlowModel newModel = this.flowEngineService.parseModel(newDef.getModelJson());
         // 构建旧节点名 → 新节点ID映射

+ 3 - 0
src/main/resources/mapper/flow/ProcessInstanceMapper.xml

@@ -34,6 +34,9 @@
         <if test="status != null">
             AND pi.status = #{status}
         </if>
+        <if test="processDefinitionId != null">
+            AND pi.process_definition_id = #{processDefinitionId}
+        </if>
         <if test="definitionName != null and definitionName != ''">
             AND pd.process_name = #{definitionName}
         </if>