feat(distribution): 优化一键同步主站商品功能(并发防重、分批入库、失效商品联动下架与初始加价)
- 后端优化: - 引入 Redis + 内存 sync.Map 双重互斥锁,避免并发/连击导致唯一索引冲突 (ErrSyncInProgress) - 使用 CreateInBatches(500) 进行大数据量批量插入,杜绝超长 SQL 与锁表超时 - 增加 CleanStaleListings 支持,自动排查并联动下架主站非在售的货架商品,清理历史幽灵数据 - 增加 DefaultShelfRatioDelta 支持,新同步商品直接继承初始加价比例,免除二次手动改价 - 前端优化: - distribution-admin 货架管理新增一键同步配置弹窗(可勾选自动下架失效商品、配置初始加价) - 同步完成后展示结构化统计弹窗(新增、保持、联动下架、主站在售总量) - 前后端类型定义与 API 客户端对齐升级 - 测试覆盖: - 补充 TestSyncSiteAccountsOptimizations 单元测试与 handler 集成测试 - 全工程测试与门禁 check.sh 100% 通过
This commit is contained in:
@@ -411,17 +411,40 @@ func TestHandler_SiteOperatorEndpoints(t *testing.T) {
|
||||
masterListing := model.RentalListing{ListingNo: "L-SYNC-1", AccountID: masterAcc.ID, OwnerID: opOwner.ID, PriceCent: 3000, Status: "published", ReviewStatus: "approved"}
|
||||
env.db.Create(&masterListing)
|
||||
|
||||
syncReq := SyncSiteAccountsRequest{ListingIDs: []uint64{masterListing.ID}}
|
||||
syncReq := SyncSiteAccountsRequest{
|
||||
ListingIDs: []uint64{masterListing.ID},
|
||||
CleanStaleListings: true,
|
||||
DefaultShelfRatioDelta: 12.5,
|
||||
}
|
||||
wSync := env.request("POST", fmt.Sprintf("/api/v1/distribution/sites/%d/sync-accounts", siteA.ID), syncReq, adminA.ID, nil)
|
||||
if wSync.Code != http.StatusOK {
|
||||
t.Fatalf("sync accounts expected 200, got %d: %s", wSync.Code, wSync.Body.String())
|
||||
}
|
||||
var syncResp struct {
|
||||
Code string `json:"code"`
|
||||
Data SyncSiteAccountsResult `json:"data"`
|
||||
}
|
||||
json.Unmarshal(wSync.Body.Bytes(), &syncResp)
|
||||
if syncResp.Data.SyncedCount != 1 {
|
||||
t.Fatalf("expected 1 synced, got %+v", syncResp.Data)
|
||||
}
|
||||
|
||||
// 获取生成的 DSA 记录
|
||||
// 获取生成的 DSA 记录并验证默认加价生效
|
||||
var dsa model.DistributionSiteAccount
|
||||
if err := env.db.Where("site_id = ? AND listing_id = ?", siteA.ID, masterListing.ID).First(&dsa).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if dsa.ShelfRatioDelta != 12.5 {
|
||||
t.Fatalf("expected shelf_ratio_delta=12.5, got %v", dsa.ShelfRatioDelta)
|
||||
}
|
||||
|
||||
// 验证负数加价比例报错 400
|
||||
wNegativeSync := env.request("POST", fmt.Sprintf("/api/v1/distribution/sites/%d/sync-accounts", siteA.ID), SyncSiteAccountsRequest{
|
||||
DefaultShelfRatioDelta: -10,
|
||||
}, adminA.ID, nil)
|
||||
if wNegativeSync.Code != http.StatusBadRequest {
|
||||
t.Fatalf("expected 400 for negative delta, got %d", wNegativeSync.Code)
|
||||
}
|
||||
|
||||
// 7. 单品调价
|
||||
markupReq := UpdateAccountMarkupRequest{ShelfRatioDelta: 15}
|
||||
|
||||
Reference in New Issue
Block a user