fix(admin): 回流接口校验/规范化 GTIN #36

Merged
lixu merged 1 commits from devin/1782352663-backflow-gtin-validate into main 2026-06-25 10:00:29 +08:00
+15 -2
View File
@@ -6,6 +6,7 @@ import (
"errors" "errors"
"strings" "strings"
"github.com/baicai2026-baicai/goods/api/internal/gtin"
"github.com/jackc/pgx/v5" "github.com/jackc/pgx/v5"
) )
@@ -76,8 +77,20 @@ func (s *Store) CreateBackflowSubmissions(ctx context.Context, items []Submissio
if g == "" { if g == "" {
in.GTIN = nil in.GTIN = nil
} else { } else {
in.GTIN = &g // Validate/normalize so a malformed barcode is reported as an
res.GTIN = &g // invalid item instead of aborting the batch (the gtin column
// is varchar(14) and only GS1 codes are archived).
norm, err := gtin.Normalize(g)
if err != nil {
res.GTIN = &g
res.Status = "invalid"
res.Reason = err.Error()
sum.Invalid++
sum.Results = append(sum.Results, res)
continue
}
in.GTIN = &norm
res.GTIN = &norm
} }
} }