1109 lines
29 KiB
JavaScript
1109 lines
29 KiB
JavaScript
'use strict';
|
||
|
||
/**
|
||
* 获取当前数据库已存在的表名集合。
|
||
* @param {import('sequelize').QueryInterface} queryInterface 查询接口。
|
||
* @return {Promise<Set<string>>} 表名集合。
|
||
*/
|
||
const getExistingTableSet = async queryInterface => {
|
||
const tables = await queryInterface.showAllTables();
|
||
return new Set(
|
||
tables.map(table => (typeof table === 'string' ? table : table.tableName))
|
||
);
|
||
};
|
||
|
||
/**
|
||
* 构建通用时间字段。
|
||
* @param {import('sequelize')} Sequelize Sequelize 实例。
|
||
* @return {{create_time: object, update_time: object}} 时间字段定义。
|
||
*/
|
||
const buildTimeColumns = Sequelize => ({
|
||
create_time: {
|
||
type: Sequelize.DATE,
|
||
allowNull: false,
|
||
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP'),
|
||
comment: '创建时间',
|
||
},
|
||
update_time: {
|
||
type: Sequelize.DATE,
|
||
allowNull: false,
|
||
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'),
|
||
comment: '更新时间',
|
||
},
|
||
});
|
||
|
||
/**
|
||
* 创建波次拣货任务主表。
|
||
* @param {import('sequelize').QueryInterface} queryInterface 查询接口。
|
||
* @param {import('sequelize')} Sequelize Sequelize 实例。
|
||
* @return {Promise<void>} 无返回值。
|
||
*/
|
||
const createWavePickTaskTable = async (queryInterface, Sequelize) => {
|
||
await queryInterface.createTable('wms_wave_pick_task', {
|
||
id: {
|
||
type: Sequelize.BIGINT,
|
||
primaryKey: true,
|
||
autoIncrement: true,
|
||
allowNull: false,
|
||
comment: '主键ID',
|
||
},
|
||
task_no: {
|
||
type: Sequelize.STRING(64),
|
||
allowNull: false,
|
||
comment: '任务编号',
|
||
},
|
||
warehouse_id: {
|
||
type: Sequelize.BIGINT,
|
||
allowNull: false,
|
||
comment: '仓库ID',
|
||
},
|
||
wave_id: {
|
||
type: Sequelize.BIGINT,
|
||
allowNull: true,
|
||
comment: '波次ID',
|
||
},
|
||
pick_mode: {
|
||
type: Sequelize.TINYINT,
|
||
allowNull: false,
|
||
defaultValue: 1,
|
||
comment: '拣货模式:1-小团购 2-单品单件 3-先拣后分 4-边拣边分 5-大团购',
|
||
},
|
||
status: {
|
||
type: Sequelize.TINYINT,
|
||
allowNull: false,
|
||
defaultValue: 0,
|
||
comment: '任务状态:0-待开始 1-拣货中 2-待复核 3-已完成 9-已取消',
|
||
},
|
||
source: {
|
||
type: Sequelize.TINYINT,
|
||
allowNull: false,
|
||
defaultValue: 1,
|
||
comment: '任务来源:1-PDA 2-后台',
|
||
},
|
||
wave_count: {
|
||
type: Sequelize.INTEGER,
|
||
allowNull: false,
|
||
defaultValue: 0,
|
||
comment: '波次数量',
|
||
},
|
||
order_count: {
|
||
type: Sequelize.INTEGER,
|
||
allowNull: false,
|
||
defaultValue: 0,
|
||
comment: '订单数量',
|
||
},
|
||
box_count: {
|
||
type: Sequelize.INTEGER,
|
||
allowNull: false,
|
||
defaultValue: 0,
|
||
comment: '框数量',
|
||
},
|
||
batch_no: {
|
||
type: Sequelize.STRING(64),
|
||
allowNull: true,
|
||
comment: '领单批次号',
|
||
},
|
||
pick_user_id: {
|
||
type: Sequelize.BIGINT,
|
||
allowNull: true,
|
||
comment: '拣货员ID',
|
||
},
|
||
pick_user_name: {
|
||
type: Sequelize.STRING(64),
|
||
allowNull: true,
|
||
comment: '拣货员名称',
|
||
},
|
||
review_user_id: {
|
||
type: Sequelize.BIGINT,
|
||
allowNull: true,
|
||
comment: '复核员ID',
|
||
},
|
||
review_user_name: {
|
||
type: Sequelize.STRING(64),
|
||
allowNull: true,
|
||
comment: '复核员名称',
|
||
},
|
||
current_cart_id: {
|
||
type: Sequelize.BIGINT,
|
||
allowNull: true,
|
||
comment: '当前绑定拣货车ID',
|
||
},
|
||
current_cart_code_snapshot: {
|
||
type: Sequelize.STRING(64),
|
||
allowNull: true,
|
||
comment: '当前绑定车码快照',
|
||
},
|
||
review_status: {
|
||
type: Sequelize.TINYINT,
|
||
allowNull: false,
|
||
defaultValue: 0,
|
||
comment: '复核状态:0-未就绪 1-待复核 2-复核中 3-复核通过 4-复核异常',
|
||
},
|
||
review_version: {
|
||
type: Sequelize.INTEGER,
|
||
allowNull: false,
|
||
defaultValue: 0,
|
||
comment: '复核并发版本号',
|
||
},
|
||
review_start_time: {
|
||
type: Sequelize.DATE,
|
||
allowNull: true,
|
||
comment: '复核开始时间',
|
||
},
|
||
review_finish_time: {
|
||
type: Sequelize.DATE,
|
||
allowNull: true,
|
||
comment: '复核结束时间',
|
||
},
|
||
review_result: {
|
||
type: Sequelize.TINYINT,
|
||
allowNull: true,
|
||
comment: '复核结果:1-通过 2-异常',
|
||
},
|
||
review_remark: {
|
||
type: Sequelize.STRING(255),
|
||
allowNull: true,
|
||
comment: '复核备注',
|
||
},
|
||
device_id: {
|
||
type: Sequelize.STRING(64),
|
||
allowNull: true,
|
||
comment: '设备ID',
|
||
},
|
||
expire_time: {
|
||
type: Sequelize.DATE,
|
||
allowNull: true,
|
||
comment: '任务过期时间',
|
||
},
|
||
transfer_from_task_id: {
|
||
type: Sequelize.BIGINT,
|
||
allowNull: true,
|
||
comment: '转移来源任务ID',
|
||
},
|
||
transfer_to_task_id: {
|
||
type: Sequelize.BIGINT,
|
||
allowNull: true,
|
||
comment: '转移目标任务ID',
|
||
},
|
||
start_time: {
|
||
type: Sequelize.DATE,
|
||
allowNull: true,
|
||
comment: '开始拣货时间',
|
||
},
|
||
finish_time: {
|
||
type: Sequelize.DATE,
|
||
allowNull: true,
|
||
comment: '完成拣货时间',
|
||
},
|
||
review_time: {
|
||
type: Sequelize.DATE,
|
||
allowNull: true,
|
||
comment: '复核完成时间',
|
||
},
|
||
remark: {
|
||
type: Sequelize.STRING(255),
|
||
allowNull: true,
|
||
comment: '备注',
|
||
},
|
||
ext_json: {
|
||
type: Sequelize.JSON,
|
||
allowNull: true,
|
||
comment: '扩展信息',
|
||
},
|
||
...buildTimeColumns(Sequelize),
|
||
}, {
|
||
charset: 'utf8mb4',
|
||
collate: 'utf8mb4_general_ci',
|
||
comment: '波次拣货任务主表',
|
||
});
|
||
|
||
await queryInterface.addIndex('wms_wave_pick_task', [ 'task_no' ], {
|
||
unique: true,
|
||
name: 'uk_task_no',
|
||
});
|
||
await queryInterface.addIndex('wms_wave_pick_task', [ 'warehouse_id', 'status' ], {
|
||
name: 'idx_warehouse_status',
|
||
});
|
||
await queryInterface.addIndex('wms_wave_pick_task', [ 'pick_user_id', 'status' ], {
|
||
name: 'idx_pick_user_status',
|
||
});
|
||
await queryInterface.addIndex('wms_wave_pick_task', [ 'warehouse_id', 'review_status' ], {
|
||
name: 'idx_warehouse_review_status',
|
||
});
|
||
await queryInterface.addIndex('wms_wave_pick_task', [ 'current_cart_id', 'review_status' ], {
|
||
name: 'idx_current_cart_review_status',
|
||
});
|
||
};
|
||
|
||
/**
|
||
* 创建任务与波次关联表。
|
||
* @param {import('sequelize').QueryInterface} queryInterface 查询接口。
|
||
* @param {import('sequelize')} Sequelize Sequelize 实例。
|
||
* @return {Promise<void>} 无返回值。
|
||
*/
|
||
const createTaskWaveTable = async (queryInterface, Sequelize) => {
|
||
await queryInterface.createTable('wms_wave_pick_task_wave', {
|
||
id: {
|
||
type: Sequelize.BIGINT,
|
||
primaryKey: true,
|
||
autoIncrement: true,
|
||
allowNull: false,
|
||
comment: '主键ID',
|
||
},
|
||
task_id: {
|
||
type: Sequelize.BIGINT,
|
||
allowNull: false,
|
||
comment: '任务ID',
|
||
},
|
||
wave_id: {
|
||
type: Sequelize.BIGINT,
|
||
allowNull: false,
|
||
comment: '波次ID',
|
||
},
|
||
wave_no: {
|
||
type: Sequelize.STRING(64),
|
||
allowNull: true,
|
||
comment: '波次号',
|
||
},
|
||
box_no: {
|
||
type: Sequelize.INTEGER,
|
||
allowNull: true,
|
||
comment: '框号',
|
||
},
|
||
status: {
|
||
type: Sequelize.TINYINT,
|
||
allowNull: false,
|
||
defaultValue: 0,
|
||
comment: '波次状态:0-待拣 1-已拣 2-异常',
|
||
},
|
||
bind_time: {
|
||
type: Sequelize.DATE,
|
||
allowNull: true,
|
||
comment: '绑定时间',
|
||
},
|
||
pick_time: {
|
||
type: Sequelize.DATE,
|
||
allowNull: true,
|
||
comment: '拣货完成时间',
|
||
},
|
||
warehouse_id: {
|
||
type: Sequelize.BIGINT,
|
||
allowNull: false,
|
||
comment: '仓库ID',
|
||
},
|
||
...buildTimeColumns(Sequelize),
|
||
}, {
|
||
charset: 'utf8mb4',
|
||
collate: 'utf8mb4_general_ci',
|
||
comment: '波次拣货任务与波次关联表',
|
||
});
|
||
|
||
await queryInterface.addIndex('wms_wave_pick_task_wave', [ 'task_id', 'wave_id' ], {
|
||
unique: true,
|
||
name: 'uk_task_wave',
|
||
});
|
||
await queryInterface.addIndex('wms_wave_pick_task_wave', [ 'warehouse_id', 'wave_id' ], {
|
||
name: 'idx_warehouse_wave',
|
||
});
|
||
};
|
||
|
||
/**
|
||
* 创建任务订单明细表。
|
||
* @param {import('sequelize').QueryInterface} queryInterface 查询接口。
|
||
* @param {import('sequelize')} Sequelize Sequelize 实例。
|
||
* @return {Promise<void>} 无返回值。
|
||
*/
|
||
const createTaskOrderTable = async (queryInterface, Sequelize) => {
|
||
await queryInterface.createTable('wms_wave_pick_task_order', {
|
||
id: {
|
||
type: Sequelize.BIGINT,
|
||
primaryKey: true,
|
||
autoIncrement: true,
|
||
allowNull: false,
|
||
comment: '主键ID',
|
||
},
|
||
task_id: {
|
||
type: Sequelize.BIGINT,
|
||
allowNull: false,
|
||
comment: '任务ID',
|
||
},
|
||
wave_id: {
|
||
type: Sequelize.BIGINT,
|
||
allowNull: true,
|
||
comment: '波次ID',
|
||
},
|
||
order_id: {
|
||
type: Sequelize.BIGINT,
|
||
allowNull: false,
|
||
comment: '订单ID',
|
||
},
|
||
order_no: {
|
||
type: Sequelize.STRING(64),
|
||
allowNull: true,
|
||
comment: '订单号',
|
||
},
|
||
box_no: {
|
||
type: Sequelize.INTEGER,
|
||
allowNull: true,
|
||
comment: '框号',
|
||
},
|
||
cart_id: {
|
||
type: Sequelize.BIGINT,
|
||
allowNull: true,
|
||
comment: '拣货车ID',
|
||
},
|
||
cart_code_snapshot: {
|
||
type: Sequelize.STRING(64),
|
||
allowNull: true,
|
||
comment: '拣货车码快照',
|
||
},
|
||
warehouse_id: {
|
||
type: Sequelize.BIGINT,
|
||
allowNull: false,
|
||
comment: '仓库ID',
|
||
},
|
||
pick_status: {
|
||
type: Sequelize.TINYINT,
|
||
allowNull: false,
|
||
defaultValue: 0,
|
||
comment: '拣货状态:0-待拣货 1-已拣货',
|
||
},
|
||
review_status: {
|
||
type: Sequelize.TINYINT,
|
||
allowNull: false,
|
||
defaultValue: 0,
|
||
comment: '复核状态:0-待复核 1-已复核 2-异常',
|
||
},
|
||
review_user_id: {
|
||
type: Sequelize.BIGINT,
|
||
allowNull: true,
|
||
comment: '复核员ID',
|
||
},
|
||
review_result: {
|
||
type: Sequelize.TINYINT,
|
||
allowNull: true,
|
||
comment: '复核结果:1-通过 2-异常',
|
||
},
|
||
review_remark: {
|
||
type: Sequelize.STRING(255),
|
||
allowNull: true,
|
||
comment: '复核备注',
|
||
},
|
||
exception_reason: {
|
||
type: Sequelize.STRING(255),
|
||
allowNull: true,
|
||
comment: '异常原因',
|
||
},
|
||
picked_time: {
|
||
type: Sequelize.DATE,
|
||
allowNull: true,
|
||
comment: '拣货完成时间',
|
||
},
|
||
review_time: {
|
||
type: Sequelize.DATE,
|
||
allowNull: true,
|
||
comment: '复核完成时间',
|
||
},
|
||
...buildTimeColumns(Sequelize),
|
||
}, {
|
||
charset: 'utf8mb4',
|
||
collate: 'utf8mb4_general_ci',
|
||
comment: '波次拣货任务订单表',
|
||
});
|
||
|
||
await queryInterface.addIndex('wms_wave_pick_task_order', [ 'task_id', 'order_id' ], {
|
||
unique: true,
|
||
name: 'uk_task_order',
|
||
});
|
||
await queryInterface.addIndex('wms_wave_pick_task_order', [ 'warehouse_id', 'order_id' ], {
|
||
name: 'idx_warehouse_order',
|
||
});
|
||
await queryInterface.addIndex('wms_wave_pick_task_order', [ 'task_id', 'pick_status' ], {
|
||
name: 'idx_task_pick_status',
|
||
});
|
||
await queryInterface.addIndex('wms_wave_pick_task_order', [ 'task_id', 'review_status' ], {
|
||
name: 'idx_task_review_status',
|
||
});
|
||
await queryInterface.addIndex('wms_wave_pick_task_order', [ 'cart_id' ], {
|
||
name: 'idx_cart_id',
|
||
});
|
||
};
|
||
|
||
/**
|
||
* 创建任务箱明细表。
|
||
* @param {import('sequelize').QueryInterface} queryInterface 查询接口。
|
||
* @param {import('sequelize')} Sequelize Sequelize 实例。
|
||
* @return {Promise<void>} 无返回值。
|
||
*/
|
||
const createTaskBoxTable = async (queryInterface, Sequelize) => {
|
||
await queryInterface.createTable('wms_wave_pick_task_box', {
|
||
id: {
|
||
type: Sequelize.BIGINT,
|
||
primaryKey: true,
|
||
autoIncrement: true,
|
||
allowNull: false,
|
||
comment: '主键ID',
|
||
},
|
||
task_id: {
|
||
type: Sequelize.BIGINT,
|
||
allowNull: false,
|
||
comment: '任务ID',
|
||
},
|
||
order_id: {
|
||
type: Sequelize.BIGINT,
|
||
allowNull: true,
|
||
comment: '订单ID',
|
||
},
|
||
box_code: {
|
||
type: Sequelize.STRING(64),
|
||
allowNull: false,
|
||
comment: '箱号',
|
||
},
|
||
box_no: {
|
||
type: Sequelize.INTEGER,
|
||
allowNull: true,
|
||
comment: '框号',
|
||
},
|
||
box_type: {
|
||
type: Sequelize.TINYINT,
|
||
allowNull: true,
|
||
comment: '框类型:1-SKU框 2-订单框 3-波次框',
|
||
},
|
||
ref_id: {
|
||
type: Sequelize.BIGINT,
|
||
allowNull: true,
|
||
comment: '关联ID(SKU或订单或波次)',
|
||
},
|
||
ref_label: {
|
||
type: Sequelize.STRING(128),
|
||
allowNull: true,
|
||
comment: '关联展示标签',
|
||
},
|
||
required_qty: {
|
||
type: Sequelize.INTEGER,
|
||
allowNull: false,
|
||
defaultValue: 0,
|
||
comment: '应放数量',
|
||
},
|
||
picked_qty: {
|
||
type: Sequelize.INTEGER,
|
||
allowNull: false,
|
||
defaultValue: 0,
|
||
comment: '已放数量',
|
||
},
|
||
box_status: {
|
||
type: Sequelize.TINYINT,
|
||
allowNull: false,
|
||
defaultValue: 0,
|
||
comment: '箱状态:0-待拣货 1-已拣货 2-已复核',
|
||
},
|
||
review_result: {
|
||
type: Sequelize.TINYINT,
|
||
allowNull: true,
|
||
comment: '复核结果:1-通过 2-缺件 3-多件',
|
||
},
|
||
review_user_id: {
|
||
type: Sequelize.BIGINT,
|
||
allowNull: true,
|
||
comment: '复核员ID',
|
||
},
|
||
review_time: {
|
||
type: Sequelize.DATE,
|
||
allowNull: true,
|
||
comment: '复核时间',
|
||
},
|
||
warehouse_id: {
|
||
type: Sequelize.BIGINT,
|
||
allowNull: false,
|
||
comment: '仓库ID',
|
||
},
|
||
...buildTimeColumns(Sequelize),
|
||
}, {
|
||
charset: 'utf8mb4',
|
||
collate: 'utf8mb4_general_ci',
|
||
comment: '波次拣货任务箱明细表',
|
||
});
|
||
|
||
await queryInterface.addIndex('wms_wave_pick_task_box', [ 'task_id', 'box_code' ], {
|
||
unique: true,
|
||
name: 'uk_task_box',
|
||
});
|
||
await queryInterface.addIndex('wms_wave_pick_task_box', [ 'order_id' ], {
|
||
name: 'idx_order_id',
|
||
});
|
||
await queryInterface.addIndex('wms_wave_pick_task_box', [ 'task_id', 'box_status' ], {
|
||
name: 'idx_task_box_status',
|
||
});
|
||
await queryInterface.addIndex('wms_wave_pick_task_box', [ 'task_id', 'box_no' ], {
|
||
name: 'idx_task_box_no',
|
||
});
|
||
await queryInterface.addIndex('wms_wave_pick_task_box', [ 'ref_id' ], {
|
||
name: 'idx_ref_id',
|
||
});
|
||
};
|
||
|
||
/**
|
||
* 创建拣货车表。
|
||
* @param {import('sequelize').QueryInterface} queryInterface 查询接口。
|
||
* @param {import('sequelize')} Sequelize Sequelize 实例。
|
||
* @return {Promise<void>} 无返回值。
|
||
*/
|
||
const createPickCartTable = async (queryInterface, Sequelize) => {
|
||
await queryInterface.createTable('wms_pick_cart', {
|
||
id: {
|
||
type: Sequelize.BIGINT,
|
||
primaryKey: true,
|
||
autoIncrement: true,
|
||
allowNull: false,
|
||
comment: '主键ID',
|
||
},
|
||
warehouse_id: {
|
||
type: Sequelize.BIGINT,
|
||
allowNull: false,
|
||
comment: '仓库ID',
|
||
},
|
||
cart_code: {
|
||
type: Sequelize.STRING(64),
|
||
allowNull: false,
|
||
comment: '拣货车编码',
|
||
},
|
||
cart_name: {
|
||
type: Sequelize.STRING(128),
|
||
allowNull: true,
|
||
comment: '拣货车名称',
|
||
},
|
||
status: {
|
||
type: Sequelize.TINYINT,
|
||
allowNull: false,
|
||
defaultValue: 1,
|
||
comment: '状态:0-停用 1-启用',
|
||
},
|
||
current_task_id: {
|
||
type: Sequelize.BIGINT,
|
||
allowNull: true,
|
||
comment: '当前绑定任务ID',
|
||
},
|
||
bind_user_id: {
|
||
type: Sequelize.BIGINT,
|
||
allowNull: true,
|
||
comment: '当前绑定人ID',
|
||
},
|
||
last_bind_time: {
|
||
type: Sequelize.DATE,
|
||
allowNull: true,
|
||
comment: '最近绑定时间',
|
||
},
|
||
last_seen_time: {
|
||
type: Sequelize.DATE,
|
||
allowNull: true,
|
||
comment: '最近扫码时间',
|
||
},
|
||
ext_json: {
|
||
type: Sequelize.JSON,
|
||
allowNull: true,
|
||
comment: '扩展信息',
|
||
},
|
||
...buildTimeColumns(Sequelize),
|
||
}, {
|
||
charset: 'utf8mb4',
|
||
collate: 'utf8mb4_general_ci',
|
||
comment: '拣货车主表',
|
||
});
|
||
|
||
await queryInterface.addIndex('wms_pick_cart', [ 'warehouse_id', 'cart_code' ], {
|
||
unique: true,
|
||
name: 'uk_warehouse_cart_code',
|
||
});
|
||
await queryInterface.addIndex('wms_pick_cart', [ 'status' ], {
|
||
name: 'idx_status',
|
||
});
|
||
await queryInterface.addIndex('wms_pick_cart', [ 'current_task_id' ], {
|
||
name: 'idx_current_task_id',
|
||
});
|
||
};
|
||
|
||
/**
|
||
* 创建任务拣货车绑定表。
|
||
* @param {import('sequelize').QueryInterface} queryInterface 查询接口。
|
||
* @param {import('sequelize')} Sequelize Sequelize 实例。
|
||
* @return {Promise<void>} 无返回值。
|
||
*/
|
||
const createTaskCartBindingTable = async (queryInterface, Sequelize) => {
|
||
await queryInterface.createTable('wms_pick_task_cart_binding', {
|
||
id: {
|
||
type: Sequelize.BIGINT,
|
||
primaryKey: true,
|
||
autoIncrement: true,
|
||
allowNull: false,
|
||
comment: '主键ID',
|
||
},
|
||
task_id: {
|
||
type: Sequelize.BIGINT,
|
||
allowNull: false,
|
||
comment: '任务ID',
|
||
},
|
||
cart_id: {
|
||
type: Sequelize.BIGINT,
|
||
allowNull: false,
|
||
comment: '拣货车ID',
|
||
},
|
||
cart_code_snapshot: {
|
||
type: Sequelize.STRING(64),
|
||
allowNull: true,
|
||
comment: '车码快照',
|
||
},
|
||
warehouse_id: {
|
||
type: Sequelize.BIGINT,
|
||
allowNull: false,
|
||
comment: '仓库ID',
|
||
},
|
||
bind_user_id: {
|
||
type: Sequelize.BIGINT,
|
||
allowNull: true,
|
||
comment: '绑定人ID',
|
||
},
|
||
bind_type: {
|
||
type: Sequelize.TINYINT,
|
||
allowNull: false,
|
||
defaultValue: 1,
|
||
comment: '绑定类型:1-领单绑定 2-换车绑定 3-管理员改绑',
|
||
},
|
||
unbind_user_id: {
|
||
type: Sequelize.BIGINT,
|
||
allowNull: true,
|
||
comment: '解绑人ID',
|
||
},
|
||
is_active: {
|
||
type: Sequelize.TINYINT,
|
||
allowNull: false,
|
||
defaultValue: 1,
|
||
comment: '是否有效绑定:0-无效 1-有效',
|
||
},
|
||
bind_time: {
|
||
type: Sequelize.DATE,
|
||
allowNull: false,
|
||
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP'),
|
||
comment: '绑定时间',
|
||
},
|
||
unbind_time: {
|
||
type: Sequelize.DATE,
|
||
allowNull: true,
|
||
comment: '解绑时间',
|
||
},
|
||
...buildTimeColumns(Sequelize),
|
||
}, {
|
||
charset: 'utf8mb4',
|
||
collate: 'utf8mb4_general_ci',
|
||
comment: '任务拣货车绑定关系表',
|
||
});
|
||
|
||
await queryInterface.addIndex('wms_pick_task_cart_binding', [ 'task_id', 'is_active' ], {
|
||
name: 'idx_task_active',
|
||
});
|
||
await queryInterface.addIndex('wms_pick_task_cart_binding', [ 'cart_id', 'is_active' ], {
|
||
name: 'idx_cart_active',
|
||
});
|
||
await queryInterface.addIndex('wms_pick_task_cart_binding', [ 'warehouse_id', 'is_active' ], {
|
||
name: 'idx_warehouse_active',
|
||
});
|
||
};
|
||
|
||
/**
|
||
* 创建订单拣货轨迹表。
|
||
* @param {import('sequelize').QueryInterface} queryInterface 查询接口。
|
||
* @param {import('sequelize')} Sequelize Sequelize 实例。
|
||
* @return {Promise<void>} 无返回值。
|
||
*/
|
||
const createOrderPickTraceTable = async (queryInterface, Sequelize) => {
|
||
await queryInterface.createTable('wms_order_pick_trace', {
|
||
id: {
|
||
type: Sequelize.BIGINT,
|
||
primaryKey: true,
|
||
autoIncrement: true,
|
||
allowNull: false,
|
||
comment: '主键ID',
|
||
},
|
||
warehouse_id: {
|
||
type: Sequelize.BIGINT,
|
||
allowNull: false,
|
||
comment: '仓库ID',
|
||
},
|
||
order_id: {
|
||
type: Sequelize.BIGINT,
|
||
allowNull: false,
|
||
comment: '订单ID',
|
||
},
|
||
task_id: {
|
||
type: Sequelize.BIGINT,
|
||
allowNull: true,
|
||
comment: '任务ID',
|
||
},
|
||
cart_id: {
|
||
type: Sequelize.BIGINT,
|
||
allowNull: true,
|
||
comment: '拣货车ID',
|
||
},
|
||
cart_code_snapshot: {
|
||
type: Sequelize.STRING(64),
|
||
allowNull: true,
|
||
comment: '拣货车码快照',
|
||
},
|
||
pick_user_id: {
|
||
type: Sequelize.BIGINT,
|
||
allowNull: true,
|
||
comment: '拣货员ID',
|
||
},
|
||
pick_time: {
|
||
type: Sequelize.DATE,
|
||
allowNull: true,
|
||
comment: '拣货时间',
|
||
},
|
||
review_user_id: {
|
||
type: Sequelize.BIGINT,
|
||
allowNull: true,
|
||
comment: '复核员ID',
|
||
},
|
||
review_time: {
|
||
type: Sequelize.DATE,
|
||
allowNull: true,
|
||
comment: '复核时间',
|
||
},
|
||
review_result: {
|
||
type: Sequelize.TINYINT,
|
||
allowNull: true,
|
||
comment: '复核结果:1-通过 2-异常',
|
||
},
|
||
event_type: {
|
||
type: Sequelize.STRING(32),
|
||
allowNull: false,
|
||
comment: '轨迹事件类型',
|
||
},
|
||
event_desc: {
|
||
type: Sequelize.STRING(255),
|
||
allowNull: true,
|
||
comment: '轨迹描述',
|
||
},
|
||
operator_id: {
|
||
type: Sequelize.BIGINT,
|
||
allowNull: true,
|
||
comment: '操作人ID',
|
||
},
|
||
operator_name: {
|
||
type: Sequelize.STRING(64),
|
||
allowNull: true,
|
||
comment: '操作人名称',
|
||
},
|
||
snapshot: {
|
||
type: Sequelize.JSON,
|
||
allowNull: true,
|
||
comment: '轨迹快照',
|
||
},
|
||
create_time: {
|
||
type: Sequelize.DATE,
|
||
allowNull: false,
|
||
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP'),
|
||
comment: '创建时间',
|
||
},
|
||
}, {
|
||
charset: 'utf8mb4',
|
||
collate: 'utf8mb4_general_ci',
|
||
comment: '订单拣货轨迹审计表',
|
||
});
|
||
|
||
await queryInterface.addIndex('wms_order_pick_trace', [ 'warehouse_id', 'order_id', 'create_time' ], {
|
||
name: 'idx_warehouse_order_create_time',
|
||
});
|
||
await queryInterface.addIndex('wms_order_pick_trace', [ 'task_id' ], {
|
||
name: 'idx_task_id',
|
||
});
|
||
await queryInterface.addIndex('wms_order_pick_trace', [ 'cart_id', 'create_time' ], {
|
||
name: 'idx_cart_id_create_time',
|
||
});
|
||
};
|
||
|
||
/**
|
||
* 创建波次拣货动作日志表。
|
||
* @param {import('sequelize').QueryInterface} queryInterface 查询接口。
|
||
* @param {import('sequelize')} Sequelize Sequelize 实例。
|
||
* @return {Promise<void>} 无返回值。
|
||
*/
|
||
const createWavePickActionLogTable = async (queryInterface, Sequelize) => {
|
||
await queryInterface.createTable('wms_wave_pick_action_log', {
|
||
id: {
|
||
type: Sequelize.BIGINT,
|
||
primaryKey: true,
|
||
autoIncrement: true,
|
||
allowNull: false,
|
||
comment: '主键ID',
|
||
},
|
||
task_id: {
|
||
type: Sequelize.BIGINT,
|
||
allowNull: false,
|
||
comment: '任务ID',
|
||
},
|
||
warehouse_id: {
|
||
type: Sequelize.BIGINT,
|
||
allowNull: false,
|
||
comment: '仓库ID',
|
||
},
|
||
wave_id: {
|
||
type: Sequelize.BIGINT,
|
||
allowNull: true,
|
||
comment: '波次ID',
|
||
},
|
||
order_id: {
|
||
type: Sequelize.BIGINT,
|
||
allowNull: true,
|
||
comment: '订单ID',
|
||
},
|
||
sku_id: {
|
||
type: Sequelize.BIGINT,
|
||
allowNull: true,
|
||
comment: '商品ID',
|
||
},
|
||
location_id: {
|
||
type: Sequelize.BIGINT,
|
||
allowNull: true,
|
||
comment: '库位ID',
|
||
},
|
||
box_no: {
|
||
type: Sequelize.INTEGER,
|
||
allowNull: true,
|
||
comment: '框号',
|
||
},
|
||
cart_id: {
|
||
type: Sequelize.BIGINT,
|
||
allowNull: true,
|
||
comment: '拣货车ID',
|
||
},
|
||
qty_delta: {
|
||
type: Sequelize.INTEGER,
|
||
allowNull: false,
|
||
defaultValue: 0,
|
||
comment: '数量变化',
|
||
},
|
||
action_type: {
|
||
type: Sequelize.STRING(32),
|
||
allowNull: false,
|
||
comment: '动作类型(enter_location/scan_sku/put_box/rollback/exception)',
|
||
},
|
||
request_id: {
|
||
type: Sequelize.STRING(64),
|
||
allowNull: false,
|
||
comment: '幂等请求ID',
|
||
},
|
||
operator_id: {
|
||
type: Sequelize.BIGINT,
|
||
allowNull: true,
|
||
comment: '操作人ID',
|
||
},
|
||
device_id: {
|
||
type: Sequelize.STRING(64),
|
||
allowNull: true,
|
||
comment: '设备ID',
|
||
},
|
||
seq_no: {
|
||
type: Sequelize.BIGINT,
|
||
allowNull: true,
|
||
comment: '序列号',
|
||
},
|
||
snapshot: {
|
||
type: Sequelize.JSON,
|
||
allowNull: true,
|
||
comment: '动作快照',
|
||
},
|
||
create_time: {
|
||
type: Sequelize.DATE,
|
||
allowNull: false,
|
||
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP'),
|
||
comment: '创建时间',
|
||
},
|
||
}, {
|
||
charset: 'utf8mb4',
|
||
collate: 'utf8mb4_general_ci',
|
||
comment: '波次拣货动作日志表',
|
||
});
|
||
|
||
await queryInterface.addIndex('wms_wave_pick_action_log', [ 'request_id' ], {
|
||
unique: true,
|
||
name: 'uk_request_id',
|
||
});
|
||
await queryInterface.addIndex('wms_wave_pick_action_log', [ 'task_id', 'create_time' ], {
|
||
name: 'idx_task_create_time',
|
||
});
|
||
await queryInterface.addIndex('wms_wave_pick_action_log', [ 'warehouse_id', 'action_type', 'create_time' ], {
|
||
name: 'idx_warehouse_action_time',
|
||
});
|
||
await queryInterface.addIndex('wms_wave_pick_action_log', [ 'order_id', 'create_time' ], {
|
||
name: 'idx_order_create_time',
|
||
});
|
||
};
|
||
|
||
/**
|
||
* 创建波次拣货断点检查点表。
|
||
* @param {import('sequelize').QueryInterface} queryInterface 查询接口。
|
||
* @param {import('sequelize')} Sequelize Sequelize 实例。
|
||
* @return {Promise<void>} 无返回值。
|
||
*/
|
||
const createWavePickCheckpointTable = async (queryInterface, Sequelize) => {
|
||
await queryInterface.createTable('wms_wave_pick_checkpoint', {
|
||
id: {
|
||
type: Sequelize.BIGINT,
|
||
primaryKey: true,
|
||
autoIncrement: true,
|
||
allowNull: false,
|
||
comment: '主键ID',
|
||
},
|
||
task_id: {
|
||
type: Sequelize.BIGINT,
|
||
allowNull: false,
|
||
comment: '任务ID',
|
||
},
|
||
warehouse_id: {
|
||
type: Sequelize.BIGINT,
|
||
allowNull: false,
|
||
comment: '仓库ID',
|
||
},
|
||
pick_user_id: {
|
||
type: Sequelize.BIGINT,
|
||
allowNull: false,
|
||
comment: '拣货员ID',
|
||
},
|
||
device_id: {
|
||
type: Sequelize.STRING(64),
|
||
allowNull: false,
|
||
comment: '设备ID',
|
||
},
|
||
current_location_id: {
|
||
type: Sequelize.BIGINT,
|
||
allowNull: true,
|
||
comment: '当前库位ID',
|
||
},
|
||
current_sku_id: {
|
||
type: Sequelize.BIGINT,
|
||
allowNull: true,
|
||
comment: '当前商品ID',
|
||
},
|
||
current_box_no: {
|
||
type: Sequelize.INTEGER,
|
||
allowNull: true,
|
||
comment: '当前框号',
|
||
},
|
||
picked_count: {
|
||
type: Sequelize.INTEGER,
|
||
allowNull: false,
|
||
defaultValue: 0,
|
||
comment: '已拣数量',
|
||
},
|
||
remaining_count: {
|
||
type: Sequelize.INTEGER,
|
||
allowNull: false,
|
||
defaultValue: 0,
|
||
comment: '剩余数量',
|
||
},
|
||
last_event_id: {
|
||
type: Sequelize.BIGINT,
|
||
allowNull: true,
|
||
comment: '最新事件ID',
|
||
},
|
||
last_seq_no: {
|
||
type: Sequelize.BIGINT,
|
||
allowNull: true,
|
||
comment: '最新序列号',
|
||
},
|
||
checkpoint_json: {
|
||
type: Sequelize.JSON,
|
||
allowNull: true,
|
||
comment: '检查点快照',
|
||
},
|
||
version: {
|
||
type: Sequelize.INTEGER,
|
||
allowNull: false,
|
||
defaultValue: 0,
|
||
comment: '乐观锁版本号',
|
||
},
|
||
...buildTimeColumns(Sequelize),
|
||
}, {
|
||
charset: 'utf8mb4',
|
||
collate: 'utf8mb4_general_ci',
|
||
comment: '波次拣货断点检查点表',
|
||
});
|
||
|
||
await queryInterface.addIndex('wms_wave_pick_checkpoint', [ 'task_id', 'pick_user_id', 'device_id' ], {
|
||
unique: true,
|
||
name: 'uk_task_user_device',
|
||
});
|
||
await queryInterface.addIndex('wms_wave_pick_checkpoint', [ 'task_id', 'update_time' ], {
|
||
name: 'idx_task_update_time',
|
||
});
|
||
await queryInterface.addIndex('wms_wave_pick_checkpoint', [ 'pick_user_id', 'device_id' ], {
|
||
name: 'idx_user_device',
|
||
});
|
||
};
|
||
|
||
module.exports = {
|
||
/**
|
||
* 执行正向迁移,创建波次拣货任务相关 9 张新表。
|
||
* @param {import('sequelize').QueryInterface} queryInterface 查询接口。
|
||
* @param {import('sequelize')} Sequelize Sequelize 实例。
|
||
* @return {Promise<void>} 无返回值。
|
||
*/
|
||
up: async (queryInterface, Sequelize) => {
|
||
const existingTables = await getExistingTableSet(queryInterface);
|
||
|
||
if (!existingTables.has('wms_wave_pick_task')) {
|
||
await createWavePickTaskTable(queryInterface, Sequelize);
|
||
existingTables.add('wms_wave_pick_task');
|
||
}
|
||
if (!existingTables.has('wms_wave_pick_task_wave')) {
|
||
await createTaskWaveTable(queryInterface, Sequelize);
|
||
existingTables.add('wms_wave_pick_task_wave');
|
||
}
|
||
if (!existingTables.has('wms_wave_pick_task_order')) {
|
||
await createTaskOrderTable(queryInterface, Sequelize);
|
||
existingTables.add('wms_wave_pick_task_order');
|
||
}
|
||
if (!existingTables.has('wms_wave_pick_task_box')) {
|
||
await createTaskBoxTable(queryInterface, Sequelize);
|
||
existingTables.add('wms_wave_pick_task_box');
|
||
}
|
||
if (!existingTables.has('wms_pick_cart')) {
|
||
await createPickCartTable(queryInterface, Sequelize);
|
||
existingTables.add('wms_pick_cart');
|
||
}
|
||
if (!existingTables.has('wms_pick_task_cart_binding')) {
|
||
await createTaskCartBindingTable(queryInterface, Sequelize);
|
||
existingTables.add('wms_pick_task_cart_binding');
|
||
}
|
||
if (!existingTables.has('wms_order_pick_trace')) {
|
||
await createOrderPickTraceTable(queryInterface, Sequelize);
|
||
existingTables.add('wms_order_pick_trace');
|
||
}
|
||
if (!existingTables.has('wms_wave_pick_action_log')) {
|
||
await createWavePickActionLogTable(queryInterface, Sequelize);
|
||
existingTables.add('wms_wave_pick_action_log');
|
||
}
|
||
if (!existingTables.has('wms_wave_pick_checkpoint')) {
|
||
await createWavePickCheckpointTable(queryInterface, Sequelize);
|
||
existingTables.add('wms_wave_pick_checkpoint');
|
||
}
|
||
},
|
||
|
||
/**
|
||
* 执行回滚迁移,按依赖逆序删除波次拣货任务相关 9 张表。
|
||
* @param {import('sequelize').QueryInterface} queryInterface 查询接口。
|
||
* @return {Promise<void>} 无返回值。
|
||
*/
|
||
down: async queryInterface => {
|
||
await queryInterface.dropTable('wms_wave_pick_checkpoint');
|
||
await queryInterface.dropTable('wms_wave_pick_action_log');
|
||
await queryInterface.dropTable('wms_order_pick_trace');
|
||
await queryInterface.dropTable('wms_pick_task_cart_binding');
|
||
await queryInterface.dropTable('wms_pick_cart');
|
||
await queryInterface.dropTable('wms_wave_pick_task_box');
|
||
await queryInterface.dropTable('wms_wave_pick_task_order');
|
||
await queryInterface.dropTable('wms_wave_pick_task_wave');
|
||
await queryInterface.dropTable('wms_wave_pick_task');
|
||
},
|
||
};
|