소스 검색

群执行优化

吴树波 1 주 전
부모
커밋
4a842ddd53

+ 1 - 0
fs-service/src/main/java/com/fs/company/domain/CompanyVoiceRobotic.java

@@ -103,6 +103,7 @@ public class CompanyVoiceRobotic {
     private String runTaskFlow;
     // 任务状态0待执行1执行中2执行中断3执行完成
     private Integer taskStatus;
+    private Integer addWxTime;
     /** 创建人 */
     @Excel(name = "创建时间")
     @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")

+ 18 - 5
fs-service/src/main/java/com/fs/company/service/impl/CompanyVoiceRoboticServiceImpl.java

@@ -127,11 +127,20 @@ public class CompanyVoiceRoboticServiceImpl extends ServiceImpl<CompanyVoiceRobo
             return entity;
         }).collect(Collectors.toList());
         companyVoiceRoboticWxService.saveBatch(collect);
+        List<CompanyWxClient> clients = companyVoiceRobotic.getUserIds().stream().map(e -> {
+            CompanyWxClient client = new CompanyWxClient();
+            client.setRoboticId(companyVoiceRobotic.getId());
+            client.setCustomerId(Long.parseLong(e));
+            return client;
+        }).collect(Collectors.toList());
+        companyWxClientServiceImpl.saveBatch(clients);
+
         return i;
     }
 
     public CalltaskcreateaiCustomizeResult addTask(CompanyVoiceRobotic companyVoiceRobotic){
-        List<CrmCustomer> customerList = crmCustomerService.selectCrmCustomerListByIds(String.join(",", companyVoiceRobotic.getUserIds()));
+        List<CompanyWxClient> companyWxClientList = companyWxClientServiceImpl.list(new QueryWrapper<CompanyWxClient>().eq("robotic_id", companyVoiceRobotic.getId()));
+        List<CrmCustomer> customerList = crmCustomerService.selectCrmCustomerListByIds(companyWxClientList.stream().map(e -> e.getCustomerId() + "").collect(Collectors.joining(",")));
         if(customerList.isEmpty()){
             throw new BaseException("拨打电话不能为空");
         }
@@ -276,6 +285,8 @@ public class CompanyVoiceRoboticServiceImpl extends ServiceImpl<CompanyVoiceRobo
     public void dispenseWx(Long roboticId){
         // 任务详情
         CompanyVoiceRobotic robotic = getById(roboticId);
+        List<CompanyWxClient> companyWxClientList = companyWxClientServiceImpl.list(new QueryWrapper<CompanyWxClient>().eq("robotic_id", roboticId));
+        Map<Long, CompanyWxClient> clientMap = PubFun.listToMapByGroupObject(companyWxClientList, CompanyWxClient::getCustomerId);
         // 拨打电话列表
         List<CompanyVoiceRoboticCallees> calleesList = companyVoiceRoboticCalleesMapper.selectByRoboticId(roboticId);
         if(calleesList.isEmpty()) return;
@@ -291,16 +302,18 @@ public class CompanyVoiceRoboticServiceImpl extends ServiceImpl<CompanyVoiceRobo
         Map<String, List<CrmCustomer>> customerMap = PubFun.listToMapByGroupList(customerList, CrmCustomer::getIntention);
         Map<String, List<CompanyVoiceRoboticWx>> roboticWxMap = PubFun.listToMapByGroupList(roboticWxList, CompanyVoiceRoboticWx::getIntention);
         // 循环客户
-        List<CompanyWxClient> collect = customerMap.entrySet().stream().filter(e -> roboticWxMap.containsKey(e.getKey())).flatMap(map -> {
+        List<CompanyWxClient> collect = customerMap.entrySet().stream().flatMap(map -> {
             String k = map.getKey();
             List<CrmCustomer> v = map.getValue();
             // 对应销售账号列表
             List<CompanyVoiceRoboticWx> wxList = roboticWxMap.get(k);
             // 组装任务数据
             return v.stream().map(e -> {
-                CompanyWxClient companyWxClient = new CompanyWxClient();
+                CompanyWxClient companyWxClient = clientMap.get(e.getCustomerId());
                 // 绑定销售
-                bindCompany(companyWxClient, wxList);
+                if(roboticWxMap.containsKey(map.getKey())){
+                    bindCompany(companyWxClient, wxList);
+                }
                 // 任务ID
                 companyWxClient.setRoboticId(roboticId);
                 // 客户名称
@@ -317,7 +330,7 @@ public class CompanyVoiceRoboticServiceImpl extends ServiceImpl<CompanyVoiceRobo
             });
         }).collect(Collectors.toList());
         companyVoiceRoboticWxService.updateBatchById(roboticWxList);
-        companyWxClientServiceImpl.saveBatch(collect);
+        companyWxClientServiceImpl.updateBatchById(collect);
         robotic.setRunTaskFlow((StringUtils.isEmpty(robotic.getRunTaskFlow()) ? "" : robotic.getRunTaskFlow() + ",") + Constants.CELL_PHONE);
         companyVoiceRoboticMapper.updateById(robotic);
         redisCache.deleteObject(Constants.TASK_ID + robotic.getId());

+ 1 - 1
fs-service/src/main/resources/mapper/company/CompanyWxClientMapper.xml

@@ -155,7 +155,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     </select>
     <select id="getAddWxList" resultType="com.fs.company.domain.CompanyWxClient">
         SELECT * FROM company_wx_client where is_add = 0 and account_id is not null
-        <if test="accountIdList">
+        <if test="accountIdList != null and !accountIdList.isEmpty()">
             and account_id in <foreach collection="accountIdList" open="(" separator="," close=")" item="item">#{item}</foreach>
         </if>
         group by account_id

+ 2 - 0
fs-wx-task/src/main/java/com/fs/app/service/WxTaskService.java

@@ -104,6 +104,8 @@ public class WxTaskService {
                     }else{
                         log.error("ROBOTIC-ID:{},加微失败:{}", client.getRoboticId(), vo);
                     }
+                }else{
+                    log.error("ROBOTIC-ID:{},当前任务没有执行加微任务", client.getRoboticId());
                 }
             }else{
                 log.error("当前账号暂无需要添加微信:{}-{}", e.getId(), e.getWxNickName());