fix(audit-20261019): T1-T9 审计修复、存储归属与审计日志列宽
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

- T1 资金/库存/报价/自采 P1(BIZ-1/2/3/4/10/13/14)
- T2 主系统反向事件墓碑/改派/孤儿处理(BIZ-6/8/9)
- T3 选分公司 ticket、trust proxy、角色权限收口(SEC-2/3/4)
- T4 缺列/RLS/tenant 名单/FK/迁移执行器(DATA-1..8)
- T5 401 登出/分页/映射口径/blob/ZIP 中文名(FE-1..4/BIZ-15)
- T6 测试脚本目标守卫/config fail-fast/容器配置(OPS-2..8)
- T7 前后端测试与 lint 门禁清零
- T8 应付卡片按关联订单日(口径 A)
- T9 存储对象全链路归属校验、敏感列禁写、审计 target_id 超长修复
This commit is contained in:
Ubuntu
2026-10-19 16:16:51 +08:00
parent 601a207b1e
commit 5fa2bbfd55
252 changed files with 18656 additions and 721 deletions
@@ -123,3 +123,39 @@ export async function sumActiveReservationsForOrders(
return Math.round((Number(r.rows[0]?.total) || 0) * 1000) / 1000;
}
/**
* 领料可扣量切分:**他单预留 = 全部在用预留 − 本单自己的在用预留**(一次成型)。
*
* 旧写法对每个本单订单号各调一次 `sumOtherOrderReservations` 再相加,而该函数每次只排除
* **一个** order_code ⇒ 同一需求单含 A、B 两张订单时,他单预留被算 N 倍(见
* `processingPickOwnReservationMultiOrder.test.ts` ①)。本函数只读、不产生写语句;
* `orderCodes` 为空(自采/独立加工)时他单 = 全部在用预留,且省掉 own 查询。
*/
export async function resolveProcessingPickReservationSplit(
db: Db,
input: { orderCodes: string[]; skuCode: string; branchCode?: string | null }
): Promise<{ totalReserved: number; ownReserved: number; otherReserved: number }> {
const sku = String(input.skuCode || '').trim();
const codes = Array.from(
new Set((input.orderCodes || []).map((c) => String(c || '').trim()).filter(Boolean))
);
const branch = String(input.branchCode || '').trim() || null;
if (!sku) return { totalReserved: 0, ownReserved: 0, otherReserved: 0 };
const totalRow = await db.query(
`SELECT COALESCE(SUM(qty), 0)::float AS total
FROM inventory_reservations
WHERE sku_code = $1
AND status = 10
AND ($2::text IS NULL OR branch_code IS NULL OR branch_code = $2)`,
[sku, branch]
);
const totalReserved = Math.round((Number(totalRow.rows[0]?.total) || 0) * 1000) / 1000;
const ownReserved = codes.length
? await sumActiveReservationsForOrders(db, { orderCodes: codes, skuCode: sku, branchCode: branch })
: 0;
const otherReserved = Math.max(
0,
Math.round((totalReserved - ownReserved) * 1000) / 1000
);
return { totalReserved, ownReserved, otherReserved };
}