fix(server): 档案合并改为无条件,既有数据可自愈 (#301)

只在键发生变化时才补档案是不够的:既有数据的键早已被前一次重解析改对了,档案
却还是空的,那样永远补不上——线上 215 条全部返回 unchanged,档案一条都没补进去。

mergeParsedSpec 对已存在的值幂等,无条件合并让这条路径能自愈。

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NTDbDcwbDw1TSAcE6wfh2F
This commit is contained in:
QiuSW
2026-09-17 09:44:48 +08:00
co-authored by Claude Opus 5
parent 0e41000f62
commit 57f6cec803
+13 -10
View File
@@ -49,17 +49,20 @@ func resyncShopeeProductKeys(tx *gorm.DB, shopeeProductID uint64, incomingRaw st
sibling.ManuallyConfirmed || sibling.AIConfirmed {
continue
}
if sibling.TargetColor == keys.Color && sibling.TargetSize == keys.Size {
continue
if sibling.TargetColor != keys.Color || sibling.TargetSize != keys.Size {
if err := tx.Model(&models.SYBProduct{}).Where("id = ?", sibling.ID).
Updates(map[string]any{"target_color": keys.Color, "target_size": keys.Size}).Error; err != nil {
return sybspec.ParseResult{}, err
}
}
if err := tx.Model(&models.SYBProduct{}).Where("id = ?", sibling.ID).
Updates(map[string]any{"target_color": keys.Color, "target_size": keys.Size}).Error; err != nil {
return sybspec.ParseResult{}, err
}
// `[必须]` 改了明细的键就必须把新键补进档案。映射是按档案里的值建的,
// 档案没有 `黑色【長袖】` 这个条目,采购查映射就查不到,明细永远停在
// 「规格待匹配」——而采购员点「一键匹配」匹到的是档案里剩下的旧键
// `黑色`,看起来成功了却没有任何明细在用它。
// `[必须]` 无条件把键补进档案,不能只在键发生变化时补。映射是按档案里的
// 值建的,档案缺了 `黑色【長袖】` 这个条目,采购查映射就查不到,明细永远
// 停在「规格待匹配」——而采购员点「一键匹配」匹到的是档案里剩下的旧键
// `黑色`,看起来成功了却没有任何明细在用它(线上 2026-09-17 实际发生)。
//
// 只在「键变化」时补是不够的:既有数据的键早已是对的,档案却是空的,
// 那样永远补不上。无条件合并让这条路径可以自愈,mergeParsedSpec 本身
// 对已存在的值是幂等的。
if err := mergeParsedSpec(tx, shopeeProductID, keys); err != nil {
return sybspec.ParseResult{}, err
}