Commit e5507c9d by naan1993

解决添加菜单编号和父编号一致会导致递归的bug

parent ae3c75ae
...@@ -46,6 +46,8 @@ public enum BizExceptionEnum { ...@@ -46,6 +46,8 @@ public enum BizExceptionEnum {
/** /**
* 错误的请求 * 错误的请求
*/ */
MENU_PCODE_COINCIDENCE(400,"菜单编号和副编号不能一致"),
EXISTED_THE_MENU(400,"菜单编号重复,不能添加"),
DICT_MUST_BE_NUMBER(400,"字典的值必须为数字"), DICT_MUST_BE_NUMBER(400,"字典的值必须为数字"),
REQUEST_NULL(400, "请求有错误"), REQUEST_NULL(400, "请求有错误"),
SESSION_TIMEOUT(400, "会话超时"), SESSION_TIMEOUT(400, "会话超时"),
......
...@@ -140,6 +140,13 @@ public class MenuController extends BaseController { ...@@ -140,6 +140,13 @@ public class MenuController extends BaseController {
if (result.hasErrors()) { if (result.hasErrors()) {
throw new BussinessException(BizExceptionEnum.REQUEST_NULL); throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
} }
//判断是否存在该编号
String existedMenuName = ConstantFactory.me().getMenuNameByCode(menu.getCode());
if (ToolUtil.isNotEmpty(existedMenuName)) {
throw new BussinessException(BizExceptionEnum.EXISTED_THE_MENU);
}
//设置父级菜单编号 //设置父级菜单编号
menuSetPcode(menu); menuSetPcode(menu);
...@@ -230,6 +237,12 @@ public class MenuController extends BaseController { ...@@ -230,6 +237,12 @@ public class MenuController extends BaseController {
Menu pMenu = menuMapper.selectById(code); Menu pMenu = menuMapper.selectById(code);
Integer pLevels = pMenu.getLevels(); Integer pLevels = pMenu.getLevels();
menu.setPcode(pMenu.getCode()); menu.setPcode(pMenu.getCode());
//如果编号和父编号一致会导致无限递归
if (menu.getCode().equals(menu.getPcode())) {
throw new BussinessException(BizExceptionEnum.MENU_PCODE_COINCIDENCE);
}
menu.setLevels(pLevels + 1); menu.setLevels(pLevels + 1);
menu.setPcodes(pMenu.getPcodes() + "[" + pMenu.getCode() + "],"); menu.setPcodes(pMenu.getPcodes() + "[" + pMenu.getCode() + "],");
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment