|
|
@@ -13,17 +13,17 @@ import com.fs.common.core.domain.entity.SysDictData;
|
|
|
import com.fs.common.utils.DateUtils;
|
|
|
import com.fs.crm.domain.CrmCustomerAnalyze;
|
|
|
import com.fs.crm.mapper.CrmCustomerAnalyzeMapper;
|
|
|
+import com.fs.crm.param.PolishingScriptParam;
|
|
|
import com.fs.crm.service.ICrmCustomerAnalyzeService;
|
|
|
import com.fs.crm.utils.CrmCustomerAiTagUtil;
|
|
|
import com.fs.system.mapper.SysDictDataMapper;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.scheduling.annotation.Async;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import java.util.Collections;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
@@ -35,6 +35,7 @@ import java.util.stream.Collectors;
|
|
|
@Service
|
|
|
public class CrmCustomerAnalyzeServiceImpl extends ServiceImpl<CrmCustomerAnalyzeMapper, CrmCustomerAnalyze> implements ICrmCustomerAnalyzeService {
|
|
|
|
|
|
+ private static final Logger log = LoggerFactory.getLogger(CrmCustomerAnalyzeServiceImpl.class);
|
|
|
@Autowired
|
|
|
private SysDictDataMapper sysDictDataMapper;
|
|
|
/**
|
|
|
@@ -114,9 +115,11 @@ public class CrmCustomerAnalyzeServiceImpl extends ServiceImpl<CrmCustomerAnalyz
|
|
|
//ai获取客户画像
|
|
|
@Override
|
|
|
@Async
|
|
|
- public void aiGeneratedCustomerPortrait(String customerId, String dataJson,String logId) {
|
|
|
- Map<String, Object> stringObjectMap = buildRequestParam(Long.valueOf(customerId), dataJson);
|
|
|
- R aiResponse = CrmCustomerAiTagUtil.callAiService(stringObjectMap, Long.valueOf(logId));
|
|
|
+ public void aiGeneratedCustomerPortrait(Long customerId, String dataJson,Long logId) {
|
|
|
+ Map<String, Object> stringObjectMap = buildRequestParam(customerId, dataJson);
|
|
|
+ stringObjectMap.put("modelType","客户画像");
|
|
|
+ log.info("请求参数:{}", stringObjectMap);
|
|
|
+ R aiResponse = CrmCustomerAiTagUtil.callAiService(stringObjectMap, logId);
|
|
|
|
|
|
JSONObject root = JSON.parseObject(JSONUtil.toJsonStr(aiResponse));
|
|
|
|
|
|
@@ -147,7 +150,247 @@ public class CrmCustomerAnalyzeServiceImpl extends ServiceImpl<CrmCustomerAnalyz
|
|
|
}
|
|
|
|
|
|
if (userInfo != null) {
|
|
|
- baseMapper.updateCustomerPortrait(Long.valueOf(customerId),userInfo.toString());
|
|
|
+ CrmCustomerAnalyze crmCustomerAnalyze = new CrmCustomerAnalyze();
|
|
|
+ crmCustomerAnalyze.setCustomerId(customerId);
|
|
|
+ crmCustomerAnalyze.setCustomerPortraitJson(userInfo.toString());
|
|
|
+ baseMapper.updateCustomerPortrait(crmCustomerAnalyze);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Async
|
|
|
+ public void aiCommunicationSummary(Long customerId, String dataJson, Long logId) {
|
|
|
+ Map<String, Object> stringObjectMap = buildRequestParam(customerId, dataJson);
|
|
|
+ stringObjectMap.put("modelType","沟通总结");
|
|
|
+ log.info("请求参数:{}", stringObjectMap);
|
|
|
+ R aiResponse = CrmCustomerAiTagUtil.callAiService(stringObjectMap, logId);
|
|
|
+ JSONObject root = JSON.parseObject(JSONUtil.toJsonStr(aiResponse));
|
|
|
+ System.out.println(aiResponse);
|
|
|
+// 获取 data.responseData
|
|
|
+ JSONArray responseData = root.getJSONObject("data").getJSONArray("responseData");
|
|
|
+
|
|
|
+ JSONArray summary = null;
|
|
|
+
|
|
|
+// 遍历 responseData
|
|
|
+ for (int i = 0; i < responseData.size(); i++) {
|
|
|
+ JSONObject node = responseData.getJSONObject(i);
|
|
|
+ JSONArray historyPreview = node.getJSONArray("historyPreview");
|
|
|
+
|
|
|
+ if (historyPreview != null) {
|
|
|
+ for (int j = 0; j < historyPreview.size(); j++) {
|
|
|
+ JSONObject historyItem = historyPreview.getJSONObject(j);
|
|
|
+
|
|
|
+ // 找到 obj 为 "AI" 的项
|
|
|
+ if ("AI".equals(historyItem.getString("obj"))) {
|
|
|
+ String valueStr = historyItem.getString("value");
|
|
|
+ JSONObject valueObj = JSON.parseObject(valueStr);
|
|
|
+ summary = valueObj.getJSONArray("tagInfos");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (summary != null) break;
|
|
|
+ }
|
|
|
+ StringBuilder summaryText = new StringBuilder();
|
|
|
+ if (summary!= null && !summary.isEmpty()) {
|
|
|
+ for (int i = 0; i < summary.size(); i++) {
|
|
|
+ summaryText.append(summary.get(i)).append(",");
|
|
|
+ }
|
|
|
+ summaryText.delete(summaryText.length()-1,summaryText.length());
|
|
|
+ CrmCustomerAnalyze crmCustomerAnalyze = new CrmCustomerAnalyze();
|
|
|
+ crmCustomerAnalyze.setCustomerId(customerId);
|
|
|
+ crmCustomerAnalyze.setCommunicationSummary(summaryText.toString());
|
|
|
+ baseMapper.updateCustomerPortrait(crmCustomerAnalyze);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Async
|
|
|
+ public void aiCommunicationAbstract(Long customerId, String dataJson, Long logId) {
|
|
|
+ Map<String, Object> stringObjectMap = buildRequestParam(customerId, dataJson);
|
|
|
+ stringObjectMap.put("modelType","沟通摘要");
|
|
|
+ log.info("请求参数:{}", stringObjectMap);
|
|
|
+
|
|
|
+ R aiResponse = CrmCustomerAiTagUtil.callAiService(stringObjectMap, logId);
|
|
|
+ JSONObject root = JSON.parseObject(JSONUtil.toJsonStr(aiResponse));
|
|
|
+
|
|
|
+// 获取 data.responseData
|
|
|
+ JSONArray responseData = root.getJSONObject("data").getJSONArray("responseData");
|
|
|
+
|
|
|
+ String summary = null;
|
|
|
+
|
|
|
+// 遍历 responseData
|
|
|
+ for (int i = 0; i < responseData.size(); i++) {
|
|
|
+ JSONObject node = responseData.getJSONObject(i);
|
|
|
+ JSONArray historyPreview = node.getJSONArray("historyPreview");
|
|
|
+
|
|
|
+ if (historyPreview != null) {
|
|
|
+ for (int j = 0; j < historyPreview.size(); j++) {
|
|
|
+ JSONObject historyItem = historyPreview.getJSONObject(j);
|
|
|
+
|
|
|
+ // 找到 obj 为 "AI" 的项
|
|
|
+ if ("AI".equals(historyItem.getString("obj"))) {
|
|
|
+ String valueStr = historyItem.getString("value");
|
|
|
+ JSONObject valueObj = JSON.parseObject(valueStr);
|
|
|
+ summary = valueObj.getString("userContent");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (summary != null) break;
|
|
|
+ }
|
|
|
+ if (summary != null){
|
|
|
+ CrmCustomerAnalyze c = new CrmCustomerAnalyze();
|
|
|
+ c.setCustomerId(customerId);
|
|
|
+ c.setCommunicationAbstract(summary);
|
|
|
+ baseMapper.updateCustomerPortrait(c);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Async
|
|
|
+ public void aiAttritionLevel(Long customerId, String dataJson, Long logId) {
|
|
|
+ Map<String, Object> stringObjectMap = buildRequestParam(customerId, dataJson);
|
|
|
+ stringObjectMap.put("modelType","流失风险等级");
|
|
|
+ log.info("请求参数:{}", stringObjectMap);
|
|
|
+
|
|
|
+ R aiResponse = CrmCustomerAiTagUtil.callAiService(stringObjectMap, logId);
|
|
|
+ JSONObject root = JSON.parseObject(JSONUtil.toJsonStr(aiResponse));
|
|
|
+
|
|
|
+// 获取 data.responseData
|
|
|
+ JSONArray responseData = root.getJSONObject("data").getJSONArray("responseData");
|
|
|
+
|
|
|
+ String summary = null;
|
|
|
+
|
|
|
+// 遍历 responseData
|
|
|
+ for (int i = 0; i < responseData.size(); i++) {
|
|
|
+ JSONObject node = responseData.getJSONObject(i);
|
|
|
+ JSONArray historyPreview = node.getJSONArray("historyPreview");
|
|
|
+
|
|
|
+ if (historyPreview != null) {
|
|
|
+ for (int j = 0; j < historyPreview.size(); j++) {
|
|
|
+ JSONObject historyItem = historyPreview.getJSONObject(j);
|
|
|
+
|
|
|
+ // 找到 obj 为 "AI" 的项
|
|
|
+ if ("AI".equals(historyItem.getString("obj"))) {
|
|
|
+ String valueStr = historyItem.getString("value");
|
|
|
+ JSONObject valueObj = JSON.parseObject(valueStr);
|
|
|
+ summary = valueObj.getString("tagInfos");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (summary != null) break;
|
|
|
+ }
|
|
|
+ if (summary != null){
|
|
|
+ //todo 响应处理
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Async
|
|
|
+ public void aiCustomerFocus(Long customerId, String dataJson, Long logId) {
|
|
|
+ Map<String, Object> stringObjectMap = buildRequestParam(customerId, dataJson);
|
|
|
+ stringObjectMap.put("modelType","客户关注点");
|
|
|
+ log.info("请求参数:{}", stringObjectMap);
|
|
|
+
|
|
|
+ R aiResponse = CrmCustomerAiTagUtil.callAiService(stringObjectMap, logId);
|
|
|
+ System.out.println(aiResponse);
|
|
|
+ JSONObject root = JSON.parseObject(JSONUtil.toJsonStr(aiResponse));
|
|
|
+
|
|
|
+// 获取 data.responseData
|
|
|
+ JSONArray responseData = root.getJSONObject("data").getJSONArray("responseData");
|
|
|
+
|
|
|
+ JSONArray summary = null;
|
|
|
+
|
|
|
+// 遍历 responseData
|
|
|
+ for (int i = 0; i < responseData.size(); i++) {
|
|
|
+ JSONObject node = responseData.getJSONObject(i);
|
|
|
+ JSONArray historyPreview = node.getJSONArray("historyPreview");
|
|
|
+
|
|
|
+ if (historyPreview != null) {
|
|
|
+ for (int j = 0; j < historyPreview.size(); j++) {
|
|
|
+ JSONObject historyItem = historyPreview.getJSONObject(j);
|
|
|
+
|
|
|
+ // 找到 obj 为 "AI" 的项
|
|
|
+ if ("AI".equals(historyItem.getString("obj"))) {
|
|
|
+ String valueStr = historyItem.getString("value");
|
|
|
+ JSONObject valueObj = JSON.parseObject(valueStr);
|
|
|
+ summary = valueObj.getJSONArray("userContent");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (summary != null) break;
|
|
|
+ }
|
|
|
+ if (summary != null){
|
|
|
+ List<String> list = new ArrayList<String>();
|
|
|
+ summary.forEach(o->{
|
|
|
+ JSONObject jsonObject = (JSONObject) o;
|
|
|
+ list.add(jsonObject.getString("tagName"));
|
|
|
+ });
|
|
|
+ CrmCustomerAnalyze crmCustomerAnalyze = new CrmCustomerAnalyze();
|
|
|
+ crmCustomerAnalyze.setCustomerId(customerId);
|
|
|
+ crmCustomerAnalyze.setCustomerFocusJson(list.toString());
|
|
|
+ baseMapper.updateCustomerPortrait(crmCustomerAnalyze);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String polishingScript(PolishingScriptParam param) {
|
|
|
+ Map<String, Object> requestParam = new HashMap<>();
|
|
|
+ requestParam.put("history", param.getContent());
|
|
|
+ requestParam.put("modelType","话术润色");
|
|
|
+ requestParam.putAll(param.getPortrait());
|
|
|
+
|
|
|
+ // 设置其他参数
|
|
|
+ requestParam.put("tagInfos", Collections.emptyList());
|
|
|
+ requestParam.put("isRepository", "");
|
|
|
+ requestParam.put("userContent", "");
|
|
|
+ requestParam.put("aiContent", "");
|
|
|
+ requestParam.put("likeRatio", "");
|
|
|
+ R aiResponse = CrmCustomerAiTagUtil.callAiService(requestParam, Long.valueOf(param.getChatId()));
|
|
|
+ System.out.println(aiResponse);
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void aiIntentionDegree(Long customerId, String dataJson, Long logId) {
|
|
|
+ Map<String, Object> stringObjectMap = buildRequestParam(customerId, dataJson);
|
|
|
+ stringObjectMap.put("modelType","客户意向度");
|
|
|
+ log.info("请求参数:{}", stringObjectMap);
|
|
|
+
|
|
|
+ R aiResponse = CrmCustomerAiTagUtil.callAiService(stringObjectMap, logId);
|
|
|
+ System.out.println(aiResponse);
|
|
|
+ JSONObject root = JSON.parseObject(JSONUtil.toJsonStr(aiResponse));
|
|
|
+
|
|
|
+// 获取 data.responseData
|
|
|
+ JSONArray responseData = root.getJSONObject("data").getJSONArray("responseData");
|
|
|
+
|
|
|
+ JSONArray summary = null;
|
|
|
+
|
|
|
+// 遍历 responseData
|
|
|
+ for (int i = 0; i < responseData.size(); i++) {
|
|
|
+ JSONObject node = responseData.getJSONObject(i);
|
|
|
+ JSONArray historyPreview = node.getJSONArray("historyPreview");
|
|
|
+
|
|
|
+ if (historyPreview != null) {
|
|
|
+ for (int j = 0; j < historyPreview.size(); j++) {
|
|
|
+ JSONObject historyItem = historyPreview.getJSONObject(j);
|
|
|
+
|
|
|
+ // 找到 obj 为 "AI" 的项
|
|
|
+ if ("AI".equals(historyItem.getString("obj"))) {
|
|
|
+ String valueStr = historyItem.getString("value");
|
|
|
+ JSONObject valueObj = JSON.parseObject(valueStr);
|
|
|
+ summary = valueObj.getJSONArray("userContent");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (summary != null) break;
|
|
|
+ }
|
|
|
+ if (summary != null) {
|
|
|
+ //todo 响应处理
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -156,6 +399,57 @@ public class CrmCustomerAnalyzeServiceImpl extends ServiceImpl<CrmCustomerAnalyz
|
|
|
return baseMapper.selectCrmCustomerAnalyzeListAll(crmCustomerAnalyze);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public String aiIntentionDegree(String content, Long chatId) {
|
|
|
+ Map<String, Object> requestParam = new HashMap<>();
|
|
|
+
|
|
|
+ // 获取各类数据
|
|
|
+ requestParam.put("history", content);
|
|
|
+
|
|
|
+ // 设置其他参数
|
|
|
+ requestParam.put("tagInfos", Collections.emptyList());
|
|
|
+ requestParam.put("isRepository", "");
|
|
|
+ requestParam.put("userContent", "");
|
|
|
+ requestParam.put("aiContent", "");
|
|
|
+ requestParam.put("likeRatio", "");
|
|
|
+ requestParam.put("modelType","客户意向度");
|
|
|
+ log.info("请求参数:{}", requestParam);
|
|
|
+
|
|
|
+ R aiResponse = CrmCustomerAiTagUtil.callAiService(requestParam, chatId);
|
|
|
+ System.out.println(aiResponse);
|
|
|
+ JSONObject root = JSON.parseObject(JSONUtil.toJsonStr(aiResponse));
|
|
|
+
|
|
|
+// 获取 data.responseData
|
|
|
+ JSONArray responseData = root.getJSONObject("data").getJSONArray("responseData");
|
|
|
+
|
|
|
+ JSONArray summary = null;
|
|
|
+
|
|
|
+// 遍历 responseData
|
|
|
+ for (int i = 0; i < responseData.size(); i++) {
|
|
|
+ JSONObject node = responseData.getJSONObject(i);
|
|
|
+ JSONArray historyPreview = node.getJSONArray("historyPreview");
|
|
|
+
|
|
|
+ if (historyPreview != null) {
|
|
|
+ for (int j = 0; j < historyPreview.size(); j++) {
|
|
|
+ JSONObject historyItem = historyPreview.getJSONObject(j);
|
|
|
+
|
|
|
+ // 找到 obj 为 "AI" 的项
|
|
|
+ if ("AI".equals(historyItem.getString("obj"))) {
|
|
|
+ String valueStr = historyItem.getString("value");
|
|
|
+ JSONObject valueObj = JSON.parseObject(valueStr);
|
|
|
+ summary = valueObj.getJSONArray("userContent");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (summary != null) break;
|
|
|
+ }
|
|
|
+ if (summary != null) {
|
|
|
+ //todo 响应处理
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
private Map<String, Object> buildRequestParam(Long customerId,
|
|
|
String communication) {
|
|
|
Map<String, Object> requestParam = new HashMap<>();
|
|
|
@@ -169,7 +463,7 @@ public class CrmCustomerAnalyzeServiceImpl extends ServiceImpl<CrmCustomerAnalyz
|
|
|
likeRatio = (String) userInfo.remove("likeRatio");
|
|
|
}
|
|
|
// 合并数据
|
|
|
- requestParam.putAll(history);
|
|
|
+ requestParam.put("history",communication);
|
|
|
requestParam.putAll(userInfo);
|
|
|
|
|
|
// 设置其他参数
|
|
|
@@ -178,7 +472,6 @@ public class CrmCustomerAnalyzeServiceImpl extends ServiceImpl<CrmCustomerAnalyz
|
|
|
requestParam.put("userContent", "");
|
|
|
requestParam.put("aiContent", "");
|
|
|
requestParam.put("likeRatio", likeRatio);
|
|
|
- requestParam.put("modelType","客户画像");
|
|
|
|
|
|
return requestParam;
|
|
|
}
|
|
|
@@ -189,16 +482,14 @@ public class CrmCustomerAnalyzeServiceImpl extends ServiceImpl<CrmCustomerAnalyz
|
|
|
// userInfo.put("name", crmCustomerAnalyze.getCustomerName()==null?"" : crmCustomerAnalyze.getCustomerName());
|
|
|
List<SysDictData> portraits = sysDictDataMapper.selectDictDataByType(AI_PORTRAIT);
|
|
|
List<String> dictValue = portraits.stream().map(SysDictData::getDictValue).collect(Collectors.toList());
|
|
|
- Map<String, String> portraitMap = portraits.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));
|
|
|
+// Map<String, String> portraitMap = portraits.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));
|
|
|
|
|
|
if (crmCustomerAnalyze.getCustomerPortraitJson() != null){
|
|
|
Map<String, String> portraitList = JSON.parseObject(
|
|
|
crmCustomerAnalyze.getCustomerPortraitJson(),
|
|
|
new TypeReference<Map<String, String>>() {}
|
|
|
);
|
|
|
- portraitList.forEach((k, v)->{
|
|
|
- if(ObjectUtil.isNotEmpty(portraitMap.get(k)))userInfo.put(portraitMap.get(k),v);
|
|
|
- });
|
|
|
+ userInfo.putAll(portraitList);
|
|
|
|
|
|
}else {
|
|
|
dictValue.forEach(o->{
|