添加银行端后端接口
This commit is contained in:
42
bank-backend/routes/completedSupervisions.js
Normal file
42
bank-backend/routes/completedSupervisions.js
Normal file
@@ -0,0 +1,42 @@
|
||||
const express = require('express')
|
||||
const router = express.Router()
|
||||
const { authMiddleware } = require('../middleware/auth')
|
||||
const {
|
||||
getCompletedSupervisions,
|
||||
getCompletedSupervisionById,
|
||||
createCompletedSupervision,
|
||||
updateCompletedSupervision,
|
||||
deleteCompletedSupervision,
|
||||
getCompletedSupervisionStats,
|
||||
batchUpdateStatus,
|
||||
batchDelete
|
||||
} = require('../controllers/completedSupervisionController')
|
||||
|
||||
// 应用认证中间件到所有路由
|
||||
router.use(authMiddleware)
|
||||
|
||||
// 获取监管任务已结项列表
|
||||
router.get('/', getCompletedSupervisions)
|
||||
|
||||
// 获取监管任务已结项统计信息
|
||||
router.get('/stats', getCompletedSupervisionStats)
|
||||
|
||||
// 根据ID获取监管任务已结项详情
|
||||
router.get('/:id', getCompletedSupervisionById)
|
||||
|
||||
// 创建监管任务已结项
|
||||
router.post('/', createCompletedSupervision)
|
||||
|
||||
// 更新监管任务已结项
|
||||
router.put('/:id', updateCompletedSupervision)
|
||||
|
||||
// 批量更新结清状态
|
||||
router.put('/batch/status', batchUpdateStatus)
|
||||
|
||||
// 删除监管任务已结项
|
||||
router.delete('/:id', deleteCompletedSupervision)
|
||||
|
||||
// 批量删除监管任务已结项
|
||||
router.delete('/batch/delete', batchDelete)
|
||||
|
||||
module.exports = router
|
||||
42
bank-backend/routes/installationTasks.js
Normal file
42
bank-backend/routes/installationTasks.js
Normal file
@@ -0,0 +1,42 @@
|
||||
const express = require('express')
|
||||
const router = express.Router()
|
||||
const { authMiddleware } = require('../middleware/auth')
|
||||
const {
|
||||
getInstallationTasks,
|
||||
getInstallationTaskById,
|
||||
createInstallationTask,
|
||||
updateInstallationTask,
|
||||
deleteInstallationTask,
|
||||
getInstallationTaskStats,
|
||||
batchUpdateStatus,
|
||||
batchDelete
|
||||
} = require('../controllers/installationTaskController')
|
||||
|
||||
// 应用认证中间件到所有路由
|
||||
router.use(authMiddleware)
|
||||
|
||||
// 获取待安装任务列表
|
||||
router.get('/', getInstallationTasks)
|
||||
|
||||
// 获取待安装任务统计信息
|
||||
router.get('/stats', getInstallationTaskStats)
|
||||
|
||||
// 根据ID获取待安装任务详情
|
||||
router.get('/:id', getInstallationTaskById)
|
||||
|
||||
// 创建待安装任务
|
||||
router.post('/', createInstallationTask)
|
||||
|
||||
// 更新待安装任务
|
||||
router.put('/:id', updateInstallationTask)
|
||||
|
||||
// 批量更新安装状态
|
||||
router.put('/batch/status', batchUpdateStatus)
|
||||
|
||||
// 删除待安装任务
|
||||
router.delete('/:id', deleteInstallationTask)
|
||||
|
||||
// 批量删除待安装任务
|
||||
router.delete('/batch/delete', batchDelete)
|
||||
|
||||
module.exports = router
|
||||
408
bank-backend/routes/loanApplications.js
Normal file
408
bank-backend/routes/loanApplications.js
Normal file
@@ -0,0 +1,408 @@
|
||||
/**
|
||||
* 贷款申请路由
|
||||
* @file loanApplications.js
|
||||
* @description 银行系统贷款申请相关路由配置
|
||||
*/
|
||||
const express = require('express');
|
||||
const router = express.Router();
|
||||
const { body } = require('express-validator');
|
||||
const loanApplicationController = require('../controllers/loanApplicationController');
|
||||
const { authMiddleware } = require('../middleware/auth');
|
||||
|
||||
// 所有路由都需要认证
|
||||
router.use(authMiddleware);
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/loan-applications:
|
||||
* get:
|
||||
* summary: 获取贷款申请列表
|
||||
* tags: [贷款申请]
|
||||
* security:
|
||||
* - bearerAuth: []
|
||||
* parameters:
|
||||
* - in: query
|
||||
* name: page
|
||||
* schema:
|
||||
* type: integer
|
||||
* default: 1
|
||||
* description: 页码
|
||||
* - in: query
|
||||
* name: pageSize
|
||||
* schema:
|
||||
* type: integer
|
||||
* default: 10
|
||||
* description: 每页数量
|
||||
* - in: query
|
||||
* name: searchField
|
||||
* schema:
|
||||
* type: string
|
||||
* enum: [applicationNumber, customerName, productName]
|
||||
* default: applicationNumber
|
||||
* description: 搜索字段
|
||||
* - in: query
|
||||
* name: searchValue
|
||||
* schema:
|
||||
* type: string
|
||||
* description: 搜索值
|
||||
* - in: query
|
||||
* name: status
|
||||
* schema:
|
||||
* type: string
|
||||
* enum: [pending_review, verification_pending, pending_binding, approved, rejected]
|
||||
* description: 申请状态筛选
|
||||
* - in: query
|
||||
* name: sortField
|
||||
* schema:
|
||||
* type: string
|
||||
* default: createdAt
|
||||
* description: 排序字段
|
||||
* - in: query
|
||||
* name: sortOrder
|
||||
* schema:
|
||||
* type: string
|
||||
* enum: [ASC, DESC]
|
||||
* default: DESC
|
||||
* description: 排序方向
|
||||
* responses:
|
||||
* 200:
|
||||
* description: 获取成功
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* success:
|
||||
* type: boolean
|
||||
* data:
|
||||
* type: object
|
||||
* properties:
|
||||
* applications:
|
||||
* type: array
|
||||
* items:
|
||||
* $ref: '#/components/schemas/LoanApplication'
|
||||
* pagination:
|
||||
* $ref: '#/components/schemas/Pagination'
|
||||
*/
|
||||
router.get('/', loanApplicationController.getApplications);
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/loan-applications/{id}:
|
||||
* get:
|
||||
* summary: 获取贷款申请详情
|
||||
* tags: [贷款申请]
|
||||
* security:
|
||||
* - bearerAuth: []
|
||||
* parameters:
|
||||
* - in: path
|
||||
* name: id
|
||||
* required: true
|
||||
* schema:
|
||||
* type: integer
|
||||
* description: 申请ID
|
||||
* responses:
|
||||
* 200:
|
||||
* description: 获取成功
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* success:
|
||||
* type: boolean
|
||||
* data:
|
||||
* $ref: '#/components/schemas/LoanApplication'
|
||||
* 404:
|
||||
* description: 申请不存在
|
||||
*/
|
||||
router.get('/:id', loanApplicationController.getApplicationById);
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/loan-applications/{id}/audit:
|
||||
* post:
|
||||
* summary: 审核贷款申请
|
||||
* tags: [贷款申请]
|
||||
* security:
|
||||
* - bearerAuth: []
|
||||
* parameters:
|
||||
* - in: path
|
||||
* name: id
|
||||
* required: true
|
||||
* schema:
|
||||
* type: integer
|
||||
* description: 申请ID
|
||||
* requestBody:
|
||||
* required: true
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* required:
|
||||
* - action
|
||||
* - comment
|
||||
* properties:
|
||||
* action:
|
||||
* type: string
|
||||
* enum: [approve, reject]
|
||||
* description: 审核动作
|
||||
* comment:
|
||||
* type: string
|
||||
* description: 审核意见
|
||||
* responses:
|
||||
* 200:
|
||||
* description: 审核成功
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* success:
|
||||
* type: boolean
|
||||
* message:
|
||||
* type: string
|
||||
* data:
|
||||
* type: object
|
||||
* properties:
|
||||
* id:
|
||||
* type: integer
|
||||
* status:
|
||||
* type: string
|
||||
* action:
|
||||
* type: string
|
||||
* comment:
|
||||
* type: string
|
||||
* 400:
|
||||
* description: 请求参数错误
|
||||
* 404:
|
||||
* description: 申请不存在
|
||||
*/
|
||||
router.post('/:id/audit', [
|
||||
body('action')
|
||||
.isIn(['approve', 'reject'])
|
||||
.withMessage('审核动作必须是approve或reject'),
|
||||
body('comment')
|
||||
.notEmpty()
|
||||
.withMessage('审核意见不能为空')
|
||||
.isLength({ max: 500 })
|
||||
.withMessage('审核意见不能超过500个字符')
|
||||
], loanApplicationController.auditApplication);
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/loan-applications/stats:
|
||||
* get:
|
||||
* summary: 获取申请统计信息
|
||||
* tags: [贷款申请]
|
||||
* security:
|
||||
* - bearerAuth: []
|
||||
* responses:
|
||||
* 200:
|
||||
* description: 获取成功
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* success:
|
||||
* type: boolean
|
||||
* data:
|
||||
* type: object
|
||||
* properties:
|
||||
* total:
|
||||
* type: object
|
||||
* properties:
|
||||
* applications:
|
||||
* type: integer
|
||||
* amount:
|
||||
* type: number
|
||||
* byStatus:
|
||||
* type: object
|
||||
* properties:
|
||||
* counts:
|
||||
* type: object
|
||||
* amounts:
|
||||
* type: object
|
||||
*/
|
||||
router.get('/stats', loanApplicationController.getApplicationStats);
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/loan-applications/batch/status:
|
||||
* put:
|
||||
* summary: 批量更新申请状态
|
||||
* tags: [贷款申请]
|
||||
* security:
|
||||
* - bearerAuth: []
|
||||
* requestBody:
|
||||
* required: true
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* required:
|
||||
* - ids
|
||||
* - status
|
||||
* properties:
|
||||
* ids:
|
||||
* type: array
|
||||
* items:
|
||||
* type: integer
|
||||
* description: 申请ID数组
|
||||
* status:
|
||||
* type: string
|
||||
* enum: [approved, rejected]
|
||||
* description: 目标状态
|
||||
* responses:
|
||||
* 200:
|
||||
* description: 更新成功
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* success:
|
||||
* type: boolean
|
||||
* message:
|
||||
* type: string
|
||||
* data:
|
||||
* type: object
|
||||
* properties:
|
||||
* updatedCount:
|
||||
* type: integer
|
||||
* status:
|
||||
* type: string
|
||||
* 400:
|
||||
* description: 请求参数错误
|
||||
*/
|
||||
router.put('/batch/status', [
|
||||
body('ids')
|
||||
.isArray({ min: 1 })
|
||||
.withMessage('请选择要操作的申请'),
|
||||
body('status')
|
||||
.isIn(['approved', 'rejected'])
|
||||
.withMessage('状态必须是approved或rejected')
|
||||
], loanApplicationController.batchUpdateStatus);
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* components:
|
||||
* schemas:
|
||||
* LoanApplication:
|
||||
* type: object
|
||||
* properties:
|
||||
* id:
|
||||
* type: integer
|
||||
* description: 申请ID
|
||||
* applicationNumber:
|
||||
* type: string
|
||||
* description: 申请单号
|
||||
* productName:
|
||||
* type: string
|
||||
* description: 贷款产品名称
|
||||
* farmerName:
|
||||
* type: string
|
||||
* description: 申请养殖户姓名
|
||||
* borrowerName:
|
||||
* type: string
|
||||
* description: 贷款人姓名
|
||||
* borrowerIdNumber:
|
||||
* type: string
|
||||
* description: 贷款人身份证号
|
||||
* assetType:
|
||||
* type: string
|
||||
* description: 生资种类
|
||||
* applicationQuantity:
|
||||
* type: string
|
||||
* description: 申请数量
|
||||
* amount:
|
||||
* type: number
|
||||
* description: 申请额度
|
||||
* status:
|
||||
* type: string
|
||||
* enum: [pending_review, verification_pending, pending_binding, approved, rejected]
|
||||
* description: 申请状态
|
||||
* type:
|
||||
* type: string
|
||||
* enum: [personal, business, mortgage]
|
||||
* description: 申请类型
|
||||
* term:
|
||||
* type: integer
|
||||
* description: 申请期限(月)
|
||||
* interestRate:
|
||||
* type: number
|
||||
* description: 预计利率
|
||||
* phone:
|
||||
* type: string
|
||||
* description: 联系电话
|
||||
* purpose:
|
||||
* type: string
|
||||
* description: 申请用途
|
||||
* remark:
|
||||
* type: string
|
||||
* description: 备注
|
||||
* applicationTime:
|
||||
* type: string
|
||||
* format: date-time
|
||||
* description: 申请时间
|
||||
* approvedTime:
|
||||
* type: string
|
||||
* format: date-time
|
||||
* description: 审批通过时间
|
||||
* rejectedTime:
|
||||
* type: string
|
||||
* format: date-time
|
||||
* description: 审批拒绝时间
|
||||
* auditRecords:
|
||||
* type: array
|
||||
* items:
|
||||
* $ref: '#/components/schemas/AuditRecord'
|
||||
* description: 审核记录
|
||||
* AuditRecord:
|
||||
* type: object
|
||||
* properties:
|
||||
* id:
|
||||
* type: integer
|
||||
* description: 记录ID
|
||||
* action:
|
||||
* type: string
|
||||
* enum: [submit, approve, reject, review, verification, binding]
|
||||
* description: 审核动作
|
||||
* auditor:
|
||||
* type: string
|
||||
* description: 审核人
|
||||
* auditorId:
|
||||
* type: integer
|
||||
* description: 审核人ID
|
||||
* comment:
|
||||
* type: string
|
||||
* description: 审核意见
|
||||
* time:
|
||||
* type: string
|
||||
* format: date-time
|
||||
* description: 审核时间
|
||||
* previousStatus:
|
||||
* type: string
|
||||
* description: 审核前状态
|
||||
* newStatus:
|
||||
* type: string
|
||||
* description: 审核后状态
|
||||
* Pagination:
|
||||
* type: object
|
||||
* properties:
|
||||
* current:
|
||||
* type: integer
|
||||
* description: 当前页码
|
||||
* pageSize:
|
||||
* type: integer
|
||||
* description: 每页数量
|
||||
* total:
|
||||
* type: integer
|
||||
* description: 总记录数
|
||||
* totalPages:
|
||||
* type: integer
|
||||
* description: 总页数
|
||||
*/
|
||||
|
||||
module.exports = router;
|
||||
568
bank-backend/routes/loanContracts.js
Normal file
568
bank-backend/routes/loanContracts.js
Normal file
@@ -0,0 +1,568 @@
|
||||
/**
|
||||
* 贷款合同路由
|
||||
* @file loanContracts.js
|
||||
* @description 银行系统贷款合同相关路由配置
|
||||
*/
|
||||
const express = require('express');
|
||||
const router = express.Router();
|
||||
const { body } = require('express-validator');
|
||||
const loanContractController = require('../controllers/loanContractController');
|
||||
const { authMiddleware } = require('../middleware/auth');
|
||||
|
||||
// 所有路由都需要认证
|
||||
router.use(authMiddleware);
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/loan-contracts:
|
||||
* get:
|
||||
* summary: 获取贷款合同列表
|
||||
* tags: [贷款合同]
|
||||
* security:
|
||||
* - bearerAuth: []
|
||||
* parameters:
|
||||
* - in: query
|
||||
* name: page
|
||||
* schema:
|
||||
* type: integer
|
||||
* default: 1
|
||||
* description: 页码
|
||||
* - in: query
|
||||
* name: pageSize
|
||||
* schema:
|
||||
* type: integer
|
||||
* default: 10
|
||||
* description: 每页数量
|
||||
* - in: query
|
||||
* name: searchField
|
||||
* schema:
|
||||
* type: string
|
||||
* enum: [contractNumber, applicationNumber, borrowerName, farmerName, productName]
|
||||
* default: contractNumber
|
||||
* description: 搜索字段
|
||||
* - in: query
|
||||
* name: searchValue
|
||||
* schema:
|
||||
* type: string
|
||||
* description: 搜索值
|
||||
* - in: query
|
||||
* name: status
|
||||
* schema:
|
||||
* type: string
|
||||
* enum: [active, pending, completed, defaulted, cancelled]
|
||||
* description: 合同状态筛选
|
||||
* - in: query
|
||||
* name: sortField
|
||||
* schema:
|
||||
* type: string
|
||||
* default: createdAt
|
||||
* description: 排序字段
|
||||
* - in: query
|
||||
* name: sortOrder
|
||||
* schema:
|
||||
* type: string
|
||||
* enum: [ASC, DESC]
|
||||
* default: DESC
|
||||
* description: 排序方向
|
||||
* responses:
|
||||
* 200:
|
||||
* description: 获取成功
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* success:
|
||||
* type: boolean
|
||||
* data:
|
||||
* type: object
|
||||
* properties:
|
||||
* contracts:
|
||||
* type: array
|
||||
* items:
|
||||
* $ref: '#/components/schemas/LoanContract'
|
||||
* pagination:
|
||||
* $ref: '#/components/schemas/Pagination'
|
||||
*/
|
||||
router.get('/', loanContractController.getContracts);
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/loan-contracts/{id}:
|
||||
* get:
|
||||
* summary: 获取贷款合同详情
|
||||
* tags: [贷款合同]
|
||||
* security:
|
||||
* - bearerAuth: []
|
||||
* parameters:
|
||||
* - in: path
|
||||
* name: id
|
||||
* required: true
|
||||
* schema:
|
||||
* type: integer
|
||||
* description: 合同ID
|
||||
* responses:
|
||||
* 200:
|
||||
* description: 获取成功
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* success:
|
||||
* type: boolean
|
||||
* data:
|
||||
* $ref: '#/components/schemas/LoanContract'
|
||||
* 404:
|
||||
* description: 合同不存在
|
||||
*/
|
||||
router.get('/:id', loanContractController.getContractById);
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/loan-contracts:
|
||||
* post:
|
||||
* summary: 创建贷款合同
|
||||
* tags: [贷款合同]
|
||||
* security:
|
||||
* - bearerAuth: []
|
||||
* requestBody:
|
||||
* required: true
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* required:
|
||||
* - applicationNumber
|
||||
* - productName
|
||||
* - farmerName
|
||||
* - borrowerName
|
||||
* - borrowerIdNumber
|
||||
* - assetType
|
||||
* - applicationQuantity
|
||||
* - amount
|
||||
* - type
|
||||
* - term
|
||||
* - interestRate
|
||||
* - phone
|
||||
* properties:
|
||||
* applicationNumber:
|
||||
* type: string
|
||||
* description: 申请单号
|
||||
* productName:
|
||||
* type: string
|
||||
* description: 贷款产品名称
|
||||
* farmerName:
|
||||
* type: string
|
||||
* description: 申请养殖户姓名
|
||||
* borrowerName:
|
||||
* type: string
|
||||
* description: 贷款人姓名
|
||||
* borrowerIdNumber:
|
||||
* type: string
|
||||
* description: 贷款人身份证号
|
||||
* assetType:
|
||||
* type: string
|
||||
* description: 生资种类
|
||||
* applicationQuantity:
|
||||
* type: string
|
||||
* description: 申请数量
|
||||
* amount:
|
||||
* type: number
|
||||
* description: 合同金额
|
||||
* type:
|
||||
* type: string
|
||||
* enum: [livestock_collateral, farmer_loan, business_loan, personal_loan]
|
||||
* description: 合同类型
|
||||
* term:
|
||||
* type: integer
|
||||
* description: 合同期限(月)
|
||||
* interestRate:
|
||||
* type: number
|
||||
* description: 利率
|
||||
* phone:
|
||||
* type: string
|
||||
* description: 联系电话
|
||||
* purpose:
|
||||
* type: string
|
||||
* description: 贷款用途
|
||||
* remark:
|
||||
* type: string
|
||||
* description: 备注
|
||||
* responses:
|
||||
* 201:
|
||||
* description: 创建成功
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* success:
|
||||
* type: boolean
|
||||
* message:
|
||||
* type: string
|
||||
* data:
|
||||
* $ref: '#/components/schemas/LoanContract'
|
||||
* 400:
|
||||
* description: 请求参数错误
|
||||
*/
|
||||
router.post('/', [
|
||||
body('applicationNumber').notEmpty().withMessage('申请单号不能为空'),
|
||||
body('productName').notEmpty().withMessage('贷款产品名称不能为空'),
|
||||
body('farmerName').notEmpty().withMessage('申请养殖户姓名不能为空'),
|
||||
body('borrowerName').notEmpty().withMessage('贷款人姓名不能为空'),
|
||||
body('borrowerIdNumber').notEmpty().withMessage('贷款人身份证号不能为空'),
|
||||
body('assetType').notEmpty().withMessage('生资种类不能为空'),
|
||||
body('applicationQuantity').notEmpty().withMessage('申请数量不能为空'),
|
||||
body('amount').isNumeric().withMessage('合同金额必须是数字'),
|
||||
body('type').isIn(['livestock_collateral', 'farmer_loan', 'business_loan', 'personal_loan']).withMessage('合同类型无效'),
|
||||
body('term').isInt({ min: 1 }).withMessage('合同期限必须大于0'),
|
||||
body('interestRate').isNumeric().withMessage('利率必须是数字'),
|
||||
body('phone').notEmpty().withMessage('联系电话不能为空')
|
||||
], loanContractController.createContract);
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/loan-contracts/{id}:
|
||||
* put:
|
||||
* summary: 更新贷款合同
|
||||
* tags: [贷款合同]
|
||||
* security:
|
||||
* - bearerAuth: []
|
||||
* parameters:
|
||||
* - in: path
|
||||
* name: id
|
||||
* required: true
|
||||
* schema:
|
||||
* type: integer
|
||||
* description: 合同ID
|
||||
* requestBody:
|
||||
* required: true
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* productName:
|
||||
* type: string
|
||||
* description: 贷款产品名称
|
||||
* farmerName:
|
||||
* type: string
|
||||
* description: 申请养殖户姓名
|
||||
* borrowerName:
|
||||
* type: string
|
||||
* description: 贷款人姓名
|
||||
* borrowerIdNumber:
|
||||
* type: string
|
||||
* description: 贷款人身份证号
|
||||
* assetType:
|
||||
* type: string
|
||||
* description: 生资种类
|
||||
* applicationQuantity:
|
||||
* type: string
|
||||
* description: 申请数量
|
||||
* amount:
|
||||
* type: number
|
||||
* description: 合同金额
|
||||
* paidAmount:
|
||||
* type: number
|
||||
* description: 已还款金额
|
||||
* status:
|
||||
* type: string
|
||||
* enum: [active, pending, completed, defaulted, cancelled]
|
||||
* description: 合同状态
|
||||
* type:
|
||||
* type: string
|
||||
* enum: [livestock_collateral, farmer_loan, business_loan, personal_loan]
|
||||
* description: 合同类型
|
||||
* term:
|
||||
* type: integer
|
||||
* description: 合同期限(月)
|
||||
* interestRate:
|
||||
* type: number
|
||||
* description: 利率
|
||||
* phone:
|
||||
* type: string
|
||||
* description: 联系电话
|
||||
* purpose:
|
||||
* type: string
|
||||
* description: 贷款用途
|
||||
* remark:
|
||||
* type: string
|
||||
* description: 备注
|
||||
* responses:
|
||||
* 200:
|
||||
* description: 更新成功
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* success:
|
||||
* type: boolean
|
||||
* message:
|
||||
* type: string
|
||||
* data:
|
||||
* $ref: '#/components/schemas/LoanContract'
|
||||
* 400:
|
||||
* description: 请求参数错误
|
||||
* 404:
|
||||
* description: 合同不存在
|
||||
*/
|
||||
router.put('/:id', loanContractController.updateContract);
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/loan-contracts/{id}:
|
||||
* delete:
|
||||
* summary: 删除贷款合同
|
||||
* tags: [贷款合同]
|
||||
* security:
|
||||
* - bearerAuth: []
|
||||
* parameters:
|
||||
* - in: path
|
||||
* name: id
|
||||
* required: true
|
||||
* schema:
|
||||
* type: integer
|
||||
* description: 合同ID
|
||||
* responses:
|
||||
* 200:
|
||||
* description: 删除成功
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* success:
|
||||
* type: boolean
|
||||
* message:
|
||||
* type: string
|
||||
* 404:
|
||||
* description: 合同不存在
|
||||
*/
|
||||
router.delete('/:id', loanContractController.deleteContract);
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/loan-contracts/stats:
|
||||
* get:
|
||||
* summary: 获取合同统计信息
|
||||
* tags: [贷款合同]
|
||||
* security:
|
||||
* - bearerAuth: []
|
||||
* responses:
|
||||
* 200:
|
||||
* description: 获取成功
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* success:
|
||||
* type: boolean
|
||||
* data:
|
||||
* type: object
|
||||
* properties:
|
||||
* total:
|
||||
* type: object
|
||||
* properties:
|
||||
* contracts:
|
||||
* type: integer
|
||||
* amount:
|
||||
* type: number
|
||||
* paidAmount:
|
||||
* type: number
|
||||
* remainingAmount:
|
||||
* type: number
|
||||
* byStatus:
|
||||
* type: object
|
||||
* properties:
|
||||
* counts:
|
||||
* type: object
|
||||
* amounts:
|
||||
* type: object
|
||||
* paidAmounts:
|
||||
* type: object
|
||||
*/
|
||||
router.get('/stats', loanContractController.getContractStats);
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/loan-contracts/batch/status:
|
||||
* put:
|
||||
* summary: 批量更新合同状态
|
||||
* tags: [贷款合同]
|
||||
* security:
|
||||
* - bearerAuth: []
|
||||
* requestBody:
|
||||
* required: true
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* required:
|
||||
* - ids
|
||||
* - status
|
||||
* properties:
|
||||
* ids:
|
||||
* type: array
|
||||
* items:
|
||||
* type: integer
|
||||
* description: 合同ID数组
|
||||
* status:
|
||||
* type: string
|
||||
* enum: [active, pending, completed, defaulted, cancelled]
|
||||
* description: 目标状态
|
||||
* responses:
|
||||
* 200:
|
||||
* description: 更新成功
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* success:
|
||||
* type: boolean
|
||||
* message:
|
||||
* type: string
|
||||
* data:
|
||||
* type: object
|
||||
* properties:
|
||||
* updatedCount:
|
||||
* type: integer
|
||||
* status:
|
||||
* type: string
|
||||
* 400:
|
||||
* description: 请求参数错误
|
||||
*/
|
||||
router.put('/batch/status', [
|
||||
body('ids').isArray({ min: 1 }).withMessage('请选择要操作的合同'),
|
||||
body('status').isIn(['active', 'pending', 'completed', 'defaulted', 'cancelled']).withMessage('状态无效')
|
||||
], loanContractController.batchUpdateStatus);
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* components:
|
||||
* schemas:
|
||||
* LoanContract:
|
||||
* type: object
|
||||
* properties:
|
||||
* id:
|
||||
* type: integer
|
||||
* description: 合同ID
|
||||
* contractNumber:
|
||||
* type: string
|
||||
* description: 合同编号
|
||||
* applicationNumber:
|
||||
* type: string
|
||||
* description: 申请单号
|
||||
* productName:
|
||||
* type: string
|
||||
* description: 贷款产品名称
|
||||
* farmerName:
|
||||
* type: string
|
||||
* description: 申请养殖户姓名
|
||||
* borrowerName:
|
||||
* type: string
|
||||
* description: 贷款人姓名
|
||||
* borrowerIdNumber:
|
||||
* type: string
|
||||
* description: 贷款人身份证号
|
||||
* assetType:
|
||||
* type: string
|
||||
* description: 生资种类
|
||||
* applicationQuantity:
|
||||
* type: string
|
||||
* description: 申请数量
|
||||
* amount:
|
||||
* type: number
|
||||
* description: 合同金额
|
||||
* paidAmount:
|
||||
* type: number
|
||||
* description: 已还款金额
|
||||
* status:
|
||||
* type: string
|
||||
* enum: [active, pending, completed, defaulted, cancelled]
|
||||
* description: 合同状态
|
||||
* type:
|
||||
* type: string
|
||||
* enum: [livestock_collateral, farmer_loan, business_loan, personal_loan]
|
||||
* description: 合同类型
|
||||
* term:
|
||||
* type: integer
|
||||
* description: 合同期限(月)
|
||||
* interestRate:
|
||||
* type: number
|
||||
* description: 利率
|
||||
* phone:
|
||||
* type: string
|
||||
* description: 联系电话
|
||||
* purpose:
|
||||
* type: string
|
||||
* description: 贷款用途
|
||||
* remark:
|
||||
* type: string
|
||||
* description: 备注
|
||||
* contractTime:
|
||||
* type: string
|
||||
* format: date-time
|
||||
* description: 合同签订时间
|
||||
* disbursementTime:
|
||||
* type: string
|
||||
* format: date-time
|
||||
* description: 放款时间
|
||||
* maturityTime:
|
||||
* type: string
|
||||
* format: date-time
|
||||
* description: 到期时间
|
||||
* completedTime:
|
||||
* type: string
|
||||
* format: date-time
|
||||
* description: 完成时间
|
||||
* remainingAmount:
|
||||
* type: number
|
||||
* description: 剩余还款金额
|
||||
* repaymentProgress:
|
||||
* type: number
|
||||
* description: 还款进度百分比
|
||||
* creator:
|
||||
* $ref: '#/components/schemas/User'
|
||||
* updater:
|
||||
* $ref: '#/components/schemas/User'
|
||||
* User:
|
||||
* type: object
|
||||
* properties:
|
||||
* id:
|
||||
* type: integer
|
||||
* description: 用户ID
|
||||
* username:
|
||||
* type: string
|
||||
* description: 用户名
|
||||
* real_name:
|
||||
* type: string
|
||||
* description: 真实姓名
|
||||
* email:
|
||||
* type: string
|
||||
* description: 邮箱
|
||||
* phone:
|
||||
* type: string
|
||||
* description: 电话
|
||||
* Pagination:
|
||||
* type: object
|
||||
* properties:
|
||||
* current:
|
||||
* type: integer
|
||||
* description: 当前页码
|
||||
* pageSize:
|
||||
* type: integer
|
||||
* description: 每页数量
|
||||
* total:
|
||||
* type: integer
|
||||
* description: 总记录数
|
||||
* totalPages:
|
||||
* type: integer
|
||||
* description: 总页数
|
||||
*/
|
||||
|
||||
module.exports = router;
|
||||
@@ -1,372 +1,42 @@
|
||||
/**
|
||||
* 贷款产品路由
|
||||
* @file loanProducts.js
|
||||
* @description 贷款产品相关的路由定义
|
||||
*/
|
||||
const express = require('express');
|
||||
const { body } = require('express-validator');
|
||||
const { authMiddleware, roleMiddleware, adminMiddleware, managerMiddleware } = require('../middleware/auth');
|
||||
const loanProductController = require('../controllers/loanProductController');
|
||||
|
||||
const router = express.Router();
|
||||
const { authMiddleware } = require('../middleware/auth');
|
||||
const {
|
||||
getLoanProducts,
|
||||
getLoanProductById,
|
||||
createLoanProduct,
|
||||
updateLoanProduct,
|
||||
deleteLoanProduct,
|
||||
getLoanProductStats,
|
||||
batchUpdateStatus,
|
||||
batchDelete
|
||||
} = require('../controllers/loanProductController');
|
||||
|
||||
// 所有路由都需要认证
|
||||
// 应用认证中间件到所有路由
|
||||
router.use(authMiddleware);
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* tags:
|
||||
* name: LoanProducts
|
||||
* description: 贷款产品管理
|
||||
*/
|
||||
// 获取贷款商品列表
|
||||
router.get('/', getLoanProducts);
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/loan-products:
|
||||
* get:
|
||||
* summary: 获取贷款产品列表
|
||||
* tags: [LoanProducts]
|
||||
* security:
|
||||
* - bearerAuth: []
|
||||
* parameters:
|
||||
* - in: query
|
||||
* name: page
|
||||
* schema:
|
||||
* type: integer
|
||||
* description: 页码
|
||||
* - in: query
|
||||
* name: limit
|
||||
* schema:
|
||||
* type: integer
|
||||
* description: 每页数量
|
||||
* - in: query
|
||||
* name: search
|
||||
* schema:
|
||||
* type: string
|
||||
* description: 搜索关键词
|
||||
* - in: query
|
||||
* name: status
|
||||
* schema:
|
||||
* type: string
|
||||
* enum: [draft, active, inactive]
|
||||
* description: 产品状态
|
||||
* - in: query
|
||||
* name: type
|
||||
* schema:
|
||||
* type: string
|
||||
* enum: [personal, business, mortgage, credit]
|
||||
* description: 产品类型
|
||||
* responses:
|
||||
* 200:
|
||||
* description: 获取成功
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* success:
|
||||
* type: boolean
|
||||
* message:
|
||||
* type: string
|
||||
* data:
|
||||
* type: object
|
||||
* properties:
|
||||
* products:
|
||||
* type: array
|
||||
* items:
|
||||
* $ref: '#/components/schemas/LoanProduct'
|
||||
* pagination:
|
||||
* $ref: '#/components/schemas/Pagination'
|
||||
* 401:
|
||||
* description: 未授权
|
||||
* 500:
|
||||
* description: 服务器内部错误
|
||||
*/
|
||||
router.get('/', roleMiddleware(['admin', 'manager', 'teller']), loanProductController.getLoanProducts);
|
||||
// 获取贷款商品统计信息
|
||||
router.get('/stats', getLoanProductStats);
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/loan-products:
|
||||
* post:
|
||||
* summary: 创建贷款产品
|
||||
* tags: [LoanProducts]
|
||||
* security:
|
||||
* - bearerAuth: []
|
||||
* requestBody:
|
||||
* required: true
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* required:
|
||||
* - name
|
||||
* - code
|
||||
* - type
|
||||
* - min_amount
|
||||
* - max_amount
|
||||
* - interest_rate
|
||||
* - term_min
|
||||
* - term_max
|
||||
* properties:
|
||||
* name:
|
||||
* type: string
|
||||
* description: 产品名称
|
||||
* code:
|
||||
* type: string
|
||||
* description: 产品代码
|
||||
* type:
|
||||
* type: string
|
||||
* enum: [personal, business, mortgage, credit]
|
||||
* description: 产品类型
|
||||
* description:
|
||||
* type: string
|
||||
* description: 产品描述
|
||||
* min_amount:
|
||||
* type: number
|
||||
* description: 最小贷款金额
|
||||
* max_amount:
|
||||
* type: number
|
||||
* description: 最大贷款金额
|
||||
* interest_rate:
|
||||
* type: number
|
||||
* description: 年化利率
|
||||
* term_min:
|
||||
* type: integer
|
||||
* description: 最短期限(月)
|
||||
* term_max:
|
||||
* type: integer
|
||||
* description: 最长期限(月)
|
||||
* requirements:
|
||||
* type: object
|
||||
* description: 申请要求
|
||||
* status:
|
||||
* type: string
|
||||
* enum: [draft, active, inactive]
|
||||
* description: 产品状态
|
||||
* responses:
|
||||
* 201:
|
||||
* description: 创建成功
|
||||
* 400:
|
||||
* description: 请求参数错误
|
||||
* 401:
|
||||
* description: 未授权
|
||||
* 403:
|
||||
* description: 权限不足
|
||||
* 500:
|
||||
* description: 服务器内部错误
|
||||
*/
|
||||
router.post('/',
|
||||
adminMiddleware,
|
||||
[
|
||||
body('name').notEmpty().withMessage('产品名称不能为空'),
|
||||
body('code').notEmpty().withMessage('产品代码不能为空'),
|
||||
body('type').isIn(['personal', 'business', 'mortgage', 'credit']).withMessage('产品类型无效'),
|
||||
body('min_amount').isNumeric().withMessage('最小金额必须是数字'),
|
||||
body('max_amount').isNumeric().withMessage('最大金额必须是数字'),
|
||||
body('interest_rate').isNumeric().withMessage('利率必须是数字'),
|
||||
body('term_min').isInt({ min: 1 }).withMessage('最短期限必须是正整数'),
|
||||
body('term_max').isInt({ min: 1 }).withMessage('最长期限必须是正整数')
|
||||
],
|
||||
loanProductController.createLoanProduct
|
||||
);
|
||||
// 根据ID获取贷款商品详情
|
||||
router.get('/:id', getLoanProductById);
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/loan-products/{id}:
|
||||
* get:
|
||||
* summary: 获取贷款产品详情
|
||||
* tags: [LoanProducts]
|
||||
* security:
|
||||
* - bearerAuth: []
|
||||
* parameters:
|
||||
* - in: path
|
||||
* name: id
|
||||
* required: true
|
||||
* schema:
|
||||
* type: integer
|
||||
* description: 产品ID
|
||||
* responses:
|
||||
* 200:
|
||||
* description: 获取成功
|
||||
* 404:
|
||||
* description: 产品不存在
|
||||
* 401:
|
||||
* description: 未授权
|
||||
* 500:
|
||||
* description: 服务器内部错误
|
||||
*/
|
||||
router.get('/:id', roleMiddleware(['admin', 'manager', 'teller']), loanProductController.getLoanProductById);
|
||||
// 创建贷款商品
|
||||
router.post('/', createLoanProduct);
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/loan-products/{id}:
|
||||
* put:
|
||||
* summary: 更新贷款产品
|
||||
* tags: [LoanProducts]
|
||||
* security:
|
||||
* - bearerAuth: []
|
||||
* parameters:
|
||||
* - in: path
|
||||
* name: id
|
||||
* required: true
|
||||
* schema:
|
||||
* type: integer
|
||||
* description: 产品ID
|
||||
* requestBody:
|
||||
* required: true
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* name:
|
||||
* type: string
|
||||
* code:
|
||||
* type: string
|
||||
* type:
|
||||
* type: string
|
||||
* enum: [personal, business, mortgage, credit]
|
||||
* description:
|
||||
* type: string
|
||||
* min_amount:
|
||||
* type: number
|
||||
* max_amount:
|
||||
* type: number
|
||||
* interest_rate:
|
||||
* type: number
|
||||
* term_min:
|
||||
* type: integer
|
||||
* term_max:
|
||||
* type: integer
|
||||
* requirements:
|
||||
* type: object
|
||||
* status:
|
||||
* type: string
|
||||
* enum: [draft, active, inactive]
|
||||
* responses:
|
||||
* 200:
|
||||
* description: 更新成功
|
||||
* 400:
|
||||
* description: 请求参数错误
|
||||
* 404:
|
||||
* description: 产品不存在
|
||||
* 401:
|
||||
* description: 未授权
|
||||
* 403:
|
||||
* description: 权限不足
|
||||
* 500:
|
||||
* description: 服务器内部错误
|
||||
*/
|
||||
router.put('/:id',
|
||||
adminMiddleware,
|
||||
[
|
||||
body('name').optional().notEmpty().withMessage('产品名称不能为空'),
|
||||
body('code').optional().notEmpty().withMessage('产品代码不能为空'),
|
||||
body('type').optional().isIn(['personal', 'business', 'mortgage', 'credit']).withMessage('产品类型无效'),
|
||||
body('min_amount').optional().isNumeric().withMessage('最小金额必须是数字'),
|
||||
body('max_amount').optional().isNumeric().withMessage('最大金额必须是数字'),
|
||||
body('interest_rate').optional().isNumeric().withMessage('利率必须是数字'),
|
||||
body('term_min').optional().isInt({ min: 1 }).withMessage('最短期限必须是正整数'),
|
||||
body('term_max').optional().isInt({ min: 1 }).withMessage('最长期限必须是正整数')
|
||||
],
|
||||
loanProductController.updateLoanProduct
|
||||
);
|
||||
// 更新贷款商品
|
||||
router.put('/:id', updateLoanProduct);
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/loan-products/{id}:
|
||||
* delete:
|
||||
* summary: 删除贷款产品
|
||||
* tags: [LoanProducts]
|
||||
* security:
|
||||
* - bearerAuth: []
|
||||
* parameters:
|
||||
* - in: path
|
||||
* name: id
|
||||
* required: true
|
||||
* schema:
|
||||
* type: integer
|
||||
* description: 产品ID
|
||||
* responses:
|
||||
* 200:
|
||||
* description: 删除成功
|
||||
* 404:
|
||||
* description: 产品不存在
|
||||
* 401:
|
||||
* description: 未授权
|
||||
* 403:
|
||||
* description: 权限不足
|
||||
* 500:
|
||||
* description: 服务器内部错误
|
||||
*/
|
||||
router.delete('/:id', adminMiddleware, loanProductController.deleteLoanProduct);
|
||||
// 批量更新在售状态
|
||||
router.put('/batch/status', batchUpdateStatus);
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/loan-products/{id}/status:
|
||||
* put:
|
||||
* summary: 更新贷款产品状态
|
||||
* tags: [LoanProducts]
|
||||
* security:
|
||||
* - bearerAuth: []
|
||||
* parameters:
|
||||
* - in: path
|
||||
* name: id
|
||||
* required: true
|
||||
* schema:
|
||||
* type: integer
|
||||
* description: 产品ID
|
||||
* requestBody:
|
||||
* required: true
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* required:
|
||||
* - status
|
||||
* properties:
|
||||
* status:
|
||||
* type: string
|
||||
* enum: [draft, active, inactive]
|
||||
* description: 产品状态
|
||||
* responses:
|
||||
* 200:
|
||||
* description: 更新成功
|
||||
* 400:
|
||||
* description: 请求参数错误
|
||||
* 404:
|
||||
* description: 产品不存在
|
||||
* 401:
|
||||
* description: 未授权
|
||||
* 403:
|
||||
* description: 权限不足
|
||||
* 500:
|
||||
* description: 服务器内部错误
|
||||
*/
|
||||
router.put('/:id/status',
|
||||
adminMiddleware,
|
||||
[
|
||||
body('status').isIn(['draft', 'active', 'inactive']).withMessage('状态值无效')
|
||||
],
|
||||
loanProductController.updateLoanProductStatus
|
||||
);
|
||||
// 删除贷款商品
|
||||
router.delete('/:id', deleteLoanProduct);
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/loan-products/stats/overview:
|
||||
* get:
|
||||
* summary: 获取贷款产品统计
|
||||
* tags: [LoanProducts]
|
||||
* security:
|
||||
* - bearerAuth: []
|
||||
* responses:
|
||||
* 200:
|
||||
* description: 获取成功
|
||||
* 401:
|
||||
* description: 未授权
|
||||
* 500:
|
||||
* description: 服务器内部错误
|
||||
*/
|
||||
router.get('/stats/overview', roleMiddleware(['admin', 'manager', 'teller']), loanProductController.getLoanProductStats);
|
||||
// 批量删除贷款商品
|
||||
router.delete('/batch/delete', batchDelete);
|
||||
|
||||
module.exports = router;
|
||||
module.exports = router;
|
||||
Reference in New Issue
Block a user