|
|
@@ -1,6 +1,7 @@
|
|
|
package com.fs.company.service.impl.call.node;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.fs.common.utils.StringUtils;
|
|
|
import com.fs.common.utils.spring.SpringUtils;
|
|
|
import com.fs.company.domain.CompanyAiWorkflowExec;
|
|
|
import com.fs.company.domain.CompanyVoiceRoboticBusiness;
|
|
|
@@ -11,15 +12,19 @@ import com.fs.company.param.ExecutionContext;
|
|
|
import com.fs.company.service.ICompanyVoiceRoboticService;
|
|
|
import com.fs.company.service.IWorkflowNode;
|
|
|
import com.fs.company.vo.AiCallConfigVO;
|
|
|
+import com.fs.company.vo.AiCallWorkflowConditionVo;
|
|
|
+import com.fs.company.vo.AiSendMsgConfigVO;
|
|
|
import com.fs.company.vo.ExecutionResult;
|
|
|
import com.fs.enums.ExecutionStatusEnum;
|
|
|
import com.fs.enums.NodeTypeEnum;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.scheduling.annotation.Async;
|
|
|
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* @author MixLiu
|
|
|
@@ -30,7 +35,7 @@ import java.util.Map;
|
|
|
public class AiSendMsgTaskNode extends AbstractWorkflowNode {
|
|
|
private static final CompanyWorkflowNodeMapper companyWorkflowNodeMapper = SpringUtils.getBean(CompanyWorkflowNodeMapper.class);
|
|
|
|
|
|
- private ICompanyVoiceRoboticService companyVoiceRoboticService;
|
|
|
+ private static final ICompanyVoiceRoboticService companyVoiceRoboticService = SpringUtils.getBean(ICompanyVoiceRoboticService.class);
|
|
|
|
|
|
public AiSendMsgTaskNode(String nodeKey, String nodeName, Map<String, Object> properties) {
|
|
|
super(nodeKey, nodeName, properties);
|
|
|
@@ -44,12 +49,24 @@ public class AiSendMsgTaskNode extends AbstractWorkflowNode {
|
|
|
*/
|
|
|
@Override
|
|
|
protected ExecutionResult doContinue(ExecutionContext context) {
|
|
|
- // 短信发送不需要回调,直接执行下一个节点
|
|
|
- List<CompanyWorkflowEdge> edges = companyWorkflowEdgeMapper.selectListByWorkflowIdAndNodeKey(
|
|
|
- context.getVariable("workflowId", Long.class), nodeKey);
|
|
|
-
|
|
|
- if (edges != null && !edges.isEmpty()) {
|
|
|
- super.runNextNode(context, edges.get(0));
|
|
|
+ CompanyAiWorkflowExec exec = companyAiWorkflowExecMapper.selectByWorkflowInstanceId(context.getWorkflowInstanceId());
|
|
|
+ List<CompanyWorkflowEdge> edges = companyWorkflowEdgeMapper.selectListByWorkflowIdAndNodeKey(exec.getWorkflowId(), nodeKey);
|
|
|
+ //发送短信成功
|
|
|
+ if (true){
|
|
|
+ List<CompanyWorkflowEdge> success = edges.stream().filter(a ->
|
|
|
+ StringUtils.isNotBlank(a.getConditionExpr()) && JSONObject.parseArray(a.getConditionExpr(), AiCallWorkflowConditionVo.class).get(0).isSendStatus())
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ if (!success.isEmpty() && nodeKey.equals(exec.getCurrentNodeKey())) {
|
|
|
+ super.runNextNode(context, success.get(0));
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ //发送短信失败
|
|
|
+ List<CompanyWorkflowEdge> fail = edges.stream().filter(a ->
|
|
|
+ StringUtils.isNotBlank(a.getConditionExpr()) && !JSONObject.parseArray(a.getConditionExpr(), AiCallWorkflowConditionVo.class).get(0).isSendStatus())
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ if (!fail.isEmpty() && nodeKey.equals(exec.getCurrentNodeKey())) {
|
|
|
+ super.runNextNode(context, fail.get(0));
|
|
|
+ }
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
@@ -65,6 +82,10 @@ public class AiSendMsgTaskNode extends AbstractWorkflowNode {
|
|
|
protected ExecutionResult doExecute(ExecutionContext context) {
|
|
|
try {
|
|
|
Thread.sleep(1000L);
|
|
|
+ //设置短信模版
|
|
|
+ CompanyWorkflowNode node = context.getVariable("currentNode", CompanyWorkflowNode.class)==null? getNodeByKey(nodeKey):context.getVariable("currentNode", CompanyWorkflowNode.class);
|
|
|
+ String nodeConfig = node.getNodeConfig();
|
|
|
+ AiSendMsgConfigVO configVO = JSONObject.parseObject(nodeConfig, AiSendMsgConfigVO.class);
|
|
|
// 获取业务数据
|
|
|
CompanyVoiceRoboticBusiness business = super.getRoboticBusiness(context.getWorkflowInstanceId());
|
|
|
if (business == null) {
|
|
|
@@ -76,23 +97,10 @@ public class AiSendMsgTaskNode extends AbstractWorkflowNode {
|
|
|
context.getWorkflowInstanceId(), business.getRoboticId(), business.getCalleeId());
|
|
|
|
|
|
// TODO: 这里可以添加实际的发送短信逻辑
|
|
|
- companyVoiceRoboticService.workflowSendSmsOne(business.getRoboticId(), business.getCalleeId(),context);
|
|
|
- // 更新业务表的发短信动作标记
|
|
|
- companyVoiceRoboticBusinessMapper.updateActionCount(3, business.getRoboticId(),
|
|
|
- business.getCalleeId(), null);
|
|
|
-
|
|
|
- //如果需要等待回调,可以在doContinue方法中处理回调逻辑,并在回调时执行下一个节点
|
|
|
- if(false){
|
|
|
- super.asyncWorkflowForBlockingNode(context.getWorkflowInstanceId(), context.getCurrentNodeKey(), context, ExecutionStatusEnum.PAUSED);
|
|
|
- return ExecutionResult.paused()
|
|
|
- .outputData(context.getVariables())
|
|
|
- .nextNodeKey("").build();
|
|
|
- }
|
|
|
-
|
|
|
+ companyVoiceRoboticService.workflowSendSmsOne(business.getRoboticId(), business.getCalleeId(),context,configVO.getSmsTempId());
|
|
|
//如果不需要等待回调,直接执行下一个节点
|
|
|
log.info("短信发送成功 - workflowInstanceId: {}", context.getWorkflowInstanceId());
|
|
|
super.updateWorkflowStatus(context.getWorkflowInstanceId(), ExecutionStatusEnum.SUCCESS);
|
|
|
- //CompanyVoiceRoboticServiceImpl.sendMsgOne()
|
|
|
// 获取下一个节点并执行
|
|
|
CompanyAiWorkflowExec exec = companyAiWorkflowExecMapper.selectByWorkflowInstanceId(context.getWorkflowInstanceId());
|
|
|
List<CompanyWorkflowEdge> edges = companyWorkflowEdgeMapper.selectListByWorkflowIdAndNodeKey(
|