-- ====================================
-- 修复后的手动插入测试
-- ====================================

-- 1. 先检查xq_client_log表的实际字段
SELECT 
    COLUMN_NAME as '字段名',
    DATA_TYPE as '数据类型',
    CHARACTER_MAXIMUM_LENGTH as '字符最大长度'
FROM INFORMATION_SCHEMA.COLUMNS 
WHERE TABLE_SCHEMA = DATABASE() 
AND TABLE_NAME = 'xq_client_log'
ORDER BY ORDINAL_POSITION;

-- 2. 根据实际字段结构插入数据
-- 注意：这里使用实际存在的字段，去掉不存在的字段
INSERT INTO xq_client_log (
    device_id, 
    device_voltage, 
    device_temp, 
    latitude, 
    longitude, 
    walk_steps, 
    y_walk_steps,
    create_time, 
    create_by, 
    update_time, 
    update_by
)
SELECT 
    device_id,
    CAST(voltage AS CHAR) as device_voltage,
    CAST(temperature AS CHAR) as device_temp,
    latitude,
    longitude,
    steps as walk_steps,
    same_day_steps as y_walk_steps,
    NOW() as create_time,
    'MANUAL_TEST' as create_by,
    NOW() as update_time,
    'MANUAL_TEST' as update_by
FROM iot_device_data 
WHERE device_type = 4 
AND latitude != '0' 
AND longitude != '0'
ORDER BY update_time DESC
LIMIT 1;

-- 3. 检查插入结果
SELECT 
    device_id,
    device_voltage,
    device_temp,
    latitude,
    longitude,
    walk_steps,
    y_walk_steps,
    create_by,
    create_time
FROM xq_client_log 
WHERE create_by = 'MANUAL_TEST';

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