- 出入库记录(库存流水):新增 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 为本地生成、不入库)
51 lines
2.9 KiB
JavaScript
51 lines
2.9 KiB
JavaScript
'use strict';
|
||
|
||
/**
|
||
* 仓库快递映射表 warehouse_express_mappings
|
||
*
|
||
* 背景:外部(WMS 等)回传的快递编码不一定是 OMS/标准编码,可能是仓库维度的「自定义编码」
|
||
* (对齐 WMS `wms_express_setting`:`code`=业务自定义编码如 SF.KY/KYSF,`express_code`=系统标准编码)。
|
||
* 出库确认(stockout.confirm)/ 发货确认(deliveryorder.confirm)回传时按以下顺序解析:
|
||
* ① 命中本表映射(warehouse_id + custom_code)→ 用映射到的「默认快递编码」;
|
||
* ② 未命中映射 → 外部编码若本身就在快递公司字典(express_companies)里,直接兜底使用;
|
||
* ③ 两者都没有 → 报错「外部传入的快递编码(xxx)没有关联映射,请到 OMS 外部仓库完成映射配置」。
|
||
*
|
||
* 幂等:showTable 判断表是否存在。
|
||
*/
|
||
module.exports = {
|
||
async up(queryInterface, Sequelize) {
|
||
const tables = await queryInterface.showAllTables();
|
||
const exists = tables
|
||
.map(t => (typeof t === 'string' ? t : (t.tableName || t.TABLE_NAME)))
|
||
.includes('warehouse_express_mappings');
|
||
if (exists) return;
|
||
|
||
const { BIGINT, STRING, TINYINT, DATE } = Sequelize;
|
||
await queryInterface.createTable('warehouse_express_mappings', {
|
||
id: { type: BIGINT.UNSIGNED, primaryKey: true, autoIncrement: true, comment: '主键' },
|
||
principal_id: { type: BIGINT.UNSIGNED, allowNull: false, comment: '所属主体ID(冗余仓库主体,便于隔离)' },
|
||
warehouse_id: { type: BIGINT.UNSIGNED, allowNull: false, comment: '仓库ID(关联 warehouses,映射按仓库维度)' },
|
||
express_code: { type: STRING(50), allowNull: false, comment: '默认快递编码(OMS/标准编码,关联 express_companies.code,如 SF/ZT)' },
|
||
custom_code: { type: STRING(50), allowNull: false, comment: '自定义编码(外部传入的快递编码,如 SF.KY/KYSF)' },
|
||
status: { type: TINYINT, allowNull: false, defaultValue: 1, comment: '状态:1启用 0禁用(仅启用参与回传解析)' },
|
||
remark: { type: STRING(255), allowNull: true, comment: '备注' },
|
||
created_at: { type: DATE, allowNull: true, comment: '创建时间' },
|
||
updated_at: { type: DATE, allowNull: true, comment: '更新时间' },
|
||
}, {
|
||
comment: '仓库快递映射表(外部快递编码 → OMS 默认快递编码)',
|
||
indexes: [
|
||
{ name: 'uk_wem_warehouse_custom', unique: true, fields: [ 'warehouse_id', 'custom_code' ] },
|
||
{ name: 'idx_wem_principal_warehouse', fields: [ 'principal_id', 'warehouse_id' ] },
|
||
],
|
||
});
|
||
},
|
||
|
||
async down(queryInterface) {
|
||
const tables = await queryInterface.showAllTables();
|
||
const exists = tables
|
||
.map(t => (typeof t === 'string' ? t : (t.tableName || t.TABLE_NAME)))
|
||
.includes('warehouse_express_mappings');
|
||
if (exists) await queryInterface.dropTable('warehouse_express_mappings');
|
||
},
|
||
};
|