|
|
@@ -2,6 +2,8 @@ package com.fs.aiSipCall.service.impl;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.fasterxml.jackson.core.type.TypeReference;
|
|
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import com.fs.aiSipCall.RemoteCommon;
|
|
|
import com.fs.aiSipCall.domain.AiSipCallOutboundCdr;
|
|
|
import com.fs.aiSipCall.domain.CcCustInfo;
|
|
|
@@ -12,8 +14,14 @@ import com.fs.aiSipCall.service.IAiSipCallOutboundCdrService;
|
|
|
import com.fs.aiSipCall.utils.DateUtils;
|
|
|
import com.fs.aiSipCall.vo.ApiCallRecordQueryVo;
|
|
|
import com.fs.common.core.domain.AjaxResult;
|
|
|
+import com.fs.common.core.redis.RedisCache;
|
|
|
+import com.fs.company.domain.CompanyAiWorkflowExec;
|
|
|
import com.fs.company.domain.CompanyVoiceRoboticCallLogCallphone;
|
|
|
+import com.fs.company.mapper.CompanyAiWorkflowExecMapper;
|
|
|
import com.fs.company.mapper.CompanyVoiceRoboticCallLogCallphoneMapper;
|
|
|
+import com.fs.company.mapper.EasyCallMapper;
|
|
|
+import com.fs.company.param.ExecutionContext;
|
|
|
+import com.fs.company.vo.easycall.EasyCallCallPhoneVO;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
@@ -21,6 +29,7 @@ import org.springframework.scheduling.annotation.Async;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.net.URLEncoder;
|
|
|
+import java.time.LocalDateTime;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.CompletableFuture;
|
|
|
import java.util.concurrent.atomic.AtomicBoolean;
|
|
|
@@ -38,6 +47,18 @@ public class AiSipCallOutboundCdrServiceImpl extends ServiceImpl<AiSipCallOutbou
|
|
|
|
|
|
@Autowired
|
|
|
private CompanyVoiceRoboticCallLogCallphoneMapper companyVoiceRoboticCallLogCallphoneMapper;
|
|
|
+ @Autowired
|
|
|
+ private RedisCache redisCache;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private EasyCallMapper easyCallMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private CompanyAiWorkflowExecMapper currentExecutionMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ObjectMapper objectMapper;
|
|
|
+
|
|
|
|
|
|
@Override
|
|
|
public AiSipCallOutboundCdr selectAiSipCallOutboundCdrById(String id) {
|
|
|
@@ -451,92 +472,48 @@ public class AiSipCallOutboundCdrServiceImpl extends ServiceImpl<AiSipCallOutbou
|
|
|
|
|
|
String callType = StringUtils.isBlank(req.getCallType()) ? "03" : req.getCallType();
|
|
|
|
|
|
- // 1. 先查本地是否已存在,防重复
|
|
|
-// CompanyVoiceRoboticCallLogCallphone exist = companyVoiceRoboticCallLogCallphoneMapper.selectByCallbackUuid(req.getUuid());
|
|
|
-// if (exist != null) {
|
|
|
-// log.info("通话记录已存在,无需重复同步,uuid={}", req.getUuid());
|
|
|
-// return 1;
|
|
|
-// }
|
|
|
-
|
|
|
- // 2. 调远程接口按 uuid 查询
|
|
|
- ApiCallRecordQueryVo remoteRecord = getRemoteRecordByUuid(req.getUuid(), callType);
|
|
|
- if (remoteRecord == null) {
|
|
|
- log.warn("远程未查到通话记录,uuid={}, callType={}", req.getUuid(), callType);
|
|
|
- return 0;
|
|
|
- }
|
|
|
-
|
|
|
- // 3. 转成本地实体
|
|
|
- CompanyVoiceRoboticCallLogCallphone entity = buildLocalEntity(remoteRecord, callType,2);
|
|
|
-
|
|
|
- // 4. 插入本地表
|
|
|
- return companyVoiceRoboticCallLogCallphoneMapper.insertCompanyVoiceRoboticCallLogCallphone(entity);
|
|
|
- }
|
|
|
-
|
|
|
- private ApiCallRecordQueryVo getRemoteRecordByUuid(String uuid, String callType) {
|
|
|
+ EasyCallCallPhoneVO callPhoneRes = easyCallMapper.getCallPhoneInfoByUuid(req.getUuid());
|
|
|
+ String callBackUuid = UUID.randomUUID().toString();
|
|
|
+ CompanyAiWorkflowExec record = currentExecutionMapper.selectByWorkflowInstanceId(req.getWorkflowInstanceId());
|
|
|
try {
|
|
|
- String url = RemoteCommon.REMOTE_ADDERSS_PREFIX
|
|
|
- + RemoteCommon.QUERY_OUTBOUNDCDR_BYUUID_API
|
|
|
- + "?uuid=" + URLEncoder.encode(uuid, "UTF-8")
|
|
|
- + "&callType=" + URLEncoder.encode(callType, "UTF-8");
|
|
|
-
|
|
|
- String result = RemoteCommon.sendGet(url);
|
|
|
-
|
|
|
- if (StringUtils.isBlank(result)) {
|
|
|
- log.error("远程查询通话记录失败,返回为空,uuid={}", uuid);
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
- JSONObject jsonObject = JSONObject.parseObject(result);
|
|
|
- Integer code = jsonObject.getInteger("code");
|
|
|
- if (code == null || code != 0) {
|
|
|
- String msg = jsonObject.getString("msg");
|
|
|
- log.error("远程查询通话记录失败,uuid={}, msg={}", uuid, msg);
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
- Object dataObj = jsonObject.get("data");
|
|
|
- if (dataObj == null) {
|
|
|
- return null;
|
|
|
+ Map<String, Object> variablesMap;
|
|
|
+ if (record.getVariables() == null || record.getVariables().isEmpty()) {
|
|
|
+ variablesMap = new HashMap<>();
|
|
|
+ } else {
|
|
|
+ variablesMap = objectMapper.readValue(record.getVariables(), new TypeReference<Map<String, Object>>() {});
|
|
|
}
|
|
|
+ variablesMap.put("callBackUuid", callBackUuid);
|
|
|
+ record.setVariables(objectMapper.writeValueAsString(variablesMap));
|
|
|
|
|
|
- return JSONObject.parseObject(JSONObject.toJSONString(dataObj), ApiCallRecordQueryVo.class);
|
|
|
} catch (Exception e) {
|
|
|
- log.error("远程查询通话记录异常,uuid={}", uuid, e);
|
|
|
- return null;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- private CompanyVoiceRoboticCallLogCallphone buildLocalEntity(ApiCallRecordQueryVo remoteRecord, String callType,Integer status) {
|
|
|
- CompanyVoiceRoboticCallLogCallphone entity = new CompanyVoiceRoboticCallLogCallphone();
|
|
|
-
|
|
|
- entity.setCallbackUuid(null);
|
|
|
- entity.setRoboticId(12345L);
|
|
|
- entity.setCallerId(null);
|
|
|
- entity.setRunTime(null);
|
|
|
- entity.setRunParam(null);
|
|
|
- entity.setResult(null);
|
|
|
- entity.setStatus(status);
|
|
|
- entity.setRecordPath(remoteRecord.getWavFileUrl());
|
|
|
- entity.setCallerNum(remoteRecord.getTelephone());
|
|
|
- entity.setCalleeNum(remoteRecord.getCallerNumber());
|
|
|
- entity.setUuid(remoteRecord.getUuid());
|
|
|
-// entity.setCallCreateTime(Long.valueOf(remoteRecord.getManualAnsweredTime()));
|
|
|
-// entity.setCallAnswerTime(Long.valueOf(remoteRecord.getAnsweredTime()));
|
|
|
- entity.setIntention(null);
|
|
|
- entity.setCompanyId(null);
|
|
|
- entity.setCompanyUserId(null);
|
|
|
- entity.setCallTime(Long.valueOf(remoteRecord.getTimeLen()));
|
|
|
- entity.setCost(null);
|
|
|
- entity.setCallType(Integer.valueOf(callType));
|
|
|
- if (remoteRecord.getDialogue() != null) {
|
|
|
- entity.setContentList(JSONObject.toJSONString(remoteRecord.getDialogue()));
|
|
|
+ log.error("反序列化上下文变量失败", e);
|
|
|
}
|
|
|
|
|
|
- entity.setCreateTime(new Date());
|
|
|
- entity.setUpdateTime(new Date());
|
|
|
|
|
|
- return entity;
|
|
|
+ CompanyVoiceRoboticCallLogCallphone companyVoiceRoboticCallLogCallphone = new CompanyVoiceRoboticCallLogCallphone();
|
|
|
+ companyVoiceRoboticCallLogCallphone.setCallbackUuid(callBackUuid);
|
|
|
+ companyVoiceRoboticCallLogCallphone.setRoboticId(req.getRoboticId());
|
|
|
+ companyVoiceRoboticCallLogCallphone.setCallerId(null);
|
|
|
+ companyVoiceRoboticCallLogCallphone.setRunTime(null);
|
|
|
+ companyVoiceRoboticCallLogCallphone.setRunParam(null);
|
|
|
+ companyVoiceRoboticCallLogCallphone.setResult(null);
|
|
|
+ companyVoiceRoboticCallLogCallphone.setStatus(req.getStatus());
|
|
|
+ companyVoiceRoboticCallLogCallphone.setRecordPath(callPhoneRes.getRecordServerUrl());
|
|
|
+ companyVoiceRoboticCallLogCallphone.setContentList(callPhoneRes.getDialogue());
|
|
|
+ companyVoiceRoboticCallLogCallphone.setCallerNum(callPhoneRes.getTelephone());
|
|
|
+ companyVoiceRoboticCallLogCallphone.setCalleeNum(callPhoneRes.getCallerNumber());
|
|
|
+ companyVoiceRoboticCallLogCallphone.setUuid(req.getUuid());
|
|
|
+ companyVoiceRoboticCallLogCallphone.setCallCreateTime(callPhoneRes.getCalloutTime());
|
|
|
+ companyVoiceRoboticCallLogCallphone.setCallAnswerTime(callPhoneRes.getConnectedTime());
|
|
|
+ companyVoiceRoboticCallLogCallphone.setIntention(callPhoneRes.getIntent());
|
|
|
+ companyVoiceRoboticCallLogCallphone.setCompanyId(req.getCompanyId());
|
|
|
+ companyVoiceRoboticCallLogCallphone.setCompanyUserId(req.getCompanyUserId());
|
|
|
+ companyVoiceRoboticCallLogCallphone.setCallTime(Long.valueOf(callPhoneRes.getTimeLen()));
|
|
|
+ companyVoiceRoboticCallLogCallphone.setCost(callPhoneRes.getTotalCost());
|
|
|
+ companyVoiceRoboticCallLogCallphone.setCallType(Integer.valueOf(callType));
|
|
|
+
|
|
|
+
|
|
|
+ return companyVoiceRoboticCallLogCallphoneMapper.insertCompanyVoiceRoboticCallLogCallphone(companyVoiceRoboticCallLogCallphone);
|
|
|
}
|
|
|
|
|
|
|