85 lines
1.7 KiB
JavaScript
85 lines
1.7 KiB
JavaScript
const sequelize = require('../config/database');
|
|
const { DataTypes } = require('sequelize');
|
|
const Department = require('./Department');
|
|
const Position = require('./Position');
|
|
|
|
const AdminStaff = sequelize.define('AdminStaff', {
|
|
id: {
|
|
type: DataTypes.INTEGER,
|
|
primaryKey: true,
|
|
autoIncrement: true
|
|
},
|
|
name: {
|
|
type: DataTypes.STRING,
|
|
allowNull: false,
|
|
comment: '员工姓名'
|
|
},
|
|
department_id: {
|
|
type: DataTypes.INTEGER,
|
|
allowNull: false,
|
|
references: {
|
|
model: Department,
|
|
key: 'id'
|
|
},
|
|
comment: '所属部门ID'
|
|
},
|
|
position_id: {
|
|
type: DataTypes.INTEGER,
|
|
allowNull: false,
|
|
references: {
|
|
model: Position,
|
|
key: 'id'
|
|
},
|
|
comment: '任职岗位ID'
|
|
},
|
|
phone: {
|
|
type: DataTypes.STRING,
|
|
allowNull: false,
|
|
unique: true,
|
|
comment: '联系电话'
|
|
},
|
|
id_card: {
|
|
type: DataTypes.STRING,
|
|
allowNull: true,
|
|
comment: '身份证号码'
|
|
},
|
|
status: {
|
|
type: DataTypes.BOOLEAN,
|
|
allowNull: false,
|
|
defaultValue: true,
|
|
comment: '账号使用状态'
|
|
}
|
|
}, {
|
|
tableName: 'government_admin_staff',
|
|
indexes: [
|
|
{
|
|
name: 'idx_admin_staff_department_id',
|
|
fields: ['department_id']
|
|
},
|
|
{
|
|
name: 'idx_admin_staff_position_id',
|
|
fields: ['position_id']
|
|
},
|
|
{
|
|
name: 'idx_admin_staff_name',
|
|
fields: ['name']
|
|
},
|
|
{
|
|
name: 'idx_admin_staff_phone',
|
|
fields: ['phone']
|
|
}
|
|
]
|
|
});
|
|
|
|
// 建立关联关系
|
|
AdminStaff.belongsTo(Department, {
|
|
foreignKey: 'department_id',
|
|
as: 'department'
|
|
});
|
|
|
|
AdminStaff.belongsTo(Position, {
|
|
foreignKey: 'position_id',
|
|
as: 'position'
|
|
});
|
|
|
|
module.exports = AdminStaff; |