You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
89 lines
3.0 KiB
89 lines
3.0 KiB
// 检查特定用户的同步状态和jiandaoyun_record_id字段
|
|
const mysql = require('mysql2/promise');
|
|
const config = require('./src/config/config');
|
|
|
|
// 要检查的用户ID
|
|
const targetUserId = 'user_1766039120078_lcmc7kom1';
|
|
|
|
async function checkSpecificUser() {
|
|
console.log(`===== 检查用户 ${targetUserId} 的同步状态 =====`);
|
|
|
|
let connection = null;
|
|
|
|
try {
|
|
// 1. 连接数据库
|
|
console.log('1. 连接数据库...');
|
|
connection = await mysql.createConnection({
|
|
host: config.db.host,
|
|
port: config.db.port,
|
|
user: config.db.user,
|
|
password: config.db.password,
|
|
database: config.db.database
|
|
});
|
|
console.log('数据库连接成功');
|
|
|
|
// 2. 查询该用户的详细信息
|
|
console.log(`\n2. 查询用户 ${targetUserId} 的详细信息...`);
|
|
const checkSql = `
|
|
SELECT userId, phoneNumber, nickName, type, authorized_region, sync_status,
|
|
last_sync_time, dataid, jiandao_record_id
|
|
FROM ${config.tables.users.name}
|
|
WHERE userId = ?
|
|
`;
|
|
const [rows] = await connection.execute(checkSql, [targetUserId]);
|
|
|
|
if (rows.length === 0) {
|
|
console.log(`未找到用户 ${targetUserId}`);
|
|
return;
|
|
}
|
|
|
|
const userInfo = rows[0];
|
|
console.log('用户信息:', JSON.stringify(userInfo, null, 2));
|
|
|
|
// 3. 检查是否有该用户的同步记录
|
|
console.log(`\n3. 检查用户 ${targetUserId} 是否在同步队列中...`);
|
|
const syncSql = `
|
|
SELECT userId, phoneNumber, sync_status, dataid
|
|
FROM ${config.tables.users.name}
|
|
WHERE (sync_status = 0 OR sync_status IS NULL)
|
|
AND (dataid IS NULL OR dataid = '')
|
|
LIMIT 10
|
|
`;
|
|
const [syncRows] = await connection.execute(syncSql);
|
|
|
|
console.log(`当前需要同步的用户数量: ${syncRows.length}`);
|
|
const isInSyncQueue = syncRows.some(user => user.userId === targetUserId);
|
|
console.log(`用户 ${targetUserId} 是否在同步队列中: ${isInSyncQueue}`);
|
|
|
|
if (syncRows.length > 0) {
|
|
console.log('同步队列中的用户ID:', syncRows.map(user => user.userId));
|
|
}
|
|
|
|
// 4. 检查是否有该用户的相关产品数据
|
|
console.log(`\n4. 检查用户 ${targetUserId} 的产品数据...`);
|
|
const productSql = `
|
|
SELECT * FROM ${config.tables.products.name}
|
|
WHERE userId = ?
|
|
LIMIT 5
|
|
`;
|
|
const [productRows] = await connection.execute(productSql, [targetUserId]);
|
|
|
|
console.log(`用户 ${targetUserId} 的产品数量: ${productRows.length}`);
|
|
if (productRows.length > 0) {
|
|
console.log('产品示例:', JSON.stringify(productRows.slice(0, 2), null, 2));
|
|
}
|
|
|
|
} catch (error) {
|
|
console.error('检查过程中发生错误:', error);
|
|
console.error('错误堆栈:', error.stack);
|
|
} finally {
|
|
if (connection) {
|
|
await connection.end();
|
|
console.log('\n数据库连接已关闭');
|
|
}
|
|
console.log('\n===== 检查完成 =====');
|
|
}
|
|
}
|
|
|
|
// 运行检查
|
|
checkSpecificUser();
|