|
|
@@ -3,7 +3,11 @@ package com.fs.company.service.impl;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.math.RoundingMode;
|
|
|
import java.util.Date;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.concurrent.CompletableFuture;
|
|
|
+import java.util.concurrent.Executor;
|
|
|
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
@@ -15,6 +19,7 @@ import com.fs.aicall.domain.apiresult.PushIIntentionResult;
|
|
|
import com.fs.aicall.domain.param.getDialogMapDomain;
|
|
|
import com.fs.aicall.service.AiCallService;
|
|
|
import com.fs.common.constant.Constants;
|
|
|
+import com.fs.common.core.redis.RedisCache;
|
|
|
import com.fs.common.utils.DateUtils;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.fs.common.utils.StringUtils;
|
|
|
@@ -22,12 +27,14 @@ import com.fs.company.domain.*;
|
|
|
import com.fs.company.mapper.CompanyVoiceRoboticBusinessMapper;
|
|
|
import com.fs.company.mapper.CompanyVoiceRoboticCalleesMapper;
|
|
|
import com.fs.company.mapper.CompanyWxAccountMapper;
|
|
|
+import com.fs.company.service.CompanyWorkflowEngine;
|
|
|
import com.fs.company.vo.CidConfigVO;
|
|
|
import com.fs.store.config.StoreConfig;
|
|
|
import com.fs.system.service.ISysConfigService;
|
|
|
import com.fs.voice.constant.Constant;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Qualifier;
|
|
|
import org.springframework.scheduling.annotation.Async;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import com.fs.company.mapper.CompanyVoiceRoboticCallLogCallphoneMapper;
|
|
|
@@ -55,6 +62,13 @@ public class CompanyVoiceRoboticCallLogCallphoneServiceImpl extends ServiceImpl<
|
|
|
CompanyVoiceRoboticCalleesMapper companyVoiceRoboticCalleesMapper;
|
|
|
@Autowired
|
|
|
CompanyVoiceRoboticBusinessMapper companyVoiceRoboticBusinessMapper;
|
|
|
+ @Autowired
|
|
|
+ RedisCache redisCache2;
|
|
|
+ @Autowired
|
|
|
+ CompanyWorkflowEngine companyWorkflowEngine;
|
|
|
+ @Autowired
|
|
|
+ @Qualifier("cidWorkFlowExecutor")
|
|
|
+ private Executor cidWorkFlowExecutor;
|
|
|
|
|
|
/**
|
|
|
* 查询调用日志_ai打电话
|
|
|
@@ -133,7 +147,7 @@ public class CompanyVoiceRoboticCallLogCallphoneServiceImpl extends ServiceImpl<
|
|
|
try {
|
|
|
callPhoneLog.setCreateTime(DateUtils.getNowDate());
|
|
|
baseMapper.insertCompanyVoiceRoboticCallLogCallphone(callPhoneLog);
|
|
|
- companyVoiceRoboticBusinessMapper.updateActionCount(2,callPhoneLog.getRoboticId(),callPhoneLog.getCallerId(),null);
|
|
|
+ companyVoiceRoboticBusinessMapper.updateActionCount(2, callPhoneLog.getRoboticId(), callPhoneLog.getCallerId(), null);
|
|
|
} catch (Exception e) {
|
|
|
log.error("记录任务执行日志失败:失败数据:{}", callPhoneLog, e);
|
|
|
}
|
|
|
@@ -146,8 +160,11 @@ public class CompanyVoiceRoboticCallLogCallphoneServiceImpl extends ServiceImpl<
|
|
|
@Autowired
|
|
|
private ISysConfigService configService;
|
|
|
|
|
|
+ public static final String WORKFLOW_CALL_ONE_REDIS_KEY = "workflowCallOne:uuid:";
|
|
|
+
|
|
|
private static final BigDecimal DEFAULT_CALL_CHARGE = new BigDecimal("0.12");
|
|
|
private static final BigDecimal ONE_MINUTES_SECOND = new BigDecimal("60");
|
|
|
+
|
|
|
@Async("callLogExcutor")
|
|
|
public void asyncHandleCalleeCallBackResult(PushIIntentionResult result, CompanyVoiceRoboticCallees callees) {
|
|
|
try {
|
|
|
@@ -165,8 +182,8 @@ public class CompanyVoiceRoboticCallLogCallphoneServiceImpl extends ServiceImpl<
|
|
|
// updateCallees.setRunTaskFlow(runTaskFlow);
|
|
|
// companyVoiceRoboticCalleesMapper.updateById(updateCallees);
|
|
|
// }
|
|
|
- String json= configService.selectConfigByKey("cid.config");
|
|
|
- if(StringUtils.isBlank( json)){
|
|
|
+ String json = configService.selectConfigByKey("cid.config");
|
|
|
+ if (StringUtils.isBlank(json)) {
|
|
|
log.error("未配置cid.config");
|
|
|
}
|
|
|
CidConfigVO cidConfigVO = JSONUtil.toBean(json, CidConfigVO.class);
|
|
|
@@ -175,7 +192,7 @@ public class CompanyVoiceRoboticCallLogCallphoneServiceImpl extends ServiceImpl<
|
|
|
String uuid = notify.getUuid();
|
|
|
|
|
|
|
|
|
- if(StringUtils.isNotBlank(uuid)){
|
|
|
+ if (StringUtils.isNotBlank(uuid)) {
|
|
|
getDialogMapDomain getDialogMap = getDialogMapDomain.builder()
|
|
|
.uuid(uuid)
|
|
|
.build();
|
|
|
@@ -193,19 +210,19 @@ public class CompanyVoiceRoboticCallLogCallphoneServiceImpl extends ServiceImpl<
|
|
|
// 写入其他记录
|
|
|
JSONObject telData = dialogMap.getTelData();
|
|
|
companyVoiceRoboticCallLog.setRecordPath((String) telData.getOrDefault("recordPath", ""));
|
|
|
- companyVoiceRoboticCallLog.setContentList(telData.containsKey("contentList")?telData.getJSONArray("contentList").toJSONString() : "");
|
|
|
+ companyVoiceRoboticCallLog.setContentList(telData.containsKey("contentList") ? telData.getJSONArray("contentList").toJSONString() : "");
|
|
|
companyVoiceRoboticCallLog.setCallerNum((String) telData.getOrDefault("callerNum", ""));
|
|
|
companyVoiceRoboticCallLog.setCalleeNum((String) telData.getOrDefault("calleeNum", ""));
|
|
|
companyVoiceRoboticCallLog.setUuid((String) telData.getOrDefault("uuid", ""));
|
|
|
- Long createTime = telData.getLong("createTime");
|
|
|
+ Long createTime = telData.getLong("createTime");
|
|
|
companyVoiceRoboticCallLog.setCallCreateTime(createTime);
|
|
|
- Long answerTime = telData.getLong("answerTime");
|
|
|
+ Long answerTime = telData.getLong("answerTime");
|
|
|
companyVoiceRoboticCallLog.setCallAnswerTime(answerTime);
|
|
|
companyVoiceRoboticCallLog.setIntention((String) telData.getOrDefault("intention", ""));
|
|
|
- companyVoiceRoboticCallLog.setCallTime( telData.getLong("duration"));
|
|
|
+ companyVoiceRoboticCallLog.setCallTime(telData.getLong("duration"));
|
|
|
BigDecimal callCharge = cidConfigVO.getCallCharge();
|
|
|
//
|
|
|
- if(null == callCharge){
|
|
|
+ if (null == callCharge) {
|
|
|
callCharge = DEFAULT_CALL_CHARGE;
|
|
|
}
|
|
|
//向上取整分钟数
|
|
|
@@ -213,34 +230,50 @@ public class CompanyVoiceRoboticCallLogCallphoneServiceImpl extends ServiceImpl<
|
|
|
BigDecimal multiply = divide.multiply(callCharge);
|
|
|
companyVoiceRoboticCallLog.setCost(multiply);
|
|
|
baseMapper.updateCompanyVoiceRoboticCallLogCallphone(companyVoiceRoboticCallLog);
|
|
|
+
|
|
|
+ if (StringUtils.isNotBlank(notify.getUserData())) {
|
|
|
+ JSONObject userData = JSONObject.parseObject(redisCache2.getCacheObject(WORKFLOW_CALL_ONE_REDIS_KEY + notify.getUserData()), JSONObject.class);
|
|
|
+ if (null != userData && userData.containsKey("callBackUuid") && userData.containsKey("workflowInstanceId") && userData.containsKey("nodeKey")) {
|
|
|
+ Map<String, Object> param = new HashMap<>();
|
|
|
+ param.put("callBackUuid", userData.getString("callBackUuid"));
|
|
|
+ param.put("callSource", "callBack");
|
|
|
+ CompletableFuture.runAsync(() -> {
|
|
|
+ companyWorkflowEngine.resumeFromBlockingNode(userData.getString("workflowInstanceId"), userData.getString("nodeKey"), param);
|
|
|
+ }, cidWorkFlowExecutor).thenRun(() -> {
|
|
|
+ redisCache2.deleteObject(WORKFLOW_CALL_ONE_REDIS_KEY + notify.getUserData());
|
|
|
+ });
|
|
|
+ }
|
|
|
+ redisCache2.deleteObject(notify.getUserData());
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
} catch (Exception ex) {
|
|
|
log.error("处理回调结果异常:{}", result, ex);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
@Async("callLogExcutor")
|
|
|
public void asyncInsertCompanyVoiceRoboticCallLogBatch(List<CompanyVoiceRoboticCallLogCallphone> list) {
|
|
|
- try{
|
|
|
- list.stream().forEach(i->i.setCreateTime(new Date()));
|
|
|
+ try {
|
|
|
+ list.stream().forEach(i -> i.setCreateTime(new Date()));
|
|
|
this.saveBatch(list);
|
|
|
} catch (Exception e) {
|
|
|
- log.error("批量记录任务执行日志失败:失败数据:{}",list, e);
|
|
|
+ log.error("批量记录任务执行日志失败:失败数据:{}", list, e);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public CompanyVoiceRoboticCallLogCallphone selectLogByRoboticIdAndCallerId(Long roboticId,Long callerId){
|
|
|
- return baseMapper.selectLogByRoboticIdAndCallerId(roboticId,callerId);
|
|
|
+ public CompanyVoiceRoboticCallLogCallphone selectLogByRoboticIdAndCallerId(Long roboticId, Long callerId) {
|
|
|
+ return baseMapper.selectLogByRoboticIdAndCallerId(roboticId, callerId);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public List<CompanyVoiceRoboticCallLogCallphone> selectCompanyVoiceRoboticCallLogCallphoneListData(CompanyVoiceRoboticCallLogCallphone companyVoiceRoboticCallLogCallphone){
|
|
|
+ public List<CompanyVoiceRoboticCallLogCallphone> selectCompanyVoiceRoboticCallLogCallphoneListData(CompanyVoiceRoboticCallLogCallphone companyVoiceRoboticCallLogCallphone) {
|
|
|
List<CompanyVoiceRoboticCallLogCallphone> result = baseMapper.selectCompanyVoiceRoboticCallLogCallphoneListData(companyVoiceRoboticCallLogCallphone);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public List<Long> getCallerIdsByCustomerId(Long customerId){
|
|
|
+ public List<Long> getCallerIdsByCustomerId(Long customerId) {
|
|
|
return companyVoiceRoboticCalleesMapper.getCallerIdsByCustomerId(customerId);
|
|
|
}
|
|
|
}
|