fix:角色菜单接口修改
This commit is contained in:
@@ -64,6 +64,8 @@ public class MenuController {
|
|||||||
}
|
}
|
||||||
String pid = systemDict.getString("para1");
|
String pid = systemDict.getString("para1");
|
||||||
List<MenuDto> menuDtoList = menuService.findByUser(String.valueOf(SecurityUtils.getCurrentUserId()),system_type);
|
List<MenuDto> menuDtoList = menuService.findByUser(String.valueOf(SecurityUtils.getCurrentUserId()),system_type);
|
||||||
|
//移除系统级菜单
|
||||||
|
menuDtoList.removeIf(a->a.getMenu_id().equals(pid));
|
||||||
List<MenuDto> menuDtos = menuService.buildTree(menuDtoList);
|
List<MenuDto> menuDtos = menuService.buildTree(menuDtoList);
|
||||||
return new ResponseEntity<>(menuService.buildMenus(menuDtos,pid),HttpStatus.OK);
|
return new ResponseEntity<>(menuService.buildMenus(menuDtos,pid),HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,14 +9,15 @@ import lombok.RequiredArgsConstructor;
|
|||||||
import org.nl.modules.logging.annotation.Log;
|
import org.nl.modules.logging.annotation.Log;
|
||||||
import org.nl.modules.wql.core.bean.WQLObject;
|
import org.nl.modules.wql.core.bean.WQLObject;
|
||||||
import org.nl.sso.system.service.RoleService;
|
import org.nl.sso.system.service.RoleService;
|
||||||
|
import org.nl.sso.tools.MapOf;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.util.CollectionUtils;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.*;
|
||||||
import java.util.Map;
|
import java.util.stream.Collectors;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author ludj
|
* @author ludj
|
||||||
@@ -70,16 +71,26 @@ public class RoleController {
|
|||||||
public ResponseEntity<Object> updateMenu(@RequestBody JSONObject form) {
|
public ResponseEntity<Object> updateMenu(@RequestBody JSONObject form) {
|
||||||
String role_id = form.getString("role_id");
|
String role_id = form.getString("role_id");
|
||||||
JSONArray menus = form.getJSONArray("menus");
|
JSONArray menus = form.getJSONArray("menus");
|
||||||
WQLObject rmTab = WQLObject.getWQLObject("sys_roles_menus");
|
|
||||||
rmTab.delete("role_id = " + role_id + "");
|
|
||||||
|
|
||||||
for (int i = 0; i < menus.size(); i++) {
|
WQLObject rmTab = WQLObject.getWQLObject("sys_roles_menus");
|
||||||
JSONObject json = menus.getJSONObject(i);
|
JSONArray result = rmTab.query("role_id = " + role_id + "").getResultJSONArray(0);
|
||||||
JSONObject param = new JSONObject();
|
Set<String> dbMenus = new HashSet<>();
|
||||||
param.put("role_id", role_id);
|
if (result.size()>0){
|
||||||
param.put("menu_id", json.getString("menu_id"));
|
dbMenus.addAll(result.stream().map(a -> ((JSONObject) a).getString("menu_id")).collect(Collectors.toSet()));
|
||||||
rmTab.insert(param);
|
|
||||||
}
|
}
|
||||||
|
Set<String> currentMenus = menus.stream().map(a -> ((HashMap<String,String>) a).get("menu_id")).collect(Collectors.toSet());
|
||||||
|
List<String> needAdd = currentMenus.stream().filter(item -> !dbMenus.contains(item)).collect(Collectors.toList());
|
||||||
|
List<String> needDel = dbMenus.stream().filter(item -> !currentMenus.contains(item)).collect(Collectors.toList());
|
||||||
|
if (!CollectionUtils.isEmpty(needAdd)){
|
||||||
|
for (String s : needAdd) {
|
||||||
|
rmTab.insert(MapOf.of("role_id",role_id,"menu_id",s));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!CollectionUtils.isEmpty(needDel)){
|
||||||
|
String collect = needDel.stream().collect(Collectors.joining("','"));
|
||||||
|
rmTab.delete("role_id = '"+role_id+"' and menu_id in ('"+collect+"')");
|
||||||
|
}
|
||||||
|
|
||||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ import org.springframework.stereotype.Service;
|
|||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.function.Predicate;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -338,6 +339,7 @@ public class MenuServiceImpl implements MenuService {
|
|||||||
@Override
|
@Override
|
||||||
public List<MenuVo> buildMenus(List<MenuDto> menuDtos,String pid) {
|
public List<MenuVo> buildMenus(List<MenuDto> menuDtos,String pid) {
|
||||||
List<MenuVo> list = new LinkedList<>();
|
List<MenuVo> list = new LinkedList<>();
|
||||||
|
//剔除系统级菜单
|
||||||
menuDtos.forEach(menuDTO -> {
|
menuDtos.forEach(menuDTO -> {
|
||||||
if (menuDTO != null) {
|
if (menuDTO != null) {
|
||||||
List<MenuDto> menuDtoList = menuDTO.getChildren();
|
List<MenuDto> menuDtoList = menuDTO.getChildren();
|
||||||
|
|||||||
Reference in New Issue
Block a user