Kaynağa Gözat

客户管理详情用户ai对话更新入customerInfo
CrmCustomerAiTagUtil工具类方法重名严重更名

lk 1 gün önce
ebeveyn
işleme
b534e522af

+ 2 - 0
fs-service/src/main/java/com/fs/crm/mapper/CrmCustomerMapper.java

@@ -970,4 +970,6 @@ public interface CrmCustomerMapper extends BaseMapper<CrmCustomer> {
     CrmCustomerInfo selectCrmCustomerInfoById(@Param("customerId") Long customerId);
 
     void insertCrmCustomerInfo(CrmCustomerInfo crmCustomerInfo);
+
+    int updateCrmCustomerInfo(CrmCustomerInfo crmCustomerInfo);
 }

+ 4 - 4
fs-service/src/main/java/com/fs/crm/service/impl/CrmCustomerPropertyServiceImpl.java

@@ -105,7 +105,7 @@ public class CrmCustomerPropertyServiceImpl extends ServiceImpl<CrmCustomerPrope
 
     public int addOrUpdateCustomerPropertyWithExtra(Long customerId, Long propertyId, String propertyName, String propertyValue, String propertyValueType, String tradeType, String intention, Integer likeRatio, String createBy) {
         String autoIntention = calculateIntentionByLikeRatio(likeRatio, intention);
-        
+
         CrmCustomerProperty existProperty = baseMapper.selectByCustomerIdAndPropertyId(customerId, propertyId);
         if (existProperty != null) {
             existProperty.setPropertyValue(propertyValue);
@@ -132,12 +132,12 @@ public class CrmCustomerPropertyServiceImpl extends ServiceImpl<CrmCustomerPrope
             return baseMapper.insertCrmCustomerProperty(property);
         }
     }
-    
+
     private String calculateIntentionByLikeRatio(Integer likeRatio, String intention) {
         if (likeRatio == null) {
             return intention;
         }
-        
+
         if (likeRatio >= 80) {
             return "high";
         } else if (likeRatio >= 50) {
@@ -217,7 +217,7 @@ public class CrmCustomerPropertyServiceImpl extends ServiceImpl<CrmCustomerPrope
         param.setJson(companyVoiceRoboticCallLogCallphone.getContentList());
         log.info("传输数据:{}", param);
         try {
-            List<CrmCustomerAiTagVo> tag = CrmCustomerAiTagUtil.getTag(param);
+            List<CrmCustomerAiTagVo> tag = CrmCustomerAiTagUtil.getCrmCustomerAiTag(param);
             log.info("解析数据:{}", tag);
             List<Long> ids = PubFun.listToNewList(tag, e -> Long.parseLong(e.getId()));
             List<CrmCustomerProperty> propertyList = tag.stream().map(e -> {

+ 19 - 4
fs-service/src/main/java/com/fs/crm/utils/CrmCustomerAiTagUtil.java

@@ -38,7 +38,6 @@ import java.util.concurrent.CompletableFuture;
 import java.util.stream.Collectors;
 import java.util.stream.Stream;
 
-@Slf4j
 @Component
 public class CrmCustomerAiTagUtil {
 
@@ -57,7 +56,7 @@ public class CrmCustomerAiTagUtil {
         APP_KEY = this.appKey;
     }
 
-    public static List<CrmCustomerAiTagVo> getTag(CrmCustomerAiTagParam content) throws JsonProcessingException {
+    public static List<CrmCustomerAiTagVo> getCrmCustomerAiTag(CrmCustomerAiTagParam content) throws JsonProcessingException {
         // 1. 参数校验
         validateParams(content);
         Long customerId = content.getCustomerId();
@@ -149,7 +148,7 @@ public class CrmCustomerAiTagUtil {
         // 获取各类数据
         String tradeName = getDictLabel(tradeType);
         Map<String, Object> tags = getTags(tradeType);
-        Map<String, Object> history = getHistory(communication);
+        Map<String, Object> history = getHistory(communication,customerId.toString());
         Map<String, Object> userInfo = getUserInfo(customerId);
         Map<String, Object> aiInfo = getAiInfo(communication.remove(0));
 
@@ -348,7 +347,7 @@ public class CrmCustomerAiTagUtil {
         return result;
     }
 
-    private static Map<String, Object> getHistory(List<Map<String, Object>> communication) {
+    private static Map<String, Object> getHistory(List<Map<String, Object>> communication,String customerId) {
         StringBuilder history = new StringBuilder();
         history.append("{");
         for (Map<String, Object> o :
@@ -361,6 +360,22 @@ public class CrmCustomerAiTagUtil {
         history.deleteCharAt(history.length() - 1).append("}");
         Map<String, Object> result = new HashMap<String, Object>();
         result.put("history", history);
+        ArrayList<Map> maps = new ArrayList<>();
+        communication.forEach(o->{
+            String role = (String) o.get("role");
+            String content = (String) o.get("content");
+            if (content != null && !content.trim().isEmpty()) { // 过滤空内容
+                String roleTag = "user".equals(role) ? "user" : "ai";
+                Map<String, String> message = new HashMap<>();
+                message.put(roleTag, content);
+                maps.add(message);
+            }
+        });
+        if (!maps.isEmpty()){
+            CrmCustomerInfo crmCustomerInfo = new CrmCustomerInfo();
+            crmCustomerInfo.setCustomerId(Long.valueOf(customerId)).setAiChatRecord(JSONUtil.toJsonStr(maps));
+            SpringUtils.getBean(CrmCustomerMapper.class).updateCrmCustomerInfo(crmCustomerInfo);
+        }
 
         return result;
     }

+ 7 - 0
fs-service/src/main/resources/mapper/crm/CrmCustomerMapper.xml

@@ -371,6 +371,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         </trim>
         where customer_id = #{customerId}
     </update>
+    <update id="updateCrmCustomerInfo">
+        update crm_customer_info
+        <trim prefix="SET" suffixOverrides=",">
+            <if test="aiChatRecord != null">ai_chat_record = #{aiChatRecord},</if>
+        </trim>
+        where customer_id = #{customerId}
+    </update>
 
     <delete id="deleteCrmCustomerById" parameterType="Long">
         delete from crm_customer where customer_id = #{customerId}