Explorar el Código

新客对话迁移

三七 hace 2 semanas
padre
commit
f021c65de3

+ 85 - 2
fs-company/src/main/java/com/fs/company/controller/qw/QwExternalContactController.java

@@ -21,6 +21,7 @@ import com.fs.crm.vo.CrmMyCustomerListQueryVO;
 import com.fs.framework.security.LoginUser;
 import com.fs.framework.service.TokenService;
 import com.fs.his.service.IFsUserService;
+import com.fs.qw.domain.QwContactWay;
 import com.fs.qw.domain.QwExternalContact;
 import com.fs.qw.domain.QwTag;
 import com.fs.qw.param.*;
@@ -28,6 +29,7 @@ import com.fs.qw.service.*;
 import com.fs.qw.vo.QwExternalContactVO;
 import com.fs.qw.vo.QwFsUserVO;
 import com.fs.qw.vo.QwUserDelLossLogVO;
+import com.fs.voice.utils.StringUtil;
 import com.github.pagehelper.PageHelper;
 import com.google.gson.Gson;
 import com.google.gson.reflect.TypeToken;
@@ -79,6 +81,9 @@ public class QwExternalContactController extends BaseController
     @Autowired
     private CompanyDeptServiceImpl companyDeptService;
 
+    @Autowired
+    private IQwContactWayService qwContactWayService;
+
     /**
      * 查询企业微信客户列表
      */
@@ -86,8 +91,13 @@ public class QwExternalContactController extends BaseController
     @GetMapping("/list")
     public TableDataInfo list(QwExternalContactParam qwExternalContact)
     {
-        startPage();
         LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
+
+        QwContactWay qwContactWay=new QwContactWay();
+        qwContactWay.setCompanyId(loginUser.getCompany().getCompanyId());
+        List<QwContactWay> wayList = qwContactWayService.selectQwContactWayList(qwContactWay);
+
+        startPage();
         qwExternalContact.setCompanyId(loginUser.getCompany().getCompanyId());
         List<QwExternalContactVO> list = qwExternalContactService.selectQwExternalContactListVO(qwExternalContact);
         list.forEach(item->{
@@ -105,11 +115,47 @@ public class QwExternalContactController extends BaseController
 
                 item.setTagIdsName(iQwTagService.selectQwTagListByTagIds(param));
             }
+
+            if (!StringUtil.strIsNullOrEmpty(item.getState()) && !wayList.isEmpty()) {
+                item.setState(item.getState()+"-"+getContactWayNameStream(item.getState(), wayList));
+            }
+
         });
 
         return getDataTable(list);
     }
 
+
+    public String getContactWayNameStream(String configStr, List<QwContactWay> wayList) {
+        if (configStr == null || wayList == null || wayList.isEmpty()) {
+            return null;
+        }
+
+        return wayList.stream()
+                .filter(way -> way.getId() != null &&
+                        way.getId().toString().equals(extractLastValue(configStr)))
+                .map(QwContactWay::getName)
+                .findFirst()
+                .orElse(null);
+    }
+
+    /**
+     * 提取最后一个冒号后的值
+     */
+    private String extractLastValue(String input) {
+        if (input == null || input.isEmpty()) {
+            return null;
+        }
+
+        int lastColonIndex = input.lastIndexOf(":");
+        if (lastColonIndex == -1) {
+            return input;
+        }
+
+        return input.substring(lastColonIndex + 1);
+    }
+
+
     @GetMapping("/test")
     public AjaxResult test()
     {
@@ -154,6 +200,10 @@ public class QwExternalContactController extends BaseController
         qwExternalContact.setUserType(loginUser.getUser().getUserType());
         qwExternalContact.setCompanyId(loginUser.getCompany().getCompanyId());
 
+        QwContactWay qwContactWay=new QwContactWay();
+        qwContactWay.setCompanyId(loginUser.getCompany().getCompanyId());
+        List<QwContactWay> wayList = qwContactWayService.selectQwContactWayList(qwContactWay);
+
         startPage();
         List<QwExternalContactVO> list = qwExternalContactService.selectQwExternalContactListVO(qwExternalContact);
         list.forEach(item->{
@@ -171,6 +221,11 @@ public class QwExternalContactController extends BaseController
 
                 item.setTagIdsName(iQwTagService.selectQwTagListByTagIds(param));
             }
+
+            if (!StringUtil.strIsNullOrEmpty(item.getState()) && !wayList.isEmpty()) {
+                item.setState(item.getState()+"-"+getContactWayNameStream(item.getState(), wayList));
+            }
+
         });
 
         return getDataTable(list);
