|
|
@@ -1729,6 +1729,11 @@ public class MarketEmailsServiceImpl extends MyBaseServiceImpl<MarketEmailsMappe
|
|
|
}
|
|
|
MarketEmailsEntity newMarketEmail = new MarketEmailsEntity();
|
|
|
BeanUtils.copyProperties(marketEmail, newMarketEmail);
|
|
|
+ // 注意:copyProperties 会把首邮件的 createTime/updateTime 也拷过来(非空),
|
|
|
+ // 导致 MyBatis-Plus 的自动填充被跳过,second 邮件的创建/更新时间变成首邮件的时间。
|
|
|
+ // 这里主动置空,交给自动填充写入真正的当前时间;若自动填充未生效,下方再兜底设值。
|
|
|
+ newMarketEmail.setCreateTime(null);
|
|
|
+ newMarketEmail.setUpdateTime(null);
|
|
|
newMarketEmail.setFirstSendId(firstId);
|
|
|
newMarketEmail.setId(null);
|
|
|
newMarketEmail.setEmailId(null);
|
|
|
@@ -1768,13 +1773,17 @@ public class MarketEmailsServiceImpl extends MyBaseServiceImpl<MarketEmailsMappe
|
|
|
}
|
|
|
}
|
|
|
if (!CollectionUtils.isEmpty(newMarketEmailList)){
|
|
|
- try {
|
|
|
- this.saveBatch(newMarketEmailList);
|
|
|
- } catch (Exception ex) {
|
|
|
- // 兜底:若并发下仍有极少量重复键(依赖 DB 唯一索引 uq_second_first_send 兜底),
|
|
|
- // 只记录告警,不让整个定时任务中断。
|
|
|
- log.warn("[sendAgain] 批量插入 follow-up 邮件部分失败(可能为并发重复键,已靠唯一索引拦截):{}",
|
|
|
- ex.getMessage());
|
|
|
+ // 逐条插入 + 单条容错:多个应用实例并发跑 sendAgain 时,即使已经加了唯一索引
|
|
|
+ // uq_second_first_send(first_send_id, has_first),仍可能因竞态让同一条 follow-up 被两个实例
|
|
|
+ // 同时插入。逐条插入可以保证「一条重复键失败」不会把同批次里其它合法的 follow-up 也拖垮
|
|
|
+ // (批量 insert 在多值语句下任一行的唯一约束冲突会导致整批失败)。重复键异常被静默吞掉即可。
|
|
|
+ for (MarketEmailsEntity newEmail : newMarketEmailList) {
|
|
|
+ try {
|
|
|
+ this.save(newEmail);
|
|
|
+ } catch (Exception ex) {
|
|
|
+ log.warn("[sendAgain] 插入 follow-up 邮件失败(可能为并发重复键,已被唯一索引拦截,可忽略):firstSendId={}, err={}",
|
|
|
+ newEmail.getFirstSendId(), ex.getMessage());
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|