82 lines
2.9 KiB
JavaScript
82 lines
2.9 KiB
JavaScript
/**
|
|
* 测试修复后的智能项圈预警
|
|
* @file test-fixed-collar-alert.js
|
|
* @description 测试修复后的智能项圈预警数据展示
|
|
*/
|
|
|
|
const axios = require('axios');
|
|
|
|
const BASE_URL = 'http://localhost:5350/api/smart-alerts/public';
|
|
|
|
async function testFixedCollarAlert() {
|
|
console.log('🔧 测试修复后的智能项圈预警...\n');
|
|
|
|
try {
|
|
// 1. 获取预警列表
|
|
console.log('1. 获取预警列表...');
|
|
const listResponse = await axios.get(`${BASE_URL}/collar`, {
|
|
params: { page: 1, limit: 5 }
|
|
});
|
|
|
|
if (listResponse.data.success) {
|
|
const data = listResponse.data.data || [];
|
|
const stats = listResponse.data.stats || {};
|
|
|
|
console.log('✅ 数据获取成功');
|
|
console.log(`数据条数: ${data.length}`);
|
|
console.log('统计数据:', stats);
|
|
|
|
// 显示统计卡片数据
|
|
console.log('\n📊 统计卡片数据:');
|
|
console.log(`低电量预警: ${stats.lowBattery || 0}`);
|
|
console.log(`离线预警: ${stats.offline || 0}`);
|
|
console.log(`温度预警: ${stats.highTemperature || 0}`);
|
|
console.log(`异常运动预警: ${stats.abnormalMovement || 0}`);
|
|
console.log(`佩戴异常预警: ${stats.wearOff || 0}`);
|
|
|
|
// 显示前几条数据
|
|
console.log('\n📋 预警列表数据:');
|
|
data.slice(0, 3).forEach((item, index) => {
|
|
console.log(`\n第${index + 1}条数据:`);
|
|
console.log(` 项圈编号: ${item.collarNumber}`);
|
|
console.log(` 预警类型: ${item.alertType}`);
|
|
console.log(` 预警级别: ${item.alertLevel}`);
|
|
console.log(` 设备电量: ${item.battery}%`);
|
|
console.log(` 设备温度: ${item.temperature}°C`);
|
|
console.log(` 当日步数: ${item.dailySteps}`);
|
|
});
|
|
|
|
} else {
|
|
console.log('❌ 数据获取失败:', listResponse.data.message);
|
|
}
|
|
|
|
// 2. 测试统计数据API
|
|
console.log('\n2. 测试统计数据API...');
|
|
const statsResponse = await axios.get(`${BASE_URL}/collar/stats`);
|
|
|
|
if (statsResponse.data.success) {
|
|
const statsData = statsResponse.data.data || {};
|
|
console.log('✅ 统计数据API正常');
|
|
console.log('统计数据:', statsData);
|
|
} else {
|
|
console.log('❌ 统计数据API失败:', statsResponse.data.message);
|
|
}
|
|
|
|
console.log('\n🎉 测试完成!');
|
|
console.log('\n💡 现在前端页面应该能正确显示:');
|
|
console.log(' - 统计卡片显示非零数据');
|
|
console.log(' - 预警列表显示正确的预警类型和级别');
|
|
console.log(' - 数据来自API而不是硬编码');
|
|
|
|
} catch (error) {
|
|
console.error('❌ 测试失败:', error.message);
|
|
if (error.response) {
|
|
console.error('响应状态:', error.response.status);
|
|
console.error('响应数据:', error.response.data);
|
|
}
|
|
}
|
|
}
|
|
|
|
// 运行测试
|
|
testFixedCollarAlert().catch(console.error);
|