Selaa lähdekoodia

营销活动不可以修改

YPZ 3 viikkoa sitten
vanhempi
sitoutus
f2fe853129

+ 3 - 3
java/storlead-sasa/storlead-trade/src/main/java/com/storlead/trade/dto/MarketingCampaignDTO.java

@@ -132,7 +132,7 @@ public class MarketingCampaignDTO extends Page {
 
     @ApiModelProperty(value = "未打开邮件跟进天数")
     @TableField("follow_up_rules_not_opened_days")
-    private String followUpRulesNotOpenedDays;
+    private Integer followUpRulesNotOpenedDays;
 
     @ApiModelProperty(value = "未回复邮件跟进规则(1是0否)")
     @TableField("follow_up_rules_not_replied")
@@ -140,7 +140,7 @@ public class MarketingCampaignDTO extends Page {
 
     @ApiModelProperty(value = "未回复邮件跟进天数")
     @TableField("follow_up_rules_not_replied_days")
-    private String followUpRulesNotRepliedDays;
+    private Integer followUpRulesNotRepliedDays;
 
     @ApiModelProperty(value = "未点击链接跟进规则(1是0否)")
     @TableField("follow_up_rules_link_not_clicked")
@@ -148,7 +148,7 @@ public class MarketingCampaignDTO extends Page {
 
     @ApiModelProperty(value = "未点击链接跟进天数")
     @TableField("follow_up_rules_link_not_clicked_days")
-    private String followUpRulesLinkNotClickedDays;
+    private Integer followUpRulesLinkNotClickedDays;
 
     @ApiModelProperty(value = "客户回复后自动停止(1是0否)")
     @TableField("follow_up_rules_replied")

+ 3 - 3
java/storlead-sasa/storlead-trade/src/main/java/com/storlead/trade/dto/MarketingCampaignSopDetailDTO.java

@@ -153,7 +153,7 @@ public class MarketingCampaignSopDetailDTO implements Serializable {
 
     @ApiModelProperty(value = "未打开邮件跟进天数")
     @TableField("follow_up_rules_not_opened_days")
-    private String followUpRulesNotOpenedDays;
+    private Integer followUpRulesNotOpenedDays;
 
     @ApiModelProperty(value = "未回复邮件跟进规则(1是0否)")
     @TableField("follow_up_rules_not_replied")
@@ -161,7 +161,7 @@ public class MarketingCampaignSopDetailDTO implements Serializable {
 
     @ApiModelProperty(value = "未回复邮件跟进天数")
     @TableField("follow_up_rules_not_replied_days")
-    private String followUpRulesNotRepliedDays;
+    private Integer followUpRulesNotRepliedDays;
 
     @ApiModelProperty(value = "未点击链接跟进规则(1是0否)")
     @TableField("follow_up_rules_link_not_clicked")
@@ -169,7 +169,7 @@ public class MarketingCampaignSopDetailDTO implements Serializable {
 
     @ApiModelProperty(value = "未点击链接跟进天数")
     @TableField("follow_up_rules_link_not_clicked_days")
-    private String followUpRulesLinkNotClickedDays;
+    private Integer followUpRulesLinkNotClickedDays;
 
     @ApiModelProperty(value = "客户回复后自动停止(1是0否)")
     @TableField("follow_up_rules_replied")

+ 4 - 0
java/storlead-sasa/storlead-trade/src/main/java/com/storlead/trade/entity/MarketEmailsEntity.java

@@ -43,6 +43,10 @@ public class MarketEmailsEntity extends SysBaseField {
     @TableField("has_reader")
     private Integer hasReader;
 
+    @ApiModelProperty(value = "打开次数")
+    @TableField("open_count")
+    private Integer openCount;
+
     @ApiModelProperty("主题")
     @TableField("subject")
     private String subject;

+ 3 - 3
java/storlead-sasa/storlead-trade/src/main/java/com/storlead/trade/entity/MarketingCampaignEntity.java

@@ -128,7 +128,7 @@ public class MarketingCampaignEntity extends SysBaseField {
 
     @ApiModelProperty(value = "未打开邮件跟进天数")
     @TableField("follow_up_rules_not_opened_days")
-    private String followUpRulesNotOpenedDays;
+    private Integer followUpRulesNotOpenedDays;
 
     @ApiModelProperty(value = "未回复邮件跟进规则(1是0否)")
     @TableField("follow_up_rules_not_replied")
@@ -136,7 +136,7 @@ public class MarketingCampaignEntity extends SysBaseField {
 
     @ApiModelProperty(value = "未回复邮件跟进天数")
     @TableField("follow_up_rules_not_replied_days")
-    private String followUpRulesNotRepliedDays;
+    private Integer followUpRulesNotRepliedDays;
 
     @ApiModelProperty(value = "未点击链接跟进规则(1是0否)")
     @TableField("follow_up_rules_link_not_clicked")
@@ -144,7 +144,7 @@ public class MarketingCampaignEntity extends SysBaseField {
 
     @ApiModelProperty(value = "未点击链接跟进天数")
     @TableField("follow_up_rules_link_not_clicked_days")
-    private String followUpRulesLinkNotClickedDays;
+    private Integer followUpRulesLinkNotClickedDays;
 
     @ApiModelProperty(value = "客户回复后自动停止(1是0否)")
     @TableField("follow_up_rules_replied")

+ 10 - 0
java/storlead-sasa/storlead-trade/src/main/java/com/storlead/trade/service/MarketEmailsService.java

@@ -109,4 +109,14 @@ public interface MarketEmailsService extends MyBaseService<MarketEmailsEntity> {
       * @Date: 2026/9/11 16:46
       */
     void send();
+
+    void sendAgain();
+
+    /***
+      * @Description:
+      * @Param:
+      * @return:
+      * @Author: YPZ
+      * @Date: 2026/9/17 15:38
+      */
 }

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

@@ -198,6 +198,7 @@ public class MarketEmailsServiceImpl extends MyBaseServiceImpl<MarketEmailsMappe
                     v.setRecipient(k);
                     v.setClickCount(0L);
                     v.setId(e.getId());
+                    v.setOpenCount(e.getOpenCount());
                     return v;
                 });
                 vo.setClickCount(vo.getClickCount() + 1);
@@ -216,6 +217,7 @@ public class MarketEmailsServiceImpl extends MyBaseServiceImpl<MarketEmailsMappe
                 if (e.getHasSuspend() != null && e.getHasSuspend() == 1) {
                     vo.setHasSuspend(1);
                 }
+
             }
         }
         // 按首次打开时间倒序
@@ -1010,6 +1012,77 @@ public class MarketEmailsServiceImpl extends MyBaseServiceImpl<MarketEmailsMappe
         }
     }
 
+    @Override
+    public void sendAgain() {
+        //查询全部开启了自动化的营销活动
+        LambdaQueryWrapper<MarketingCampaignEntity> marketingCampaignQueryWrapper = new LambdaQueryWrapper<>();
+        marketingCampaignQueryWrapper.eq(MarketingCampaignEntity::getIsDelete, CommonConstant.DEL_FLAG_0);
+        marketingCampaignQueryWrapper.eq(MarketingCampaignEntity::getStatus, 1);
+        marketingCampaignQueryWrapper.eq(MarketingCampaignEntity::getFollowUpRulesNotOpened, 1);
+        List<MarketingCampaignEntity> marketingCampaignList = marketingCampaignService.list(marketingCampaignQueryWrapper);
+        if (CollectionUtils.isEmpty(marketingCampaignList)){
+            return;
+        }
+        for (MarketingCampaignEntity marketingCampaignEntity : marketingCampaignList) {
+            //查询自动化设置的未跟进天数
+            Integer followUpDays = marketingCampaignEntity.getFollowUpRulesNotOpenedDays();
+            LocalDateTime now = LocalDateTime.now();
+            //获取当前时间的前 followUpDays 天
+            LocalDateTime followUpDate = now.minusDays(followUpDays);
+
+            LambdaQueryWrapper<MarketEmailsEntity> queryWrapper = new LambdaQueryWrapper<>();
+
+            LocalDateTime start = followUpDate.withSecond(0).withNano(0);
+            LocalDateTime end = followUpDate.withSecond(59).withNano(999_999_999);
+            queryWrapper.between(MarketEmailsEntity::getExpectSendTime, start, end);
+
+            queryWrapper.eq(MarketEmailsEntity::getStatus, 1);
+            queryWrapper.eq(MarketEmailsEntity::getHasReader,0);
+            queryWrapper.eq(MarketEmailsEntity::getIsDelete, CommonConstant.DEL_FLAG_0);
+            queryWrapper.eq(MarketEmailsEntity::getHasProtect,0);
+            queryWrapper.eq(MarketEmailsEntity::getHasSuspend,0);
+            queryWrapper.eq(MarketEmailsEntity::getMarketingCampaignId, marketingCampaignEntity.getId());
+            List<MarketEmailsEntity> marketEmailList = this.list(queryWrapper);
+
+            if (CollectionUtils.isEmpty(marketEmailList)){
+                return;
+            }
+            log.info("queryWrapper: {}", queryWrapper);
+            log.info("marketEmailList: {}", marketEmailList);
+            for (MarketEmailsEntity marketEmail : marketEmailList){
+                MktSendMailRemoteDTO dto = new MktSendMailRemoteDTO();
+                List<String> recipientls = new ArrayList<>();
+                recipientls.add(marketEmail.getRecipient());
+                dto.setRecipientls(recipientls);
+                dto.setSubject(marketEmail.getSubject());
+                dto.setContent(marketEmail.getContent());
+                dto.setIsTrack(1);
+    //            dto.setDelaySendTime(marketEmail.getExpectSendTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime());
+                Result result = mktMailRemoteClient.send(dto);
+                if (result.isSuccess()) {
+                    // 远程返回 result 是 LinkedHashMap(Jackson 默认反序列化),按 Map 取字段
+                    Map<String, Object> sentMail = (Map<String, Object>) result.getResult();
+                    //将邮件id写入MarketEmailsEntity
+                    marketEmail.setEmailId(((Number) sentMail.get("id")).longValue());
+                    marketEmail.setStatus((Integer) sentMail.get("status"));
+                    log.info("id为:{}", sentMail.get("id"));
+                    log.info("status为:{}", sentMail.get("status"));
+                    log.info("邮件发送成功,邮件ID:{}", marketEmail.getId());
+                } else {
+                    log.error("邮件发送失败,邮件ID:{},错误信息:{}", marketEmail.getId(), result.getMessage());
+                }
+
+    //            123
+            }
+            if (!CollectionUtils.isEmpty(marketEmailList)){
+                this.updateBatchById(marketEmailList);
+            }
+
+        }
+
+
+    }
+
     /**
      * 调用 AI workflow 并解析调度阶段,带重试。
      * 入参 chatDTO 经 workflowsService.AiWorkflows 返回 Result<Object>,

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

@@ -434,6 +434,9 @@ public class MarketingCampaignServiceImpl
             marketEmailsUpdateWrapper.set(MarketEmailsEntity::getStatus, -3);
             marketEmailsService.update(marketEmailsUpdateWrapper);
         }
+
+        //修改邮件发送状态,如果营销活动开启了客户回复后停止自动化,查询对应的营销邮件,如果有回复,将未发送的改为取消
+
     }
 
     /**

+ 6 - 0
java/storlead-sasa/storlead-trade/src/main/java/com/storlead/trade/task/MarketEmailsSendSyncTask.java

@@ -22,7 +22,13 @@ public class MarketEmailsSendSyncTask {
     public void sync() {
         long start = System.currentTimeMillis();
         try {
+            //到时间自动发送
             marketEmailsService.send();
+
+            //客户开启自动化后,到时间没有发送未打开邮件,再次发送
+            marketEmailsService.sendAgain();
+
+
         } catch (Exception e) {
             log.error("mkt_mail_status → market_emails 同步失败", e);
         }

+ 1 - 1
java/storlead-sasa/storlead-trade/src/main/java/com/storlead/trade/task/MarketStartOrEndTask.java

@@ -18,7 +18,7 @@ public class MarketStartOrEndTask {
     @Resource
     private MarketingCampaignService marketingCampaignService;
 
-    @Scheduled(cron = "0 50 10 * * ?")
+    @Scheduled(cron = "0 0 8 * * ?")
     public void dispatch() {
         long start = System.currentTimeMillis();
         log.info("营销活动开始/结束状态同步任务开始");

+ 4 - 0
java/storlead-sasa/storlead-trade/src/main/java/com/storlead/trade/vo/MarketEmailsOpenVO.java

@@ -1,6 +1,7 @@
 package com.storlead.trade.vo;
 
 import com.alibaba.fastjson.annotation.JSONField;
+import com.baomidou.mybatisplus.annotation.TableField;
 import com.fasterxml.jackson.annotation.JsonFormat;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
@@ -34,6 +35,9 @@ public class MarketEmailsOpenVO implements Serializable {
     @ApiModelProperty(value = "点击次数(同 recipient 下的邮件打开记录数)")
     private Long clickCount;
 
+    @ApiModelProperty(value = "打开次数")
+    private Integer openCount;
+
     @ApiModelProperty(value = "首次打开时间")
     @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
     @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")

+ 3 - 3
java/storlead-sasa/storlead-trade/src/main/java/com/storlead/trade/vo/MarketingCampaignVO.java

@@ -102,19 +102,19 @@ public class MarketingCampaignVO extends SysBaseField {
     private Integer followUpRulesNotOpened;
 
     @ApiModelProperty(value = "未打开邮件跟进天数")
-    private String followUpRulesNotOpenedDays;
+    private Integer followUpRulesNotOpenedDays;
 
     @ApiModelProperty(value = "未回复邮件跟进规则(1是0否)")
     private Integer followUpRulesNotReplied;
 
     @ApiModelProperty(value = "未回复邮件跟进天数")
-    private String followUpRulesNotRepliedDays;
+    private Integer followUpRulesNotRepliedDays;
 
     @ApiModelProperty(value = "未点击链接跟进规则(1是0否)")
     private Integer followUpRulesLinkNotClicked;
 
     @ApiModelProperty(value = "未点击链接跟进天数")
-    private String followUpRulesLinkNotClickedDays;
+    private Integer followUpRulesLinkNotClickedDays;
 
     @ApiModelProperty(value = "客户回复后自动停止(1是0否)")
     private Integer followUpRulesReplied;