|
|
|
@ -162,12 +162,11 @@ public class ResourceServiceImpl implements IResourceService { |
|
|
|
|
|
|
|
// ==================== 校验逻辑 ====================
|
|
|
|
|
|
|
|
/** 层级约束:6 种非法父子组合 */ |
|
|
|
/** 层级约束:复用 {@link MenuType#isLegalChild},根节点单独处理 */ |
|
|
|
private void validateHierarchy(ResourceNode node) { |
|
|
|
MenuType childType = node.getType(); |
|
|
|
|
|
|
|
if (node.getParentId() == null || node.getParentId() == 0) { |
|
|
|
// 根节点:只允许 catalog / menu
|
|
|
|
if (childType == MenuType.BUTTON) { |
|
|
|
throw new BusinessErrorException(CODE_RESOURCE_INVALID, "根节点不允许添加 button 类型"); |
|
|
|
} |
|
|
|
@ -180,17 +179,13 @@ public class ResourceServiceImpl implements IResourceService { |
|
|
|
} |
|
|
|
MenuType parentType = MenuType.fromCode(parent.getMenuType()); |
|
|
|
|
|
|
|
// 叶子节点
|
|
|
|
if (parentType == MenuType.BUTTON) { |
|
|
|
throw new BusinessErrorException(CODE_RESOURCE_INVALID, "button 是叶子节点,不可添加子节点"); |
|
|
|
} |
|
|
|
// catalog 只能挂 menu
|
|
|
|
if (parentType == MenuType.CATALOG && childType != MenuType.MENU) { |
|
|
|
throw new BusinessErrorException(CODE_RESOURCE_INVALID, "catalog 节点下只能添加 menu 类型"); |
|
|
|
} |
|
|
|
// menu 只能挂 button
|
|
|
|
if (parentType == MenuType.MENU && childType != MenuType.BUTTON) { |
|
|
|
throw new BusinessErrorException(CODE_RESOURCE_INVALID, "menu 节点下只能添加 button 类型"); |
|
|
|
if (!MenuType.isLegalChild(parentType, childType)) { |
|
|
|
String msg = switch (parentType) { |
|
|
|
case CATALOG -> "catalog 节点下只能添加 menu 类型"; |
|
|
|
case MENU -> "menu 节点下只能添加 button 类型"; |
|
|
|
case BUTTON -> "button 是叶子节点,不可添加子节点"; |
|
|
|
}; |
|
|
|
throw new BusinessErrorException(CODE_RESOURCE_INVALID, msg); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -233,8 +228,8 @@ public class ResourceServiceImpl implements IResourceService { |
|
|
|
entity.setMenuType(node.getType().getCode()); |
|
|
|
} |
|
|
|
|
|
|
|
// route / path:若未传则保留原有值
|
|
|
|
if (node.getRoute() != null) { |
|
|
|
// route / path:非空值覆盖,空串/空白保留原有值
|
|
|
|
if (StrUtil.isNotBlank(node.getRoute())) { |
|
|
|
entity.setPath(node.getRoute()); |
|
|
|
} |
|
|
|
|
|
|
|
|