Forráskód Böngészése

客户详情ai标签调试
客户详情ai模型切换,所有功能调试

lk 2 hete
szülő
commit
30e509e2b5

+ 79 - 26
fs-admin/src/main/java/com/fs/task/CrmCustomerAiProcessingTask.java

@@ -7,6 +7,7 @@ import lombok.extern.slf4j.Slf4j;
 import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.stereotype.Component;
 
+import java.util.Arrays;
 import java.util.List;
 import java.util.Map;
 import java.util.concurrent.*;
@@ -94,41 +95,93 @@ public class CrmCustomerAiProcessingTask {
         String threadName = Thread.currentThread().getName();
         long batchStartTime = System.currentTimeMillis();
 
-//        try {
+        try {
             log.info("线程 {} 开始处理批次, 数据量: {}", threadName, batch.size());
 
-            // 示例:处理每条数据
-            for (Map<String, String> data : batch) {
-                // 获取数据
-                Long customerId = Long.valueOf(data.get("customerId"));
-                String dataJson = data.get("data");
-                Long logId = Long.valueOf(data.get("logId"));
-                //todo 业务!!!!!!2.流失风险等级8.9.客户意向度 //都要异步处理
-                //客户画像
-                crmCustomerAnalyzeService.aiGeneratedCustomerPortrait(customerId,dataJson,logId);
-                //沟通总结
-                crmCustomerAnalyzeService.aiCommunicationSummary(customerId,dataJson,logId);
-                //沟通摘要
-                crmCustomerAnalyzeService.aiCommunicationAbstract(customerId,dataJson,logId);
-//                //流失风险等级 //ai暂时未提供,等ai提供
-                crmCustomerAnalyzeService.aiAttritionLevel(customerId,dataJson,logId);
-                //客户关注点
-                crmCustomerAnalyzeService.aiCustomerFocus(customerId,dataJson,logId);
-                //客户意向度
-                crmCustomerAnalyzeService.aiIntentionDegree(customerId,dataJson,logId);
+            List<CompletableFuture<Void>> customerFutures = batch.stream()
+                    .map(data -> CompletableFuture.runAsync(() -> {
+                        processSingleCustomer(data, successCount, failCount);
+                    }, executorService))
+                    .collect(Collectors.toList());
 
-            }
+            // 等待该批次内所有客户处理完成
+            CompletableFuture.allOf(customerFutures.toArray(new CompletableFuture[0]))
+                    .join();
+            // 示例:处理每条数据
+//            for (Map<String, String> data : batch) {
+//                // 获取数据
+//                Long customerId = Long.valueOf(data.get("customerId"));
+//                String dataJson = data.get("data");
+//                Long logId = Long.valueOf(data.get("logId"));
+//                //客户画像1
+//                crmCustomerAnalyzeService.aiGeneratedCustomerPortrait(customerId,dataJson,logId);
+//                //沟通总结
+//                crmCustomerAnalyzeService.aiCommunicationSummary(customerId,dataJson,logId);
+//                //沟通摘要
+//                crmCustomerAnalyzeService.aiCommunicationAbstract(customerId,dataJson,logId);
+//                //流失风险等级
+//                crmCustomerAnalyzeService.aiAttritionLevel(customerId,dataJson,logId);
+//                //客户关注点
+//                crmCustomerAnalyzeService.aiCustomerFocus(customerId,dataJson,logId);
+//                //客户意向度
+//                crmCustomerAnalyzeService.aiIntentionDegree(customerId,dataJson,logId);
+//
+//            }
 
             long costTime = System.currentTimeMillis() - batchStartTime;
             successCount.addAndGet(batch.size());
             log.info("线程 {} 批次处理完成, 数据量: {}, 耗时: {}ms",
                     threadName, batch.size(), costTime);
 
-//        } catch (Exception e) {
-//            failCount.addAndGet(batch.size());
-//            log.error("线程 {} 批次处理失败, 数据量: {}", threadName, batch.size(), e);
-//            throw new RuntimeException("批次处理失败", e);
-//        }
+        } catch (Exception e) {
+            failCount.addAndGet(batch.size());
+            log.error("线程 {} 批次处理失败, 数据量: {}", threadName, batch.size(), e);
+            throw new RuntimeException("批次处理失败", e);
+        }
+    }
+    /**
+     * 处理单个客户的AI分析(6个接口并行)
+     */
+    private void processSingleCustomer(Map<String, String> data,
+                                       AtomicInteger successCount,
+                                       AtomicInteger failCount) {
+        try {
+            Long customerId = Long.valueOf(data.get("customerId"));
+            String dataJson = data.get("data");
+            Long logId = Long.valueOf(data.get("logId"));
+
+            long startTime = System.currentTimeMillis();
+
+            // 并行调用6个AI分析接口
+            List<CompletableFuture<Void>> aiFutures = Arrays.asList(
+                    CompletableFuture.runAsync(() ->
+                            crmCustomerAnalyzeService.aiGeneratedCustomerPortrait(customerId, dataJson, logId), executorService),
+                    CompletableFuture.runAsync(() ->
+                            crmCustomerAnalyzeService.aiCommunicationSummary(customerId, dataJson, logId), executorService),
+                    CompletableFuture.runAsync(() ->
+                            crmCustomerAnalyzeService.aiCommunicationAbstract(customerId, dataJson, logId), executorService),
+                    CompletableFuture.runAsync(() ->
+                            crmCustomerAnalyzeService.aiAttritionLevel(customerId, dataJson, logId), executorService),
+                    CompletableFuture.runAsync(() ->
+                            crmCustomerAnalyzeService.aiCustomerFocus(customerId, dataJson, logId), executorService),
+                    CompletableFuture.runAsync(() ->
+                            crmCustomerAnalyzeService.aiIntentionDegree(customerId, dataJson, logId), executorService)
+            );
+
+            // 等待该客户的所有AI分析完成
+            CompletableFuture<Void> allAiFutures = CompletableFuture.allOf(
+                    aiFutures.toArray(new CompletableFuture[aiFutures.size()])
+            );
+            allAiFutures.get(30, TimeUnit.SECONDS);
+            long costTime = System.currentTimeMillis() - startTime;
+            successCount.incrementAndGet();
+            log.info("客户 {} 的AI分析完成, 耗时: {}ms", customerId, costTime);
+
+        } catch (Exception e) {
+            failCount.incrementAndGet();
+            log.error("处理客户数据失败, customerId: {}, logId: {}",
+                    data.get("customerId"), data.get("logId"), e);
+        }
     }
     /**
      * 处理失败的数据

+ 0 - 1
fs-company/src/main/java/com/fs/company/controller/crm/CrmCustomerAnalyzeController.java

@@ -120,7 +120,6 @@ public class CrmCustomerAnalyzeController extends BaseController
      * 话术润色
      */
     @PreAuthorize("@ss.hasPermi('crm:analyze:polishingScript')")
