Kaynağa Gözat

去除教师节活动时可能会产生的重复消息

wujiefeng 9 ay önce
ebeveyn
işleme
3a768561d1

+ 3 - 1
RewardServer/src/main/java/com/zhongshu/reward/server/core/dao/VipUserRecordDao.java

@@ -12,8 +12,10 @@ import java.util.List;
  */
 public interface VipUserRecordDao extends MongoDao<VipUserRecord>, VipUserRecordDaoExtend {
 
-    boolean existsByCpIdAndSucIn(String cpId, List<Integer> suc);
+    boolean existsByCpIdAndSucInAndIdNot(String cpId, List<Integer> suc, String id);
     VipUserRecord findTop1ByCpIdAndSucOrderByOperateTime(String cpId, Integer suc);
 
     VipUserRecord findTop1ByCpIdOrderByOperateTime(String cpId);
+
+    VipUserRecord findTop1ByCpIdAndSucAndPlanningIdOrderByCreateTimeDesc(String cpId, Integer suc, String planningId);
 }

+ 8 - 5
RewardServer/src/main/java/com/zhongshu/reward/server/core/service/InviteReceiptsService.java

@@ -18,6 +18,7 @@ import com.zswl.cloud.bdb.client.service.InviteReceiptsRoleFeignService;
 import com.zswl.cloud.bdb.client.vo.InviteReceiptsRoleVo;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.ObjectUtils;
+import org.apache.commons.lang3.StringUtils;
 import org.bson.types.ObjectId;
 import org.jetbrains.annotations.NotNull;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -76,7 +77,7 @@ public class InviteReceiptsService {
 
         if (vipUserRecord.getSuc().equals(1) || vipUserRecord.getSuc().equals(4)){//订阅
 
-           if (isFirstSuc(ruler, vipUserRecord.getCpId(), vipUserRecord.getOperateTime(), inviteRecord.getRegisterTime())){ //首次订购,且时间小于48小时
+           if (isFirstSuc(ruler, vipUserRecord.getCpId(), vipUserRecord.getOperateTime(), inviteRecord.getRegisterTime(), vipUserRecord.getId())){ //首次订购,且时间小于48小时
 
                sucToReceipts(ruler, vipUserRecord, inviteRecord.getInviteUserId());
                vipUserRecord.setFirst(true);
@@ -128,8 +129,8 @@ public class InviteReceiptsService {
         return ObjectUtils.isNotEmpty(topVipUserRecord) && topVipUserRecord.isFirst();
     }
 
-    private boolean isFirstSuc(InviteReceiptsRoleVo rulerVo, String userId, Long operateTime, Long registerTime){
-        return rulerVo.getFirstPurchaseDay()!=null && !vipUserRecordDao.existsByCpIdAndSucIn(userId, List.of(1)) && Math.abs(operateTime - registerTime) <= 48L*60*60*1000;
+    private boolean isFirstSuc(InviteReceiptsRoleVo rulerVo, String userId, Long operateTime, Long registerTime, String vipUserRecordId){
+        return rulerVo.getFirstPurchaseDay()!=null && !vipUserRecordDao.existsByCpIdAndSucInAndIdNot(userId, List.of(1), vipUserRecordId) && Math.abs(operateTime - registerTime) <= 48L*60*60*1000;
     }
 
     private boolean isSucLastMonth(String userId){
@@ -221,7 +222,9 @@ public class InviteReceiptsService {
         walletReceipts.setOutTradeNo(vipUserRecord.getPlanningId());
         walletReceipts.setTotal(rulerVo.getBaseTotal());
         walletReceipts.setEstimatedTime(DateUtils.nextMonthDayStartTime(rulerVo.getDay()));
-        vipUserRecord.setId(new ObjectId().toHexString());
+        if (StringUtils.isEmpty(vipUserRecord.getId())){
+            vipUserRecord.setId(new ObjectId().toHexString());
+        }
         walletReceipts.setVipUserRecord(vipUserRecord);
         walletReceipts.setRuler(rulerVo);
         //邀请人钱包
@@ -344,7 +347,7 @@ public class InviteReceiptsService {
                         }else if (topOne.getSuc().equals(1) || topOne.getSuc().equals(4)){
                             //上月最后消息为订购,生成入账(若本月已生成持续返利则不自动生成)
                             WalletReceipts noCancelByCreateTime = walletReceiptsDao.findNoCancelByCreateTime(walletReceipts.getUserId(), DateUtils.getCurrentMonthStartTime(), new Date().getTime());
-                            if (ObjectUtils.isEmpty(noCancelByCreateTime)){
+                            if (ObjectUtils.isNotEmpty(noCancelByCreateTime)){
                                 return;
                             }
                             insertReceipts(ruler, walletReceipts);

+ 9 - 0
RewardServer/src/main/java/com/zhongshu/reward/server/core/stream/VipUserStream.java

@@ -8,6 +8,7 @@ import com.zhongshu.reward.server.core.service.WalletReceiptsService;
 import com.zhongshu.reward.server.core.util.DateUtils;
 import com.zhongshu.vip.client.model.param.VipUserParam;
 import lombok.extern.log4j.Log4j2;
+import org.apache.commons.lang3.ObjectUtils;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
@@ -28,10 +29,18 @@ public class VipUserStream extends StreamConsumer<VipUserParam> {
     @Override
     public void accept(VipUserParam vipUserParam) {
         log.info("收到会员套餐消息:{}",vipUserParam);
+
+        VipUserRecord existsRecord = vipUserRecordDao.findTop1ByCpIdAndSucAndPlanningIdOrderByCreateTimeDesc(vipUserParam.getCpId(), vipUserParam.getSuc(), vipUserParam.getPlanningId());
+        if (ObjectUtils.isNotEmpty(existsRecord)){
+            log.info("重复订阅消息");
+            return;
+        }
+
         VipUserRecord vipUserRecord = new VipUserRecord();
         BeanUtils.copyProperties(vipUserParam, vipUserRecord, "createTime");
         vipUserRecord.setOperateTime(DateUtils.timeToLong(vipUserParam.getCreateTime(), DateUtils.FORMAT_LONG));
         vipUserRecord.setFirst(false);
+        vipUserRecordDao.save(vipUserRecord);
         inviteReceiptsService.receipts(vipUserRecord);
     }
 }