Files
nxxmdata/bank-backend/models/Project.js

120 lines
2.5 KiB
JavaScript
Raw Normal View History

const { DataTypes } = require('sequelize');
const { sequelize } = require('../config/database');
const Project = sequelize.define('Project', {
id: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true
},
name: {
type: DataTypes.STRING(100),
allowNull: false,
comment: '项目名称'
},
status: {
type: DataTypes.ENUM('supervision', 'completed'),
allowNull: false,
defaultValue: 'supervision',
comment: '项目状态supervision-监管中completed-已结项'
},
farmName: {
type: DataTypes.STRING(200),
allowNull: false,
comment: '养殖场名称'
},
supervisionObject: {
type: DataTypes.STRING(50),
allowNull: false,
comment: '监管对象'
},
supervisionQuantity: {
type: DataTypes.INTEGER,
allowNull: false,
defaultValue: 0,
comment: '监管数量'
},
supervisionPeriod: {
type: DataTypes.STRING(50),
allowNull: false,
comment: '监管周期'
},
supervisionAmount: {
type: DataTypes.DECIMAL(15, 2),
allowNull: false,
defaultValue: 0.00,
comment: '监管金额'
},
startTime: {
type: DataTypes.DATEONLY,
allowNull: false,
comment: '起始时间'
},
endTime: {
type: DataTypes.DATEONLY,
allowNull: false,
comment: '结束时间'
},
earTag: {
type: DataTypes.INTEGER,
allowNull: false,
defaultValue: 0,
comment: '耳标数量'
},
collar: {
type: DataTypes.INTEGER,
allowNull: false,
defaultValue: 0,
comment: '项圈数量'
},
host: {
type: DataTypes.INTEGER,
allowNull: false,
defaultValue: 0,
comment: '主机数量'
},
loanOfficer: {
type: DataTypes.STRING(100),
allowNull: true,
comment: '贷款专员'
},
description: {
type: DataTypes.TEXT,
allowNull: true,
comment: '项目描述'
},
createdBy: {
type: DataTypes.INTEGER,
allowNull: true,
comment: '创建人ID'
},
updatedBy: {
type: DataTypes.INTEGER,
allowNull: true,
comment: '更新人ID'
}
}, {
tableName: 'projects',
timestamps: true,
createdAt: 'createdAt',
updatedAt: 'updatedAt',
comment: '项目清单表'
});
// 定义关联关系
Project.associate = (models) => {
// 项目与用户关联(创建人)
Project.belongsTo(models.User, {
foreignKey: 'createdBy',
as: 'creator'
});
// 项目与用户关联(更新人)
Project.belongsTo(models.User, {
foreignKey: 'updatedBy',
as: 'updater'
});
};
module.exports = Project;