菜单更新
This commit is contained in:
@@ -131,8 +131,8 @@ public class MenuController {
|
||||
@ApiOperation("修改菜单")
|
||||
@PutMapping
|
||||
@SaCheckPermission("menu:edit")
|
||||
public ResponseEntity<Object> update(@Validated(Menu.Update.class) @RequestBody Menu resources) {
|
||||
menuService.update(resources);
|
||||
public ResponseEntity<Object> update(@Validated(Menu.Update.class) @RequestBody JSONObject form) {
|
||||
menuService.update(form);
|
||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||
}
|
||||
|
||||
|
||||
@@ -85,7 +85,7 @@ public interface MenuService {
|
||||
*
|
||||
* @param resources /
|
||||
*/
|
||||
void update(Menu resources);
|
||||
void update(JSONObject form);
|
||||
|
||||
/**
|
||||
* 获取所有子节点,包含自身ID
|
||||
|
||||
@@ -7,8 +7,10 @@ import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
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.SecurityUtils;
|
||||
import org.nl.modules.common.utils.ValidationUtil;
|
||||
import org.nl.modules.system.domain.Menu;
|
||||
import org.nl.modules.system.domain.vo.MenuMetaVo;
|
||||
import org.nl.modules.system.domain.vo.MenuVo;
|
||||
@@ -190,13 +192,42 @@ public class MenuServiceImpl implements MenuService {
|
||||
}
|
||||
|
||||
menuTab.insert(form);
|
||||
updateSubCnt(menu_id);
|
||||
updateSubCnt(form.getString("pid"));
|
||||
}
|
||||
|
||||
@Override
|
||||
@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
|
||||
@@ -302,9 +333,9 @@ public class MenuServiceImpl implements MenuService {
|
||||
menuVo.setHidden(menuDTO.getHidden());
|
||||
// 如果不是外链
|
||||
if (!menuDTO.getI_frame()) {
|
||||
if (StrUtil.isEmpty(menuDTO.getPid()) ) {
|
||||
if (StrUtil.isEmpty(menuDTO.getPid())) {
|
||||
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());
|
||||
|
||||
} else if (!StrUtil.isEmpty(menuDTO.getComponent())) {
|
||||
@@ -342,13 +373,13 @@ public class MenuServiceImpl implements MenuService {
|
||||
return list;
|
||||
}
|
||||
|
||||
private void updateSubCnt(String menuId) {
|
||||
if (menuId != null) {
|
||||
private void updateSubCnt(String pid) {
|
||||
if (pid != null) {
|
||||
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();
|
||||
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