fix: 使用原始SKU辅助档口匹配 (#259)
This commit is contained in:
@@ -19,10 +19,11 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
MaxInnerCodeUploadBytes = 10 * 1024 * 1024
|
||||
MaxInnerCodeImportRows = 5000
|
||||
MaxInnerCodeValueRunes = 128
|
||||
innerCodeSheetName = "标签入库码映射"
|
||||
MaxInnerCodeUploadBytes = 10 * 1024 * 1024
|
||||
MaxInnerCodeImportRows = 5000
|
||||
MaxInnerCodeValueRunes = 128
|
||||
MaxInnerCodeSourceSKURunes = 500
|
||||
innerCodeSheetName = "标签入库码映射"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -270,6 +271,7 @@ func parseInnerCodeRows(rows *excelize.Rows, originalFilename, actorUserID strin
|
||||
specRaw := strings.ReplaceAll(innerCodeCell(columns, specColumn), "\r", " ")
|
||||
specRaw = strings.TrimSpace(strings.ReplaceAll(specRaw, "\n", " "))
|
||||
stall := innerCodeStall(columns, headers)
|
||||
sourceSKURaw := innerCodeRawNamedCell(columns, headers, "原始SKU")
|
||||
shop := innerCodeNamedCell(columns, headers, "店铺名称")
|
||||
printSequence := 0
|
||||
if raw := innerCodeNamedCell(columns, headers, "标签打印序号"); raw != "" {
|
||||
@@ -277,7 +279,7 @@ func parseInnerCodeRows(rows *excelize.Rows, originalFilename, actorUserID strin
|
||||
printSequence = value
|
||||
}
|
||||
}
|
||||
if err := validateInnerCodeFields(rowNumber, orderNumber, shop, stall, specRaw, innerCode); err != nil {
|
||||
if err := validateInnerCodeFields(rowNumber, orderNumber, shop, stall, sourceSKURaw, specRaw, innerCode); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
specKey := NormalizeInnerCodeSpecKey(specRaw)
|
||||
@@ -285,7 +287,8 @@ func parseInnerCodeRows(rows *excelize.Rows, originalFilename, actorUserID strin
|
||||
parsed = append(parsed, innerCodeParsedRow{InnerCodeImportRow: model.InnerCodeImportRow{
|
||||
BusinessDate: businessDate, SourceRow: rowNumber, PrintSequence: printSequence,
|
||||
OrderNumber: orderNumber, ShopName: shop, Stall: stall, SpecRaw: specRaw,
|
||||
SpecKey: specKey, InnerCode: innerCode, SourceDuplicateCount: 1,
|
||||
SourceSKURaw: sourceSKURaw,
|
||||
SpecKey: specKey, InnerCode: innerCode, SourceDuplicateCount: 1,
|
||||
CreatedByUserID: actorUserID,
|
||||
}, businessKey: key})
|
||||
}
|
||||
@@ -318,6 +321,20 @@ func parseInnerCodeRows(rows *excelize.Rows, originalFilename, actorUserID strin
|
||||
seen[original.businessKey] = true
|
||||
group := groups[original.businessKey]
|
||||
row := original.InnerCodeImportRow
|
||||
var sourceSKUCompare string
|
||||
for _, member := range group {
|
||||
candidate := normalizeInnerCodeSourceSKU(member.SourceSKURaw)
|
||||
if candidate == "" {
|
||||
continue
|
||||
}
|
||||
if sourceSKUCompare != "" && candidate != sourceSKUCompare {
|
||||
return nil, nil, fmt.Errorf("第 %d 行起的同业务键包含不同原始 SKU,请拆分或修正源数据", row.SourceRow)
|
||||
}
|
||||
if sourceSKUCompare == "" {
|
||||
sourceSKUCompare = candidate
|
||||
row.SourceSKURaw = member.SourceSKURaw
|
||||
}
|
||||
}
|
||||
codes := make([]string, 0, len(group))
|
||||
seenCodes := make(map[string]bool, len(group))
|
||||
for _, member := range group {
|
||||
@@ -389,6 +406,10 @@ func innerCodeHeaderMap(columns []string) (map[string]int, int) {
|
||||
for index, raw := range columns {
|
||||
name := strings.TrimSpace(raw)
|
||||
result[name] = index
|
||||
compactName := strings.ToLower(innerCodeSpaces.ReplaceAllString(name, ""))
|
||||
if strings.HasPrefix(compactName, "原始sku") {
|
||||
result["原始SKU"] = index
|
||||
}
|
||||
if name == "清洗后规格" || (specColumn < 0 && strings.HasPrefix(name, "原始产品规格")) {
|
||||
specColumn = index
|
||||
}
|
||||
@@ -416,6 +437,18 @@ func innerCodeNamedCell(columns []string, headers map[string]int, name string) s
|
||||
return innerCodeCell(columns, index)
|
||||
}
|
||||
|
||||
func innerCodeRawNamedCell(columns []string, headers map[string]int, name string) string {
|
||||
index, ok := headers[name]
|
||||
if !ok || index < 0 || index >= len(columns) {
|
||||
return ""
|
||||
}
|
||||
return columns[index]
|
||||
}
|
||||
|
||||
func normalizeInnerCodeSourceSKU(value string) string {
|
||||
return strings.TrimSpace(value)
|
||||
}
|
||||
|
||||
func innerCodeCell(columns []string, index int) string {
|
||||
if index < 0 || index >= len(columns) {
|
||||
return ""
|
||||
@@ -423,7 +456,7 @@ func innerCodeCell(columns []string, index int) string {
|
||||
return strings.TrimSpace(columns[index])
|
||||
}
|
||||
|
||||
func validateInnerCodeFields(row int, order, shop, stall, spec, code string) error {
|
||||
func validateInnerCodeFields(row int, order, shop, stall, sourceSKU, spec, code string) error {
|
||||
if strings.Contains(code, ",") {
|
||||
return fmt.Errorf("第 %d 行内部档口入库码不能包含英文逗号", row)
|
||||
}
|
||||
@@ -437,6 +470,7 @@ func validateInnerCodeFields(row int, order, shop, stall, spec, code string) err
|
||||
max int
|
||||
}{
|
||||
{"Shopee订单编号", order, 64}, {"店铺名称", shop, 191}, {"档口及货号", stall, 191},
|
||||
{"原始 SKU", sourceSKU, MaxInnerCodeSourceSKURunes},
|
||||
{"规格", spec, 500}, {"内部档口入库码", code, MaxInnerCodeValueRunes},
|
||||
} {
|
||||
if utf8.RuneCountInString(field.value) > field.max {
|
||||
|
||||
Reference in New Issue
Block a user