@@ -183,8 +238,14 @@ public class QwExternalContactController extends BaseController
         if(qwExternalContact.getQwUserId()==null){
             return null;
         }
-        startPage();
         LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
+
+        QwContactWay qwContactWay=new QwContactWay();
+        qwContactWay.setCompanyId(loginUser.getCompany().getCompanyId());
+        List<QwContactWay> wayList = qwContactWayService.selectQwContactWayList(qwContactWay);
+
+
+        startPage();
         qwExternalContact.setCompanyId(loginUser.getCompany().getCompanyId());
         List<QwExternalContactVO> list = qwExternalContactService.selectQwExternalContactListVO(qwExternalContact);
         list.forEach(item->{
@@ -202,6 +263,10 @@ public class QwExternalContactController extends BaseController
 
                 item.setTagIdsName(iQwTagService.selectQwTagListByTagIds(param));
             }
+
+            if (!StringUtil.strIsNullOrEmpty(item.getState()) && !wayList.isEmpty()) {
+                item.setState(item.getState()+"-"+getContactWayNameStream(item.getState(), wayList));
+            }
         });
 
         return getDataTable(list);
@@ -232,7 +297,13 @@ public class QwExternalContactController extends BaseController
         if (qwExternalContact.getCorpId()==null){
             return AjaxResult.success();
         }
+
         LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
+
+        QwContactWay qwContactWay=new QwContactWay();
+        qwContactWay.setCompanyId(loginUser.getCompany().getCompanyId());
+        List<QwContactWay> wayList = qwContactWayService.selectQwContactWayList(qwContactWay);
+
         qwExternalContact.setCompanyId(loginUser.getCompany().getCompanyId());
         List<QwExternalContactVO> list = qwExternalContactService.selectQwExternalContactListVO(qwExternalContact);
         list.forEach(item->{
@@ -250,6 +321,10 @@ public class QwExternalContactController extends BaseController
 
                 item.setTagIdsName(iQwTagService.selectQwTagListByTagIds(param));
             }
+
+            if (!StringUtil.strIsNullOrEmpty(item.getState()) && !wayList.isEmpty()) {
+                item.setState(item.getState()+"-"+getContactWayNameStream(item.getState(), wayList));
+            }
         });
         ExcelUtil<QwExternalContactVO> util = new ExcelUtil<QwExternalContactVO>(QwExternalContactVO.class);
         return util.exportExcel(list, "企业微信客户数据");
@@ -266,6 +341,10 @@ public class QwExternalContactController extends BaseController
         }
         LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
         qwExternalContact.setCompanyId(loginUser.getCompany().getCompanyId());
+        QwContactWay qwContactWay=new QwContactWay();
+        qwContactWay.setCompanyId(loginUser.getCompany().getCompanyId());
+        List<QwContactWay> wayList = qwContactWayService.selectQwContactWayList(qwContactWay);
+
 
         List<QwExternalContactVO> list = qwExternalContactService.selectQwExternalContactListVO(qwExternalContact);
 
@@ -284,6 +363,10 @@ public class QwExternalContactController extends BaseController
 
                 item.setTagIdsName(iQwTagService.selectQwTagListByTagIds(param));
             }
+
+            if (!StringUtil.strIsNullOrEmpty(item.getState()) && !wayList.isEmpty()) {
+                item.setState(item.getState()+"-"+getContactWayNameStream(item.getState(), wayList));
+            }
         });
 
         ExcelUtil<QwExternalContactVO> util = new ExcelUtil<QwExternalContactVO>(QwExternalContactVO.class);

+ 23 - 0
fs-service/src/main/java/com/fs/qw/service/AsyncQwAiChatSopService.java

@@ -12,7 +12,9 @@ import com.fs.course.mapper.FsCourseWatchLogMapper;
 import com.fs.fastGpt.domain.FastGptChatReplaceWords;
 import com.fs.fastGpt.mapper.FastGptChatReplaceWordsMapper;
 import com.fs.qw.domain.QwCompany;
+import com.fs.qw.domain.QwExternalContactInfo;
 import com.fs.qw.domain.QwUser;
+import com.fs.qw.mapper.QwExternalContactInfoMapper;
 import com.fs.qw.vo.QwSopRuleTimeVO;
 import com.fs.qw.vo.QwSopTempSetting;
 import com.fs.sop.domain.QwSopLogs;
