收口订单详情分片事务写入
This commit is contained in:
1 parent
6375eecf8f
commit
c27db2381b
2 files changed
+43
-16
No files matched your search
@@ -740,3 +740,4 @@ npm --prefix frontend run build
|
||||
| 2026-08-15 | P2 订单缺失状态批量写入切片 | 已完成 | `SoftDeleteMissingForCookie` 改为单条 `NOT IN` 批量 UPDATE,消除逐订单读取与逐条写入;空线上订单集合和保留订单回归均覆盖,数据库注释门禁与定向测试通过。订单详情逐单 Upsert、刷新后台 Job、游标分页和三库大数据量查询计划仍待治理,阶段 8 继续保持“进行中” |
|
||||
| 2026-08-15 | P1 订单补偿恢复 worker 切片 | 已完成 | 新增 `internal/reconciliation` 服务和受 Server `backgroundWG` 管理的扫描器;pending 手动发货补偿会重试本地订单状态写入,成功后标记 resolved,失败保留 pending 并递增 attempts;新增成功恢复/失败重试测试,定向测试与中文注释门禁通过。更广泛自动化动作补偿、指数退避和运维查询接口仍待治理,阶段 5/8 继续保持“进行中” |
|
||||
| 2026-08-15 | P1 账号删除生命周期 fencing 切片 | 已完成 | 删除流程新增账号级 `BeginStopping/EndStopping` fencing,停止窗口内拒绝新的 runtime 启动;删除前停止 runtime 改为受 5 秒请求 Context 约束的同步收束,超时返回明确冲突,不再创建游离 Stop goroutine;重新取得凭证锁后复核账号归属再删除,避免停止窗口内误删被替换账号;新增 Manager fencing 回归测试,Go/Server 定向测试、`make check` 和 Go/React 注释门禁通过。调度器 Context-aware 等待、删除任务 ID/状态查询、其他生命周期任务统一清单仍待治理,阶段 5 继续保持“进行中” |
|
||||
| 2026-08-15 | P2 订单详情分片事务写入切片 | 已完成 | 订单详情远端请求仍在锁外执行;每个详情分片先收集成功结果,再通过订单应用 `UnitOfWork` 在单事务内提交,避免逐订单独立事务和分片内部分提交;事务失败时整片结果统一失败并保留远端会话收束逻辑;订单刷新定向测试、`make check`、架构和中文注释门禁通过。尚未实现真正单 SQL 多行 UPSERT、游标分页和后台 Job 化,P2 批量同步仍保持“进行中” |
|
||||
@@ -148,6 +148,18 @@ type orderApplicationService struct {
|
||||
repository orderapp.Repository
|
||||
}
|
||||
|
||||
// orderRefreshWrite 保存已从平台成功获取、等待同一事务批量写入的订单详情。
|
||||
type orderRefreshWrite struct {
|
||||
// orderID 是待更新订单的业务标识。
|
||||
orderID string
|
||||
// currentStatus 是刷新前的订单状态。
|
||||
currentStatus string
|
||||
// newStatus 是平台返回并经过本地规则校正后的订单状态。
|
||||
newStatus string
|
||||
// options 是写入订单所需的应用层字段集合。
|
||||
options orderapp.UpsertOptions
|
||||
}
|
||||
|
||||
// errOrderDetailUnsupported 保存err订单DetailUnsupported,供当前处理流程使用
|
||||
var errOrderDetailUnsupported = errors.New("当前 Go MTOP 客户端不支持订单详情接口")
|
||||
|
||||
@@ -1032,6 +1044,8 @@ func (a *orderApplicationService) Refresh(ctx context.Context, userID int64, coo
|
||||
credentialUnlock()
|
||||
// sessionErr 保存会话Err,供当前处理流程使用
|
||||
var sessionErr error
|
||||
// pendingWrites 保存当前详情分片中已成功获取、等待事务批量写入的订单。
|
||||
pendingWrites := make([]orderRefreshWrite, 0, len(chunk))
|
||||
// target 表示当前遍历过程中的target
|
||||
for _, target := range chunk {
|
||||
// detail、fetchErr 保存detail、fetchErr,供当前处理流程使用
|
||||
@@ -1059,32 +1073,44 @@ func (a *orderApplicationService) Refresh(ctx context.Context, userID int64, coo
|
||||
if !validEditableOrderStatus(newStatus) {
|
||||
newStatus = target.CurrentStatus
|
||||
}
|
||||
// err 保存err,供当前处理流程使用
|
||||
err := a.repository.UpsertOrder(ctx, target.OrderID, orderapp.UpsertOptions{
|
||||
CookieID: cid,
|
||||
OrderStatus: newStatus,
|
||||
SpecName: detail.SpecName,
|
||||
SpecValue: detail.SpecValue,
|
||||
Quantity: detail.Quantity,
|
||||
Amount: detail.Amount,
|
||||
pendingWrites = append(pendingWrites, orderRefreshWrite{
|
||||
orderID: target.OrderID,
|
||||
currentStatus: target.CurrentStatus,
|
||||
newStatus: newStatus,
|
||||
options: orderapp.UpsertOptions{
|
||||
CookieID: cid, OrderStatus: newStatus, SpecName: detail.SpecName,
|
||||
SpecValue: detail.SpecValue, Quantity: detail.Quantity, Amount: detail.Amount,
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
}
|
||||
// batchWriteErr 表示当前详情分片的订单批量事务写入错误。
|
||||
batchWriteErr := a.repository.WithTransaction(ctx, func(writer orderapp.Writer) error {
|
||||
// write 表示当前事务中待写入的订单详情。
|
||||
for _, write := range pendingWrites {
|
||||
// err 表示当前订单写入失败的底层错误。
|
||||
if err := writer.UpsertOrder(ctx, write.orderID, write.options); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
// write 表示当前批量写入结果对应的订单详情。
|
||||
for _, write := range pendingWrites {
|
||||
if batchWriteErr != nil {
|
||||
failed++
|
||||
results = append(results, map[string]any{"order_id": target.OrderID, "success": false, "message": "更新数据库失败"})
|
||||
results = append(results, map[string]any{"order_id": write.orderID, "success": false, "message": "批量更新数据库失败"})
|
||||
continue
|
||||
}
|
||||
// changed 保存changed,供当前处理流程使用
|
||||
changed := newStatus != "" && newStatus != target.CurrentStatus
|
||||
// changed 表示当前订单状态是否发生变化。
|
||||
changed := write.newStatus != "" && write.newStatus != write.currentStatus
|
||||
if changed {
|
||||
updated++
|
||||
} else {
|
||||
noChange++
|
||||
}
|
||||
results = append(results, map[string]any{
|
||||
"order_id": target.OrderID,
|
||||
"success": true,
|
||||
"old_status": target.CurrentStatus,
|
||||
"new_status": newStatus,
|
||||
"order_id": write.orderID, "success": true,
|
||||
"old_status": write.currentStatus, "new_status": write.newStatus,
|
||||
})
|
||||
}
|
||||
cancel()
|
||||
|
||||
Reference in new issue
Block a user