-    @Log(title = "话术润色", businessType = BusinessType.INSERT)
     @PostMapping("/polishingScript")
     public R polishingScript(@RequestBody PolishingScriptParam param)
     {

+ 1 - 2
fs-service/src/main/java/com/fs/crm/service/ICrmCustomerAnalyzeService.java

@@ -2,7 +2,6 @@ package com.fs.crm.service;
 
 import java.util.List;
 import com.baomidou.mybatisplus.extension.service.IService;
-import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fs.crm.domain.CrmCustomerAnalyze;
 import com.fs.crm.param.PolishingScriptParam;
 
@@ -77,5 +76,5 @@ public interface ICrmCustomerAnalyzeService extends IService<CrmCustomerAnalyze>
 
     List<CrmCustomerAnalyze> selectCrmCustomerAnalyzeListAll(CrmCustomerAnalyze crmCustomerAnalyze);
 
-    String aiIntentionDegree(String content , Long chatId) throws JsonProcessingException;
+    String aiIntentionDegree(String content , Long chatId) ;
 }

+ 96 - 56
fs-service/src/main/java/com/fs/crm/service/impl/CrmCustomerAnalyzeServiceImpl.java

@@ -1,6 +1,7 @@
 package com.fs.crm.service.impl;
 
 import cn.hutool.core.lang.TypeReference;
