- 列表:B2B 待处理/配送列表固定加急优先排序(wms_order_b2b.is_urgent='Y' 置顶), 作业明细筛选口径不变 - 备货/提货:新增 setB2bUrgent/cancelB2bUrgent、startB2bPrep/cancelB2bPrep/finishB2bPrep、 setB2bPickupPlate、pickupB2b、updateB2bOrderImages;提货即出库完成 (写 outbound_status=fin / step=4 / delivery_time 并迁移到配送表),车牌与提货照片 随单落库 - 分箱:新增 wms_order_b2b_items 与 order.updateB2bPackingItems、order.getB2bPackingSnapshot; 快照按商品行返回 wms_picking 取货储位(items[].pick_locations / pick_location_count), 列表不再携带储位明细 - 齐套校验:仓库 subject_config 新增 b2b_packing_quantity_check,备货完成时逐商品校验 分箱数量合计等于 plan_qty 且总箱数与箱号数一致 - 拦截:B2B 订单不参与波次抓取、快捷复核批量发货、反审回待审核与克隆,命中即整批驳回 - 明细:order.pendingOrder.detail / order.deliveryOrder.detail 为 B2B 订单附加副表作业明细 b2b、备货照片 images 与提货照片 pickup_images - 迁移:wms_order_b2b 新增 is_urgent 与备货作业字段,新建 wms_order_b2b_items - 文档:methods/system.json 与 methods/changes/system.json 同步至 0.3.375 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
141 lines
5.0 KiB
JavaScript
141 lines
5.0 KiB
JavaScript
'use strict';
|
||
|
||
/**
|
||
* wms_order_b2b 增加备货作业字段(B2B 备货开始 / 取消备货 / 备货结束)。
|
||
*
|
||
* 新增:
|
||
* - prep_status ENUM('none','padding','fin') NOT NULL DEFAULT 'none' 备货状态
|
||
* - prep_operator_id BIGINT UNSIGNED NULL 备货人工号ID
|
||
* - prep_operator_name VARCHAR(50) NULL 备货人姓名
|
||
* - prep_start_at DATETIME NULL 备货开始时间
|
||
* - idx_prep_status_operator (prep_status, prep_operator_id) 我的备货任务筛选
|
||
*
|
||
* 已有字段复用:prep_remark(备货备注)、total_box_count(总箱数)、
|
||
* prep_at(备货完成时间)、prep_duration_seconds(备货用时)。
|
||
*
|
||
* 幂等:列/索引存在性判断后再执行,重复运行安全。
|
||
*/
|
||
|
||
const TABLE_NAME = 'wms_order_b2b';
|
||
const INDEX_NAME = 'idx_prep_status_operator';
|
||
|
||
const COLUMNS = [
|
||
{
|
||
name: 'prep_status',
|
||
definition: {
|
||
type: "ENUM('none', 'padding', 'fin')",
|
||
allowNull: false,
|
||
defaultValue: 'none',
|
||
comment: '备货状态:none=未开始 padding=备货中 fin=已完成',
|
||
},
|
||
},
|
||
{
|
||
name: 'prep_operator_id',
|
||
definition: {
|
||
type: 'BIGINT UNSIGNED',
|
||
allowNull: true,
|
||
comment: '备货人工号ID(工号,用于同工号校验)',
|
||
},
|
||
},
|
||
{
|
||
name: 'prep_operator_name',
|
||
definition: {
|
||
type: 'VARCHAR(50)',
|
||
allowNull: true,
|
||
comment: '备货人姓名',
|
||
},
|
||
},
|
||
{
|
||
name: 'prep_start_at',
|
||
definition: {
|
||
type: 'DATETIME',
|
||
allowNull: true,
|
||
comment: '备货开始时间',
|
||
},
|
||
},
|
||
];
|
||
|
||
/**
|
||
* 判断索引是否存在。
|
||
* @param {import('sequelize').QueryInterface} queryInterface 查询接口。
|
||
* @param {string} indexName 索引名。
|
||
* @return {Promise<boolean>} 是否存在。
|
||
*/
|
||
async function indexExists(queryInterface, indexName) {
|
||
const indexes = await queryInterface.showIndex(TABLE_NAME);
|
||
return (Array.isArray(indexes) ? indexes : []).some(index => {
|
||
const name = String(index && (index.name || index.Key_name || index.key_name) || '');
|
||
return name.toLowerCase() === String(indexName).toLowerCase();
|
||
});
|
||
}
|
||
|
||
module.exports = {
|
||
/**
|
||
* 执行迁移:新增备货作业字段与索引。
|
||
* @param {import('sequelize').QueryInterface} queryInterface 查询接口。
|
||
* @param {Object} Sequelize Sequelize 类型集合。
|
||
* @return {Promise<void>} 无返回值。
|
||
*/
|
||
async up(queryInterface, Sequelize) {
|
||
const { DataTypes } = Sequelize;
|
||
const log = [];
|
||
|
||
const columns = await queryInterface.describeTable(TABLE_NAME);
|
||
if (!columns || Object.keys(columns).length === 0) {
|
||
throw new Error(`表 ${TABLE_NAME} 不存在,无法新增备货字段`);
|
||
}
|
||
|
||
for (const column of COLUMNS) {
|
||
if (Object.prototype.hasOwnProperty.call(columns, column.name)) {
|
||
log.push({ action: 'skip-add-column', columnName: column.name, reason: 'exists' });
|
||
continue;
|
||
}
|
||
|
||
const definition = column.name === 'prep_status'
|
||
? { type: DataTypes.ENUM('none', 'padding', 'fin'), allowNull: false, defaultValue: 'none', comment: column.definition.comment }
|
||
: column.name === 'prep_operator_id'
|
||
? { type: DataTypes.BIGINT.UNSIGNED, allowNull: true, comment: column.definition.comment }
|
||
: column.name === 'prep_operator_name'
|
||
? { type: DataTypes.STRING(50), allowNull: true, comment: column.definition.comment }
|
||
: { type: DataTypes.DATE, allowNull: true, comment: column.definition.comment };
|
||
|
||
await queryInterface.addColumn(TABLE_NAME, column.name, definition);
|
||
log.push({ action: 'add-column', columnName: column.name });
|
||
}
|
||
|
||
if (!(await indexExists(queryInterface, INDEX_NAME))) {
|
||
await queryInterface.addIndex(TABLE_NAME, [ 'prep_status', 'prep_operator_id' ], { name: INDEX_NAME });
|
||
log.push({ action: 'add-index', indexName: INDEX_NAME });
|
||
} else {
|
||
log.push({ action: 'skip-add-index', indexName: INDEX_NAME, reason: 'exists' });
|
||
}
|
||
|
||
console.log('[20261117200000-add-prep-fields-to-wms-order-b2b] up results:', JSON.stringify(log));
|
||
},
|
||
|
||
/**
|
||
* 回滚迁移:移除备货作业字段与索引。
|
||
* @param {import('sequelize').QueryInterface} queryInterface 查询接口。
|
||
* @return {Promise<void>} 无返回值。
|
||
*/
|
||
async down(queryInterface) {
|
||
const log = [];
|
||
|
||
if (await indexExists(queryInterface, INDEX_NAME)) {
|
||
await queryInterface.removeIndex(TABLE_NAME, INDEX_NAME);
|
||
log.push({ action: 'drop-index', indexName: INDEX_NAME });
|
||
}
|
||
|
||
const columns = await queryInterface.describeTable(TABLE_NAME);
|
||
for (const column of [ ...COLUMNS ].reverse()) {
|
||
if (!Object.prototype.hasOwnProperty.call(columns, column.name)) {
|
||
continue;
|
||
}
|
||
await queryInterface.removeColumn(TABLE_NAME, column.name);
|
||
log.push({ action: 'drop-column', columnName: column.name });
|
||
}
|
||
|
||
console.log('[20261117200000-add-prep-fields-to-wms-order-b2b] down results:', JSON.stringify(log));
|
||
},
|
||
};
|