|
|
@@ -5,7 +5,6 @@ import java.math.RoundingMode;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.CompletableFuture;
|
|
|
import java.util.concurrent.Executor;
|
|
|
-import java.util.stream.Collectors;
|
|
|
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
@@ -16,7 +15,6 @@ import com.fs.aicall.domain.apiresult.Notify;
|
|
|
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.domain.entity.SysDictData;
|
|
|
import com.fs.common.core.redis.RedisCache;
|
|
|
import com.fs.common.utils.DateUtils;
|
|
|
@@ -25,18 +23,14 @@ import com.fs.common.utils.StringUtils;
|
|
|
import com.fs.company.domain.*;
|
|
|
import com.fs.company.mapper.*;
|
|
|
import com.fs.company.service.CompanyWorkflowEngine;
|
|
|
-import com.fs.company.vo.CidConfigVO;
|
|
|
-import com.fs.company.vo.CompanyVoiceRoboticCallLogCallPhoneVO;
|
|
|
-import com.fs.company.vo.CompanyVoiceRoboticCallLogCount;
|
|
|
-import com.fs.company.vo.DictVO;
|
|
|
+import com.fs.company.vo.*;
|
|
|
import com.fs.company.vo.easycall.EasyCallCallPhoneVO;
|
|
|
+import com.fs.crm.service.ICrmCustomerAnalyzeService;
|
|
|
import com.fs.crm.service.ICrmCustomerPropertyService;
|
|
|
import com.fs.qw.domain.QwUser;
|
|
|
import com.fs.qw.mapper.QwUserMapper;
|
|
|
-import com.fs.store.config.StoreConfig;
|
|
|
import com.fs.system.service.ISysConfigService;
|
|
|
import com.fs.system.service.impl.SysDictTypeServiceImpl;
|
|
|
-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;
|
|
|
@@ -77,6 +71,8 @@ public class CompanyVoiceRoboticCallLogCallphoneServiceImpl extends ServiceImpl<
|
|
|
@Autowired
|
|
|
QwUserMapper qwUserMapper;
|
|
|
@Autowired
|
|
|
+ private ICrmCustomerAnalyzeService crmCustomerAnalyzeService;
|
|
|
+ @Autowired
|
|
|
@Qualifier("cidWorkFlowExecutor")
|
|
|
private Executor cidWorkFlowExecutor;
|
|
|
|
|
|
@@ -252,7 +248,7 @@ public class CompanyVoiceRoboticCallLogCallphoneServiceImpl extends ServiceImpl<
|
|
|
baseMapper.updateCompanyVoiceRoboticCallLogCallphone(companyVoiceRoboticCallLog);
|
|
|
|
|
|
if (StringUtils.isNotBlank(notify.getUserData())) {
|
|
|
- JSONObject userData = JSONObject.parseObject(redisCache2.getCacheObject(WORKFLOW_CALL_ONE_REDIS_KEY + notify.getUserData()), JSONObject.class);
|
|
|
+ JSONObject userData = parseRedisCacheToJsonObject(redisCache2.getCacheObject(WORKFLOW_CALL_ONE_REDIS_KEY + notify.getUserData()));
|
|
|
if (null != userData && userData.containsKey("callBackUuid") && userData.containsKey("workflowInstanceId") && userData.containsKey("nodeKey")) {
|
|
|
Map<String, Object> param = new HashMap<>();
|
|
|
param.put("callBackUuid", userData.getString("callBackUuid"));
|
|
|
@@ -313,16 +309,32 @@ public class CompanyVoiceRoboticCallLogCallphoneServiceImpl extends ServiceImpl<
|
|
|
companyVoiceRoboticCallLog.setCallCreateTime(createTime);
|
|
|
Long answerTime = result.getCallEndTime();
|
|
|
companyVoiceRoboticCallLog.setCallAnswerTime(answerTime);
|
|
|
- String intention = result.getIntent();
|
|
|
+ String intention = null;
|
|
|
+ if (StringUtils.isNotBlank(result.getDialogue())) {
|
|
|
+ try {
|
|
|
+ intention = crmCustomerAnalyzeService.aiIntentionDegree(
|
|
|
+ result.getDialogue(),
|
|
|
+ java.time.LocalTime.now().getLong(java.time.temporal.ChronoField.MILLI_OF_SECOND)
|
|
|
+ );
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("easyCall回调日志意向度AI解析失败,uuid={}", result.getUuid(), e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 历史第三方值(当前不启用,保留用于回滚)
|
|
|
+ // String intention = result.getIntent();
|
|
|
String intentf = null;
|
|
|
+ final String intentionLabel = intention;
|
|
|
List<SysDictData> customerIntentionLevel = sysDictTypeService.selectDictDataByType("customer_intention_level");
|
|
|
- if (!isPositiveInteger(intention)) {
|
|
|
- Optional<SysDictData> firstDict = customerIntentionLevel.stream().filter(e -> e.getDictLabel().equals(intention)).findFirst();
|
|
|
+ if (!isPositiveInteger(intentionLabel)) {
|
|
|
+ Optional<SysDictData> firstDict = customerIntentionLevel.stream().filter(e -> e.getDictLabel().equals(intentionLabel)).findFirst();
|
|
|
if (firstDict.isPresent()) {
|
|
|
SysDictData sysDictData = firstDict.get();
|
|
|
intentf = sysDictData.getDictValue();
|
|
|
}
|
|
|
+ } else {
|
|
|
+ intentf = intentionLabel;
|
|
|
}
|
|
|
+ if (StringUtils.isBlank(intentf)) intentf = "0";
|
|
|
companyVoiceRoboticCallLog.setIntention(intentf);
|
|
|
companyVoiceRoboticCallLog.setCallTime(Long.valueOf(result.getTimeLen()/1000));
|
|
|
BigDecimal callCharge = cidConfigVO.getCallCharge();
|
|
|
@@ -340,7 +352,7 @@ public class CompanyVoiceRoboticCallLogCallphoneServiceImpl extends ServiceImpl<
|
|
|
|
|
|
if (StringUtils.isNotBlank(result.getBizJson())) {
|
|
|
JSONObject bizJson = JSONObject.parseObject(result.getBizJson());
|
|
|
- JSONObject userData = JSONObject.parseObject(redisCache2.getCacheObject(EASYCALL_WORKFLOW_REDIS_KEY + bizJson.getString("callBackUuid")), JSONObject.class);
|
|
|
+ JSONObject userData = parseRedisCacheToJsonObject(redisCache2.getCacheObject(EASYCALL_WORKFLOW_REDIS_KEY + bizJson.getString("callBackUuid")));
|
|
|
if (null != userData && userData.containsKey("callBackUuid") && userData.containsKey("workflowInstanceId") && userData.containsKey("nodeKey")) {
|
|
|
Map<String, Object> param = new HashMap<>();
|
|
|
param.put("callBackUuid", userData.getString("callBackUuid"));
|
|
|
@@ -380,6 +392,41 @@ public class CompanyVoiceRoboticCallLogCallphoneServiceImpl extends ServiceImpl<
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public List<CustomerRoboticCallOutCountVO> countRoboticCallOutByCustomerIds(List<Long> customerIds, Long companyId) {
|
|
|
+ if (customerIds == null || customerIds.isEmpty()) {
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
+ return baseMapper.countRoboticCallOutByCustomerIds(customerIds, companyId);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<CalleeRoboticCallOutCountVO> countRoboticCallOutByCalleeIds(List<Long> calleeIds, Long roboticId, Long companyId) {
|
|
|
+ if (calleeIds == null || calleeIds.isEmpty() || roboticId == null) {
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
+ return baseMapper.countRoboticCallOutByCalleeIds(calleeIds, roboticId, companyId);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * Redis 中 workflow 回调缓存可能是 String 或已反序列化的 JSONObject,避免 ClassCastException。
|
|
|
+ */
|
|
|
+ private static JSONObject parseRedisCacheToJsonObject(Object cacheObj) {
|
|
|
+ if (cacheObj == null) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ if (cacheObj instanceof JSONObject) {
|
|
|
+ return (JSONObject) cacheObj;
|
|
|
+ }
|
|
|
+ if (cacheObj instanceof String) {
|
|
|
+ String s = (String) cacheObj;
|
|
|
+ if (StringUtils.isBlank(s)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ return JSONObject.parseObject(s);
|
|
|
+ }
|
|
|
+ return JSONObject.parseObject(JSONObject.toJSONString(cacheObj));
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public List<Long> getCallerIdsByCustomerId(Long customerId) {
|
|
|
return companyVoiceRoboticCalleesMapper.getCallerIdsByCustomerId(customerId);
|