+import cn.hutool.core.map.MapUtil;
 import cn.hutool.core.util.ObjectUtil;
 import cn.hutool.json.JSONUtil;
 import com.alibaba.fastjson.JSON;
@@ -21,7 +22,7 @@ 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.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 
 import java.util.*;
@@ -113,15 +114,16 @@ public class CrmCustomerAnalyzeServiceImpl extends ServiceImpl<CrmCustomerAnalyz
     }
     private static final String AI_PORTRAIT = "crm_ai_portrait";
     private static final ObjectMapper mapper = new ObjectMapper();
+    @Value("${crm.customer.ai.Key:mygpt-qZllJOSsaKw51T8D1Ug20aGJWcEPlC9OoR5kOKLQ8G9dsCeW3xa2m}")
+    private String OTHER_KEY;
     //ai获取客户画像
     @Override
-    @Async
     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);
-
+        R aiResponse = CrmCustomerAiTagUtil.callAiService(stringObjectMap, logId,OTHER_KEY);
+//        System.out.println(aiResponse);
         JSONObject root = JSON.parseObject(JSONUtil.toJsonStr(aiResponse));
 
 // 获取 data.responseData
@@ -159,18 +161,17 @@ public class CrmCustomerAnalyzeServiceImpl extends ServiceImpl<CrmCustomerAnalyz
     }
 
     @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);
+        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");
 
-        JSONArray summary = null;
+        JSONObject summary = null;
 
 // 遍历 responseData
         for (int i = 0; i < responseData.size(); i++) {
@@ -185,40 +186,40 @@ public class CrmCustomerAnalyzeServiceImpl extends ServiceImpl<CrmCustomerAnalyz
                     if ("AI".equals(historyItem.getString("obj"))) {
                         String valueStr = historyItem.getString("value");
                         JSONObject valueObj = JSON.parseObject(valueStr);
-                        summary = valueObj.getJSONArray("tagInfos");
+                        summary = valueObj.getJSONObject("userInfo");
                         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());
+
+        if (!summary.isEmpty() ) {
+            String summaryText = summary.getString("沟通总结");
             CrmCustomerAnalyze crmCustomerAnalyze = new CrmCustomerAnalyze();
             crmCustomerAnalyze.setCustomerId(customerId);
-            crmCustomerAnalyze.setCommunicationSummary(summaryText.toString());
+            crmCustomerAnalyze.setCommunicationSummary(summaryText);
             baseMapper.updateCustomerPortrait(crmCustomerAnalyze);
         }
     }
 
     @Override
-    @Async
     public void aiCommunicationAbstract(Long customerId, String dataJson, Long logId) {
         Map<String, Object> stringObjectMap = buildRequestParam(customerId, dataJson);
         stringObjectMap.put("modelType","沟通摘要");
+        stringObjectMap.remove("userInfo");
+        HashMap<String, String> map = MapUtil.of("沟通摘要", "");
+        stringObjectMap.put("userInfo", map);
         log.info("请求参数:{}", stringObjectMap);
 
-        R aiResponse = CrmCustomerAiTagUtil.callAiService(stringObjectMap, logId);
+        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 summary = null;
+        JSONObject summary = null;
 
 // 遍历 responseData
         for (int i = 0; i < responseData.size(); i++) {
@@ -233,7 +234,7 @@ public class CrmCustomerAnalyzeServiceImpl extends ServiceImpl<CrmCustomerAnalyz
                     if ("AI".equals(historyItem.getString("obj"))) {
                         String valueStr = historyItem.getString("value");
                         JSONObject valueObj = JSON.parseObject(valueStr);
-                        summary = valueObj.getString("userContent");
+                        summary = valueObj.getJSONObject("userInfo");
                         break;
                     }
                 }
@@ -243,25 +244,28 @@ public class CrmCustomerAnalyzeServiceImpl extends ServiceImpl<CrmCustomerAnalyz
         if (summary != null){
             CrmCustomerAnalyze c = new CrmCustomerAnalyze();
             c.setCustomerId(customerId);
-            c.setCommunicationAbstract(summary);
+            c.setCommunicationAbstract(summary.getString("沟通摘要"));
             baseMapper.updateCustomerPortrait(c);
         }
     }
 
     @Override