@@ -82,6 +84,9 @@ public class AsyncQwAiChatSopService {
     @Autowired
     private IQwSopTempVoiceService sopTempVoiceService;
 
+    @Autowired
+    private QwExternalContactInfoMapper qwExternalContactInfoMapper;
+
     @Async("threadPoolTaskExecutor")
     public void executeQwAiChatSop(QwSopAutoByTags qwSopAutoByTags, String userID,
                                    QwUser qwUser, String externalUserID, String externalContactName,
@@ -320,4 +325,22 @@ public class AsyncQwAiChatSopService {
         }
     }
 
+    /**
+     * 在职转接 -AI用户信息 一起转
+     */
+    @Async("threadPoolTaskExecutor")
+    public void executeQwSopJobTransfer(Long externalContactId, Long externalId){
+        try {
+            QwExternalContactInfo contactInfo = qwExternalContactInfoMapper.selectQwExternalContactInfoByExternalContactId(externalContactId);
+            if (contactInfo != null) {
+                contactInfo.setExternalContactId(externalId);
+                qwExternalContactInfoMapper.insertQwExternalContactInfo(contactInfo);
+            }
+        }catch (Exception e){
+            log.error("在职转接-转接客户AI信息失败:{},{}",externalContactId,externalId,e);
+        }
+
+    }
+
+
 }

+ 80 - 0
fs-service/src/main/java/com/fs/qw/service/impl/QwExternalContactServiceImpl.java

@@ -202,6 +202,9 @@ public class QwExternalContactServiceImpl extends ServiceImpl<QwExternalContactM
     @Autowired
     private ISysDictTypeService dictTypeService;
 
+    @Autowired
+    private AsyncQwAiChatSopService asyncQwAiChatSopService;
+
 
     Logger logger = LoggerFactory.getLogger(getClass());
 
@@ -2183,6 +2186,14 @@ public class QwExternalContactServiceImpl extends ServiceImpl<QwExternalContactM
     @Override
     public void insertQwExternalContactByExternalUserId(String externalUserID, String userID, Long companyId, String corpId, String state, String welcomeCode) throws ParseException {
 
+
+        String qwApiExternal=redisCache.getCacheObject("qwApiExternal:"+userID+":"+corpId+":"+externalUserID);
+        if (!StringUtil.strIsNullOrEmpty(qwApiExternal)){
+            return;
+        }else {
+            redisCache.setCacheObject("qwApiExternal:"+userID+":"+corpId+":"+externalUserID ,"1",10, TimeUnit.MINUTES);
+        }
+
         // 获取当前日期(只包含年月日)
         LocalDate currentDate = LocalDate.now();
         // 获取当前系统时间 (HH:mm)
@@ -2767,6 +2778,13 @@ public class QwExternalContactServiceImpl extends ServiceImpl<QwExternalContactM
                     //SOP规则
                     qwSopRuleTimeTools(qwSopRuleTimeVOS,userID,qwUser,corpId,externalUserID,externalContact.getName(),contact,currentDate,localTime,combinedTagsList);
                 }
+
+                //新客对话任务
+                Boolean sopAiChatByRedis = getSopAiChatByRedis(userID, corpId, externalUserID);
+                if (!sopAiChatByRedis){
+                    asyncQwAiChatSopService.executeQwAiChatSop(qwSopAutoByTags,userID,qwUser,externalUserID
+                            ,externalContact.getName(),contact.getId(),contact.getFsUserId(),currentDate,localTime);
+                }
                 //aiSop任务
 //                List<QwSopRuleTimeVO> qwSopAiRuleTimeVOS = qwSopMapper.selectQwAiSopAutoByTagsByForeach(qwSopAutoByTags);
 //                if (qwSopAiRuleTimeVOS != null && !qwSopAiRuleTimeVOS.isEmpty()){
@@ -3216,6 +3234,12 @@ public class QwExternalContactServiceImpl extends ServiceImpl<QwExternalContactM
                     //SOP规则
                     qwSopRuleTimeTools(qwSopRuleTimeVOS,contact.getUserId(),qwUser,contact.getCorpId(),contact.getExternalUserId(),contact.getName(),contact,currentDate,localTime,combinedTagsList);
                 }
