yangys
2025-08-07 a0881c9a8dbff2bf7f3e10255b998b9529c7aef3
blade-service/blade-mdm/src/main/java/org/springblade/mdm/flow/service/FlowCommonService.java
@@ -1,10 +1,18 @@
package org.springblade.mdm.flow.service;
import lombok.AllArgsConstructor;
import org.flowable.engine.HistoryService;
import org.flowable.engine.RuntimeService;
import org.flowable.engine.TaskService;
import org.flowable.engine.history.HistoricProcessInstance;
import org.flowable.engine.runtime.ProcessInstance;
import org.flowable.task.api.Task;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.StringUtil;
import org.springblade.mdm.flow.constants.FlowContants;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestBody;
import java.util.Map;
@@ -12,6 +20,7 @@
@Service
public class FlowCommonService {
   private final RuntimeService runtimeService;
   private final HistoryService historyService;
   /**
    * 根据流程实例id获取definitionKey
@@ -49,7 +58,41 @@
      programProperties.setCraftEdition(String.valueOf(vars.get(FlowContants.CRAFT_EDITION)));
      programProperties.setHasCuredProgram(String.valueOf(vars.get(FlowContants.HAS_CURED_PROGRAM)));
      ProcessInstance processInstance = runtimeService.createProcessInstanceQuery()
         .processInstanceId(processInstanceId)
         .singleResult();
      String processDefinitionKey = processInstance.getProcessDefinitionKey();
      programProperties.setProcessDefinitionKey(processDefinitionKey);
      return programProperties;
   }
   /**
    * 流程是否在进行
    * @param processInstanceId 实例id
    */
   public boolean isProcessInstanceActive(String processInstanceId) {
      if(processInstanceId == null){
         return false;
      }
      // 先查运行时表
      ProcessInstance instance = runtimeService.createProcessInstanceQuery()
         .processInstanceId(processInstanceId)
         .singleResult();
      if (instance != null) {
         return true;
      }
      // 再查历史表确认是否曾经存在
      HistoricProcessInstance historicInstance = historyService.createHistoricProcessInstanceQuery()
         .processInstanceId(processInstanceId)
         .singleResult();
      return historicInstance != null && historicInstance.getEndTime() == null;
   }
}