'use strict'; module.exports = app => { const { STRING, INTEGER, DATE, BOOLEAN, ENUM, DECIMAL, BIGINT } = app.Sequelize; const LocationSpace = app.model.define('wms_location_space', { id: { type: BIGINT(20).UNSIGNED, primaryKey: true, autoIncrement: true, comment: '仓位ID', }, warehouse_id: { type: BIGINT(20).UNSIGNED, allowNull: false, comment: '仓库ID', }, zone_id: { type: INTEGER(10).UNSIGNED, allowNull: false, comment: '所属分区ID', }, location_type_id: { type: INTEGER(10).UNSIGNED, allowNull: false, comment: '仓位类型ID', }, space_code: { type: STRING(50), allowNull: false, comment: '仓位编码', }, custom_name: { type: STRING(100), allowNull: true, comment: '自定义名称', }, custom_barcode: { type: STRING(100), allowNull: true, comment: '自定义条码', }, row_no: { type: STRING(10), allowNull: true, comment: '排号', }, column_no: { type: STRING(10), allowNull: true, comment: '列号', }, level_no: { type: STRING(10), allowNull: true, comment: '层号', }, cell_no: { type: STRING(10), allowNull: true, comment: '格号', }, length: { type: DECIMAL(8, 2), allowNull: true, comment: '长度(cm)', }, width: { type: DECIMAL(8, 2), allowNull: true, comment: '宽度(cm)', }, height: { type: DECIMAL(8, 2), allowNull: true, comment: '高度(cm)', }, volume: { type: DECIMAL(10, 2), allowNull: true, comment: '体积(m³)', }, max_weight: { type: INTEGER(11), allowNull: true, defaultValue: 0, comment: '最大承重(g)', }, space_status: { type: ENUM('AVAILABLE', 'OCCUPIED', 'RESERVED', 'MAINTENANCE', 'DISABLED'), allowNull: false, defaultValue: 'AVAILABLE', comment: '仓位状态', }, is_enabled: { type: BOOLEAN, allowNull: false, defaultValue: true, comment: '是否启用', }, current_sku_count: { type: INTEGER(11), allowNull: true, defaultValue: 0, comment: '当前SKU种类数', }, current_quantity: { type: INTEGER(11), allowNull: true, defaultValue: 0, comment: '当前库存数量', }, current_weight: { type: INTEGER(11), allowNull: true, defaultValue: 0, comment: '当前重量(g)', }, current_volume: { type: DECIMAL(10, 2), allowNull: true, defaultValue: 0, comment: '当前体积(m³)', }, pick_sequence: { type: INTEGER(10), allowNull: true, comment: '拣货顺序', }, pick_zone_id: { type: INTEGER(10), allowNull: true, comment: '所属拣货分区ID', }, is_preferred_pick: { type: BOOLEAN, allowNull: true, defaultValue: false, comment: '是否优先拣货位', }, distance_from_start: { type: INTEGER(11), allowNull: true, comment: '距起始点距离(mm)', }, pick_time_estimate: { type: INTEGER(11), allowNull: true, defaultValue: 0, comment: '预估拣货时间(秒)', }, pick_priority: { type: INTEGER(3), allowNull: true, defaultValue: 50, comment: '拣货优先级(1-100)', }, last_picked_at: { type: DATE, allowNull: true, comment: '最后拣货时间', }, pick_count: { type: INTEGER(11), allowNull: true, defaultValue: 0, comment: '拣货次数', }, relative_x: { type: DECIMAL(8, 2), allowNull: true, comment: '在货架内的X坐标(cm)', }, relative_y: { type: DECIMAL(8, 2), allowNull: true, comment: '在货架内的Y坐标(cm)', }, relative_z: { type: DECIMAL(8, 2), allowNull: true, comment: '在货架内的Z坐标(cm)', }, created_by: { type: BIGINT(20), allowNull: true, comment: '创建人', }, updated_by: { type: BIGINT(20), allowNull: true, comment: '更新人', }, deleted_at: { type: DATE, allowNull: true, comment: '软删除时间', }, }, { tableName: 'wms_location_space', timestamps: true, createdAt: 'created_at', updatedAt: 'updated_at', paranoid: true, deletedAt: 'deleted_at', comment: '仓位格子表', indexes: [ { name: 'uk_warehouse_space_code', unique: true, fields: [ 'warehouse_id', 'space_code', 'deleted_at' ], }, { name: 'uk_warehouse_custom_barcode', unique: true, fields: [ 'warehouse_id', 'custom_barcode', 'deleted_at' ] }, { fields: [ 'warehouse_id', 'zone_id' ] }, { fields: [ 'location_type_id' ] }, { fields: [ 'space_status' ] }, { fields: [ 'is_enabled' ] }, { fields: [ 'row_no', 'column_no', 'level_no' ] }, { fields: [ 'zone_id' ] }, { fields: [ 'warehouse_id', 'pick_sequence', 'space_status' ] }, { fields: [ 'pick_priority', 'space_status' ] }, { fields: [ 'last_picked_at' ] }, { fields: [ 'pick_zone_id' ] }, ], }); // 关联关系 LocationSpace.associate = function() { const { LocationSpace, LocationZone, Store, LocationType, ReceivingDetail } = app.model; LocationSpace.belongsTo(LocationZone, { as: 'zone', foreignKey: 'zone_id', }); LocationSpace.belongsTo(Store, { as: 'warehouse', foreignKey: 'warehouse_id', }); LocationSpace.belongsTo(LocationType, { as: 'locationType', foreignKey: 'location_type_id', }); // 关联系统商品 LocationSpace.hasMany(ReceivingDetail, { as: 'receiving', foreignKey: 'space_id', }); }; return LocationSpace; };