-- 验证工单数据和字段
-- 用于诊断工单页面刷新不出数据的问题

-- 1. 查看最新创建的工单数据
SELECT 
    id AS 工单ID,
    batch_id AS 批次ID,
    batch_name AS 批次名称,
    name AS 工单名称,
    test_eut_id AS 产品ID,
    test_category_id AS 测试类别ID,
    order_id AS 订单ID,
    create_time AS 创建时间
FROM test_work_order
ORDER BY id DESC
LIMIT 10;

-- 2. 检查是否有 order_id 为 NULL 的工单（应该显示在列表中）
SELECT 
    COUNT(*) AS 未汇总工单数量
FROM test_work_order
WHERE order_id IS NULL;

-- 3. 检查 batch_id 和 batch_name 是否有值
SELECT 
    COUNT(*) AS 总工单数,
    COUNT(batch_id) AS 有批次ID的数量,
    COUNT(batch_name) AS 有批次名称的数量,
    COUNT(CASE WHEN order_id IS NULL THEN 1 END) AS 未汇总数量
FROM test_work_order;

-- 4. 查看工单表的字段结构（确认字段名）
DESCRIBE test_work_order;
