'use strict'; /** * 创建退回拆包主表 wms_return_unpack。 * * 字段:仓库隔离 warehouse_id、拆包单号 unpack_no(RP+YYYYMMDD+6位序号)、 * 关联退回收到单 return_received_id(非必填)、运单号 waybill_code、拆包日期 unpack_date、 * 起止时间 start_time/end_time、拆包人 unpacker_id/unpacker_name、状态 status/detail_status、 * 汇总 total_items/total_quantity、原单关联 order_express_id/order_id/store_id(非必填)、 * 摄像头列表 camera_ids(JSON)、备注 remark。 * * 索引: * uk_unpack_no(单号唯一) * idx_warehouse_unpack_date(仓库+日期隔离查询) * idx_return_received_id / idx_waybill_code / idx_order_express_id * idx_unpacker_id / idx_start_time / idx_store_id */ const TABLE_NAME = 'wms_return_unpack'; module.exports = { // eslint-disable-next-line no-unused-vars async up(queryInterface, Sequelize) { const { BIGINT, STRING, INTEGER, DATE } = Sequelize; await queryInterface.createTable(TABLE_NAME, { id: { type: BIGINT(20).UNSIGNED, primaryKey: true, autoIncrement: true, allowNull: false, comment: '主键', }, warehouse_id: { type: BIGINT(20).UNSIGNED, allowNull: false, comment: '仓库ID(数据隔离维度)', }, unpack_no: { type: STRING(50), allowNull: false, comment: '拆包单号,RP+YYYYMMDD+6位序号', }, return_received_id: { type: BIGINT(20).UNSIGNED, allowNull: true, comment: '关联退回收到表 wms_return_received.id;非必填', }, waybill_code: { type: STRING(50), allowNull: false, comment: '拆包的运单号(退回包裹运单号)', }, unpack_date: { type: DATE, allowNull: false, comment: '拆包日期', }, start_time: { type: DATE, allowNull: true, comment: '拆包开始时间', }, end_time: { type: DATE, allowNull: true, comment: '拆包结束时间', }, unpacker_id: { type: BIGINT(20).UNSIGNED, allowNull: false, comment: '拆包人员工号ID(employees_id)', }, unpacker_name: { type: STRING(50), allowNull: false, comment: '拆包人员工号名称快照(employees_name / real_name)', }, status: { type: STRING(20), allowNull: false, defaultValue: 'unpacking', comment: '拆包状态:unpacking/completed/cancelled', }, detail_status: { type: STRING(30), allowNull: false, defaultValue: 'none_recognized', comment: '明细识别状态:none_recognized/partial_recognized/all_recognized', }, total_items: { type: INTEGER(11), allowNull: false, defaultValue: 0, comment: '物品种类数(明细行数)', }, total_quantity: { type: INTEGER(11), allowNull: false, defaultValue: 0, comment: '物品总数量(明细数量合计)', }, order_express_id: { type: BIGINT(20).UNSIGNED, allowNull: true, comment: '原运单ID,关联 wms_order_express.id;原单退回时回填', }, order_id: { type: BIGINT(20).UNSIGNED, allowNull: true, comment: '原订单ID,便于快速匹配;原单退回时回填', }, store_id: { type: BIGINT(20).UNSIGNED, allowNull: true, comment: '货主ID,原单退回/识别到系统商品时回填', }, camera_ids: { type: Sequelize.JSON, allowNull: true, comment: '摄像头ID列表,如 [1,2,3](参考 wms_pack_task.device_ids)', }, remark: { type: STRING(500), allowNull: true, comment: '备注', }, created_at: { type: DATE, allowNull: false }, updated_at: { type: DATE, allowNull: false }, }); await queryInterface.addIndex(TABLE_NAME, [ 'unpack_no' ], { unique: true, name: 'uk_unpack_no' }); await queryInterface.addIndex(TABLE_NAME, [ 'warehouse_id', 'unpack_date' ], { name: 'idx_warehouse_unpack_date' }); await queryInterface.addIndex(TABLE_NAME, [ 'return_received_id' ], { name: 'idx_return_received_id' }); await queryInterface.addIndex(TABLE_NAME, [ 'waybill_code' ], { name: 'idx_waybill_code' }); await queryInterface.addIndex(TABLE_NAME, [ 'order_express_id' ], { name: 'idx_order_express_id' }); await queryInterface.addIndex(TABLE_NAME, [ 'unpacker_id' ], { name: 'idx_unpacker_id' }); await queryInterface.addIndex(TABLE_NAME, [ 'start_time' ], { name: 'idx_start_time' }); await queryInterface.addIndex(TABLE_NAME, [ 'store_id' ], { name: 'idx_store_id' }); }, // eslint-disable-next-line no-unused-vars async down(queryInterface, Sequelize) { await queryInterface.dropTable(TABLE_NAME); }, };