添加银行端后端接口

This commit is contained in:
2025-09-24 17:49:32 +08:00
parent b58ed724b0
commit 111ebaec84
95 changed files with 22115 additions and 4246 deletions

View File

@@ -0,0 +1,133 @@
'use strict'
module.exports = {
async up(queryInterface, Sequelize) {
await queryInterface.createTable('installation_tasks', {
id: {
type: Sequelize.DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true,
comment: '主键ID'
},
applicationNumber: {
type: Sequelize.DataTypes.STRING(50),
allowNull: false,
unique: true,
comment: '申请单号'
},
contractNumber: {
type: Sequelize.DataTypes.STRING(50),
allowNull: false,
comment: '放款合同编号'
},
productName: {
type: Sequelize.DataTypes.STRING(100),
allowNull: false,
comment: '产品名称'
},
customerName: {
type: Sequelize.DataTypes.STRING(50),
allowNull: false,
comment: '客户姓名'
},
idType: {
type: Sequelize.DataTypes.ENUM('ID_CARD', 'PASSPORT', 'OTHER'),
allowNull: false,
defaultValue: 'ID_CARD',
comment: '证件类型'
},
idNumber: {
type: Sequelize.DataTypes.STRING(50),
allowNull: false,
comment: '证件号码'
},
assetType: {
type: Sequelize.DataTypes.STRING(50),
allowNull: false,
comment: '养殖生资种类'
},
equipmentToInstall: {
type: Sequelize.DataTypes.STRING(100),
allowNull: false,
comment: '待安装设备'
},
installationStatus: {
type: Sequelize.DataTypes.ENUM('pending', 'in-progress', 'completed', 'failed'),
allowNull: false,
defaultValue: 'pending',
comment: '安装状态'
},
taskGenerationTime: {
type: Sequelize.DataTypes.DATE,
allowNull: false,
comment: '生成安装任务时间'
},
completionTime: {
type: Sequelize.DataTypes.DATE,
allowNull: true,
comment: '安装完成生效时间'
},
installationNotes: {
type: Sequelize.DataTypes.TEXT,
allowNull: true,
comment: '安装备注'
},
installerName: {
type: Sequelize.DataTypes.STRING(50),
allowNull: true,
comment: '安装员姓名'
},
installerPhone: {
type: Sequelize.DataTypes.STRING(20),
allowNull: true,
comment: '安装员电话'
},
installationAddress: {
type: Sequelize.DataTypes.STRING(200),
allowNull: true,
comment: '安装地址'
},
createdBy: {
type: Sequelize.DataTypes.INTEGER,
allowNull: false,
comment: '创建人ID'
},
updatedBy: {
type: Sequelize.DataTypes.INTEGER,
allowNull: true,
comment: '更新人ID'
},
createdAt: {
type: Sequelize.DataTypes.DATE,
allowNull: false,
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP'),
comment: '创建时间'
},
updatedAt: {
type: Sequelize.DataTypes.DATE,
allowNull: false,
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'),
comment: '更新时间'
}
}, {
comment: '待安装任务表'
})
// 添加索引
await queryInterface.addIndex('installation_tasks', ['contractNumber'], {
name: 'idx_installation_tasks_contract_number'
})
await queryInterface.addIndex('installation_tasks', ['installationStatus'], {
name: 'idx_installation_tasks_status'
})
await queryInterface.addIndex('installation_tasks', ['createdBy'], {
name: 'idx_installation_tasks_created_by'
})
},
async down(queryInterface, Sequelize) {
await queryInterface.dropTable('installation_tasks')
}
}

View File

