保险前后端,养殖端和保险端小程序

This commit is contained in:
xuqiuyun
2025-09-17 19:01:52 +08:00
parent e4287b83fe
commit 473891163c
218 changed files with 109331 additions and 14103 deletions

View File

@@ -0,0 +1,49 @@
const { Sequelize } = require('sequelize');
require('dotenv').config();
// 创建Sequelize实例
const sequelize = new Sequelize({
dialect: process.env.DB_DIALECT || 'mysql',
host: process.env.DB_HOST || '129.211.213.226',
port: process.env.DB_PORT || 9527,
database: process.env.DB_NAME || 'insurance_data',
username: process.env.DB_USER || 'root',
password: process.env.DB_PASSWORD || 'aiotAiot123!',
logging: process.env.NODE_ENV === 'development' ? console.log : false,
pool: {
max: 10,
min: 0,
acquire: 30000,
idle: 10000
},
define: {
timestamps: true,
underscored: true,
charset: 'utf8mb4',
collate: 'utf8mb4_unicode_ci'
},
dialectOptions: {
// 解决MySQL严格模式问题
dateStrings: true,
typeCast: true,
// 允许0000-00-00日期值
connectAttributes: {
sql_mode: 'TRADITIONAL'
}
},
timezone: '+08:00' // 设置时区为东八区
});
// 测试数据库连接
const testConnection = async () => {
try {
await sequelize.authenticate();
console.log('✅ 数据库连接成功');
return true;
} catch (error) {
console.error('❌ 数据库连接失败:', error.message);
return false;
}
};
module.exports = { sequelize, testConnection };

View File

@@ -0,0 +1,42 @@
const redis = require('redis');
require('dotenv').config();
// 创建Redis客户端
const createRedisClient = () => {
const client = redis.createClient({
socket: {
host: process.env.REDIS_HOST || 'localhost',
port: process.env.REDIS_PORT || 6379
},
password: process.env.REDIS_PASSWORD || '',
legacyMode: false
});
// 错误处理
client.on('error', (err) => {
console.error('❌ Redis连接错误:', err);
});
// 连接成功
client.on('connect', () => {
console.log('✅ Redis连接成功');
});
return client;
};
// 创建并连接Redis客户端
const redisClient = createRedisClient();
// 连接Redis
const connectRedis = async () => {
try {
await redisClient.connect();
return true;
} catch (error) {
console.error('❌ Redis连接失败:', error.message);
return false;
}
};
module.exports = { redisClient, connectRedis };

View File

@@ -0,0 +1,148 @@
const swaggerJSDoc = require('swagger-jsdoc');
const swaggerDefinition = {
openapi: '3.0.0',
info: {
title: '保险端口系统 API',
version: '1.0.0',
description: '保险端口系统后端API文档',
contact: {
name: '技术支持',
email: 'support@insurance.com'
},
license: {
name: 'MIT',
url: 'https://opensource.org/licenses/MIT'
}
},
servers: [
{
url: 'http://localhost:3000',
description: '开发环境服务器'
},
{
url: 'https://api.insurance.com',
description: '生产环境服务器'
}
],
components: {
securitySchemes: {
bearerAuth: {
type: 'http',
scheme: 'bearer',
bearerFormat: 'JWT'
}
},
schemas: {
User: {
type: 'object',
properties: {
id: { type: 'integer', description: '用户ID' },
username: { type: 'string', description: '用户名' },
email: { type: 'string', description: '邮箱' },
phone: { type: 'string', description: '手机号' },
status: { type: 'string', enum: ['active', 'inactive'], description: '用户状态' },
createdAt: { type: 'string', format: 'date-time', description: '创建时间' },
updatedAt: { type: 'string', format: 'date-time', description: '更新时间' }
}
},
InsuranceApplication: {
type: 'object',
properties: {
id: { type: 'integer', description: '申请ID' },
applicantName: { type: 'string', description: '申请人姓名' },
insuranceType: { type: 'string', description: '保险类型' },
status: { type: 'string', enum: ['pending', 'approved', 'rejected'], description: '申请状态' },
amount: { type: 'number', format: 'float', description: '保险金额' },
createdAt: { type: 'string', format: 'date-time', description: '创建时间' }
}
},
Policy: {
type: 'object',
properties: {
id: { type: 'integer', description: '保单ID' },
policyNumber: { type: 'string', description: '保单号' },
insuranceType: { type: 'string', description: '保险类型' },
premium: { type: 'number', format: 'float', description: '保费' },
status: { type: 'string', enum: ['active', 'expired', 'cancelled'], description: '保单状态' },
startDate: { type: 'string', format: 'date', description: '生效日期' },
endDate: { type: 'string', format: 'date', description: '到期日期' }
}
},
Claim: {
type: 'object',
properties: {
id: { type: 'integer', description: '理赔ID' },
claimNumber: { type: 'string', description: '理赔单号' },
policyId: { type: 'integer', description: '关联保单ID' },
amount: { type: 'number', format: 'float', description: '理赔金额' },
status: { type: 'string', enum: ['pending', 'approved', 'paid', 'rejected'], description: '理赔状态' },
createdAt: { type: 'string', format: 'date-time', description: '创建时间' }
}
},
Error: {
type: 'object',
properties: {
code: { type: 'integer', description: '错误码' },
status: { type: 'string', description: '错误状态' },
message: { type: 'string', description: '错误信息' },
timestamp: { type: 'string', format: 'date-time', description: '时间戳' }
}
}
},
responses: {
UnauthorizedError: {
description: '认证失败',
content: {
'application/json': {
schema: {
$ref: '#/components/schemas/Error'
},
example: {
code: 401,
status: 'error',
message: '未授权访问',
timestamp: '2024-01-01T00:00:00.000Z'
}
}
}
},
NotFoundError: {
description: '资源不存在',
content: {
'application/json': {
schema: {
$ref: '#/components/schemas/Error'
},
example: {
code: 404,
status: 'error',
message: '资源不存在',
timestamp: '2024-01-01T00:00:00.000Z'
}
}
}
}
}
},
tags: [
{ name: '认证', description: '用户认证相关接口' },
{ name: '用户管理', description: '用户管理相关接口' },
{ name: '保险申请', description: '保险申请管理相关接口' },
{ name: '保单管理', description: '保单管理相关接口' },
{ name: '理赔管理', description: '理赔管理相关接口' },
{ name: '系统管理', description: '系统管理相关接口' }
]
};
const options = {
swaggerDefinition,
apis: [
'./routes/*.js',
'./controllers/*.js'
]
};
const swaggerSpec = swaggerJSDoc(options);
module.exports = swaggerSpec;