Merge pull request 'fix(admin): 回流接口校验/规范化 GTIN' (#36) from devin/1782352663-backflow-gtin-validate into main
This commit was merged in pull request #36.
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user