@@ -0,0 +1,135 @@
'use strict'
module.exports = {
async up(queryInterface, Sequelize) {
await queryInterface.createTable('completed_supervisions', {
id: {
type: Sequelize.DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true,
comment: '主键ID'
},
applicationNumber: {
type: Sequelize.DataTypes.STRING(50),
allowNull: false,
unique: true,
comment: '申请单号'
},
contractNumber: {
type: Sequelize.DataTypes.STRING(50),
allowNull: false,
comment: '放款合同编号'
},
productName: {
type: Sequelize.DataTypes.STRING(100),
allowNull: false,
comment: '产品名称'
},
customerName: {
type: Sequelize.DataTypes.STRING(50),
allowNull: false,
comment: '客户姓名'
},
idType: {
type: Sequelize.DataTypes.ENUM('ID_CARD', 'PASSPORT', 'OTHER'),
allowNull: false,
defaultValue: 'ID_CARD',
comment: '证件类型'
},
idNumber: {
type: Sequelize.DataTypes.STRING(50),
allowNull: false,
comment: '证件号码'
},
assetType: {
type: Sequelize.DataTypes.STRING(50),
allowNull: false,
comment: '养殖生资种类'
},
assetQuantity: {
type: Sequelize.DataTypes.INTEGER,
allowNull: false,
defaultValue: 0,
comment: '监管生资数量'
},
totalRepaymentPeriods: {
type: Sequelize.DataTypes.INTEGER,
allowNull: false,
defaultValue: 0,
comment: '总还款期数'
},
settlementStatus: {
type: Sequelize.DataTypes.ENUM('settled', 'unsettled', 'partial'),
allowNull: false,
defaultValue: 'unsettled',
comment: '结清状态'
},
settlementDate: {
type: Sequelize.DataTypes.DATEONLY,
allowNull: true,
comment: '结清日期'
},
importTime: {
type: Sequelize.DataTypes.DATE,
allowNull: false,
comment: '结清任务导入时间'
},
settlementAmount: {
type: Sequelize.DataTypes.DECIMAL(15, 2),
allowNull: true,
comment: '结清金额'
},
remainingAmount: {
type: Sequelize.DataTypes.DECIMAL(15, 2),
allowNull: true,
comment: '剩余金额'
},
settlementNotes: {
type: Sequelize.DataTypes.TEXT,
allowNull: true,
comment: '结清备注'
},
createdBy: {
type: Sequelize.DataTypes.INTEGER,
allowNull: false,
comment: '创建人ID'
},
updatedBy: {
type: Sequelize.DataTypes.INTEGER,
allowNull: true,
comment: '更新人ID'
},
createdAt: {
type: Sequelize.DataTypes.DATE,
allowNull: false,
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP'),
comment: '创建时间'
},
updatedAt: {
type: Sequelize.DataTypes.DATE,
allowNull: false,
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'),
comment: '更新时间'
}
}, {
comment: '监管任务已结项表'
})
// 添加索引
await queryInterface.addIndex('completed_supervisions', ['contractNumber'], {
name: 'idx_completed_supervisions_contract_number'
})
await queryInterface.addIndex('completed_supervisions', ['settlementStatus'], {
name: 'idx_completed_supervisions_settlement_status'
})
await queryInterface.addIndex('completed_supervisions', ['createdBy'], {
name: 'idx_completed_supervisions_created_by'
})
},
async down(queryInterface, Sequelize) {
await queryInterface.dropTable('completed_supervisions')
}
}

View File

