Files
wq-wms-java/sql/pm_plating_split_upgrade.sql

22 lines
1.1 KiB
SQL
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

CREATE TABLE pm_plating_allocation (
id varchar(64) NOT NULL PRIMARY KEY,
demand_id varchar(64) NOT NULL,
item_id varchar(64) NOT NULL,
pallet_code varchar(100) NOT NULL,
outbound_id varchar(64) NOT NULL,
warehouse_code varchar(100) NOT NULL,
qty decimal(20,8) NOT NULL,
delivered tinyint NOT NULL DEFAULT 0,
KEY idx_pallet (pallet_code, delivered),
KEY idx_bill (outbound_id),
KEY idx_demand (demand_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='每次配盘托盘需求分配台账';
-- 升级前暂停配盘/配送任务;旧版每条需求物料仅对应一次分配,沿用明细ID以兼容已有组盘关联。
INSERT INTO pm_plating_allocation (id,demand_id,item_id,pallet_code,outbound_id,warehouse_code,qty,delivered)
SELECT i.id,d.id,i.id,d.pallet_code,d.outbound_id,d.source_warehouse,i.allocated_qty,
CASE WHEN i.outbound_qty >= i.allocated_qty THEN 1 ELSE 0 END
FROM pm_plating_demand d JOIN pm_plating_demand_item i ON i.demand_id=d.id
WHERE d.outbound_id IS NOT NULL AND d.source_warehouse IS NOT NULL
AND d.pallet_code IS NOT NULL AND i.allocated_qty > 0;