fix: 使用原始SKU辅助档口匹配 (#259)
This commit is contained in:
@@ -263,10 +263,15 @@ func planInnerCodeRowsWithReserved(records []model.InnerCodeRecord, stockIDsByOr
|
||||
plans = append(plans, innerCodeSkippedPlan(plan, message))
|
||||
continue
|
||||
}
|
||||
matches := matchInnerCodeItems(record.SpecRaw, record.Stall, eligible)
|
||||
specMatches := matchInnerCodeSpecItems(record.SpecRaw, eligible)
|
||||
matches, evidenceReason := matchInnerCodeItemsWithEvidence(record.Stall, record.SourceSKURaw, specMatches)
|
||||
if evidenceReason != "" {
|
||||
plans = append(plans, innerCodeSkippedPlan(plan, evidenceReason))
|
||||
continue
|
||||
}
|
||||
if len(matches) == 0 {
|
||||
reason := "候选商品中没有相同规格"
|
||||
if len(matchInnerCodeItems(record.SpecRaw, "", eligible)) > 0 {
|
||||
if len(specMatches) > 0 {
|
||||
reason = "规格能匹配,但档口及货号与候选商品不一致"
|
||||
}
|
||||
plans = append(plans, innerCodeSkippedPlan(plan, reason))
|
||||
@@ -320,6 +325,10 @@ func innerCodeSkippedPlan(plan model.InnerCodeRecord, message string) model.Inne
|
||||
}
|
||||
|
||||
func matchInnerCodeItems(spec, stall string, eligible []syb.DetailItem) []syb.DetailItem {
|
||||
return filterInnerCodeItemsByStall(matchInnerCodeSpecItems(spec, eligible), stall)
|
||||
}
|
||||
|
||||
func matchInnerCodeSpecItems(spec string, eligible []syb.DetailItem) []syb.DetailItem {
|
||||
matches := make([]syb.DetailItem, 0)
|
||||
for _, item := range eligible {
|
||||
if item.ProductSpec == spec {
|
||||
@@ -337,7 +346,34 @@ func matchInnerCodeItems(spec, stall string, eligible []syb.DetailItem) []syb.De
|
||||
}
|
||||
}
|
||||
}
|
||||
return filterInnerCodeItemsByStall(matches, stall)
|
||||
return matches
|
||||
}
|
||||
|
||||
func matchInnerCodeItemsWithEvidence(stall, sourceSKURaw string, specMatches []syb.DetailItem) ([]syb.DetailItem, string) {
|
||||
sourceSKU := normalizeInnerCodeSourceSKU(sourceSKURaw)
|
||||
if sourceSKU != "" {
|
||||
sourceMatches := make([]syb.DetailItem, 0)
|
||||
for _, item := range specMatches {
|
||||
if normalizeInnerCodeSourceSKU(innerCodeRawText(item.Raw["sku"])) == sourceSKU ||
|
||||
normalizeInnerCodeSourceSKU(innerCodeRawText(item.Raw["variationSku"])) == sourceSKU {
|
||||
sourceMatches = append(sourceMatches, item)
|
||||
}
|
||||
}
|
||||
if len(sourceMatches) > 1 {
|
||||
return nil, "原始 SKU 候选重复,不能自动选择"
|
||||
}
|
||||
if len(sourceMatches) == 1 {
|
||||
stallMatches := filterInnerCodeItemsByStallStrict(specMatches, stall)
|
||||
if len(stallMatches) > 1 {
|
||||
return nil, "档口货号候选重复,不能自动选择"
|
||||
}
|
||||
if len(stallMatches) == 1 && stallMatches[0].ID != sourceMatches[0].ID {
|
||||
return nil, "原始 SKU 与档口货号冲突,不能自动选择"
|
||||
}
|
||||
return sourceMatches, ""
|
||||
}
|
||||
}
|
||||
return filterInnerCodeItemsByStall(specMatches, stall), ""
|
||||
}
|
||||
|
||||
func filterInnerCodeItemsByStall(items []syb.DetailItem, stall string) []syb.DetailItem {
|
||||
@@ -362,6 +398,20 @@ func filterInnerCodeItemsByStall(items []syb.DetailItem, stall string) []syb.Det
|
||||
return matched
|
||||
}
|
||||
|
||||
func filterInnerCodeItemsByStallStrict(items []syb.DetailItem, stall string) []syb.DetailItem {
|
||||
stall = strings.TrimSpace(stall)
|
||||
if stall == "" {
|
||||
return nil
|
||||
}
|
||||
matched := make([]syb.DetailItem, 0)
|
||||
for _, item := range items {
|
||||
if innerCodeStallMatches(stall, item) {
|
||||
matched = append(matched, item)
|
||||
}
|
||||
}
|
||||
return matched
|
||||
}
|
||||
|
||||
func innerCodeStallMatches(stall string, item syb.DetailItem) bool {
|
||||
sku := innerCodeRawText(item.Raw["sku"])
|
||||
variation := innerCodeRawText(item.Raw["variationSku"])
|
||||
|
||||
Reference in New Issue
Block a user