@@ -0,0 +1,147 @@
'use strict';
module.exports = {
async up(queryInterface, Sequelize) {
await queryInterface.createTable('loan_products', {
id: {
type: Sequelize.DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true,
comment: '主键ID'
},
productName: {
type: Sequelize.DataTypes.STRING(200),
allowNull: false,
comment: '贷款产品名称'
},
loanAmount: {
type: Sequelize.DataTypes.STRING(100),
allowNull: false,
comment: '贷款额度'
},
loanTerm: {
type: Sequelize.DataTypes.INTEGER,
allowNull: false,
comment: '贷款周期(月)'
},
interestRate: {
type: Sequelize.DataTypes.DECIMAL(5, 2),
allowNull: false,
comment: '贷款利率(%'
},
serviceArea: {
type: Sequelize.DataTypes.STRING(200),
allowNull: false,
comment: '服务区域'
},
servicePhone: {
type: Sequelize.DataTypes.STRING(20),
allowNull: false,
comment: '服务电话'
},
totalCustomers: {
type: Sequelize.DataTypes.INTEGER,
allowNull: false,
defaultValue: 0,
comment: '服务客户总数量'
},
supervisionCustomers: {
type: Sequelize.DataTypes.INTEGER,
allowNull: false,
defaultValue: 0,
comment: '监管中客户数量'
},
completedCustomers: {
type: Sequelize.DataTypes.INTEGER,
allowNull: false,
defaultValue: 0,
comment: '已结项客户数量'
},
onSaleStatus: {
type: Sequelize.DataTypes.BOOLEAN,
allowNull: false,
defaultValue: true,
comment: '在售状态'
},
productDescription: {
type: Sequelize.DataTypes.TEXT,
allowNull: true,
comment: '产品描述'
},
applicationRequirements: {
type: Sequelize.DataTypes.TEXT,
allowNull: true,
comment: '申请条件'
},
requiredDocuments: {
type: Sequelize.DataTypes.TEXT,
allowNull: true,
comment: '所需材料'
},
approvalProcess: {
type: Sequelize.DataTypes.TEXT,
allowNull: true,
comment: '审批流程'
},
riskLevel: {
type: Sequelize.DataTypes.ENUM('LOW', 'MEDIUM', 'HIGH'),
allowNull: false,
defaultValue: 'MEDIUM',
comment: '风险等级'
},
minLoanAmount: {
type: Sequelize.DataTypes.DECIMAL(15, 2),
allowNull: true,
comment: '最小贷款金额'
},
maxLoanAmount: {
type: Sequelize.DataTypes.DECIMAL(15, 2),
allowNull: true,
comment: '最大贷款金额'
},
createdBy: {
type: Sequelize.DataTypes.INTEGER,
allowNull: false,
comment: '创建人ID'
},
updatedBy: {
type: Sequelize.DataTypes.INTEGER,
allowNull: true,
comment: '更新人ID'
},
createdAt: {
type: Sequelize.DataTypes.DATE,
allowNull: false,
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP'),
comment: '创建时间'
},
updatedAt: {
type: Sequelize.DataTypes.DATE,
allowNull: false,
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'),
comment: '更新时间'
}
}, {
comment: '贷款商品表',
charset: 'utf8mb4',
collate: 'utf8mb4_unicode_ci'
});
// 添加索引
await queryInterface.addIndex('loan_products', ['productName'], {
name: 'idx_loan_products_product_name'
});
await queryInterface.addIndex('loan_products', ['onSaleStatus'], {
name: 'idx_loan_products_on_sale_status'
});
await queryInterface.addIndex('loan_products', ['createdBy'], {
name: 'idx_loan_products_created_by'
});
},
async down(queryInterface, Sequelize) {
await queryInterface.dropTable('loan_products');
}
};

View File

