2025-12-24 16:44:27 +08:00
|
|
|
const { DataTypes } = require('sequelize');
|
|
|
|
|
const { sequelize } = require('../db');
|
|
|
|
|
const Consumable = require('./Consumable');
|
|
|
|
|
|
|
|
|
|
const ConsumableRecord = sequelize.define('ConsumableRecord', {
|
|
|
|
|
recordId: {
|
|
|
|
|
type: DataTypes.UUID,
|
|
|
|
|
primaryKey: true,
|
|
|
|
|
defaultValue: DataTypes.UUIDV4,
|
2026-03-13 22:11:34 +08:00
|
|
|
allowNull: false
|
2025-12-24 16:44:27 +08:00
|
|
|
},
|
|
|
|
|
consumableId: {
|
|
|
|
|
type: DataTypes.STRING,
|
|
|
|
|
allowNull: false,
|
|
|
|
|
references: {
|
|
|
|
|
model: Consumable,
|
|
|
|
|
key: 'consumableId'
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
type: {
|
|
|
|
|
type: DataTypes.ENUM('in', 'out'),
|
|
|
|
|
allowNull: false
|
|
|
|
|
},
|
|
|
|
|
quantity: {
|
|
|
|
|
type: DataTypes.INTEGER,
|
|
|
|
|
allowNull: false
|
|
|
|
|
},
|
|
|
|
|
previousStock: {
|
|
|
|
|
type: DataTypes.INTEGER,
|
|
|
|
|
allowNull: false
|
|
|
|
|
},
|
|
|
|
|
currentStock: {
|
|
|
|
|
type: DataTypes.INTEGER,
|
|
|
|
|
allowNull: false
|
|
|
|
|
},
|
|
|
|
|
operator: {
|
|
|
|
|
type: DataTypes.STRING,
|
|
|
|
|
allowNull: false
|
|
|
|
|
},
|
|
|
|
|
reason: {
|
|
|
|
|
type: DataTypes.STRING
|
|
|
|
|
},
|
|
|
|
|
recipient: {
|
|
|
|
|
type: DataTypes.STRING
|
|
|
|
|
},
|
|
|
|
|
notes: {
|
|
|
|
|
type: DataTypes.TEXT
|
2026-03-05 09:57:44 +08:00
|
|
|
},
|
|
|
|
|
snList: {
|
|
|
|
|
type: DataTypes.JSON,
|
|
|
|
|
allowNull: true,
|
|
|
|
|
defaultValue: [],
|
|
|
|
|
comment: '本次操作的SN序列号列表'
|
2025-12-24 16:44:27 +08:00
|
|
|
}
|
|
|
|
|
}, {
|
|
|
|
|
tableName: 'consumable_records',
|
2026-01-20 14:31:20 +08:00
|
|
|
timestamps: true,
|
|
|
|
|
indexes: [
|
|
|
|
|
{ fields: ['consumableId'] },
|
|
|
|
|
{ fields: ['type'] },
|
|
|
|
|
{ fields: ['createdAt'] }
|
|
|
|
|
]
|
2025-12-24 16:44:27 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
ConsumableRecord.belongsTo(Consumable, {
|
|
|
|
|
foreignKey: 'consumableId',
|
|
|
|
|
onDelete: 'CASCADE'
|
|
|
|
|
});
|
|
|
|
|
Consumable.hasMany(ConsumableRecord, {
|
|
|
|
|
foreignKey: 'consumableId',
|
|
|
|
|
onDelete: 'CASCADE'
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
module.exports = ConsumableRecord;
|