oms/backend/database/migrations/20260915001800-backfill-waybill-codes-single-package.js
liufumingren 39c19a4de7 feat(backend): 出入库记录与库存锁定链路、出库单快递/收件人与推送队列
- 出入库记录(库存流水):新增 stock_records 表/模型/只读接口(列表 + 业务动作选项)与「出入库记录」菜单;
  库存变动统一收敛到 app/utils/stockRecord.js#applyStockChange,与流水写入同事务(含变动前后总/锁定/可用数量)
- 发货单:审核(1→2) 按明细锁定库存、发货确认(3→4) 扣减、推送失败退回/驳回/取消/作废释放(新增 stock_locked 列);
  恢复(9→1) 时曾推送过的单据换号(WMS 取消后原单号仍被占用,沿用旧号重推会被判「订单已存在」)
- 出库单:新增快递(express_code/express_name)、收件人(receiver_*) 与多运单号(express_codes) 字段;
  推送报文补齐 logisticsCode/receiverInfo;新增出库单推送服务与定时任务
- 快递:多运单号回填、仓库快递映射(warehouse_express_mappings) 与快递字典补录等迁移
- 契约:补充出入库记录、出库单快递/收件人等定义(swagger.json 为本地生成、不入库)
2026-09-14 00:59:23 +08:00

34 lines
1.6 KiB
JavaScript
Raw 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.

'use strict';
/**
* 出库单运单号补充回填:从确认摘要的「单值运单号」补齐 waybill_codes
*
* 背景:`20260915001700` 的回填只认摘要 JSON 里的运单号**列表**(confirm.waybill_codes /
* confirm.express_codes 两个键),但 20260915001400~01700 之间写的早期摘要里只有根节点
* **单值** `confirm.express_code`(当时还没有列表键),这些单的 `waybill_codes` 仍未回填。
*
* 回填规则(只在能确认「运单号集合完整」时才写,避免以偏概全):
* 摘要 `confirm.packages` 数组**恰好 1 个包裹**,且根节点 `confirm.express_code` 非空
* → waybill_codes = [ 该单值运单号 ](唯一包裹即全部运单号)
* 多包裹的历史摘要若缺列表键则不动(信息不全,宁可留空等 WMS 重推时由回调补写)。
*
* 幂等:只更新 waybill_codes IS NULL 的行;可重复执行。
*/
module.exports = {
async up(queryInterface) {
await queryInterface.sequelize.query(`
UPDATE outbound_orders
SET waybill_codes = JSON_ARRAY(JSON_UNQUOTE(JSON_EXTRACT(wms_push_result, '$.confirm.express_code')))
WHERE waybill_codes IS NULL
AND wms_push_result IS NOT NULL
AND JSON_LENGTH(JSON_EXTRACT(wms_push_result, '$.confirm.packages')) = 1
AND JSON_EXTRACT(wms_push_result, '$.confirm.express_code') IS NOT NULL
AND JSON_UNQUOTE(JSON_EXTRACT(wms_push_result, '$.confirm.express_code')) <> ''
`);
},
async down() {
// 回填属数据修正,不反向撤销(撤销只会丢掉运单号,无业务意义)
},
};