+
+                Boolean sopAiChatByRedis = getSopAiChatByRedis(qwUser.getQwUserId(), qwUser.getCorpId(), contact.getExternalUserId());
+                if (!sopAiChatByRedis){
+                    asyncQwAiChatSopService.executeQwAiChatSop(qwSopAutoByTags,qwUser.getQwUserId(),qwUser, contact.getExternalUserId()
+                            ,contact.getName(),contact.getId(),contact.getFsUserId(),currentDate,localTime);
+                }
 //                //aiSop任务
 //                List<QwSopRuleTimeVO> qwSopAiRuleTimeVOS = qwSopMapper.selectQwAiSopAutoByTagsByForeach(qwSopAutoByTags);
 //                if (qwSopAiRuleTimeVOS != null && !qwSopAiRuleTimeVOS.isEmpty()){
@@ -3398,6 +3422,15 @@ public class QwExternalContactServiceImpl extends ServiceImpl<QwExternalContactM
 
                         }
 
+                        try {
+
+                            asyncQwAiChatSopService.executeQwSopJobTransfer(transferLogVO.getExternalContactId(), logsInfoNew.getExternalId());
+
+                        }catch (Exception e){
+                            logger.error("在职转接-转接客户AI信息失败:{},{}",transferLogVO.getExternalContactId(),logsInfoNew.getExternalId(),e);
+                        }
+
+
                         //删除原员工对此客户的营期信息
                         sopUserLogsInfoMapper.deleteById(logsInfoOld.getId());
 
@@ -4976,6 +5009,14 @@ public class QwExternalContactServiceImpl extends ServiceImpl<QwExternalContactM
                                                 //SOP规则
                                                 qwSopRuleTimeTools(qwSopRuleTimeVOS, qwUserId, qwUser, corpId, ext, externalContact.getName(), contact, currentDate, localTime, combinedTagsList);
                                             }
+
+                                            //aiSop任务
+                                            Boolean sopAiChatByRedis = getSopAiChatByRedis(userID, corpId, externalUserID);
+                                            if (!sopAiChatByRedis){
+                                                asyncQwAiChatSopService.executeQwAiChatSop(qwSopAutoByTags,userID,qwUser,externalUserID
+                                                        ,externalContact.getName(),contact.getId(),contact.getFsUserId(),currentDate,localTime);
+                                            }
+
                                             //aiSop任务
 //                                            List<QwSopRuleTimeVO> qwSopAiRuleTimeVOS = qwSopMapper.selectQwAiSopAutoByTagsByForeach(qwSopAutoByTags);
 //                                            if (qwSopAiRuleTimeVOS != null && !qwSopAiRuleTimeVOS.isEmpty()) {
@@ -5014,6 +5055,14 @@ public class QwExternalContactServiceImpl extends ServiceImpl<QwExternalContactM
                                                 //SOP规则
                                                 qwSopRuleTimeTools(qwSopRuleTimeVOS, userID, qwUser, corpId, externalUserID, externalContact.getName(), contact, currentDate, localTime, combinedTagsList);
                                             }
+
+                                            //aiSop任务
+                                            Boolean sopAiChatByRedis = getSopAiChatByRedis(userID, corpId, externalUserID);
+                                            if (!sopAiChatByRedis){
+                                                asyncQwAiChatSopService.executeQwAiChatSop(qwSopAutoByTags,userID,qwUser,externalUserID
+                                                        ,externalContact.getName(),contact.getId(),contact.getFsUserId(),currentDate,localTime);
+                                            }
+
 //                                            //aiSop任务
 //                                            logger.info("/n 传参:" + qwSopAutoByTags);
 //                                            List<QwSopRuleTimeVO> qwSopAiRuleTimeVOS = qwSopMapper.selectQwAiSopAutoByTagsByForeach(qwSopAutoByTags);
@@ -5048,6 +5097,14 @@ public class QwExternalContactServiceImpl extends ServiceImpl<QwExternalContactM
                                                 //SOP规则
                                                 qwSopRuleTimeTools(qwSopRuleTimeVOS, userID, qwUser, corpId, externalUserID, externalContact.getName(), contact, currentDate, localTime, combinedTagsList);
                                             }
