|
|
@@ -36,18 +36,18 @@ public class MenuServiceImpl implements MenuService {
|
|
|
public synchronized Result addMenu(Menu menu) {
|
|
|
int pid = menu.getPid();
|
|
|
int total = menuRepository.countByPid(pid);
|
|
|
- if (total >= 100) {
|
|
|
- return Result.result(ResultStatus.FAIL, "每个 dir 最多可包含 100 个 page");
|
|
|
- }
|
|
|
-
|
|
|
- Result result = moreThanTwoParents(pid);
|
|
|
- if (result.getCode() != ResultStatus.SUCCESS.getCode()) {
|
|
|
- return result;
|
|
|
+ if (total >= 10) {
|
|
|
+ return Result.result(ResultStatus.FAIL, "每个 dir 最多可包含 10 个 page");
|
|
|
}
|
|
|
|
|
|
+ int total1 = getParentCount(pid);
|
|
|
String type = menu.getType();
|
|
|
if (type.equals(MenuType.dir.name())) {
|
|
|
- menu.setUrl("#");
|
|
|
+ if (total1 < 2) {
|
|
|
+ menu.setUrl("#");
|
|
|
+ } else {
|
|
|
+ return Result.result(ResultStatus.FAIL, "当前父目录处于第二层, 只能添加 page menu, root -> level1 -> level2");
|
|
|
+ }
|
|
|
} else {
|
|
|
String url = menu.getUrl();
|
|
|
Result result1 = checkUrl(url);
|
|
|
@@ -79,26 +79,32 @@ public class MenuServiceImpl implements MenuService {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 检查菜单的层级, Menu 最多只能有两个 parent, 即最多只能有三级菜单
|
|
|
+ * 检查菜单的层级, Menu 最多只能有两个 parent, 即最多只能有三层
|
|
|
*
|
|
|
* @param
|
|
|
* @return
|
|
|
* @date 2021-07-15 上午11:15
|
|
|
*/
|
|
|
- private Result moreThanTwoParents(int pid) {
|
|
|
- if (pid != 0) {
|
|
|
- Menu menu1 = menuRepository.getOne(pid);
|
|
|
+ private int getParentCount(int menuId) {
|
|
|
+ int total = 1;
|
|
|
+ if (menuId != 0) {
|
|
|
+ // 2
|
|
|
+ total++;
|
|
|
+ Menu menu1 = menuRepository.getOne(menuId);
|
|
|
int pid1 = menu1.getPid();
|
|
|
if (pid1 != 0) {
|
|
|
+ // 3
|
|
|
+ total++;
|
|
|
Menu menu2 = menuRepository.getOne(pid1);
|
|
|
int pid2 = menu2.getPid();
|
|
|
if (pid2 != 0) {
|
|
|
- return Result.result(ResultStatus.FAIL, "Menu 最多只能有两个 parent,即最多只能有三级菜单");
|
|
|
+ // 4
|
|
|
+ total++;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- return Result.result(ResultStatus.SUCCESS);
|
|
|
+ return total;
|
|
|
}
|
|
|
|
|
|
@Override
|