YPZ 2 日 前
親
コミット
08afb6bdec

+ 33 - 0
java/storlead-sasa/storlead-trade/src/main/java/com/storlead/trade/service/impl/MarketingCampaignServiceImpl.java

@@ -649,6 +649,39 @@ public class MarketingCampaignServiceImpl
                 .le(MarketingCampaignEntity::getBeginData, today)
                 .list();
         if (!CollectionUtils.isEmpty(autoStartList)) {
+            for (MarketingCampaignEntity entity : autoStartList) {
+                //如果要开启营销活动,需要先生成全部邮件模板
+                if (entity.getStatus() == STATUS_RUNNING) {
+                    // 1. 查询该营销活动绑定的 SOP 步骤(marketing_campaign_sop_detail_id 列表)
+                    LambdaQueryWrapper<MarketingCampaignSopDetailEntity> sopWrapper = new LambdaQueryWrapper<>();
+                    sopWrapper.eq(MarketingCampaignSopDetailEntity::getMarketingId, entity.getId());
+                    sopWrapper.eq(MarketingCampaignSopDetailEntity::getIsDelete, CommonConstant.DEL_FLAG_0);
+                    List<MarketingCampaignSopDetailEntity> sopDetailList = marketingCampaignSopDetailService.list(sopWrapper);
+                    if (CollectionUtils.isEmpty(sopDetailList)) {
+                        continue;
+                    }
+                    List<Long> sopDetailIds = sopDetailList.stream()
+                            .map(MarketingCampaignSopDetailEntity::getId)
+                            .filter(sopId -> sopId != null)
+                            .collect(Collectors.toList());
+
+                    // 2. 这些 SOP 步骤在 market_emails 表中,每个步骤至少有一封待发送(-1)的邮件即可。
+                    //    允许部分客户取消/已发送(状态非 -1),只要该步骤还存在待发送邮件就认为模板就绪。
+                    List<MarketEmailsEntity> readyEmails = marketEmailsService.lambdaQuery()
+                            .eq(MarketEmailsEntity::getIsDelete, CommonConstant.DEL_FLAG_0)
+                            .in(MarketEmailsEntity::getMarketingCampaignSopDetailId, sopDetailIds)
+                            .in(MarketEmailsEntity::getStatus, Arrays.asList(-1,-3))
+                            .select(MarketEmailsEntity::getMarketingCampaignSopDetailId)
+                            .list();
+                    Set<Long> readySopDetailIds = readyEmails.stream()
+                            .map(MarketEmailsEntity::getMarketingCampaignSopDetailId)
+                            .filter(sopId -> sopId != null)
+                            .collect(Collectors.toSet());
+                    if (readySopDetailIds.size() < sopDetailIds.size()) {
+                        continue;
+                    }
+                }
+            }
             List<Long> autoStartIdList = autoStartList.stream()
                     .map(MarketingCampaignEntity::getId)
                     .collect(Collectors.toList());