+
+                                            //新客对话任务
+                                            Boolean sopAiChatByRedis = getSopAiChatByRedis(userID, corpId, externalUserID);
+                                            if (!sopAiChatByRedis){
+                                                asyncQwAiChatSopService.executeQwAiChatSop(qwSopAutoByTags,userID,qwUser,externalUserID
+                                                        ,externalContact.getName(),contact.getId(),contact.getFsUserId(),currentDate,localTime);
+                                            }
+
 //                                            //aiSop任务
 //                                            List<QwSopRuleTimeVO> qwSopAiRuleTimeVOS = qwSopMapper.selectQwAiSopAutoByTagsByForeach(qwSopAutoByTags);
 //                                            if (qwSopAiRuleTimeVOS != null && !qwSopAiRuleTimeVOS.isEmpty()) {
@@ -5264,6 +5321,14 @@ public class QwExternalContactServiceImpl extends ServiceImpl<QwExternalContactM
                                                         //SOP规则
                                                         qwSopRuleTimeTools(qwSopRuleTimeVOS, qwUserId, qwUser, corpId, ext, externalContact.getName(), contact, currentDate, localTime, combinedTagsList);
                                                     }
+
+                                                    //aiSop任务
+                                                    Boolean sopAiChatByRedis = getSopAiChatByRedis(userID, corpId, externalUserID);
+                                                    if (!sopAiChatByRedis){
+                                                        asyncQwAiChatSopService.executeQwAiChatSop(qwSopAutoByTags,userID,qwUser,externalUserID
+                                                                ,externalContact.getName(),contact.getId(),contact.getFsUserId(),currentDate,localTime);
+                                                    }
+
                                                     //aiSop任务
 //                                                    List<QwSopRuleTimeVO> qwSopAiRuleTimeVOS = qwSopMapper.selectQwAiSopAutoByTagsByForeach(qwSopAutoByTags);
 //                                                    if (qwSopAiRuleTimeVOS != null && !qwSopAiRuleTimeVOS.isEmpty()) {
@@ -5295,6 +5360,13 @@ public class QwExternalContactServiceImpl extends ServiceImpl<QwExternalContactM
                                                         //SOP规则
                                                         qwSopRuleTimeTools(qwSopRuleTimeVOS, userID, qwUser, corpId, externalUserID, externalContact.getName(), contact, currentDate, localTime, combinedTagsList);
                                                     }
+
+                                                    //aiSop任务
+                                                    Boolean sopAiChatByRedis = getSopAiChatByRedis(userID, corpId, externalUserID);
+                                                    if (!sopAiChatByRedis){
+                                                        asyncQwAiChatSopService.executeQwAiChatSop(qwSopAutoByTags,userID,qwUser,externalUserID
+                                                                ,externalContact.getName(),contact.getId(),contact.getFsUserId(),currentDate,localTime);
+                                                    }
                                                     //aiSop任务
 //                                                    List<QwSopRuleTimeVO> qwSopAiRuleTimeVOS = qwSopMapper.selectQwAiSopAutoByTagsByForeach(qwSopAutoByTags);
 //                                                    if (qwSopAiRuleTimeVOS != null && !qwSopAiRuleTimeVOS.isEmpty()) {
@@ -5322,6 +5394,14 @@ public class QwExternalContactServiceImpl extends ServiceImpl<QwExternalContactM
                                                         //SOP规则
                                                         qwSopRuleTimeTools(qwSopRuleTimeVOS, userID, qwUser, corpId, externalUserID, externalContact.getName(), contact, currentDate, localTime, combinedTagsList);
                                                     }
+
+                                                    //aiSop任务
+                                                    Boolean sopAiChatByRedis = getSopAiChatByRedis(userID, corpId, externalUserID);
+                                                    if (!sopAiChatByRedis){
+                                                        asyncQwAiChatSopService.executeQwAiChatSop(qwSopAutoByTags,userID,qwUser,externalUserID
+                                                                ,externalContact.getName(),contact.getId(),contact.getFsUserId(),currentDate,localTime);
+                                                    }
+
                                                     //aiSop任务
 //                                                    List<QwSopRuleTimeVO> qwSopAiRuleTimeVOS = qwSopMapper.selectQwAiSopAutoByTagsByForeach(qwSopAutoByTags);
 //                                                    if (qwSopAiRuleTimeVOS != null && !qwSopAiRuleTimeVOS.isEmpty()) {

+ 2 - 0
fs-service/src/main/java/com/fs/qw/vo/QwExternalContactVO.java

@@ -108,7 +108,9 @@ public class QwExternalContactVO {
     private Date registerTime;
     private Integer transferNum;
 
+    @Excel(name = "活码")
     private String state;
+
     private Long wayId;
     private String stageStatus;
     private String customerName;