Files
nxxmdata/backend/models/CattlePen.js
2025-09-22 19:09:45 +08:00

90 lines
2.0 KiB
JavaScript

const { DataTypes } = require('sequelize');
const { sequelize } = require('../config/database-simple');
const CattlePen = sequelize.define('CattlePen', {
id: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true,
allowNull: false
},
name: {
type: DataTypes.STRING(100),
allowNull: false,
comment: '栏舍名称'
},
code: {
type: DataTypes.STRING(50),
allowNull: false,
unique: true,
comment: '栏舍编号'
},
type: {
type: DataTypes.ENUM('育成栏', '产房', '配种栏', '隔离栏', '治疗栏'),
allowNull: false,
comment: '栏舍类型'
},
capacity: {
type: DataTypes.INTEGER,
allowNull: false,
comment: '栏舍容量'
},
currentCount: {
type: DataTypes.INTEGER,
allowNull: false,
defaultValue: 0,
field: 'current_count',
comment: '当前牛只数量'
},
area: {
type: DataTypes.DECIMAL(10, 2),
allowNull: false,
comment: '面积(平方米)'
},
location: {
type: DataTypes.TEXT,
allowNull: true,
comment: '位置描述'
},
status: {
type: DataTypes.ENUM('启用', '停用'),
allowNull: false,
defaultValue: '启用',
comment: '状态'
},
remark: {
type: DataTypes.TEXT,
allowNull: true,
comment: '备注'
},
farmId: {
type: DataTypes.INTEGER,
allowNull: true,
field: 'farm_id',
comment: '所属农场ID'
}
}, {
tableName: 'cattle_pens',
timestamps: true,
createdAt: 'created_at',
updatedAt: 'updated_at',
comment: '栏舍设置表'
});
// 关联关系已在 models/index.js 中定义
// CattlePen.associate = (models) => {
// // 栏舍属于农场
// CattlePen.belongsTo(models.Farm, {
// foreignKey: 'farmId',
// as: 'farm'
// });
// // 栏舍有多个动物
// CattlePen.hasMany(models.Animal, {
// foreignKey: 'penId',
// as: 'animals'
// });
// };
module.exports = CattlePen;