WMS_MAIN/database/migrations/20260813140000-add-order-delivery-base-table-missing-columns.js
liufumingren 38b29be776 feat: 新增退回拆包模块(returnUnpack)与序列表原子取号
- 新增 wms_return_unpack 主表/明细/视频 与 wms_return_query_log 表(model + 迁移)
- 新增序列表 wms_number_sequence,单号取号改为 INSERT...ON DUPLICATE KEY 原子递增(含历史 seed 对齐)
- 补齐 wms_order_delivery 基表缺失 25 列(修复 Unknown column)
- 权限固定 ID 540-549 + 角色授权迁移
- 修复 returnReceived.create 出参 record 包装;修复 afterSale 发件人查询列名(name→company_name)
- detail 接口按设计走 548 权限校验
2026-08-13 21:40:50 +08:00

119 lines
5.7 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';
/**
* 补齐 wms_order_delivery 基表相对模型缺失的 25 列。
*
* 背景:app/model/order_delivery.js 声明 92 个字段,但基表只有 67 列,
* 缺列导致按模型全字段 SELECT(如 afterSale._resolveOrderDetail 先查基表)时
* 报 Unknown column 'extend_props' 等错误。
* 分表(wms_order_delivery_100000 等)均已有这些列,本迁移以分表结构为参照补齐基表。
*
* 修复后 afterSale._resolveOrderDetail 查基表不再抛错(查无数据时回退工厂分表)。
*/
const TABLE_NAME = 'wms_order_delivery';
/** 缺失列定义(类型/是否可空/默认值/注释),与分表结构一致 */
const MISSING_COLUMNS = [
{ name: 'extend_props', type: 'JSON', allowNull: true, defaultValue: null, comment: '订单扩展属性' },
{ name: 'create_channel', type: 'STRING(20)', allowNull: false, defaultValue: 'MANUAL', comment: '创建来源渠道' },
{ name: 'sys_platform_code', type: 'STRING(50)', allowNull: true, defaultValue: null, comment: '系统平台编码' },
{ name: 'sys_platform_name', type: 'STRING(200)', allowNull: true, defaultValue: null, comment: '系统平台名称' },
{ name: 'buyer_message', type: 'STRING(500)', allowNull: true, defaultValue: null, comment: '买家留言' },
{ name: 'seller_message', type: 'STRING(500)', allowNull: true, defaultValue: null, comment: '卖家留言' },
{ name: 'remark', type: 'STRING(500)', allowNull: true, defaultValue: null, comment: '备注' },
{ name: 'sys_logistics_code', type: 'STRING(50)', allowNull: true, defaultValue: null, comment: '系统物流公司编码' },
{ name: 'sys_logistics_name', type: 'STRING(200)', allowNull: true, defaultValue: null, comment: '系统物流公司名称' },
{ name: 'basket_number', type: 'STRING(50)', allowNull: true, defaultValue: null, comment: '筐号' },
{ name: 'from_key', type: 'INTEGER(11)', allowNull: true, defaultValue: null, comment: '来源键' },
{ name: 'items', type: 'TEXT', allowNull: true, defaultValue: null, comment: '商品JSON字符串' },
{ name: 'items_count', type: 'SMALLINT(5).UNSIGNED', allowNull: false, defaultValue: 0, comment: '商品种类数' },
{ name: 'items_total', type: 'INTEGER(10).UNSIGNED', allowNull: false, defaultValue: 0, comment: '商品总数' },
{ name: 'items_weight', type: 'INTEGER(11)', allowNull: false, defaultValue: 0, comment: '总重量(g)' },
{ name: 'items_hash', type: 'CHAR(32)', allowNull: false, defaultValue: '', comment: 'MD5哈希值(32位)' },
{ name: 'items_crc', type: 'INTEGER(10).UNSIGNED', allowNull: false, defaultValue: 0, comment: 'CRC32校验码' },
{ name: 'wave_id', type: 'BIGINT(20)', allowNull: false, defaultValue: 0, comment: '波次ID,0表示未分配' },
{ name: 'wave_no', type: 'STRING(50)', allowNull: false, defaultValue: '', comment: '波次号,空字符串表示未分配' },
{ name: 'wave_strategy_version', type: 'INTEGER(10)', allowNull: false, defaultValue: 0, comment: '波次策略版本号' },
{ name: 'wave_scan_result', type: 'INTEGER(10)', allowNull: false, defaultValue: 0, comment: '波次扫描结果,0未扫描' },
{ name: 'sended_status', type: 'ENUM', enumValues: [ 'none', 'padding', 'fin', 'error' ], allowNull: true, defaultValue: 'none', comment: '发货状态机' },
{ name: 'recheck_status', type: 'STRING(20)', allowNull: true, defaultValue: 'none', comment: '复核状态' },
{ name: 'recheck_time', type: 'DATE', allowNull: true, defaultValue: null, comment: '复核时间' },
{ name: 'print_lock_status', type: 'ENUM', enumValues: [ 'none', 'warehouse' ], allowNull: true, defaultValue: 'none', comment: '打印锁定状态机' },
];
/**
* 将列定义转为 Sequelize 字段描述。
*
* @param {Object} Sequelize Sequelize 构造器。
* @param {Object} def 列定义(name/type/allowNull/defaultValue/comment)。
* @return {Object} Sequelize addColumn 字段描述。
*/
function toColumnDef(Sequelize, def) {
let type;
if (def.type === 'ENUM') {
type = Sequelize.ENUM(...def.enumValues);
} else if (def.type === 'JSON') {
type = Sequelize.JSON;
} else if (def.type === 'DATE') {
type = Sequelize.DATE;
} else if (def.type === 'TEXT') {
type = Sequelize.TEXT;
} else if (def.type === 'CHAR(32)') {
type = Sequelize.CHAR(32);
} else {
const match = def.type.match(/^([A-Z]+)(?:\(([^)]+)\))?(?:\.([A-Z]+))?$/);
if (!match) {
throw new Error(`无法解析列类型: ${def.type}`);
}
const base = match[1];
const args = match[2] ? match[2].split(',').map(s => Number(s.trim())) : [];
const unsigned = Boolean(match[3] && match[3] === 'UNSIGNED');
switch (base) {
case 'STRING':
type = Sequelize.STRING(args[0]);
break;
case 'INTEGER':
type = Sequelize.INTEGER(args[0]);
break;
case 'BIGINT':
type = Sequelize.BIGINT(args[0]);
break;
case 'SMALLINT':
type = Sequelize.SMALLINT(args[0]);
break;
default:
throw new Error(`无法解析列类型: ${def.type}`);
}
if (unsigned) {
type = type.UNSIGNED;
}
}
const columnDef = {
type,
allowNull: def.allowNull,
comment: def.comment,
};
if (def.defaultValue !== null && def.defaultValue !== undefined) {
columnDef.defaultValue = def.defaultValue;
}
return columnDef;
}
module.exports = {
// eslint-disable-next-line no-unused-vars
async up(queryInterface, Sequelize) {
for (const def of MISSING_COLUMNS) {
await queryInterface.addColumn(TABLE_NAME, def.name, toColumnDef(Sequelize, def));
}
},
// eslint-disable-next-line no-unused-vars
async down(queryInterface, Sequelize) {
for (const def of MISSING_COLUMNS) {
await queryInterface.removeColumn(TABLE_NAME, def.name);
}
},
};