diff --git a/api/internal/adminstore/backflow.go b/api/internal/adminstore/backflow.go index a6fcbcb..ccac9a2 100644 --- a/api/internal/adminstore/backflow.go +++ b/api/internal/adminstore/backflow.go @@ -6,6 +6,7 @@ import ( "errors" "strings" + "github.com/baicai2026-baicai/goods/api/internal/gtin" "github.com/jackc/pgx/v5" ) @@ -76,8 +77,20 @@ func (s *Store) CreateBackflowSubmissions(ctx context.Context, items []Submissio if g == "" { in.GTIN = nil } else { - in.GTIN = &g - res.GTIN = &g + // Validate/normalize so a malformed barcode is reported as an + // 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 } }