119 lines
4.2 KiB
JavaScript
119 lines
4.2 KiB
JavaScript
|
|
/**
|
||
|
|
* 检查特定项圈数据
|
||
|
|
* @file check-specific-collar.js
|
||
|
|
* @description 检查项圈编号22012000107的数据
|
||
|
|
*/
|
||
|
|
|
||
|
|
const axios = require('axios');
|
||
|
|
|
||
|
|
const BASE_URL = 'http://localhost:5350/api/smart-alerts/public';
|
||
|
|
|
||
|
|
async function checkSpecificCollar() {
|
||
|
|
console.log('🔍 检查项圈编号22012000107的数据...\n');
|
||
|
|
|
||
|
|
try {
|
||
|
|
// 1. 搜索特定项圈编号
|
||
|
|
console.log('1. 搜索项圈编号22012000107...');
|
||
|
|
const searchResponse = await axios.get(`${BASE_URL}/collar`, {
|
||
|
|
params: {
|
||
|
|
search: '22012000107',
|
||
|
|
page: 1,
|
||
|
|
limit: 10
|
||
|
|
}
|
||
|
|
});
|
||
|
|
|
||
|
|
if (searchResponse.data.success) {
|
||
|
|
const data = searchResponse.data.data || [];
|
||
|
|
console.log(`找到 ${data.length} 条相关数据`);
|
||
|
|
|
||
|
|
data.forEach((item, index) => {
|
||
|
|
console.log(`\n第${index + 1}条数据:`);
|
||
|
|
console.log('原始API数据:', {
|
||
|
|
id: item.id,
|
||
|
|
collarNumber: item.collarNumber,
|
||
|
|
battery: item.battery,
|
||
|
|
batteryLevel: item.batteryLevel,
|
||
|
|
temperature: item.temperature,
|
||
|
|
temp: item.temp,
|
||
|
|
alertType: item.alertType,
|
||
|
|
alertLevel: item.alertLevel,
|
||
|
|
alertTime: item.alertTime,
|
||
|
|
dailySteps: item.dailySteps,
|
||
|
|
steps: item.steps
|
||
|
|
});
|
||
|
|
|
||
|
|
// 模拟前端转换逻辑
|
||
|
|
const transformedData = {
|
||
|
|
id: item.id || `${item.deviceId || item.sn}_${item.alertType || 'normal'}`,
|
||
|
|
collarNumber: item.collarNumber || item.sn || item.deviceId || '',
|
||
|
|
battery: item.battery || item.batteryLevel || '',
|
||
|
|
temperature: item.temperature || item.temp || '',
|
||
|
|
dailySteps: item.dailySteps || item.steps || ''
|
||
|
|
};
|
||
|
|
|
||
|
|
console.log('前端转换后:', transformedData);
|
||
|
|
});
|
||
|
|
|
||
|
|
} else {
|
||
|
|
console.log('❌ 搜索失败:', searchResponse.data.message);
|
||
|
|
}
|
||
|
|
|
||
|
|
// 2. 获取所有数据并查找特定项圈
|
||
|
|
console.log('\n2. 获取所有数据查找特定项圈...');
|
||
|
|
const allResponse = await axios.get(`${BASE_URL}/collar`, {
|
||
|
|
params: { page: 1, limit: 100 }
|
||
|
|
});
|
||
|
|
|
||
|
|
if (allResponse.data.success) {
|
||
|
|
const allData = allResponse.data.data || [];
|
||
|
|
const specificCollars = allData.filter(item =>
|
||
|
|
item.collarNumber == 22012000107 ||
|
||
|
|
item.deviceName == 22012000107 ||
|
||
|
|
item.sn == 22012000107
|
||
|
|
);
|
||
|
|
|
||
|
|
console.log(`在所有数据中找到 ${specificCollars.length} 条项圈22012000107的数据`);
|
||
|
|
|
||
|
|
specificCollars.forEach((item, index) => {
|
||
|
|
console.log(`\n项圈22012000107 - 第${index + 1}条:`);
|
||
|
|
console.log('ID:', item.id);
|
||
|
|
console.log('项圈编号:', item.collarNumber);
|
||
|
|
console.log('设备名称:', item.deviceName);
|
||
|
|
console.log('电量字段1 (battery):', item.battery);
|
||
|
|
console.log('电量字段2 (batteryLevel):', item.batteryLevel);
|
||
|
|
console.log('温度字段1 (temperature):', item.temperature);
|
||
|
|
console.log('温度字段2 (temp):', item.temp);
|
||
|
|
console.log('预警类型:', item.alertType);
|
||
|
|
console.log('预警级别:', item.alertLevel);
|
||
|
|
console.log('预警时间:', item.alertTime);
|
||
|
|
console.log('步数字段1 (dailySteps):', item.dailySteps);
|
||
|
|
console.log('步数字段2 (steps):', item.steps);
|
||
|
|
console.log('总步数:', item.totalSteps);
|
||
|
|
console.log('昨日步数:', item.yesterdaySteps);
|
||
|
|
});
|
||
|
|
|
||
|
|
} else {
|
||
|
|
console.log('❌ 获取所有数据失败:', allResponse.data.message);
|
||
|
|
}
|
||
|
|
|
||
|
|
// 3. 检查数据库原始数据
|
||
|
|
console.log('\n3. 检查数据库原始数据...');
|
||
|
|
console.log('请检查数据库中项圈22012000107的原始数据');
|
||
|
|
console.log('可能需要检查以下字段:');
|
||
|
|
console.log('- battery_level 或 battery 字段');
|
||
|
|
console.log('- temperature 或 temp 字段');
|
||
|
|
console.log('- 数据更新时间');
|
||
|
|
console.log('- 是否有多个记录');
|
||
|
|
|
||
|
|
} catch (error) {
|
||
|
|
console.error('❌ 检查失败:', error.message);
|
||
|
|
if (error.response) {
|
||
|
|
console.error('响应状态:', error.response.status);
|
||
|
|
console.error('响应数据:', error.response.data);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// 运行检查
|
||
|
|
checkSpecificCollar().catch(console.error);
|