lmx 1 місяць тому
батько
коміт
fc4651acd1
40 змінених файлів з 939 додано та 38 видалено
  1. 33 4
      fs-company/src/main/java/com/fs/company/controller/company/CompanyVoiceRoboticCallLogAddwxController.java
  2. 20 5
      fs-company/src/main/java/com/fs/company/controller/company/CompanyVoiceRoboticCallLogCallphoneController.java
  3. 33 0
      fs-company/src/main/java/com/fs/company/controller/company/CompanyVoiceRoboticCallLogSendmsgController.java
  4. 9 0
      fs-company/src/main/java/com/fs/company/controller/company/CompanyVoiceRoboticController.java
  5. 13 1
      fs-company/src/test/java/com/mixLiu/test/mixLiuTester.java
  6. 15 0
      fs-service/src/main/java/com/fs/aicall/domain/CIDGroupInfo.java
  7. 13 0
      fs-service/src/main/java/com/fs/aicall/domain/CIDGroupInfoDataItem.java
  8. 1 1
      fs-service/src/main/java/com/fs/aicall/domain/param/CalltaskcreateaiCustomizeDomain.java
  9. 12 2
      fs-service/src/main/java/com/fs/aicall/service/AiCallService.java
  10. 126 0
      fs-service/src/main/java/com/fs/common/service/impl/SmsServiceImpl.java
  11. 8 0
      fs-service/src/main/java/com/fs/company/domain/CompanyVoiceRoboticCallLogAddwx.java
  12. 14 0
      fs-service/src/main/java/com/fs/company/domain/CompanyVoiceRoboticCallLogCallphone.java
  13. 8 0
      fs-service/src/main/java/com/fs/company/domain/CompanyVoiceRoboticCallLogSendmsg.java
  14. 3 0
      fs-service/src/main/java/com/fs/company/domain/CompanyVoiceRoboticCallees.java
  15. 6 0
      fs-service/src/main/java/com/fs/company/mapper/CompanyVoiceRoboticCallLogAddwxMapper.java
  16. 2 0
      fs-service/src/main/java/com/fs/company/mapper/CompanyVoiceRoboticCallLogCallphoneMapper.java
  17. 3 0
      fs-service/src/main/java/com/fs/company/mapper/CompanyVoiceRoboticCallLogSendmsgMapper.java
  18. 9 0
      fs-service/src/main/java/com/fs/company/mapper/CompanyVoiceRoboticCalleesMapper.java
  19. 2 0
      fs-service/src/main/java/com/fs/company/mapper/CompanyVoiceRoboticMapper.java
  20. 4 0
      fs-service/src/main/java/com/fs/company/mapper/CompanyWxClientMapper.java
  21. 11 0
      fs-service/src/main/java/com/fs/company/service/ICompanyVoiceRoboticCallLogAddwxService.java
  22. 15 0
      fs-service/src/main/java/com/fs/company/service/ICompanyVoiceRoboticCallLogCallphoneService.java
  23. 3 0
      fs-service/src/main/java/com/fs/company/service/ICompanyVoiceRoboticCallLogSendmsgService.java
  24. 3 0
      fs-service/src/main/java/com/fs/company/service/ICompanyVoiceRoboticService.java
  25. 38 0
      fs-service/src/main/java/com/fs/company/service/impl/CompanyVoiceRoboticCallLogAddwxServiceImpl.java
  26. 57 1
      fs-service/src/main/java/com/fs/company/service/impl/CompanyVoiceRoboticCallLogCallphoneServiceImpl.java
  27. 7 0
      fs-service/src/main/java/com/fs/company/service/impl/CompanyVoiceRoboticCallLogSendmsgServiceImpl.java
  28. 7 1
      fs-service/src/main/java/com/fs/company/service/impl/CompanyVoiceRoboticCalleesServiceImpl.java
  29. 95 16
      fs-service/src/main/java/com/fs/company/service/impl/CompanyVoiceRoboticServiceImpl.java
  30. 13 0
      fs-service/src/main/java/com/fs/company/vo/CidConfigVO.java
  31. 50 0
      fs-service/src/main/java/com/fs/company/vo/CompanyVoiceRoboticCallLogAddwxVO.java
  32. 73 0
      fs-service/src/main/java/com/fs/company/vo/CompanyVoiceRoboticCallLogSendmsgVO.java
  33. 15 0
      fs-service/src/main/java/com/fs/company/vo/SendMsgByTaskVO.java
  34. 38 0
      fs-service/src/main/resources/mapper/company/CompanyVoiceRoboticCallLogAddwxMapper.xml
  35. 21 0
      fs-service/src/main/resources/mapper/company/CompanyVoiceRoboticCallLogCallphoneMapper.xml
  36. 22 0
      fs-service/src/main/resources/mapper/company/CompanyVoiceRoboticCallLogSendmsgMapper.xml
  37. 83 0
      fs-service/src/main/resources/mapper/company/CompanyVoiceRoboticCalleesMapper.xml
  38. 14 1
      fs-service/src/main/resources/mapper/company/CompanyVoiceRoboticMapper.xml
  39. 10 1
      fs-service/src/main/resources/mapper/company/CompanyWxClientMapper.xml
  40. 30 5
      fs-wx-task/src/main/java/com/fs/app/service/WxTaskService.java

+ 33 - 4
fs-company/src/main/java/com/fs/company/controller/company/CompanyVoiceRoboticCallLogAddwxController.java

@@ -1,6 +1,14 @@
 package com.fs.company.controller.company;
 
+import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import com.fs.common.utils.StringUtils;
+import com.fs.company.domain.CompanyWxClient;
+import com.fs.company.vo.CompanyVoiceRoboticCallLogAddwxVO;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.GetMapping;
@@ -38,11 +46,32 @@ public class CompanyVoiceRoboticCallLogAddwxController extends BaseController
      */
     @PreAuthorize("@ss.hasPermi('company:addwxlog:list')")
     @GetMapping("/list")
-    public TableDataInfo list(CompanyVoiceRoboticCallLogAddwx companyVoiceRoboticCallLogAddwx)
+    public TableDataInfo listByCustomerIdAndRoboticId(CompanyVoiceRoboticCallLogAddwx companyVoiceRoboticCallLogAddwx)
     {
-        startPage();
-        List<CompanyVoiceRoboticCallLogAddwx> list = companyVoiceRoboticCallLogAddwxService.selectCompanyVoiceRoboticCallLogAddwxList(companyVoiceRoboticCallLogAddwx);
-        return getDataTable(list);
+//        if( null == companyVoiceRoboticCallLogAddwx.getCustomerId() || null == companyVoiceRoboticCallLogAddwx.getRoboticId()){
+//            return getDataTable(null);
+//        }
+        //查询用户
+        if(null == companyVoiceRoboticCallLogAddwx.getRoboticId()){
+            List<CompanyWxClient> wxclients = companyVoiceRoboticCallLogAddwxService.getWxClientInfoByCustomerId(companyVoiceRoboticCallLogAddwx.getCustomerId());
+            if(null != wxclients && !wxclients.isEmpty()){
+                Set<Long> collect = wxclients.stream().map(e -> e.getId()).collect(Collectors.toSet());
+                companyVoiceRoboticCallLogAddwx.setWxclientIds(new ArrayList<>( collect));
+                startPage();
+                List<CompanyVoiceRoboticCallLogAddwxVO> companyVoiceRoboticCallLogAddwxVOS = companyVoiceRoboticCallLogAddwxService.listByCustomerId(companyVoiceRoboticCallLogAddwx);
+                return getDataTable(companyVoiceRoboticCallLogAddwxVOS);
+            } else{
+                return getDataTable(Collections.EMPTY_LIST);
+            }
+        }
+        else {
+            CompanyWxClient wxClient = companyVoiceRoboticCallLogAddwxService.getWxClientInfoByCustomerIdAndRoboticId(companyVoiceRoboticCallLogAddwx.getCustomerId(), companyVoiceRoboticCallLogAddwx.getRoboticId());
+            companyVoiceRoboticCallLogAddwx.setWxClientId(wxClient.getId());
+            startPage();
+            List<CompanyVoiceRoboticCallLogAddwxVO> list = companyVoiceRoboticCallLogAddwxService.listByCustomerIdAndRoboticId(companyVoiceRoboticCallLogAddwx);
+            return getDataTable(list);
+        }
+
     }
 //
 //    /**

+ 20 - 5
fs-company/src/main/java/com/fs/company/controller/company/CompanyVoiceRoboticCallLogCallphoneController.java

@@ -1,5 +1,6 @@
 package com.fs.company.controller.company;
 
+import java.util.ArrayList;
 import java.util.List;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -38,11 +39,25 @@ public class CompanyVoiceRoboticCallLogCallphoneController extends BaseControlle
      */
     @PreAuthorize("@ss.hasPermi('company:callphonelog:list')")
     @GetMapping("/list")
