菜单更新

This commit is contained in:
ludj
2022-11-30 16:26:44 +08:00
parent 67a4def2cc
commit 3cdefdd4d8
4 changed files with 19 additions and 23 deletions

View File

@@ -18,6 +18,7 @@ package org.nl.modules.system.rest;
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaMode;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api;
@@ -106,13 +107,12 @@ public class MenuController {
@ApiOperation("查询菜单:根据ID获取同级与上级数据")
@PostMapping("/superior")
@SaCheckPermission("menu:list")
public ResponseEntity<Object> getSuperior(@RequestBody List<String> ids) {
public ResponseEntity<Object> getSuperior(@RequestBody JSONObject param) {
Set<MenuDto> menuDtos = new LinkedHashSet<>();
if (CollectionUtil.isNotEmpty(ids)) {
for (String id : ids) {
String id=param.getString("ids");
if (StrUtil.isNotEmpty(id)) {
MenuDto menuDto = menuService.findById(id);
menuDtos.addAll(menuService.getSuperior(menuDto, new ArrayList<>()));
}
return new ResponseEntity<>(menuService.buildTree(new ArrayList<>(menuDtos)), HttpStatus.OK);
}
return new ResponseEntity<>(menuService.getMenus(null), HttpStatus.OK);

View File

@@ -7,10 +7,9 @@ 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.utils.*;
import org.nl.modules.common.utils.RedisUtils;
import org.nl.modules.common.utils.SecurityUtils;
import org.nl.modules.system.domain.Menu;
import org.nl.modules.system.domain.Role;
import org.nl.modules.system.domain.User;
import org.nl.modules.system.domain.vo.MenuMetaVo;
import org.nl.modules.system.domain.vo.MenuVo;
import org.nl.modules.system.repository.UserRepository;
@@ -109,7 +108,6 @@ public class MenuServiceImpl implements MenuService {
@Override
public MenuDto menuJsonToMenuDto(JSONObject json) {
MenuDto menuDto = new MenuDto();
menuDto.setName(json.getString("title"));
menuDto.setMenu_id(json.getString("menu_id"));
menuDto.setType(json.getInteger("type"));
menuDto.setPermission(json.getString("permission"));
@@ -117,12 +115,7 @@ public class MenuServiceImpl implements MenuService {
menuDto.setMenu_sort(json.getInteger("menu_sort"));
menuDto.setPath(json.getString("path"));
menuDto.setComponent(json.getString("component"));
if (StrUtil.isNotEmpty(json.getString("pid"))) {
menuDto.setPid(json.getString("pid"));
} else {
menuDto.setPid(null);
}
menuDto.setPid(json.getString("pid"));
menuDto.setSub_count(json.getInteger("sub_count"));
menuDto.setI_frame("1".equals(json.getString("i_frame")));
@@ -237,7 +230,7 @@ public class MenuServiceImpl implements MenuService {
// 菜单表【sys_menu】
WQLObject menuTab = WQLObject.getWQLObject("sys_menu");
JSONArray menus;
if (pid != null && !pid.equals(0L)) {
if (pid != null && !pid.equals("0")) {
menus = menuTab.query("menu_id = '" + pid + "'").getResultJSONArray(0);
} else {
menus = menuTab.query("(pid =0 or pid is null)").getResultJSONArray(0);
@@ -255,7 +248,7 @@ public class MenuServiceImpl implements MenuService {
@Override
public List<MenuDto> getSuperior(MenuDto menuDto, List<MenuDto> menus) {
WQLObject menuTab = WQLObject.getWQLObject("sys_menu");
if (menuDto.getPid() == null) {
if (StrUtil.isEmpty(menuDto.getPid())) {
JSONArray arr = menuTab.query("pid is null").getResultJSONArray(0);
for (int i = 0; i < arr.size(); i++) {
JSONObject json = arr.getJSONObject(i);
@@ -277,7 +270,7 @@ public class MenuServiceImpl implements MenuService {
List<MenuDto> trees = new ArrayList<>();
Set<String> ids = new HashSet<>();
for (MenuDto menuDTO : menuDtos) {
if (menuDTO.getPid() == null) {
if (ObjectUtil.isEmpty(menuDTO.getPid())) {
trees.add(menuDTO);
}
for (MenuDto it : menuDtos) {
@@ -305,13 +298,13 @@ public class MenuServiceImpl implements MenuService {
MenuVo menuVo = new MenuVo();
menuVo.setName(ObjectUtil.isNotEmpty(menuDTO.getComponent_name()) ? menuDTO.getComponent_name() : menuDTO.getTitle());
// 一级目录需要加斜杠,不然会报警告
menuVo.setPath(menuDTO.getPid() == null ? "/" + menuDTO.getPath() : menuDTO.getPath());
menuVo.setPath(StrUtil.isEmpty(menuDTO.getPid()) ? "/" + menuDTO.getPath() : menuDTO.getPath());
menuVo.setHidden(menuDTO.getHidden());
// 如果不是外链
if (!menuDTO.getI_frame()) {
if (menuDTO.getPid() == null) {
if (StrUtil.isEmpty(menuDTO.getPid()) ) {
menuVo.setComponent(StrUtil.isEmpty(menuDTO.getComponent()) ? "Layout" : menuDTO.getComponent());
} else if (menuDTO.getPid() != null && 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())) {
@@ -324,7 +317,7 @@ public class MenuServiceImpl implements MenuService {
menuVo.setRedirect("noredirect");
menuVo.setChildren(buildMenus(menuDtoList));
// 处理是一级菜单并且没有子菜单的情况
} else if (menuDTO.getPid() == null) {
} else if (StrUtil.isEmpty(menuDTO.getPid())) {
MenuVo menuVo1 = new MenuVo();
menuVo1.setMeta(menuVo.getMeta());
// 非外链