吴树波 1 день тому
батько
коміт
0b409e750a

+ 5 - 0
fs-service/src/main/java/com/fs/company/service/impl/CompanyVoiceRoboticCallLogCallphoneServiceImpl.java

@@ -30,6 +30,7 @@ import com.fs.company.vo.CompanyVoiceRoboticCallLogCallPhoneVO;
 import com.fs.company.vo.CompanyVoiceRoboticCallLogCount;
 import com.fs.company.vo.DictVO;
 import com.fs.company.vo.easycall.EasyCallCallPhoneVO;
+import com.fs.crm.service.ICrmCustomerPropertyService;
 import com.fs.qw.domain.QwUser;
 import com.fs.qw.mapper.QwUserMapper;
 import com.fs.store.config.StoreConfig;
@@ -72,6 +73,8 @@ public class CompanyVoiceRoboticCallLogCallphoneServiceImpl extends ServiceImpl<
     @Autowired
     CompanyWorkflowEngine companyWorkflowEngine;
     @Autowired
+    private ICrmCustomerPropertyService crmCustomerPropertyService;
+    @Autowired
     QwUserMapper qwUserMapper;
     @Autowired
     @Qualifier("cidWorkFlowExecutor")
@@ -332,6 +335,8 @@ public class CompanyVoiceRoboticCallLogCallphoneServiceImpl extends ServiceImpl<
                 BigDecimal multiply = divide.multiply(callCharge);
                 companyVoiceRoboticCallLog.setCost(multiply);
                 baseMapper.updateCompanyVoiceRoboticCallLogCallphone(companyVoiceRoboticCallLog);
+                // 更新用户标签
+                crmCustomerPropertyService.addPropertyByCallLog(companyVoiceRoboticCallLog);
 
                 if (StringUtils.isNotBlank(result.getBizJson())) {
                     JSONObject bizJson = JSONObject.parseObject(result.getBizJson());

+ 3 - 0
fs-service/src/main/java/com/fs/crm/domain/CrmCustomerPropertyTemplate.java

@@ -22,4 +22,7 @@ public class CrmCustomerPropertyTemplate extends BaseEntityTow {
 
     @Excel(name = "行业类型")
     private String tradeType;
+
+    @Excel(name = "是否有意向度0否1是")
+    private Integer intention;
 }

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

@@ -967,7 +967,7 @@ public interface CrmCustomerMapper extends BaseMapper<CrmCustomer> {
      */
     List<Long> selectCustomerIdByCompanyUserId(@Param("companyUserId") Long companyUserId);
 
-    CrmCustomerInfo selectCrmCustomerInfoById(@Param("customerId") String customerId);
+    CrmCustomerInfo selectCrmCustomerInfoById(@Param("customerId") Long customerId);
 
     void insertCrmCustomerInfo(CrmCustomerInfo crmCustomerInfo);
 }

+ 2 - 2
fs-service/src/main/java/com/fs/crm/param/CrmCustomerAiTagParam.java

@@ -14,9 +14,9 @@ public class CrmCustomerAiTagParam {
 
     //company_voice_robotic_call_log_callphone 的log_id
     @ApiModelProperty("日志id")
-    private String logId;
+    private Long logId;
     @ApiModelProperty("客户id")
-    private String customerId;
+    private Long customerId;
     //crm_customer_property_template的 trade_type
     @ApiModelProperty("行业")
     private String tradeType;

+ 3 - 0
fs-service/src/main/java/com/fs/crm/service/ICrmCustomerPropertyService.java

@@ -1,6 +1,7 @@
 package com.fs.crm.service;
 
 import com.baomidou.mybatisplus.extension.service.IService;
+import com.fs.company.domain.CompanyVoiceRoboticCallLogCallphone;
 import com.fs.crm.domain.CrmCustomerProperty;
 
 import java.util.List;
@@ -139,4 +140,6 @@ public interface ICrmCustomerPropertyService extends IService<CrmCustomerPropert
      * @return 添加结果(添加的记录数)
      */
     int batchAddPropertiesByTemplateIds(Long customerId, Map<Long, String> propertyMap, String createBy);
+
+    void addPropertyByCallLog(CompanyVoiceRoboticCallLogCallphone companyVoiceRoboticCallLog);
 }

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

@@ -1,24 +1,40 @@
 package com.fs.crm.service.impl;
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fs.common.utils.DateUtils;
+import com.fs.common.utils.PubFun;
+import com.fs.company.domain.CompanyVoiceRoboticCallLogCallphone;
+import com.fs.company.domain.CompanyVoiceRoboticCallees;
+import com.fs.company.service.ICompanyVoiceRoboticCalleesService;
 import com.fs.crm.domain.CrmCustomerProperty;
 import com.fs.crm.domain.CrmCustomerPropertyTemplate;
 import com.fs.crm.mapper.CrmCustomerPropertyMapper;
+import com.fs.crm.param.CrmCustomerAiTagParam;
 import com.fs.crm.service.ICrmCustomerPropertyService;
 import com.fs.crm.service.ICrmCustomerPropertyTemplateService;
+import com.fs.crm.utils.CrmCustomerAiTagUtil;
+import com.fs.crm.vo.CrmCustomerAiTagVo;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import java.util.List;
 import java.util.Map;
+import java.util.stream.Collectors;
 
+@Slf4j
 @Service
 public class CrmCustomerPropertyServiceImpl extends ServiceImpl<CrmCustomerPropertyMapper, CrmCustomerProperty> implements ICrmCustomerPropertyService {
 
     @Autowired
     private ICrmCustomerPropertyTemplateService propertyTemplateService;
+    @Autowired
+    private ICompanyVoiceRoboticCalleesService companyVoiceRoboticCalleesService;
 
     @Override
     public CrmCustomerProperty selectCrmCustomerPropertyById(Long id) {
@@ -188,4 +204,41 @@ public class CrmCustomerPropertyServiceImpl extends ServiceImpl<CrmCustomerPrope
         }
         return count;
     }
+
+    @Override
+    @Async
+    public void addPropertyByCallLog(CompanyVoiceRoboticCallLogCallphone companyVoiceRoboticCallLogCallphone) {
+        CompanyVoiceRoboticCallees companyVoiceRoboticCallees = companyVoiceRoboticCalleesService.selectCompanyVoiceRoboticCalleesById(companyVoiceRoboticCallLogCallphone.getCallerId());
+        log.info("获取电话记录:{}", companyVoiceRoboticCallees);
+        CrmCustomerAiTagParam param = new CrmCustomerAiTagParam();
+        param.setLogId(companyVoiceRoboticCallLogCallphone.getLogId());
+        param.setCustomerId(companyVoiceRoboticCallees.getUserId());
+        param.setTradeType("3");
+        param.setJson(companyVoiceRoboticCallLogCallphone.getContentList());
+        log.info("传输数据:{}", param);
+        try {
+            List<CrmCustomerAiTagVo> tag = CrmCustomerAiTagUtil.getTag(param);
+            log.info("解析数据:{}", tag);
+            List<Long> ids = PubFun.listToNewList(tag, e -> Long.parseLong(e.getId()));
+            List<CrmCustomerProperty> propertyList = tag.stream().map(e -> {
+                CrmCustomerProperty property = new CrmCustomerProperty();
+                property.setCustomerId(e.getCustomerId());
+                property.setPropertyId(Long.parseLong(e.getId()));
+                property.setPropertyName(e.getName());
+                property.setPropertyValue(e.getValue());
+                property.setPropertyValueType("String");
+                property.setTradeType("3");
+                property.setIntention("medium");
+                property.setLikeRatio(50);
+                return property;
+            }).collect(Collectors.toList());
+            remove(new LambdaQueryWrapper<CrmCustomerProperty>()
+                    .eq(CrmCustomerProperty::getCustomerId, companyVoiceRoboticCallees.getUserId())
+                    .in(CrmCustomerProperty::getPropertyId, ids)
+            );
+            saveBatch(propertyList);
+        } catch (JsonProcessingException e) {
+            throw new RuntimeException(e);
+        }
+    }
 }