-    public TableDataInfo list(CompanyVoiceRoboticCallLogCallphone companyVoiceRoboticCallLogCallphone)
-    {
-        startPage();
-        List<CompanyVoiceRoboticCallLogCallphone> list = companyVoiceRoboticCallLogCallphoneService.selectCompanyVoiceRoboticCallLogCallphoneList(companyVoiceRoboticCallLogCallphone);
-        return getDataTable(list);
+    public TableDataInfo list(CompanyVoiceRoboticCallLogCallphone companyVoiceRoboticCallLogCallphone) {
+        if (null == companyVoiceRoboticCallLogCallphone.getRoboticId() && null == companyVoiceRoboticCallLogCallphone.getCallerId()) {
+            if (companyVoiceRoboticCallLogCallphone.getCustomerId() != null) {
+                List<Long> calleeIds = companyVoiceRoboticCallLogCallphoneService.getCallerIdsByCustomerId(companyVoiceRoboticCallLogCallphone.getCustomerId());
+                if(null == calleeIds || calleeIds.isEmpty()){
+                    return getDataTable(new ArrayList<>());
+                }
+                companyVoiceRoboticCallLogCallphone.setCallerIds(calleeIds);
+                startPage();
+                List<CompanyVoiceRoboticCallLogCallphone> list = companyVoiceRoboticCallLogCallphoneService.selectCompanyVoiceRoboticCallLogCallphoneListData(companyVoiceRoboticCallLogCallphone);
+                return getDataTable(list);
+            } else {
+                return getDataTable(new ArrayList<>());
+            }
+        } else {
+            startPage();
+            List<CompanyVoiceRoboticCallLogCallphone> list = companyVoiceRoboticCallLogCallphoneService.selectCompanyVoiceRoboticCallLogCallphoneListData(companyVoiceRoboticCallLogCallphone);
+            return getDataTable(list);
+        }
     }
 
 //    /**

+ 33 - 0
fs-company/src/main/java/com/fs/company/controller/company/CompanyVoiceRoboticCallLogSendmsgController.java

@@ -1,6 +1,10 @@
 package com.fs.company.controller.company;
 
+import java.util.ArrayList;
 import java.util.List;
+
+import com.fs.company.service.ICompanyVoiceRoboticCallLogCallphoneService;
+import com.fs.company.vo.CompanyVoiceRoboticCallLogSendmsgVO;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.GetMapping;
@@ -33,6 +37,8 @@ public class CompanyVoiceRoboticCallLogSendmsgController extends BaseController
     @Autowired
     private ICompanyVoiceRoboticCallLogSendmsgService companyVoiceRoboticCallLogSendmsgService;
 
+    @Autowired
+    private ICompanyVoiceRoboticCallLogCallphoneService companyVoiceRoboticCallLogCallphoneService;
     /**
      * 查询调用日志_发送短信列表
      */
@@ -45,6 +51,33 @@ public class CompanyVoiceRoboticCallLogSendmsgController extends BaseController
         return getDataTable(list);
     }
 
+    /**
+     * 查询调用日志_发送短信列表
+     */
+    @PreAuthorize("@ss.hasPermi('company:sendmsglog:list')")
+    @GetMapping("/listByCallerIdAndRoboticId")
+    public TableDataInfo listByCallerIdAndRoboticId(CompanyVoiceRoboticCallLogSendmsg companyVoiceRoboticCallLogSendmsg)
+    {
+        if (null == companyVoiceRoboticCallLogSendmsg.getRoboticId() && null == companyVoiceRoboticCallLogSendmsg.getCallerId()) {
+            if (companyVoiceRoboticCallLogSendmsg.getCustomerId() != null) {
+                List<Long> calleeIds = companyVoiceRoboticCallLogCallphoneService.getCallerIdsByCustomerId(companyVoiceRoboticCallLogSendmsg.getCustomerId());
+                if(null == calleeIds || calleeIds.isEmpty()){
+                    return getDataTable(new ArrayList<>());
+                }
+                companyVoiceRoboticCallLogSendmsg.setCallerIds(calleeIds);
+                List<CompanyVoiceRoboticCallLogSendmsgVO> list = companyVoiceRoboticCallLogSendmsgService.listByCallerIdAndRoboticId(companyVoiceRoboticCallLogSendmsg);
+                return getDataTable(list);
+            } else{
+                return getDataTable(new ArrayList<>());
+            }
+        }else{
+            startPage();
+            List<CompanyVoiceRoboticCallLogSendmsgVO> list = companyVoiceRoboticCallLogSendmsgService.listByCallerIdAndRoboticId(companyVoiceRoboticCallLogSendmsg);
+            return getDataTable(list);
+        }
+
+    }
+
 //    /**
 //     * 导出调用日志_发送短信列表
 //     */

+ 9 - 0
fs-company/src/main/java/com/fs/company/controller/company/CompanyVoiceRoboticController.java

@@ -1,7 +1,9 @@
 package com.fs.company.controller.company;
 
+import com.fs.aicall.domain.BaseDomain;
 import com.fs.aicall.domain.TaskInfo;
 import com.fs.aicall.domain.apiresult.PushIIntentionResult;
+import com.fs.aicall.domain.result.CIDGroupListResult;
 import com.fs.aicall.domain.result.EditDialogResult;
 import com.fs.aicall.domain.result.GetairobotResult;
 import com.fs.aicall.domain.result.QueryCallTaskInfoResult;
@@ -230,4 +232,11 @@ public class CompanyVoiceRoboticController extends BaseController
         companyVoiceRoboticService.taskRun(id);
         return R.ok();
     }
+
+    @GetMapping("/getCIDGroupList")
+    public R getCIDGroupList(){
+        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
+        List<CIDGroupListResult> cidGroupList = aiCallService.getCIDGroupList(null, loginUser.getCompany().getCompanyId());
+        return R.ok().put("data", cidGroupList);
+    }
 }

+ 13 - 1
fs-company/src/test/java/com/mixLiu/test/mixLiuTester.java

@@ -4,6 +4,7 @@ import com.fs.FsCompanyApplication;
 import com.fs.aicall.domain.TaskInfo;
 import com.fs.aicall.domain.param.getDialogMapDomain;
 import com.fs.aicall.service.AiCallService;
+import com.fs.his.domain.FsDoctor;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.junit.Test;
@@ -24,9 +25,20 @@ public class mixLiuTester {
     @Test
     public void testQuery(){
         getDialogMapDomain getDialogMap = getDialogMapDomain.builder()
-                .uuid("9aa78108-f123-11f0-a543-e1463f771d05")
+                .uuid("6ed561ce-f2b5-11f0-b192-5b962a6d1eb9")
                 .build();
         TaskInfo dialogMap = aiCallService.getDialogMapNew(getDialogMap, 329L);
         log.info("{}",dialogMap);
     }
+
+    @Test
+    public void test11(){
+        FsDoctor doctorMap = new FsDoctor();
+        doctorMap.setDoctorId(1L);
+        doctorMap.setJpushId("123");
+
+        if(doctorMap.getStatus() != 1){
+            System.out.println("开始删除处方医生");
+        }
+    }
 }

+ 15 - 0
fs-service/src/main/java/com/fs/aicall/domain/CIDGroupInfo.java

@@ -0,0 +1,15 @@
+package com.fs.aicall.domain;
+
+import lombok.*;
+
+import java.util.List;
+
+@Data
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
+@EqualsAndHashCode(callSuper = true)
+public class CIDGroupInfo extends BaseDomain {
+
+    public List<CIDGroupInfoDataItem> data;
+}

+ 13 - 0
fs-service/src/main/java/com/fs/aicall/domain/CIDGroupInfoDataItem.java

@@ -0,0 +1,13 @@
+package com.fs.aicall.domain;
+
+import com.google.gson.JsonArray;
+import lombok.Data;
+
+@Data
+public class CIDGroupInfoDataItem {
+    private String id;
+    private String name;
+    private JsonArray did;
+    private JsonArray cid;
+    private JsonArray channel;
+}

+ 1 - 1
fs-service/src/main/java/com/fs/aicall/domain/param/CalltaskcreateaiCustomizeDomain.java

@@ -44,7 +44,7 @@ public class CalltaskcreateaiCustomizeDomain extends BaseDomain {
     主叫分组ID	Int	N	-	主叫号码 和 主叫分组ID 必传其中一个,都传情况下,以 主叫分组ID为主
      */
     @JsonProperty("CIDGroupID")
-    private String CIDGroupID = "2";
+    private String CIDGroupID;
     /*
     任务名称	String	N	-	-
      */

+ 12 - 2
fs-service/src/main/java/com/fs/aicall/service/AiCallService.java

@@ -51,6 +51,16 @@ public class AiCallService {
             return t;
         };
     }
