feat(ingestion): import bypos-collector JSONL into goods #20
Reference in New Issue
Block a user
Delete Branch "devin/1782268418-bypos-importer"
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?
Summary
新增「采集器 JSONL → goods/天工库」的导入链路,把
tools/bypos-collector采到的中心库商品档案入库。只导入status=hit的记录,按 GTIN 去重 upsert,重复导入幂等。本地用 docker postgres(全部迁移)实测 49 项测试全过,并端到端导入实采的 demo/products JSONL 验证。改动
adapters/bypos.py— 新增纯函数transform_bypos(rec):把采集器一行 JSONL 转成内部 product 形状。barcode→gtin(校验 EAN 校验位);name→name;spec仅当能解析为质量/体积(如500mL/5kg)时填net_content,否则原样留在attributes.spec(20支/1X24这类计数规格不污染净含量);unit/area/license/in_price/sell_price存入attributes;sell_price>0 → msrp;country_of_origin="中国",产地省市留attributes.origin_area。etl/load.py— 新增ensure_bypos_source/load_bypos_record(_safe)与_ensure_manufacturer。food_detail;product_source按 source 删后插,故重复导入不产生重复行;attributes = product.attributes || EXCLUDED.attributes(合并而非覆盖)。jobs/import_bypos.py— CLI:python -m opengoods.jobs.import_bypos --input products.jsonl [--limit N] [--dsn ...],支持.jsonl/.jsonl.gz。tests/test_bypos.py— transform 纯函数用例 + DB roundtrip(无库自动跳过)+ 幂等校验。tools/bypos-collector/README.md— 补充导入用法与字段映射。实测
入库结果(节选):
6920459905012 康师傅冰红茶490ml | 490ml | 中国 | 瓶 | 浙江杭州 | MSRP 3.00。来源记为bypos中心库,带字段级 provenance。注:
bypos中心库为厂商目录数据(非开放许可),source.license 标为proprietary,公开站对外展示/导出需注意来源约束。