|
@@ -30,7 +30,9 @@ public class ResourceService {
|
|
|
|
|
|
|
|
public synchronized void addResource(Menu menu) {
|
|
public synchronized void addResource(Menu menu) {
|
|
|
// menu 最多只能有两个 parent,即最多只能有三级菜单
|
|
// menu 最多只能有两个 parent,即最多只能有三级菜单
|
|
|
- checkMenu(menu);
|
|
|
|
|
|
|
+ if (!checkMenu(menu.getPid())) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
// 调整 menu 组内元素的位置
|
|
// 调整 menu 组内元素的位置
|
|
|
adjustPosition(menu);
|
|
adjustPosition(menu);
|
|
|
menu.setIsEnabled(true);
|
|
menu.setIsEnabled(true);
|
|
@@ -48,8 +50,7 @@ public class ResourceService {
|
|
|
* @return
|
|
* @return
|
|
|
* @date 2021-07-15 上午11:15
|
|
* @date 2021-07-15 上午11:15
|
|
|
*/
|
|
*/
|
|
|
- private void checkMenu(Menu menu) {
|
|
|
|
|
- int pid = menu.getPid();
|
|
|
|
|
|
|
+ private boolean checkMenu(int pid) {
|
|
|
if (pid != 0) {
|
|
if (pid != 0) {
|
|
|
Menu menu1 = getResourceById(pid);
|
|
Menu menu1 = getResourceById(pid);
|
|
|
int pid1 = menu1.getPid();
|
|
int pid1 = menu1.getPid();
|
|
@@ -58,10 +59,12 @@ public class ResourceService {
|
|
|
int pid2 = menu2.getPid();
|
|
int pid2 = menu2.getPid();
|
|
|
if (pid2 != 0) {
|
|
if (pid2 != 0) {
|
|
|
log.error("menu 最多只能有两个 parent,即最多只能有三级菜单...");
|
|
log.error("menu 最多只能有两个 parent,即最多只能有三级菜单...");
|
|
|
- return;
|
|
|
|
|
|
|
+ return false;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ return true;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -87,7 +90,7 @@ public class ResourceService {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // menu 的位置
|
|
|
|
|
|
|
+ // menu 的新位置
|
|
|
int pos = menu.getPos()+1;
|
|
int pos = menu.getPos()+1;
|
|
|
int size = menus.size();
|
|
int size = menus.size();
|
|
|
if (pos == 1) {
|
|
if (pos == 1) {
|
|
@@ -144,17 +147,23 @@ public class ResourceService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
int pid = vo.getPid();
|
|
int pid = vo.getPid();
|
|
|
|
|
+ if (!checkMenu(pid)) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
if (pid != menuEntity.getPid()) {
|
|
if (pid != menuEntity.getPid()) {
|
|
|
- // menu 更换到了新的 menu 组
|
|
|
|
|
|
|
+ // TODO menu 更换到了新的 menu 组
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
int oldPos = menuEntity.getPos();
|
|
int oldPos = menuEntity.getPos();
|
|
|
- int pos = vo.getPos();
|
|
|
|
|
|
|
+ // menu 的新位置
|
|
|
|
|
+ int pos = vo.getPos()+1;
|
|
|
if (oldPos != pos) {
|
|
if (oldPos != pos) {
|
|
|
- // menu 在组内的位置发生变化
|
|
|
|
|
|
|
+ // TODO menu 在组内的位置发生变化
|
|
|
List<Menu> menus = menuRepository.findByPid(pid);
|
|
List<Menu> menus = menuRepository.findByPid(pid);
|
|
|
menus.sort(Comparator.comparingInt(Menu::getPos));
|
|
menus.sort(Comparator.comparingInt(Menu::getPos));
|
|
|
|
|
+ System.out.println();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
menuEntity.setName(vo.getName());
|
|
menuEntity.setName(vo.getName());
|