Files
huachuang/sql/mysql/wms_b22411_inventory_delete.sql

83 lines
3.0 KiB
SQL
Raw 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.

-- 删除 ZJDB26091412537 / B22411-1002L ~ B22411-1005L 的关联库存数据
-- 用途:清除旧推送数据,以便 ERP 重新推送。
-- 删除顺序:释放货位 -> 分配明细 -> 入库明细 -> 入库主单 -> 组盘 -> LMS 包装关系。
START TRANSACTION;
-- 1. 仅当货位仍由对应箱号占用时释放货位。
UPDATE `wms_structattr`
SET `storagevehicle_code` = NULL,
`storagevehicle_qty` = 0,
`inventory_type` = '0',
`lock_type` = '1',
`inv_type` = NULL,
`inv_id` = NULL,
`inv_code` = NULL,
`task_code` = NULL,
`updater` = 'codex',
`update_time` = NOW()
WHERE (`struct_id` = '100203' AND `storagevehicle_code` = 'B22411-1002L')
OR (`struct_id` = '140201' AND `storagevehicle_code` = 'B22411-1003L')
OR (`struct_id` = '140202' AND `storagevehicle_code` = 'B22411-1004L')
OR (`struct_id` = '140203' AND `storagevehicle_code` = 'B22411-1005L');
-- 2. 删除 WMS 入库分配记录。
DELETE FROM `wms_iostorinvdis`
WHERE `iostorinv_id` = '2103058507293097985'
AND `storagevehicle_code` IN
('B22411-1002L', 'B22411-1003L', 'B22411-1004L', 'B22411-1005L');
-- 3. 删除 WMS 入库明细。
DELETE FROM `wms_iostorinvdtl`
WHERE `iostorinv_id` = 2103058507293097985
AND `source_bill_code` = 'ZJDB26091412537';
-- 4. 删除 WMS 入库主单。
DELETE FROM `wms_iostorinv`
WHERE `iostorinv_id` = 2103058507293097985
AND `source_name` = 'ZJDB26091412537';
-- 5. 删除 WMS 组盘记录。
DELETE FROM `wms_group_plate`
WHERE `group_id` IN
(2103058506940776449, 2103058506944970753,
2103058506953359361, 2103058506961747970)
AND `ext_code` = 'ZJDB26091412537'
AND `vehicle_code` IN
('B22411-1002L', 'B22411-1003L', 'B22411-1004L', 'B22411-1005L');
-- 6. 删除 LMS 包装关系;这部分是“单据内容冲突”校验的数据来源。
DELETE FROM `lms_sub_package_relation`
WHERE `id` IN
(2103058335427297282, 2103058335473434625,
2103058335494406145, 2103058335519571969)
AND `sub_type` = '标准直接调拨单'
AND `ext_code` = 'ZJDB26091412537'
AND `package_box_sn` IN
('B22411-1002L', 'B22411-1003L', 'B22411-1004L', 'B22411-1005L');
COMMIT;
-- 执行后校验:下面五项数量均应为 0,四个货位应为空。
SELECT 'REL' AS `data_type`, COUNT(*) AS `remaining_count`
FROM `lms_sub_package_relation`
WHERE `sub_type` = '标准直接调拨单' AND `ext_code` = 'ZJDB26091412537'
UNION ALL
SELECT 'GROUP', COUNT(*) FROM `wms_group_plate`
WHERE `ext_code` = 'ZJDB26091412537'
UNION ALL
SELECT 'HEAD', COUNT(*) FROM `wms_iostorinv`
WHERE `source_name` = 'ZJDB26091412537'
UNION ALL
SELECT 'DTL', COUNT(*) FROM `wms_iostorinvdtl`
WHERE `source_bill_code` = 'ZJDB26091412537'
UNION ALL
SELECT 'DIS', COUNT(*) FROM `wms_iostorinvdis`
WHERE `storagevehicle_code` IN
('B22411-1002L', 'B22411-1003L', 'B22411-1004L', 'B22411-1005L');
SELECT `struct_id`, `storagevehicle_code`, `storagevehicle_qty`, `inventory_type`, `lock_type`
FROM `wms_structattr`
WHERE `struct_id` IN ('100203', '140201', '140202', '140203')
ORDER BY `struct_id`;