173 lines
6.5 KiB
JavaScript
173 lines
6.5 KiB
JavaScript
|
|
/**
|
|||
|
|
* 监管任务API测试脚本
|
|||
|
|
* @file test-supervision-tasks-api.js
|
|||
|
|
* @description 测试监管任务相关的API接口
|
|||
|
|
*/
|
|||
|
|
const axios = require('axios');
|
|||
|
|
|
|||
|
|
const API_BASE_URL = 'http://localhost:5351';
|
|||
|
|
|
|||
|
|
async function testSupervisionTasksAPI() {
|
|||
|
|
try {
|
|||
|
|
console.log('🚀 开始测试监管任务API...\n');
|
|||
|
|
|
|||
|
|
// 1. 先登录获取token
|
|||
|
|
console.log('1. 登录获取认证token...');
|
|||
|
|
const loginResponse = await axios.post(`${API_BASE_URL}/api/auth/login`, {
|
|||
|
|
username: 'admin',
|
|||
|
|
password: 'Admin123456'
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
if (!loginResponse.data.success) {
|
|||
|
|
throw new Error('登录失败: ' + loginResponse.data.message);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
const token = loginResponse.data.data.token;
|
|||
|
|
console.log('✅ 登录成功,获取到token\n');
|
|||
|
|
|
|||
|
|
const headers = {
|
|||
|
|
'Authorization': `Bearer ${token}`,
|
|||
|
|
'Content-Type': 'application/json'
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
// 2. 测试获取监管任务列表
|
|||
|
|
console.log('2. 测试获取监管任务列表...');
|
|||
|
|
const listResponse = await axios.get(`${API_BASE_URL}/api/supervision-tasks`, { headers });
|
|||
|
|
|
|||
|
|
if (listResponse.data.success) {
|
|||
|
|
console.log('✅ 获取监管任务列表成功');
|
|||
|
|
console.log(`📊 共 ${listResponse.data.data.tasks.length} 个监管任务`);
|
|||
|
|
console.log(`📈 分页信息: 第${listResponse.data.data.pagination.currentPage}页,共${listResponse.data.data.pagination.totalPages}页\n`);
|
|||
|
|
} else {
|
|||
|
|
console.log('❌ 获取监管任务列表失败:', listResponse.data.message);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 3. 测试获取监管任务统计
|
|||
|
|
console.log('3. 测试获取监管任务统计...');
|
|||
|
|
const statsResponse = await axios.get(`${API_BASE_URL}/api/supervision-tasks/stats`, { headers });
|
|||
|
|
|
|||
|
|
if (statsResponse.data.success) {
|
|||
|
|
console.log('✅ 获取监管任务统计成功');
|
|||
|
|
console.log('📊 统计信息:');
|
|||
|
|
console.log(` 总计: ${statsResponse.data.data.total}`);
|
|||
|
|
console.log(` 待监管: ${statsResponse.data.data.pending}`);
|
|||
|
|
console.log(` 监管中: ${statsResponse.data.data.supervising}`);
|
|||
|
|
console.log(` 已完成: ${statsResponse.data.data.completed}`);
|
|||
|
|
console.log(` 已暂停: ${statsResponse.data.data.suspended}\n`);
|
|||
|
|
} else {
|
|||
|
|
console.log('❌ 获取监管任务统计失败:', statsResponse.data.message);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 4. 测试创建监管任务
|
|||
|
|
console.log('4. 测试创建监管任务...');
|
|||
|
|
const newTask = {
|
|||
|
|
applicationNumber: 'APP_TEST_' + Date.now(),
|
|||
|
|
contractNumber: 'CONTRACT_TEST_' + Date.now(),
|
|||
|
|
productName: '测试农业贷款产品',
|
|||
|
|
customerName: '测试客户',
|
|||
|
|
idType: 'id_card',
|
|||
|
|
idNumber: '110101199001011234',
|
|||
|
|
assetType: 'cattle',
|
|||
|
|
assetQuantity: 10,
|
|||
|
|
supervisionStatus: 'pending',
|
|||
|
|
startTime: '2024-12-20',
|
|||
|
|
endTime: '2024-12-31',
|
|||
|
|
loanAmount: 100000.00,
|
|||
|
|
interestRate: 0.0600,
|
|||
|
|
loanTerm: 12,
|
|||
|
|
supervisorName: '测试监管员',
|
|||
|
|
supervisorPhone: '13800138000',
|
|||
|
|
farmAddress: '测试养殖场地址',
|
|||
|
|
remarks: '这是一个测试监管任务'
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
const createResponse = await axios.post(`${API_BASE_URL}/api/supervision-tasks`, newTask, { headers });
|
|||
|
|
|
|||
|
|
if (createResponse.data.success) {
|
|||
|
|
console.log('✅ 创建监管任务成功');
|
|||
|
|
console.log(`📋 任务ID: ${createResponse.data.data.id}`);
|
|||
|
|
console.log(`📋 申请单号: ${createResponse.data.data.applicationNumber}\n`);
|
|||
|
|
|
|||
|
|
const taskId = createResponse.data.data.id;
|
|||
|
|
|
|||
|
|
// 5. 测试获取监管任务详情
|
|||
|
|
console.log('5. 测试获取监管任务详情...');
|
|||
|
|
const detailResponse = await axios.get(`${API_BASE_URL}/api/supervision-tasks/${taskId}`, { headers });
|
|||
|
|
|
|||
|
|
if (detailResponse.data.success) {
|
|||
|
|
console.log('✅ 获取监管任务详情成功');
|
|||
|
|
console.log(`📋 客户姓名: ${detailResponse.data.data.customerName}`);
|
|||
|
|
console.log(`📋 监管状态: ${detailResponse.data.data.supervisionStatus}\n`);
|
|||
|
|
} else {
|
|||
|
|
console.log('❌ 获取监管任务详情失败:', detailResponse.data.message);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 6. 测试更新监管任务
|
|||
|
|
console.log('6. 测试更新监管任务...');
|
|||
|
|
const updateData = {
|
|||
|
|
supervisionStatus: 'supervising',
|
|||
|
|
remarks: '更新后的备注信息'
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
const updateResponse = await axios.put(`${API_BASE_URL}/api/supervision-tasks/${taskId}`, updateData, { headers });
|
|||
|
|
|
|||
|
|
if (updateResponse.data.success) {
|
|||
|
|
console.log('✅ 更新监管任务成功');
|
|||
|
|
console.log(`📋 新状态: ${updateResponse.data.data.supervisionStatus}\n`);
|
|||
|
|
} else {
|
|||
|
|
console.log('❌ 更新监管任务失败:', updateResponse.data.message);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 7. 测试批量更新状态
|
|||
|
|
console.log('7. 测试批量更新状态...');
|
|||
|
|
const batchUpdateData = {
|
|||
|
|
ids: [taskId],
|
|||
|
|
supervisionStatus: 'completed'
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
const batchUpdateResponse = await axios.put(`${API_BASE_URL}/api/supervision-tasks/batch/status`, batchUpdateData, { headers });
|
|||
|
|
|
|||
|
|
if (batchUpdateResponse.data.success) {
|
|||
|
|
console.log('✅ 批量更新状态成功');
|
|||
|
|
console.log(`📋 更新数量: ${batchUpdateResponse.data.data.updatedCount}\n`);
|
|||
|
|
} else {
|
|||
|
|
console.log('❌ 批量更新状态失败:', batchUpdateResponse.data.message);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 8. 测试删除监管任务
|
|||
|
|
console.log('8. 测试删除监管任务...');
|
|||
|
|
const deleteResponse = await axios.delete(`${API_BASE_URL}/api/supervision-tasks/${taskId}`, { headers });
|
|||
|
|
|
|||
|
|
if (deleteResponse.data.success) {
|
|||
|
|
console.log('✅ 删除监管任务成功\n');
|
|||
|
|
} else {
|
|||
|
|
console.log('❌ 删除监管任务失败:', deleteResponse.data.message);
|
|||
|
|
}
|
|||
|
|
} else {
|
|||
|
|
console.log('❌ 创建监管任务失败:', createResponse.data.message);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 9. 测试搜索功能
|
|||
|
|
console.log('9. 测试搜索功能...');
|
|||
|
|
const searchResponse = await axios.get(`${API_BASE_URL}/api/supervision-tasks?search=张三&supervisionStatus=supervising`, { headers });
|
|||
|
|
|
|||
|
|
if (searchResponse.data.success) {
|
|||
|
|
console.log('✅ 搜索功能测试成功');
|
|||
|
|
console.log(`📊 搜索结果: ${searchResponse.data.data.tasks.length} 条记录\n`);
|
|||
|
|
} else {
|
|||
|
|
console.log('❌ 搜索功能测试失败:', searchResponse.data.message);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
console.log('🎉 所有API测试完成!');
|
|||
|
|
|
|||
|
|
} catch (error) {
|
|||
|
|
console.error('❌ 测试失败:', error.message);
|
|||
|
|
if (error.response) {
|
|||
|
|
console.error('响应数据:', error.response.data);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 运行测试
|
|||
|
|
testSupervisionTasksAPI();
|