Ver código fonte

Merge remote-tracking branch 'origin/master-ai-cell' into master-ai-cell

zyy 2 semanas atrás
pai
commit
269cd0710f

+ 8 - 0
fs-service/src/main/java/com/fs/company/domain/CompanyAiWorkflowExec.java

@@ -73,5 +73,13 @@ public class CompanyAiWorkflowExec {
     @Excel(name = "业务键值")
     private String businessKey;
 
+    /**
+     * 开始节点key
+     */
+    private String startNodeKey;
+    /**
+     * 结束节点key
+     */
+    private String endNodeKey;
 
 }

+ 4 - 2
fs-service/src/main/java/com/fs/company/service/impl/CompanyWorkflowEngineImpl.java

@@ -74,7 +74,7 @@ public class CompanyWorkflowEngineImpl implements CompanyWorkflowEngine {
 
             // 保存当前执行记录
             saveInitialExecution(workflowInstanceId, workflowDefinitionId,
-                    definition.getStartNodeKey(), context);
+                    definition.getStartNodeKey(), context,definition);
 
             log.info("工作流初始化成功: {} -> {}", workflowInstanceId, workflowDefinitionId);
 
@@ -260,7 +260,7 @@ public class CompanyWorkflowEngineImpl implements CompanyWorkflowEngine {
      * 保存初始执行记录
      */
     private void saveInitialExecution(String workflowInstanceId, Long workflowDefinitionId,
-                                      String startNodeKey, ExecutionContext context) {
+                                      String startNodeKey, ExecutionContext context,CompanyWorkflow workflow) {
 
         try {
             CompanyAiWorkflowExec currentExec = new CompanyAiWorkflowExec();
@@ -274,6 +274,8 @@ public class CompanyWorkflowEngineImpl implements CompanyWorkflowEngine {
             currentExec.setVariables(objectMapper.writeValueAsString(context.getVariables()));
             // 如果有业务键
             currentExec.setBusinessKey(context.getBusinessId());
+            currentExec.setStartNodeKey(workflow.getStartNodeKey());
+            currentExec.setEndNodeKey(workflow.getEndNodeKey());
             currentExecutionMapper.insert(currentExec);
         } catch (JsonProcessingException e) {
             throw new RuntimeException(e);

+ 19 - 0
fs-service/src/main/java/com/fs/company/service/impl/call/node/AbstractWorkflowNode.java

@@ -57,6 +57,10 @@ public abstract class AbstractWorkflowNode implements IWorkflowNode {
 
     @Override
     public ExecutionResult execute(ExecutionContext context) {
+        if(!runnable(context)){
+            log.info("当前流程已到达结束节点,节点执行失败:- {},- {} -,{}" , nodeName, nodeKey, context.getWorkflowInstanceId());
+            return null;
+        }
         log.info("开始执行节点:" + nodeName + " - " + nodeKey);
         // 记录执行开始时间
         long startTime = System.currentTimeMillis();
@@ -92,6 +96,10 @@ public abstract class AbstractWorkflowNode implements IWorkflowNode {
 
     @Override
     public ExecutionResult continueExecute(ExecutionContext context) {
+        if(!runnable(context)){
+            log.info("当前流程已到达结束节点,节点继续执行失败:- {},- {} -,{}" , nodeName, nodeKey, context.getWorkflowInstanceId());
+            return null;
+        }
         RLock lock = null;
         try {
             String lockKey = NODE_EXEC_LOCK_PREFIX + context.getWorkflowInstanceId();
@@ -409,4 +417,15 @@ public abstract class AbstractWorkflowNode implements IWorkflowNode {
         IWorkflowNode node = workflowNodeFactory.createNode(nextNode.getNodeKey(), NodeTypeEnum.fromCode(nextNode.getNodeType()), nextNode.getNodeName(), null);
         node.execute(nextContext);
     }
+
+    /**
+     * 节点是否可以继续执行状态检查
+     * @param context
+     * @return
+     */
+    protected Boolean runnable(ExecutionContext context) {
+        CompanyAiWorkflowExec exec = companyAiWorkflowExecMapper.selectByWorkflowInstanceId(context.getWorkflowInstanceId());
+        return !exec.getCurrentNodeKey().equals(exec.getEndNodeKey());
+    }
+
 }

+ 6 - 0
fs-service/src/main/resources/mapper/company/CompanyAiWorkflowExecMapper.xml

@@ -37,6 +37,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="startTime != null "> and start_time = #{startTime}</if>
             <if test="lastUpdateTime != null "> and last_update_time = #{lastUpdateTime}</if>
             <if test="businessKey != null  and businessKey != ''"> and business_key = #{businessKey}</if>
+            <if test="startNodeKey != null  and startNodeKey != ''"> and start_node_key = #{startNodeKey}</if>
+            <if test="endNodeKey != null  and endNodeKey != ''"> and end_node_key = #{endNodeKey}</if>
         </where>
     </select>
     
@@ -60,6 +62,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="startTime != null">start_time,</if>
             <if test="lastUpdateTime != null">last_update_time,</if>
             <if test="businessKey != null">business_key,</if>
+            <if test="startNodeKey != null">start_node_key,</if>
+            <if test="endNodeKey != null">end_node_key,</if>
          </trim>
         <trim prefix="values (" suffix=")" suffixOverrides=",">
             <if test="id != null">#{id},</if>
@@ -74,6 +78,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="startTime != null">#{startTime},</if>
             <if test="lastUpdateTime != null">#{lastUpdateTime},</if>
             <if test="businessKey != null">#{businessKey},</if>
+            <if test="startNodeKey != null">#{startNodeKey},</if>
+            <if test="endNodeKey != null">#{endNodeKey},</if>
          </trim>
     </insert>