+    private <T extends BaseDomain> Function<JSONObject, List<T>> getArr(String attr, Class<T> clazz){
+        return e -> {
+            List<T> t = e.getJSONArray(attr).toJavaList(clazz);
+            t.forEach(i->{
+                i.setUserData(e.getString("userData"));
+                i.setSeq(e.getString("seq"));
+            });
+            return t;
+        };
+    }
 
     private <T extends BaseDomain> Function<JSONObject, List<T>> getList(String attr, Class<T> clazz){
         return e -> {
@@ -143,7 +153,7 @@ public class AiCallService {
      * 获取主叫分组
      * @param param 参数
      */
-    public CIDGroupListResult getCIDGroupList(BaseDomain param, Long companyId){
-        return AiCallUtils.send("getCIDGroupList", OBJECT_MAPPER.valueToTree(param), getObj("telData", CIDGroupListResult.class), companyId);
+    public List<CIDGroupListResult> getCIDGroupList(BaseDomain param, Long companyId){
+        return AiCallUtils.send("getCIDGroupList",null, getArr("data", CIDGroupListResult.class), companyId);
     }
 }

+ 126 - 0
fs-service/src/main/java/com/fs/common/service/impl/SmsServiceImpl.java

@@ -47,6 +47,7 @@ import java.net.URLEncoder;
 import java.text.SimpleDateFormat;
 import java.util.Date;
 import java.util.List;
+import java.util.concurrent.ConcurrentHashMap;
 
 @Service
 @Slf4j
@@ -747,6 +748,131 @@ public class SmsServiceImpl implements ISmsService
 
 
 
+        }
+    }
+
+    private static ConcurrentHashMap<Long, Object> smsCompanyLock = new ConcurrentHashMap();
+
+    /**
+     * copy一份 batchSmsOp
+     * @param temp
+     * @param param
+     */
+    @Async
+    public void batchSmsOp4AiSend(CompanySmsTemp temp, SmsSendBatchParam param){
+        CompanyUser companyUser=companyUserService.selectCompanyUserById(param.getCompanyUserId());
+        for(Long id:param.getCustomerIds()){
+            CrmCustomer crmCustomer=crmCustomerService.selectCrmCustomerById(id);
+            String content="";
+            content=param.getContent();
+            if(StringUtils.isNotEmpty(crmCustomer.getCustomerName())){
+                content=content.replace("${sms.csName}",crmCustomer.getCustomerName());
+            }
+            if(companyUser!=null&& StringUtils.isNotEmpty(companyUser.getPhonenumber())){
+                content=content.replace("${sms.phoneNumber}",companyUser.getPhonenumber());
+            }
+            if(StringUtils.isNotEmpty(param.getCardUrl())){
+                content=content.replace("${sms.cardUrl}",param.getCardUrl());
+            }
+            if(StringUtils.isNotEmpty(param.getSenderName())){
+                content=content.replace("${sms.senderName}",param.getSenderName());
+            }
+
+            String urls= null;
+            // 通知类的不加 退订回T 只有营销类的加
+            //最多500个手机号
+            SysConfig sysConfig = sysConfigMapper.selectConfigByConfigKey("his.sms");
+            FsSmsConfig sms = JSON.parseObject(sysConfig.getConfigValue(), FsSmsConfig.class);
+            if (sms.getType().equals("rf")){
+                try {
+                    if(temp.getTempType().equals(1)){
+                        urls = sms.getRfUrl1()+"sms?action=send&account="+sms.getRfAccount1()+"&password="+sms.getRfPassword1()+"&mobile="+crmCustomer.getMobile()+"&content="+ URLEncoder.encode(sms.getRfSign()+content, "UTF-8")+"&extno="+sms.getRfCode1()+"&rt=json";
+                    }
+                    else if(temp.getTempType().equals(2)){
+                        urls = sms.getRfUrl2()+"sms?action=send&account="+sms.getRfAccount2()+"&password="+sms.getRfPassword2()+"&mobile="+crmCustomer.getMobile()+"&content="+ URLEncoder.encode(sms.getRfSign()+content+"拒收请回复R", "UTF-8")+"&extno="+sms.getRfCode2()+"&rt=json";
+                    }
+                } catch (UnsupportedEncodingException e) {
+                    e.printStackTrace();
+                }
+                String post = HttpRequest.get(urls)
+//                            .body(String.valueOf(jsonObject))
+                        .execute().body();
+                SmsSendVO vo=JSONUtil.toBean(post, SmsSendVO.class);
+                if(vo.getStatus().equals(0)){
+                    Integer resultCount=0;
+                    for(SmsSendItemVO itemVO:vo.getList()){
+                        if(itemVO.getResult().equals("0")){
+                            CompanySmsLogs logs=new CompanySmsLogs();
+                            logs.setCompanyId(param.getCompanyId());
+                            logs.setCustomerId(id);
+                            logs.setContent(content);
+                            logs.setTempCode(temp.getTempCode());
+                            logs.setCompanyUserId(param.getCompanyUserId());
+                            logs.setTempId(temp.getTempId());
+                            logs.setPhone(crmCustomer.getMobile());
+                            logs.setSendTime(new Date());
+                            logs.setStatus(0);
+                            logs.setType(sms.getType());
+                            logs.setMid(itemVO.getMid());
+                            Integer counts=logs.getContent().length()/67;
+                            if(logs.getContent().length()%67>0){
+                                counts=counts+1;
+                            }
+                            if(counts==0){
+                                counts=1;
+                            }
+                            logs.setNumber(counts);
+                            smsLogsService.insertCompanySmsLogs(logs);
+                            Object lock = smsCompanyLock.computeIfAbsent(logs.getCompanyId(), k -> new Object());
+                            //任务调用时可能存在并发情况 这里优化一下扣减时条数准确
+                            synchronized (lock) {
+                                companySmsService.subCompanySms(logs.getCompanyId(), logs.getNumber());
+                            }
+//                            companySmsService.subCompanySms(logs.getCompanyId(),logs.getNumber());
+                            resultCount++;
+                        }
+                    }
+                }
+            }else if (sms.getType().equals("dh")){
+                SendSmsReturn sendSmsReturn =null;
+                CompanySmsLogs logs=new CompanySmsLogs();
+                logs.setCompanyId(param.getCompanyId());
+                logs.setCustomerId(id);
+                logs.setContent(content);
+                logs.setTempCode(temp.getTempCode());
+                logs.setCompanyUserId(param.getCompanyUserId());
+                logs.setTempId(temp.getTempId());
+                logs.setPhone(crmCustomer.getMobile());
+                logs.setSendTime(new Date());
+                logs.setStatus(0);
+                logs.setType(sms.getType());
+                Integer counts=logs.getContent().length()/67;
+                if(logs.getContent().length()%67>0){
+                    counts=counts+1;
+                }
+                if(counts==0){
+                    counts=1;
+                }
+                logs.setNumber(counts);
+                if(temp.getTempType().equals(1)){
+                    sendSmsReturn = smsTService.sendSms(sms.getDhAccount1(), sms.getDhPassword1(), content, crmCustomer.getMobile());
+                }
+                else if(temp.getTempType().equals(2)){
+                    sendSmsReturn=  smsTService.sendSms(sms.getDhAccount2(),sms.getDhPassword2(),content+"拒收请回复R",crmCustomer.getMobile());
+                }
+                System.out.println(sendSmsReturn);
+                if (sendSmsReturn!=null){
+                    if (sendSmsReturn.getResult()!=null&&sendSmsReturn.getResult().equals("0")){
+                        logs.setMid(sendSmsReturn.getMsgid());
+                        smsLogsService.insertCompanySmsLogs(logs);
+//                        companySmsService.subCompanySms(logs.getCompanyId(),logs.getNumber());
+                        Object lock = smsCompanyLock.computeIfAbsent(logs.getCompanyId(), k -> new Object());
+                        synchronized (lock) {
+                            companySmsService.subCompanySms(logs.getCompanyId(), logs.getNumber());
+                        }
+                    }
+                }
+            }
         }
     }
 }

+ 8 - 0
fs-service/src/main/java/com/fs/company/domain/CompanyVoiceRoboticCallLogAddwx.java

@@ -1,8 +1,10 @@
 package com.fs.company.domain;
 
 import java.util.Date;
+import java.util.List;
 
 import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableField;
 import com.fasterxml.jackson.annotation.JsonFormat;
 import com.baomidou.mybatisplus.annotation.TableId;
 import com.fs.common.annotation.Excel;
