添加银行政府后端接口
This commit is contained in:
85
government-backend/models/AdminStaff.js
Normal file
85
government-backend/models/AdminStaff.js
Normal file
@@ -0,0 +1,85 @@
|
||||
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;
|
||||
41
government-backend/models/Department.js
Normal file
41
government-backend/models/Department.js
Normal file
@@ -0,0 +1,41 @@
|
||||
const sequelize = require('../config/database');
|
||||
const { DataTypes } = require('sequelize');
|
||||
|
||||
const Department = sequelize.define('Department', {
|
||||
id: {
|
||||
type: DataTypes.INTEGER,
|
||||
primaryKey: true,
|
||||
autoIncrement: true
|
||||
},
|
||||
name: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
unique: true,
|
||||
comment: '部门名称'
|
||||
},
|
||||
description: {
|
||||
type: DataTypes.TEXT,
|
||||
allowNull: true,
|
||||
comment: '部门描述'
|
||||
},
|
||||
created_by: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: true,
|
||||
comment: '创建人ID'
|
||||
},
|
||||
updated_by: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: true,
|
||||
comment: '更新人ID'
|
||||
}
|
||||
}, {
|
||||
tableName: 'government_departments',
|
||||
indexes: [
|
||||
{
|
||||
name: 'idx_department_name',
|
||||
fields: ['name']
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
module.exports = Department;
|
||||
66
government-backend/models/Position.js
Normal file
66
government-backend/models/Position.js
Normal file
@@ -0,0 +1,66 @@
|
||||
const sequelize = require('../config/database');
|
||||
const { DataTypes } = require('sequelize');
|
||||
const Department = require('./Department');
|
||||
|
||||
const Position = sequelize.define('Position', {
|
||||
id: {
|
||||
type: DataTypes.INTEGER,
|
||||
primaryKey: true,
|
||||
autoIncrement: true
|
||||
},
|
||||
department_id: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
references: {
|
||||
model: Department,
|
||||
key: 'id'
|
||||
},
|
||||
comment: '所属部门ID'
|
||||
},
|
||||
name: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
comment: '岗位名称'
|
||||
},
|
||||
has_permission: {
|
||||
type: DataTypes.BOOLEAN,
|
||||
allowNull: false,
|
||||
defaultValue: false,
|
||||
comment: '是否已设置权限'
|
||||
},
|
||||
created_by: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: true,
|
||||
comment: '创建人ID'
|
||||
},
|
||||
updated_by: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: true,
|
||||
comment: '更新人ID'
|
||||
}
|
||||
}, {
|
||||
tableName: 'government_positions',
|
||||
indexes: [
|
||||
{
|
||||
name: 'idx_position_department_id',
|
||||
fields: ['department_id']
|
||||
},
|
||||
{
|
||||
name: 'idx_position_name',
|
||||
fields: ['name']
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
// 定义关系
|
||||
Department.hasMany(Position, {
|
||||
foreignKey: 'department_id',
|
||||
as: 'positions'
|
||||
});
|
||||
|
||||
Position.belongsTo(Department, {
|
||||
foreignKey: 'department_id',
|
||||
as: 'department'
|
||||
});
|
||||
|
||||
module.exports = Position;
|
||||
Reference in New Issue
Block a user