lmx hace 3 semanas
padre
commit
66aafbd9f8

+ 3 - 6
fs-service/src/main/java/com/fs/company/service/impl/CompanyVoiceRoboticServiceImpl.java

@@ -4,7 +4,6 @@ import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import com.fasterxml.jackson.databind.ObjectMapper;
 import com.fs.aicall.domain.apiresult.Notify;
 import com.fs.aicall.domain.apiresult.PushIIntentionResult;
 import com.fs.aicall.domain.param.CalleeDomain;
@@ -13,7 +12,6 @@ import com.fs.aicall.domain.result.CalltaskcreateaiCustomizeResult;
 import com.fs.aicall.service.AiCallService;
 import com.fs.common.annotation.DataScope;
 import com.fs.common.constant.Constants;
-import com.fs.common.core.domain.R;
 import com.fs.common.core.redis.RedisCacheT;
 import com.fs.common.exception.base.BaseException;
 import com.fs.common.service.impl.SmsServiceImpl;
@@ -29,7 +27,6 @@ import com.fs.crm.param.SmsSendBatchParam;
 import com.fs.crm.service.impl.CrmCustomerServiceImpl;
 import com.fs.system.mapper.SysDictDataMapper;
 import com.fs.system.service.ISysConfigService;
-import lombok.AllArgsConstructor;
 import lombok.RequiredArgsConstructor;
 import lombok.Synchronized;
 import lombok.extern.slf4j.Slf4j;
@@ -97,8 +94,8 @@ public class CompanyVoiceRoboticServiceImpl extends ServiceImpl<CompanyVoiceRobo
     private final CompanyWorkflowEngine companyWorkflowEngine;
 
     @Autowired
