|
@@ -4,6 +4,7 @@ import cn.hutool.core.collection.ListUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
import cn.hutool.json.JSONUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
import com.fasterxml.jackson.core.type.TypeReference;
|
|
import com.fasterxml.jackson.core.type.TypeReference;
|
|
@@ -11,6 +12,7 @@ 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;
|
|
|
|
|
+import com.fs.common.exception.CustomException;
|
|
|
import com.fs.common.utils.DictUtils;
|
|
import com.fs.common.utils.DictUtils;
|
|
|
import com.fs.common.utils.spring.SpringUtils;
|
|
import com.fs.common.utils.spring.SpringUtils;
|
|
|
import com.fs.config.ai.AiHostProper;
|
|
import com.fs.config.ai.AiHostProper;
|
|
@@ -25,6 +27,7 @@ import com.fs.crm.vo.CrmCustomerAiTagVo;
|
|
|
import com.fs.fastgptApi.param.ChatParam;
|
|
import com.fs.fastgptApi.param.ChatParam;
|
|
|
import com.fs.fastgptApi.service.ChatService;
|
|
import com.fs.fastgptApi.service.ChatService;
|
|
|
import com.fs.hisapi.util.MapUtil;
|
|
import com.fs.hisapi.util.MapUtil;
|
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
@@ -35,7 +38,7 @@ import java.util.concurrent.CompletableFuture;
|
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
import java.util.stream.Stream;
|
|
import java.util.stream.Stream;
|
|
|
|
|
|
|
|
-
|
|
|
|
|
|
|
+@Slf4j
|
|
|
@Component
|
|
@Component
|
|
|
public class CrmCustomerAiTagUtil {
|
|
public class CrmCustomerAiTagUtil {
|
|
|
|
|
|
|
@@ -57,8 +60,8 @@ public class CrmCustomerAiTagUtil {
|
|
|
public static List<CrmCustomerAiTagVo> getTag(CrmCustomerAiTagParam content) throws JsonProcessingException {
|
|
public static List<CrmCustomerAiTagVo> getTag(CrmCustomerAiTagParam content) throws JsonProcessingException {
|
|
|
// 1. 参数校验
|
|
// 1. 参数校验
|
|
|
validateParams(content);
|
|
validateParams(content);
|
|
|
- String customerId = content.getCustomerId();
|
|
|
|
|
- String logId = content.getLogId();
|
|
|
|
|
|
|
+ Long customerId = content.getCustomerId();
|
|
|
|
|
+ Long logId = content.getLogId();
|
|
|
String tradeType = content.getTradeType();
|
|
String tradeType = content.getTradeType();
|
|
|
List<Map<String, Object>> communication = parseCommunicationJson(content.getJson());
|
|
List<Map<String, Object>> communication = parseCommunicationJson(content.getJson());
|
|
|
|
|
|
|
@@ -75,7 +78,7 @@ public class CrmCustomerAiTagUtil {
|
|
|
saveToRedisAsync(customerId, aiResponse);
|
|
saveToRedisAsync(customerId, aiResponse);
|
|
|
return results;
|
|
return results;
|
|
|
}
|
|
}
|
|
|
- private static void saveToRedisAsync(String customerId, R aiResponse) {
|
|
|
|
|
|
|
+ private static void saveToRedisAsync(Long customerId, R aiResponse) {
|
|
|
// 使用线程池异步保存,避免影响主流程
|
|
// 使用线程池异步保存,避免影响主流程
|
|
|
CompletableFuture.runAsync(() -> {
|
|
CompletableFuture.runAsync(() -> {
|
|
|
try {
|
|
try {
|
|
@@ -93,7 +96,7 @@ public class CrmCustomerAiTagUtil {
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
- private static CrmCustomerAiTagVo buildTagVo(Map<String, String> tag, String customerId) {
|
|
|
|
|
|
|
+ private static CrmCustomerAiTagVo buildTagVo(Map<String, String> tag, Long customerId) {
|
|
|
CrmCustomerAiTagVo vo = new CrmCustomerAiTagVo();
|
|
CrmCustomerAiTagVo vo = new CrmCustomerAiTagVo();
|
|
|
vo.setCustomerId(customerId);
|
|
vo.setCustomerId(customerId);
|
|
|
vo.setId(tag.get("id"));
|
|
vo.setId(tag.get("id"));
|
|
@@ -101,7 +104,7 @@ public class CrmCustomerAiTagUtil {
|
|
|
vo.setValue(tag.get("value"));
|
|
vo.setValue(tag.get("value"));
|
|
|
return vo;
|
|
return vo;
|
|
|
}
|
|
}
|
|
|
- private static List<CrmCustomerAiTagVo> parseAiResponse(R aiResponse, String customerId) {
|
|
|
|
|
|
|
+ private static List<CrmCustomerAiTagVo> parseAiResponse(R aiResponse, Long customerId) {
|
|
|
if (aiResponse == null || !Integer.valueOf(200).equals(aiResponse.get("code"))) {
|
|
if (aiResponse == null || !Integer.valueOf(200).equals(aiResponse.get("code"))) {
|
|
|
throw new RuntimeException("AI响应异常: " +
|
|
throw new RuntimeException("AI响应异常: " +
|
|
|
(aiResponse != null ? aiResponse.get("msg") : "响应为空"));
|
|
(aiResponse != null ? aiResponse.get("msg") : "响应为空"));
|
|
@@ -116,12 +119,12 @@ public class CrmCustomerAiTagUtil {
|
|
|
.map(tag -> buildTagVo(tag, customerId))
|
|
.map(tag -> buildTagVo(tag, customerId))
|
|
|
.collect(Collectors.toList());
|
|
.collect(Collectors.toList());
|
|
|
}
|
|
}
|
|
|
- private static R callAiService(Map<String, Object> requestParam, String logId) {
|
|
|
|
|
|
|
+ private static R callAiService(Map<String, Object> requestParam, Long logId) {
|
|
|
try {
|
|
try {
|
|
|
String requestJson = mapper.writeValueAsString(requestParam);
|
|
String requestJson = mapper.writeValueAsString(requestParam);
|
|
|
|
|
|
|
|
ChatParam param = new ChatParam();
|
|
ChatParam param = new ChatParam();
|
|
|
- param.setChatId(logId);
|
|
|
|
|
|
|
+ param.setChatId(logId.toString());
|
|
|
param.setStream(false);
|
|
param.setStream(false);
|
|
|
param.setDetail(true);
|
|
param.setDetail(true);
|
|
|
ChatParam.Message message = new ChatParam.Message();
|
|
ChatParam.Message message = new ChatParam.Message();
|
|
@@ -138,7 +141,7 @@ public class CrmCustomerAiTagUtil {
|
|
|
throw new RuntimeException("AI服务调用失败", e);
|
|
throw new RuntimeException("AI服务调用失败", e);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- private static Map<String, Object> buildRequestParam(String customerId,
|
|
|
|
|
|
|
+ private static Map<String, Object> buildRequestParam(Long customerId,
|
|
|
String tradeType,
|
|
String tradeType,
|
|
|
List<Map<String, Object>> communication) {
|
|
List<Map<String, Object>> communication) {
|
|
|
Map<String, Object> requestParam = new HashMap<>();
|
|
Map<String, Object> requestParam = new HashMap<>();
|
|
@@ -321,9 +324,9 @@ public class CrmCustomerAiTagUtil {
|
|
|
return result;
|
|
return result;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private static Map<String, Object> getUserInfo(String customerId) {
|
|
|
|
|
|
|
+ private static Map<String, Object> getUserInfo(Long customerId) {
|
|
|
CrmCustomerMapper customerMapper = SpringUtils.getBean(CrmCustomerMapper.class);
|
|
CrmCustomerMapper customerMapper = SpringUtils.getBean(CrmCustomerMapper.class);
|
|
|
- CrmCustomer crmCustomer = customerMapper.selectCrmCustomerById(Long.valueOf(customerId));
|
|
|
|
|
|
|
+ CrmCustomer crmCustomer = customerMapper.selectCrmCustomerById(customerId);
|
|
|
if (ObjectUtil.isEmpty(crmCustomer)) throw new RuntimeException("客户不存在");
|
|
if (ObjectUtil.isEmpty(crmCustomer)) throw new RuntimeException("客户不存在");
|
|
|
CrmCustomerInfo crmCustomerInfo = customerMapper.selectCrmCustomerInfoById(customerId);
|
|
CrmCustomerInfo crmCustomerInfo = customerMapper.selectCrmCustomerInfoById(customerId);
|
|
|
if (ObjectUtil.isEmpty(crmCustomerInfo)) {
|
|
if (ObjectUtil.isEmpty(crmCustomerInfo)) {
|