修改保险后端代码,政府前端代码
This commit is contained in:
@@ -13,9 +13,11 @@ class BaseModel extends Model {
|
||||
*/
|
||||
getSafeInfo(excludeFields = ['password', 'pin', 'secret']) {
|
||||
const data = this.get({ plain: true });
|
||||
excludeFields.forEach(field => {
|
||||
delete data[field];
|
||||
});
|
||||
if (Array.isArray(excludeFields)) {
|
||||
excludeFields.forEach(field => {
|
||||
delete data[field];
|
||||
});
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
55
bank-backend/models/Department.js
Normal file
55
bank-backend/models/Department.js
Normal file
@@ -0,0 +1,55 @@
|
||||
/**
|
||||
* 部门模型
|
||||
* @file Department.js
|
||||
* @description 部门数据模型
|
||||
*/
|
||||
const { DataTypes } = require('sequelize');
|
||||
const { sequelize } = require('../config/database');
|
||||
|
||||
const Department = sequelize.define('Department', {
|
||||
id: {
|
||||
type: DataTypes.INTEGER,
|
||||
primaryKey: true,
|
||||
autoIncrement: true
|
||||
},
|
||||
name: {
|
||||
type: DataTypes.STRING(100),
|
||||
allowNull: false,
|
||||
comment: '部门名称'
|
||||
},
|
||||
description: {
|
||||
type: DataTypes.TEXT,
|
||||
allowNull: true,
|
||||
comment: '部门描述'
|
||||
},
|
||||
manager_id: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: true,
|
||||
comment: '部门经理ID'
|
||||
},
|
||||
status: {
|
||||
type: DataTypes.ENUM('active', 'inactive'),
|
||||
allowNull: false,
|
||||
defaultValue: 'active',
|
||||
comment: '部门状态'
|
||||
},
|
||||
created_at: {
|
||||
type: DataTypes.DATE,
|
||||
allowNull: false,
|
||||
defaultValue: DataTypes.NOW
|
||||
},
|
||||
updated_at: {
|
||||
type: DataTypes.DATE,
|
||||
allowNull: false,
|
||||
defaultValue: DataTypes.NOW
|
||||
}
|
||||
}, {
|
||||
sequelize,
|
||||
tableName: 'bank_departments',
|
||||
modelName: 'Department',
|
||||
timestamps: true,
|
||||
createdAt: 'created_at',
|
||||
updatedAt: 'updated_at'
|
||||
});
|
||||
|
||||
module.exports = Department;
|
||||
82
bank-backend/models/Employee.js
Normal file
82
bank-backend/models/Employee.js
Normal file
@@ -0,0 +1,82 @@
|
||||
/**
|
||||
* 员工模型
|
||||
* @file Employee.js
|
||||
* @description 员工数据模型
|
||||
*/
|
||||
const { DataTypes } = require('sequelize');
|
||||
const { sequelize } = require('../config/database');
|
||||
|
||||
const Employee = sequelize.define('Employee', {
|
||||
id: {
|
||||
type: DataTypes.INTEGER,
|
||||
primaryKey: true,
|
||||
autoIncrement: true
|
||||
},
|
||||
name: {
|
||||
type: DataTypes.STRING(50),
|
||||
allowNull: false,
|
||||
comment: '员工姓名'
|
||||
},
|
||||
employee_id: {
|
||||
type: DataTypes.STRING(20),
|
||||
allowNull: false,
|
||||
unique: true,
|
||||
comment: '员工编号'
|
||||
},
|
||||
department_id: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
comment: '部门ID'
|
||||
},
|
||||
position_id: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
comment: '职位ID'
|
||||
},
|
||||
phone: {
|
||||
type: DataTypes.STRING(20),
|
||||
allowNull: true,
|
||||
comment: '联系电话'
|
||||
},
|
||||
email: {
|
||||
type: DataTypes.STRING(100),
|
||||
allowNull: true,
|
||||
comment: '邮箱地址'
|
||||
},
|
||||
hire_date: {
|
||||
type: DataTypes.DATEONLY,
|
||||
allowNull: false,
|
||||
comment: '入职日期'
|
||||
},
|
||||
salary: {
|
||||
type: DataTypes.BIGINT,
|
||||
allowNull: false,
|
||||
defaultValue: 0,
|
||||
comment: '薪资(分)'
|
||||
},
|
||||
status: {
|
||||
type: DataTypes.ENUM('active', 'inactive', 'resigned'),
|
||||
allowNull: false,
|
||||
defaultValue: 'active',
|
||||
comment: '员工状态:在职、离职、已辞职'
|
||||
},
|
||||
created_at: {
|
||||
type: DataTypes.DATE,
|
||||
allowNull: false,
|
||||
defaultValue: DataTypes.NOW
|
||||
},
|
||||
updated_at: {
|
||||
type: DataTypes.DATE,
|
||||
allowNull: false,
|
||||
defaultValue: DataTypes.NOW
|
||||
}
|
||||
}, {
|
||||
sequelize,
|
||||
tableName: 'bank_employees',
|
||||
modelName: 'Employee',
|
||||
timestamps: true,
|
||||
createdAt: 'created_at',
|
||||
updatedAt: 'updated_at'
|
||||
});
|
||||
|
||||
module.exports = Employee;
|
||||
93
bank-backend/models/LoanProduct.js
Normal file
93
bank-backend/models/LoanProduct.js
Normal file
@@ -0,0 +1,93 @@
|
||||
/**
|
||||
* 贷款产品模型
|
||||
* @file LoanProduct.js
|
||||
* @description 贷款产品数据模型
|
||||
*/
|
||||
const { DataTypes } = require('sequelize');
|
||||
const { sequelize } = require('../config/database');
|
||||
|
||||
const LoanProduct = sequelize.define('LoanProduct', {
|
||||
id: {
|
||||
type: DataTypes.INTEGER,
|
||||
primaryKey: true,
|
||||
autoIncrement: true
|
||||
},
|
||||
name: {
|
||||
type: DataTypes.STRING(100),
|
||||
allowNull: false,
|
||||
comment: '产品名称'
|
||||
},
|
||||
code: {
|
||||
type: DataTypes.STRING(50),
|
||||
allowNull: false,
|
||||
unique: true,
|
||||
comment: '产品代码'
|
||||
},
|
||||
type: {
|
||||
type: DataTypes.ENUM('personal', 'business', 'mortgage', 'credit'),
|
||||
allowNull: false,
|
||||
comment: '产品类型:个人贷款、企业贷款、抵押贷款、信用贷款'
|
||||
},
|
||||
description: {
|
||||
type: DataTypes.TEXT,
|
||||
allowNull: true,
|
||||
comment: '产品描述'
|
||||
},
|
||||
min_amount: {
|
||||
type: DataTypes.BIGINT,
|
||||
allowNull: false,
|
||||
defaultValue: 0,
|
||||
comment: '最小贷款金额(分)'
|
||||
},
|
||||
max_amount: {
|
||||
type: DataTypes.BIGINT,
|
||||
allowNull: false,
|
||||
defaultValue: 0,
|
||||
comment: '最大贷款金额(分)'
|
||||
},
|
||||
interest_rate: {
|
||||
type: DataTypes.DECIMAL(5, 4),
|
||||
allowNull: false,
|
||||
comment: '年化利率'
|
||||
},
|
||||
term_min: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
comment: '最短期限(月)'
|
||||
},
|
||||
term_max: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
comment: '最长期限(月)'
|
||||
},
|
||||
requirements: {
|
||||
type: DataTypes.JSON,
|
||||
allowNull: true,
|
||||
comment: '申请要求(JSON格式)'
|
||||
},
|
||||
status: {
|
||||
type: DataTypes.ENUM('draft', 'active', 'inactive'),
|
||||
allowNull: false,
|
||||
defaultValue: 'draft',
|
||||
comment: '产品状态:草稿、启用、停用'
|
||||
},
|
||||
created_at: {
|
||||
type: DataTypes.DATE,
|
||||
allowNull: false,
|
||||
defaultValue: DataTypes.NOW
|
||||
},
|
||||
updated_at: {
|
||||
type: DataTypes.DATE,
|
||||
allowNull: false,
|
||||
defaultValue: DataTypes.NOW
|
||||
}
|
||||
}, {
|
||||
sequelize,
|
||||
tableName: 'bank_loan_products',
|
||||
modelName: 'LoanProduct',
|
||||
timestamps: true,
|
||||
createdAt: 'created_at',
|
||||
updatedAt: 'updated_at'
|
||||
});
|
||||
|
||||
module.exports = LoanProduct;
|
||||
67
bank-backend/models/Position.js
Normal file
67
bank-backend/models/Position.js
Normal file
@@ -0,0 +1,67 @@
|
||||
/**
|
||||
* 职位模型
|
||||
* @file Position.js
|
||||
* @description 职位数据模型
|
||||
*/
|
||||
const { DataTypes } = require('sequelize');
|
||||
const { sequelize } = require('../config/database');
|
||||
|
||||
const Position = sequelize.define('Position', {
|
||||
id: {
|
||||
type: DataTypes.INTEGER,
|
||||
primaryKey: true,
|
||||
autoIncrement: true
|
||||
},
|
||||
name: {
|
||||
type: DataTypes.STRING(100),
|
||||
allowNull: false,
|
||||
comment: '职位名称'
|
||||
},
|
||||
level: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
comment: '职位级别'
|
||||
},
|
||||
description: {
|
||||
type: DataTypes.TEXT,
|
||||
allowNull: true,
|
||||
comment: '职位描述'
|
||||
},
|
||||
min_salary: {
|
||||
type: DataTypes.BIGINT,
|
||||
allowNull: false,
|
||||
defaultValue: 0,
|
||||
comment: '最低薪资(分)'
|
||||
},
|
||||
max_salary: {
|
||||
type: DataTypes.BIGINT,
|
||||
allowNull: false,
|
||||
defaultValue: 0,
|
||||
comment: '最高薪资(分)'
|
||||
},
|
||||
status: {
|
||||
type: DataTypes.ENUM('active', 'inactive'),
|
||||
allowNull: false,
|
||||
defaultValue: 'active',
|
||||
comment: '职位状态'
|
||||
},
|
||||
created_at: {
|
||||
type: DataTypes.DATE,
|
||||
allowNull: false,
|
||||
defaultValue: DataTypes.NOW
|
||||
},
|
||||
updated_at: {
|
||||
type: DataTypes.DATE,
|
||||
allowNull: false,
|
||||
defaultValue: DataTypes.NOW
|
||||
}
|
||||
}, {
|
||||
sequelize,
|
||||
tableName: 'bank_positions',
|
||||
modelName: 'Position',
|
||||
timestamps: true,
|
||||
createdAt: 'created_at',
|
||||
updatedAt: 'updated_at'
|
||||
});
|
||||
|
||||
module.exports = Position;
|
||||
86
bank-backend/models/Report.js
Normal file
86
bank-backend/models/Report.js
Normal file
@@ -0,0 +1,86 @@
|
||||
const { DataTypes } = require('sequelize');
|
||||
const sequelize = require('../config/database');
|
||||
const BaseModel = require('./BaseModel');
|
||||
|
||||
class Report extends BaseModel {
|
||||
static associate(models) {
|
||||
// 报表属于用户
|
||||
Report.belongsTo(models.User, {
|
||||
as: 'creator',
|
||||
foreignKey: 'createdBy',
|
||||
targetKey: 'id'
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Report.init({
|
||||
id: {
|
||||
type: DataTypes.INTEGER,
|
||||
primaryKey: true,
|
||||
autoIncrement: true
|
||||
},
|
||||
name: {
|
||||
type: DataTypes.STRING(255),
|
||||
allowNull: false,
|
||||
comment: '报表名称'
|
||||
},
|
||||
type: {
|
||||
type: DataTypes.ENUM('transaction', 'account', 'user'),
|
||||
allowNull: false,
|
||||
comment: '报表类型'
|
||||
},
|
||||
format: {
|
||||
type: DataTypes.ENUM('excel', 'pdf', 'csv'),
|
||||
allowNull: false,
|
||||
comment: '报表格式'
|
||||
},
|
||||
status: {
|
||||
type: DataTypes.ENUM('processing', 'completed', 'failed'),
|
||||
allowNull: false,
|
||||
defaultValue: 'processing',
|
||||
comment: '报表状态'
|
||||
},
|
||||
filePath: {
|
||||
type: DataTypes.STRING(500),
|
||||
allowNull: true,
|
||||
comment: '文件路径'
|
||||
},
|
||||
parameters: {
|
||||
type: DataTypes.JSON,
|
||||
allowNull: true,
|
||||
comment: '生成参数'
|
||||
},
|
||||
data: {
|
||||
type: DataTypes.JSON,
|
||||
allowNull: true,
|
||||
comment: '报表数据'
|
||||
},
|
||||
error: {
|
||||
type: DataTypes.TEXT,
|
||||
allowNull: true,
|
||||
comment: '错误信息'
|
||||
},
|
||||
createdBy: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
comment: '创建人ID'
|
||||
}
|
||||
}, {
|
||||
sequelize,
|
||||
modelName: 'Report',
|
||||
tableName: 'reports',
|
||||
comment: '报表记录表',
|
||||
indexes: [
|
||||
{
|
||||
fields: ['type', 'status']
|
||||
},
|
||||
{
|
||||
fields: ['createdBy']
|
||||
},
|
||||
{
|
||||
fields: ['createdAt']
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
module.exports = Report;
|
||||
@@ -10,6 +10,11 @@ const User = require('./User');
|
||||
const Role = require('./Role');
|
||||
const Account = require('./Account');
|
||||
const Transaction = require('./Transaction');
|
||||
const LoanProduct = require('./LoanProduct');
|
||||
const Employee = require('./Employee');
|
||||
const Department = require('./Department');
|
||||
const Position = require('./Position');
|
||||
const Report = require('./Report');
|
||||
|
||||
// 定义模型关联关系
|
||||
|
||||
@@ -50,11 +55,52 @@ Transaction.belongsTo(Account, {
|
||||
// 交易记录与用户关联(通过账户)
|
||||
// 移除不合理的Transaction->User through Account的belongsTo定义,避免错误外键映射
|
||||
|
||||
// 员工与部门关联
|
||||
Employee.belongsTo(Department, {
|
||||
foreignKey: 'department_id',
|
||||
as: 'department',
|
||||
targetKey: 'id'
|
||||
});
|
||||
|
||||
Department.hasMany(Employee, {
|
||||
foreignKey: 'department_id',
|
||||
as: 'employees'
|
||||
});
|
||||
|
||||
// 员工与职位关联
|
||||
Employee.belongsTo(Position, {
|
||||
foreignKey: 'position_id',
|
||||
as: 'position',
|
||||
targetKey: 'id'
|
||||
});
|
||||
|
||||
Position.hasMany(Employee, {
|
||||
foreignKey: 'position_id',
|
||||
as: 'employees'
|
||||
});
|
||||
|
||||
// 报表与用户关联
|
||||
Report.belongsTo(User, {
|
||||
foreignKey: 'createdBy',
|
||||
as: 'creator',
|
||||
targetKey: 'id'
|
||||
});
|
||||
|
||||
User.hasMany(Report, {
|
||||
foreignKey: 'createdBy',
|
||||
as: 'reports'
|
||||
});
|
||||
|
||||
// 导出所有模型和数据库实例
|
||||
module.exports = {
|
||||
sequelize,
|
||||
User,
|
||||
Role,
|
||||
Account,
|
||||
Transaction
|
||||
Transaction,
|
||||
LoanProduct,
|
||||
Employee,
|
||||
Department,
|
||||
Position,
|
||||
Report
|
||||
};
|
||||
Reference in New Issue
Block a user