- 出入库记录(库存流水):新增 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 为本地生成、不入库)
67 lines
3.3 KiB
JavaScript
67 lines
3.3 KiB
JavaScript
'use strict';
|
||
|
||
/**
|
||
* 出库单「运单号集合」列改名:outbound_orders.express_codes → waybill_codes(并回填存量)
|
||
*
|
||
* 背景(命名冲突,2026-09-14 核对 WMS 源码发现):
|
||
* WMS `wms_order_stockout` 的列口径是
|
||
* express_code / express_name → **快递公司**编码/名称(回传为 logisticsCode/logisticsName)
|
||
* waybill_code / waybill_codes → **运单号**(单个 / 列表,支持多包裹)
|
||
* express_codes → 已废弃(注释:@deprecated 运单号列表,请使用 waybill_codes)
|
||
* OMS 出库单此前把「运单号集合」放在 `express_codes`,与 WMS 现行命名正好撞车 ——
|
||
* 一旦同表再加上 `express_code`(快递公司编码,见 20260915001600 迁移),
|
||
* `express_code`(快递公司) 与 `express_codes`(运单号集合) 并存就是 WMS 自己已经废弃的那个坑,故改名对齐。
|
||
*
|
||
* 本迁移做三件事(幂等,可重复执行):
|
||
* ① outbound_orders.express_codes → waybill_codes(列重命名)
|
||
* ② 回填 outbound_orders.waybill_codes:历史单的列还是 NULL,但确认摘要 JSON 里已有运单号列表
|
||
* (兼容旧键 confirm.express_codes 与新键 confirm.waybill_codes)
|
||
* ③ 回填 order_deliveries.express_codes:发货单只有一个运单号列(express_code),
|
||
* 多值列为空时按单元素数组补齐,保证两列口径一致
|
||
*
|
||
* 注:`order_deliveries.express_codes` **不改名** —— 该表没有 WMS 对应列(wms_order_delivery 只有
|
||
* express_code=面单号),且本表内 express_code(运单号) / express_codes(运单号集合) 是自洽的单值/多值对。
|
||
*/
|
||
module.exports = {
|
||
async up(queryInterface) {
|
||
const outbound = await queryInterface.describeTable('outbound_orders');
|
||
|
||
// ① 列重命名
|
||
if (outbound.express_codes && !outbound.waybill_codes) {
|
||
await queryInterface.renameColumn('outbound_orders', 'express_codes', 'waybill_codes');
|
||
}
|
||
|
||
// ② 出库单回填:从确认摘要 JSON 取(先新键后旧键)
|
||
await queryInterface.sequelize.query(`
|
||
UPDATE outbound_orders
|
||
SET waybill_codes = COALESCE(
|
||
JSON_EXTRACT(wms_push_result, '$.confirm.waybill_codes'),
|
||
JSON_EXTRACT(wms_push_result, '$.confirm.express_codes')
|
||
)
|
||
WHERE waybill_codes IS NULL
|
||
AND wms_push_result IS NOT NULL
|
||
AND COALESCE(
|
||
JSON_EXTRACT(wms_push_result, '$.confirm.waybill_codes'),
|
||
JSON_EXTRACT(wms_push_result, '$.confirm.express_codes')
|
||
) IS NOT NULL
|
||
`);
|
||
|
||
// ③ 发货单回填:单值 express_code → [express_code]
|
||
await queryInterface.sequelize.query(`
|
||
UPDATE order_deliveries
|
||
SET express_codes = JSON_ARRAY(express_code)
|
||
WHERE express_codes IS NULL
|
||
AND express_code IS NOT NULL
|
||
AND express_code <> ''
|
||
`);
|
||
},
|
||
|
||
async down(queryInterface) {
|
||
const outbound = await queryInterface.describeTable('outbound_orders');
|
||
if (outbound.waybill_codes && !outbound.express_codes) {
|
||
await queryInterface.renameColumn('outbound_orders', 'waybill_codes', 'express_codes');
|
||
}
|
||
// 回填属数据修正,不反向撤销(撤销只会丢掉运单号,无业务意义)
|
||
},
|
||
};
|