-    @Qualifier("workFlowExecutor")
-    Executor workFlowExecutor;
+    @Qualifier("cidWorkFlowExecutor")
+    private Executor cidWorkFlowExecutor;
     /**
      * 查询机器人外呼任务
      *
@@ -641,7 +638,7 @@ public class CompanyVoiceRoboticServiceImpl extends ServiceImpl<CompanyVoiceRobo
                 param.put("callBackUuid",userData.getString("callBackUuid"));
                 CompletableFuture.runAsync(()->{
                     companyWorkflowEngine.resumeFromBlockingNode(userData.getString("workflowInstanceId"),userData.getString("nodeKey"),param);
-                },workFlowExecutor);
+                },cidWorkFlowExecutor);
             }
         }
         long count = companyVoiceRoboticCalleesMapper.countByRoboticIdNotUuid(callee.getRoboticId());

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

@@ -409,23 +409,23 @@ public class CompanyWorkflowEngineImpl implements CompanyWorkflowEngine {
         // 实现根据ID加载工作流定义的逻辑
         return companyWorkflowMapper.selectCompanyWorkflowById(id);
     }
-    /**
-     * 将工作流设置为阻塞状态
-     */
-    private void pauseWorkflowForBlockingNode(String workflowInstanceId, String nodeKey, ExecutionContext context) {
-        try {
-            CompanyAiWorkflowExec update = new CompanyAiWorkflowExec();
-            update.setWorkflowInstanceId(workflowInstanceId);
-            update.setStatus(ExecutionStatusEnum.WAITING.getValue());
-            update.setLastUpdateTime(LocalDateTime.now());
-            update.setVariables(objectMapper.writeValueAsString(context.getVariables()));
-
-            currentExecutionMapper.updateByWorkflowInstanceId(update);
-            log.info("工作流已阻塞在节点: {} -> {}", workflowInstanceId, nodeKey);
-        } catch (Exception e) {
-            log.error("更新工作流阻塞状态失败: {}", workflowInstanceId, e);
-        }
-    }
+//    /**
+//     * 将工作流设置为阻塞状态
+//     */
+//    private void pauseWorkflowForBlockingNode(String workflowInstanceId, String nodeKey, ExecutionContext context) {
+//        try {
+//            CompanyAiWorkflowExec update = new CompanyAiWorkflowExec();
+//            update.setWorkflowInstanceId(workflowInstanceId);
+//            update.setStatus(ExecutionStatusEnum.WAITING.getValue());
+//            update.setLastUpdateTime(LocalDateTime.now());
+//            update.setVariables(objectMapper.writeValueAsString(context.getVariables()));
+//
+//            currentExecutionMapper.updateByWorkflowInstanceId(update);
+//            log.info("工作流已阻塞在节点: {} -> {}", workflowInstanceId, nodeKey);
+//        } catch (Exception e) {
+//            log.error("更新工作流阻塞状态失败: {}", workflowInstanceId, e);
+//        }
+//    }
     @Override
     @Transactional
     public void resumeFromBlockingNode(String workflowInstanceId, String nodeKey, Map<String, Object> inputData) {

+ 15 - 2
fs-service/src/main/java/com/fs/company/service/impl/call/node/AbstractWorkflowNode.java

@@ -3,6 +3,7 @@ package com.fs.company.service.impl.call.node;
 import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.fs.common.core.redis.RedisCache;
+import com.fs.common.exception.CustomException;
 import com.fs.common.utils.spring.SpringUtils;
 import com.fs.company.domain.*;
 import com.fs.company.mapper.*;
@@ -74,7 +75,7 @@ public abstract class AbstractWorkflowNode implements IWorkflowNode {
         try {
             CompanyAiWorkflowExec companyAiWorkflowExec = companyAiWorkflowExecMapper.selectByWorkflowInstanceId(context.getWorkflowInstanceId());
             if (!Integer.valueOf(ExecutionStatusEnum.WAITING.getValue()).equals(companyAiWorkflowExec.getStatus())) {
-                return handleExecutionError(new Exception("状态不符合"), context);
+                return handleExecutionError(new CustomException("状态不符合"), context);
             }
             return doContinue(context);
         } catch (Exception e) {
@@ -85,7 +86,15 @@ public abstract class AbstractWorkflowNode implements IWorkflowNode {
             companyAiWorkflowExecLog.setWorkflowInstanceId(context.getWorkflowInstanceId());
             companyAiWorkflowExecLog.setNodeKey(context.getCurrentNodeKey());
             companyAiWorkflowExecLog.setStatus(ExecutionStatusEnum.PAUSED.getValue());
-            companyAiWorkflowExecLogMapper.selectCompanyAiWorkflowExecLogList(companyAiWorkflowExecLog)
+            List<CompanyAiWorkflowExecLog> companyAiWorkflowExecLogs = companyAiWorkflowExecLogMapper.selectCompanyAiWorkflowExecLogList(companyAiWorkflowExecLog);
+            if(null != companyAiWorkflowExecLogs){
+                CompanyAiWorkflowExecLog fExecLog = companyAiWorkflowExecLogs.get(0);
+                fExecLog.setStatus(ExecutionStatusEnum.SUCCESS.getValue());
+                fExecLog.setEndTime(new Date());
+                long durationInMillis = fExecLog.getEndTime().getTime() - fExecLog.getStartTime().getTime();
+                fExecLog.setDuration(durationInMillis);
+                companyAiWorkflowExecLogMapper.updateById(fExecLog);
+            }
         }
     }
 
@@ -112,6 +121,7 @@ public abstract class AbstractWorkflowNode implements IWorkflowNode {
         Integer logStatus = 0;
         if (result.isSuccess()) {
             logStatus = ExecutionStatusEnum.SUCCESS.getValue();
+            updateWorkflowStatus(context.getWorkflowInstanceId(), ExecutionStatusEnum.SUCCESS);
         } else {
             logStatus = ExecutionStatusEnum.FAILURE.getValue();
             updateWorkflowStatus(context.getWorkflowInstanceId(), ExecutionStatusEnum.FAILURE);
@@ -226,10 +236,13 @@ public abstract class AbstractWorkflowNode implements IWorkflowNode {
             CompanyAiWorkflowExecLog logEntry = new CompanyAiWorkflowExecLog();
             logEntry.setWorkflowInstanceId(workflowInstanceId);
             logEntry.setNodeKey(nodeKey);
+            logEntry.setNodeName(nodeName);
             logEntry.setNodeType(nodeType.getValue());
             logEntry.setStatus(result.getStatus().getValue());
+            logEntry.setInputData(objectMapper.writeValueAsString(context.getVariables()));
             logEntry.setOutputData(objectMapper.writeValueAsString(result.getOutputData()));
             logEntry.setErrorMessage(result.getErrorMessage());
+            logEntry.setCreatedTime(new Date());
             Long startTime = context.getVariable("node_start_time_" + nodeKey, Long.class);
             if (null != startTime) {
                 logEntry.setStartTime(new Date(startTime));

+ 1 - 1
fs-service/src/main/java/com/fs/enums/ExecutionStatusEnum.java

@@ -43,7 +43,7 @@ public enum ExecutionStatusEnum {
     /**
      * 中断
      */
-    TIMEOUT("TIMEOUT", "执行中断", 7);
+    INTERRUPT("INTERRUPT", "执行中断", 8);
 
     private final String code;
     private final String description;

+ 3 - 3
fs-service/src/main/java/com/fs/wxcid/threadExecutor/workFlowExecutor.java → fs-service/src/main/java/com/fs/wxcid/threadExecutor/cidCompanyWorkFlowExecutor.java

@@ -10,10 +10,10 @@ import java.util.concurrent.ThreadPoolExecutor;
 
 @Configuration
 @EnableAsync
-public class workFlowExecutor {
+public class cidCompanyWorkFlowExecutor {
 
-    @Bean("workFlowExecutor")
-    public Executor workFlowExecutor() {
+    @Bean("cidWorkFlowExecutor")
+    public Executor cidWorkFlowExecutor() {
         ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
         executor.setCorePoolSize(8);
         executor.setMaxPoolSize(16);