Ver Fonte

出参修改

chenkq há 2 semanas atrás
pai
commit
65eb4a71b8

+ 2 - 0
storlead-mail/storlead-mail-common/src/main/resources/sql/mkt_mail_recreate.sql

@@ -97,6 +97,8 @@ CREATE TABLE mkt_mail_status (
     first_read_time   datetime     NULL COMMENT '首次已读时间',
     replied           tinyint      NOT NULL DEFAULT 0 COMMENT '是否已回复:0否 1是',
     first_reply_time  datetime     NULL COMMENT '首次回复时间',
+    first_reply_email_id bigint    NULL COMMENT '首次回复邮件ID,对应 mkt_mail_message.id',
+    first_reply_theme varchar(512) NULL COMMENT '首次回复邮件主题',
     status_updated_at datetime     NOT NULL COMMENT '业务状态变更时间(打开/回复/发送态等变更时刷新)',
     synced_at         datetime     NULL COMMENT '业务侧最后同步时间;null或小于status_updated_at表示待同步',
     owner_by          bigint       NULL COMMENT '数据归属人',

+ 2 - 0
storlead-mail/storlead-mail-common/src/main/resources/sql/mkt_mail_status.sql

@@ -12,6 +12,8 @@ CREATE TABLE IF NOT EXISTS mkt_mail_status (
     first_read_time   datetime     NULL COMMENT '首次已读时间',
     replied           tinyint      NOT NULL DEFAULT 0 COMMENT '是否已回复:0否 1是',
     first_reply_time  datetime     NULL COMMENT '首次回复时间',
+    first_reply_email_id bigint    NULL COMMENT '首次回复邮件ID,对应 mkt_mail_message.id',
+    first_reply_theme varchar(512) NULL COMMENT '首次回复邮件主题',
 
     status_updated_at datetime     NOT NULL COMMENT '业务状态变更时间(打开/回复/发送态等变更时刷新)',
     synced_at         datetime     NULL COMMENT '业务侧最后同步时间;null或小于status_updated_at表示待同步',

+ 4 - 0
storlead-mail/storlead-mail-common/src/main/resources/sql/mkt_mail_status_add_first_reply_mail.sql

@@ -0,0 +1,4 @@
+-- mkt_mail_status:首次回复邮件 ID / 主题
+ALTER TABLE mkt_mail_status
+    ADD COLUMN first_reply_email_id bigint NULL COMMENT '首次回复邮件ID,对应 mkt_mail_message.id' AFTER first_reply_time,
+    ADD COLUMN first_reply_theme varchar(512) NULL COMMENT '首次回复邮件主题' AFTER first_reply_email_id;

+ 8 - 0
storlead-mail/storlead-mail-mkt/src/main/java/com/storlead/sales/mail/mkt/entity/MktMailStatusEntity.java

@@ -85,6 +85,14 @@ public class MktMailStatusEntity extends SysBaseField {
     @TableField("first_reply_time")
     private Date firstReplyTime;
 
+    @ApiModelProperty("首次回复邮件ID,对应 mkt_mail_message.id")
+    @TableField("first_reply_email_id")
+    private Long firstReplyEmailId;
+
+    @ApiModelProperty("首次回复邮件主题")
+    @TableField("first_reply_theme")
+    private String firstReplyTheme;
+
     @ApiModelProperty("业务状态变更时间(打开/回复/发送态等变更时刷新)")
     @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
     @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")

+ 10 - 5
storlead-mail/storlead-mail-mkt/src/main/java/com/storlead/sales/mail/mkt/receive/MktMailReceivePersist.java

@@ -174,6 +174,16 @@ public class MktMailReceivePersist implements MailReceivePersistSpi {
             bindReply(account.getId(), message, draft, entity);
 
             if (mktMailMessageService.save(entity)) {
+                // 落库后才有回复邮件 ID,再标记原信已回复并写入首次回复邮件/主题
+                if (entity.getReplyMsgId() != null) {
+                    try {
+                        mktMailMessageService.markReplied(
+                                entity.getReplyMsgId(), entity.getId(), entity.getSubject());
+                    } catch (Exception e) {
+                        log.error("mkt markReplied error, parentMailId={}, replyMailId={}",
+                                entity.getReplyMsgId(), entity.getId(), e);
+                    }
+                }
                 if (MktMailFolderEnum.INBOX.code.equals(folder)) {
                     handleBounceIfNeeded(entity, body);
                 }
@@ -472,11 +482,6 @@ public class MktMailReceivePersist implements MailReceivePersistSpi {
         if (!StringUtils.hasText(entity.getBizBatchNo()) && StringUtils.hasText(parent.getBizBatchNo())) {
             entity.setBizBatchNo(parent.getBizBatchNo());
         }
-        try {
-            mktMailMessageService.markReplied(parent.getId());
-        } catch (Exception e) {
-            log.error("mkt markReplied error, parentMailId={}", parent.getId(), e);
-        }
     }
 
     /**

+ 6 - 2
storlead-mail/storlead-mail-mkt/src/main/java/com/storlead/sales/mail/mkt/service/MktMailMessageService.java

@@ -50,9 +50,13 @@ public interface MktMailMessageService extends MyBaseService<MktMailMessageEntit
 
     /**
      * 收信绑定到原信后:按 mailId 标记已回复(幂等;无效 id 返回 false)。
-     * 同时回写 mkt_mail_message 与 mkt_mail_status。
+     * 同时回写 mkt_mail_message 与 mkt_mail_status(含首次回复邮件 ID / 主题)。
+     *
+     * @param mailId        原信(发出信)ID
+     * @param replyEmailId  回复邮件 ID
+     * @param replyTheme    回复邮件主题
      */
-    boolean markReplied(Long mailId);
+    boolean markReplied(Long mailId, Long replyEmailId, String replyTheme);
 
     /**
      * 按业务单号汇总打开情况。

+ 7 - 2
storlead-mail/storlead-mail-mkt/src/main/java/com/storlead/sales/mail/mkt/service/MktMailStatusService.java

@@ -27,9 +27,14 @@ public interface MktMailStatusService extends MyBaseService<MktMailStatusEntity>
     void markOpened(Long mailId);
 
     /**
-     * 收到针对原信的回复:更新 replied / first_reply_time(仅首次)。
+     * 收到针对原信的回复:更新 replied / first_reply_time,
+     * 以及首次回复邮件 ID、主题(仅首次写入)。
+     *
+     * @param mailId            原信(发出信)ID
+     * @param firstReplyEmailId 回复邮件 ID(入站 mkt_mail_message.id)
+     * @param firstReplyTheme   回复邮件主题
      */
-    void markReplied(Long mailId);
+    void markReplied(Long mailId, Long firstReplyEmailId, String firstReplyTheme);
 
     /**
      * 业务侧同步完成后回写同步时间(synced_at)。

+ 2 - 2
storlead-mail/storlead-mail-mkt/src/main/java/com/storlead/sales/mail/mkt/service/impl/MktMailMessageServiceImpl.java

@@ -418,7 +418,7 @@ public class MktMailMessageServiceImpl extends MyBaseServiceImpl<MktMailMessageM
     }
 
     @Override
-    public boolean markReplied(Long mailId) {
+    public boolean markReplied(Long mailId, Long replyEmailId, String replyTheme) {
         if (mailId == null) {
             return false;
         }
@@ -444,7 +444,7 @@ public class MktMailMessageServiceImpl extends MyBaseServiceImpl<MktMailMessageM
         MktMailMessageEntity latest = this.getById(before.getId());
         fireReplyCallbacks(latest == null ? before : latest, firstReply);
         try {
-            mktMailStatusService.markReplied(before.getId());
+            mktMailStatusService.markReplied(before.getId(), replyEmailId, replyTheme);
         } catch (Exception e) {
             log.error("mkt_mail_status markReplied error, mailId={}", before.getId(), e);
         }

+ 18 - 1
storlead-mail/storlead-mail-mkt/src/main/java/com/storlead/sales/mail/mkt/service/impl/MktMailStatusServiceImpl.java

@@ -12,6 +12,7 @@ import lombok.extern.log4j.Log4j2;
 import org.springframework.dao.DuplicateKeyException;
 import org.springframework.stereotype.Service;
 import org.springframework.util.CollectionUtils;
+import org.springframework.util.StringUtils;
 
 import java.util.Collection;
 import java.util.Date;
@@ -100,17 +101,33 @@ public class MktMailStatusServiceImpl extends MyBaseServiceImpl<MktMailStatusMap
     }
 
     @Override
-    public void markReplied(Long mailId) {
+    public void markReplied(Long mailId, Long firstReplyEmailId, String firstReplyTheme) {
         if (mailId == null) {
             return;
         }
         ensureMinimalRow(mailId);
+        MktMailStatusEntity existing = getByMailId(mailId);
         Date now = new Date();
         LambdaUpdateWrapper<MktMailStatusEntity> update = new LambdaUpdateWrapper<>();
         update.eq(MktMailStatusEntity::getMailId, mailId);
         update.eq(MktMailStatusEntity::getIsDelete, CommonConstant.DEL_FLAG_0);
         update.set(MktMailStatusEntity::getReplied, 1);
         update.setSql("first_reply_time = IFNULL(first_reply_time, NOW())");
+        // 仅首次写入回复邮件 ID / 主题
+        if (existing == null || existing.getFirstReplyEmailId() == null) {
+            if (firstReplyEmailId != null) {
+                update.set(MktMailStatusEntity::getFirstReplyEmailId, firstReplyEmailId);
+            }
+        }
+        if (existing == null || !StringUtils.hasText(existing.getFirstReplyTheme())) {
+            if (StringUtils.hasText(firstReplyTheme)) {
+                String theme = firstReplyTheme.trim();
+                if (theme.length() > 512) {
+                    theme = theme.substring(0, 512);
+                }
+                update.set(MktMailStatusEntity::getFirstReplyTheme, theme);
+            }
+        }
         update.set(MktMailStatusEntity::getStatusUpdatedAt, now);
         update.set(MktMailStatusEntity::getUpdateTime, now);
         this.update(update);