@@ -0,0 +1,170 @@
/**
* 创建贷款申请表迁移
* @file 20241220000007-create-loan-applications.js
*/
'use strict';
module.exports = {
up: async (queryInterface, Sequelize) => {
await queryInterface.createTable('bank_loan_applications', {
id: {
type: Sequelize.INTEGER,
primaryKey: true,
autoIncrement: true
},
applicationNumber: {
type: Sequelize.STRING(50),
allowNull: false,
unique: true,
comment: '申请单号'
},
productName: {
type: Sequelize.STRING(200),
allowNull: false,
comment: '贷款产品名称'
},
farmerName: {
type: Sequelize.STRING(100),
allowNull: false,
comment: '申请养殖户姓名'
},
borrowerName: {
type: Sequelize.STRING(100),
allowNull: false,
comment: '贷款人姓名'
},
borrowerIdNumber: {
type: Sequelize.STRING(20),
allowNull: false,
comment: '贷款人身份证号'
},
assetType: {
type: Sequelize.STRING(50),
allowNull: false,
comment: '生资种类'
},
applicationQuantity: {
type: Sequelize.STRING(100),
allowNull: false,
comment: '申请数量'
},
amount: {
type: Sequelize.DECIMAL(15, 2),
allowNull: false,
comment: '申请额度'
},
status: {
type: Sequelize.ENUM(
'pending_review',
'verification_pending',
'pending_binding',
'approved',
'rejected'
),
allowNull: false,
defaultValue: 'pending_review',
comment: '申请状态'
},
type: {
type: Sequelize.ENUM('personal', 'business', 'mortgage'),
allowNull: false,
defaultValue: 'personal',
comment: '申请类型'
},
term: {
type: Sequelize.INTEGER,
allowNull: false,
comment: '申请期限(月)'
},
interestRate: {
type: Sequelize.DECIMAL(5, 2),
allowNull: false,
comment: '预计利率'
},
phone: {
type: Sequelize.STRING(20),
allowNull: false,
comment: '联系电话'
},
purpose: {
type: Sequelize.TEXT,
allowNull: true,
comment: '申请用途'
},
remark: {
type: Sequelize.TEXT,
allowNull: true,
comment: '备注'
},
applicationTime: {
type: Sequelize.DATE,
allowNull: false,
defaultValue: Sequelize.NOW,
comment: '申请时间'
},
approvedTime: {
type: Sequelize.DATE,
allowNull: true,
comment: '审批通过时间'
},
rejectedTime: {
type: Sequelize.DATE,
allowNull: true,
comment: '审批拒绝时间'
},
applicantId: {
type: Sequelize.INTEGER,
allowNull: true,
comment: '申请人ID',
references: {
model: 'bank_users',
key: 'id'
}
},
approvedBy: {
type: Sequelize.INTEGER,
allowNull: true,
comment: '审批人ID',
references: {
model: 'bank_users',
key: 'id'
}
},
rejectedBy: {
type: Sequelize.INTEGER,
allowNull: true,
comment: '拒绝人ID',
references: {
model: 'bank_users',
key: 'id'
}
},
rejectionReason: {
type: Sequelize.TEXT,
allowNull: true,
comment: '拒绝原因'
},
createdAt: {
type: Sequelize.DATE,
allowNull: false,
defaultValue: Sequelize.NOW
},
updatedAt: {
type: Sequelize.DATE,
allowNull: false,
defaultValue: Sequelize.NOW
}
});
// 添加索引
await queryInterface.addIndex('bank_loan_applications', ['applicationNumber']);
await queryInterface.addIndex('bank_loan_applications', ['status']);
await queryInterface.addIndex('bank_loan_applications', ['borrowerName']);
await queryInterface.addIndex('bank_loan_applications', ['farmerName']);
await queryInterface.addIndex('bank_loan_applications', ['applicationTime']);
},
down: async (queryInterface, Sequelize) => {
await queryInterface.dropTable('bank_loan_applications');
}
};

View File

@@ -0,0 +1,93 @@
/**
* 创建审核记录表迁移
* @file 20241220000008-create-audit-records.js
*/
'use strict';
module.exports = {
up: async (queryInterface, Sequelize) => {
await queryInterface.createTable('bank_audit_records', {
id: {
type: Sequelize.INTEGER,
primaryKey: true,
autoIncrement: true
},
applicationId: {
type: Sequelize.INTEGER,
allowNull: false,
comment: '申请ID',
references: {
model: 'bank_loan_applications',
key: 'id'
}
},
action: {
type: Sequelize.ENUM(
'submit',
'approve',
'reject',
'review',
'verification',
'binding'
),
allowNull: false,
comment: '审核动作'
},
auditor: {
type: Sequelize.STRING(100),
allowNull: false,
comment: '审核人'
},
auditorId: {
type: Sequelize.INTEGER,
allowNull: true,
comment: '审核人ID',
references: {
model: 'bank_users',
key: 'id'
}
},
comment: {
type: Sequelize.TEXT,
allowNull: true,
comment: '审核意见'
},
auditTime: {
type: Sequelize.DATE,
allowNull: false,
defaultValue: Sequelize.NOW,
comment: '审核时间'
},
previousStatus: {
type: Sequelize.STRING(50),
allowNull: true,
comment: '审核前状态'
},
newStatus: {
type: Sequelize.STRING(50),
allowNull: true,
comment: '审核后状态'
},
createdAt: {
type: Sequelize.DATE,
allowNull: false,
defaultValue: Sequelize.NOW
},
updatedAt: {
type: Sequelize.DATE,
allowNull: false,
defaultValue: Sequelize.NOW
}
});
// 添加索引
await queryInterface.addIndex('bank_audit_records', ['applicationId']);
await queryInterface.addIndex('bank_audit_records', ['action']);
await queryInterface.addIndex('bank_audit_records', ['auditorId']);
await queryInterface.addIndex('bank_audit_records', ['auditTime']);
},
down: async (queryInterface, Sequelize) => {
await queryInterface.dropTable('bank_audit_records');
}
};

