浏览代码

sop 全部标签不生效优化

xgb 1 天之前
父节点
当前提交
47287fedd5

+ 18 - 2
fs-service/src/main/java/com/fs/qw/service/impl/QwExternalContactServiceImpl.java

@@ -69,6 +69,7 @@ import com.fs.sop.params.*;
 import com.fs.sop.service.IQwSopService;
 import com.fs.sop.service.ISopUserLogsInfoService;
 import com.fs.sop.service.ISopUserLogsService;
+import com.fs.sop.util.SopTagMatchUtils;
 import com.fs.system.service.ISysConfigService;
 import com.fs.system.service.ISysDictTypeService;
 import com.fs.voice.utils.StringUtil;
@@ -3420,6 +3421,14 @@ public class QwExternalContactServiceImpl extends ServiceImpl<QwExternalContactM
         // sop任务
         qwSopRuleTimeVOS.forEach(ruleTimeVO -> {
 
+            // 标签规则:SQL 粗筛为 OR,此处按 filterType 精确校验(1含全部 / 2含任意)
+            if (!SopTagMatchUtils.customerMatchSopTags(ruleTimeVO.getFilterType(), ruleTimeVO.getTags(), combinedTagsList)) {
+                logger.info("客户标签不满足SOP规则,移出营期 sopId={}, filterType={}, sopTags={}, customerTags={}",
+                        ruleTimeVO.getId(), ruleTimeVO.getFilterType(), ruleTimeVO.getTags(), combinedTagsList);
+                deleteBySopIdToContactIdTools(ruleTimeVO.getId(), userID, corpId, contact.getId());
+                return;
+            }
+
             // 将排除的字符串转成列表
             List<String> excludedTagsList = new ArrayList<>();
             if (ruleTimeVO.getExcludeTags() != null && !ruleTimeVO.getExcludeTags().isEmpty()) {
@@ -4065,6 +4074,14 @@ public class QwExternalContactServiceImpl extends ServiceImpl<QwExternalContactM
                     //匹配上剩下的标签看看符合不符合
                     qwSopRuleTimeVOS.forEach(ruleTimeVO -> {
 
+                        // 标签规则:SQL 粗筛为 OR,此处按 filterType 精确校验(1含全部 / 2含任意)
+                        if (!SopTagMatchUtils.customerMatchSopTags(ruleTimeVO.getFilterType(), ruleTimeVO.getTags(), cleanedTagList)) {
+                            logger.info("客户标签不满足SOP规则,移出营期 sopId={}, filterType={}, sopTags={}, customerTags={}",
+                                    ruleTimeVO.getId(), ruleTimeVO.getFilterType(), ruleTimeVO.getTags(), cleanedTagList);
+                            deleteBySopIdToContactIdTools(ruleTimeVO.getId(), qwExternalContact.getUserId(), qwExternalContact.getCorpId(), qwExternalContact.getId());
+                            return;
+                        }
+
                         // 将排除的字符串转成列表
                         List<String> excludedTagsList = new ArrayList<>();
                         if (ruleTimeVO.getExcludeTags() != null && !ruleTimeVO.getExcludeTags().isEmpty()) {
@@ -4168,8 +4185,7 @@ public class QwExternalContactServiceImpl extends ServiceImpl<QwExternalContactM
     ;
 
 
-    //固定营期  以 SOP 任务的开始时间为营期
-    private void qwSopRuleTimeToolsCheckByIsFixed(LocalDate sopStartLocalDate, DateTimeFormatter dateFormatter,
+    public void qwSopRuleTimeToolsCheckByIsFixed(LocalDate sopStartLocalDate, DateTimeFormatter dateFormatter,
                                                   SopUserLogs userLogs, SopUserLogsInfo logsInfo,
                                                   SopUserLogsParamByDate userLogsParamByDate) {
 

+ 13 - 0
fs-service/src/main/java/com/fs/qw/service/impl/QwExternalErrRetryServiceImpl.java

@@ -23,8 +23,10 @@ import com.fs.sop.domain.SopUserLogsInfo;
 import com.fs.sop.mapper.QwSopMapper;
 import com.fs.sop.mapper.SopUserLogsInfoMapper;
 import com.fs.sop.params.QwSopAutoByTags;
+import com.fs.sop.params.SopUserLogsInfoDelParam;
 import com.fs.sop.params.SopUserLogsParamByDate;
 import com.fs.sop.service.ISopUserLogsService;
+import com.fs.sop.util.SopTagMatchUtils;
 import com.fs.voice.utils.StringUtil;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -230,6 +232,17 @@ public class QwExternalErrRetryServiceImpl implements IQwExternalErrRetryService
         // sop任务
         qwSopRuleTimeVOS.forEach(ruleTimeVO -> {
 
+            // 标签规则:SQL 粗筛为 OR,此处按 filterType 精确校验(1含全部 / 2含任意)
+            if (!SopTagMatchUtils.customerMatchSopTags(ruleTimeVO.getFilterType(), ruleTimeVO.getTags(), combinedTagsList)) {
+                SopUserLogsInfoDelParam logsInfoDelParam = new SopUserLogsInfoDelParam();
+                logsInfoDelParam.setSopId(ruleTimeVO.getId());
+                logsInfoDelParam.setQwUserId(userID);
+                logsInfoDelParam.setCorpId(corpId);
+                logsInfoDelParam.setExternalId(contact.getId());
+                sopUserLogsInfoMapper.deleteBySopIdToContactId(logsInfoDelParam);
+                return;
+            }
+
             // 将排除的字符串转成列表
             List<String> excludedTagsList=new ArrayList<>();
             if (ruleTimeVO.getExcludeTags() != null && !ruleTimeVO.getExcludeTags().isEmpty()){

+ 28 - 3
fs-service/src/main/java/com/fs/qw/service/impl/QwUserServiceAsyncHelperImpl.java

@@ -28,6 +28,7 @@ import com.fs.sop.mapper.SopUserLogsInfoMapper;
 import com.fs.sop.params.DeleteQwSopParam;
 import com.fs.sop.params.QwSopAutoByTags;
 import com.fs.sop.params.SopUserLogsParamByDate;
+import com.fs.sop.util.SopTagMatchUtils;
 import com.fs.voice.utils.StringUtil;
 import com.fs.watch.mapper.WatchCompanyUserMapper;
 import lombok.extern.slf4j.Slf4j;
@@ -531,6 +532,14 @@ public class QwUserServiceAsyncHelperImpl implements IQwUserServiceAsyncHelper {
                     //匹配上剩下的标签看看符合不符合
                     qwSopRuleTimeVOS.forEach(ruleTimeVO -> {
 
+                        // 标签规则:SQL 粗筛为 OR,此处按 filterType 精确校验(1含全部 / 2含任意)
+                        if (!SopTagMatchUtils.customerMatchSopTags(ruleTimeVO.getFilterType(), ruleTimeVO.getTags(), cleanedTagList)) {
+                            logger.info("客户标签不满足SOP规则,移出营期 sopId={}, filterType={}, sopTags={}, customerTags={}",
+                                    ruleTimeVO.getId(), ruleTimeVO.getFilterType(), ruleTimeVO.getTags(), cleanedTagList);
+                            qwExternalContactService.deleteBySopIdToContactIdTools(ruleTimeVO.getId(), qwExternalContact.getUserId(), qwExternalContact.getCorpId(), qwExternalContact.getId());
+                            return;
+                        }
+
                         // 将排除的字符串转成列表
                         List<String> excludedTagsList = new ArrayList<>();
                         if (ruleTimeVO.getExcludeTags() != null && !ruleTimeVO.getExcludeTags().isEmpty()) {
@@ -589,9 +598,25 @@ public class QwUserServiceAsyncHelperImpl implements IQwUserServiceAsyncHelper {
 
                             logger.warn("sop任务的时间设置Tags:{}|{}|{}|{}", ruleTimeVO.getAutoSopTime(), ruleTimeVO.getId(), ruleTimeVO.getTags(), ruleTimeVO.getExcludeTags());
 
-                            //检查营期(如果开启了新客自动创建sop才检查营期,进入营期)
-                            if (ruleTimeVO.getIsAutoSop() == 1) {
-                                qwExternalContactService.qwSopRuleTimeToolsCheck(sopStartLocalDate, currentDate, dateFormatter, userLogs, logsInfo, userLogsParamByDate, qwAutoSopTimeParam, timeFormatter, localTime);
+                            // 与 QwExternalContactServiceImpl.processTagsAll 保持一致:固定营期 / 自动时段入营
+                            if (Integer.valueOf(1).equals(ruleTimeVO.getIsFixed())) {
+                                qwExternalContactService.qwSopRuleTimeToolsCheckByIsFixed(sopStartLocalDate, dateFormatter, userLogs, logsInfo, userLogsParamByDate);
+                            } else if (Integer.valueOf(1).equals(ruleTimeVO.getIsAutoSop())) {
+                                if (qwAutoSopTimeParam == null) {
+                                    logger.warn("autoSopTime为空,降级按固定营期入营 sopId={}", ruleTimeVO.getId());
+                                    qwExternalContactService.qwSopRuleTimeToolsCheckByIsFixed(sopStartLocalDate, dateFormatter, userLogs, logsInfo, userLogsParamByDate);
+                                } else {
+                                    qwExternalContactService.qwSopRuleTimeToolsCheck(sopStartLocalDate, currentDate, dateFormatter, userLogs, logsInfo, userLogsParamByDate, qwAutoSopTimeParam, timeFormatter, localTime);
+                                }
+                            } else {
+                                // 未开启「新客户自动创建sop」时,打标签原本不入营;
+                                // 但标签已满足规则时仍应能入营(与删标签可移出对称,避免加回标签进不来)
+                                logger.info("SOP未开启自动入营仍按标签规则入营 sopId={}, isAutoSop={}", ruleTimeVO.getId(), ruleTimeVO.getIsAutoSop());
+                                if (qwAutoSopTimeParam == null) {
+                                    qwExternalContactService.qwSopRuleTimeToolsCheckByIsFixed(sopStartLocalDate, dateFormatter, userLogs, logsInfo, userLogsParamByDate);
+                                } else {
+                                    qwExternalContactService.qwSopRuleTimeToolsCheck(sopStartLocalDate, currentDate, dateFormatter, userLogs, logsInfo, userLogsParamByDate, qwAutoSopTimeParam, timeFormatter, localTime);
+                                }
                             }
 
                         }