菜单更新
This commit is contained in:
@@ -131,8 +131,8 @@ public class MenuController {
|
|||||||
@ApiOperation("修改菜单")
|
@ApiOperation("修改菜单")
|
||||||
@PutMapping
|
@PutMapping
|
||||||
@SaCheckPermission("menu:edit")
|
@SaCheckPermission("menu:edit")
|
||||||
public ResponseEntity<Object> update(@Validated(Menu.Update.class) @RequestBody Menu resources) {
|
public ResponseEntity<Object> update(@Validated(Menu.Update.class) @RequestBody JSONObject form) {
|
||||||
menuService.update(resources);
|
menuService.update(form);
|
||||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ public interface MenuService {
|
|||||||
*
|
*
|
||||||
* @param resources /
|
* @param resources /
|
||||||
*/
|
*/
|
||||||
void update(Menu resources);
|
void update(JSONObject form);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取所有子节点,包含自身ID
|
* 获取所有子节点,包含自身ID
|
||||||
|
|||||||
@@ -7,8 +7,10 @@ import com.alibaba.fastjson.JSONArray;
|
|||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.nl.modules.common.exception.BadRequestException;
|
import org.nl.modules.common.exception.BadRequestException;
|
||||||
|
import org.nl.modules.common.exception.EntityExistException;
|
||||||
import org.nl.modules.common.utils.RedisUtils;
|
import org.nl.modules.common.utils.RedisUtils;
|
||||||
import org.nl.modules.common.utils.SecurityUtils;
|
import org.nl.modules.common.utils.SecurityUtils;
|
||||||
|
import org.nl.modules.common.utils.ValidationUtil;
|
||||||
import org.nl.modules.system.domain.Menu;
|
import org.nl.modules.system.domain.Menu;
|
||||||
import org.nl.modules.system.domain.vo.MenuMetaVo;
|
import org.nl.modules.system.domain.vo.MenuMetaVo;
|
||||||
import org.nl.modules.system.domain.vo.MenuVo;
|
import org.nl.modules.system.domain.vo.MenuVo;
|
||||||
@@ -190,13 +192,42 @@ public class MenuServiceImpl implements MenuService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
menuTab.insert(form);
|
menuTab.insert(form);
|
||||||
updateSubCnt(menu_id);
|
updateSubCnt(form.getString("pid"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void update(Menu resources) {
|
public void update(JSONObject form) {
|
||||||
|
WQLObject menuTab = WQLObject.getWQLObject("sys_menu");
|
||||||
|
|
||||||
|
MenuDto newMenu = this.menuJsonToMenuDto(form);
|
||||||
|
if (newMenu.getMenu_id().equals(newMenu.getPid())) {
|
||||||
|
throw new BadRequestException("上级不能为自己");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (newMenu.getI_frame()) {
|
||||||
|
String http = "http://", https = "https://";
|
||||||
|
if (!(newMenu.getPath().toLowerCase().startsWith(http) || newMenu.getPath().toLowerCase().startsWith(https))) {
|
||||||
|
throw new BadRequestException("外链必须以http://或者https://开头");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//根节点数据库存为null
|
||||||
|
if ("0".equals(form.getString("pid"))) {
|
||||||
|
form.remove("pid");
|
||||||
|
}
|
||||||
|
|
||||||
|
JSONObject oldMenuJson = menuTab.query("menu_id = '" + form.getString("menu_id") + "'").uniqueResult(0);
|
||||||
|
MenuDto oldMenu = this.menuJsonToMenuDto(oldMenuJson);
|
||||||
|
// 记录的父节点ID
|
||||||
|
String oldPid = oldMenu.getPid();
|
||||||
|
String newPid = newMenu.getPid();
|
||||||
|
menuTab.update(form);
|
||||||
|
|
||||||
|
// 计算父级菜单节点数目
|
||||||
|
updateSubCnt(oldPid);
|
||||||
|
updateSubCnt(newPid);
|
||||||
|
// 清理缓存
|
||||||
|
// delCaches(resources.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -302,9 +333,9 @@ public class MenuServiceImpl implements MenuService {
|
|||||||
menuVo.setHidden(menuDTO.getHidden());
|
menuVo.setHidden(menuDTO.getHidden());
|
||||||
// 如果不是外链
|
// 如果不是外链
|
||||||
if (!menuDTO.getI_frame()) {
|
if (!menuDTO.getI_frame()) {
|
||||||
if (StrUtil.isEmpty(menuDTO.getPid()) ) {
|
if (StrUtil.isEmpty(menuDTO.getPid())) {
|
||||||
menuVo.setComponent(StrUtil.isEmpty(menuDTO.getComponent()) ? "Layout" : menuDTO.getComponent());
|
menuVo.setComponent(StrUtil.isEmpty(menuDTO.getComponent()) ? "Layout" : menuDTO.getComponent());
|
||||||
} else if (!StrUtil.isEmpty(menuDTO.getPid()) && menuDTO.getType() == 0) {
|
} else if (!StrUtil.isEmpty(menuDTO.getPid()) && menuDTO.getType() == 0) {
|
||||||
menuVo.setComponent(StrUtil.isEmpty(menuDTO.getComponent()) ? "ParentView" : menuDTO.getComponent());
|
menuVo.setComponent(StrUtil.isEmpty(menuDTO.getComponent()) ? "ParentView" : menuDTO.getComponent());
|
||||||
|
|
||||||
} else if (!StrUtil.isEmpty(menuDTO.getComponent())) {
|
} else if (!StrUtil.isEmpty(menuDTO.getComponent())) {
|
||||||
@@ -342,13 +373,13 @@ public class MenuServiceImpl implements MenuService {
|
|||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateSubCnt(String menuId) {
|
private void updateSubCnt(String pid) {
|
||||||
if (menuId != null) {
|
if (pid != null) {
|
||||||
WQLObject menuTab = WQLObject.getWQLObject("sys_menu");
|
WQLObject menuTab = WQLObject.getWQLObject("sys_menu");
|
||||||
JSONArray arr = menuTab.query("pid = '" + menuId + "'").getResultJSONArray(0);
|
JSONArray arr = menuTab.query("pid = '" + pid + "'").getResultJSONArray(0);
|
||||||
JSONObject param = new JSONObject();
|
JSONObject param = new JSONObject();
|
||||||
param.put("sub_count", arr.size());
|
param.put("sub_count", arr.size());
|
||||||
menuTab.update(param, "menu_id = '" + menuId + "'");
|
menuTab.update(param, "menu_id = '" + pid + "'");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user