View File

@@ -0,0 +1,177 @@
/**
* 创建贷款合同表迁移
* @file 20241220000009-create-loan-contracts.js
*/
'use strict';
module.exports = {
up: async (queryInterface, Sequelize) => {
await queryInterface.createTable('bank_loan_contracts', {
id: {
type: Sequelize.INTEGER,
primaryKey: true,
autoIncrement: true
},
contractNumber: {
type: Sequelize.STRING(50),
allowNull: false,
unique: true,
comment: '合同编号'
},
applicationNumber: {
type: Sequelize.STRING(50),
allowNull: false,
comment: '申请单号'
},
productName: {
type: Sequelize.STRING(200),
allowNull: false,
comment: '贷款产品名称'
},
farmerName: {
type: Sequelize.STRING(100),
allowNull: false,
comment: '申请养殖户姓名'
},
borrowerName: {
type: Sequelize.STRING(100),
allowNull: false,
comment: '贷款人姓名'
},
borrowerIdNumber: {
type: Sequelize.STRING(20),
allowNull: false,
comment: '贷款人身份证号'
},
assetType: {
type: Sequelize.STRING(50),
allowNull: false,
comment: '生资种类'
},
applicationQuantity: {
type: Sequelize.STRING(100),
allowNull: false,
comment: '申请数量'
},
amount: {
type: Sequelize.DECIMAL(15, 2),
allowNull: false,
comment: '合同金额'
},
paidAmount: {
type: Sequelize.DECIMAL(15, 2),
allowNull: false,
defaultValue: 0,
comment: '已还款金额'
},
status: {
type: Sequelize.ENUM(
'active',
'pending',
'completed',
'defaulted',
'cancelled'
),
allowNull: false,
defaultValue: 'pending',
comment: '合同状态'
},
type: {
type: Sequelize.ENUM(
'livestock_collateral',
'farmer_loan',
'business_loan',
'personal_loan'
),
allowNull: false,
comment: '合同类型'
},
term: {
type: Sequelize.INTEGER,
allowNull: false,
comment: '合同期限(月)'
},
interestRate: {
type: Sequelize.DECIMAL(5, 2),
allowNull: false,
comment: '利率'
},
phone: {
type: Sequelize.STRING(20),
allowNull: false,
comment: '联系电话'
},
purpose: {
type: Sequelize.TEXT,
allowNull: true,
comment: '贷款用途'
},
remark: {
type: Sequelize.TEXT,
allowNull: true,
comment: '备注'
},
contractTime: {
type: Sequelize.DATE,
allowNull: false,
defaultValue: Sequelize.NOW,
comment: '合同签订时间'
},
disbursementTime: {
type: Sequelize.DATE,
allowNull: true,
comment: '放款时间'
},
maturityTime: {
type: Sequelize.DATE,
allowNull: true,
comment: '到期时间'
},
completedTime: {
type: Sequelize.DATE,
allowNull: true,
comment: '完成时间'
},
createdBy: {
type: Sequelize.INTEGER,
allowNull: true,
comment: '创建人ID',
references: {
model: 'bank_users',
key: 'id'
}
},
updatedBy: {
type: Sequelize.INTEGER,
allowNull: true,
comment: '更新人ID',
references: {
model: 'bank_users',
key: 'id'
}
},
createdAt: {
type: Sequelize.DATE,
allowNull: false,
defaultValue: Sequelize.NOW
},
updatedAt: {
type: Sequelize.DATE,
allowNull: false,
defaultValue: Sequelize.NOW
}
});
// 添加索引
await queryInterface.addIndex('bank_loan_contracts', ['contractNumber']);
await queryInterface.addIndex('bank_loan_contracts', ['applicationNumber']);
await queryInterface.addIndex('bank_loan_contracts', ['status']);
await queryInterface.addIndex('bank_loan_contracts', ['borrowerName']);
await queryInterface.addIndex('bank_loan_contracts', ['farmerName']);
await queryInterface.addIndex('bank_loan_contracts', ['contractTime']);
},
down: async (queryInterface, Sequelize) => {
await queryInterface.dropTable('bank_loan_contracts');
}
};