fix(watch): QH_WAT_USER_DATA并发写入唯一约束冲突时忽略重复插入

notice接口并发上报同一手表同一天数据时,先删后插存在竞态,
两个线程同时插入触发唯一约束WATCH_USER_DATA_WATCH_NO,
捕获DuplicateKeyException降级为warn日志,数据不丢失

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
wanghao
2026-08-25 11:05:26 +08:00
co-authored by Claude
parent a8e8b53203
commit 674891eba3
@@ -42,6 +42,7 @@ import org.jeecgframework.poi.excel.entity.params.ExcelExportEntity;
import org.jeecgframework.poi.exception.excel.enums.ExcelExportEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.task.AsyncTaskExecutor;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
@@ -208,7 +209,12 @@ public class WatchUserDataServiceImpl extends ServiceImpl<WatchUserDataMapper, W
watchUserData.setDataDate(bindDateSave);
watchUserData.setWatchNo(watchNo);
watchUserData.setCreateDate(new Date());
this.save(watchUserData);
try {
this.save(watchUserData);
} catch (DuplicateKeyException e) {
//并发上报同一手表同一天数据时,先删后插存在竞态,另一线程已插入相同记录,忽略即可
log.warn("QH_WAT_USER_DATA并发写入冲突,已忽略: watchNo={}, dataDate={}", watchNo, s);
}
}
// @Override