Files
yunrui_asset/backend/models/ConsumableRecord.js
T
zhang1106 568f9c7db8 feat(consumables): 添加耗材管理功能模块
添加耗材管理相关功能,包括:
1. 后端模型、路由和控制器
2. 前端页面和组件
3. 耗材分类管理
4. 耗材出入库记录
5. 耗材统计和日志功能
6. 集成到现有系统菜单
2025-12-24 16:44:27 +08:00

65 lines
1.2 KiB
JavaScript

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,
allowNull: false,
unique: true
},
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
}
}, {
tableName: 'consumable_records',
timestamps: true
});
ConsumableRecord.belongsTo(Consumable, {
foreignKey: 'consumableId',
onDelete: 'CASCADE'
});
Consumable.hasMany(ConsumableRecord, {
foreignKey: 'consumableId',
onDelete: 'CASCADE'
});
module.exports = ConsumableRecord;