|
|
@@ -258,29 +258,37 @@ public class MarketingCampaignServiceImpl
|
|
|
wrapper.eq(MarketingCampaignSopDetailEntity::getIsDelete, CommonConstant.DEL_FLAG_0);
|
|
|
List<MarketingCampaignSopDetailEntity> relationList = marketingCampaignSopDetailService.list(wrapper);
|
|
|
|
|
|
- // 2.0 计算每个 SOP 步骤是否已执行:开始日期 + 间隔天数 <= 今天 → 已执行
|
|
|
- LocalDate todayForSop = LocalDate.now(ZoneId.of("Asia/Shanghai"));
|
|
|
- LocalDate beginData = campaign.getBeginData();
|
|
|
- if (beginData != null && !CollectionUtils.isEmpty(relationList)) {
|
|
|
+ // 2.0 计算每个 SOP 步骤的执行状态(未开始/进行中/已完成),依据该阶段关联邮件的发送状态:
|
|
|
+ // 未发送任何邮件(或没有邮件)→ 未开始(0);有邮件已发送但未全部发送 → 进行中(1);全部已发送 → 已完成(2)
|
|
|
+ Map<Long, List<MarketEmailsEntity>> emailsBySopDetail = new HashMap<>();
|
|
|
+ List<MarketEmailsEntity> campaignEmails = marketEmailsService.lambdaQuery()
|
|
|
+ .eq(MarketEmailsEntity::getMarketingCampaignId, id)
|
|
|
+ .eq(MarketEmailsEntity::getIsDelete, CommonConstant.DEL_FLAG_0)
|
|
|
+ .list();
|
|
|
+ for (MarketEmailsEntity email : campaignEmails) {
|
|
|
+ if (email.getMarketingCampaignSopDetailId() != null) {
|
|
|
+ emailsBySopDetail.computeIfAbsent(email.getMarketingCampaignSopDetailId(), k -> new ArrayList<>()).add(email);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!CollectionUtils.isEmpty(relationList)) {
|
|
|
for (MarketingCampaignSopDetailEntity sop : relationList) {
|
|
|
- String daysStr = sop.getDays();
|
|
|
- if (daysStr != null && !daysStr.trim().isEmpty()) {
|
|
|
- try {
|
|
|
- int days = Integer.parseInt(daysStr.trim());
|
|
|
- LocalDate executeDate = beginData.plusDays(days);
|
|
|
- sop.setExecuted(!todayForSop.isBefore(executeDate));
|
|
|
- } catch (NumberFormatException e) {
|
|
|
- sop.setExecuted(false);
|
|
|
- }
|
|
|
+ List<MarketEmailsEntity> stageEmails = emailsBySopDetail.get(sop.getId());
|
|
|
+ if (stageEmails == null) {
|
|
|
+ stageEmails = new ArrayList<>();
|
|
|
+ }
|
|
|
+ int total = stageEmails.size();
|
|
|
+ long sentCount = stageEmails.stream()
|
|
|
+ .filter(e -> Integer.valueOf(1).equals(e.getStatus()))
|
|
|
+ .count();
|
|
|
+ int sopStatus;
|
|
|
+ if (sentCount == 0) {
|
|
|
+ sopStatus = 0; // 未开始
|
|
|
+ } else if (sentCount < total) {
|
|
|
+ sopStatus = 1; // 进行中
|
|
|
} else {
|
|
|
- // days 为空:开始当天即执行
|
|
|
- sop.setExecuted(!todayForSop.isBefore(beginData));
|
|
|
+ sopStatus = 2; // 已完成
|
|
|
}
|
|
|
- }
|
|
|
- } else if (!CollectionUtils.isEmpty(relationList)) {
|
|
|
- // beginData 为空,全部标记为未执行
|
|
|
- for (MarketingCampaignSopDetailEntity sop : relationList) {
|
|
|
- sop.setExecuted(false);
|
|
|
+ sop.setSopStatus(sopStatus);
|
|
|
}
|
|
|
}
|
|
|
|