@@ -58,6 +60,12 @@ public class CompanyVoiceRoboticCallLogAddwx extends BaseEntity{
     /** 个微账号id */
     @Excel(name = "个微账号id")
     private Long wxAccountId;
+
+    @TableField(exist = false)
+    private Long customerId;
+
+    @TableField(exist = false)
+    private List<Long> wxclientIds;
     public static CompanyVoiceRoboticCallLogAddwx initCallLog( String runParam, Long keyId, Long taskId,Long wxAccountId,Long companyId) {
         CompanyVoiceRoboticCallLogAddwx log = new CompanyVoiceRoboticCallLogAddwx();
         log.wxClientId = keyId;

+ 14 - 0
fs-service/src/main/java/com/fs/company/domain/CompanyVoiceRoboticCallLogCallphone.java

@@ -2,8 +2,10 @@ package com.fs.company.domain;
 
 import java.math.BigDecimal;
 import java.util.Date;
+import java.util.List;
 
 import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableField;
 import com.fasterxml.jackson.annotation.JsonFormat;
 import com.baomidou.mybatisplus.annotation.TableId;
 import com.fs.common.annotation.Excel;
@@ -98,6 +100,18 @@ public class CompanyVoiceRoboticCallLogCallphone extends BaseEntity{
     @Excel(name = "花费金额")
     private BigDecimal cost;
 
+    @TableField(exist = false)
+    private String companyName;
+
+    @TableField(exist = false)
+    private String companyUserName;
+
+    @TableField(exist = false)
+    private Long customerId;
+
+    @TableField(exist = false)
+    private List<Long> callerIds;
+
     public static CompanyVoiceRoboticCallLogCallphone initCallLog( String runParam, Long keyId, Long taskId,Long companyId) {
         CompanyVoiceRoboticCallLogCallphone log = new CompanyVoiceRoboticCallLogCallphone();
         log.callerId = keyId;

+ 8 - 0
fs-service/src/main/java/com/fs/company/domain/CompanyVoiceRoboticCallLogSendmsg.java

@@ -2,8 +2,10 @@ package com.fs.company.domain;
 
 import java.math.BigDecimal;
 import java.util.Date;
+import java.util.List;
 
 import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableField;
 import com.fasterxml.jackson.annotation.JsonFormat;
 import com.baomidou.mybatisplus.annotation.TableId;
 import com.fs.common.annotation.Excel;
@@ -70,6 +72,12 @@ public class CompanyVoiceRoboticCallLogSendmsg extends BaseEntity{
     @Excel(name = "内容长度")
     private Integer contentLen;
 
+    @TableField(exist = false)
+    private Long customerId;
+
+    @TableField(exist = false)
+    private List<Long> callerIds;
+
     public static CompanyVoiceRoboticCallLogSendmsg initCallLog( String runParam, Long keyId, Long taskId,Long companyId,Long companyUserId,Long tempId) {
         CompanyVoiceRoboticCallLogSendmsg log = new CompanyVoiceRoboticCallLogSendmsg();
         log.callerId = keyId;

+ 3 - 0
fs-service/src/main/java/com/fs/company/domain/CompanyVoiceRoboticCallees.java

@@ -59,4 +59,7 @@ public class CompanyVoiceRoboticCallees{
     private String taskName;
     //是否已发送短信:-1:不需要发送, 0:未发送,1:已发送
     private Integer isSendMsg;
+
+    @TableField(exist = false)
+    private String idToString;
 }

+ 6 - 0
fs-service/src/main/java/com/fs/company/mapper/CompanyVoiceRoboticCallLogAddwxMapper.java

@@ -3,6 +3,8 @@ package com.fs.company.mapper;
 import java.util.List;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.fs.company.domain.CompanyVoiceRoboticCallLogAddwx;
+import com.fs.company.vo.CompanyVoiceRoboticCallLogAddwxVO;
+import org.apache.ibatis.annotations.Param;
 
 /**
  * 调用日志_加微信Mapper接口
@@ -58,4 +60,8 @@ public interface CompanyVoiceRoboticCallLogAddwxMapper extends BaseMapper<Compan
      * @return 结果
      */
     int deleteCompanyVoiceRoboticCallLogAddwxByLogIds(Long[] logIds);
+
+    List<CompanyVoiceRoboticCallLogAddwxVO>  listByCustomerIdAndRoboticId(CompanyVoiceRoboticCallLogAddwx companyVoiceRoboticCallLogAddwx);
+
+    List<CompanyVoiceRoboticCallLogAddwxVO> listByCustomerId(CompanyVoiceRoboticCallLogAddwx companyVoiceRoboticCallLogAddwx);
 }

+ 2 - 0
fs-service/src/main/java/com/fs/company/mapper/CompanyVoiceRoboticCallLogCallphoneMapper.java

@@ -64,4 +64,6 @@ public interface CompanyVoiceRoboticCallLogCallphoneMapper extends BaseMapper<Co
     CompanyVoiceRoboticCallLogCallphone selectNoResultLogByCallees(CompanyVoiceRoboticCallees callees);
 
     CompanyVoiceRoboticCallLogCallphone selectLogByRoboticIdAndCallerId(@Param("roboticId") Long roboticId,@Param("callerId") Long callerId);
+
+    List<CompanyVoiceRoboticCallLogCallphone>  selectCompanyVoiceRoboticCallLogCallphoneListData(CompanyVoiceRoboticCallLogCallphone companyVoiceRoboticCallLogCallphone);
 }

+ 3 - 0
fs-service/src/main/java/com/fs/company/mapper/CompanyVoiceRoboticCallLogSendmsgMapper.java

@@ -3,6 +3,7 @@ package com.fs.company.mapper;
 import java.util.List;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.fs.company.domain.CompanyVoiceRoboticCallLogSendmsg;
+import com.fs.company.vo.CompanyVoiceRoboticCallLogSendmsgVO;
 
 /**
  * 调用日志_发送短信Mapper接口
@@ -58,4 +59,6 @@ public interface CompanyVoiceRoboticCallLogSendmsgMapper extends BaseMapper<Comp
      * @return 结果
      */
     int deleteCompanyVoiceRoboticCallLogSendmsgByLogIds(Long[] logIds);
+
+    List<CompanyVoiceRoboticCallLogSendmsgVO> listByCallerIdAndRoboticId(CompanyVoiceRoboticCallLogSendmsg companyVoiceRoboticCallLogSendmsg);
 }

+ 9 - 0
fs-service/src/main/java/com/fs/company/mapper/CompanyVoiceRoboticCalleesMapper.java

@@ -2,6 +2,8 @@ package com.fs.company.mapper;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.fs.company.domain.CompanyVoiceRoboticCallees;
+import com.fs.company.domain.CompanyWxClient;
+import com.fs.company.vo.SendMsgByTaskVO;
 import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
@@ -77,4 +79,11 @@ public interface CompanyVoiceRoboticCalleesMapper extends BaseMapper<CompanyVoic
     List<CompanyVoiceRoboticCallees> selectCalleesListByRoboticIdsAndUserIds(@Param("userIds") Set<Long> userIds, @Param("taskIds") Set<Long> taskIds);
 
     Integer getRoboticIsDoneByRoboticIdAndTaskFlow(@Param("roboticId") Long roboticId,@Param("taskFlow") String taskFlow);
+
+    List<Long> getCallerIdsByCustomerId(@Param("customerId") Long customerId);
+
+    List<SendMsgByTaskVO> getSendMsgTaskListByRoboticId(@Param("roboticId") Long roboticId);
+
+    List<CompanyVoiceRoboticCallees> selectExcludeList(@Param("list")List<CompanyWxClient> list);
+    List<Long> getNotFinishAddWxRobotic(@Param("roboticIds") Set<Long> roboticIds);
 }

+ 2 - 0
fs-service/src/main/java/com/fs/company/mapper/CompanyVoiceRoboticMapper.java

@@ -67,4 +67,6 @@ public interface CompanyVoiceRoboticMapper extends BaseMapper<CompanyVoiceRoboti
     List<CompanyVoiceRoboticQwUserListVo> qwUserListCompany(CompanyVoiceRobotic companyVoiceRobotic);
 
     void finishRobotic(@Param("id") Long id);
+
+    int finishAddWxRobotic(@Param("collect") List<Long> collect);
 }

+ 4 - 0
fs-service/src/main/java/com/fs/company/mapper/CompanyWxClientMapper.java

@@ -2,6 +2,7 @@ package com.fs.company.mapper;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.fs.company.domain.CompanyUser;
+import com.fs.company.domain.CompanyVoiceRoboticCallLogAddwx;
 import com.fs.company.domain.CompanyWxClient;
 import org.apache.ibatis.annotations.Param;
 
@@ -75,4 +76,7 @@ public interface CompanyWxClientMapper extends BaseMapper<CompanyWxClient> {
 
     List<CompanyWxClient> selectListByRoboticId(@Param("roboticId") Long roboticId);
     CompanyWxClient selectOneByRoboticIdAndUserId(@Param("roboticId") Long roboticId,@Param("customerId") Long customerId);
+
+    List<CompanyWxClient> getWxClientInfoByCustomerId(@Param("customerId") Long customerId);
+
 }

+ 11 - 0
fs-service/src/main/java/com/fs/company/service/ICompanyVoiceRoboticCallLogAddwxService.java

@@ -3,6 +3,8 @@ package com.fs.company.service;
 import java.util.List;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.fs.company.domain.CompanyVoiceRoboticCallLogAddwx;
+import com.fs.company.domain.CompanyWxClient;
+import com.fs.company.vo.CompanyVoiceRoboticCallLogAddwxVO;
 
 /**
  * 调用日志_加微信Service接口
@@ -58,4 +60,13 @@ public interface ICompanyVoiceRoboticCallLogAddwxService extends IService<Compan
      * @return 结果
      */
     int deleteCompanyVoiceRoboticCallLogAddwxByLogId(Long logId);
+
+    CompanyWxClient getWxClientInfoByCustomerIdAndRoboticId(Long customerId, Long roboticId);
+
+    List<CompanyWxClient> getWxClientInfoByCustomerId(Long customerId);
+
+
+    List<CompanyVoiceRoboticCallLogAddwxVO> listByCustomerIdAndRoboticId(CompanyVoiceRoboticCallLogAddwx companyVoiceRoboticCallLogAddwx);
+
+    List<CompanyVoiceRoboticCallLogAddwxVO> listByCustomerId(CompanyVoiceRoboticCallLogAddwx companyVoiceRoboticCallLogAddwx);
 }

+ 15 - 0
fs-service/src/main/java/com/fs/company/service/ICompanyVoiceRoboticCallLogCallphoneService.java

@@ -58,4 +58,19 @@ public interface ICompanyVoiceRoboticCallLogCallphoneService extends IService<Co
      * @return 结果
      */
     int deleteCompanyVoiceRoboticCallLogCallphoneByLogId(Long logId);
+
+    /**
+     * 查询调用日志_ai打电话列表
+     *
+     * @param companyVoiceRoboticCallLogCallphone 调用日志_ai打电话
+     * @return 调用日志_ai打电话集合
+     */
+    List<CompanyVoiceRoboticCallLogCallphone> selectCompanyVoiceRoboticCallLogCallphoneListData(CompanyVoiceRoboticCallLogCallphone companyVoiceRoboticCallLogCallphone);
+
+    /**
+     * 查询 calleesIds
+     * @param customerId
+     * @return
+     */
+    List<Long> getCallerIdsByCustomerId(Long customerId);
 }

+ 3 - 0
fs-service/src/main/java/com/fs/company/service/ICompanyVoiceRoboticCallLogSendmsgService.java

@@ -3,6 +3,7 @@ package com.fs.company.service;
 import java.util.List;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.fs.company.domain.CompanyVoiceRoboticCallLogSendmsg;
+import com.fs.company.vo.CompanyVoiceRoboticCallLogSendmsgVO;
 
 /**
  * 调用日志_发送短信Service接口
@@ -58,4 +59,6 @@ public interface ICompanyVoiceRoboticCallLogSendmsgService extends IService<Comp
      * @return 结果
      */
     int deleteCompanyVoiceRoboticCallLogSendmsgByLogId(Long logId);
+
+    List<CompanyVoiceRoboticCallLogSendmsgVO> listByCallerIdAndRoboticId(CompanyVoiceRoboticCallLogSendmsg companyVoiceRoboticCallLogSendmsg);
 }

+ 3 - 0
fs-service/src/main/java/com/fs/company/service/ICompanyVoiceRoboticService.java

@@ -8,6 +8,7 @@ import com.fs.company.vo.AddWxClientVo;
 import com.fs.company.vo.CompanyVoiceRoboticQwUserListVo;
 
 import java.util.List;
