-- 检查和修复排班数据问题

-- 1. 检查医生1在2026-03-06的所有排班记录
SELECT 
    id,
    doctor_id,
    date,
    period,
    status,
    quota,
    CASE 
        WHEN status = 1 THEN '出诊'
        WHEN status = 2 THEN '停诊'
        WHEN status = 3 THEN '休息'
        WHEN status = 4 THEN '请假'
        ELSE '未知'
    END as status_desc
FROM zyt_doctor_roster
WHERE doctor_id = 1 AND date = '2026-03-06'
ORDER BY period;

-- 2. 如果发现有下午的记录且status=1，需要确认是否应该删除或修改
-- 示例：如果下午不应该有排班，删除下午的记录
-- DELETE FROM zyt_doctor_roster 
-- WHERE doctor_id = 1 AND date = '2026-03-06' AND period IN ('afternoon', '下午', '2');

-- 3. 检查所有医生在2026-03-04到2026-03-08期间的排班
SELECT 
    doctor_id,
    date,
    period,
    status,
    quota,
    COUNT(*) as record_count
FROM zyt_doctor_roster
WHERE date BETWEEN '2026-03-04' AND '2026-03-08'
GROUP BY doctor_id, date, period, status, quota
HAVING COUNT(*) > 1;  -- 查找重复记录

-- 4. 检查是否有period字段值异常的记录
SELECT 
    id,
    doctor_id,
    date,
    period,
    status
FROM zyt_doctor_roster
WHERE period NOT IN ('morning', 'afternoon', '上午', '下午', '1', '2', 1, 2)
LIMIT 20;