-    @Async
     public void aiAttritionLevel(Long customerId, String dataJson, Long logId) {
         Map<String, Object> stringObjectMap = buildRequestParam(customerId, dataJson);
         stringObjectMap.put("modelType","流失风险等级");
+        stringObjectMap.remove("userInfo");
+        HashMap<String, String> map = MapUtil.of("流失风险等级", "");
+        stringObjectMap.put("userInfo", map);
         log.info("请求参数:{}", stringObjectMap);
 
-        R aiResponse = CrmCustomerAiTagUtil.callAiService(stringObjectMap, logId);
+        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 summary = null;
+        JSONObject summary = null;
 
 // 遍历 responseData
         for (int i = 0; i < responseData.size(); i++) {
@@ -276,33 +280,50 @@ public class CrmCustomerAnalyzeServiceImpl extends ServiceImpl<CrmCustomerAnalyz
                     if ("AI".equals(historyItem.getString("obj"))) {
                         String valueStr = historyItem.getString("value");
                         JSONObject valueObj = JSON.parseObject(valueStr);
-                        summary = valueObj.getString("tagInfos");
+                        summary = valueObj.getJSONObject("userInfo");
                         break;
                     }
                 }
             }
-            if (summary != null) break;
+            if (summary != null && !summary.isEmpty()) break;
         }
-        if (summary != null){
-            //todo 响应处理
+        if (summary != null && !summary.isEmpty()){
+            String level = summary.getString("流失风险等级");
+
+            CrmCustomerAnalyze c = new CrmCustomerAnalyze();
+            c.setCustomerId(customerId);
+            c.setAttritionLevel(getScore(level));
+            baseMapper.updateCustomerPortrait(c);
         }
     }
 
+
+        private static Long getScore(String level) {
+            if ("十分满意".equals(level) || "满意".equals(level) || "A".equals(level) || "B".equals(level)) return 1L;
+            if ("基本满意".equals(level) || "C".equals(level)) return 2L;
+            if ("不满意".equals(level) || "D".equals(level)) return 3L;
+            if ("十分不满意".equals(level) || "E".equals(level)) return 4L;
+            return 0L; // 未知
+        }
+
+
     @Override
-    @Async
     public void aiCustomerFocus(Long customerId, String dataJson, Long logId) {
         Map<String, Object> stringObjectMap = buildRequestParam(customerId, dataJson);
         stringObjectMap.put("modelType","客户关注点");
+        stringObjectMap.remove("userInfo");
+        HashMap<String, String> map = MapUtil.of("客户关注点", "");
+        stringObjectMap.put("userInfo", map);
         log.info("请求参数:{}", stringObjectMap);
 
-        R aiResponse = CrmCustomerAiTagUtil.callAiService(stringObjectMap, logId);
-        System.out.println(aiResponse);
+        R aiResponse = CrmCustomerAiTagUtil.callAiService(stringObjectMap, logId,OTHER_KEY);
+//        System.out.println(aiResponse);
         JSONObject root = JSON.parseObject(JSONUtil.toJsonStr(aiResponse));
 
 // 获取 data.responseData
         JSONArray responseData = root.getJSONObject("data").getJSONArray("responseData");
 
-        JSONArray summary = null;
+        JSONObject summary = null;
 
 // 遍历 responseData
         for (int i = 0; i < responseData.size(); i++) {
@@ -317,22 +338,17 @@ public class CrmCustomerAnalyzeServiceImpl extends ServiceImpl<CrmCustomerAnalyz
                     if ("AI".equals(historyItem.getString("obj"))) {
                         String valueStr = historyItem.getString("value");
                         JSONObject valueObj = JSON.parseObject(valueStr);
-                        summary = valueObj.getJSONArray("userContent");
+                        summary = valueObj.getJSONObject("userInfo");
                         break;
                     }
                 }
             }
-            if (summary != null) break;
+            if (summary != null && !summary.isEmpty()) break;
         }