+ 14 - 11
fs-service/src/main/java/com/fs/crm/utils/CrmCustomerAiTagUtil.java

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

+ 1 - 1
fs-service/src/main/java/com/fs/crm/vo/CrmCustomerAiTagVo.java

@@ -12,5 +12,5 @@ public class CrmCustomerAiTagVo {
     private String id; // 标签id
     private String name; // 标签名称
     private String value; // 标签值
-    private String customerId; // 客户id
+    private Long customerId; // 客户id
 }

+ 0 - 1
fs-service/src/main/resources/application-config-dev.yml

@@ -106,7 +106,6 @@ ipad:
   url:
   ipadUrl: http://ipad.cdwjyyh.com
   wxIpadUrl: http://ipad.cdwjyyh.com
-  aiApi: http://152.136.202.157:3000/api
   voiceApi:
   commonApi:
 wx_miniapp_temp:

+ 5 - 0
fs-wx-task/pom.xml

@@ -105,6 +105,11 @@
             <groupId>com.fs</groupId>
             <artifactId>fs-service</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-test</artifactId>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 
     <build>

+ 26 - 0
fs-wx-task/src/main/java/com/fs/app/controller/CommonController.java

@@ -1,20 +1,29 @@
 package com.fs.app.controller;
 
 
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.ObjectMapper;
 import com.fs.app.service.WxTaskService;
+import com.fs.company.domain.CompanyVoiceRoboticCallLogCallphone;
+import com.fs.company.service.ICompanyVoiceRoboticCallLogCallphoneService;
 import com.fs.company.service.ICompanyWxAccountService;
 import com.fs.company.service.impl.CompanyWxServiceImpl;
 import com.fs.company.vo.CdrDetailVo;
+import com.fs.crm.service.ICrmCustomerPropertyService;
 import com.fs.wxcid.dto.message.SendImageMessageParam;
 import com.fs.wxcid.dto.message.SendVideoMessageParam;
 import com.fs.wxcid.service.MessageService;
 import io.swagger.annotations.Api;
 import lombok.AllArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
+import org.junit.Test;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
 import java.util.Collections;
+import java.util.List;
+import java.util.Map;
 
 @Slf4j
 @Api("公共接口")
@@ -102,5 +111,22 @@ public class CommonController {
         return  "success";
     }
 
+    @Autowired
+    private ICrmCustomerPropertyService crmCustomerPropertyService;
+    @Autowired
+    private ICompanyVoiceRoboticCallLogCallphoneService companyVoiceRoboticCallLogCallphoneService;
+
+    @PostMapping("/testProperty")
+    public void testProperty() throws JsonProcessingException {
+        log.info("开始解析");
+        CompanyVoiceRoboticCallLogCallphone byId = companyVoiceRoboticCallLogCallphoneService.getById(251L);
+        List<Map<String, Object>> maps = new ObjectMapper().readValue(
+                byId.getContentList(),
+                new TypeReference<List<Map<String, Object>>>() {
+                }
+        );
+        log.info("解析数据:{}", maps);
+        crmCustomerPropertyService.addPropertyByCallLog(byId);
+    }
 
 }