Files
SupplierSystem/migrations/20261022_main_system_actual_qty_requests.sql
Ubuntu aa2db57b0f
CI / server typecheck + tests (push) Canceled after 0s
CI / web typecheck + tests + miniprogram syntax (push) Canceled after 0s
CI / eslint (观察项,C7 骨架) (push) Canceled after 0s
CI / npm audit (critical 硬拦) (push) Canceled after 0s
feat(main-system): 免入库单取货链路 + 实收数量「事实登记 + 事后同步」
免入库(主系统骑手上门取货):
- 50 展示「待取货」、副文案「待主系统骑手上门取货」、不建我方配送任务(守卫与开关解耦)
- 我方 50 即回写备货完成;两开关(SKIP_INBOUND_AWAIT_PICKUP / FULFILLMENT_EVENTS)改默认开

核货事实镜像(「核货完毕」标记):
- 按主系统 lookup 的 actual_qty 落台账,新增 GET/POST /orders/:orderCode/main-system-prep-facts[/refresh]
- 详情行内显示「核货完毕」(含核货量),分配对账兜底刷新

实收数量/单位口径变更(对方先改 + 我方事后同步):
- 台账加 applied_at;inbound 与 picking_check 同为事实登记(驳回不回滚)
- 同意才落我方值:免入库改装车核货量、送仓改验收实收(已入库走既有库存调整)、已结算/已结案只留痕
- 计划量与金额一起改,并同步结算投影(syncStatementsForOrderSafe)
- 审核页语义改「主系统实际值(已生效)/ 是否同步」+ 已处理历史(双方时间与落值结论)

台账对照与回写修复:
- 行级对照改整单一次性(同名商品不再重复认领)+ 存量纠正 healOrderPrepMapping
- 堵住客户绑定回填旁路(免入库单不再被派我方骑手)
- 回写触发函数改对象参数(修 branch/order 传反导致的静默不回写)

文档:设计文档 4 篇 +《给主系统 AI 的对接改造清单》§2.9(第六批契约)

回归:服务端全量与 HEAD 基线一致(24 个失败文件同集合);前端 140 文件 / 699 测试全绿;tsc 双端干净
2026-10-09 21:52:17 +08:00

59 lines
2.8 KiB
SQL
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
-- 跨系统「实收数量 / 单位」申请台账(**对方发起、我方审核**方向)
--
-- 背景(开发者 2026-10-11 定稿;主系统提交 b8519fbb 已交付):
-- · 核货节点:主系统核货值是**事实登记**(先落库)⇒ 发申请告知我方,我方通过即对齐、驳回**不回滚**;
-- · order_status >= 60(配送中及以后)改实收/单位、>= 90 改成本价 ⇒ **先审后改**(pending 期间两边都不落库);
-- · 事件:`preparations.actual_qty_request`(收) / `preparations.actual_qty_decided`(对方结果回执);
-- · 决策回传:我方调 `POST /api/supplier/preparations/actual-qty-decision`。
--
-- 与 `main_system_price_qty_requests`(**我方发起、对方审**)**方向相反、各自一张表**,互不覆盖。
-- 设计文档:docs/design/20261011-跨系统改价改量审核.md
CREATE TABLE IF NOT EXISTS public.main_system_actual_qty_requests (
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
branch_code varchar(64) NOT NULL,
-- 主系统申请行 id(对方生成,幂等键)
request_id varchar(128) NOT NULL,
prep_id uuid,
order_code varchar(128),
our_order_code varchar(128),
sku_code varchar(120),
-- 触发节点:picking_check(核货)| admin_received_qty(对方管理端)| post_complete_price(完结后成本价)
node varchar(40) NOT NULL,
-- 变更字段:qty(实收数量)| unit(单位)| price(成本价,仅 post_complete_price)
field varchar(16) NOT NULL,
before_value numeric,
proposed_value numeric,
before_unit varchar(32),
unit varchar(32),
operator varchar(120),
reason text,
client_request_id varchar(160),
status varchar(16) NOT NULL DEFAULT 'pending',
final_value numeric,
reviewer varchar(120),
decided_at timestamptz,
decision_reason text,
-- 核货节点=事实登记(驳回不回滚);>=60/>=90=先审后改
fact_registered boolean NOT NULL DEFAULT false,
payload jsonb,
created_at timestamptz NOT NULL DEFAULT NOW(),
updated_at timestamptz NOT NULL DEFAULT NOW(),
CONSTRAINT main_system_actual_qty_requests_status_check
CHECK (status IN ('pending', 'approved', 'rejected', 'superseded')),
CONSTRAINT main_system_actual_qty_requests_field_check
CHECK (field IN ('qty', 'unit', 'price'))
);
-- 幂等:同一分公司内,对方同一申请行只落一条
CREATE UNIQUE INDEX IF NOT EXISTS uq_main_system_actual_qty_requests_request
ON public.main_system_actual_qty_requests (branch_code, request_id);
-- 待审队列
CREATE INDEX IF NOT EXISTS idx_main_system_actual_qty_requests_pending
ON public.main_system_actual_qty_requests (branch_code, status, created_at DESC);
-- 按备货行/我方订单回查
CREATE INDEX IF NOT EXISTS idx_main_system_actual_qty_requests_prep
ON public.main_system_actual_qty_requests (branch_code, prep_id);