ETest-Vue-FastAPI/remove_sample_order_creatio...

31 lines
992 B
SQL
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

-- 移除样品生成工单时自动创建订单的功能
-- 修改 test_work_order 表,允许 test_order_id 为空
-- 1. 修改 test_work_order.test_order_id 字段为可空
ALTER TABLE test_work_order
MODIFY COLUMN test_order_id INTEGER NULL COMMENT '工单分组(可选)';
-- 2. 查看当前从样品生成的订单(这些订单没有关联工单的 order_id
SELECT
o.id AS order_id,
o.name AS order_name,
o.create_time,
COUNT(w.id) AS work_order_count
FROM test_order o
LEFT JOIN test_work_order w ON w.test_order_id = o.id
WHERE w.order_id IS NULL -- 这些工单没有被汇总到新订单
GROUP BY o.id, o.name, o.create_time
ORDER BY o.id DESC;
-- 3. 可选:清理从样品自动创建的订单(如果需要)
-- 注意:执行前请先备份数据!
-- DELETE FROM test_order
-- WHERE id IN (
-- SELECT DISTINCT test_order_id
-- FROM test_work_order
-- WHERE order_id IS NULL
-- );
-- 4. 验证修改
DESCRIBE test_work_order;