|
|
@@ -36,6 +36,7 @@ import java.util.Date;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
+import java.util.Set;
|
|
|
import java.util.function.Consumer;
|
|
|
import java.util.stream.Collectors;
|
|
|
import java.math.BigDecimal;
|
|
|
@@ -582,15 +583,35 @@ public class MarketingCampaignServiceImpl
|
|
|
if (entity == null || CommonConstant.DEL_FLAG_1.equals(entity.getIsDelete())) {
|
|
|
return Result.error("营销活动不存在");
|
|
|
}
|
|
|
- //如果要开启营销活动,需要先生成邮件模板(即存在待发送的邮件)
|
|
|
+ //如果要开启营销活动,需要先生成全部邮件模板
|
|
|
if (status == STATUS_RUNNING) {
|
|
|
- LambdaQueryWrapper<MarketEmailsEntity> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
- queryWrapper.eq(MarketEmailsEntity::getMarketingCampaignId, id);
|
|
|
- queryWrapper.eq(MarketEmailsEntity::getIsDelete, CommonConstant.DEL_FLAG_0);
|
|
|
- queryWrapper.eq(MarketEmailsEntity::getStatus, -1);
|
|
|
- Integer emailsCount = marketEmailsService.count(queryWrapper);
|
|
|
- if (emailsCount == null || emailsCount <= 0) {
|
|
|
- return Result.error("请于创建/修改20分钟后,且完成邮件模板配置启动营销!");
|
|
|
+ // 1. 查询该营销活动绑定的 SOP 步骤(marketing_campaign_sop_detail_id 列表)
|
|
|
+ LambdaQueryWrapper<MarketingCampaignSopDetailEntity> sopWrapper = new LambdaQueryWrapper<>();
|
|
|
+ sopWrapper.eq(MarketingCampaignSopDetailEntity::getMarketingId, id);
|
|
|
+ sopWrapper.eq(MarketingCampaignSopDetailEntity::getIsDelete, CommonConstant.DEL_FLAG_0);
|
|
|
+ List<MarketingCampaignSopDetailEntity> sopDetailList = marketingCampaignSopDetailService.list(sopWrapper);
|
|
|
+ if (CollectionUtils.isEmpty(sopDetailList)) {
|
|
|
+ return Result.error("请先配置营销序列(SOP步骤)后再启动营销!");
|
|
|
+ }
|
|
|
+ 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)
|
|
|
+ .eq(MarketEmailsEntity::getStatus, -1)
|
|
|
+ .select(MarketEmailsEntity::getMarketingCampaignSopDetailId)
|
|
|
+ .list();
|
|
|
+ Set<Long> readySopDetailIds = readyEmails.stream()
|
|
|
+ .map(MarketEmailsEntity::getMarketingCampaignSopDetailId)
|
|
|
+ .filter(sopId -> sopId != null)
|
|
|
+ .collect(Collectors.toSet());
|
|
|
+ if (readySopDetailIds.size() < sopDetailIds.size()) {
|
|
|
+ return Result.error("营销活动存在未配置待发送邮件模板的营销序列步骤,请确认后再启动营销!");
|
|
|
}
|
|
|
}
|
|
|
entity.setStatus(status);
|