修改后端接口

This commit is contained in:
2025-09-25 17:43:54 +08:00
parent 5b6b7e0a96
commit 76b5393182
31 changed files with 2155 additions and 468 deletions

View File

@@ -46,7 +46,7 @@ const getEmployees = async (req, res) => {
where,
limit,
offset,
order: [['createdAt', 'DESC']],
order: [['created_at', 'DESC']],
attributes: {
exclude: ['password'] // 不返回密码
}

View File

@@ -35,6 +35,9 @@ const getApplications = async (req, res) => {
where.customer_phone = { [Op.like]: `%${searchValue}%` };
} else if (searchField === 'customerIdCard') {
where.customer_id_card = { [Op.like]: `%${searchValue}%` };
} else if (searchField === 'applicationNumber') {
// 数据库中实际没有applicationNumber字段使用id作为替代
where.id = { [Op.like]: `%${searchValue}%` };
}
}
@@ -47,8 +50,17 @@ const getApplications = async (req, res) => {
const offset = (parseInt(page) - 1) * parseInt(pageSize);
const limit = parseInt(pageSize);
// 排序参数
const order = [[sortField, sortOrder.toUpperCase()]];
// 排序参数 - 映射字段名
const fieldMapping = {
'createdAt': 'created_at',
'updatedAt': 'updated_at',
'applicationDate': 'application_date',
'loanAmount': 'loan_amount',
'loanTerm': 'loan_term',
'interestRate': 'interest_rate'
};
const dbSortField = fieldMapping[sortField] || sortField;
const order = [[dbSortField, sortOrder.toUpperCase()]];
// 查询数据
const { count, rows } = await LoanApplication.findAndCountAll({

View File

@@ -37,6 +37,9 @@ const getContracts = async (req, res) => {
where.customer_phone = { [Op.like]: `%${searchValue}%` };
} else if (searchField === 'customerIdCard') {
where.customer_id_card = { [Op.like]: `%${searchValue}%` };
} else if (searchField === 'applicationNumber') {
// 数据库中实际没有applicationNumber字段使用id作为替代
where.id = { [Op.like]: `%${searchValue}%` };
}
}
@@ -49,8 +52,17 @@ const getContracts = async (req, res) => {
const offset = (parseInt(page) - 1) * parseInt(pageSize);
const limit = parseInt(pageSize);
// 排序参数
const order = [[sortField, sortOrder.toUpperCase()]];
// 排序参数 - 映射字段名
const fieldMapping = {
'createdAt': 'created_at',
'updatedAt': 'updated_at',
'contractDate': 'contract_date',
'loanAmount': 'loan_amount',
'loanTerm': 'loan_term',
'interestRate': 'interest_rate'
};
const dbSortField = fieldMapping[sortField] || sortField;
const order = [[dbSortField, sortOrder.toUpperCase()]];
// 查询数据
const { count, rows } = await LoanContract.findAndCountAll({

View File

@@ -200,6 +200,14 @@ const createLoanProduct = async (req, res) => {
});
}
// 检查用户信息
if (!req.user || !req.user.id) {
return res.status(401).json({
success: false,
message: '用户信息无效'
});
}
const product = await LoanProduct.create({
productName,
loanAmount,

View File

@@ -68,21 +68,14 @@ module.exports = (sequelize) => {
type: DataTypes.DATE,
allowNull: true,
comment: '锁定到期时间'
},
createdBy: {
type: DataTypes.INTEGER,
allowNull: true,
comment: '创建人ID'
},
updatedBy: {
type: DataTypes.INTEGER,
allowNull: true,
comment: '更新人ID'
}
}, {
tableName: 'bank_employees',
timestamps: true,
createdAt: 'created_at',
updatedAt: 'updated_at',
paranoid: true,
deletedAt: 'deleted_at',
comment: '银行员工表',
hooks: {
beforeSave: async (employee) => {

View File

@@ -107,7 +107,11 @@ Role.init({
}, {
sequelize,
tableName: 'bank_roles',
modelName: 'Role'
modelName: 'Role',
timestamps: true,
underscored: true,
createdAt: 'created_at',
updatedAt: 'updated_at'
});
module.exports = Role;

View File

@@ -0,0 +1,42 @@
/**
* 测试创建贷款商品
*/
const { LoanProduct } = require('./models');
async function testCreateLoanProduct() {
try {
console.log('🧪 测试创建贷款商品...');
const productData = {
productName: '测试贷款产品',
loanAmount: '50000~5000000',
loanTerm: 12,
interestRate: 5.5,
serviceArea: '北京市',
servicePhone: '13800138000',
productDescription: '这是一个测试贷款产品',
applicationRequirements: '需要提供身份证和收入证明',
requiredDocuments: '身份证、收入证明、银行流水',
approvalProcess: '提交申请->审核->放款',
riskLevel: 'LOW',
minLoanAmount: 50000,
maxLoanAmount: 5000000,
createdBy: 2,
updatedBy: 2
};
console.log('创建数据:', productData);
const product = await LoanProduct.create(productData);
console.log('✅ 创建成功:', product.toJSON());
} catch (error) {
console.error('❌ 创建失败:', error.message);
console.error('详细错误:', error);
}
process.exit(0);
}
testCreateLoanProduct();

View File

@@ -1,16 +0,0 @@
const axios = require('axios');
async function testLogin() {
try {
console.log('测试登录API...');
const response = await axios.post('http://localhost:3001/api/auth/login', {
username: 'admin',
password: 'Admin123456'
});
console.log('登录成功:', response.data);
} catch (error) {
console.log('登录失败:', error.response ? error.response.data : error.message);
}
}
testLogin();