-- 清除生产环境:全部订单履约数据 + 财务相关数据 -- 保留:客户/供应商/商品/账号/权限/分公司/系统配置/报价单等主数据 -- 可重复执行 BEGIN; -- ========== 分拣 ========== DELETE FROM picking_scan_logs; DELETE FROM picking_containers; DELETE FROM picking_items; DELETE FROM picking_tasks; -- ========== 配送任务(保留配送员主数据) ========== DELETE FROM delivery_signatures; DELETE FROM sign_records; DELETE FROM delivery_tasks; DELETE FROM delivery_location_history; -- ========== 验收 / 加工 ========== DELETE FROM inspection_review_logs; DELETE FROM inspection_returns; DELETE FROM inspection_loss_confirmations; DELETE FROM processing_tasks; DELETE FROM processing_logs; DELETE FROM inspections; -- ========== 采购 / 备货 / 分配 ========== DELETE FROM purchase_orders; DELETE FROM supplier_preparations; DELETE FROM allocation_tasks; DELETE FROM order_allocation_batches; DELETE FROM product_substitutions; -- ========== 库存流水(订单入库产生) ========== DELETE FROM inventory_logs; DELETE FROM inventory; -- ========== 售后 / 异常 ========== DELETE FROM after_sales; DELETE FROM exception_tickets; -- ========== 订单 ========== DELETE FROM order_items; DELETE FROM orders; -- ========== 财务 ========== DELETE FROM statement_disputes; DELETE FROM statement_lines; DELETE FROM customer_statements; DELETE FROM supplier_statements; DELETE FROM invoices; DELETE FROM cost_details; DELETE FROM cost_adjustments; DELETE FROM fixed_costs; -- ========== 业务通知(与订单/财务相关的站内信) ========== DELETE FROM notifications WHERE notify_type IN ( 'inspection_rejected', 'order', 'purchase', 'delivery', 'finance', 'statement', 'invoice', 'cost', 'exception', 'after_sales' ) OR related_order_code IS NOT NULL; COMMIT; -- 校验 SELECT 'orders' AS tbl, COUNT(*)::int AS cnt FROM orders UNION ALL SELECT 'order_items', COUNT(*)::int FROM order_items UNION ALL SELECT 'purchase_orders', COUNT(*)::int FROM purchase_orders UNION ALL SELECT 'supplier_preparations', COUNT(*)::int FROM supplier_preparations UNION ALL SELECT 'inspections', COUNT(*)::int FROM inspections UNION ALL SELECT 'picking_tasks', COUNT(*)::int FROM picking_tasks UNION ALL SELECT 'delivery_tasks', COUNT(*)::int FROM delivery_tasks UNION ALL SELECT 'inventory', COUNT(*)::int FROM inventory UNION ALL SELECT 'customer_statements', COUNT(*)::int FROM customer_statements UNION ALL SELECT 'supplier_statements', COUNT(*)::int FROM supplier_statements UNION ALL SELECT 'invoices', COUNT(*)::int FROM invoices UNION ALL SELECT 'cost_details', COUNT(*)::int FROM cost_details ORDER BY 1;