|
@@ -9,6 +9,7 @@ import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
|
|
+import com.fasterxml.jackson.databind.JsonNode;
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import com.fs.common.core.domain.R;
|
|
import com.fs.common.core.domain.R;
|
|
|
import com.fs.common.core.domain.entity.SysDictData;
|
|
import com.fs.common.core.domain.entity.SysDictData;
|
|
@@ -114,187 +115,194 @@ public class CrmCustomerAnalyzeServiceImpl extends ServiceImpl<CrmCustomerAnalyz
|
|
|
}
|
|
}
|
|
|
private static final String AI_PORTRAIT = "crm_ai_portrait";
|
|
private static final String AI_PORTRAIT = "crm_ai_portrait";
|
|
|
private static final ObjectMapper mapper = new ObjectMapper();
|
|
private static final ObjectMapper mapper = new ObjectMapper();
|
|
|
- @Value("${crm.customer.ai.Key:mygpt-oPG2ifhnq0ODGioOBMUvMfOZGrtCykqw3oMeYLchdUDK5He6iNiactrhFWA0sID}")
|
|
|
|
|
|
|
+ @Value("${crm.customer.ai.Key:mygpt-iTUua2CHVd4WGrBbQQGl1HHjyyBAD1KuXARsxHj5eHpLYv5CfnOh8iwVU}")
|
|
|
private String OTHER_KEY;
|
|
private String OTHER_KEY;
|
|
|
//ai获取客户画像
|
|
//ai获取客户画像
|
|
|
@Override
|
|
@Override
|
|
|
- public void aiGeneratedCustomerPortrait(Long customerId, String dataJson,Long logId) {
|
|
|
|
|
|
|
+ public String aiGeneratedCustomerPortrait(Long customerId, String dataJson, Long logId) {
|
|
|
Map<String, Object> stringObjectMap = buildRequestParam(customerId, dataJson);
|
|
Map<String, Object> stringObjectMap = buildRequestParam(customerId, dataJson);
|
|
|
- stringObjectMap.put("modelType","客户画像");
|
|
|
|
|
- log.info("请求参数:{}", stringObjectMap);
|
|
|
|
|
- R aiResponse = CrmCustomerAiTagUtil.callAiService(stringObjectMap, logId,OTHER_KEY);
|
|
|
|
|
|
|
+ stringObjectMap.put("modelType", "客户画像");
|
|
|
|
|
+// log.info("请求参数:{}", stringObjectMap);
|
|
|
|
|
+ R aiResponse = CrmCustomerAiTagUtil.callAiService(stringObjectMap, logId, OTHER_KEY);
|
|
|
// System.out.println(aiResponse);
|
|
// System.out.println(aiResponse);
|
|
|
- JSONObject root = JSON.parseObject(JSONUtil.toJsonStr(aiResponse));
|
|
|
|
|
|
|
+ String result = "";
|
|
|
|
|
+ try {
|
|
|
|
|
|
|
|
-// 获取 data.responseData
|
|
|
|
|
- JSONArray responseData = root.getJSONObject("data").getJSONArray("responseData");
|
|
|
|
|
|
|
+ JsonNode rootS = mapper.readTree(JSONUtil.toJsonStr(aiResponse));
|
|
|
|
|
+ JsonNode choices = rootS.path("data").path("choices");
|
|
|
|
|
|
|
|
- JSONObject userInfo = null;
|
|
|
|
|
|
|
+ if (choices.isArray() && choices.size() > 0) {
|
|
|
|
|
+ JsonNode contentNode = choices.get(0).path("message").path("content");
|
|
|
|
|
|
|
|
-// 遍历 responseData
|
|
|
|
|
- for (int i = 0; i < responseData.size(); i++) {
|
|
|
|
|
- JSONObject node = responseData.getJSONObject(i);
|
|
|
|
|
- JSONArray historyPreview = node.getJSONArray("historyPreview");
|
|
|
|
|
|
|
+ if (contentNode.isTextual()) {
|
|
|
|
|
+ String contentStr = contentNode.asText();
|
|
|
|
|
+ // 将content字符串解析为JsonNode
|
|
|
|
|
+ JsonNode contentArray = mapper.readTree(contentStr);
|
|
|
|
|
|
|
|
- if (historyPreview != null) {
|
|
|
|
|
- for (int j = 0; j < historyPreview.size(); j++) {
|
|
|
|
|
- JSONObject historyItem = historyPreview.getJSONObject(j);
|
|
|
|
|
|
|
+ if (contentArray.isArray() && contentArray.size() > 1) {
|
|
|
|
|
+ JsonNode secondElement = contentArray.get(1);
|
|
|
|
|
+ JsonNode textNode = secondElement.path("text");
|
|
|
|
|
|
|
|
- // 找到 obj 为 "AI" 的项
|
|
|
|
|
- if ("AI".equals(historyItem.getString("obj"))) {
|
|
|
|
|
- String valueStr = historyItem.getString("value");
|
|
|
|
|
- JSONObject valueObj = JSON.parseObject(valueStr);
|
|
|
|
|
- userInfo = valueObj.getJSONObject("userInfo");
|
|
|
|
|
- break;
|
|
|
|
|
|
|
+ if (!textNode.isMissingNode()) {
|
|
|
|
|
+ JsonNode contentInnerNode = textNode.path("content");
|
|
|
|
|
+
|
|
|
|
|
+ if (contentInnerNode.isTextual()) {
|
|
|
|
|
+ String innerJsonStr = contentInnerNode.asText();
|
|
|
|
|
+ JsonNode innerJson = mapper.readTree(innerJsonStr);
|
|
|
|
|
+ JsonNode userInfo = innerJson.path("userInfo");
|
|
|
|
|
+ result =userInfo.toString();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- if (userInfo != null) break;
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
- if (userInfo != null) {
|
|
|
|
|
- CrmCustomerAnalyze crmCustomerAnalyze = new CrmCustomerAnalyze();
|
|
|
|
|
- crmCustomerAnalyze.setCustomerId(customerId);
|
|
|
|
|
- crmCustomerAnalyze.setCustomerPortraitJson(userInfo.toString());
|
|
|
|
|
- baseMapper.updateCustomerPortrait(crmCustomerAnalyze);
|
|
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
}
|
|
}
|
|
|
|
|
+ return result;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
- public void aiCommunicationSummary(Long customerId, String dataJson, Long logId) {
|
|
|
|
|
|
|
+ public String aiCommunicationSummary(Long customerId, String dataJson, Long logId) {
|
|
|
Map<String, Object> stringObjectMap = buildRequestParam(customerId, dataJson);
|
|
Map<String, Object> stringObjectMap = buildRequestParam(customerId, dataJson);
|
|
|
stringObjectMap.put("modelType","沟通总结");
|
|
stringObjectMap.put("modelType","沟通总结");
|
|
|
- log.info("请求参数:{}", stringObjectMap);
|
|
|
|
|
|
|
+// log.info("请求参数:{}", stringObjectMap);
|
|
|
R aiResponse = CrmCustomerAiTagUtil.callAiService(stringObjectMap, logId,OTHER_KEY);
|
|
R aiResponse = CrmCustomerAiTagUtil.callAiService(stringObjectMap, logId,OTHER_KEY);
|
|
|
- JSONObject root = JSON.parseObject(JSONUtil.toJsonStr(aiResponse));
|
|
|
|
|
-// System.out.println(aiResponse);
|
|
|
|
|
-// 获取 data.responseData
|
|
|
|
|
- JSONArray responseData = root.getJSONObject("data").getJSONArray("responseData");
|
|
|
|
|
|
|
+ String result = "";
|
|
|
|
|
+ try {
|
|
|
|
|
+
|
|
|
|
|
+ JsonNode rootS = mapper.readTree(JSONUtil.toJsonStr(aiResponse));
|
|
|
|
|
+ JsonNode choices = rootS.path("data").path("choices");
|
|
|
|
|
|
|
|
- JSONObject summary = null;
|
|
|
|
|
|
|
+ if (choices.isArray() && choices.size() > 0) {
|
|
|
|
|
+ JsonNode contentNode = choices.get(0).path("message").path("content");
|
|
|
|
|
|
|
|
-// 遍历 responseData
|
|
|
|
|
- for (int i = 0; i < responseData.size(); i++) {
|
|
|
|
|
- JSONObject node = responseData.getJSONObject(i);
|
|
|
|
|
- JSONArray historyPreview = node.getJSONArray("historyPreview");
|
|
|
|
|
|
|
+ if (contentNode.isTextual()) {
|
|
|
|
|
+ String contentStr = contentNode.asText();
|
|
|
|
|
+ // 将content字符串解析为JsonNode
|
|
|
|
|
+ JsonNode contentArray = mapper.readTree(contentStr);
|
|
|
|
|
|
|
|
- if (historyPreview != null) {
|
|
|
|
|
- for (int j = 0; j < historyPreview.size(); j++) {
|
|
|
|
|
- JSONObject historyItem = historyPreview.getJSONObject(j);
|
|
|
|
|
|
|
+ if (contentArray.isArray() && contentArray.size() > 1) {
|
|
|
|
|
+ JsonNode secondElement = contentArray.get(1);
|
|
|
|
|
+ JsonNode textNode = secondElement.path("text");
|
|
|
|
|
|
|
|
- // 找到 obj 为 "AI" 的项
|
|
|
|
|
- if ("AI".equals(historyItem.getString("obj"))) {
|
|
|
|
|
- String valueStr = historyItem.getString("value");
|
|
|
|
|
- JSONObject valueObj = JSON.parseObject(valueStr);
|
|
|
|
|
- summary = valueObj.getJSONObject("userInfo");
|
|
|
|
|
- break;
|
|
|
|
|
|
|
+ if (!textNode.isMissingNode()) {
|
|
|
|
|
+ JsonNode contentInnerNode = textNode.path("content");
|
|
|
|
|
+
|
|
|
|
|
+ if (contentInnerNode.isTextual()) {
|
|
|
|
|
+ String innerJsonStr = contentInnerNode.asText();
|
|
|
|
|
+ JsonNode innerJson = mapper.readTree(innerJsonStr);
|
|
|
|
|
+ JsonNode userInfo = innerJson.path("userInfo");
|
|
|
|
|
+ result = userInfo.get("沟通总结").asText();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- if (summary != null) break;
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
- if (!summary.isEmpty() ) {
|
|
|
|
|
- String summaryText = summary.getString("沟通总结");
|
|
|
|
|
- CrmCustomerAnalyze crmCustomerAnalyze = new CrmCustomerAnalyze();
|
|
|
|
|
- crmCustomerAnalyze.setCustomerId(customerId);
|
|
|
|
|
- crmCustomerAnalyze.setCommunicationSummary(summaryText);
|
|
|
|
|
- baseMapper.updateCustomerPortrait(crmCustomerAnalyze);
|
|
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
}
|
|
}
|
|
|
|
|
+ return result;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
- public void aiCommunicationAbstract(Long customerId, String dataJson, Long logId) {
|
|
|
|
|
|
|
+ public String aiCommunicationAbstract(Long customerId, String dataJson, Long logId) {
|
|
|
Map<String, Object> stringObjectMap = buildRequestParam(customerId, dataJson);
|
|
Map<String, Object> stringObjectMap = buildRequestParam(customerId, dataJson);
|
|
|
stringObjectMap.put("modelType","沟通摘要");
|
|
stringObjectMap.put("modelType","沟通摘要");
|
|
|
stringObjectMap.remove("userInfo");
|
|
stringObjectMap.remove("userInfo");
|
|
|
HashMap<String, String> map = MapUtil.of("沟通摘要", "");
|
|
HashMap<String, String> map = MapUtil.of("沟通摘要", "");
|
|
|
stringObjectMap.put("userInfo", map);
|
|
stringObjectMap.put("userInfo", map);
|
|
|
- log.info("请求参数:{}", stringObjectMap);
|
|
|
|
|
|
|
+// log.info("请求参数:{}", stringObjectMap);
|
|
|
|
|
|
|
|
R aiResponse = CrmCustomerAiTagUtil.callAiService(stringObjectMap, logId,OTHER_KEY);
|
|
R aiResponse = CrmCustomerAiTagUtil.callAiService(stringObjectMap, logId,OTHER_KEY);
|
|
|
- JSONObject root = JSON.parseObject(JSONUtil.toJsonStr(aiResponse));
|
|
|
|
|
// System.out.println(aiResponse);
|
|
// System.out.println(aiResponse);
|
|
|
|
|
|
|
|
-// 获取 data.responseData
|
|
|
|
|
- JSONArray responseData = root.getJSONObject("data").getJSONArray("responseData");
|
|
|
|
|
|
|
+ String result = "";
|
|
|
|
|
+ try {
|
|
|
|
|
+
|
|
|
|
|
+ JsonNode rootS = mapper.readTree(JSONUtil.toJsonStr(aiResponse));
|
|
|
|
|
+ JsonNode choices = rootS.path("data").path("choices");
|
|
|
|
|
+
|
|
|
|
|
+ if (choices.isArray() && choices.size() > 0) {
|
|
|
|
|
+ JsonNode contentNode = choices.get(0).path("message").path("content");
|
|
|
|
|
|
|
|
- JSONObject summary = null;
|
|
|
|
|
|
|
+ if (contentNode.isTextual()) {
|
|
|
|
|
+ String contentStr = contentNode.asText();
|
|
|
|
|
+ // 将content字符串解析为JsonNode
|
|
|
|
|
+ JsonNode contentArray = mapper.readTree(contentStr);
|
|
|
|
|
|
|
|
-// 遍历 responseData
|
|
|
|
|
- for (int i = 0; i < responseData.size(); i++) {
|
|
|
|
|
- JSONObject node = responseData.getJSONObject(i);
|
|
|
|
|
- JSONArray historyPreview = node.getJSONArray("historyPreview");
|
|
|
|
|
|
|
+ if (contentArray.isArray() && contentArray.size() > 1) {
|
|
|
|
|
+ JsonNode secondElement = contentArray.get(1);
|
|
|
|
|
+ JsonNode textNode = secondElement.path("text");
|
|
|
|
|
|
|
|
- if (historyPreview != null) {
|
|
|
|
|
- for (int j = 0; j < historyPreview.size(); j++) {
|
|
|
|
|
- JSONObject historyItem = historyPreview.getJSONObject(j);
|
|
|
|
|
|
|
+ if (!textNode.isMissingNode()) {
|
|
|
|
|
+ JsonNode contentInnerNode = textNode.path("content");
|
|
|
|
|
|
|
|
- // 找到 obj 为 "AI" 的项
|
|
|
|
|
- if ("AI".equals(historyItem.getString("obj"))) {
|
|
|
|
|
- String valueStr = historyItem.getString("value");
|
|
|
|
|
- JSONObject valueObj = JSON.parseObject(valueStr);
|
|
|
|
|
- summary = valueObj.getJSONObject("userInfo");
|
|
|
|
|
- break;
|
|
|
|
|
|
|
+ if (contentInnerNode.isTextual()) {
|
|
|
|
|
+ String innerJsonStr = contentInnerNode.asText();
|
|
|
|
|
+ JsonNode innerJson = mapper.readTree(innerJsonStr);
|
|
|
|
|
+ JsonNode userInfo = innerJson.path("userInfo");
|
|
|
|
|
+ result = userInfo.get("沟通摘要").asText();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- if (summary != null) break;
|
|
|
|
|
- }
|
|
|
|
|
- if (summary != null){
|
|
|
|
|
- CrmCustomerAnalyze c = new CrmCustomerAnalyze();
|
|
|
|
|
- c.setCustomerId(customerId);
|
|
|
|
|
- c.setCommunicationAbstract(summary.getString("沟通摘要"));
|
|
|
|
|
- baseMapper.updateCustomerPortrait(c);
|
|
|
|
|
|
|
+
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
}
|
|
}
|
|
|
|
|
+ return result;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
- public void aiAttritionLevel(Long customerId, String dataJson, Long logId) {
|
|
|
|
|
|
|
+ public Long aiAttritionLevel(Long customerId, String dataJson, Long logId) {
|
|
|
Map<String, Object> stringObjectMap = buildRequestParam(customerId, dataJson);
|
|
Map<String, Object> stringObjectMap = buildRequestParam(customerId, dataJson);
|
|
|
stringObjectMap.put("modelType","流失风险等级");
|
|
stringObjectMap.put("modelType","流失风险等级");
|
|
|
stringObjectMap.remove("userInfo");
|
|
stringObjectMap.remove("userInfo");
|
|
|
HashMap<String, String> map = MapUtil.of("流失风险等级", "");
|
|
HashMap<String, String> map = MapUtil.of("流失风险等级", "");
|
|
|
stringObjectMap.put("userInfo", map);
|
|
stringObjectMap.put("userInfo", map);
|
|
|
- log.info("请求参数:{}", stringObjectMap);
|
|
|
|
|
|
|
+// log.info("请求参数:{}", stringObjectMap);
|
|
|
|
|
|
|
|
R aiResponse = CrmCustomerAiTagUtil.callAiService(stringObjectMap, logId,OTHER_KEY);
|
|
R aiResponse = CrmCustomerAiTagUtil.callAiService(stringObjectMap, logId,OTHER_KEY);
|
|
|
- JSONObject root = JSON.parseObject(JSONUtil.toJsonStr(aiResponse));
|
|
|
|
|
-// System.out.println(aiResponse);
|
|
|
|
|
|
|
+ Long result = null;
|
|
|
|
|
+ try {
|
|
|
|
|
|
|
|
-// 获取 data.responseData
|
|
|
|
|
- JSONArray responseData = root.getJSONObject("data").getJSONArray("responseData");
|
|
|
|
|
|
|
+ JsonNode rootS = mapper.readTree(JSONUtil.toJsonStr(aiResponse));
|
|
|
|
|
+ JsonNode choices = rootS.path("data").path("choices");
|
|
|
|
|
+
|
|
|
|
|
+ if (choices.isArray() && choices.size() > 0) {
|
|
|
|
|
+ JsonNode contentNode = choices.get(0).path("message").path("content");
|
|
|
|
|
|
|
|
- JSONObject summary = null;
|
|
|
|
|
|
|
+ if (contentNode.isTextual()) {
|
|
|
|
|
+ String contentStr = contentNode.asText();
|
|
|
|
|
+ // 将content字符串解析为JsonNode
|
|
|
|
|
+ JsonNode contentArray = mapper.readTree(contentStr);
|
|
|
|
|
|
|
|
-// 遍历 responseData
|
|
|
|
|
- for (int i = 0; i < responseData.size(); i++) {
|
|
|
|
|
- JSONObject node = responseData.getJSONObject(i);
|
|
|
|
|
- JSONArray historyPreview = node.getJSONArray("historyPreview");
|
|
|
|
|
|
|
+ if (contentArray.isArray() && contentArray.size() > 1) {
|
|
|
|
|
+ JsonNode secondElement = contentArray.get(1);
|
|
|
|
|
+ JsonNode textNode = secondElement.path("text");
|
|
|
|
|
|
|
|
- if (historyPreview != null) {
|
|
|
|
|
- for (int j = 0; j < historyPreview.size(); j++) {
|
|
|
|
|
- JSONObject historyItem = historyPreview.getJSONObject(j);
|
|
|
|
|
|
|
+ if (!textNode.isMissingNode()) {
|
|
|
|
|
+ JsonNode contentInnerNode = textNode.path("content");
|
|
|
|
|
|
|
|
- // 找到 obj 为 "AI" 的项
|
|
|
|
|
- if ("AI".equals(historyItem.getString("obj"))) {
|
|
|
|
|
- String valueStr = historyItem.getString("value");
|
|
|
|
|
- JSONObject valueObj = JSON.parseObject(valueStr);
|
|
|
|
|
- summary = valueObj.getJSONObject("userInfo");
|
|
|
|
|
- break;
|
|
|
|
|
|
|
+ if (contentInnerNode.isTextual()) {
|
|
|
|
|
+ String innerJsonStr = contentInnerNode.asText();
|
|
|
|
|
+ JsonNode innerJson = mapper.readTree(innerJsonStr);
|
|
|
|
|
+ String userInfo = innerJson.path("userInfo").path("流失风险等级").asText();
|
|
|
|
|
+ result = getScore(userInfo);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- if (summary != null && !summary.isEmpty()) break;
|
|
|
|
|
- }
|
|
|
|
|
- if (summary != null && !summary.isEmpty()){
|
|
|
|
|
- String level = summary.getString("流失风险等级");
|
|
|
|
|
|
|
|
|
|
- CrmCustomerAnalyze c = new CrmCustomerAnalyze();
|
|
|
|
|
- c.setCustomerId(customerId);
|
|
|
|
|
- c.setAttritionLevel(getScore(level));
|
|
|
|
|
- baseMapper.updateCustomerPortrait(c);
|
|
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
}
|
|
}
|
|
|
|
|
+ return result;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -308,49 +316,52 @@ public class CrmCustomerAnalyzeServiceImpl extends ServiceImpl<CrmCustomerAnalyz
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
- public void aiCustomerFocus(Long customerId, String dataJson, Long logId) {
|
|
|
|
|
|
|
+ public String aiCustomerFocus(Long customerId, String dataJson, Long logId) {
|
|
|
Map<String, Object> stringObjectMap = buildRequestParam(customerId, dataJson);
|
|
Map<String, Object> stringObjectMap = buildRequestParam(customerId, dataJson);
|
|
|
stringObjectMap.put("modelType","客户关注点");
|
|
stringObjectMap.put("modelType","客户关注点");
|
|
|
stringObjectMap.remove("userInfo");
|
|
stringObjectMap.remove("userInfo");
|
|
|
HashMap<String, String> map = MapUtil.of("客户关注点", "");
|
|
HashMap<String, String> map = MapUtil.of("客户关注点", "");
|
|
|
stringObjectMap.put("userInfo", map);
|
|
stringObjectMap.put("userInfo", map);
|
|
|
- log.info("请求参数:{}", stringObjectMap);
|
|
|
|
|
|
|
+// log.info("请求参数:{}", stringObjectMap);
|
|
|
|
|
|
|
|
R aiResponse = CrmCustomerAiTagUtil.callAiService(stringObjectMap, logId,OTHER_KEY);
|
|
R aiResponse = CrmCustomerAiTagUtil.callAiService(stringObjectMap, logId,OTHER_KEY);
|
|
|
// System.out.println(aiResponse);
|
|
// System.out.println(aiResponse);
|
|
|
- JSONObject root = JSON.parseObject(JSONUtil.toJsonStr(aiResponse));
|
|
|
|
|
|
|
+ String result = "";
|
|
|
|
|
+ try {
|
|
|
|
|
|
|
|
-// 获取 data.responseData
|
|
|
|
|
- JSONArray responseData = root.getJSONObject("data").getJSONArray("responseData");
|
|
|
|
|
|
|
+ JsonNode rootS = mapper.readTree(JSONUtil.toJsonStr(aiResponse));
|
|
|
|
|
+ JsonNode choices = rootS.path("data").path("choices");
|
|
|
|
|
+
|
|
|
|
|
+ if (choices.isArray() && choices.size() > 0) {
|
|
|
|
|
+ JsonNode contentNode = choices.get(0).path("message").path("content");
|
|
|
|
|
|
|
|
- JSONObject summary = null;
|
|
|
|
|
|
|
+ if (contentNode.isTextual()) {
|
|
|
|
|
+ String contentStr = contentNode.asText();
|
|
|
|
|
+ // 将content字符串解析为JsonNode
|
|
|
|
|
+ JsonNode contentArray = mapper.readTree(contentStr);
|
|
|
|
|
|
|
|
-// 遍历 responseData
|
|
|
|
|
- for (int i = 0; i < responseData.size(); i++) {
|
|
|
|
|
- JSONObject node = responseData.getJSONObject(i);
|
|
|
|
|
- JSONArray historyPreview = node.getJSONArray("historyPreview");
|
|
|
|
|
|
|
+ if (contentArray.isArray() && contentArray.size() > 1) {
|
|
|
|
|
+ JsonNode secondElement = contentArray.get(1);
|
|
|
|
|
+ JsonNode textNode = secondElement.path("text");
|
|
|
|
|
|
|
|
- if (historyPreview != null) {
|
|
|
|
|
- for (int j = 0; j < historyPreview.size(); j++) {
|
|
|
|
|
- JSONObject historyItem = historyPreview.getJSONObject(j);
|
|
|
|
|
|
|
+ if (!textNode.isMissingNode()) {
|
|
|
|
|
+ JsonNode contentInnerNode = textNode.path("content");
|
|
|
|
|
|
|
|
- // 找到 obj 为 "AI" 的项
|
|
|
|
|
- if ("AI".equals(historyItem.getString("obj"))) {
|
|
|
|
|
- String valueStr = historyItem.getString("value");
|
|
|
|
|
- JSONObject valueObj = JSON.parseObject(valueStr);
|
|
|
|
|
- summary = valueObj.getJSONObject("userInfo");
|
|
|
|
|
- break;
|
|
|
|
|
|
|
+ if (contentInnerNode.isTextual()) {
|
|
|
|
|
+ String innerJsonStr = contentInnerNode.asText();
|
|
|
|
|
+ JsonNode innerJson = mapper.readTree(innerJsonStr);
|
|
|
|
|
+ JsonNode userInfo = innerJson.path("userInfo");
|
|
|
|
|
+ result = userInfo.get("客户关注点").asText();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- if (summary != null && !summary.isEmpty()) break;
|
|
|
|
|
- }
|
|
|
|
|
- if (summary != null && !summary.isEmpty()){
|
|
|
|
|
- CrmCustomerAnalyze crmCustomerAnalyze = new CrmCustomerAnalyze();
|
|
|
|
|
- crmCustomerAnalyze.setCustomerId(customerId);
|
|
|
|
|
- crmCustomerAnalyze.setCustomerFocusJson(summary.getString("客户关注点"));
|
|
|
|
|
- baseMapper.updateCustomerPortrait(crmCustomerAnalyze);
|
|
|
|
|
|
|
+
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
}
|
|
}
|
|
|
|
|
+ return result;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -368,75 +379,93 @@ public class CrmCustomerAnalyzeServiceImpl extends ServiceImpl<CrmCustomerAnalyz
|
|
|
requestParam.put("aiContent", "");
|
|
requestParam.put("aiContent", "");
|
|
|
requestParam.put("likeRatio", "");
|
|
requestParam.put("likeRatio", "");
|
|
|
R aiResponse = CrmCustomerAiTagUtil.callAiService(requestParam, Long.valueOf(param.getChatId()),OTHER_KEY);
|
|
R aiResponse = CrmCustomerAiTagUtil.callAiService(requestParam, Long.valueOf(param.getChatId()),OTHER_KEY);
|
|
|
-// System.out.println(aiResponse);
|
|
|
|
|
- JSONObject root = JSON.parseObject(JSONUtil.toJsonStr(aiResponse));
|
|
|
|
|
- JSONArray responseData = root.getJSONObject("data").getJSONArray("responseData");
|
|
|
|
|
-
|
|
|
|
|
-// 遍历 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);
|
|
|
|
|
- return valueObj.getString("aiContent");
|
|
|
|
|
|
|
+ System.out.println(aiResponse);
|
|
|
|
|
+ String result = "";
|
|
|
|
|
+ try {
|
|
|
|
|
+
|
|
|
|
|
+ JsonNode rootS = mapper.readTree(JSONUtil.toJsonStr(aiResponse));
|
|
|
|
|
+ JsonNode choices = rootS.path("data").path("choices");
|
|
|
|
|
+
|
|
|
|
|
+ if (choices.isArray() && choices.size() > 0) {
|
|
|
|
|
+ JsonNode contentNode = choices.get(0).path("message").path("content");
|
|
|
|
|
+
|
|
|
|
|
+ if (contentNode.isTextual()) {
|
|
|
|
|
+ String contentStr = contentNode.asText();
|
|
|
|
|
+ // 将content字符串解析为JsonNode
|
|
|
|
|
+ JsonNode contentArray = mapper.readTree(contentStr);
|
|
|
|
|
+
|
|
|
|
|
+ if (contentArray.isArray() && contentArray.size() > 1) {
|
|
|
|
|
+ JsonNode secondElement = contentArray.get(1);
|
|
|
|
|
+ JsonNode textNode = secondElement.path("text");
|
|
|
|
|
+
|
|
|
|
|
+ if (!textNode.isMissingNode()) {
|
|
|
|
|
+ JsonNode contentInnerNode = textNode.path("content");
|
|
|
|
|
+
|
|
|
|
|
+ if (contentInnerNode.isTextual()) {
|
|
|
|
|
+ String innerJsonStr = contentInnerNode.asText();
|
|
|
|
|
+// JsonNode innerJson = mapper.readTree(innerJsonStr);
|
|
|
|
|
+// JsonNode userInfo1 = innerJson.path("aiContent");
|
|
|
|
|
+// = userInfo1.asText();
|
|
|
|
|
+ result = innerJsonStr;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
}
|
|
}
|
|
|
- return "";
|
|
|
|
|
|
|
+ return result;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
- public void aiIntentionDegree(Long customerId, String dataJson, Long logId) {
|
|
|
|
|
|
|
+ public String aiIntentionDegree(Long customerId, String dataJson, Long logId) {
|
|
|
Map<String, Object> stringObjectMap = buildRequestParam(customerId, dataJson);
|
|
Map<String, Object> stringObjectMap = buildRequestParam(customerId, dataJson);
|
|
|
stringObjectMap.put("modelType","客户意向度");
|
|
stringObjectMap.put("modelType","客户意向度");
|
|
|
stringObjectMap.remove("userInfo");
|
|
stringObjectMap.remove("userInfo");
|
|
|
HashMap<String, String> map = MapUtil.of("客户意向度", "");
|
|
HashMap<String, String> map = MapUtil.of("客户意向度", "");
|
|
|
stringObjectMap.put("userInfo", map);
|
|
stringObjectMap.put("userInfo", map);
|
|
|
- log.info("请求参数:{}", stringObjectMap);
|
|
|
|
|
|
|
+// log.info("请求参数:{}", stringObjectMap);
|
|
|
|
|
|
|
|
R aiResponse = CrmCustomerAiTagUtil.callAiService(stringObjectMap, logId,OTHER_KEY);
|
|
R aiResponse = CrmCustomerAiTagUtil.callAiService(stringObjectMap, logId,OTHER_KEY);
|
|
|
// System.out.println(aiResponse);
|
|
// System.out.println(aiResponse);
|
|
|
- JSONObject root = JSON.parseObject(JSONUtil.toJsonStr(aiResponse));
|
|
|
|
|
|
|
+ String result = "";
|
|
|
|
|
+ try {
|
|
|
|
|
|
|
|
-// 获取 data.responseData
|
|
|
|
|
- JSONArray responseData = root.getJSONObject("data").getJSONArray("responseData");
|
|
|
|
|
|
|
+ JsonNode rootS = mapper.readTree(JSONUtil.toJsonStr(aiResponse));
|
|
|
|
|
+ JsonNode choices = rootS.path("data").path("choices");
|
|
|
|
|
+
|
|
|
|
|
+ if (choices.isArray() && choices.size() > 0) {
|
|
|
|
|
+ JsonNode contentNode = choices.get(0).path("message").path("content");
|
|
|
|
|
|
|
|
- JSONObject summary = null;
|
|
|
|
|
|
|
+ if (contentNode.isTextual()) {
|
|
|
|
|
+ String contentStr = contentNode.asText();
|
|
|
|
|
+ // 将content字符串解析为JsonNode
|
|
|
|
|
+ JsonNode contentArray = mapper.readTree(contentStr);
|
|
|
|
|
|
|
|
-// 遍历 responseData
|
|
|
|
|
- for (int i = 0; i < responseData.size(); i++) {
|
|
|
|
|
- JSONObject node = responseData.getJSONObject(i);
|
|
|
|
|
- JSONArray historyPreview = node.getJSONArray("historyPreview");
|
|
|
|
|
|
|
+ if (contentArray.isArray() && contentArray.size() > 1) {
|
|
|
|
|
+ JsonNode secondElement = contentArray.get(1);
|
|
|
|
|
+ JsonNode textNode = secondElement.path("text");
|
|
|
|
|
|
|
|
- if (historyPreview != null) {
|
|
|
|
|
- for (int j = 0; j < historyPreview.size(); j++) {
|
|
|
|
|
- JSONObject historyItem = historyPreview.getJSONObject(j);
|
|
|
|
|
|
|
+ if (!textNode.isMissingNode()) {
|
|
|
|
|
+ JsonNode contentInnerNode = textNode.path("content");
|
|
|
|
|
|
|
|
- // 找到 obj 为 "AI" 的项
|
|
|
|
|
- if ("AI".equals(historyItem.getString("obj"))) {
|
|
|
|
|
- String valueStr = historyItem.getString("value");
|
|
|
|
|
- JSONObject valueObj = JSON.parseObject(valueStr);
|
|
|
|
|
- summary = valueObj.getJSONObject("userInfo");
|
|
|
|
|
- break;
|
|
|
|
|
|
|
+ if (contentInnerNode.isTextual()) {
|
|
|
|
|
+ String innerJsonStr = contentInnerNode.asText();
|
|
|
|
|
+ JsonNode innerJson = mapper.readTree(innerJsonStr);
|
|
|
|
|
+ JsonNode userInfo = innerJson.path("userInfo");
|
|
|
|
|
+ result = userInfo.get("客户意向度").asText();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- if (summary != null && !summary.isEmpty()) break;
|
|
|
|
|
- }
|
|
|
|
|
- if (summary != null && !summary.isEmpty()) {
|
|
|
|
|
- CrmCustomerAnalyze crmCustomerAnalyze = new CrmCustomerAnalyze();
|
|
|
|
|
- crmCustomerAnalyze.setCustomerId(customerId);
|
|
|
|
|
- crmCustomerAnalyze.setIntentionDegree(summary.getString("客户意向度"));
|
|
|
|
|
- baseMapper.updateCustomerPortrait(crmCustomerAnalyze);
|
|
|
|
|
|
|
+
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
}
|
|
}
|
|
|
|
|
+ return result;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -475,40 +504,53 @@ public class CrmCustomerAnalyzeServiceImpl extends ServiceImpl<CrmCustomerAnalyz
|
|
|
requestParam.put("aiContent", "");
|
|
requestParam.put("aiContent", "");
|
|
|
requestParam.put("likeRatio", "");
|
|
requestParam.put("likeRatio", "");
|
|
|
requestParam.put("modelType","客户意向度");
|
|
requestParam.put("modelType","客户意向度");
|
|
|
- log.info("请求参数:{}", requestParam);
|
|
|
|
|
|
|
+// log.info("请求参数:{}", requestParam);
|
|
|
|
|
|
|
|
R aiResponse = CrmCustomerAiTagUtil.callAiService(requestParam, chatId,OTHER_KEY);
|
|
R aiResponse = CrmCustomerAiTagUtil.callAiService(requestParam, chatId,OTHER_KEY);
|
|
|
JSONObject root = JSON.parseObject(JSONUtil.toJsonStr(aiResponse));
|
|
JSONObject root = JSON.parseObject(JSONUtil.toJsonStr(aiResponse));
|
|
|
// System.out.println(aiResponse);
|
|
// System.out.println(aiResponse);
|
|
|
// 获取 data.responseData
|
|
// 获取 data.responseData
|
|
|
- JSONArray responseData = root.getJSONObject("data").getJSONArray("responseData");
|
|
|
|
|
|
|
+ String result = "";
|
|
|
|
|
+ try {
|
|
|
|
|
|
|
|
- String summary = null;
|
|
|
|
|
|
|
+ JsonNode rootS = mapper.readTree(JSONUtil.toJsonStr(aiResponse));
|
|
|
|
|
+ JsonNode choices = rootS.path("data").path("choices");
|
|
|
|
|
|
|
|
-// 遍历 responseData
|
|
|
|
|
- for (int i = 0; i < responseData.size(); i++) {
|
|
|
|
|
- JSONObject node = responseData.getJSONObject(i);
|
|
|
|
|
- JSONArray historyPreview = node.getJSONArray("historyPreview");
|
|
|
|
|
|
|
+ if (choices.isArray() && choices.size() > 0) {
|
|
|
|
|
+ JsonNode contentNode = choices.get(0).path("message").path("content");
|
|
|
|
|
|
|
|
- if (historyPreview != null) {
|
|
|
|
|
- for (int j = 0; j < historyPreview.size(); j++) {
|
|
|
|
|
- JSONObject historyItem = historyPreview.getJSONObject(j);
|
|
|
|
|
|
|
+ if (contentNode.isTextual()) {
|
|
|
|
|
+ String contentStr = contentNode.asText();
|
|
|
|
|
+ // 将content字符串解析为JsonNode
|
|
|
|
|
+ JsonNode contentArray = mapper.readTree(contentStr);
|
|
|
|
|
|
|
|
- // 找到 obj 为 "AI" 的项
|
|
|
|
|
- if ("AI".equals(historyItem.getString("obj"))) {
|
|
|
|
|
- String valueStr = historyItem.getString("value");
|
|
|
|
|
- JSONObject valueObj = JSON.parseObject(valueStr);
|
|
|
|
|
- summary = valueObj.getString("userIntent");
|
|
|
|
|
- break;
|
|
|
|
|
|
|
+ if (contentArray.isArray() && contentArray.size() > 1) {
|
|
|
|
|
+ JsonNode secondElement = contentArray.get(1);
|
|
|
|
|
+ JsonNode textNode = secondElement.path("text");
|
|
|
|
|
+
|
|
|
|
|
+ if (!textNode.isMissingNode()) {
|
|
|
|
|
+ JsonNode contentInnerNode = textNode.path("content");
|
|
|
|
|
+
|
|
|
|
|
+ if (contentInnerNode.isTextual()) {
|
|
|
|
|
+ String innerJsonStr = contentInnerNode.asText();
|
|
|
|
|
+ JsonNode innerJson = mapper.readTree(innerJsonStr);
|
|
|
|
|
+ JsonNode userInfo = innerJson.path("userIntent");
|
|
|
|
|
+ result = userInfo.asText();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- if (summary != null && !summary.isEmpty()) break;
|
|
|
|
|
- }
|
|
|
|
|
- if (summary != null && !summary.isEmpty()) {
|
|
|
|
|
- return summary;
|
|
|
|
|
|
|
+
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
}
|
|
}
|
|
|
- return null;
|
|
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public int updateCrmCustomerAnalyzeByCustomerId(CrmCustomerAnalyze crmCustomerAnalyze) {
|
|
|
|
|
+ return baseMapper.updateCustomerPortrait(crmCustomerAnalyze);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private Map<String, Object> buildRequestParam(Long customerId,
|
|
private Map<String, Object> buildRequestParam(Long customerId,
|
|
@@ -545,7 +587,7 @@ public class CrmCustomerAnalyzeServiceImpl extends ServiceImpl<CrmCustomerAnalyz
|
|
|
List<String> dictValue = portraits.stream().map(SysDictData::getDictValue).collect(Collectors.toList());
|
|
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){
|
|
|
|
|
|
|
+ if (!crmCustomerAnalyze.getCustomerPortraitJson().isEmpty()){
|
|
|
Map<String, String> portraitList = JSON.parseObject(
|
|
Map<String, String> portraitList = JSON.parseObject(
|
|
|
crmCustomerAnalyze.getCustomerPortraitJson(),
|
|
crmCustomerAnalyze.getCustomerPortraitJson(),
|
|
|
new TypeReference<Map<String, String>>() {}
|
|
new TypeReference<Map<String, String>>() {}
|