YPZ 2 hete
szülő
commit
4d8576a77c

+ 32 - 0
java/storlead-sasa/storlead-trade/src/main/java/com/storlead/trade/service/impl/MarketEmailsServiceImpl.java

@@ -1683,6 +1683,28 @@ public class MarketEmailsServiceImpl extends MyBaseServiceImpl<MarketEmailsMappe
         if (CollectionUtils.isEmpty(marketingCampaignList)){
             return;
         }
+        // ===== 客户级防护:一次性查出「任何营销活动中」存在已回复邮件的客户 / 收件人 =====
+        // 需求:只要某个客户在任意营销活动里有回复过的邮件,就不再给它生成二次发送邮件。
+        // 这里跑一次全量去重查询,后续生成二次发送时按 customerId / recipient 命中即跳过,
+        // 避免对已回复客户继续打扰(即便其所属营销活动未配置「回复后停止」)。
+        Set<Long> repliedCustomerIds = new HashSet<>();
+        Set<String> repliedRecipients = new HashSet<>();
+        {
+            LambdaQueryWrapper<MarketEmailsEntity> replyQuery = new LambdaQueryWrapper<>();
+            replyQuery.select(MarketEmailsEntity::getCustomerId, MarketEmailsEntity::getRecipient)
+                    .eq(MarketEmailsEntity::getIsDelete, CommonConstant.DEL_FLAG_0)
+                    .eq(MarketEmailsEntity::getHasReply, 1);
+            List<MarketEmailsEntity> repliedEmails = this.list(replyQuery);
+            for (MarketEmailsEntity replied : repliedEmails) {
+                if (replied.getCustomerId() != null) {
+                    repliedCustomerIds.add(replied.getCustomerId());
+                }
+                String r = replied.getRecipient();
+                if (r != null && !r.isEmpty()) {
+                    repliedRecipients.add(r);
+                }
+            }
+        }
         for (MarketingCampaignEntity marketingCampaignEntity : marketingCampaignList) {
             if (marketingCampaignEntity.getId().equals(43L)){
                 log.info("测试");
@@ -1727,6 +1749,16 @@ public class MarketEmailsServiceImpl extends MyBaseServiceImpl<MarketEmailsMappe
                         || pendingFirstSendIds.contains(firstId)) {
                     continue;
                 }
+                // 客户级防护:该客户(customerId)或收件人(recipient)在任何营销活动中存在已回复邮件,
+                // 则不生成二次发送。命中即跳过,避免对已回复客户继续打扰。
+                Long cid = marketEmail.getCustomerId();
+                String recipient = marketEmail.getRecipient();
+                if ((cid != null && repliedCustomerIds.contains(cid))
+                        || (recipient != null && !recipient.isEmpty() && repliedRecipients.contains(recipient))) {
+                    log.info("[sendAgain] 客户已在任意营销活动中回复过,跳过二次发送:customerId={}, recipient={}, firstSendId={}",
+                            cid, recipient, firstId);
+                    continue;
+                }
                 MarketEmailsEntity newMarketEmail = new MarketEmailsEntity();
                 BeanUtils.copyProperties(marketEmail, newMarketEmail);
                 // 注意:copyProperties 会把首邮件的 createTime/updateTime 也拷过来(非空),