+import java.util.Set;
 
 /**
  * 机器人外呼任务Service接口
@@ -80,4 +81,6 @@ public interface ICompanyVoiceRoboticService extends IService<CompanyVoiceRoboti
     void cidList(Long companyId);
 
     void taskRun(Long id);
+
+    void finishAddWxByCallees(Set<Long> roboticIds);
 }

+ 38 - 0
fs-service/src/main/java/com/fs/company/service/impl/CompanyVoiceRoboticCallLogAddwxServiceImpl.java

@@ -5,6 +5,9 @@ import java.util.List;
 import com.fs.common.utils.DateUtils;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.fs.company.domain.CompanyVoiceRoboticCallLog;
+import com.fs.company.domain.CompanyWxClient;
+import com.fs.company.mapper.CompanyWxClientMapper;
+import com.fs.company.vo.CompanyVoiceRoboticCallLogAddwxVO;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.scheduling.annotation.Async;
@@ -105,4 +108,39 @@ public class CompanyVoiceRoboticCallLogAddwxServiceImpl extends ServiceImpl<Comp
             log.error("记录任务执行日志失败:失败数据:{}",companyVoiceRoboticCallLog, e);
         }
     }
+
+
+    @Autowired
+    CompanyWxClientMapper companyWxClientMapper;
+    /**
+     * 查询用户调用日志记录 1、查询client信息
+     * @param customerId
+     * @param roboticId
+     * @return
+     */
+    @Override
+    public CompanyWxClient getWxClientInfoByCustomerIdAndRoboticId(Long customerId, Long roboticId){
+        CompanyWxClient client = companyWxClientMapper.selectOneByRoboticIdAndUserId(roboticId, customerId);
+        return client;
+    }
+    @Override
+    public List<CompanyVoiceRoboticCallLogAddwxVO> listByCustomerIdAndRoboticId(CompanyVoiceRoboticCallLogAddwx companyVoiceRoboticCallLogAddwx){
+
+        return baseMapper.listByCustomerIdAndRoboticId(companyVoiceRoboticCallLogAddwx);
+    }
+
+    @Override
+    public List<CompanyVoiceRoboticCallLogAddwxVO> listByCustomerId(CompanyVoiceRoboticCallLogAddwx companyVoiceRoboticCallLogAddwx){
+        return baseMapper.listByCustomerId(companyVoiceRoboticCallLogAddwx);
+    }
+
+    /**
+     * 查询用户微信信息
+     * @param customerId
+     * @return
+     */
+    @Override
+    public  List<CompanyWxClient> getWxClientInfoByCustomerId(Long customerId){
+        return companyWxClientMapper.getWxClientInfoByCustomerId(customerId);
+    }
 }

+ 57 - 1
fs-service/src/main/java/com/fs/company/service/impl/CompanyVoiceRoboticCallLogCallphoneServiceImpl.java

@@ -1,8 +1,11 @@
 package com.fs.company.service.impl;
 
+import java.math.BigDecimal;
+import java.math.RoundingMode;
 import java.util.Date;
 import java.util.List;
 
+import cn.hutool.json.JSONUtil;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
@@ -11,10 +14,17 @@ import com.fs.aicall.domain.apiresult.Notify;
 import com.fs.aicall.domain.apiresult.PushIIntentionResult;
 import com.fs.aicall.domain.param.getDialogMapDomain;
 import com.fs.aicall.service.AiCallService;
+import com.fs.common.constant.Constants;
 import com.fs.common.utils.DateUtils;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.fs.common.utils.StringUtils;
 import com.fs.company.domain.*;
+import com.fs.company.mapper.CompanyVoiceRoboticCalleesMapper;
 import com.fs.company.mapper.CompanyWxAccountMapper;
+import com.fs.company.vo.CidConfigVO;
+import com.fs.store.config.StoreConfig;
+import com.fs.system.service.ISysConfigService;
+import com.fs.voice.constant.Constant;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.scheduling.annotation.Async;
@@ -40,6 +50,8 @@ public class CompanyVoiceRoboticCallLogCallphoneServiceImpl extends ServiceImpl<
     CompanyVoiceRoboticWxServiceImpl companyVoiceRoboticWxServiceImpl;
     @Autowired
     CompanyWxAccountMapper companyWxAccountMapper;
