完善保险端前后端和养殖端小程序
This commit is contained in:
85
backend/test-model-connection.js
Normal file
85
backend/test-model-connection.js
Normal file
@@ -0,0 +1,85 @@
|
||||
/**
|
||||
* 测试模型连接
|
||||
* @file test-model-connection.js
|
||||
* @description 测试IotXqClient模型是否从正确的数据库读取数据
|
||||
*/
|
||||
|
||||
const { IotXqClient } = require('./models');
|
||||
|
||||
async function testModelConnection() {
|
||||
console.log('🔍 测试IotXqClient模型连接...\n');
|
||||
|
||||
try {
|
||||
// 1. 测试数据库连接
|
||||
console.log('1. 测试数据库连接...');
|
||||
await IotXqClient.sequelize.authenticate();
|
||||
console.log('✅ 数据库连接成功');
|
||||
|
||||
// 2. 检查数据库配置
|
||||
console.log('\n2. 检查数据库配置...');
|
||||
const config = IotXqClient.sequelize.config;
|
||||
console.log('数据库配置:');
|
||||
console.log('主机:', config.host);
|
||||
console.log('端口:', config.port);
|
||||
console.log('数据库名:', config.database);
|
||||
console.log('用户名:', config.username);
|
||||
|
||||
// 3. 查询项圈22012000107的数据
|
||||
console.log('\n3. 查询项圈22012000107的数据...');
|
||||
const devices = await IotXqClient.findAll({
|
||||
where: {
|
||||
sn: '22012000107'
|
||||
},
|
||||
order: [['uptime', 'DESC']]
|
||||
});
|
||||
|
||||
console.log(`找到 ${devices.length} 条记录`);
|
||||
|
||||
devices.forEach((device, index) => {
|
||||
console.log(`\n记录${index + 1}:`);
|
||||
console.log('ID:', device.id);
|
||||
console.log('SN:', device.sn);
|
||||
console.log('设备ID:', device.deviceId);
|
||||
console.log('电量:', device.battery, '(类型:', typeof device.battery, ')');
|
||||
console.log('温度:', device.temperature, '(类型:', typeof device.temperature, ')');
|
||||
console.log('状态:', device.state);
|
||||
console.log('更新时间:', device.uptime);
|
||||
});
|
||||
|
||||
// 4. 查询所有项圈的最新数据
|
||||
console.log('\n4. 查询所有项圈的最新数据...');
|
||||
const allDevices = await IotXqClient.findAll({
|
||||
order: [['uptime', 'DESC']],
|
||||
limit: 10
|
||||
});
|
||||
|
||||
console.log('所有项圈的最新数据:');
|
||||
allDevices.forEach((device, index) => {
|
||||
console.log(`${index + 1}. SN: ${device.sn}, 电量: ${device.battery}, 温度: ${device.temperature}, 状态: ${device.state}`);
|
||||
});
|
||||
|
||||
// 5. 检查是否有电量为99的记录
|
||||
console.log('\n5. 检查是否有电量为99的记录...');
|
||||
const battery99Devices = await IotXqClient.findAll({
|
||||
where: {
|
||||
battery: '99'
|
||||
},
|
||||
order: [['uptime', 'DESC']],
|
||||
limit: 5
|
||||
});
|
||||
|
||||
console.log(`找到 ${battery99Devices.length} 条电量为99的记录`);
|
||||
battery99Devices.forEach((device, index) => {
|
||||
console.log(`${index + 1}. SN: ${device.sn}, 电量: ${device.battery}, 温度: ${device.temperature}, 状态: ${device.state}`);
|
||||
});
|
||||
|
||||
} catch (error) {
|
||||
console.error('❌ 测试失败:', error.message);
|
||||
console.error('错误详情:', error);
|
||||
} finally {
|
||||
process.exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
// 运行测试
|
||||
testModelConnection().catch(console.error);
|
||||
Reference in New Issue
Block a user