完善保险端前后端和养殖端小程序

This commit is contained in:
xuqiuyun
2025-09-22 19:09:45 +08:00
parent 02a25515a9
commit 325c114c38
256 changed files with 48348 additions and 4444 deletions

114
backend/check-all-tables.js Normal file
View File

@@ -0,0 +1,114 @@
/**
* 检查所有相关表
* @file check-all-tables.js
* @description 检查所有可能包含项圈数据的表
*/
const { sequelize } = require('./config/database-simple');
async function checkAllTables() {
console.log('🔍 检查所有相关表...\n');
try {
// 1. 列出所有表
console.log('1. 列出所有表...');
const [tables] = await sequelize.query("SHOW TABLES");
console.log('数据库中的所有表:');
tables.forEach((table, index) => {
const tableName = Object.values(table)[0];
console.log(`${index + 1}. ${tableName}`);
});
// 2. 检查可能包含项圈数据的表
const possibleTables = [
'iot_xq_client',
'iot_collar',
'smart_collar',
'collar_device',
'device_info',
'iot_device'
];
console.log('\n2. 检查可能包含项圈数据的表...');
for (const tableName of possibleTables) {
try {
console.log(`\n检查表: ${tableName}`);
const [rows] = await sequelize.query(`SELECT COUNT(*) as count FROM ${tableName}`);
const count = rows[0].count;
console.log(`记录数: ${count}`);
if (count > 0) {
// 查看表结构
const [columns] = await sequelize.query(`DESCRIBE ${tableName}`);
console.log('表结构:');
columns.forEach(col => {
console.log(` ${col.Field}: ${col.Type}`);
});
// 查找包含22012000107的记录
const [searchResults] = await sequelize.query(`
SELECT * FROM ${tableName}
WHERE sn = '22012000107' OR device_id = '22012000107' OR deviceId = '22012000107'
LIMIT 5
`);
if (searchResults.length > 0) {
console.log(`找到 ${searchResults.length} 条包含22012000107的记录:`);
searchResults.forEach((row, index) => {
console.log(`记录${index + 1}:`, row);
});
} else {
console.log('未找到包含22012000107的记录');
}
}
} catch (error) {
console.log(`${tableName} 不存在或无法访问: ${error.message}`);
}
}
// 3. 检查iot_xq_client表的详细信息
console.log('\n3. 检查iot_xq_client表的详细信息...');
const [xqClientData] = await sequelize.query(`
SELECT * FROM iot_xq_client
WHERE sn = '22012000107'
ORDER BY uptime DESC
`);
console.log(`iot_xq_client表中项圈22012000107的记录:`);
xqClientData.forEach((row, index) => {
console.log(`\n记录${index + 1}:`);
console.log('ID:', row.id);
console.log('SN:', row.sn);
console.log('电量:', row.battery);
console.log('温度:', row.temperature);
console.log('状态:', row.state);
console.log('更新时间:', row.uptime);
console.log('创建时间:', row.created_at);
console.log('更新时间:', row.updated_at);
});
// 4. 检查是否有其他项圈编号
console.log('\n4. 检查所有项圈编号...');
const [allSnData] = await sequelize.query(`
SELECT sn, battery, temperature, state, uptime
FROM iot_xq_client
ORDER BY uptime DESC
LIMIT 20
`);
console.log('所有项圈编号及其电量:');
allSnData.forEach((row, index) => {
console.log(`${index + 1}. SN: ${row.sn}, 电量: ${row.battery}, 温度: ${row.temperature}, 状态: ${row.state}`);
});
} catch (error) {
console.error('❌ 检查失败:', error.message);
console.error('错误详情:', error);
} finally {
process.exit(0);
}
}
// 运行检查
checkAllTables().catch(console.error);