-- ====================================
-- 深入分析latitude数据截断问题
-- ====================================

-- 1. 检查所有项圈设备的latitude和longitude数据
SELECT 
    device_id,
    latitude,
    longitude,
    LENGTH(latitude) as lat_length,
    LENGTH(longitude) as lng_length,
    voltage,
    temperature,
    steps,
    same_day_steps,
    update_time
FROM iot_device_data 
WHERE device_type = 4
ORDER BY update_time DESC;

-- 2. 检查是否有latitude或longitude包含特殊字符
SELECT 
    device_id,
    latitude,
    longitude,
    ASCII(latitude) as lat_ascii,
    ASCII(longitude) as lng_ascii
FROM iot_device_data 
WHERE device_type = 4
AND (latitude LIKE '%[^0-9.-]%' OR longitude LIKE '%[^0-9.-]%');

-- 3. 检查xq_client_log表的字段长度限制
SELECT 
    COLUMN_NAME,
    DATA_TYPE,
    CHARACTER_MAXIMUM_LENGTH,
    COLUMN_TYPE
FROM INFORMATION_SCHEMA.COLUMNS 
WHERE TABLE_SCHEMA = DATABASE() 
AND TABLE_NAME = 'xq_client_log'
AND COLUMN_NAME IN ('latitude', 'longitude', 'device_voltage', 'device_temp');

-- 4. 尝试手动插入一条简单的数据测试
INSERT INTO xq_client_log (
    device_id, 
    device_voltage, 
    device_temp, 
    server_device_id,
    latitude, 
    longitude, 
    walk_steps, 
    y_walk_steps,
    create_time, 
    create_by, 
    update_time, 
    update_by
) VALUES (
    'TEST_DEVICE_001',
    '3.6',
    '25.5',
    'HOST_001',
    '30.481277875444164',
    '104.123456789012345',
    1000,
    500,
    NOW(),
    'MANUAL_TEST',
    NOW(),
    'MANUAL_TEST'
);

-- 5. 检查插入结果
SELECT * FROM xq_client_log WHERE create_by = 'MANUAL_TEST';

-- 6. 清理测试数据
DELETE FROM xq_client_log WHERE create_by = 'MANUAL_TEST';
