修复一些bug

This commit is contained in:
chfei committed 2026-11-10 09:54:12 +08:00
1 parent 9bb17a67d2
commit f4913b4fc2
7 files changed
+38 -10

No files matched your search

@@ -112,9 +112,22 @@ public class GoodsViolationRepository(
public async Task InsertLogsAsync(GoodsViolationLogEntity[] logs)
{
// 即使 ORM 拆分 INSERT,各批次也在同一事务内提交。
using var unit = Orm.CreateUnitOfWork();
await unit.GetRepository<GoodsViolationLogEntity>().InsertAsync(logs);
unit.GetOrBeginTransaction();
foreach (var log in logs)
{
try
{
await unit.Orm.Insert(log).ExecuteAffrowsAsync();
}
catch (Exception ex) when (ex.GetBaseException() is MySql.Data.MySqlClient.MySqlException { Number: 1062 } duplicate
&& (duplicate.Message.EndsWith(".ux_violation_log_event'", StringComparison.Ordinal)
|| duplicate.Message.EndsWith("'ux_violation_log_event'", StringComparison.Ordinal)))
{
// 事件唯一键已存在即视为上报成功,保留首次记录,继续写入本批其他事件。
continue;
}
}
unit.Commit();
}