+    @Autowired
+    CompanyVoiceRoboticCalleesMapper companyVoiceRoboticCalleesMapper;
 
     /**
      * 查询调用日志_ai打电话
@@ -127,9 +139,34 @@ public class CompanyVoiceRoboticCallLogCallphoneServiceImpl extends ServiceImpl<
     @Autowired
     AiCallService aiCallService;
 
+    @Autowired
+    private ISysConfigService configService;
+
+    private static final BigDecimal DEFAULT_CALL_CHARGE = new BigDecimal("0.12");
+    private static final BigDecimal ONE_MINUTES_SECOND = new BigDecimal("60");
     @Async("callLogExcutor")
     public void asyncHandleCalleeCallBackResult(PushIIntentionResult result, CompanyVoiceRoboticCallees callees) {
         try {
+            String runTaskFlow = callees.getRunTaskFlow();
+            if(StringUtils.isBlank(runTaskFlow)){
+                runTaskFlow = Constants.CELL_PHONE;
+            }else{
+                if (!runTaskFlow.contains(Constants.CELL_PHONE)) {
+                    runTaskFlow = runTaskFlow + "," + Constants.CELL_PHONE;
+                }
+            }
+            if(!runTaskFlow.equals(callees.getRunTaskFlow())){
+                CompanyVoiceRoboticCallees updateCallees = new CompanyVoiceRoboticCallees();
+                updateCallees.setId(callees.getId());
+                updateCallees.setRunTaskFlow(runTaskFlow);
+                companyVoiceRoboticCalleesMapper.updateById(updateCallees);
+            }
+            String json= configService.selectConfigByKey("cid.config");
+            if(StringUtils.isBlank( json)){
+                log.error("未配置cid.config");
+            }
+            CidConfigVO cidConfigVO = JSONUtil.toBean(json, CidConfigVO.class);
+
             Notify notify = result.getNotify();
             String uuid = notify.getUuid();
             getDialogMapDomain getDialogMap = getDialogMapDomain.builder()
@@ -160,7 +197,15 @@ public class CompanyVoiceRoboticCallLogCallphoneServiceImpl extends ServiceImpl<
             companyVoiceRoboticCallLog.setCallAnswerTime(answerTime);
             companyVoiceRoboticCallLog.setIntention((String) telData.getOrDefault("intention", ""));
             companyVoiceRoboticCallLog.setCallTime( telData.getLong("duration"));
-
+            BigDecimal callCharge = cidConfigVO.getCallCharge();
+            //
+            if(null == callCharge){
+                callCharge = DEFAULT_CALL_CHARGE;
+            }
+            //向上取整分钟数
+            BigDecimal divide = new BigDecimal(companyVoiceRoboticCallLog.getCallTime()).divide(ONE_MINUTES_SECOND, 0, RoundingMode.CEILING);
+            BigDecimal multiply = divide.multiply(callCharge);
+            companyVoiceRoboticCallLog.setCost(multiply);
             baseMapper.updateCompanyVoiceRoboticCallLogCallphone(companyVoiceRoboticCallLog);
         } catch (Exception ex) {
             log.error("处理回调结果异常:{}", result, ex);
@@ -179,4 +224,15 @@ public class CompanyVoiceRoboticCallLogCallphoneServiceImpl extends ServiceImpl<
     public CompanyVoiceRoboticCallLogCallphone selectLogByRoboticIdAndCallerId(Long roboticId,Long callerId){
             return  baseMapper.selectLogByRoboticIdAndCallerId(roboticId,callerId);
     }
+
+    @Override
+    public List<CompanyVoiceRoboticCallLogCallphone> selectCompanyVoiceRoboticCallLogCallphoneListData(CompanyVoiceRoboticCallLogCallphone companyVoiceRoboticCallLogCallphone){
+        List<CompanyVoiceRoboticCallLogCallphone> result = baseMapper.selectCompanyVoiceRoboticCallLogCallphoneListData(companyVoiceRoboticCallLogCallphone);
+        return result;
+    }
+
+    @Override
+    public List<Long> getCallerIdsByCustomerId(Long customerId){
+        return companyVoiceRoboticCalleesMapper.getCallerIdsByCustomerId(customerId);
+    }
 }

+ 7 - 0
fs-service/src/main/java/com/fs/company/service/impl/CompanyVoiceRoboticCallLogSendmsgServiceImpl.java

@@ -1,9 +1,11 @@
 package com.fs.company.service.impl;
 
+import java.util.Collections;
 import java.util.List;
 import com.fs.common.utils.DateUtils;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.fs.company.domain.CompanyVoiceRoboticCallLogCallphone;
+import com.fs.company.vo.CompanyVoiceRoboticCallLogSendmsgVO;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.scheduling.annotation.Async;
@@ -108,4 +110,9 @@ public class CompanyVoiceRoboticCallLogSendmsgServiceImpl extends ServiceImpl<Co
             log.error("记录任务执行日志失败:失败数据:{}",sendMsgLog, e);
         }
     }
+
+    @Override
+    public List<CompanyVoiceRoboticCallLogSendmsgVO> listByCallerIdAndRoboticId(CompanyVoiceRoboticCallLogSendmsg companyVoiceRoboticCallLogSendmsg){
+        return baseMapper.listByCallerIdAndRoboticId(companyVoiceRoboticCallLogSendmsg);
+    }
 }

+ 7 - 1
fs-service/src/main/java/com/fs/company/service/impl/CompanyVoiceRoboticCalleesServiceImpl.java

@@ -97,6 +97,12 @@ public class CompanyVoiceRoboticCalleesServiceImpl extends ServiceImpl<CompanyVo
     public List<CompanyVoiceRoboticCallees> selectCompanyVoiceRoboticCalleesListByRoboticId(Long id) {
         CompanyVoiceRoboticCallees param = new CompanyVoiceRoboticCallees();
         param.setRoboticId(id);
-        return selectCompanyVoiceRoboticCalleesList(param);
+        List<CompanyVoiceRoboticCallees> companyVoiceRoboticCallees = selectCompanyVoiceRoboticCalleesList(param);
+        if(null != companyVoiceRoboticCallees && !companyVoiceRoboticCallees.isEmpty()){
+            companyVoiceRoboticCallees.forEach(item -> {
+                item.setIdToString(item.getId().toString());
+            });
+        }
+        return companyVoiceRoboticCallees;
     }
 }

+ 95 - 16
fs-service/src/main/java/com/fs/company/service/impl/CompanyVoiceRoboticServiceImpl.java

@@ -20,10 +20,7 @@ import com.fs.common.utils.*;
 import com.fs.company.domain.*;
 import com.fs.company.mapper.*;
 import com.fs.company.service.*;
-import com.fs.company.vo.AddWxClientVo;
-import com.fs.company.vo.CompanyVoiceRoboticQwUserListVo;
-import com.fs.company.vo.RoboticWxAccountVo;
-import com.fs.company.vo.RoboticWxVo;
+import com.fs.company.vo.*;
 import com.fs.crm.domain.CrmCustomer;
 import com.fs.crm.mapper.CrmCustomerMapper;
 import com.fs.crm.param.SmsSendBatchParam;
@@ -172,20 +169,24 @@ public class CompanyVoiceRoboticServiceImpl extends ServiceImpl<CompanyVoiceRobo
         List<CompanyVoiceRoboticCallLogCallphone>  addLogs = new ArrayList<>();
         // 构建三方接口请求数据
         CalltaskcreateaiCustomizeDomain param = new CalltaskcreateaiCustomizeDomain();
+        param.setCIDGroupID(companyVoiceRobotic.getCidGroupId().toString());
         param.setRobot(companyVoiceRobotic.getRobot());
         param.setDialogID(companyVoiceRobotic.getDialogId());
         param.setMode(companyVoiceRobotic.getMode());
         // 保存外呼电话列表
-        List<CompanyVoiceRoboticCallees> calleesList = customerList.stream().map(e -> {
-            CompanyVoiceRoboticCallees entity = new CompanyVoiceRoboticCallees();
-            entity.setUserId(e.getCustomerId());
-            entity.setUserName(e.getCustomerName());
-            entity.setPhone(e.getMobile());
-            entity.setRoboticId(companyVoiceRobotic.getId());
-            return entity;
-        }).collect(Collectors.toList());
-        companyVoiceRoboticCalleesMapper.deleteByRoboticId(companyVoiceRobotic.getId());
-        companyVoiceRoboticCalleesMapper.insertCompanyVoiceRoboticCalleesList(calleesList);
+//        List<CompanyVoiceRoboticCallees> calleesList = customerList.stream().map(e -> {
+//            CompanyVoiceRoboticCallees entity = new CompanyVoiceRoboticCallees();
+//            entity.setUserId(e.getCustomerId());
+//            entity.setUserName(e.getCustomerName());
+//            entity.setPhone(e.getMobile());
+//            entity.setRoboticId(companyVoiceRobotic.getId());
+//            return entity;
+//        }).collect(Collectors.toList());
+//        companyVoiceRoboticCalleesMapper.deleteByRoboticId(companyVoiceRobotic.getId());
+//        companyVoiceRoboticCalleesMapper.insertCompanyVoiceRoboticCalleesList(calleesList);
+        CompanyVoiceRoboticCallees querP = new CompanyVoiceRoboticCallees();
+        querP.setRoboticId(companyVoiceRobotic.getId());
+        List<CompanyVoiceRoboticCallees> calleesList = companyVoiceRoboticCalleesMapper.selectCompanyVoiceRoboticCalleesList(querP);
         // 外呼电话列表
         List<CalleeDomain> mobileList = calleesList.stream().map(e -> CalleeDomain.builder().number(e.getPhone()).userData(e.getId().toString()).build()).collect(Collectors.toList());
         param.setCallees(mobileList);
@@ -293,7 +294,7 @@ public class CompanyVoiceRoboticServiceImpl extends ServiceImpl<CompanyVoiceRobo
     @Synchronized
     public void sendMsgOne(Long roboticId,Long callerId){
         try{
-            log.info("开始发送短信*************");
+            log.info("开始发送短信个人*************");
             CompanyVoiceRobotic robotic = companyVoiceRoboticMapper.selectById(roboticId);
             CompanyVoiceRoboticCallees callees = companyVoiceRoboticCalleesMapper.selectById(callerId);
             CompanyWxClient wxClient = companyWxClientMapper.selectOneByRoboticIdAndUserId(roboticId,callees.getUserId());
@@ -304,6 +305,9 @@ public class CompanyVoiceRoboticServiceImpl extends ServiceImpl<CompanyVoiceRobo
                 CompanySms sms=companySmsService.selectCompanySmsByCompanyId(wxAccount.getCompanyId());
                 if(sms!=null){
                     if(sms.getRemainSmsCount()>0){
+//                        if(sms.getRemainSmsCount()<(param.getCustomerIds().length*2)){
+//                            return R.error("短信数量不足");
+//                        }
                         SmsSendBatchParam smsSendBatchParam=new SmsSendBatchParam();
                         smsSendBatchParam.setSmsType(temp.getTempType());
                         smsSendBatchParam.setCompanyId(wxAccount.getCompanyId());
@@ -374,6 +378,74 @@ public class CompanyVoiceRoboticServiceImpl extends ServiceImpl<CompanyVoiceRobo
         }
     }
 
+
+//    public void sendMsgTask(Long roboticId) {
+//        try {
+//            //根据任务找到发送短信对象
+//            List<SendMsgByTaskVO> list = companyVoiceRoboticCalleesMapper.getSendMsgTaskListByRoboticId(roboticId);
+//            // 按 companyId 分组
+//            Map<Long, List<SendMsgByTaskVO>> groupedByCompanyId = list.stream()
+//                    .collect(Collectors.groupingBy(SendMsgByTaskVO::getCompanyId));
+//            // 遍历每个公司的任务列表
+//            for (Map.Entry<Long, List<SendMsgByTaskVO>> entry : groupedByCompanyId.entrySet()) {
+//                Long companyId = entry.getKey();
+//                List<SendMsgByTaskVO> companyTasks = entry.getValue();
+//                CompanySms sms = companySmsService.selectCompanySmsByCompanyId(companyId);
+//                if(sms!=null){
+//                    if(sms.getRemainSmsCount()>0){
+//                        if(sms.getRemainSmsCount()<(companyTasks.size()*2)){
+//                            log.error("短信数量不足,请充值:task:{},companyId:{}",roboticId,companyId);
+//                            continue;
+//                        }
+//                        // 处理每个公司的任务
+//                        for (SendMsgByTaskVO item : companyTasks) {
+//                            // 处理逻辑
+//                            CompanySmsTemp temp = item.getCompanySmsTemp();
+//                            if (temp != null && temp.getStatus().equals(1) && temp.getIsAudit().equals(1)) {
+//                                SmsSendBatchParam smsSendBatchParam=new SmsSendBatchParam();
+//                                smsSendBatchParam.setSmsType(temp.getTempType());
+//                                smsSendBatchParam.setCompanyId(item.getCompanyId());
+//                                smsSendBatchParam.setCompanyUserId(item.getCompanyUserId());
+//                                smsSendBatchParam.setTempCode(temp.getTempCode());
+//                                Long[] ids=new Long[1];
+//                                ids[0]=item.getUserId();
+//                                smsSendBatchParam.setCustomerIds(ids);
+//                                smsSendBatchParam.setContent(temp.getContent());
+//                                smsSendBatchParam.setSenderName(item.getWxNickName());
+//                                JSONObject runParam = (JSONObject) JSON.toJSON(smsSendBatchParam);
+//                                runParam.put("temp",temp);
+//                                CompanyVoiceRoboticCallLogSendmsg addLog = CompanyVoiceRoboticCallLogSendmsg.initCallLog(
+//                                        runParam.toJSONString(), item.getCalleesId(), roboticId,item.getCompanyId(),item.getCompanyUserId(),temp.getTempId());
+//                                addLog.setStatus(2);
+//                                try{
+//                                    sendMsgBatch(temp,smsSendBatchParam);
+//                                } catch(Exception ex){
+//                                    addLog.setStatus(3);
+//                                    addLog.setResult(ex.getMessage());
+//                                    log.error("sendMsgTask:",ex);
+//                                }
+//                                int smsContentLen = getSmsContentLen(smsSendBatchParam);
+//                                addLog.setContentLen(smsContentLen);
+//                                companyVoiceRoboticCallLogSendmsgService.asyncInsertCompanyVoiceRoboticCallLog(addLog);
+//                            } else {
+//                                log.error("模板未审核,不发送:task:{},calleesId :{} ,smsTemp:{}", roboticId, item.getCalleesId(), temp);
+//                            }
+//                        }
+//                    }
+//                    else {
+//                        log.error("剩余短信数量不足,请充值:task:{},companyId:{}",roboticId,companyId);
+//                    }
+//                }
+//                else{
+//                    log.error("sendMsgTask 请充值:task:{},companyId:{}",roboticId,companyId);
+//                }
+//            }
+//        } catch (Exception ex) {
+//            log.error("sendMsgTask异常,roboticId:{}\n", roboticId, ex);
+//            throw new RuntimeException(ex);
+//        }
+//    }
+
     public int getSmsContentLen(SmsSendBatchParam param){
         CompanyUser companyUser=companyUserService.selectCompanyUserById(param.getCompanyUserId());
 
@@ -400,7 +472,7 @@ public class CompanyVoiceRoboticServiceImpl extends ServiceImpl<CompanyVoiceRobo
      * @param param
      */
     public void sendMsgBatch(CompanySmsTemp temp, SmsSendBatchParam param){
-        smsService.batchSmsOp(temp, param);
+        smsService.batchSmsOp4AiSend(temp, param);
     }
     /**
      * 修改机器人外呼任务
@@ -708,4 +780,11 @@ public class CompanyVoiceRoboticServiceImpl extends ServiceImpl<CompanyVoiceRobo
             companyVoiceRoboticWxService.updateById(companyVoiceRoboticWx);
         }
     }
+
+    @Override
+    public void finishAddWxByCallees(Set<Long> roboticIds){
+        List<Long> notFinishAddWxRobotic = companyVoiceRoboticCalleesMapper.getNotFinishAddWxRobotic(roboticIds);
+        List<Long> collect = roboticIds.stream().filter(roboticId -> !notFinishAddWxRobotic.contains(roboticId)).collect(Collectors.toList());
+        companyVoiceRoboticMapper.finishAddWxRobotic(collect);
+    }
 }

+ 13 - 0
fs-service/src/main/java/com/fs/company/vo/CidConfigVO.java

@@ -0,0 +1,13 @@
+package com.fs.company.vo;
+
+import lombok.Data;
+
+import java.math.BigDecimal;
+
+@Data
+public class CidConfigVO {
+
+    private BigDecimal callCharge;
+
+    private BigDecimal smsCharge;
+}

+ 50 - 0
fs-service/src/main/java/com/fs/company/vo/CompanyVoiceRoboticCallLogAddwxVO.java

@@ -0,0 +1,50 @@
+package com.fs.company.vo;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import com.fs.common.annotation.Excel;
+import lombok.Data;
+
+import java.util.Date;
+
+@Data
+public class CompanyVoiceRoboticCallLogAddwxVO {
+    private Long logId;
+
+    private Long roboticId;
+
+    private Long wxClientId;
+    private String wxClientName;
+
+    /** 记录调用时间 */
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    @Excel(name = "记录调用时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
+    private Date runTime;
+
+    /** 调用参数 */
+    @Excel(name = "调用参数")
+    private String runParam;
+
+    /** 执行结果 */
+    @Excel(name = "执行结果")
+    private String result;
+
+    /** 执行状态:1、执行中,2、执行成功,3、执行失败 */
+    @Excel(name = "执行状态:1、执行中,2、执行成功,3、执行失败")
+    private Integer status;
+
+    /** 公司id */
+    @Excel(name = "公司id")
+    private Long companyId;
+    private String companyName;
+    private String companyUserName;
+
+    /** 个微账号id */
+    @Excel(name = "个微账号id")
+    private Long wxAccountId;
+    private String wxAccountName;
+
+    private Long customerId;
+}

