← 回到冰箱

Amazon Ops · DEMO

补货审批工作流

用一组预设补货文件演示从导出到人工确认,再到两份结果成对校验的完整链路。

自动化最危险的地方,是它不知道自己该停

你敢让它自己跑吗?

18 行合成数据3 个异常埋在里面

补货会花掉真钱。程序能算建议,但不该替人确认范围。先选择是否保留这道闸门。

打开透明层:查看判断依据与源码
校验是怎么做的范围 + 数量两道断言

审批表和发货表必须包含完全相同的 SKU 范围,逐项数量也必须守住确认结果。

assert set(approval.sku) == set(shipping.sku)
assert sum(approval.qty) == sum(shipping.qty)
为什么先写临时目录成对发布或全部撤销

两份文件先在临时目录完成并互相校验,全部通过后才一起发布。

temp = create_temporary_output_dir()
write_pair(temp)
validate_pair(temp)
publish_pair(temp)

完整处理顺序

01batch = load_batch('examples/batch.json')# 读取合成补货批次,不接触访客文件
02source_files = discover_workbooks(batch.input_dir)# 定位导出、库存和审批模板
03source_files = reject_temporary_files(source_files)# 忽略锁文件与未完成下载
04rows = validate_schema(batch['rows'])# 检查 SKU 与数量字段
05rows = normalize_headers_and_whitespace(rows)# 统一字段别名并清理不可见字符
06rows = filter_marketplace(rows, market='US')# 只保留明确目标站点
07index = build_exact_sku_index(rows)# 建立精确索引,拒绝模糊匹配
08assert_no_duplicate_skus(index)# 重复 SKU 在正式生成前阻断
09candidates = preview_replenishment(index)# 此时只生成候选范围
10exceptions = collect_blocking_exceptions(candidates)# 集中展示缺失库存与异常数量
11confirmed = await_operator_confirmation(candidates)# 在业务判断点暂停
12confirmed = lock_confirmed_scope(confirmed)# 确认后冻结本批商品范围
13workspace = create_temporary_output_dir()# 先在临时目录生成,避免半成品
14approval = write_approval(confirmed)# 写入审批结果
15shipment = write_shipment(confirmed)# 同步写入发货结果
16assert_same_scope(approval, shipment)# 两份结果必须包含相同 SKU
17assert_quantity_conservation(approval, shipment)# 回读并验证数量守恒
18publish_pair(workspace, output_dir)# 全部通过后一次性交付两份结果
查看 GitHub 源码
换一组数据再试一次