feat(admin): 新增 /api/import/bypos 导入接口(修复采集器导入失败) #33
Reference in New Issue
Block a user
Delete Branch "devin/1782307670-bypos-import-endpoint"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
背景
采集器(bypos-collector)的「④ 导入到 Goods 系统」功能会把 JSONL 数据 POST 到后台
/api/import/bypos,但该后端接口此前只存在于未合并分支 b08495b,生产没有,导致后台返回 404 文本页,浏览器JSON.parse报「unexpected character at line 1 column 1」。改动
从
b08495b引入两份后端文件并注册路由(纯新增,不改动既有代码/接口):api/internal/adminstore/import_bypos.go:ByposRecord解析 + 事务化批量 upsert(按 GTINON CONFLICT),写入 manufacturer / MSRP / product_barcode / product_source 溯源,并按记录重算质量分;仅导入status=hit且有名称的记录。api/internal/adminhandler/import_bypos.go:ImportBypos处理器,流式解析 NDJSON,返回{loaded, skipped, errored},空请求返回 400。handler.go:在鉴权路由组注册POST /api/import/bypos。本地验证(临时 Postgres,迁移至 v13)
{"loaded":2,"skipped":1,"errored":0}。go build ./...、go vet、gofmt全部通过。