优化
This commit is contained in:
@@ -235,27 +235,84 @@ DELIMITER $$
|
||||
CREATE PROCEDURE migrate_legacy_loading_pick_task()
|
||||
BEGIN
|
||||
DECLARE source_exists INT DEFAULT 0;
|
||||
DECLARE source_total_columns INT DEFAULT 0;
|
||||
DECLARE source_smart_columns INT DEFAULT 0;
|
||||
DECLARE source_inbound_columns INT DEFAULT 0;
|
||||
DECLARE target_exists INT DEFAULT 0;
|
||||
DECLARE target_total_columns INT DEFAULT 0;
|
||||
DECLARE target_inbound_columns INT DEFAULT 0;
|
||||
|
||||
SELECT COUNT(*) INTO source_exists
|
||||
FROM information_schema.tables
|
||||
WHERE table_schema = 'baiyue_firstleg' AND table_name = 'fl_loading_pick_task';
|
||||
IF source_exists = 1 THEN
|
||||
SELECT COUNT(*) INTO source_total_columns
|
||||
FROM information_schema.columns
|
||||
WHERE table_schema = 'baiyue_firstleg' AND table_name = 'fl_loading_pick_task';
|
||||
SELECT COUNT(*) INTO source_smart_columns
|
||||
FROM information_schema.columns
|
||||
WHERE table_schema = 'baiyue_firstleg' AND table_name = 'fl_loading_pick_task'
|
||||
AND column_name IN ('loading_plan_id', 'container_no', 'task_status');
|
||||
WHERE table_schema = 'baiyue_firstleg' AND table_name = 'fl_loading_pick_task' AND (
|
||||
(column_name = 'id' AND LOWER(column_type) = 'bigint unsigned' AND is_nullable = 'NO')
|
||||
OR (column_name = 'loading_plan_id' AND LOWER(column_type) = 'bigint unsigned' AND is_nullable = 'NO')
|
||||
OR (column_name = 'container_no' AND LOWER(column_type) = 'varchar(64)' AND is_nullable = 'NO')
|
||||
OR (column_name = 'task_status' AND LOWER(column_type) = 'varchar(16)' AND is_nullable = 'NO' AND column_default = 'LOADING')
|
||||
OR (column_name = 'started_by' AND LOWER(column_type) = 'bigint unsigned' AND is_nullable = 'NO')
|
||||
OR (column_name = 'started_by_name' AND LOWER(column_type) = 'varchar(64)' AND is_nullable = 'YES')
|
||||
OR (column_name = 'started_at' AND data_type = 'datetime' AND datetime_precision = 3 AND is_nullable = 'NO' AND LOWER(column_default) LIKE 'current_timestamp%')
|
||||
OR (column_name = 'completed_by' AND LOWER(column_type) = 'bigint unsigned' AND is_nullable = 'YES')
|
||||
OR (column_name = 'completed_by_name' AND LOWER(column_type) = 'varchar(64)' AND is_nullable = 'YES')
|
||||
OR (column_name = 'completed_at' AND data_type = 'datetime' AND datetime_precision = 3 AND is_nullable = 'YES')
|
||||
OR (column_name = 'version' AND LOWER(column_type) = 'int unsigned' AND is_nullable = 'NO' AND CAST(column_default AS CHAR) = '0')
|
||||
);
|
||||
SELECT COUNT(*) INTO source_inbound_columns
|
||||
FROM information_schema.columns
|
||||
WHERE table_schema = 'baiyue_firstleg' AND table_name = 'fl_loading_pick_task'
|
||||
AND column_name IN ('tenant_id', 'inbound_id', 'status', 'expected_count', 'picked_count');
|
||||
WHERE table_schema = 'baiyue_firstleg' AND table_name = 'fl_loading_pick_task' AND (
|
||||
(column_name = 'id' AND LOWER(column_type) = 'bigint unsigned' AND is_nullable = 'NO')
|
||||
OR (column_name = 'tenant_id' AND LOWER(column_type) = 'bigint unsigned' AND is_nullable = 'NO')
|
||||
OR (column_name = 'inbound_id' AND LOWER(column_type) = 'bigint unsigned' AND is_nullable = 'NO')
|
||||
OR (column_name = 'status' AND LOWER(column_type) = 'varchar(24)' AND is_nullable = 'NO' AND column_default = 'PENDING')
|
||||
OR (column_name = 'version' AND LOWER(column_type) = 'int' AND is_nullable = 'NO' AND CAST(column_default AS CHAR) = '0')
|
||||
OR (column_name = 'expected_count' AND LOWER(column_type) = 'int unsigned' AND is_nullable = 'YES')
|
||||
OR (column_name = 'picked_count' AND LOWER(column_type) = 'int unsigned' AND is_nullable = 'YES')
|
||||
OR (column_name = 'remark' AND LOWER(column_type) = 'varchar(1000)' AND is_nullable = 'YES')
|
||||
OR (column_name = 'updated_by' AND LOWER(column_type) = 'bigint unsigned' AND is_nullable = 'NO')
|
||||
OR (column_name = 'updated_by_name' AND LOWER(column_type) = 'varchar(64)' AND is_nullable = 'YES')
|
||||
OR (column_name = 'created_at' AND data_type = 'datetime' AND datetime_precision = 3 AND is_nullable = 'NO' AND LOWER(column_default) LIKE 'current_timestamp%')
|
||||
OR (column_name = 'updated_at' AND data_type = 'datetime' AND datetime_precision = 3 AND is_nullable = 'NO' AND LOWER(column_default) LIKE 'current_timestamp%' AND LOWER(extra) LIKE '%on update current_timestamp%')
|
||||
);
|
||||
|
||||
IF source_smart_columns = 3 AND source_inbound_columns = 0 THEN
|
||||
IF source_total_columns = 11 AND source_smart_columns = 11 AND source_inbound_columns < 12
|
||||
AND (SELECT COUNT(*) FROM information_schema.statistics
|
||||
WHERE table_schema = 'baiyue_firstleg' AND table_name = 'fl_loading_pick_task'
|
||||
AND index_name = 'uk_loading_pick_task_plan' AND non_unique = 0
|
||||
AND seq_in_index = 1 AND column_name = 'loading_plan_id') = 1
|
||||
AND (SELECT COUNT(*) FROM information_schema.statistics
|
||||
WHERE table_schema = 'baiyue_firstleg' AND table_name = 'fl_loading_pick_task'
|
||||
AND index_name = 'idx_loading_pick_container'
|
||||
AND ((seq_in_index = 1 AND column_name = 'container_no')
|
||||
OR (seq_in_index = 2 AND column_name = 'task_status')
|
||||
OR (seq_in_index = 3 AND column_name = 'started_at'))) = 3
|
||||
AND (SELECT COUNT(*) FROM information_schema.key_column_usage
|
||||
WHERE constraint_schema = 'baiyue_firstleg' AND table_name = 'fl_loading_pick_task'
|
||||
AND column_name = 'loading_plan_id' AND referenced_table_name = 'fl_loading_plan'
|
||||
AND referenced_column_name = 'id') = 1 THEN
|
||||
SET source_exists = 1;
|
||||
ELSEIF source_smart_columns = 0 AND source_inbound_columns = 5 THEN
|
||||
ELSEIF source_total_columns = 12 AND source_inbound_columns = 12 AND source_smart_columns < 11
|
||||
AND (SELECT COUNT(*) FROM information_schema.statistics
|
||||
WHERE table_schema = 'baiyue_firstleg' AND table_name = 'fl_loading_pick_task'
|
||||
AND index_name = 'uk_loading_pick_tenant_inbound' AND non_unique = 0
|
||||
AND ((seq_in_index = 1 AND column_name = 'tenant_id')
|
||||
OR (seq_in_index = 2 AND column_name = 'inbound_id'))) = 2
|
||||
AND (SELECT COUNT(*) FROM information_schema.statistics
|
||||
WHERE table_schema = 'baiyue_firstleg' AND table_name = 'fl_loading_pick_task'
|
||||
AND index_name = 'idx_loading_pick_status'
|
||||
AND ((seq_in_index = 1 AND column_name = 'tenant_id')
|
||||
OR (seq_in_index = 2 AND column_name = 'status')
|
||||
OR (seq_in_index = 3 AND column_name = 'updated_at'))) = 3
|
||||
AND (SELECT COUNT(*) FROM information_schema.key_column_usage
|
||||
WHERE constraint_schema = 'baiyue_firstleg' AND table_name = 'fl_loading_pick_task'
|
||||
AND column_name = 'inbound_id' AND referenced_table_name = 'fl_inbound_order'
|
||||
AND referenced_column_name = 'id') = 1 THEN
|
||||
SELECT COUNT(*) INTO target_exists
|
||||
FROM information_schema.tables
|
||||
WHERE table_schema = 'baiyue_firstleg'
|
||||
@@ -263,14 +320,44 @@ BEGIN
|
||||
IF target_exists = 0 THEN
|
||||
RENAME TABLE fl_loading_pick_task TO fl_inbound_loading_pick_task;
|
||||
ELSE
|
||||
SELECT COUNT(*) INTO target_total_columns
|
||||
FROM information_schema.columns
|
||||
WHERE table_schema = 'baiyue_firstleg' AND table_name = 'fl_inbound_loading_pick_task';
|
||||
SELECT COUNT(*) INTO target_inbound_columns
|
||||
FROM information_schema.columns
|
||||
WHERE table_schema = 'baiyue_firstleg'
|
||||
AND table_name = 'fl_inbound_loading_pick_task'
|
||||
AND column_name IN ('tenant_id', 'inbound_id', 'status', 'expected_count', 'picked_count');
|
||||
IF target_inbound_columns <> 5 THEN
|
||||
AND table_name = 'fl_inbound_loading_pick_task' AND (
|
||||
(column_name = 'id' AND LOWER(column_type) = 'bigint unsigned' AND is_nullable = 'NO')
|
||||
OR (column_name = 'tenant_id' AND LOWER(column_type) = 'bigint unsigned' AND is_nullable = 'NO')
|
||||
OR (column_name = 'inbound_id' AND LOWER(column_type) = 'bigint unsigned' AND is_nullable = 'NO')
|
||||
OR (column_name = 'status' AND LOWER(column_type) = 'varchar(24)' AND is_nullable = 'NO' AND column_default = 'PENDING')
|
||||
OR (column_name = 'version' AND LOWER(column_type) = 'int' AND is_nullable = 'NO' AND CAST(column_default AS CHAR) = '0')
|
||||
OR (column_name = 'expected_count' AND LOWER(column_type) = 'int unsigned' AND is_nullable = 'YES')
|
||||
OR (column_name = 'picked_count' AND LOWER(column_type) = 'int unsigned' AND is_nullable = 'YES')
|
||||
OR (column_name = 'remark' AND LOWER(column_type) = 'varchar(1000)' AND is_nullable = 'YES')
|
||||
OR (column_name = 'updated_by' AND LOWER(column_type) = 'bigint unsigned' AND is_nullable = 'NO')
|
||||
OR (column_name = 'updated_by_name' AND LOWER(column_type) = 'varchar(64)' AND is_nullable = 'YES')
|
||||
OR (column_name = 'created_at' AND data_type = 'datetime' AND datetime_precision = 3 AND is_nullable = 'NO' AND LOWER(column_default) LIKE 'current_timestamp%')
|
||||
OR (column_name = 'updated_at' AND data_type = 'datetime' AND datetime_precision = 3 AND is_nullable = 'NO' AND LOWER(column_default) LIKE 'current_timestamp%' AND LOWER(extra) LIKE '%on update current_timestamp%')
|
||||
);
|
||||
IF target_total_columns <> 12 OR target_inbound_columns <> 12
|
||||
OR (SELECT COUNT(*) FROM information_schema.statistics
|
||||
WHERE table_schema = 'baiyue_firstleg' AND table_name = 'fl_inbound_loading_pick_task'
|
||||
AND index_name = 'uk_loading_pick_tenant_inbound' AND non_unique = 0
|
||||
AND ((seq_in_index = 1 AND column_name = 'tenant_id')
|
||||
OR (seq_in_index = 2 AND column_name = 'inbound_id'))) <> 2
|
||||
OR (SELECT COUNT(*) FROM information_schema.statistics
|
||||
WHERE table_schema = 'baiyue_firstleg' AND table_name = 'fl_inbound_loading_pick_task'
|
||||
AND index_name = 'idx_loading_pick_status'
|
||||
AND ((seq_in_index = 1 AND column_name = 'tenant_id')
|
||||
OR (seq_in_index = 2 AND column_name = 'status')
|
||||
OR (seq_in_index = 3 AND column_name = 'updated_at'))) <> 3
|
||||
OR (SELECT COUNT(*) FROM information_schema.key_column_usage
|
||||
WHERE constraint_schema = 'baiyue_firstleg' AND table_name = 'fl_inbound_loading_pick_task'
|
||||
AND column_name = 'inbound_id' AND referenced_table_name = 'fl_inbound_order'
|
||||
AND referenced_column_name = 'id') <> 1 THEN
|
||||
SIGNAL SQLSTATE '45000'
|
||||
SET MESSAGE_TEXT = '拣货任务迁移失败:fl_inbound_loading_pick_task 不是入库汇总结构';
|
||||
SET MESSAGE_TEXT = '拣货任务迁移失败:fl_inbound_loading_pick_task 不是完整入库汇总结构';
|
||||
END IF;
|
||||
INSERT INTO fl_inbound_loading_pick_task
|
||||
(id, tenant_id, inbound_id, status, version, expected_count, picked_count,
|
||||
@@ -776,6 +863,95 @@ DELIMITER ;
|
||||
|
||||
-- 三期智能装柜、预装清单和装柜清单平台权限;与一期平台根菜单幂等合并。
|
||||
USE baiyue_iam;
|
||||
DROP PROCEDURE IF EXISTS relocate_legacy_inbound_loading_permissions;
|
||||
DELIMITER $$
|
||||
CREATE PROCEDURE relocate_legacy_inbound_loading_permissions()
|
||||
BEGIN
|
||||
DECLARE legacy_count INT DEFAULT 0;
|
||||
SELECT COUNT(*) INTO legacy_count
|
||||
FROM iam_permission
|
||||
WHERE tenant_id = 0 AND app_code = 'PLATFORM'
|
||||
AND permission_code IN (
|
||||
'firstleg:inbound:split', 'firstleg:inbound:preload', 'firstleg:inbound:preload-view',
|
||||
'platform:firstleg:inbound:loading:edit', 'platform:firstleg:inbound:loading:view',
|
||||
'platform:firstleg:inbound:loading:complete', 'platform:firstleg:inbound:delivery:complete',
|
||||
'platform:firstleg:inbound:picking:edit', 'platform:firstleg:inbound:picking:view'
|
||||
);
|
||||
IF legacy_count > 0 THEN
|
||||
IF EXISTS (
|
||||
SELECT 1 FROM iam_permission
|
||||
WHERE id BETWEEN 5102121 AND 5102129
|
||||
AND permission_code <> CASE id
|
||||
WHEN 5102121 THEN 'firstleg:inbound:split'
|
||||
WHEN 5102122 THEN 'firstleg:inbound:preload'
|
||||
WHEN 5102123 THEN 'firstleg:inbound:preload-view'
|
||||
WHEN 5102124 THEN 'platform:firstleg:inbound:loading:edit'
|
||||
WHEN 5102125 THEN 'platform:firstleg:inbound:loading:view'
|
||||
WHEN 5102126 THEN 'platform:firstleg:inbound:loading:complete'
|
||||
WHEN 5102127 THEN 'platform:firstleg:inbound:delivery:complete'
|
||||
WHEN 5102128 THEN 'platform:firstleg:inbound:picking:edit'
|
||||
WHEN 5102129 THEN 'platform:firstleg:inbound:picking:view'
|
||||
END
|
||||
) THEN
|
||||
SIGNAL SQLSTATE '45000'
|
||||
SET MESSAGE_TEXT = '三期权限迁移失败:5102121-5102129 已被其他权限占用';
|
||||
END IF;
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp_phase3_inbound_role_grant;
|
||||
CREATE TEMPORARY TABLE tmp_phase3_inbound_role_grant (
|
||||
role_id BIGINT UNSIGNED NOT NULL,
|
||||
tenant_id BIGINT UNSIGNED NOT NULL,
|
||||
permission_code VARCHAR(128) NOT NULL,
|
||||
PRIMARY KEY (role_id, tenant_id, permission_code)
|
||||
) ENGINE=MEMORY;
|
||||
INSERT IGNORE INTO tmp_phase3_inbound_role_grant (role_id, tenant_id, permission_code)
|
||||
SELECT role_permission.role_id, role_permission.tenant_id, permission.permission_code
|
||||
FROM iam_role_permission role_permission
|
||||
JOIN iam_permission permission ON permission.id = role_permission.permission_id
|
||||
WHERE permission.permission_code IN (
|
||||
'firstleg:inbound:split', 'firstleg:inbound:preload', 'firstleg:inbound:preload-view',
|
||||
'platform:firstleg:inbound:loading:edit', 'platform:firstleg:inbound:loading:view',
|
||||
'platform:firstleg:inbound:loading:complete', 'platform:firstleg:inbound:delivery:complete',
|
||||
'platform:firstleg:inbound:picking:edit', 'platform:firstleg:inbound:picking:view'
|
||||
);
|
||||
DELETE role_permission FROM iam_role_permission role_permission
|
||||
JOIN iam_permission permission ON permission.id = role_permission.permission_id
|
||||
WHERE permission.permission_code IN (
|
||||
'firstleg:inbound:split', 'firstleg:inbound:preload', 'firstleg:inbound:preload-view',
|
||||
'platform:firstleg:inbound:loading:edit', 'platform:firstleg:inbound:loading:view',
|
||||
'platform:firstleg:inbound:loading:complete', 'platform:firstleg:inbound:delivery:complete',
|
||||
'platform:firstleg:inbound:picking:edit', 'platform:firstleg:inbound:picking:view'
|
||||
);
|
||||
DELETE FROM iam_permission WHERE permission_code IN (
|
||||
'firstleg:inbound:split', 'firstleg:inbound:preload', 'firstleg:inbound:preload-view',
|
||||
'platform:firstleg:inbound:loading:edit', 'platform:firstleg:inbound:loading:view',
|
||||
'platform:firstleg:inbound:loading:complete', 'platform:firstleg:inbound:delivery:complete',
|
||||
'platform:firstleg:inbound:picking:edit', 'platform:firstleg:inbound:picking:view'
|
||||
);
|
||||
INSERT INTO iam_permission
|
||||
(id, tenant_id, app_code, permission_type, parent_id, permission_code,
|
||||
permission_name, route_path, http_method, sort_no, status, built_in, deleted)
|
||||
VALUES
|
||||
(5102121, 0, 'PLATFORM', 'BUTTON', 5102030, 'firstleg:inbound:split', '智能分柜', NULL, NULL, 140, 'ACTIVE', 1, 0),
|
||||
(5102122, 0, 'PLATFORM', 'BUTTON', 5102030, 'firstleg:inbound:preload', '编辑并确认预装清单', NULL, NULL, 150, 'ACTIVE', 1, 0),
|
||||
(5102123, 0, 'PLATFORM', 'BUTTON', 5102030, 'firstleg:inbound:preload-view', '查看预装清单', NULL, NULL, 160, 'ACTIVE', 1, 0),
|
||||
(5102124, 0, 'PLATFORM', 'BUTTON', 5102030, 'platform:firstleg:inbound:loading:edit', '维护装柜证据', NULL, NULL, 170, 'ACTIVE', 1, 0),
|
||||
(5102125, 0, 'PLATFORM', 'BUTTON', 5102030, 'platform:firstleg:inbound:loading:view', '查看装柜证据', NULL, NULL, 180, 'ACTIVE', 1, 0),
|
||||
(5102126, 0, 'PLATFORM', 'BUTTON', 5102030, 'platform:firstleg:inbound:loading:complete', '完成装柜', NULL, NULL, 190, 'ACTIVE', 1, 0),
|
||||
(5102127, 0, 'PLATFORM', 'BUTTON', 5102030, 'platform:firstleg:inbound:delivery:complete', '完成派送', NULL, NULL, 200, 'ACTIVE', 1, 0),
|
||||
(5102128, 0, 'PLATFORM', 'BUTTON', 5102030, 'platform:firstleg:inbound:picking:edit', '执行拣货', NULL, NULL, 210, 'ACTIVE', 1, 0),
|
||||
(5102129, 0, 'PLATFORM', 'BUTTON', 5102030, 'platform:firstleg:inbound:picking:view', '查看拣货任务', NULL, NULL, 220, 'ACTIVE', 1, 0);
|
||||
INSERT IGNORE INTO iam_role_permission (role_id, permission_id, tenant_id)
|
||||
SELECT grant_row.role_id, permission.id, grant_row.tenant_id
|
||||
FROM tmp_phase3_inbound_role_grant grant_row
|
||||
JOIN iam_permission permission ON permission.permission_code = grant_row.permission_code
|
||||
AND permission.tenant_id = 0 AND permission.app_code = 'PLATFORM';
|
||||
DROP TEMPORARY TABLE tmp_phase3_inbound_role_grant;
|
||||
END IF;
|
||||
END$$
|
||||
DELIMITER ;
|
||||
CALL relocate_legacy_inbound_loading_permissions();
|
||||
DROP PROCEDURE relocate_legacy_inbound_loading_permissions;
|
||||
|
||||
INSERT INTO iam_permission
|
||||
(id, tenant_id, app_code, permission_type, parent_id, permission_code,
|
||||
permission_name, route_path, http_method, sort_no, status, built_in, deleted)
|
||||
@@ -857,9 +1033,9 @@ BEGIN
|
||||
IF (SELECT COUNT(*) FROM information_schema.check_constraints
|
||||
WHERE constraint_schema = 'baiyue_firstleg'
|
||||
AND constraint_name = 'chk_loading_plan_status'
|
||||
AND check_clause LIKE '%''EDITING''%'
|
||||
AND check_clause LIKE '%''LOADING''%'
|
||||
AND check_clause LIKE '%''COMPLETED''%') <> 1 THEN
|
||||
AND UPPER(check_clause) LIKE '%EDITING%'
|
||||
AND UPPER(check_clause) LIKE '%LOADING%'
|
||||
AND UPPER(check_clause) LIKE '%COMPLETED%') <> 1 THEN
|
||||
SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = '智能装柜迁移失败:装柜状态约束不是最终三状态';
|
||||
END IF;
|
||||
IF (SELECT COUNT(*) FROM information_schema.columns
|
||||
|
||||
Reference in New Issue
Block a user