-        if (summary != null){
-            List<String> list = new ArrayList<String>();
-            summary.forEach(o->{
-                JSONObject jsonObject = (JSONObject) o;
-                list.add(jsonObject.getString("tagName"));
-            });
+        if (summary != null && !summary.isEmpty()){
             CrmCustomerAnalyze crmCustomerAnalyze = new CrmCustomerAnalyze();
             crmCustomerAnalyze.setCustomerId(customerId);
-            crmCustomerAnalyze.setCustomerFocusJson(list.toString());
+            crmCustomerAnalyze.setCustomerFocusJson(summary.getString("客户关注点"));
             baseMapper.updateCustomerPortrait(crmCustomerAnalyze);
         }
     }
@@ -342,7 +358,8 @@ public class CrmCustomerAnalyzeServiceImpl extends ServiceImpl<CrmCustomerAnalyz
         Map<String, Object> requestParam = new HashMap<>();
         requestParam.put("history", param.getContent());
         requestParam.put("modelType","话术润色");
-        requestParam.putAll(param.getPortrait());
+        HashMap<String, Map<String, String>> userInfo = MapUtil.of("userInfo", param.getPortrait());
+        requestParam.putAll(userInfo);
 
         // 设置其他参数
         requestParam.put("tagInfos", Collections.emptyList());
@@ -350,26 +367,49 @@ public class CrmCustomerAnalyzeServiceImpl extends ServiceImpl<CrmCustomerAnalyz
         requestParam.put("userContent", "");
         requestParam.put("aiContent", "");
         requestParam.put("likeRatio", "");
-        R aiResponse = CrmCustomerAiTagUtil.callAiService(requestParam, Long.valueOf(param.getChatId()));
-        System.out.println(aiResponse);
+        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");
+                    }
+                }
+            }
+        }
         return "";
     }
 
     @Override
-    @Async
     public void aiIntentionDegree(Long customerId, String dataJson, Long logId) {
         Map<String, Object> stringObjectMap = buildRequestParam(customerId, dataJson);
         stringObjectMap.put("modelType","客户意向度");
+        stringObjectMap.remove("userInfo");
+        HashMap<String, String> map = MapUtil.of("客户意向度", "");
+        stringObjectMap.put("userInfo", map);
         log.info("请求参数:{}", stringObjectMap);
 
-        R aiResponse = CrmCustomerAiTagUtil.callAiService(stringObjectMap, logId);
-        System.out.println(aiResponse);
+        R aiResponse = CrmCustomerAiTagUtil.callAiService(stringObjectMap, logId,OTHER_KEY);
+//        System.out.println(aiResponse);
         JSONObject root = JSON.parseObject(JSONUtil.toJsonStr(aiResponse));
 
 // 获取 data.responseData
         JSONArray responseData = root.getJSONObject("data").getJSONArray("responseData");
 
-        String summary = null;
+        JSONObject summary = null;
 
 // 遍历 responseData
         for (int i = 0; i < responseData.size(); i++) {
@@ -384,17 +424,17 @@ public class CrmCustomerAnalyzeServiceImpl extends ServiceImpl<CrmCustomerAnalyz
                     if ("AI".equals(historyItem.getString("obj"))) {
                         String valueStr = historyItem.getString("value");
                         JSONObject valueObj = JSON.parseObject(valueStr);
-                        summary = valueObj.getString("userIntent");
+                        summary = valueObj.getJSONObject("userInfo");
                         break;
                     }
                 }
             }
-            if (summary != null) break;
+            if (summary != null && !summary.isEmpty()) break;
         }
-        if (summary != null) {
+        if (summary != null && !summary.isEmpty()) {
             CrmCustomerAnalyze crmCustomerAnalyze = new CrmCustomerAnalyze();
             crmCustomerAnalyze.setCustomerId(customerId);
-            crmCustomerAnalyze.setIntentionDegree(summary);
+            crmCustomerAnalyze.setIntentionDegree(summary.getString("客户意向度"));
             baseMapper.updateCustomerPortrait(crmCustomerAnalyze);
         }
     }
@@ -437,9 +477,9 @@ public class CrmCustomerAnalyzeServiceImpl extends ServiceImpl<CrmCustomerAnalyz
         requestParam.put("modelType","客户意向度");
         log.info("请求参数:{}", requestParam);
 
