- storeWarehouse.store.saveApiConfig:新增 resolveContractApiInterfaceType, interface_type_id=3(OPEN_API_WAREHOUSE 仓库开放接口)自动映射为 2(OPEN_API 货主开放接口)落库, 不再要求当前主体为仓库(货主可维护自身签约关系下的接口配置) - callback_url 不再取入参(含 callbackUrl 别名),统一写入 config.openapi.defaultCallbackUrl(新增配置项,默认空) - storeWarehouse.store.listApiConfig:interface_type_id 过滤同步映射(传 3 按 2 查询) - 文档:methods/system.json 升级 0.3.350、methods/changes/system.json 变更记录、docs/openapi-callback-events.md 回调地址来源说明 - 测试:saveApiConfig 新增 4 条用例(3→2 落库、忽略入参回调地址、默认值未配置、货主主体可保存、缺失类型 404),listApiConfig 新增 1 条过滤映射用例 同时提交工作区其余在制品改动: - waybill:移除 wms_order_express_trace 模型并新增 drop 迁移,轨迹查询/取号/打印链路调整 - order:订单 SN 编码(order_item_sn / order_item_sn_log / sn_code_rule、has_sn_item 回填迁移),pendingOrder/recheckOrder/wave/base 调整 - express_platform、order_async、order_export、order_storage_allocation、storage.report、stock_store 配套修复 - lib:新增 jd_client,调整 qimen_client、callback_functions 及配套测试 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
72 lines
2.6 KiB
JavaScript
72 lines
2.6 KiB
JavaScript
'use strict';
|
||
|
||
const ORDER_ITEM_SN_TABLE = 'wms_order_item_sn';
|
||
const ORDER_ITEM_SN_LOG_TABLE = 'wms_order_item_sn_log';
|
||
/** SN 编码目标长度:支持以链接/二维码内容作为 SN,同时保证 (warehouse_id, sn_code) 唯一索引不超过 3072 字节 */
|
||
const TARGET_SN_CODE_LENGTH = 512;
|
||
|
||
/**
|
||
* 读取列当前定义的字符长度。
|
||
* @param {import('sequelize').QueryInterface} queryInterface 查询接口。
|
||
* @param {string} tableName 表名。
|
||
* @param {string} columnName 列名。
|
||
* @return {Promise<number>} 当前字符长度,取不到时返回 0。
|
||
*/
|
||
const getColumnLength = async (queryInterface, tableName, columnName) => {
|
||
const tableDefinition = await queryInterface.describeTable(tableName);
|
||
const column = tableDefinition[columnName];
|
||
if (!column) {
|
||
return 0;
|
||
}
|
||
|
||
const length = Number(column.character_maximum_length || column.maxLength || 0);
|
||
return Number.isFinite(length) ? length : 0;
|
||
};
|
||
|
||
module.exports = {
|
||
/**
|
||
* 把 SN 编码列扩充到 512 字符(支持链接/二维码内容作为 SN 码)。
|
||
* @param {import('sequelize').QueryInterface} queryInterface 查询接口。
|
||
* @param {import('sequelize')} Sequelize Sequelize 实例。
|
||
* @return {Promise<void>} 无返回值。
|
||
*/
|
||
async up(queryInterface, Sequelize) {
|
||
const existingTables = new Set((await queryInterface.showAllTables()).map(table => (
|
||
typeof table === 'string' ? table : (table.tableName || table.name || '')
|
||
).toLowerCase()));
|
||
|
||
for (const tableName of [ ORDER_ITEM_SN_TABLE, ORDER_ITEM_SN_LOG_TABLE ]) {
|
||
if (!existingTables.has(tableName)) {
|
||
continue;
|
||
}
|
||
|
||
const currentLength = await getColumnLength(queryInterface, tableName, 'sn_code');
|
||
if (currentLength >= TARGET_SN_CODE_LENGTH) {
|
||
continue;
|
||
}
|
||
|
||
await queryInterface.changeColumn(tableName, 'sn_code', {
|
||
type: Sequelize.STRING(TARGET_SN_CODE_LENGTH),
|
||
allowNull: false,
|
||
comment: 'SN编码(支持链接/二维码内容,最长512字符)',
|
||
});
|
||
}
|
||
},
|
||
|
||
/**
|
||
* 回滚为 128 字符(超长数据会失败,需先清理)。
|
||
* @param {import('sequelize').QueryInterface} queryInterface 查询接口。
|
||
* @param {import('sequelize')} Sequelize Sequelize 实例。
|
||
* @return {Promise<void>} 无返回值。
|
||
*/
|
||
async down(queryInterface, Sequelize) {
|
||
for (const tableName of [ ORDER_ITEM_SN_TABLE, ORDER_ITEM_SN_LOG_TABLE ]) {
|
||
await queryInterface.changeColumn(tableName, 'sn_code', {
|
||
type: Sequelize.STRING(128),
|
||
allowNull: false,
|
||
comment: 'SN编码',
|
||
});
|
||
}
|
||
},
|
||
};
|