完善保险端的前后端
This commit is contained in:
29
insurance_backend/scripts/check_claims_table.js
Normal file
29
insurance_backend/scripts/check_claims_table.js
Normal file
@@ -0,0 +1,29 @@
|
||||
const { Sequelize } = require('sequelize');
|
||||
|
||||
const sequelize = new Sequelize('insurance_db', 'root', '123456', {
|
||||
host: 'localhost',
|
||||
dialect: 'mysql',
|
||||
logging: false
|
||||
});
|
||||
|
||||
async function checkClaimsTable() {
|
||||
try {
|
||||
const [results] = await sequelize.query('DESCRIBE livestock_claims');
|
||||
|
||||
console.log('livestock_claims表结构:');
|
||||
console.log('='.repeat(50));
|
||||
|
||||
results.forEach(field => {
|
||||
const required = field.Null === 'NO' ? '(必填)' : '(可选)';
|
||||
const defaultValue = field.Default ? ` 默认值: ${field.Default}` : '';
|
||||
console.log(`- ${field.Field}: ${field.Type} ${required}${defaultValue}`);
|
||||
});
|
||||
|
||||
} catch (error) {
|
||||
console.error('检查表结构失败:', error.message);
|
||||
} finally {
|
||||
await sequelize.close();
|
||||
}
|
||||
}
|
||||
|
||||
checkClaimsTable();
|
||||
34
insurance_backend/scripts/check_required_fields.js
Normal file
34
insurance_backend/scripts/check_required_fields.js
Normal file
@@ -0,0 +1,34 @@
|
||||
const { sequelize } = require('../config/database');
|
||||
|
||||
async function checkRequiredFields() {
|
||||
try {
|
||||
console.log('检查 livestock_policies 表的必填字段...');
|
||||
|
||||
const [rows] = await sequelize.query('DESCRIBE livestock_policies');
|
||||
|
||||
console.log('必填字段(NOT NULL):');
|
||||
console.log('序号 | 字段名 | 类型 | 默认值');
|
||||
console.log('-----|--------|------|--------');
|
||||
|
||||
const requiredFields = rows.filter(row => row.Null === 'NO');
|
||||
requiredFields.forEach((row, index) => {
|
||||
console.log(`${index + 1}. ${row.Field} | ${row.Type} | ${row.Default || 'NULL'}`);
|
||||
});
|
||||
|
||||
console.log('\n可选字段(允许NULL):');
|
||||
console.log('序号 | 字段名 | 类型');
|
||||
console.log('-----|--------|------');
|
||||
|
||||
const optionalFields = rows.filter(row => row.Null === 'YES');
|
||||
optionalFields.forEach((row, index) => {
|
||||
console.log(`${index + 1}. ${row.Field} | ${row.Type}`);
|
||||
});
|
||||
|
||||
} catch (error) {
|
||||
console.error('❌ 检查字段失败:', error.message);
|
||||
} finally {
|
||||
await sequelize.close();
|
||||
}
|
||||
}
|
||||
|
||||
checkRequiredFields();
|
||||
24
insurance_backend/scripts/check_table_structure.js
Normal file
24
insurance_backend/scripts/check_table_structure.js
Normal file
@@ -0,0 +1,24 @@
|
||||
const { sequelize } = require('../config/database');
|
||||
|
||||
async function checkTableStructure() {
|
||||
try {
|
||||
console.log('检查 livestock_policies 表结构...');
|
||||
|
||||
const [rows] = await sequelize.query('DESCRIBE livestock_policies');
|
||||
|
||||
console.log('livestock_policies表结构:');
|
||||
console.log('序号 | 字段名 | 类型 | 是否为空 | 默认值');
|
||||
console.log('-----|--------|------|----------|--------');
|
||||
|
||||
rows.forEach((row, index) => {
|
||||
console.log(`${index + 1}. ${row.Field} | ${row.Type} | ${row.Null} | ${row.Default || 'NULL'}`);
|
||||
});
|
||||
|
||||
} catch (error) {
|
||||
console.error('❌ 检查表结构失败:', error.message);
|
||||
} finally {
|
||||
await sequelize.close();
|
||||
}
|
||||
}
|
||||
|
||||
checkTableStructure();
|
||||
20
insurance_backend/scripts/check_tables.js
Normal file
20
insurance_backend/scripts/check_tables.js
Normal file
@@ -0,0 +1,20 @@
|
||||
const { sequelize } = require('../config/database');
|
||||
|
||||
async function checkTables() {
|
||||
try {
|
||||
await sequelize.query('USE insurance_data');
|
||||
|
||||
const [results] = await sequelize.query("SHOW TABLES LIKE 'livestock_%'");
|
||||
console.log('livestock表:', results);
|
||||
|
||||
const [allTables] = await sequelize.query("SHOW TABLES");
|
||||
console.log('所有表:', allTables.map(t => Object.values(t)[0]));
|
||||
|
||||
} catch (error) {
|
||||
console.error('错误:', error.message);
|
||||
} finally {
|
||||
await sequelize.close();
|
||||
}
|
||||
}
|
||||
|
||||
checkTables();
|
||||
21
insurance_backend/scripts/check_users.js
Normal file
21
insurance_backend/scripts/check_users.js
Normal file
@@ -0,0 +1,21 @@
|
||||
const { sequelize } = require('../config/database');
|
||||
|
||||
async function checkUsers() {
|
||||
try {
|
||||
const [users] = await sequelize.query('SELECT id, username, real_name FROM users LIMIT 10');
|
||||
console.log('用户列表:');
|
||||
if (users.length === 0) {
|
||||
console.log('❌ 没有找到任何用户数据');
|
||||
} else {
|
||||
users.forEach(user => {
|
||||
console.log(`- ID: ${user.id}, 用户名: ${user.username}, 姓名: ${user.real_name}`);
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('❌ 查询用户失败:', error.message);
|
||||
} finally {
|
||||
await sequelize.close();
|
||||
}
|
||||
}
|
||||
|
||||
checkUsers();
|
||||
86
insurance_backend/scripts/create_regulatory_tables.js
Normal file
86
insurance_backend/scripts/create_regulatory_tables.js
Normal file
@@ -0,0 +1,86 @@
|
||||
const mysql = require('mysql2/promise');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
require('dotenv').config();
|
||||
|
||||
async function createRegulatoryTables() {
|
||||
let connection;
|
||||
|
||||
try {
|
||||
// 创建数据库连接
|
||||
connection = await mysql.createConnection({
|
||||
host: process.env.DB_HOST || '129.211.213.226',
|
||||
port: process.env.DB_PORT || 9527,
|
||||
user: process.env.DB_USER || 'root',
|
||||
password: process.env.DB_PASSWORD || 'aiotAiot123!',
|
||||
database: process.env.DB_DATABASE || 'nxxmdata',
|
||||
multipleStatements: true
|
||||
});
|
||||
|
||||
console.log('数据库连接成功');
|
||||
|
||||
// 读取SQL文件
|
||||
const sqlFilePath = path.join(__dirname, 'regulatory_task_completion.sql');
|
||||
const sqlContent = fs.readFileSync(sqlFilePath, 'utf8');
|
||||
|
||||
// 分割SQL语句(按分号分割,但忽略注释中的分号)
|
||||
const sqlStatements = sqlContent
|
||||
.split('\n')
|
||||
.filter(line => !line.trim().startsWith('--') && line.trim() !== '')
|
||||
.join('\n')
|
||||
.split(';')
|
||||
.filter(statement => statement.trim() !== '');
|
||||
|
||||
console.log(`准备执行 ${sqlStatements.length} 条SQL语句`);
|
||||
|
||||
// 逐条执行SQL语句
|
||||
for (let i = 0; i < sqlStatements.length; i++) {
|
||||
const statement = sqlStatements[i].trim();
|
||||
if (statement) {
|
||||
try {
|
||||
console.log(`执行第 ${i + 1} 条SQL语句...`);
|
||||
await connection.execute(statement);
|
||||
console.log(`第 ${i + 1} 条SQL语句执行成功`);
|
||||
} catch (error) {
|
||||
console.error(`第 ${i + 1} 条SQL语句执行失败:`, error.message);
|
||||
console.error('SQL语句:', statement.substring(0, 100) + '...');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 验证表是否创建成功
|
||||
const [tables] = await connection.execute(`
|
||||
SELECT TABLE_NAME, TABLE_COMMENT
|
||||
FROM INFORMATION_SCHEMA.TABLES
|
||||
WHERE TABLE_SCHEMA = ? AND TABLE_NAME LIKE 'regulatory_task_%'
|
||||
`, [process.env.DB_DATABASE || 'nxxmdata']);
|
||||
|
||||
console.log('\n创建的监管任务结项相关表:');
|
||||
tables.forEach(table => {
|
||||
console.log(`- ${table.TABLE_NAME}: ${table.TABLE_COMMENT}`);
|
||||
});
|
||||
|
||||
// 查询示例数据
|
||||
const [sampleData] = await connection.execute(`
|
||||
SELECT application_no, policy_no, customer_name, completion_status
|
||||
FROM regulatory_task_completions
|
||||
LIMIT 3
|
||||
`);
|
||||
|
||||
console.log('\n示例数据:');
|
||||
console.table(sampleData);
|
||||
|
||||
console.log('\n监管任务结项表创建完成!');
|
||||
|
||||
} catch (error) {
|
||||
console.error('创建表时发生错误:', error);
|
||||
} finally {
|
||||
if (connection) {
|
||||
await connection.end();
|
||||
console.log('数据库连接已关闭');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 执行创建表操作
|
||||
createRegulatoryTables();
|
||||
53
insurance_backend/scripts/execute_livestock_schema.js
Normal file
53
insurance_backend/scripts/execute_livestock_schema.js
Normal file
@@ -0,0 +1,53 @@
|
||||
const { sequelize } = require('../config/database');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
async function executeLivestockSchema() {
|
||||
try {
|
||||
// 确保使用正确的数据库
|
||||
await sequelize.query('USE insurance_data');
|
||||
console.log('✅ 已切换到 insurance_data 数据库');
|
||||
|
||||
// 读取SQL文件
|
||||
const sqlFile = path.join(__dirname, 'livestock_insurance_schema.sql');
|
||||
const sqlContent = fs.readFileSync(sqlFile, 'utf8');
|
||||
|
||||
// 分割SQL语句(按分号分割,但忽略注释中的分号)
|
||||
const statements = sqlContent
|
||||
.split('\n')
|
||||
.filter(line => !line.trim().startsWith('--') && line.trim() !== '')
|
||||
.join('\n')
|
||||
.split(';')
|
||||
.filter(statement => statement.trim() !== '');
|
||||
|
||||
console.log('开始执行生资保单数据库表创建...');
|
||||
|
||||
// 逐个执行SQL语句
|
||||
for (let i = 0; i < statements.length; i++) {
|
||||
const statement = statements[i].trim();
|
||||
if (statement) {
|
||||
try {
|
||||
console.log(`执行语句 ${i + 1}/${statements.length}...`);
|
||||
await sequelize.query(statement);
|
||||
console.log(`✅ 语句 ${i + 1} 执行成功`);
|
||||
} catch (error) {
|
||||
console.error(`❌ 语句 ${i + 1} 执行失败:`, error.message);
|
||||
console.log('失败的语句:', statement.substring(0, 100) + '...');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
console.log('✅ 生资保单数据库表创建完成');
|
||||
|
||||
// 验证表是否创建成功
|
||||
const [results] = await sequelize.query("SHOW TABLES LIKE 'livestock_%'");
|
||||
console.log('创建的表:', results.map(row => Object.values(row)[0]));
|
||||
|
||||
} catch (error) {
|
||||
console.error('❌ 执行失败:', error.message);
|
||||
} finally {
|
||||
await sequelize.close();
|
||||
}
|
||||
}
|
||||
|
||||
executeLivestockSchema();
|
||||
51
insurance_backend/scripts/fix-admin-permissions.js
Normal file
51
insurance_backend/scripts/fix-admin-permissions.js
Normal file
@@ -0,0 +1,51 @@
|
||||
console.log('🚀 开始修复admin权限...');
|
||||
|
||||
const { sequelize } = require('../config/database');
|
||||
const Role = require('../models/Role');
|
||||
|
||||
async function fixAdminPermissions() {
|
||||
try {
|
||||
console.log('📡 连接数据库...');
|
||||
|
||||
// 测试数据库连接
|
||||
await sequelize.authenticate();
|
||||
console.log('✅ 数据库连接成功');
|
||||
|
||||
// 查询当前admin角色
|
||||
console.log('🔍 查询当前admin角色...');
|
||||
const adminRole = await Role.findOne({ where: { name: 'admin' } });
|
||||
|
||||
if (adminRole) {
|
||||
console.log('📋 当前admin角色权限:', adminRole.permissions);
|
||||
|
||||
// 更新admin角色权限,添加insurance相关权限
|
||||
console.log('🔧 更新admin角色权限...');
|
||||
const newPermissions = [
|
||||
'user:read', 'user:create', 'user:update', 'user:delete',
|
||||
'insurance:read', 'insurance:create', 'insurance:update', 'insurance:delete', 'insurance:review',
|
||||
'insurance_type:read', 'insurance_type:create', 'insurance_type:update', 'insurance_type:delete', 'insurance_type:review',
|
||||
'policy:read', 'policy:create', 'policy:update', 'policy:delete',
|
||||
'claim:read', 'claim:create', 'claim:update', 'claim:review',
|
||||
'system:read', 'system:update', 'system:admin'
|
||||
];
|
||||
|
||||
await adminRole.update({
|
||||
permissions: JSON.stringify(newPermissions)
|
||||
});
|
||||
|
||||
console.log('✅ admin角色权限更新成功');
|
||||
console.log('📋 新的admin权限:', newPermissions);
|
||||
} else {
|
||||
console.log('❌ 未找到admin角色');
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
console.error('❌ 执行失败:', error.message);
|
||||
console.error('错误详情:', error);
|
||||
} finally {
|
||||
await sequelize.close();
|
||||
console.log('\n✅ 数据库连接已关闭');
|
||||
}
|
||||
}
|
||||
|
||||
fixAdminPermissions().catch(console.error);
|
||||
49
insurance_backend/scripts/fix-permissions.js
Normal file
49
insurance_backend/scripts/fix-permissions.js
Normal file
@@ -0,0 +1,49 @@
|
||||
console.log('🚀 开始修复权限...');
|
||||
|
||||
const { sequelize } = require('../config/database');
|
||||
const Role = require('../models/Role');
|
||||
|
||||
async function fixPermissions() {
|
||||
try {
|
||||
console.log('📡 连接数据库...');
|
||||
|
||||
// 测试数据库连接
|
||||
await sequelize.authenticate();
|
||||
console.log('✅ 数据库连接成功');
|
||||
|
||||
// 查询当前agent角色
|
||||
console.log('🔍 查询当前agent角色...');
|
||||
const agentRole = await Role.findOne({ where: { name: 'agent' } });
|
||||
|
||||
if (agentRole) {
|
||||
console.log('📋 当前agent角色权限:', agentRole.permissions);
|
||||
|
||||
// 更新agent角色权限
|
||||
console.log('🔧 更新agent角色权限...');
|
||||
await agentRole.update({
|
||||
permissions: JSON.stringify(['insurance:read', 'insurance:create', 'policy:read', 'policy:create', 'claim:read', 'claim:create'])
|
||||
});
|
||||
|
||||
console.log('✅ agent角色权限更新成功');
|
||||
} else {
|
||||
console.log('❌ 未找到agent角色');
|
||||
}
|
||||
|
||||
// 查询所有角色权限确认
|
||||
console.log('📋 查询当前所有角色权限配置...');
|
||||
const roles = await Role.findAll();
|
||||
console.log('\n当前角色权限配置:');
|
||||
roles.forEach(role => {
|
||||
console.log(`${role.name}: ${role.permissions}`);
|
||||
});
|
||||
|
||||
} catch (error) {
|
||||
console.error('❌ 执行失败:', error.message);
|
||||
console.error('错误详情:', error);
|
||||
} finally {
|
||||
await sequelize.close();
|
||||
console.log('\n✅ 数据库连接已关闭');
|
||||
}
|
||||
}
|
||||
|
||||
fixPermissions().catch(console.error);
|
||||
41
insurance_backend/scripts/insert_claims_only.js
Normal file
41
insurance_backend/scripts/insert_claims_only.js
Normal file
@@ -0,0 +1,41 @@
|
||||
const { sequelize } = require('../config/database');
|
||||
|
||||
async function insertClaimsData() {
|
||||
try {
|
||||
console.log('开始插入理赔数据...');
|
||||
|
||||
// 插入理赔数据
|
||||
await sequelize.query(`
|
||||
INSERT INTO livestock_claims (
|
||||
claim_no, policy_id, claim_type, incident_date, report_date,
|
||||
incident_description, incident_location, affected_count,
|
||||
claim_amount, claim_status, investigator_id,
|
||||
reviewer_id, created_by, updated_by
|
||||
) VALUES
|
||||
('CL202303050001', 1, 'disease', '2023-03-01', '2023-03-02', '牛群感染口蹄疫,导致5头牛死亡', '内蒙古自治区呼和浩特市赛罕区昭乌达路养殖场', 5, 35000.00, 'approved', 1, 1, 1, 1),
|
||||
('CL202303100002', 2, 'natural_disaster', '2023-03-08', '2023-03-09', '暴雪导致羊舍倒塌,造成10只羊死亡', '内蒙古自治区包头市昆都仑区钢铁大街养殖场', 10, 10000.00, 'investigating', 1, NULL, 1, 1),
|
||||
('CL202302200003', 4, 'accident', '2023-02-18', '2023-02-19', '运输车辆事故,导致3头牛受伤', '内蒙古自治区通辽市科尔沁区建国路', 3, 12000.00, 'pending', NULL, NULL, 1, 1)
|
||||
`);
|
||||
console.log('✅ 理赔数据插入成功');
|
||||
|
||||
// 验证数据插入结果
|
||||
const [claimCount] = await sequelize.query("SELECT COUNT(*) as count FROM livestock_claims");
|
||||
console.log(`数据库中共有 ${claimCount[0].count} 条理赔记录`);
|
||||
|
||||
} catch (error) {
|
||||
console.error('❌ 插入理赔数据失败:', error.message);
|
||||
if (error.errors) {
|
||||
console.error('详细错误信息:');
|
||||
error.errors.forEach(err => {
|
||||
console.error(`- ${err.path}: ${err.message}`);
|
||||
});
|
||||
}
|
||||
if (error.sql) {
|
||||
console.error('SQL语句:', error.sql);
|
||||
}
|
||||
} finally {
|
||||
await sequelize.close();
|
||||
}
|
||||
}
|
||||
|
||||
insertClaimsData();
|
||||
@@ -4,13 +4,13 @@ SET CHARACTER SET utf8mb4;
|
||||
-- 更新默认角色权限
|
||||
UPDATE roles SET
|
||||
description = '系统管理员',
|
||||
permissions = '["user:read","user:create","user:update","user:delete","insurance:read","insurance:create","insurance:update","insurance:delete","insurance:review","policy:read","policy:create","policy:update","policy:delete","claim:read","claim:create","claim:update","claim:review","system:read","system:update","system:admin"]'
|
||||
permissions = '["user:read","user:create","user:update","user:delete","insurance:read","insurance:create","insurance:update","insurance:delete","insurance:review","policy:read","policy:create","policy:update","policy:delete","livestock_policy:read","livestock_policy:create","livestock_policy:update","livestock_policy:delete","claim:read","claim:create","claim:update","claim:review","system:read","system:update","system:admin"]'
|
||||
WHERE name = 'admin';
|
||||
|
||||
-- 插入其他角色(如果不存在)
|
||||
INSERT IGNORE INTO roles (name, description, permissions, status) VALUES
|
||||
('agent', '保险代理人', '["insurance:read","insurance:create","policy:read","policy:create","claim:read","claim:create"]', 'active'),
|
||||
('customer', '客户', '["insurance:read","policy:read","claim:read","claim:create"]', 'active');
|
||||
('agent', '保险代理人', '["insurance:read","insurance:create","policy:read","policy:create","livestock_policy:read","livestock_policy:create","livestock_policy:update","claim:read","claim:create"]', 'active'),
|
||||
('customer', '客户', '["insurance:read","policy:read","livestock_policy:read","claim:read","claim:create"]', 'active');
|
||||
|
||||
-- 插入默认保险类型
|
||||
INSERT IGNORE INTO insurance_types (name, description, coverage_amount_min, coverage_amount_max, premium_rate, status) VALUES
|
||||
|
||||
235
insurance_backend/scripts/insert_livestock_test_data.js
Normal file
235
insurance_backend/scripts/insert_livestock_test_data.js
Normal file
@@ -0,0 +1,235 @@
|
||||
const { sequelize } = require('../models');
|
||||
const { LivestockType, LivestockPolicy, LivestockClaim, User } = require('../models');
|
||||
|
||||
async function insertTestData() {
|
||||
try {
|
||||
console.log('开始插入生资保险测试数据...');
|
||||
|
||||
// 创建测试用户(如果不存在)
|
||||
const [testUser] = await User.findOrCreate({
|
||||
where: { username: 'test_admin' },
|
||||
defaults: {
|
||||
username: 'test_admin',
|
||||
password: '$2b$10$example', // 示例密码哈希
|
||||
real_name: '测试管理员',
|
||||
email: 'test@example.com',
|
||||
phone: '13800138000',
|
||||
role_id: 1, // admin角色ID
|
||||
status: 'active'
|
||||
}
|
||||
});
|
||||
|
||||
// 插入牲畜类型测试数据
|
||||
const livestockTypes = [
|
||||
{
|
||||
name: '奶牛',
|
||||
code: 'DAIRY_COW',
|
||||
description: '用于产奶的牛类',
|
||||
unit_price_min: 10000.00,
|
||||
unit_price_max: 20000.00,
|
||||
premium_rate: 0.05,
|
||||
status: 'active'
|
||||
},
|
||||
{
|
||||
name: '肉牛',
|
||||
code: 'BEEF_COW',
|
||||
description: '用于肉类生产的牛类',
|
||||
unit_price_min: 8000.00,
|
||||
unit_price_max: 16000.00,
|
||||
premium_rate: 0.04,
|
||||
status: 'active'
|
||||
},
|
||||
{
|
||||
name: '生猪',
|
||||
code: 'PIG',
|
||||
description: '用于肉类生产的猪类',
|
||||
unit_price_min: 1500.00,
|
||||
unit_price_max: 2500.00,
|
||||
premium_rate: 0.06,
|
||||
status: 'active'
|
||||
},
|
||||
{
|
||||
name: '羊',
|
||||
code: 'SHEEP',
|
||||
description: '包括山羊和绵羊',
|
||||
unit_price_min: 600.00,
|
||||
unit_price_max: 1000.00,
|
||||
premium_rate: 0.05,
|
||||
status: 'active'
|
||||
}
|
||||
];
|
||||
|
||||
console.log('插入牲畜类型数据...');
|
||||
const createdTypes = await LivestockType.bulkCreate(livestockTypes, {
|
||||
returning: true
|
||||
});
|
||||
console.log(`成功插入 ${createdTypes.length} 个牲畜类型`);
|
||||
|
||||
// 插入生资保单测试数据
|
||||
const policies = [
|
||||
{
|
||||
policy_no: 'LP2024001',
|
||||
farmer_name: '张三',
|
||||
farmer_phone: '13800138001',
|
||||
farmer_id_card: '110101199001011234',
|
||||
livestock_type_id: createdTypes[0].id, // 奶牛
|
||||
livestock_count: 10,
|
||||
unit_value: 15000.00,
|
||||
total_value: 150000.00,
|
||||
premium_rate: 0.05,
|
||||
premium_amount: 7500.00,
|
||||
start_date: '2024-01-01',
|
||||
end_date: '2024-12-31',
|
||||
farm_name: '张三奶牛养殖场',
|
||||
farm_address: '北京市朝阳区某某村123号',
|
||||
farm_license: 'BJ2024001',
|
||||
policy_status: 'active',
|
||||
payment_status: 'paid',
|
||||
payment_date: '2024-01-01',
|
||||
notes: '优质奶牛保险',
|
||||
created_by: testUser.id,
|
||||
updated_by: testUser.id
|
||||
},
|
||||
{
|
||||
policy_no: 'LP2024002',
|
||||
farmer_name: '李四',
|
||||
farmer_phone: '13800138002',
|
||||
farmer_id_card: '110101199002021234',
|
||||
livestock_type_id: createdTypes[1].id, // 肉牛
|
||||
livestock_count: 20,
|
||||
unit_value: 12000.00,
|
||||
total_value: 240000.00,
|
||||
premium_rate: 0.04,
|
||||
premium_amount: 9600.00,
|
||||
start_date: '2024-02-01',
|
||||
end_date: '2025-01-31',
|
||||
farm_name: '李四肉牛养殖场',
|
||||
farm_address: '北京市海淀区某某村456号',
|
||||
farm_license: 'BJ2024002',
|
||||
policy_status: 'active',
|
||||
payment_status: 'paid',
|
||||
payment_date: '2024-02-01',
|
||||
notes: '肉牛养殖保险',
|
||||
created_by: testUser.id,
|
||||
updated_by: testUser.id
|
||||
},
|
||||
{
|
||||
policy_no: 'LP2024003',
|
||||
farmer_name: '王五',
|
||||
farmer_phone: '13800138003',
|
||||
farmer_id_card: '110101199003031234',
|
||||
livestock_type_id: createdTypes[2].id, // 生猪
|
||||
livestock_count: 100,
|
||||
unit_value: 2000.00,
|
||||
total_value: 200000.00,
|
||||
premium_rate: 0.06,
|
||||
premium_amount: 12000.00,
|
||||
start_date: '2024-03-01',
|
||||
end_date: '2025-02-28',
|
||||
farm_name: '王五生猪养殖场',
|
||||
farm_address: '北京市昌平区某某村789号',
|
||||
farm_license: 'BJ2024003',
|
||||
policy_status: 'active',
|
||||
payment_status: 'unpaid',
|
||||
notes: '生猪养殖保险',
|
||||
created_by: testUser.id,
|
||||
updated_by: testUser.id
|
||||
},
|
||||
{
|
||||
policy_no: 'LP2024004',
|
||||
farmer_name: '赵六',
|
||||
farmer_phone: '13800138004',
|
||||
farmer_id_card: '110101199004041234',
|
||||
livestock_type_id: createdTypes[3].id, // 羊
|
||||
livestock_count: 50,
|
||||
unit_value: 800.00,
|
||||
total_value: 40000.00,
|
||||
premium_rate: 0.05,
|
||||
premium_amount: 2000.00,
|
||||
start_date: '2024-04-01',
|
||||
end_date: '2025-03-31',
|
||||
farm_name: '赵六羊群养殖场',
|
||||
farm_address: '北京市房山区某某村101号',
|
||||
farm_license: 'BJ2024004',
|
||||
policy_status: 'active',
|
||||
payment_status: 'partial',
|
||||
payment_date: '2024-04-01',
|
||||
notes: '羊群保险',
|
||||
created_by: testUser.id,
|
||||
updated_by: testUser.id
|
||||
}
|
||||
];
|
||||
|
||||
console.log('插入生资保单数据...');
|
||||
const createdPolicies = await LivestockPolicy.bulkCreate(policies, {
|
||||
returning: true
|
||||
});
|
||||
console.log(`成功插入 ${createdPolicies.length} 个生资保单`);
|
||||
|
||||
// 插入生资理赔测试数据
|
||||
const claims = [
|
||||
{
|
||||
claim_no: 'LC2024001',
|
||||
policy_id: createdPolicies[0].id,
|
||||
claim_amount: 30000.00,
|
||||
incident_date: '2024-06-15',
|
||||
incident_description: '奶牛因疾病死亡2头',
|
||||
claim_status: 'paid',
|
||||
investigator_id: testUser.id,
|
||||
investigation_report: '经现场调查,确认奶牛因疫病死亡,符合保险条款',
|
||||
investigation_date: '2024-06-20',
|
||||
reviewer_id: testUser.id,
|
||||
review_notes: '经核实,符合理赔条件',
|
||||
review_date: '2024-06-25',
|
||||
payment_date: '2024-07-01',
|
||||
payment_amount: 30000.00,
|
||||
supporting_documents: JSON.stringify([
|
||||
{ type: 'death_certificate', url: '/documents/death_cert_001.pdf' },
|
||||
{ type: 'veterinary_report', url: '/documents/vet_report_001.pdf' }
|
||||
]),
|
||||
created_by: testUser.id,
|
||||
updated_by: testUser.id
|
||||
},
|
||||
{
|
||||
claim_no: 'LC2024002',
|
||||
policy_id: createdPolicies[1].id,
|
||||
claim_amount: 24000.00,
|
||||
incident_date: '2024-07-20',
|
||||
incident_description: '肉牛因自然灾害死亡2头',
|
||||
claim_status: 'investigating',
|
||||
investigator_id: testUser.id,
|
||||
investigation_report: '正在进行现场调查',
|
||||
investigation_date: '2024-07-25',
|
||||
supporting_documents: JSON.stringify([
|
||||
{ type: 'incident_report', url: '/documents/incident_002.pdf' }
|
||||
]),
|
||||
created_by: testUser.id,
|
||||
updated_by: testUser.id
|
||||
}
|
||||
];
|
||||
|
||||
console.log('插入生资理赔数据...');
|
||||
const createdClaims = await LivestockClaim.bulkCreate(claims, {
|
||||
returning: true
|
||||
});
|
||||
console.log(`成功插入 ${createdClaims.length} 个生资理赔记录`);
|
||||
|
||||
console.log('生资保险测试数据插入完成!');
|
||||
console.log('数据统计:');
|
||||
console.log(`- 牲畜类型: ${createdTypes.length} 个`);
|
||||
console.log(`- 生资保单: ${createdPolicies.length} 个`);
|
||||
console.log(`- 理赔记录: ${createdClaims.length} 个`);
|
||||
|
||||
} catch (error) {
|
||||
console.error('插入测试数据失败:', error);
|
||||
} finally {
|
||||
await sequelize.close();
|
||||
}
|
||||
}
|
||||
|
||||
// 如果直接运行此脚本
|
||||
if (require.main === module) {
|
||||
insertTestData();
|
||||
}
|
||||
|
||||
module.exports = insertTestData;
|
||||
80
insurance_backend/scripts/insert_livestock_test_data.sql
Normal file
80
insurance_backend/scripts/insert_livestock_test_data.sql
Normal file
@@ -0,0 +1,80 @@
|
||||
-- 插入生资保险测试数据
|
||||
|
||||
-- 插入牲畜类型测试数据
|
||||
INSERT INTO livestock_types (name, code, description, unit_price_min, unit_price_max, premium_rate, status) VALUES
|
||||
('奶牛', 'DAIRY_COW', '用于产奶的牛类', 10000.00, 20000.00, 0.0500, 'active'),
|
||||
('肉牛', 'BEEF_COW', '用于肉类生产的牛类', 8000.00, 16000.00, 0.0400, 'active'),
|
||||
('生猪', 'PIG', '用于肉类生产的猪类', 1500.00, 2500.00, 0.0600, 'active'),
|
||||
('羊', 'SHEEP', '包括山羊和绵羊', 600.00, 1000.00, 0.0500, 'active');
|
||||
|
||||
-- 插入生资保单测试数据
|
||||
INSERT INTO livestock_policies (
|
||||
policy_no, farmer_name, farmer_phone, farmer_id_card, livestock_type_id,
|
||||
livestock_count, unit_value, total_value, premium_rate, premium_amount,
|
||||
start_date, end_date, farm_name, farm_address, farm_license,
|
||||
policy_status, payment_status, payment_date, notes, created_by, updated_by
|
||||
) VALUES
|
||||
(
|
||||
'LP2024001', '张三', '13800138001', '110101199001011234',
|
||||
(SELECT id FROM livestock_types WHERE code = 'DAIRY_COW'),
|
||||
10, 15000.00, 150000.00, 0.0500, 7500.00,
|
||||
'2024-01-01', '2024-12-31', '张三奶牛养殖场', '北京市朝阳区某某村123号', 'BJ2024001',
|
||||
'active', 'paid', '2024-01-01', '优质奶牛保险', 1, 1
|
||||
),
|
||||
(
|
||||
'LP2024002', '李四', '13800138002', '110101199002021234',
|
||||
(SELECT id FROM livestock_types WHERE code = 'BEEF_COW'),
|
||||
20, 12000.00, 240000.00, 0.0400, 9600.00,
|
||||
'2024-02-01', '2025-01-31', '李四肉牛养殖场', '北京市海淀区某某村456号', 'BJ2024002',
|
||||
'active', 'paid', '2024-02-01', '肉牛养殖保险', 1, 1
|
||||
),
|
||||
(
|
||||
'LP2024003', '王五', '13800138003', '110101199003031234',
|
||||
(SELECT id FROM livestock_types WHERE code = 'PIG'),
|
||||
100, 2000.00, 200000.00, 0.0600, 12000.00,
|
||||
'2024-03-01', '2025-02-28', '王五生猪养殖场', '北京市昌平区某某村789号', 'BJ2024003',
|
||||
'active', 'unpaid', NULL, '生猪养殖保险', 1, 1
|
||||
),
|
||||
(
|
||||
'LP2024004', '赵六', '13800138004', '110101199004041234',
|
||||
(SELECT id FROM livestock_types WHERE code = 'SHEEP'),
|
||||
50, 800.00, 40000.00, 0.0500, 2000.00,
|
||||
'2024-04-01', '2025-03-31', '赵六羊群养殖场', '北京市房山区某某村101号', 'BJ2024004',
|
||||
'active', 'partial', '2024-04-01', '羊群保险', 1, 1
|
||||
);
|
||||
|
||||
-- 插入生资理赔测试数据
|
||||
INSERT INTO livestock_claims (
|
||||
claim_no, policy_id, claim_amount, incident_date, incident_description,
|
||||
claim_status, investigator_id, investigation_report, investigation_date,
|
||||
reviewer_id, review_notes, review_date, payment_date, payment_amount,
|
||||
supporting_documents, created_by, updated_by
|
||||
) VALUES
|
||||
(
|
||||
'LC2024001',
|
||||
(SELECT id FROM livestock_policies WHERE policy_no = 'LP2024001'),
|
||||
30000.00, '2024-06-15', '奶牛因疾病死亡2头',
|
||||
'paid', 1, '经现场调查,确认奶牛因疫病死亡,符合保险条款', '2024-06-20',
|
||||
1, '经核实,符合理赔条件', '2024-06-25', '2024-07-01', 30000.00,
|
||||
'[{"type":"death_certificate","url":"/documents/death_cert_001.pdf"},{"type":"veterinary_report","url":"/documents/vet_report_001.pdf"}]',
|
||||
1, 1
|
||||
),
|
||||
(
|
||||
'LC2024002',
|
||||
(SELECT id FROM livestock_policies WHERE policy_no = 'LP2024002'),
|
||||
24000.00, '2024-07-20', '肉牛因自然灾害死亡2头',
|
||||
'investigating', 1, '正在进行现场调查', '2024-07-25',
|
||||
NULL, NULL, NULL, NULL, NULL,
|
||||
'[{"type":"incident_report","url":"/documents/incident_002.pdf"}]',
|
||||
1, 1
|
||||
);
|
||||
|
||||
-- 查询插入结果
|
||||
SELECT '牲畜类型数据:' as info;
|
||||
SELECT id, name, code, unit_price_min, unit_price_max, premium_rate, status FROM livestock_types;
|
||||
|
||||
SELECT '生资保单数据:' as info;
|
||||
SELECT id, policy_no, farmer_name, livestock_count, total_value, policy_status, payment_status FROM livestock_policies;
|
||||
|
||||
SELECT '理赔记录数据:' as info;
|
||||
SELECT id, claim_no, claim_amount, incident_date, claim_status FROM livestock_claims;
|
||||
81
insurance_backend/scripts/insert_test_data.js
Normal file
81
insurance_backend/scripts/insert_test_data.js
Normal file
@@ -0,0 +1,81 @@
|
||||
const { sequelize } = require('../config/database');
|
||||
|
||||
async function insertTestData() {
|
||||
try {
|
||||
// 确保使用正确的数据库
|
||||
await sequelize.query('USE insurance_data');
|
||||
console.log('✅ 已切换到 insurance_data 数据库');
|
||||
|
||||
console.log('开始插入测试数据...');
|
||||
|
||||
// 1. 插入牲畜类型数据
|
||||
await sequelize.query(`
|
||||
INSERT IGNORE INTO livestock_types (name, code, description, unit_price_min, unit_price_max, premium_rate, status)
|
||||
VALUES
|
||||
('牛', 'CATTLE', '肉牛、奶牛等牛类牲畜', 5000.00, 30000.00, 0.0050, 'active'),
|
||||
('羊', 'SHEEP', '绵羊、山羊等羊类牲畜', 500.00, 3000.00, 0.0060, 'active'),
|
||||
('猪', 'PIG', '生猪、种猪等猪类牲畜', 1000.00, 5000.00, 0.0040, 'active'),
|
||||
('鸡', 'CHICKEN', '肉鸡、蛋鸡等鸡类家禽', 20.00, 100.00, 0.0080, 'active'),
|
||||
('鸭', 'DUCK', '肉鸭、蛋鸭等鸭类家禽', 30.00, 150.00, 0.0070, 'active')
|
||||
`);
|
||||
console.log('✅ 牲畜类型数据插入成功');
|
||||
|
||||
// 2. 插入生资保单数据
|
||||
await sequelize.query(`
|
||||
INSERT INTO livestock_policies (
|
||||
policy_no, livestock_type_id, policyholder_name, policyholder_id_card, policyholder_phone,
|
||||
policyholder_address, farm_address, livestock_count, unit_value, total_value,
|
||||
premium_amount, start_date, end_date, policy_status,
|
||||
created_by, updated_by
|
||||
) VALUES
|
||||
('202209312456789', 1, '张三', '150102198001011234', '13800138001', '内蒙古自治区呼和浩特市赛罕区昭乌达路', '内蒙古自治区呼和浩特市赛罕区昭乌达路养殖场', 50, 8000.00, 400000.00, 2000.00, '2023-03-05', '2024-03-04', 'active', 1, 1),
|
||||
('202209314567890', 2, '李四', '150203198002022345', '13800138002', '内蒙古自治区包头市昆都仑区钢铁大街', '内蒙古自治区包头市昆都仑区钢铁大街养殖场', 100, 1200.00, 120000.00, 720.00, '2023-03-10', '2024-03-09', 'active', 1, 1),
|
||||
('202209315432100', 3, '王五', '150602198003033456', '13800138003', '内蒙古自治区鄂尔多斯市东胜区铁西路', '内蒙古自治区鄂尔多斯市东胜区铁西路养殖场', 200, 2500.00, 500000.00, 2000.00, '2023-02-15', '2024-02-14', 'active', 1, 1),
|
||||
('202203316542100', 1, '赵六', '150502198004044567', '13800138004', '内蒙古自治区通辽市科尔沁区建国路', '内蒙古自治区通辽市科尔沁区建国路养殖场', 30, 12000.00, 360000.00, 1800.00, '2023-02-20', '2024-02-19', 'active', 1, 1),
|
||||
('202203311087654', 2, '孙七', '150802198005055678', '13800138005', '内蒙古自治区巴彦淖尔市临河区胜利路', '内蒙古自治区巴彦淖尔市临河区胜利路养殖场', 80, 1500.00, 120000.00, 720.00, '2023-01-30', '2024-01-29', 'active', 1, 1),
|
||||
('202203178001234', 4, '周八', '150902198006066789', '13800138006', '内蒙古自治区乌兰察布市集宁区新华街', '内蒙古自治区乌兰察布市集宁区新华街养殖场', 1000, 50.00, 50000.00, 400.00, '2023-01-15', '2024-01-14', 'active', 1, 1),
|
||||
('202203112345678', 5, '吴九', '152502198007077890', '13800138007', '内蒙古自治区锡林郭勒盟锡林浩特市额尔敦路', '内蒙古自治区锡林郭勒盟锡林浩特市额尔敦路养殖场', 800, 80.00, 64000.00, 448.00, '2023-01-10', '2024-01-09', 'active', 1, 1),
|
||||
('202203134567890', 1, '郑十', '150702198008088901', '13800138008', '内蒙古自治区呼伦贝尔市海拉尔区胜利大街', '内蒙古自治区呼伦贝尔市海拉尔区胜利大街养殖场', 25, 15000.00, 375000.00, 1875.00, '2022-12-20', '2023-12-19', 'expired', 1, 1),
|
||||
('202203154321098', 3, '陈十一', '150402198009099012', '13800138009', '内蒙古自治区赤峰市红山区钢铁街', '内蒙古自治区赤峰市红山区钢铁街养殖场', 150, 3000.00, 450000.00, 1800.00, '2022-12-15', '2023-12-14', 'expired', 1, 1)
|
||||
`);
|
||||
console.log('✅ 生资保单数据插入成功');
|
||||
|
||||
// 3. 插入理赔数据
|
||||
await sequelize.query(`
|
||||
INSERT INTO livestock_claims (
|
||||
claim_no, policy_id, claim_type, incident_date, report_date,
|
||||
incident_description, incident_location, affected_count,
|
||||
claim_amount, claim_status, investigator_id,
|
||||
reviewer_id, created_by, updated_by
|
||||
) VALUES
|
||||
('CL202303050001', 1, 'disease', '2023-03-01', '2023-03-02', '牛群感染口蹄疫,导致5头牛死亡', '内蒙古自治区呼和浩特市赛罕区昭乌达路养殖场', 5, 35000.00, 'approved', 1, 1, 1, 1),
|
||||
('CL202303100002', 2, 'natural_disaster', '2023-03-08', '2023-03-09', '暴雪导致羊舍倒塌,造成10只羊死亡', '内蒙古自治区包头市昆都仑区钢铁大街养殖场', 10, 10000.00, 'investigating', 1, NULL, 1, 1),
|
||||
('CL202302200003', 4, 'accident', '2023-02-18', '2023-02-19', '运输车辆事故,导致3头牛受伤', '内蒙古自治区通辽市科尔沁区建国路', 3, 12000.00, 'pending', NULL, NULL, 1, 1)
|
||||
`);
|
||||
console.log('✅ 理赔数据插入成功');
|
||||
|
||||
// 验证数据插入结果
|
||||
const [policyCount] = await sequelize.query("SELECT COUNT(*) as count FROM livestock_policies");
|
||||
const [claimCount] = await sequelize.query("SELECT COUNT(*) as count FROM livestock_claims");
|
||||
const [typeCount] = await sequelize.query("SELECT COUNT(*) as count FROM livestock_types");
|
||||
|
||||
console.log(`✅ 数据插入完成:`);
|
||||
console.log(` - 牲畜类型: ${typeCount[0].count} 条`);
|
||||
console.log(` - 生资保单: ${policyCount[0].count} 条`);
|
||||
console.log(` - 理赔记录: ${claimCount[0].count} 条`);
|
||||
|
||||
} catch (error) {
|
||||
console.error('❌ 插入测试数据失败:', error.message);
|
||||
if (error.errors) {
|
||||
console.error('详细错误信息:');
|
||||
error.errors.forEach(err => {
|
||||
console.error(`- ${err.path}: ${err.message}`);
|
||||
});
|
||||
}
|
||||
console.error('完整错误:', error);
|
||||
} finally {
|
||||
await sequelize.close();
|
||||
}
|
||||
}
|
||||
|
||||
insertTestData();
|
||||
129
insurance_backend/scripts/livestock_insurance_schema.sql
Normal file
129
insurance_backend/scripts/livestock_insurance_schema.sql
Normal file
@@ -0,0 +1,129 @@
|
||||
-- 生资保单相关数据库表结构
|
||||
-- 创建时间: 2024-01-XX
|
||||
-- 说明: 包含牲畜类型、生资保单、理赔记录等表
|
||||
|
||||
USE insurance_data;
|
||||
|
||||
-- 1. 生资保险类型表(牲畜类型)
|
||||
CREATE TABLE IF NOT EXISTS livestock_types (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY COMMENT '牲畜类型ID',
|
||||
name VARCHAR(50) NOT NULL UNIQUE COMMENT '牲畜类型名称(如:牛、羊、猪等)',
|
||||
code VARCHAR(20) NOT NULL UNIQUE COMMENT '牲畜类型代码',
|
||||
description TEXT NULL COMMENT '牲畜类型描述',
|
||||
unit_price_min DECIMAL(10,2) NOT NULL DEFAULT 0.00 COMMENT '单头最低价值',
|
||||
unit_price_max DECIMAL(10,2) NOT NULL DEFAULT 50000.00 COMMENT '单头最高价值',
|
||||
premium_rate DECIMAL(5,4) NOT NULL DEFAULT 0.0050 COMMENT '保险费率',
|
||||
status ENUM('active', 'inactive') NOT NULL DEFAULT 'active' COMMENT '状态',
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
|
||||
INDEX idx_livestock_type_name (name),
|
||||
INDEX idx_livestock_type_code (code),
|
||||
INDEX idx_livestock_type_status (status)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='牲畜类型表';
|
||||
|
||||
-- 2. 生资保单表
|
||||
CREATE TABLE IF NOT EXISTS livestock_policies (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY COMMENT '生资保单ID',
|
||||
policy_no VARCHAR(50) NOT NULL UNIQUE COMMENT '保单编号',
|
||||
policyholder_name VARCHAR(100) NOT NULL COMMENT '投保人姓名',
|
||||
policyholder_id_card VARCHAR(18) NOT NULL COMMENT '投保人身份证号',
|
||||
policyholder_phone VARCHAR(20) NOT NULL COMMENT '投保人手机号',
|
||||
policyholder_address VARCHAR(500) NOT NULL COMMENT '投保人地址',
|
||||
|
||||
livestock_type_id INT NOT NULL COMMENT '牲畜类型ID',
|
||||
livestock_count INT NOT NULL DEFAULT 1 COMMENT '参保数量',
|
||||
unit_value DECIMAL(10,2) NOT NULL COMMENT '单头价值',
|
||||
total_value DECIMAL(15,2) NOT NULL COMMENT '总保额',
|
||||
premium_amount DECIMAL(10,2) NOT NULL COMMENT '保费金额',
|
||||
|
||||
start_date DATE NOT NULL COMMENT '保险开始日期',
|
||||
end_date DATE NOT NULL COMMENT '保险结束日期',
|
||||
|
||||
farm_name VARCHAR(200) NULL COMMENT '养殖场名称',
|
||||
farm_address VARCHAR(500) NOT NULL COMMENT '养殖场地址',
|
||||
farm_license VARCHAR(100) NULL COMMENT '养殖许可证号',
|
||||
|
||||
policy_status ENUM('active', 'expired', 'cancelled', 'suspended') NOT NULL DEFAULT 'active' COMMENT '保单状态',
|
||||
payment_status ENUM('paid', 'unpaid', 'partial') NOT NULL DEFAULT 'unpaid' COMMENT '支付状态',
|
||||
payment_date DATE NULL COMMENT '支付日期',
|
||||
|
||||
policy_document_url VARCHAR(500) NULL COMMENT '保单文件URL',
|
||||
notes TEXT NULL COMMENT '备注信息',
|
||||
|
||||
created_by INT NULL COMMENT '创建人ID',
|
||||
updated_by INT NULL COMMENT '更新人ID',
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
|
||||
UNIQUE INDEX idx_livestock_policy_no (policy_no),
|
||||
INDEX idx_livestock_policy_holder (policyholder_name),
|
||||
INDEX idx_livestock_policy_id_card (policyholder_id_card),
|
||||
INDEX idx_livestock_policy_phone (policyholder_phone),
|
||||
INDEX idx_livestock_policy_status (policy_status),
|
||||
INDEX idx_livestock_policy_payment_status (payment_status),
|
||||
INDEX idx_livestock_policy_dates (start_date, end_date),
|
||||
INDEX idx_livestock_policy_type (livestock_type_id),
|
||||
|
||||
FOREIGN KEY (livestock_type_id) REFERENCES livestock_types(id) ON DELETE RESTRICT,
|
||||
FOREIGN KEY (created_by) REFERENCES users(id) ON DELETE SET NULL,
|
||||
FOREIGN KEY (updated_by) REFERENCES users(id) ON DELETE SET NULL
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='生资保单表';
|
||||
|
||||
-- 3. 生资保单理赔表
|
||||
CREATE TABLE IF NOT EXISTS livestock_claims (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY COMMENT '理赔ID',
|
||||
claim_no VARCHAR(50) NOT NULL UNIQUE COMMENT '理赔编号',
|
||||
policy_id INT NOT NULL COMMENT '关联的生资保单ID',
|
||||
|
||||
claim_type ENUM('death', 'disease', 'accident', 'natural_disaster') NOT NULL COMMENT '理赔类型',
|
||||
affected_count INT NOT NULL DEFAULT 1 COMMENT '受损数量',
|
||||
claim_amount DECIMAL(15,2) NOT NULL COMMENT '理赔金额',
|
||||
|
||||
incident_date DATE NOT NULL COMMENT '事故发生日期',
|
||||
report_date DATE NOT NULL COMMENT '报案日期',
|
||||
incident_description TEXT NOT NULL COMMENT '事故描述',
|
||||
incident_location VARCHAR(500) NOT NULL COMMENT '事故地点',
|
||||
|
||||
claim_status ENUM('pending', 'investigating', 'approved', 'rejected', 'paid') NOT NULL DEFAULT 'pending' COMMENT '理赔状态',
|
||||
|
||||
investigator_id INT NULL COMMENT '调查员ID',
|
||||
investigation_report TEXT NULL COMMENT '调查报告',
|
||||
investigation_date DATE NULL COMMENT '调查日期',
|
||||
|
||||
reviewer_id INT NULL COMMENT '审核人ID',
|
||||
review_notes TEXT NULL COMMENT '审核备注',
|
||||
review_date DATE NULL COMMENT '审核日期',
|
||||
|
||||
payment_date DATE NULL COMMENT '支付日期',
|
||||
payment_amount DECIMAL(15,2) NULL COMMENT '实际支付金额',
|
||||
|
||||
supporting_documents JSON NULL COMMENT '支持文件',
|
||||
|
||||
created_by INT NULL COMMENT '创建人ID',
|
||||
updated_by INT NULL COMMENT '更新人ID',
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
|
||||
UNIQUE INDEX idx_livestock_claim_no (claim_no),
|
||||
INDEX idx_livestock_claim_policy (policy_id),
|
||||
INDEX idx_livestock_claim_status (claim_status),
|
||||
INDEX idx_livestock_claim_type (claim_type),
|
||||
INDEX idx_livestock_claim_date (incident_date),
|
||||
INDEX idx_livestock_claim_investigator (investigator_id),
|
||||
INDEX idx_livestock_claim_reviewer (reviewer_id),
|
||||
|
||||
FOREIGN KEY (policy_id) REFERENCES livestock_policies(id) ON DELETE RESTRICT,
|
||||
FOREIGN KEY (investigator_id) REFERENCES users(id) ON DELETE SET NULL,
|
||||
FOREIGN KEY (reviewer_id) REFERENCES users(id) ON DELETE SET NULL,
|
||||
FOREIGN KEY (created_by) REFERENCES users(id) ON DELETE SET NULL,
|
||||
FOREIGN KEY (updated_by) REFERENCES users(id) ON DELETE SET NULL
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='生资保单理赔表';
|
||||
|
||||
-- 插入默认牲畜类型数据
|
||||
INSERT INTO livestock_types (name, code, description, unit_price_min, unit_price_max, premium_rate, status) VALUES
|
||||
('牛', 'CATTLE', '肉牛、奶牛等牛类牲畜', 5000.00, 30000.00, 0.0050, 'active'),
|
||||
('羊', 'SHEEP', '绵羊、山羊等羊类牲畜', 500.00, 3000.00, 0.0060, 'active'),
|
||||
('猪', 'PIG', '生猪、种猪等猪类牲畜', 1000.00, 5000.00, 0.0040, 'active'),
|
||||
('鸡', 'CHICKEN', '肉鸡、蛋鸡等鸡类家禽', 20.00, 100.00, 0.0080, 'active'),
|
||||
('鸭', 'DUCK', '肉鸭、蛋鸭等鸭类家禽', 30.00, 150.00, 0.0070, 'active');
|
||||
108
insurance_backend/scripts/regulatory_task_completion.sql
Normal file
108
insurance_backend/scripts/regulatory_task_completion.sql
Normal file
@@ -0,0 +1,108 @@
|
||||
-- 监管任务结项功能数据库表结构
|
||||
-- 创建时间: 2025-01-23
|
||||
-- 数据库: MySQL 8.0+
|
||||
|
||||
USE nxxmdata;
|
||||
|
||||
-- 1. 监管任务结项表
|
||||
CREATE TABLE IF NOT EXISTS regulatory_task_completions (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY COMMENT '结项ID',
|
||||
application_no VARCHAR(50) NOT NULL COMMENT '申请编号',
|
||||
policy_no VARCHAR(50) NOT NULL COMMENT '保单编号',
|
||||
product_name VARCHAR(100) NOT NULL COMMENT '产品名称',
|
||||
customer_name VARCHAR(100) NOT NULL COMMENT '客户姓名',
|
||||
id_type ENUM('身份证', '护照', '军官证', '其他') NOT NULL DEFAULT '身份证' COMMENT '证件类型',
|
||||
id_number VARCHAR(50) NOT NULL COMMENT '证件号码',
|
||||
product_type_premium DECIMAL(15,2) NOT NULL COMMENT '产品类型保费',
|
||||
regulatory_effective_premium DECIMAL(15,2) NOT NULL COMMENT '监管生效保费',
|
||||
insurance_period VARCHAR(100) NOT NULL COMMENT '保险期间',
|
||||
insurance_amount DECIMAL(15,2) NOT NULL COMMENT '保险金额',
|
||||
payment_method VARCHAR(50) NOT NULL COMMENT '缴费方式',
|
||||
payment_period VARCHAR(50) NOT NULL COMMENT '缴费期间',
|
||||
|
||||
-- 结项相关字段
|
||||
completion_status ENUM('pending', 'in_progress', 'completed', 'rejected') NOT NULL DEFAULT 'pending' COMMENT '结项状态',
|
||||
completion_date DATE NULL COMMENT '结项日期',
|
||||
completion_notes TEXT NULL COMMENT '结项备注',
|
||||
completion_documents JSON NULL COMMENT '结项文档',
|
||||
|
||||
-- 审核相关字段
|
||||
reviewer_id INT NULL COMMENT '审核人ID',
|
||||
review_date DATE NULL COMMENT '审核日期',
|
||||
review_notes TEXT NULL COMMENT '审核备注',
|
||||
|
||||
-- 关联字段(暂不设置外键约束)
|
||||
policy_id INT NULL COMMENT '关联保单ID',
|
||||
application_id INT NULL COMMENT '关联申请ID',
|
||||
insurance_type_id INT NULL COMMENT '保险类型ID',
|
||||
customer_id INT NULL COMMENT '客户ID',
|
||||
|
||||
-- 系统字段
|
||||
created_by INT NULL COMMENT '创建人ID',
|
||||
updated_by INT NULL COMMENT '更新人ID',
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
|
||||
-- 索引
|
||||
UNIQUE INDEX idx_application_no (application_no),
|
||||
INDEX idx_policy_no (policy_no),
|
||||
INDEX idx_customer_name (customer_name),
|
||||
INDEX idx_id_number (id_number),
|
||||
INDEX idx_completion_status (completion_status),
|
||||
INDEX idx_completion_date (completion_date),
|
||||
INDEX idx_reviewer_id (reviewer_id),
|
||||
INDEX idx_policy_id (policy_id),
|
||||
INDEX idx_application_id (application_id),
|
||||
INDEX idx_customer_id (customer_id),
|
||||
INDEX idx_created_at (created_at)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='监管任务结项表';
|
||||
|
||||
-- 2. 监管任务结项操作日志表
|
||||
CREATE TABLE IF NOT EXISTS regulatory_task_completion_logs (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY COMMENT '日志ID',
|
||||
completion_id INT NOT NULL COMMENT '结项ID',
|
||||
operation_type ENUM('create', 'update', 'review', 'approve', 'reject', 'complete') NOT NULL COMMENT '操作类型',
|
||||
operation_description TEXT NOT NULL COMMENT '操作描述',
|
||||
old_status VARCHAR(50) NULL COMMENT '原状态',
|
||||
new_status VARCHAR(50) NULL COMMENT '新状态',
|
||||
operator_id INT NOT NULL COMMENT '操作人ID',
|
||||
operation_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT '操作时间',
|
||||
ip_address VARCHAR(45) NULL COMMENT 'IP地址',
|
||||
user_agent TEXT NULL COMMENT '用户代理',
|
||||
|
||||
INDEX idx_completion_id (completion_id),
|
||||
INDEX idx_operation_type (operation_type),
|
||||
INDEX idx_operator_id (operator_id),
|
||||
INDEX idx_operation_time (operation_time)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='监管任务结项操作日志表';
|
||||
|
||||
-- 3. 监管任务结项附件表
|
||||
CREATE TABLE IF NOT EXISTS regulatory_task_completion_attachments (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY COMMENT '附件ID',
|
||||
completion_id INT NOT NULL COMMENT '结项ID',
|
||||
file_name VARCHAR(255) NOT NULL COMMENT '文件名',
|
||||
file_path VARCHAR(500) NOT NULL COMMENT '文件路径',
|
||||
file_size BIGINT NOT NULL COMMENT '文件大小(字节)',
|
||||
file_type VARCHAR(50) NOT NULL COMMENT '文件类型',
|
||||
mime_type VARCHAR(100) NOT NULL COMMENT 'MIME类型',
|
||||
upload_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT '上传时间',
|
||||
uploaded_by INT NOT NULL COMMENT '上传人ID',
|
||||
|
||||
INDEX idx_completion_id (completion_id),
|
||||
INDEX idx_file_type (file_type),
|
||||
INDEX idx_upload_time (upload_time),
|
||||
INDEX idx_uploaded_by (uploaded_by)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='监管任务结项附件表';
|
||||
|
||||
-- 插入示例数据
|
||||
INSERT INTO regulatory_task_completions (
|
||||
application_no, policy_no, product_name, customer_name, id_type, id_number,
|
||||
product_type_premium, regulatory_effective_premium, insurance_period,
|
||||
insurance_amount, payment_method, payment_period, completion_status
|
||||
) VALUES
|
||||
('APP20250123001', 'POL20250123001', '养殖保险', '张三', '身份证', '110101199001011234',
|
||||
5000.00, 4800.00, '2025-01-01至2025-12-31', 100000.00, '年缴', '1年', 'pending'),
|
||||
('APP20250123002', 'POL20250123002', '牲畜保险', '李四', '身份证', '110101199002021234',
|
||||
3000.00, 2900.00, '2025-01-01至2025-12-31', 80000.00, '年缴', '1年', 'in_progress'),
|
||||
('APP20250123003', 'POL20250123003', '农业保险', '王五', '身份证', '110101199003031234',
|
||||
4000.00, 3800.00, '2025-01-01至2025-12-31', 90000.00, '年缴', '1年', 'completed');
|
||||
269
insurance_backend/scripts/test_frontend_integration.js
Normal file
269
insurance_backend/scripts/test_frontend_integration.js
Normal file
@@ -0,0 +1,269 @@
|
||||
const axios = require('axios');
|
||||
|
||||
// 配置API基础URL
|
||||
const API_BASE_URL = 'http://localhost:3000/api';
|
||||
|
||||
// 创建axios实例
|
||||
const api = axios.create({
|
||||
baseURL: API_BASE_URL,
|
||||
timeout: 10000
|
||||
});
|
||||
|
||||
// 测试数据
|
||||
const testData = {
|
||||
username: 'admin',
|
||||
password: '123456'
|
||||
};
|
||||
|
||||
let authToken = '';
|
||||
|
||||
// 测试函数
|
||||
async function testLogin() {
|
||||
console.log('\n=== 测试1: 用户登录 ===');
|
||||
try {
|
||||
const response = await api.post('/auth/login', testData);
|
||||
console.log('✅ 登录成功');
|
||||
console.log('响应数据:', JSON.stringify(response.data, null, 2));
|
||||
|
||||
if (response.data.code === 200 && response.data.data.token) {
|
||||
authToken = response.data.data.token;
|
||||
// 设置后续请求的认证头
|
||||
api.defaults.headers.common['Authorization'] = `Bearer ${authToken}`;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
} catch (error) {
|
||||
console.log('❌ 登录失败:', error.response?.data || error.message);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
async function testLivestockPolicyList() {
|
||||
console.log('\n=== 测试2: 获取生资保单列表 ===');
|
||||
try {
|
||||
const response = await api.get('/livestock-policies');
|
||||
console.log('✅ 获取生资保单列表成功');
|
||||
console.log('响应数据:', JSON.stringify(response.data, null, 2));
|
||||
return response.data.data?.list || [];
|
||||
} catch (error) {
|
||||
console.log('❌ 获取生资保单列表失败:', error.response?.data || error.message);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
async function testLivestockTypes() {
|
||||
console.log('\n=== 测试3: 获取牲畜类型列表 ===');
|
||||
try {
|
||||
const response = await api.get('/livestock-types?status=active');
|
||||
console.log('✅ 获取牲畜类型列表成功');
|
||||
console.log('响应数据:', JSON.stringify(response.data, null, 2));
|
||||
|
||||
// 根据实际的响应格式解析数据
|
||||
const list = response.data.data || [];
|
||||
// console.log('🔍 解析出的牲畜类型数组长度:', list.length);
|
||||
// if (list.length > 0) {
|
||||
// console.log('🔍 第一个牲畜类型:', list[0]);
|
||||
// }
|
||||
return list;
|
||||
} catch (error) {
|
||||
console.log('❌ 获取牲畜类型列表失败:', error.response?.data || error.message);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
async function testCreateLivestockPolicy(livestockTypes) {
|
||||
console.log('\n=== 测试4: 创建生资保单 ===');
|
||||
// console.log('🔍 接收到的牲畜类型参数:', livestockTypes);
|
||||
// console.log('🔍 牲畜类型数组长度:', livestockTypes ? livestockTypes.length : 'undefined');
|
||||
|
||||
if (!livestockTypes || livestockTypes.length === 0) {
|
||||
console.log('❌ 无法创建保单:没有可用的牲畜类型');
|
||||
return null;
|
||||
}
|
||||
|
||||
const livestockType = livestockTypes[0];
|
||||
const livestockCount = 10;
|
||||
const unitValue = 5000;
|
||||
const totalValue = livestockCount * unitValue;
|
||||
const premiumAmount = totalValue * parseFloat(livestockType.premium_rate);
|
||||
|
||||
const newPolicy = {
|
||||
policy_no: `LP${Date.now()}${Math.random().toString(36).substr(2, 9).toUpperCase()}`,
|
||||
livestock_type_id: livestockType.id,
|
||||
policyholder_name: '测试农户',
|
||||
policyholder_id_card: '110101199001011234',
|
||||
policyholder_phone: '13800138000',
|
||||
policyholder_address: '北京市朝阳区测试街道123号',
|
||||
farm_address: '北京市朝阳区测试街道123号',
|
||||
livestock_count: livestockCount,
|
||||
unit_value: unitValue,
|
||||
total_value: totalValue,
|
||||
premium_amount: premiumAmount,
|
||||
start_date: '2024-01-01 08:00:00',
|
||||
end_date: '2024-12-31 08:00:00',
|
||||
policy_status: 'active',
|
||||
payment_status: 'unpaid',
|
||||
created_by: 1
|
||||
};
|
||||
|
||||
try {
|
||||
const response = await api.post('/livestock-policies', newPolicy);
|
||||
console.log('✅ 创建生资保单成功');
|
||||
console.log('响应数据:', JSON.stringify(response.data, null, 2));
|
||||
return response.data.data;
|
||||
} catch (error) {
|
||||
console.log('❌ 创建生资保单失败:', error.response?.data || error.message);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async function testUpdateLivestockPolicy(policyId) {
|
||||
console.log('\n=== 测试5: 更新生资保单 ===');
|
||||
|
||||
const updateData = {
|
||||
farmer_name: '测试农户(已更新)',
|
||||
livestock_count: 15,
|
||||
total_value: 75000,
|
||||
premium_amount: 750
|
||||
};
|
||||
|
||||
try {
|
||||
const response = await api.put(`/livestock-policies/${policyId}`, updateData);
|
||||
console.log('✅ 更新生资保单成功');
|
||||
console.log('响应数据:', JSON.stringify(response.data, null, 2));
|
||||
return response.data.data;
|
||||
} catch (error) {
|
||||
console.log('❌ 更新生资保单失败:', error.response?.data || error.message);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async function testGetLivestockPolicyDetail(policyId) {
|
||||
console.log('\n=== 测试6: 获取生资保单详情 ===');
|
||||
|
||||
try {
|
||||
const response = await api.get(`/livestock-policies/${policyId}`);
|
||||
console.log('✅ 获取生资保单详情成功');
|
||||
console.log('响应数据:', JSON.stringify(response.data, null, 2));
|
||||
return response.data.data;
|
||||
} catch (error) {
|
||||
console.log('❌ 获取生资保单详情失败:', error.response?.data || error.message);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async function testUpdatePolicyStatus(policyId) {
|
||||
console.log('\n=== 测试7: 更新保单状态 ===');
|
||||
|
||||
try {
|
||||
const response = await api.patch(`/livestock-policies/${policyId}/status`, {
|
||||
policy_status: 'active'
|
||||
});
|
||||
console.log('✅ 更新保单状态成功');
|
||||
console.log('响应数据:', JSON.stringify(response.data, null, 2));
|
||||
return response.data.data;
|
||||
} catch (error) {
|
||||
console.log('❌ 更新保单状态失败:', error.response?.data || error.message);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async function testSearchLivestockPolicies() {
|
||||
console.log('\n=== 测试8: 搜索生资保单 ===');
|
||||
|
||||
try {
|
||||
const response = await api.get('/livestock-policies', {
|
||||
params: {
|
||||
farmer_name: '测试',
|
||||
policy_status: 'active',
|
||||
page: 1,
|
||||
limit: 10
|
||||
}
|
||||
});
|
||||
console.log('✅ 搜索生资保单成功');
|
||||
console.log('响应数据:', JSON.stringify(response.data, null, 2));
|
||||
return response.data.data?.list || [];
|
||||
} catch (error) {
|
||||
console.log('❌ 搜索生资保单失败:', error.response?.data || error.message);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
async function testDeleteLivestockPolicy(policyId) {
|
||||
console.log('\n=== 测试9: 删除生资保单 ===');
|
||||
|
||||
try {
|
||||
const response = await api.delete(`/livestock-policies/${policyId}`);
|
||||
console.log('✅ 删除生资保单成功');
|
||||
console.log('响应数据:', JSON.stringify(response.data, null, 2));
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.log('❌ 删除生资保单失败:', error.response?.data || error.message);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// 主测试函数
|
||||
async function runTests() {
|
||||
console.log('🚀 开始前端集成测试...');
|
||||
console.log('测试API基础URL:', API_BASE_URL);
|
||||
|
||||
try {
|
||||
// 1. 测试登录
|
||||
const loginSuccess = await testLogin();
|
||||
if (!loginSuccess) {
|
||||
console.log('\n❌ 登录失败,终止测试');
|
||||
return;
|
||||
}
|
||||
|
||||
// 2. 测试获取保单列表
|
||||
const initialList = await testLivestockPolicyList();
|
||||
console.log(`\n📊 当前保单数量: ${initialList.length}`);
|
||||
|
||||
// 3. 测试获取牲畜类型
|
||||
const livestockTypes = await testLivestockTypes();
|
||||
|
||||
// 4. 测试创建保单
|
||||
const newPolicy = await testCreateLivestockPolicy(livestockTypes);
|
||||
if (!newPolicy) {
|
||||
console.log('\n❌ 创建保单失败,跳过后续测试');
|
||||
return;
|
||||
}
|
||||
|
||||
const policyId = newPolicy.id;
|
||||
console.log(`\n📝 创建的保单ID: ${policyId}`);
|
||||
|
||||
// 5. 测试获取保单详情
|
||||
await testGetLivestockPolicyDetail(policyId);
|
||||
|
||||
// 6. 测试更新保单
|
||||
await testUpdateLivestockPolicy(policyId);
|
||||
|
||||
// 7. 测试更新保单状态
|
||||
await testUpdatePolicyStatus(policyId);
|
||||
|
||||
// 8. 测试搜索保单
|
||||
await testSearchLivestockPolicies();
|
||||
|
||||
// 9. 测试删除保单
|
||||
await testDeleteLivestockPolicy(policyId);
|
||||
|
||||
// 10. 再次获取保单列表验证删除
|
||||
const finalList = await testLivestockPolicyList();
|
||||
console.log(`\n📊 删除后保单数量: ${finalList.length}`);
|
||||
|
||||
console.log('\n🎉 所有测试完成!');
|
||||
|
||||
} catch (error) {
|
||||
console.error('\n💥 测试过程中发生错误:', error);
|
||||
}
|
||||
}
|
||||
|
||||
// 运行测试
|
||||
runTests().then(() => {
|
||||
console.log('\n✨ 测试脚本执行完毕');
|
||||
process.exit(0);
|
||||
}).catch(error => {
|
||||
console.error('\n💥 测试脚本执行失败:', error);
|
||||
process.exit(1);
|
||||
});
|
||||
56
insurance_backend/scripts/test_login.js
Normal file
56
insurance_backend/scripts/test_login.js
Normal file
@@ -0,0 +1,56 @@
|
||||
const axios = require('axios');
|
||||
|
||||
// 测试登录功能
|
||||
async function testLogin() {
|
||||
const baseURL = 'http://localhost:3000';
|
||||
|
||||
console.log('=== 开始测试登录功能 ===\n');
|
||||
|
||||
try {
|
||||
// 测试1: 正确的用户名和密码
|
||||
console.log('测试1: 使用正确的用户名和密码登录');
|
||||
const loginResponse = await axios.post(`${baseURL}/api/auth/login`, {
|
||||
username: 'admin',
|
||||
password: '123456'
|
||||
});
|
||||
|
||||
console.log('登录成功:', loginResponse.data);
|
||||
const token = loginResponse.data.data.token;
|
||||
|
||||
// 测试2:使用token访问受保护的API
|
||||
console.log('\n测试2:使用token访问生资保单API...');
|
||||
const protectedResponse = await axios.get('http://localhost:3000/api/livestock-policies', {
|
||||
headers: {
|
||||
'Authorization': `Bearer ${token}`
|
||||
}
|
||||
});
|
||||
console.log('✓ 带token访问成功:', protectedResponse.data);
|
||||
|
||||
// 测试3: 错误的用户名和密码
|
||||
console.log('\n测试3: 使用错误的用户名和密码');
|
||||
try {
|
||||
await axios.post(`${baseURL}/api/auth/login`, {
|
||||
username: 'wronguser',
|
||||
password: 'wrongpass'
|
||||
});
|
||||
} catch (error) {
|
||||
console.log('预期的登录失败:', error.response?.data?.message || error.message);
|
||||
}
|
||||
|
||||
// 测试4: 无token访问受保护的API
|
||||
console.log('\n测试4: 无token访问受保护的API');
|
||||
try {
|
||||
await axios.get(`${baseURL}/api/livestock-policies`);
|
||||
} catch (error) {
|
||||
console.log('预期的访问失败:', error.response?.data?.message || error.message);
|
||||
}
|
||||
|
||||
console.log('\n=== 登录功能测试完成 ===');
|
||||
|
||||
} catch (error) {
|
||||
console.error('测试失败:', error.response?.data || error.message);
|
||||
}
|
||||
}
|
||||
|
||||
// 运行测试
|
||||
testLogin();
|
||||
Reference in New Issue
Block a user