fix: 拒绝并发覆盖颜色映射 (#293)
This commit is contained in:
@@ -278,9 +278,18 @@ func colorMappingContextVersion(context *ProductColorMappingContext, pddUpdatedA
|
||||
Key, Raw string
|
||||
FormalCount, SybCount int
|
||||
}
|
||||
type contextMapping struct {
|
||||
ColorKey, DimensionKey, TargetValue, MappedAt string
|
||||
}
|
||||
colors := make([]contextColor, 0, len(context.Rows))
|
||||
mappings := make([]contextMapping, 0, len(context.Rows))
|
||||
for _, row := range context.Rows {
|
||||
colors = append(colors, contextColor{row.Color.Key, row.Color.Raw, row.Color.FormalCount, row.Color.SybCount})
|
||||
if row.Mapping != nil {
|
||||
mappings = append(mappings, contextMapping{
|
||||
row.Color.Key, row.Mapping.PddDimensionKey, row.Mapping.PddColorValue, row.Mapping.MappedAt,
|
||||
})
|
||||
}
|
||||
}
|
||||
pddHash := sha256.Sum256([]byte(pddSKUsJSON))
|
||||
payload := struct {
|
||||
@@ -290,7 +299,8 @@ func colorMappingContextVersion(context *ProductColorMappingContext, pddUpdatedA
|
||||
PddUpdatedAt string
|
||||
PddHash string
|
||||
Colors []contextColor
|
||||
}{ProductColorMappingRulesVersion, context.ShopeeGoodsID, context.PddGoodsID, pddUpdatedAt, hex.EncodeToString(pddHash[:]), colors}
|
||||
Mappings []contextMapping
|
||||
}{ProductColorMappingRulesVersion, context.ShopeeGoodsID, context.PddGoodsID, pddUpdatedAt, hex.EncodeToString(pddHash[:]), colors, mappings}
|
||||
raw, _ := json.Marshal(payload)
|
||||
sum := sha256.Sum256(raw)
|
||||
return hex.EncodeToString(sum[:])
|
||||
|
||||
@@ -101,6 +101,10 @@ func TestSaveProductColorMappings_保存审计并用上下文版本防过期(t *
|
||||
if err := db.QueryRow(`SELECT COUNT(*) FROM product_color_mapping_audits WHERE shopee_goods_id='S-COLOR'`).Scan(&audits); err != nil || audits != 1 {
|
||||
t.Fatalf("审计记录=%d err=%v", audits, err)
|
||||
}
|
||||
if _, err := SaveProductColorMappings(db, actor, "S-COLOR", context.ContextVersion,
|
||||
[]ProductColorMappingUpdate{{ShopeeColorKey: "黑色"}}); err == nil {
|
||||
t.Fatal("并发颜色映射已经变化时,旧页面必须拒绝整批保存")
|
||||
}
|
||||
if _, err := db.Exec(`UPDATE pdd_products SET updated_at=? WHERE goods_id='P-COLOR'`, "2026-08-23T02:00:00Z"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user