This commit is contained in:
2026-08-10 12:46:12 +08:00
parent fc554273b9
commit 986e97acb6
14 changed files with 198 additions and 13 deletions
@@ -33,6 +33,7 @@ import java.security.MessageDigest;
import java.util.HexFormat;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;
@@ -694,12 +694,35 @@ BEGIN
SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = '主子入仓单关系字段未完整创建';
END IF;
IF (SELECT COUNT(DISTINCT index_name) FROM information_schema.statistics
WHERE table_schema = DATABASE()
AND index_name IN ('uk_inbound_master_order', 'uk_inbound_parent_split_sequence',
'uk_inbound_split_operation', 'uk_inbound_split_idempotency',
'uk_inbound_split_history_operation')) <> 5 THEN
WHERE table_schema = DATABASE() AND table_name = 'fl_inbound_order'
AND index_name IN ('uk_inbound_master_order', 'uk_inbound_parent_split_sequence')) <> 2
OR (SELECT COUNT(DISTINCT index_name) FROM information_schema.statistics
WHERE table_schema = DATABASE() AND table_name = 'fl_inbound_split_batch'
AND index_name IN ('uk_inbound_split_operation', 'uk_inbound_split_idempotency',
'uk_inbound_split_source_once')) <> 3
OR (SELECT COUNT(DISTINCT index_name) FROM information_schema.statistics
WHERE table_schema = DATABASE() AND table_name = 'fl_inbound_split_item'
AND index_name IN ('uk_inbound_split_batch_line',
'uk_inbound_split_batch_source_child')) <> 2
OR (SELECT COUNT(DISTINCT index_name) FROM information_schema.statistics
WHERE table_schema = DATABASE() AND table_name = 'fl_inbound_split_history'
AND index_name = 'uk_inbound_split_history_operation') <> 1 THEN
SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = '主子入仓单唯一约束未完整创建';
END IF;
IF (SELECT COUNT(*) FROM information_schema.columns
WHERE table_schema = DATABASE() AND table_name = 'fl_inbound_split_batch'
AND column_name IN ('source_inbound_id', 'loaded_child_inbound_id',
'remainder_child_inbound_id', 'loaded_package_count',
'remaining_package_count', 'loading_plan_id',
'container_booking_id')) <> 7 THEN
SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = '拆分批次来源、子单、数量或柜次字段未完整创建';
END IF;
IF (SELECT COUNT(*) FROM information_schema.columns
WHERE table_schema = DATABASE() AND table_name = 'fl_inbound_split_item'
AND column_name IN ('source_measurement_id', 'source_measurement_item_id')
AND is_nullable = 'NO') <> 2 THEN
SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = '拆分数量台账必须绑定非空测量来源';
END IF;
IF (SELECT COUNT(*) FROM information_schema.table_constraints
WHERE constraint_schema = DATABASE()
AND constraint_name IN ('fk_inbound_parent_order', 'fk_inbound_root_order',
@@ -725,10 +748,20 @@ BEGIN
SELECT 1 FROM information_schema.statistics
WHERE table_schema = DATABASE()
AND table_name = 'fl_inbound_order'
AND index_name IN ('uk_inbound_tenant_order', 'uk_inbound_one_child')
AND index_name IN ('uk_inbound_tenant_order', 'uk_inbound_one_child',
'uk_inbound_one_secondary', 'uk_inbound_parent_sequence')
) THEN
SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = '旧订单唯一索引仍阻止创建子入仓单';
END IF;
IF EXISTS (
SELECT 1 FROM information_schema.statistics
WHERE table_schema = DATABASE()
AND table_name = 'fl_inbound_split_item'
AND index_name IN ('uk_inbound_split_child', 'uk_inbound_split_batch_child',
'uk_inbound_split_batch_source_item')
) THEN
SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = '旧拆分明细唯一索引仍阻止数量守恒分配';
END IF;
END$$
DELIMITER ;
CALL phase3_assert_inbound_parent_child_schema();