This commit is contained in:
2026-08-08 14:19:45 +08:00
parent 87c1bfbb71
commit 13a2b90e98
6 changed files with 304 additions and 5 deletions
@@ -6529,6 +6529,130 @@ USE baiyue_firstleg;
CALL assert_phase3_smart_loading_schema();
DROP PROCEDURE IF EXISTS assert_phase3_smart_loading_schema;
-- ============================================================================
-- 三期正式范围:海运订舱与拖车预约 IAM 权限
-- 来源:firstleg/src/main/resources/db/phase3-ocean-booking-schema.sql
-- firstleg/src/main/resources/db/phase3-truck-appointment-schema.sql
-- ============================================================================
USE baiyue_iam;
DROP PROCEDURE IF EXISTS assert_phase3_booking_truck_permission_ids_available;
DELIMITER $$
CREATE PROCEDURE assert_phase3_booking_truck_permission_ids_available()
BEGIN
IF EXISTS (
SELECT 1 FROM iam_permission
WHERE (id BETWEEN 5102140 AND 5102154
AND permission_code <> CASE id
WHEN 5102140 THEN 'platform:firstleg:ocean-booking:list'
WHEN 5102141 THEN 'platform:firstleg:ocean-booking:view'
WHEN 5102142 THEN 'platform:firstleg:ocean-booking:create'
WHEN 5102143 THEN 'platform:firstleg:ocean-booking:edit'
WHEN 5102144 THEN 'platform:firstleg:ocean-booking:submit'
WHEN 5102145 THEN 'platform:firstleg:ocean-booking:confirm'
WHEN 5102146 THEN 'platform:firstleg:ocean-booking:release'
WHEN 5102147 THEN 'platform:firstleg:ocean-booking:cancel'
WHEN 5102148 THEN 'platform:firstleg:ocean-booking:change'
WHEN 5102149 THEN 'platform:firstleg:ocean-booking:allocate'
WHEN 5102150 THEN 'platform:firstleg:truck-appointment:list'
WHEN 5102151 THEN 'platform:firstleg:truck-appointment:view'
WHEN 5102152 THEN 'platform:firstleg:truck-appointment:create'
WHEN 5102153 THEN 'platform:firstleg:truck-appointment:edit'
WHEN 5102154 THEN 'platform:firstleg:truck-appointment:operate'
END)
OR (permission_code IN (
'platform:firstleg:ocean-booking:list', 'platform:firstleg:ocean-booking:view',
'platform:firstleg:ocean-booking:create', 'platform:firstleg:ocean-booking:edit',
'platform:firstleg:ocean-booking:submit', 'platform:firstleg:ocean-booking:confirm',
'platform:firstleg:ocean-booking:release', 'platform:firstleg:ocean-booking:cancel',
'platform:firstleg:ocean-booking:change', 'platform:firstleg:ocean-booking:allocate',
'platform:firstleg:truck-appointment:list', 'platform:firstleg:truck-appointment:view',
'platform:firstleg:truck-appointment:create', 'platform:firstleg:truck-appointment:edit',
'platform:firstleg:truck-appointment:operate')
AND (tenant_id <> 0 OR app_code <> 'PLATFORM' OR id NOT BETWEEN 5102140 AND 5102154))
) THEN
SIGNAL SQLSTATE '45000'
SET MESSAGE_TEXT = '三期订舱/拖车权限迁移失败:5102140-5102154 ID 或权限码被其他语义占用';
END IF;
END$$
DELIMITER ;
CALL assert_phase3_booking_truck_permission_ids_available();
DROP PROCEDURE IF EXISTS assert_phase3_booking_truck_permission_ids_available;
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
(5102140,0,'PLATFORM','MENU',5102000,'platform:firstleg:ocean-booking:list','订舱管理','/first-leg/ocean-bookings','GET',80,'ACTIVE',1,0),
(5102141,0,'PLATFORM','BUTTON',5102140,'platform:firstleg:ocean-booking:view','查看订舱',NULL,'GET',10,'ACTIVE',1,0),
(5102142,0,'PLATFORM','BUTTON',5102140,'platform:firstleg:ocean-booking:create','创建订舱',NULL,'POST',20,'ACTIVE',1,0),
(5102143,0,'PLATFORM','BUTTON',5102140,'platform:firstleg:ocean-booking:edit','编辑订舱',NULL,'PUT',30,'ACTIVE',1,0),
(5102144,0,'PLATFORM','BUTTON',5102140,'platform:firstleg:ocean-booking:submit','提交订舱',NULL,'POST',40,'ACTIVE',1,0),
(5102145,0,'PLATFORM','BUTTON',5102140,'platform:firstleg:ocean-booking:confirm','确认订舱',NULL,'POST',50,'ACTIVE',1,0),
(5102146,0,'PLATFORM','BUTTON',5102140,'platform:firstleg:ocean-booking:release','确认放舱',NULL,'POST',60,'ACTIVE',1,0),
(5102147,0,'PLATFORM','BUTTON',5102140,'platform:firstleg:ocean-booking:cancel','取消订舱',NULL,'POST',70,'ACTIVE',1,0),
(5102148,0,'PLATFORM','BUTTON',5102140,'platform:firstleg:ocean-booking:change','变更船期',NULL,'POST',80,'ACTIVE',1,0),
(5102149,0,'PLATFORM','BUTTON',5102140,'platform:firstleg:ocean-booking:allocate','分配柜次',NULL,'POST',90,'ACTIVE',1,0),
(5102150,0,'PLATFORM','MENU',5102000,'platform:firstleg:truck-appointment:list','拖车预约','/first-leg/truck-appointments','GET',90,'ACTIVE',1,0),
(5102151,0,'PLATFORM','BUTTON',5102150,'platform:firstleg:truck-appointment:view','查看拖车预约',NULL,'GET',10,'ACTIVE',1,0),
(5102152,0,'PLATFORM','BUTTON',5102150,'platform:firstleg:truck-appointment:create','创建拖车预约',NULL,'POST',20,'ACTIVE',1,0),
(5102153,0,'PLATFORM','BUTTON',5102150,'platform:firstleg:truck-appointment:edit','编辑拖车预约',NULL,'PUT',30,'ACTIVE',1,0),
(5102154,0,'PLATFORM','BUTTON',5102150,'platform:firstleg:truck-appointment:operate','操作拖车预约',NULL,'POST',40,'ACTIVE',1,0)
ON DUPLICATE KEY UPDATE tenant_id=0,app_code='PLATFORM',permission_type=VALUES(permission_type),
permission_code=VALUES(permission_code),permission_name=VALUES(permission_name),parent_id=VALUES(parent_id),
route_path=VALUES(route_path),http_method=VALUES(http_method),sort_no=VALUES(sort_no),status='ACTIVE',built_in=1,deleted=0;
INSERT IGNORE INTO iam_role_permission(role_id,permission_id,tenant_id)
SELECT role.id,permission.id,0 FROM iam_role role JOIN iam_permission permission
ON permission.tenant_id=0 AND permission.app_code='PLATFORM'
AND (permission.permission_code LIKE 'platform:firstleg:ocean-booking:%'
OR permission.permission_code LIKE 'platform:firstleg:truck-appointment:%')
WHERE role.tenant_id=0 AND role.role_code IN ('PLATFORM_ADMIN','ORDER_OPERATOR');
DROP PROCEDURE IF EXISTS assert_phase3_booking_truck_permissions;
DELIMITER $$
CREATE PROCEDURE assert_phase3_booking_truck_permissions()
BEGIN
IF (SELECT COUNT(*) FROM iam_permission
WHERE tenant_id=0 AND app_code='PLATFORM' AND status='ACTIVE' AND deleted=0
AND ((id=5102140 AND permission_code='platform:firstleg:ocean-booking:list' AND parent_id=5102000 AND route_path='/first-leg/ocean-bookings' AND http_method='GET')
OR (id=5102141 AND permission_code='platform:firstleg:ocean-booking:view' AND parent_id=5102140 AND http_method='GET')
OR (id=5102142 AND permission_code='platform:firstleg:ocean-booking:create' AND parent_id=5102140 AND http_method='POST')
OR (id=5102143 AND permission_code='platform:firstleg:ocean-booking:edit' AND parent_id=5102140 AND http_method='PUT')
OR (id=5102144 AND permission_code='platform:firstleg:ocean-booking:submit' AND parent_id=5102140 AND http_method='POST')
OR (id=5102145 AND permission_code='platform:firstleg:ocean-booking:confirm' AND parent_id=5102140 AND http_method='POST')
OR (id=5102146 AND permission_code='platform:firstleg:ocean-booking:release' AND parent_id=5102140 AND http_method='POST')
OR (id=5102147 AND permission_code='platform:firstleg:ocean-booking:cancel' AND parent_id=5102140 AND http_method='POST')
OR (id=5102148 AND permission_code='platform:firstleg:ocean-booking:change' AND parent_id=5102140 AND http_method='POST')
OR (id=5102149 AND permission_code='platform:firstleg:ocean-booking:allocate' AND parent_id=5102140 AND http_method='POST')
OR (id=5102150 AND permission_code='platform:firstleg:truck-appointment:list' AND parent_id=5102000 AND route_path='/first-leg/truck-appointments' AND http_method='GET')
OR (id=5102151 AND permission_code='platform:firstleg:truck-appointment:view' AND parent_id=5102150 AND http_method='GET')
OR (id=5102152 AND permission_code='platform:firstleg:truck-appointment:create' AND parent_id=5102150 AND http_method='POST')
OR (id=5102153 AND permission_code='platform:firstleg:truck-appointment:edit' AND parent_id=5102150 AND http_method='PUT')
OR (id=5102154 AND permission_code='platform:firstleg:truck-appointment:operate' AND parent_id=5102150 AND http_method='POST'))) <> 15 THEN
SIGNAL SQLSTATE '45000'
SET MESSAGE_TEXT = '统一迁移失败:三期订舱/拖车 15 项权限映射不完整';
END IF;
IF EXISTS (
SELECT 1 FROM iam_role role
WHERE role.tenant_id=0 AND role.role_code IN ('PLATFORM_ADMIN','ORDER_OPERATOR')
AND EXISTS (
SELECT 1 FROM iam_permission permission
WHERE permission.tenant_id=0 AND permission.app_code='PLATFORM'
AND permission.id BETWEEN 5102140 AND 5102154
AND NOT EXISTS (
SELECT 1 FROM iam_role_permission grant_row
WHERE grant_row.role_id=role.id AND grant_row.permission_id=permission.id
AND grant_row.tenant_id=0))
) THEN
SIGNAL SQLSTATE '45000'
SET MESSAGE_TEXT = '统一迁移失败:三期订舱/拖车角色授权不完整';
END IF;
END$$
DELIMITER ;
CALL assert_phase3_booking_truck_permissions();
DROP PROCEDURE IF EXISTS assert_phase3_booking_truck_permissions;
USE baiyue_firstleg;
-- 兼容已经执行过旧单行配置模型的开发/测试库。仅精确识别旧结构时丢弃旧值并重建;
-- 已是四箱规结构时不做 DDL,避免破坏 Admin 已编辑的数据。
DROP PROCEDURE IF EXISTS unified_upgrade_legacy_customer_dimension_config;