-- 检查课件路径与实际文件是否一致
-- 用于部署前验证

-- 1. 查看数据库中的课件记录
SELECT 
    id AS 课件ID,
    courseware_name AS 课件名称,
    type AS 类型,
    file_path AS 数据库路径,
    duration AS 时长秒,
    CASE 
        WHEN duration IS NULL OR duration = 0 THEN '⚠️ 时长缺失'
        ELSE '✓ 有时长'
    END AS 时长状态,
    CONCAT('期望文件位置: D:/ruoyi/uploadPath', REPLACE(file_path, '/profile', '')) AS 服务器文件路径,
    CONCAT('访问URL: http://服务器IP:30091', file_path) AS 访问地址
FROM study_courseware
WHERE course_id = 1  -- 修改为你的课程ID
ORDER BY courseware_order;

-- 2. 检查路径格式是否正确
SELECT 
    id,
    courseware_name,
    file_path,
    CASE 
        WHEN file_path LIKE '/profile/upload/%' THEN '✓ 路径格式正确'
        WHEN file_path LIKE 'profile/upload/%' THEN '⚠️ 缺少前导斜杠'
        WHEN file_path LIKE 'http://%' THEN '❌ 不应包含完整URL'
        ELSE '❌ 路径格式错误'
    END AS 路径检查
FROM study_courseware
WHERE course_id = 1;

-- 3. 统计课件状态
SELECT 
    type AS 类型,
    COUNT(*) AS 数量,
    SUM(CASE WHEN duration IS NULL OR duration = 0 THEN 1 ELSE 0 END) AS 时长缺失数量,
    ROUND(AVG(CASE WHEN duration > 0 THEN duration ELSE NULL END), 2) AS 平均时长秒
FROM study_courseware
WHERE course_id = 1
GROUP BY type;

-- 4. 部署前修复建议
-- 为duration=0的视频设置默认时长（根据实际情况调整）
-- UPDATE study_courseware 
-- SET duration = 60  -- 假设平均1分钟
-- WHERE course_id = 1 
--   AND type = 'video' 
--   AND (duration IS NULL OR duration = 0);

-- 说明：
-- 1. 数据库存储的file_path是相对路径，如：/profile/upload/2025/12/05/xxx.mp4
-- 2. 实际文件应该在：D:/ruoyi/uploadPath/upload/2025/12/05/xxx.mp4
-- 3. 访问URL会动态拼接：http://服务器IP:30091/profile/upload/2025/12/05/xxx.mp4
-- 4. 只要文件存在于正确位置，IP地址改变不影响功能
