-- 更新attendance_ubi_device表的cfg_id，根据project_id和com_id从attendance_cfg中找到默认配置ID
UPDATE attendance_ubi_device ud
SET cfg_id = (
    SELECT id 
    FROM attendance_cfg 
    WHERE project_id = ud.project_id 
    AND com_id = ud.com_id 
    AND is_default = 1 
    AND enabled = 1 
    LIMIT 1 
)
WHERE ud.cfg_id IS NULL;