Browse Source

coding:重复回传设置

zhangqin 6 days ago
parent
commit
cace29523a

+ 3 - 3
fs-service/src/main/java/com/fs/newAdv/dto/res/AdvConfigRes.java

@@ -17,7 +17,7 @@ public class AdvConfigRes implements Serializable {
 
     @Getter
     @Setter
-    static class DuplicateRegistrationSettings {
+    public class DuplicateRegistrationSettings {
         // 报名逻辑 1学员可正常报名.2学员不可重复报名
         private Integer signUpLogic;
         // 处理逻辑的天数
@@ -26,7 +26,7 @@ public class AdvConfigRes implements Serializable {
 
     @Getter
     @Setter
-    static class RegularCustomerSettings {
+    public class RegularCustomerSettings {
         // 全局熟客开关 1开启 2关闭
         private Integer repeatSwitch;
         // 小程序表单/加粉站点判断微信授权熟客 1开启 2关闭
@@ -35,7 +35,7 @@ public class AdvConfigRes implements Serializable {
 
     @Getter
     @Setter
-    static class RepeatPostbackSettings {
+    public static class RepeatPostbackSettings {
         // 重复回传过滤 1开启 2关闭
         private Integer filter;
         // 过滤方式 1按行为过滤,2按手机号过滤

+ 40 - 3
fs-service/src/main/java/com/fs/newAdv/service/impl/LeadServiceImpl.java

@@ -2,10 +2,13 @@ package com.fs.newAdv.service.impl;
 
 import cn.hutool.core.util.ObjectUtil;
 import cn.hutool.core.util.StrUtil;
+import cn.hutool.json.JSONUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.fs.newAdv.constant.AdvConfigConstant;
 import com.fs.newAdv.domain.Lead;
+import com.fs.newAdv.dto.res.AdvConfigRes;
 import com.fs.newAdv.enums.SystemEventTypeEnum;
 import com.fs.newAdv.event.ConversionEventPublisher;
 import com.fs.newAdv.mapper.LeadMapper;
@@ -13,6 +16,7 @@ import com.fs.newAdv.service.ILeadService;
 import com.fs.qw.domain.QwExternalContact;
 import com.fs.qw.mapper.QwExternalContactMapper;
 import com.fs.qw.service.IQwExternalContactService;
+import com.fs.system.service.ISysConfigService;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.scheduling.annotation.Async;
@@ -40,6 +44,10 @@ public class LeadServiceImpl extends ServiceImpl<LeadMapper, Lead> implements IL
     @Autowired
     private QwExternalContactMapper qwExternalContactMapper;
 
+
+    @Autowired
+    private ISysConfigService sysConfigService;
+
     @Override
     public Lead getByTraceId(String traceId) {
         List<Lead> list = this.list(new LambdaQueryWrapper<Lead>()
@@ -80,7 +88,9 @@ public class LeadServiceImpl extends ServiceImpl<LeadMapper, Lead> implements IL
         } else if (StrUtil.isNotEmpty(name)) {
             last.eq(Lead::getWeiChatName, name);
         }
-        last.eq(Lead::getAddContactQw, 0).last("LIMIT 1");
+        last.eq(Lead::getAddContactQw, 0);
+        last.eq(Lead::getStatus, 0);
+        last.orderByDesc(Lead::getCreateTime).last("LIMIT 1");
         // 末次归因逻辑
         Lead lead = this.getOne(last);
         if (lead != null) {
@@ -88,15 +98,34 @@ public class LeadServiceImpl extends ServiceImpl<LeadMapper, Lead> implements IL
             lead.setAddContactQw(1);
             lead.setCorpId(corpId);
             this.updateById(lead);
-            if (ObjectUtil.isNotEmpty(lead.getLandingPageTs()) && lead.getLandingPageTs().toLocalDate().isEqual(LocalDate.now())) {
+
+            // 判断去重逻辑是否开启
+            if (this.isStatusByPhone(lead.getPhone())) {
+                log.info("用户加群线索信息已转化:{} {}", lead.getTraceId(), lead.getPhone());
+                return;
+            }
+
+            // 判断是否当日加群
+            if (ObjectUtil.isNotEmpty(lead.getLandingPageTs())
+                    && lead.getLandingPageTs().toLocalDate().isEqual(LocalDate.now())
+            ) {
                 // 当日加群事件回调
                 conversionEventPublisher.publishConversionEvent(lead.getTraceId(), SystemEventTypeEnum.GROUP_TODAY);
             }
         } else {
             log.info("用户加群线索信息不存在:{}", name);
         }
+    }
 
-
+    private Boolean isStatusByPhone(String phone) {
+        AdvConfigRes bean = JSONUtil.toBean(sysConfigService.selectConfigByKey(AdvConfigConstant.ADV_CONFIG), AdvConfigRes.class);
+        if (bean.getRepeatPostbackSettings().getFilter().equals(1) && bean.getRepeatPostbackSettings().getMethod().equals(2)) {
+            return !this.list(new LambdaQueryWrapper<Lead>()
+                    .eq(Lead::getPhone, phone)
+                    .eq(Lead::getStatus, 1)).isEmpty();
+        } else {
+            return false;
+        }
     }
 
     @Override
@@ -146,6 +175,7 @@ public class LeadServiceImpl extends ServiceImpl<LeadMapper, Lead> implements IL
         } else if (StrUtil.isNotEmpty(qwExternalContact.getName())) {
             last.eq(Lead::getWeiChatName, qwExternalContact.getName());
         }
+        last.eq(Lead::getStatus, 0);
         last.eq(Lead::getAddContactQwGroup, 0).last("LIMIT 1");
         // 末次归因逻辑
         Lead lead = this.getOne(last);
@@ -158,6 +188,13 @@ public class LeadServiceImpl extends ServiceImpl<LeadMapper, Lead> implements IL
             temp.setId(qwExternalContact.getId());
             temp.setTraceId(lead.getTraceId());
             qwExternalContactMapper.updateById(temp);
+
+            // 判断去重逻辑是否开启
+            if (this.isStatusByPhone(lead.getPhone())) {
+                log.info("用户加微线索信息已转化:{} {}", lead.getTraceId(), lead.getPhone());
+                return;
+            }
+
             if (ObjectUtil.isNotEmpty(lead.getLandingPageTs()) && lead.getLandingPageTs().toLocalDate().isEqual(LocalDate.now())) {
                 // 当日加微事件回调
                 conversionEventPublisher.publishConversionEvent(lead.getTraceId(), SystemEventTypeEnum.WEI_CHAT_TODAY);