fix: 兼容档口货号括号与前导零 (#273)

This commit is contained in:
chengma
2026-08-18 17:20:50 +08:00
parent 8e58793a0b
commit 5e0cf95859
2 changed files with 161 additions and 8 deletions
+69
View File
@@ -223,6 +223,75 @@ func TestMatchInnerCodeItemsWithEvidence_重复和证据冲突均阻断(t *testi
}
}
func TestInnerCodeStallMatches_中文括号货号与数字前导零(t *testing.T) {
tests := []struct {
name string
stall string
item syb.DetailItem
want bool
}{
{
name: "067在中文括号前为独立货号",
stall: "将客大码网批#067",
item: innerCodeTestItem(1, "黑色(有口袋),2XL【建議67.5-82.5公斤】", map[string]any{
"sku": "067【将客大码网批】-黑色(有口袋)-2XL",
}),
want: true,
},
{
name: "同档口67与067等价",
stall: "将客大码网批#067",
item: innerCodeTestItem(2, "黑色,2XL", map[string]any{
"variationSku": "汽配-将客大码网批#67#(&19)",
}),
want: true,
},
{
name: "同货号不同档口不匹配",
stall: "将客大码网批#067",
item: innerCodeTestItem(3, "黑色,2XL", map[string]any{
"sku": "067【其他档口】-黑色-2XL", "variationSku": "汽配-其他档口#67",
}),
want: false,
},
{
name: "非数字货号不做类似转换",
stall: "A档#A01",
item: innerCodeTestItem(4, "黑色,M", map[string]any{"sku": "A档#A1"}),
want: false,
},
{
name: "非数字货号精确匹配",
stall: "A档#A01",
item: innerCodeTestItem(5, "黑色,M", map[string]any{"sku": "A档#A01"}),
want: true,
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
if got := innerCodeStallMatches(test.stall, test.item); got != test.want {
t.Fatalf("innerCodeStallMatches(%q)=%t,期望 %t", test.stall, got, test.want)
}
})
}
}
func TestPlanInnerCodeRows_将客档口067唯一匹配生产样例(t *testing.T) {
record := model.InnerCodeRecord{ID: 255, OrderNumber: "260814A21AAB1G",
Stall: "将客大码网批#067", SpecRaw: "黑色(有口袋),2XL【建議67.5-82.5公斤】",
InnerCode: "DK-255", SourceDuplicateCount: 1}
item := innerCodeTestItem(147048059, record.SpecRaw, map[string]any{
"sku": "067【将客大码网批】-黑色(有口袋)-2XL",
"variationSku": "汽配-将客大码网批#67#(&19)",
})
plans := planInnerCodeRows([]model.InnerCodeRecord{record},
map[string][]int64{record.OrderNumber: {76159471}},
map[int64]syb.StockDetail{76159471: {ID: 76159471, Details: []syb.DetailItem{item}}})
if len(plans) != 1 || plans[0].Status != model.InnerCodeReady || plans[0].DetailID != item.ID {
t.Fatalf("将客档口记录未生成可回写计划: %+v", plans)
}
}
func TestPlanInnerCodeRows_多件数量一致放行且其他异常继续阻断(t *testing.T) {
records := []model.InnerCodeRecord{
{ID: 1, OrderNumber: "DUP", SpecRaw: "黑色,M", InnerCode: "DK1,DK2", SourceDuplicateCount: 2},