|
|
@@ -4,18 +4,18 @@ import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.fs.aicall.domain.result.CalltaskcreateaiCustomizeResult;
|
|
|
import com.fs.common.utils.spring.SpringUtils;
|
|
|
-import com.fs.company.domain.CompanyAiWorkflowExec;
|
|
|
-import com.fs.company.domain.CompanyVoiceRoboticBusiness;
|
|
|
-import com.fs.company.domain.CompanyVoiceRoboticCallees;
|
|
|
-import com.fs.company.domain.CompanyWorkflowEdge;
|
|
|
+import com.fs.company.domain.*;
|
|
|
import com.fs.company.mapper.CompanyWorkflowNodeMapper;
|
|
|
import com.fs.company.param.ExecutionContext;
|
|
|
import com.fs.company.service.ICompanyVoiceRoboticService;
|
|
|
import com.fs.company.service.impl.CompanyVoiceRoboticServiceImpl;
|
|
|
+import com.fs.company.vo.AiCallConfigVO;
|
|
|
import com.fs.company.vo.AiCallWorkflowConditionVo;
|
|
|
import com.fs.company.vo.ExecutionResult;
|
|
|
+import com.fs.enums.ExecutionStatusEnum;
|
|
|
import com.fs.enums.NodeTypeEnum;
|
|
|
|
|
|
+import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
@@ -27,6 +27,7 @@ import java.util.Map;
|
|
|
public class AiCallTaskNode extends AbstractWorkflowNode {
|
|
|
private static final CompanyWorkflowNodeMapper companyWorkflowNodeMapper = SpringUtils.getBean(CompanyWorkflowNodeMapper.class);
|
|
|
private static final ICompanyVoiceRoboticService companyVoiceRoboticService = SpringUtils.getBean(ICompanyVoiceRoboticService.class);
|
|
|
+ public static final String DELAY_CALL_KEY = "aiCallTask:delay:%s:%s:";
|
|
|
|
|
|
public AiCallTaskNode(String nodeKey, String nodeName, Map<String, Object> properties) {
|
|
|
super(nodeKey, nodeName, properties);
|
|
|
@@ -40,45 +41,58 @@ public class AiCallTaskNode extends AbstractWorkflowNode {
|
|
|
*/
|
|
|
@Override
|
|
|
protected ExecutionResult doContinue(ExecutionContext context) {
|
|
|
-
|
|
|
CompanyAiWorkflowExec exec = companyAiWorkflowExecMapper.selectByWorkflowInstanceId(context.getWorkflowInstanceId());
|
|
|
-
|
|
|
List<CompanyWorkflowEdge> edges = companyWorkflowEdgeMapper.selectListByWorkflowIdAndNodeKey(exec.getWorkflowId(), nodeKey);
|
|
|
- //获取外呼回调结果
|
|
|
- CompanyVoiceRoboticCallees callees = super.companyVoiceRoboticBusinessMapper.selectCalleesByBusinessId(Long.valueOf(exec.getBusinessKey()));
|
|
|
+ //获取外呼回调结果日志
|
|
|
+ CompanyVoiceRoboticCallLogCallphone callRes = super.companyVoiceRoboticCallLogCallphoneMapper.selectCallLogByCallbackUuid(context.getVariable("callbackUuid", String.class));
|
|
|
edges.forEach(edge -> {
|
|
|
AiCallWorkflowConditionVo condition = JSONObject.parseObject(edge.getConditionExpr(), AiCallWorkflowConditionVo.class);
|
|
|
+ //拨通
|
|
|
+ if (condition.isCallConnected() && callRes.getCallTime() > 0) {
|
|
|
+ //如果含有意向度过滤
|
|
|
+ if(null != condition.getIntention()){
|
|
|
+ if( condition.getIntention().equals(callRes.getIntention())){
|
|
|
+ this.runNextNode(context,edge);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ this.runNextNode(context,edge);
|
|
|
+ }
|
|
|
+ }
|
|
|
//未拨通
|
|
|
- if (!condition.isCallConnected()) {
|
|
|
+ else if (!condition.isCallConnected() && (Long.valueOf(0).equals(callRes.getCallTime()) || callRes.getCallAnswerTime() == null)) {
|
|
|
+ //延时操作
|
|
|
if (null != condition.getCallTime()) {
|
|
|
-
|
|
|
+ //计算延时分片分钟
|
|
|
+ Date nowDay = new Date(System.currentTimeMillis() + condition.getCallTime() * 60 * 1000);
|
|
|
+ //添加到延时扫描redis
|
|
|
+ super.redisCache.setCacheObject(String.format(DELAY_CALL_KEY, nowDay.getHours(), nowDay.getMinutes()) + exec.getWorkflowInstanceId(), context);
|
|
|
+ super.asyncWorkflowForBlockingNode(context.getWorkflowInstanceId(), context.getCurrentNodeKey(), context, ExecutionStatusEnum.WAITING);
|
|
|
+ }
|
|
|
+ //无时间驱动
|
|
|
+ else {
|
|
|
+ this.runNextNode(context,edge);
|
|
|
}
|
|
|
- }
|
|
|
- //拨通
|
|
|
- else {
|
|
|
-
|
|
|
}
|
|
|
});
|
|
|
- //加入到计时组
|
|
|
-
|
|
|
- //同步监听回调回调
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
protected ExecutionResult doExecute(ExecutionContext context) {
|
|
|
if (isAsync()) {
|
|
|
-
|
|
|
+ //当前节点信息
|
|
|
+ CompanyWorkflowNode node = companyWorkflowNodeMapper.selectNodeByNodeKey(context.getCurrentNodeKey());
|
|
|
+ String nodeConfig = node.getNodeConfig();
|
|
|
+ AiCallConfigVO callConfigVo = JSONObject.parseObject(nodeConfig, AiCallConfigVO.class);
|
|
|
//执行外呼逻辑 需要传入节点信息
|
|
|
CompanyVoiceRoboticBusiness bus = super.getRoboticBusiness(context.getWorkflowInstanceId());
|
|
|
- CalltaskcreateaiCustomizeResult result = companyVoiceRoboticService.workflowCallPhoneOne(bus.getRoboticId(), bus.getCalleeId(), context.getWorkflowInstanceId());
|
|
|
-
|
|
|
-
|
|
|
+ companyVoiceRoboticService.workflowCallPhoneOne(bus.getRoboticId(), bus.getCalleeId(), context.getWorkflowInstanceId(), callConfigVo);
|
|
|
+ super.asyncWorkflowForBlockingNode(context.getWorkflowInstanceId(), context.getCurrentNodeKey(), context, ExecutionStatusEnum.PAUSED);
|
|
|
return ExecutionResult.paused()
|
|
|
- .nextNodeKey(getNextNodeKey(context.getWorkflowInstanceId(), nodeKey)).build();
|
|
|
+ .nextNodeKey("").build();
|
|
|
} else {
|
|
|
- return ExecutionResult.success()
|
|
|
- .nextNodeKey(getNextNodeKey(context.getWorkflowInstanceId(), nodeKey)).build();
|
|
|
+ return ExecutionResult.failure()
|
|
|
+ .nextNodeKey("").build();
|
|
|
}
|
|
|
|
|
|
}
|
|
|
@@ -116,4 +130,16 @@ public class AiCallTaskNode extends AbstractWorkflowNode {
|
|
|
//没有满足的节点
|
|
|
return null;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 运行下一个节点
|
|
|
+ * @param context
|
|
|
+ * @param edge
|
|
|
+ */
|
|
|
+ private void runNextNode(ExecutionContext context, CompanyWorkflowEdge edge){
|
|
|
+ ExecutionContext nextContext = context.clone();
|
|
|
+ nextContext.setCurrentNodeKey(edge.getTargetNodeKey());
|
|
|
+ super.execPointNextNode(nextContext);
|
|
|
+ super.execute(nextContext);
|
|
|
+ }
|
|
|
}
|