-- 重置样品状态为"待测试"
-- 当删除工单后，需要重置样品状态，以便重新生成工单

-- 查看当前样品状态分布
SELECT 
    status,
    CASE 
        WHEN status = '0' THEN '待测试'
        WHEN status = '1' THEN '测试中'
        WHEN status = '2' THEN '已完成'
        ELSE '未知'
    END AS status_name,
    COUNT(*) AS count
FROM warehouse_sample
GROUP BY status;

-- 重置所有样品状态为"待测试"
UPDATE warehouse_sample
SET status = '0',
    update_time = NOW()
WHERE status != '0';

-- 验证更新结果
SELECT 
    status,
    CASE 
        WHEN status = '0' THEN '待测试'
        WHEN status = '1' THEN '测试中'
        WHEN status = '2' THEN '已完成'
        ELSE '未知'
    END AS status_name,
    COUNT(*) AS count
FROM warehouse_sample
GROUP BY status;
