Files
yunrui_asset/backend/models/Consumable.js
T
zhang1106 384a1a9246 fix(consumable): 修复最大库存字段逻辑并改进耗材管理
将 maxStock 字段从允许 null 改为默认 0 表示无限制
添加耗材创建时的数据验证和错误处理
优化前端耗材管理页面的表单初始化和显示逻辑
添加数据库迁移脚本处理现有数据
2026-02-05 16:26:51 +08:00

77 lines
1.5 KiB
JavaScript

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,
allowNull: false,
defaultValue: 0,
comment: '最大库存,0表示无限制'
},
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'
},
version: {
type: DataTypes.INTEGER,
allowNull: false,
defaultValue: 0,
comment: '乐观锁版本号'
}
}, {
tableName: 'consumables',
timestamps: true,
indexes: [
{ fields: ['category'] },
{ fields: ['status'] },
{ fields: ['category', 'status'] },
{ fields: ['updatedAt'] }
]
});
module.exports = Consumable;