-        R aiResponse = CrmCustomerAiTagUtil.callAiService(requestParam, chatId);
+        R aiResponse = CrmCustomerAiTagUtil.callAiService(requestParam, chatId,OTHER_KEY);
         JSONObject root = JSON.parseObject(JSONUtil.toJsonStr(aiResponse));
-
+//        System.out.println(aiResponse);
 // 获取 data.responseData
         JSONArray responseData = root.getJSONObject("data").getJSONArray("responseData");
 
@@ -463,9 +503,9 @@ public class CrmCustomerAnalyzeServiceImpl extends ServiceImpl<CrmCustomerAnalyz
                     }
                 }
             }
-            if (summary != null) break;
+            if (summary != null && !summary.isEmpty()) break;
         }
-        if (summary != null) {
+        if (summary != null && !summary.isEmpty()) {
             return summary;
         }
         return null;

+ 6 - 5
fs-service/src/main/java/com/fs/crm/utils/CrmCustomerAiTagUtil.java

@@ -48,7 +48,7 @@ public class CrmCustomerAiTagUtil {
 
     //行业字典名称
     private static final String TRADE_TYPE = "trade_type";
-    @Value("${crm.customer.ai.key:mygpt-xZeWD9u6tTebmfn3huS8bTQ63WL2bldp56LpXnB4FWhTnIQMqW4t}")
+    @Value("${crm.customer.ai.key:mygpt-qZllJOSsaKw51T8D1Ug20aGJWcEPlC9OoR5kOKLQ8G9dsCeW3xa2m}")
     private String appKey;
     private static final String CRM_AI_REDIS_KEY = "crm:AI:data:processing";
 
@@ -81,7 +81,8 @@ public class CrmCustomerAiTagUtil {
         Map<String, Object> requestParam = buildRequestParam(customerId, tradeType, communication);
 
         // 3. 调用AI服务
-        R aiResponse = callAiService(requestParam, logId);
+        R aiResponse = callAiService(requestParam, logId,APP_KEY);
+//        System.out.println(aiResponse);
         // 4. 解析响应并保存
         List<CrmCustomerAiTagVo> results = parseAiResponse(aiResponse, customerId);
 
@@ -129,7 +130,7 @@ public class CrmCustomerAiTagUtil {
                 .map(tag -> buildTagVo(tag, customerId))
                 .collect(Collectors.toList());
     }
-    public static R callAiService(Map<String, Object> requestParam, Long logId) {
+    public static R callAiService(Map<String, Object> requestParam, Long logId,String appKey) {
         try {
             String requestJson = mapper.writeValueAsString(requestParam);
 
@@ -146,7 +147,7 @@ public class CrmCustomerAiTagUtil {
             ChatService chatService = SpringUtils.getBean(ChatService.class);
             AiHostProper aiHost = SpringUtils.getBean(AiHostProper.class);
 
-            return chatService.initiatingTakeChat(param, aiHost.getAiApi(), APP_KEY);
+            return chatService.initiatingTakeChat(param, aiHost.getAiApi(), appKey);
         } catch (Exception e) {
             throw new RuntimeException("AI服务调用失败", e);
         }
@@ -226,7 +227,7 @@ public class CrmCustomerAiTagUtil {
                             // 如果 value 是字符串,需要再次解析
                             if (valueNode.isTextual()) {
                                 String valueStr = valueNode.asText();
-                                JsonNode tagInfosNode = mapper.readTree(valueStr).path("tagsInfo");
+                                JsonNode tagInfosNode = mapper.readTree(valueStr).path("tagInfos");
 
                                 if (tagInfosNode.isArray()) {
                                     return mapper.convertValue(tagInfosNode,

+ 3 - 0
fs-service/src/main/resources/mapper/crm/CrmCustomerAnalyzeMapper.xml

@@ -130,6 +130,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="intentionDegree != null and intentionDegree != ''">
                 intention_degree = #{intentionDegree},
             </if>
+            <if test="attritionLevel != null and attritionLevel != ''">
+                attrition_level = #{attritionLevel},
+            </if>
 
         </set>
         where customer_id = #{customerId}