2025-12-24 16:44:27 +08:00
|
|
|
const { DataTypes } = require('sequelize');
|
|
|
|
|
const { sequelize } = require('../db');
|
|
|
|
|
|
|
|
|
|
const Consumable = sequelize.define('Consumable', {
|
|
|
|
|
consumableId: {
|
|
|
|
|
type: DataTypes.STRING,
|
|
|
|
|
primaryKey: true,
|
|
|
|
|
allowNull: false,
|
|
|
|
|
unique: true
|
|
|
|
|
},
|
|
|
|
|
name: {
|
|
|
|
|
type: DataTypes.STRING,
|
|
|
|
|
allowNull: false
|
|
|
|
|
},
|
|
|
|
|
category: {
|
|
|
|
|
type: DataTypes.STRING,
|
|
|
|
|
allowNull: false
|
|
|
|
|
},
|
|
|
|
|
unit: {
|
|
|
|
|
type: DataTypes.STRING,
|
|
|
|
|
allowNull: false,
|
|
|
|
|
defaultValue: '个'
|
|
|
|
|
},
|
|
|
|
|
currentStock: {
|
|
|
|
|
type: DataTypes.INTEGER,
|
|
|
|
|
allowNull: false,
|
|
|
|
|
defaultValue: 0
|
|
|
|
|
},
|
|
|
|
|
minStock: {
|
|
|
|
|
type: DataTypes.INTEGER,
|
|
|
|
|
allowNull: false,
|
|
|
|
|
defaultValue: 10
|
|
|
|
|
},
|
|
|
|
|
maxStock: {
|
|
|
|
|
type: DataTypes.INTEGER,
|
2026-01-30 14:01:23 +08:00
|
|
|
allowNull: true,
|
|
|
|
|
defaultValue: null,
|
|
|
|
|
comment: '最大库存,null表示无限制'
|
2025-12-24 16:44:27 +08:00
|
|
|
},
|
|
|
|
|
unitPrice: {
|
|
|
|
|
type: DataTypes.DECIMAL(10, 2),
|
|
|
|
|
allowNull: false,
|
|
|
|
|
defaultValue: 0
|
|
|
|
|
},
|
|
|
|
|
supplier: {
|
|
|
|
|
type: DataTypes.STRING
|
|
|
|
|
},
|
|
|
|
|
location: {
|
|
|
|
|
type: DataTypes.STRING,
|
|
|
|
|
comment: '存放位置'
|
|
|
|
|
},
|
|
|
|
|
description: {
|
|
|
|
|
type: DataTypes.TEXT
|
|
|
|
|
},
|
|
|
|
|
status: {
|
|
|
|
|
type: DataTypes.STRING,
|
|
|
|
|
defaultValue: 'active'
|
2026-01-29 16:53:29 +08:00
|
|
|
},
|
|
|
|
|
version: {
|
|
|
|
|
type: DataTypes.INTEGER,
|
|
|
|
|
allowNull: false,
|
|
|
|
|
defaultValue: 0,
|
|
|
|
|
comment: '乐观锁版本号'
|
2025-12-24 16:44:27 +08:00
|
|
|
}
|
|
|
|
|
}, {
|
|
|
|
|
tableName: 'consumables',
|
2026-01-20 14:31:20 +08:00
|
|
|
timestamps: true,
|
|
|
|
|
indexes: [
|
|
|
|
|
{ fields: ['category'] },
|
|
|
|
|
{ fields: ['status'] },
|
2026-01-29 16:53:29 +08:00
|
|
|
{ fields: ['category', 'status'] },
|
|
|
|
|
{ fields: ['updatedAt'] }
|
2026-01-20 14:31:20 +08:00
|
|
|
]
|
2025-12-24 16:44:27 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
module.exports = Consumable;
|