+ 73 - 0
fs-service/src/main/java/com/fs/company/vo/CompanyVoiceRoboticCallLogSendmsgVO.java

@@ -0,0 +1,73 @@
+package com.fs.company.vo;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import com.fs.common.annotation.Excel;
+import lombok.Data;
+
+import java.math.BigDecimal;
+import java.util.Date;
+
+@Data
+public class CompanyVoiceRoboticCallLogSendmsgVO {
+
+    /** $column.columnComment */
+    private Long logId;
+
+    /** 任务id */
+    @Excel(name = "任务id")
+    private Long roboticId;
+
+    @Excel(name = "任务名称")
+    private String roboticName;
+
+    /** caller_id */
+    @Excel(name = "caller_id")
+    private Long callerId;
+
+    /** 记录调用时间 */
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    @Excel(name = "记录调用时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
+    private Date runTime;
+
+    /** 调用参数 */
+    @Excel(name = "调用参数")
+    private String runParam;
+
+    /** 执行结果 */
+    @Excel(name = "执行结果")
+    private String result;
+
+    /** 执行状态:1、执行中,2、执行成功,3、执行失败 */
+    @Excel(name = "执行状态:1、执行中,2、执行成功,3、执行失败")
+    private Integer status;
+
+    /** 公司id */
+    @Excel(name = "公司id")
+    private Long companyId;
+
+    @Excel(name = "公司名称")
+    private String companyName;
+
+    /** 销售id */
+    @Excel(name = "销售id")
+    private Long companyUserId;
+    @Excel(name = "销售名称")
+    private String companyUserName;
+
+    /** 发送短信模板id */
+    @Excel(name = "发送短信模板id")
+    private Long tempId;
+
+    /** 花费金额 */
+    @Excel(name = "花费金额")
+    private BigDecimal cost;
+
+    /** 内容长度 */
+    @Excel(name = "内容长度")
+    private Integer contentLen;
+
+    @Excel(name = "短信模板名称")
+    private String smsTempName;
+}

+ 15 - 0
fs-service/src/main/java/com/fs/company/vo/SendMsgByTaskVO.java

@@ -0,0 +1,15 @@
+package com.fs.company.vo;
+
+import com.fs.company.domain.CompanySmsTemp;
+import lombok.Data;
+
+@Data
+public class SendMsgByTaskVO {
+    private Long roboticId;
+    private Long calleesId;
+    private Long userId;
+    private Long companyId;
+    private Long companyUserId;
+    private String wxNickName;
+    private CompanySmsTemp companySmsTemp;
+}

+ 38 - 0
fs-service/src/main/resources/mapper/company/CompanyVoiceRoboticCallLogAddwxMapper.xml

@@ -92,4 +92,42 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             #{logId}
         </foreach>
     </delete>
+
+    <select id="listByCustomerIdAndRoboticId" parameterType="CompanyVoiceRoboticCallLogAddwx" resultType="com.fs.company.vo.CompanyVoiceRoboticCallLogAddwxVO">
+        select
+        t1.*,
+        t2.wx_nick_name as wxAccountName,
+        t3.nick_name as wxClientName,
+        t4.company_name as companyName,
+        t5.nick_name as companyUserName
+        from company_voice_robotic_call_log_addwx t1
+        left join company_wx_account t2 on t1.wx_account_id = t2.id
+        left join company_wx_client t3 on t3.id = t1.wx_client_id
+        left join company t4 on t4.company_id = t2.company_id
+        left join company_user t5 on t5.user_id = t2.company_user_id
+        where 1=1
+        <if test="roboticId != null "> and t1.robotic_id = #{roboticId}</if>
+        <if test="wxClientId != null "> and t1.wx_client_id = #{wxClientId}</if>
+    </select>
+
+    <select id="listByCustomerId" resultType="com.fs.company.vo.CompanyVoiceRoboticCallLogAddwxVO">
+        select
+            t1.*,
+            t2.wx_nick_name as wxAccountName,
+            t3.nick_name as wxClientName,
+            t4.company_name as companyName,
+            t5.nick_name as companyUserName
+        from company_voice_robotic_call_log_addwx t1
+                 left join company_wx_account t2 on t1.wx_account_id = t2.id
+                 left join company_wx_client t3 on t3.id = t1.wx_client_id
+                 left join company t4 on t4.company_id = t2.company_id
+                 left join company_user t5 on t5.user_id = t2.company_user_id
+        where 1=1
+        <if test="wxclientIds != null ">
+            and t1.wx_client_id in
+            <foreach  item='item' index='index' collection='wxclientIds' open='(' separator=',' close=')'>
+                #{item}
+            </foreach>
+        </if>
+    </select>
 </mapper>

+ 21 - 0
fs-service/src/main/resources/mapper/company/CompanyVoiceRoboticCallLogCallphoneMapper.xml

@@ -149,4 +149,25 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     <select id="selectLogByRoboticIdAndCallerId"   resultType="CompanyVoiceRoboticCallLogCallphone">
         select * from company_voice_robotic_call_log_callphone where robotic_id = #{roboticId} And caller_id = #{callerId}
     </select>
+
+    <select id="selectCompanyVoiceRoboticCallLogCallphoneListData" parameterType="com.fs.company.domain.CompanyVoiceRoboticCallLogCallphone"  resultType="CompanyVoiceRoboticCallLogCallphone">
+        select
+        t1.*,
+        t2.company_name as companyName,
+        t3.nick_name as companyUserName
+        from company_voice_robotic_call_log_callphone t1
+        left join company t2 on t1.company_id = t2.company_id
+        left join company_user t3 on t3.user_id = t1.company_user_id
+        <where>
+            <if test="logId != null">and t1.log_id = #{logId}</if>
+            <if test="roboticId != null "> and t1.robotic_id = #{roboticId}</if>
+            <if test="callerId != null "> and t1.caller_id = #{callerId}</if>
+            <if test="callerIds != null">
+                AND t1.caller_id IN
+                <foreach collection='callerIds' item='item' open='(' separator=',' close=')'>
+                    #{item}
+                </foreach>
+            </if>
+        </where>
+    </select>
 </mapper>

+ 22 - 0
fs-service/src/main/resources/mapper/company/CompanyVoiceRoboticCallLogSendmsgMapper.xml

@@ -107,4 +107,26 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             #{logId}
         </foreach>
     </delete>
+
+    <select id="listByCallerIdAndRoboticId" resultType="com.fs.company.vo.CompanyVoiceRoboticCallLogSendmsgVO" parameterType="CompanyVoiceRoboticCallLogSendmsg">
+        SELECT
+            t1.*,
+            t2.company_name,
+            t3.nick_name as companyUserName,
+            t4.title as smsTempName
+        FROM company_voice_robotic_call_log_sendmsg t1
+                 left join company t2 on t1.company_id = t2.company_id
+                 left join company_user t3 on t3.user_id = t1.company_user_id
+                 left join company_sms_temp t4 on t4.temp_id = t1.temp_id
+        where 1=1
+        <if test="roboticId != null">and t1.robotic_id = #{roboticId}</if>
+        <if test="callerId != null">and t1.caller_id = #{callerId}</if>
+        <if test="callerIds != null">
+            AND t1.caller_id IN
+            <foreach collection='callerIds' item='item' open='(' separator=',' close=')'>
+                #{item}
+            </foreach>
+        </if>
+    </select>
+
 </mapper>

+ 83 - 0
fs-service/src/main/resources/mapper/company/CompanyVoiceRoboticCalleesMapper.xml

@@ -115,4 +115,87 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     <select id="getRoboticIsDoneByRoboticIdAndTaskFlow" resultType="java.lang.Integer">
         SELECT count(*) FROM company_voice_robotic_callees where robotic_id = #{roboticId} and (FIND_IN_SET(#{taskFlow},run_task_flow) =0 or FIND_IN_SET(#{taskFlow},run_task_flow) is null)
     </select>
+
+    <select id="getCallerIdsByCustomerId" parameterType="java.lang.Long" resultType="java.lang.Long">
+        select
+            id
+        from
+            company_voice_robotic_callees
+         where user_id = #{customerId}
+    </select>
+    <resultMap id="getSendMsgTaskListByRoboticIdMap" type="com.fs.company.vo.SendMsgByTaskVO">
+        <result column="robotidId" property="robotidId"></result>
+        <result column="calleesId" property="calleesId"></result>
+        <result column="userId" property="userId"></result>
+        <result column="companyId" property="companyId"></result>
+        <result column="companyUserId" property="companyUserId"></result>
+        <result column="wxNickName" property="wxNickName"></result>
+        <association property="companySmsTemp" javaType="com.fs.company.domain.CompanySmsTemp">
+            <id column="tempId" property="tempId"/>
+            <result column="tempId" property="tempId"/>
+            <result column="tempCode" property="tempCode"/>
+            <result column="tempTitle" property="title"/>
+            <result column="tempContent" property="content"/>
+            <result column="tempType" property="tempType"/>
+            <result column="tempStatus" property="status"/>
+            <result column="tempCateId" property="cateId"/>
+            <result column="tempIsAudit" property="isAudit"/>
+            <result column="tempCreateTime" property="createTime"/>
+            <result column="tempUpdateTime" property="updateTime"/>
+        </association>
+    </resultMap>
+
+    <select id="getSendMsgTaskListByRoboticId" resultType="com.fs.company.vo.SendMsgByTaskVO" parameterType="java.lang.Long">
+        SELECT
+            t1.id as roboticId,
+            t2.id as calleesId,
+            t2.user_id as userId,
+            t5.company_id as companyId,
+            t5.company_user_id as companyUserId,
+            t5.wx_nick_name as wxNickName,
+            t6.temp_id as tempId,
+            t6.company_id as tempCompanyId,
+            t6.title as tempTitle,
+            t6.content as tempContent,
+            t6.temp_code as tempCode,
+            t6.temp_type as tempType,
+            t6.create_time as tempCreateTime,
+            t6.update_time as tempUpdateTime,
+            t6.status as tempStatus,
+            t6.cate_id as tempCateId,
+            t6.is_audit as tempIsAudit
+        FROM company_voice_robotic t1
+                 left join company_voice_robotic_callees t2 on t1.id = t2.robotic_id
+                 left join company_wx_client t3 on t3.robotic_id = t2.robotic_id and t3.customer_id = t2.user_id
+                 left join company_voice_robotic_wx t4 on t3.robotic_wx_id = t4.id
+                 left join company_wx_account t5 on t5.id = t4.account_id
+                 left join company_sms_temp t6 on t6.temp_id = t4.sms_temp_id
+        where t1.id = #{roboticId}
+    </select>
+
+    <select id="selectExcludeList" resultType="com.fs.company.domain.CompanyVoiceRoboticCallees" >
+        SELECT * FROM  company_voice_robotic_callees where 1=1
+        <if test="list != null">
+            and
+            <foreach item="item" collection="list" separator=" or " open="(" close=")">
+                ( user_id = #{item.customerId} and robotic_id = #{item.roboticId} )
+            </foreach>
+        </if>
+    </select>
+
+    <select id="getNotFinishAddWxRobotic"  resultType="java.lang.Long" >
+        select
+            robotic_id
+        from company_voice_robotic_callees
+        where 1=1
+          and (FIND_IN_SET('addWx', run_task_flow) = 0
+          or FIND_IN_SET('addWx', run_task_flow) is null)
+        <if test="roboticIds != null">
+            and robotic_id in
+            <foreach item="item" collection="roboticIds" separator="," open="(" close=")">
+                #{item}
+            </foreach>
+        </if>
+
+    </select>
 </mapper>

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

@@ -187,5 +187,18 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     <update id="finishRobotic" parameterType="java.lang.Long">
         update company_voice_robotic set task_status = 3 where id = #{id} and task_flow = run_task_flow
     </update>
-    
+
+    <update id="finishAddWxRobotic" >
+        update company_voice_robotic
+        set run_task_flow =  CASE
+                                 WHEN run_task_flow is null or run_task_flow = '' THEN
+                                     'addWx'
+                                 ELSE
+                                     CONCAT(run_task_flow,',','addWx')
+            END
+        where id in
+        <foreach item="id" collection="collect" open="(" separator="," close=")">
+            #{id}
+        </foreach>
+    </update>
 </mapper>

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

@@ -169,6 +169,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     </select>
 
     <select id="selectOneByRoboticIdAndUserId" resultType="com.fs.company.domain.CompanyWxClient">
-        select * from company_wx_client where robotic_id = #{roboticId} and customer_id = #{customerId}
+        select * from company_wx_client
+                 where 1=1
+        <if test="roboticId != null"> and  robotic_id = #{roboticId}  </if>
+        <if test="customerId != null">  and customer_id = #{customerId} </if>
+    </select>
+
+    <select id="getWxClientInfoByCustomerId" resultType="com.fs.company.domain.CompanyWxClient">
+        select * from company_wx_client
+        where 1=1
+        <if test="customerId != null">  and customer_id = #{customerId} </if>
     </select>
 </mapper>

+ 30 - 5
fs-wx-task/src/main/java/com/fs/app/service/WxTaskService.java

@@ -82,6 +82,22 @@ public class WxTaskService {
         WxConfig config = JSONUtil.toBean(json, WxConfig.class);
         // 需要添加微信的列表
         List<CompanyWxClient> list = companyWxClientService.getAddWxList(accountIdList);
+        //排除掉没到达加微步骤的人
+        List<CompanyVoiceRoboticCallees> exList = companyVoiceRoboticCalleesMapper.selectExcludeList(list);
+        List<CompanyVoiceRoboticCallees> collect =
+                exList.stream().filter(e -> !Constants.ADD_WX.equals(getNextTaskOptimized(e.getTaskFlow(), e.getRunTaskFlow())))
+                        .collect(Collectors.toList());
+        Set<String> existingKeys = collect.stream()
+                .map(callee -> callee.getRoboticId() + "_" + callee.getUserId())
+                .collect(Collectors.toSet());
+
+         list = list.stream()
+                .filter(client -> {
+                    String key = client.getRoboticId() + "_" + client.getCustomerId();
+                    return !existingKeys.contains(key);
+                })
+                .collect(Collectors.toList());
+
         log.info("需要添加微信的数量:{}", list.size());
         if(list.isEmpty()) return;
         List<CompanyWxClient> addList = new ArrayList<>();
@@ -107,7 +123,6 @@ public class WxTaskService {
         addAccountList.forEach(e -> {
             CompanyWxClient client = clientMap.get(e.getId());
             if(client != null){
-
                 String task = redisCache.getCacheObject(Constants.TASK_ID + client.getRoboticId());
                 log.info("ROBOTIC-ID:{},CLIENT-ID:{},当前任务执行状态:{}", client.getRoboticId(), client.getId(), task);
                 if(StringUtils.isNotEmpty(task) && Constants.ADD_WX.equals(task)){
@@ -189,7 +204,7 @@ public class WxTaskService {
                     )
             );
             companyVoiceRoboticCalleesServiceImpl.updateBatchById(companyVoiceRoboticCallees);
-
+            companyVoiceRoboticServiceImpl.finishAddWxByCallees(roboticIdSet);
         }
         if(!addAccountList.isEmpty()){
             companyWxAccountService.updateBatchById(addAccountList);
@@ -380,6 +395,16 @@ public class WxTaskService {
 //        return resArr;
 //    }
 
+    /**
+     * 单任务加微
+     * @param roboticId
+     * @param callerId
+     * @return
+     */
+    private  Boolean addWxOne(Long roboticId,Long callerId){
+
+        return Boolean.TRUE;
+    }
     /**
      * 单个任务执行且为单条执行对象
      * @param roboticId
@@ -422,9 +447,9 @@ public class WxTaskService {
                     companyVoiceRoboticService.callPhoneOne(roboticId, callerId);
                     nextTaskOptimized = getNextTaskOptimized(taskFlow, data.getRunTaskFlow() + "," + Constants.CELL_PHONE);
                     break;
-//            case Constants.ADD_WX:
-//                companyVoiceRoboticService.addWxOne();
-//                break;
+                case Constants.ADD_WX:
+                    Boolean success = addWxOne(roboticId, callerId);
+                    break;
                 case Constants.SEND_MSG:
                     if(Integer.valueOf(0).equals(data.getIsSendMsg())){
                         //发送短信前一个任务如果是打电话 等待电话打完以后再执行发送