修改菜单角色慢的问题
This commit is contained in:
parent
8b3e256aaf
commit
581e8b098a
@ -172,8 +172,6 @@ public class RoleController extends BaseController {
|
||||
@PathVariable("roleId") String roleId,
|
||||
@PathVariable("type") String type) throws SearchException, ParamsException {
|
||||
Map<String, Object> params = requestParams();
|
||||
params.put("menuParentId", menuParentId);
|
||||
params.put("roleId", roleId);
|
||||
if (!IRoleService.AUTH_TYPE_INSERT.equals(type) &&
|
||||
!IRoleService.AUTH_TYPE_DELETE.equals(type) &&
|
||||
!IRoleService.AUTH_TYPE_UPDATE.equals(type) &&
|
||||
@ -181,11 +179,7 @@ public class RoleController extends BaseController {
|
||||
!IRoleService.AUTH_TYPE_MENU.equals(type)) {
|
||||
throw new ParamsException("授权类型错误");
|
||||
}
|
||||
params.put("type", type);
|
||||
if (IRoleService.AUTH_TYPE_MENU.equals(type)) {
|
||||
params.put("menuType", 1);
|
||||
}
|
||||
return menuService.listMenuAllJson(params);
|
||||
return menuService.listMenuByRoleIdAndType(roleId, type);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "执行授权", notes = "执行授权接口")
|
||||
|
@ -53,7 +53,7 @@ public class MenuResourceController extends BaseController {
|
||||
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
|
||||
@GetMapping("listmenubyclientid/{clientId}/{userId}")
|
||||
public Callable<SuccessResultData<List<MenuDTO>>> listMenuByClientId(@PathVariable("clientId") String clientId, @PathVariable("userId") String userId, HttpServletRequest httpServletRequest) throws Exception {
|
||||
return () -> menuService.listMenuByClientIdAndUserId(clientId, userId);
|
||||
return () -> new SuccessResultData<>(menuService.listMenuByClientIdAndUserId(clientId, userId));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -77,7 +77,7 @@ public class MenuDTO implements Serializable {
|
||||
}
|
||||
|
||||
public Boolean getParent() {
|
||||
return isParent;
|
||||
return isParent == null ? false : isParent;
|
||||
}
|
||||
|
||||
public void setParent(Boolean parent) {
|
||||
@ -173,7 +173,7 @@ public class MenuDTO implements Serializable {
|
||||
}
|
||||
|
||||
public Boolean getRight() {
|
||||
return isRight;
|
||||
return isRight == null ? false : isRight;
|
||||
}
|
||||
|
||||
public void setRight(Boolean right) {
|
||||
|
@ -121,7 +121,16 @@ public interface IMenuService {
|
||||
* @return
|
||||
* @throws SearchException
|
||||
*/
|
||||
SuccessResultData<List<MenuDTO>> listMenuByClientIdAndUserId(String clientId, String userId) throws Exception;
|
||||
List<MenuDTO> listMenuByClientIdAndUserId(String clientId, String userId) throws Exception;
|
||||
|
||||
/**
|
||||
* 通过角色和类型获取菜单列表
|
||||
*
|
||||
* @param roleId
|
||||
* @param type
|
||||
* @return
|
||||
*/
|
||||
List<MenuDTO> listMenuByRoleIdAndType(String roleId, String type);
|
||||
|
||||
/**
|
||||
* 通过用户获取菜单
|
||||
@ -131,4 +140,5 @@ public interface IMenuService {
|
||||
* @throws SearchException
|
||||
*/
|
||||
List<String> listMenuIdByUser(Map<String, Object> params) throws SearchException;
|
||||
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package com.cm.serviceusercenter.service.system.menu.impl;
|
||||
|
||||
import com.cm.common.component.SecurityComponent;
|
||||
import com.cm.common.constants.ISystemConstant;
|
||||
import com.cm.common.exception.RemoveException;
|
||||
import com.cm.common.exception.SaveException;
|
||||
import com.cm.common.exception.SearchException;
|
||||
@ -12,12 +11,12 @@ import com.cm.common.pojo.dtos.ZTreeDTO;
|
||||
import com.cm.common.result.SuccessResult;
|
||||
import com.cm.common.result.SuccessResultData;
|
||||
import com.cm.common.result.SuccessResultList;
|
||||
import com.cm.common.utils.ArrayListUtil;
|
||||
import com.cm.common.utils.UUIDUtil;
|
||||
import com.cm.serviceusercenter.dao.system.menu.IMenuDao;
|
||||
import com.cm.serviceusercenter.dao.system.role.IRoleDao;
|
||||
import com.cm.serviceusercenter.pojo.dtos.MenuDTO;
|
||||
import com.cm.serviceusercenter.pojo.dtos.OauthClientDTO;
|
||||
import com.cm.serviceusercenter.pojo.pos.UserPO;
|
||||
import com.cm.serviceusercenter.service.BaseService;
|
||||
import com.cm.serviceusercenter.service.system.menu.IMenuService;
|
||||
import com.cm.serviceusercenter.service.system.oauthclient.IOauthClientService;
|
||||
@ -149,7 +148,7 @@ public class MenuServiceImpl extends BaseService implements IMenuService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public SuccessResultData<List<MenuDTO>> listMenuByClientIdAndUserId(String clientId, String userId) throws Exception {
|
||||
public List<MenuDTO> listMenuByClientIdAndUserId(String clientId, String userId) throws Exception {
|
||||
Map<String, Object> params = new HashMap<>(1);
|
||||
params.put("clientId", clientId);
|
||||
OauthClientDTO oauthClientDTO = oauthClientService.getOauthClient(params);
|
||||
@ -158,24 +157,127 @@ public class MenuServiceImpl extends BaseService implements IMenuService {
|
||||
}
|
||||
String menuId = oauthClientDTO.getMenuId();
|
||||
if (StringUtils.isBlank(menuId)) {
|
||||
return new SuccessResultData<>(new ArrayList<>());
|
||||
return new ArrayList<>();
|
||||
}
|
||||
List<String> userMenuIds;
|
||||
List<MenuDTO> menuDTOs;
|
||||
// 如果是管理员获取管理员配置的菜单,管理员的ID是1
|
||||
if (StringUtils.equalsIgnoreCase(userId, "1")) {
|
||||
userMenuIds = listAdminMenuId();
|
||||
List<String> userMenuIds = listAdminMenuId();
|
||||
menuDTOs = listMenuTree(userMenuIds, true);
|
||||
} else {
|
||||
params.put("userId", userId);
|
||||
params.put(IRoleService.ROLE_TYPE, IRoleService.ROLE_MENU);
|
||||
userMenuIds = listMenuIdByUser(params);
|
||||
List<String> userMenuIds = listMenuIdByUser(params);
|
||||
menuDTOs = listMenuTree(userMenuIds, false);
|
||||
}
|
||||
// 获取全部菜单
|
||||
params.clear();
|
||||
params.put("menuParentId", menuId);
|
||||
// 老方法
|
||||
// List<MenuDTO> menuDTOs = listMenusAll(params);
|
||||
// 新方法
|
||||
// 返回客户端菜单
|
||||
List<MenuDTO> clientMenuDTOs = new ArrayList<>();
|
||||
for (MenuDTO menuDTO : menuDTOs) {
|
||||
if (StringUtils.equals(menuId, menuDTO.getMenuId())) {
|
||||
clientMenuDTOs.addAll(menuDTO.getSubMenus());
|
||||
}
|
||||
}
|
||||
return clientMenuDTOs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MenuDTO> listMenuByRoleIdAndType(String roleId, String type) {
|
||||
Map<String, Object> params = getHashMap(4);
|
||||
// 全部菜单
|
||||
params.put("menuStatus", 0);
|
||||
params.put("menuIds", userMenuIds);
|
||||
List<MenuDTO> menuDTOs = listMenusAll(params);
|
||||
return new SuccessResultData<>(menuDTOs);
|
||||
List<MenuDTO> menuDTOs = ArrayListUtil.deepClone(menuDao.listMenus(params), MenuDTO.class);
|
||||
List<MenuDTO> resultMenuDTOs = new ArrayList<>();
|
||||
params.clear();
|
||||
params.put("roleId", roleId);
|
||||
if (IRoleService.AUTH_TYPE_INSERT.equals(type)) {
|
||||
params.put(IRoleService.ROLE_TYPE, IRoleService.ROLE_INSERT);
|
||||
} else if (IRoleService.AUTH_TYPE_DELETE.equals(type)) {
|
||||
params.put(IRoleService.ROLE_TYPE, IRoleService.ROLE_DELETE);
|
||||
} else if (IRoleService.AUTH_TYPE_UPDATE.equals(type)) {
|
||||
params.put(IRoleService.ROLE_TYPE, IRoleService.ROLE_UPDATE);
|
||||
} else if (IRoleService.AUTH_TYPE_QUERY.equals(type)) {
|
||||
params.put(IRoleService.ROLE_TYPE, IRoleService.ROLE_QUERY);
|
||||
} else {
|
||||
params.put(IRoleService.ROLE_TYPE, IRoleService.ROLE_MENU);
|
||||
}
|
||||
// 角色菜单
|
||||
List<RoleMenuBO> roleMenuBOs = roleDao.listRoleMenuInfo(params);
|
||||
// 勾选权限
|
||||
for (MenuDTO menuDTO : menuDTOs) {
|
||||
for (RoleMenuBO roleMenuBO : roleMenuBOs) {
|
||||
if (StringUtils.equals(roleMenuBO.getMenuId(), menuDTO.getMenuId())) {
|
||||
menuDTO.setRight(true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
buildMenuTree(resultMenuDTOs, menuDTOs, "0");
|
||||
return resultMenuDTOs;
|
||||
}
|
||||
|
||||
/**
|
||||
* 菜单树列表
|
||||
*
|
||||
* @param userMenuIds
|
||||
* @param isAdmin
|
||||
* @return
|
||||
*/
|
||||
private List<MenuDTO> listMenuTree(List<String> userMenuIds, boolean isAdmin) {
|
||||
Map<String, Object> params = getHashMap(6);
|
||||
params.put("menuStatus", 0);
|
||||
List<MenuDTO> menuDTOs = ArrayListUtil.deepClone(menuDao.listMenus(params), MenuDTO.class);
|
||||
List<MenuDTO> resultMenuDTOs = new ArrayList<>();
|
||||
if (isAdmin && userMenuIds.isEmpty()) {
|
||||
buildMenuTree(resultMenuDTOs, menuDTOs, "0");
|
||||
return resultMenuDTOs;
|
||||
}
|
||||
// 得到用户菜单
|
||||
for (int i = 0; i < menuDTOs.size(); i++) {
|
||||
MenuDTO menuDTO = menuDTOs.get(i);
|
||||
boolean isUserMenu = false;
|
||||
for (String menuId : userMenuIds) {
|
||||
if (StringUtils.equals(menuDTO.getMenuId(), menuId)) {
|
||||
isUserMenu = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!isUserMenu) {
|
||||
menuDTOs.remove(i);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
// 构建树形结构
|
||||
buildMenuTree(resultMenuDTOs, menuDTOs, "0");
|
||||
return resultMenuDTOs;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建菜单树
|
||||
*
|
||||
* @param parentMenuDTOs
|
||||
* @param menuDTOs
|
||||
* @param menuParentId
|
||||
*/
|
||||
private void buildMenuTree(List<MenuDTO> parentMenuDTOs, List<MenuDTO> menuDTOs, String menuParentId) {
|
||||
for (int i = 0; i < menuDTOs.size(); i++) {
|
||||
MenuDTO menuDTO = menuDTOs.get(i);
|
||||
if (StringUtils.equals(menuDTO.getMenuParentId(), menuParentId)) {
|
||||
parentMenuDTOs.add(menuDTO);
|
||||
menuDTOs.remove(i);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
for (MenuDTO menuDTO : parentMenuDTOs) {
|
||||
List<MenuDTO> subMenuDTOs = new ArrayList<>();
|
||||
menuDTO.setSubMenus(subMenuDTOs);
|
||||
buildMenuTree(subMenuDTOs, menuDTOs, menuDTO.getMenuId());
|
||||
if (!subMenuDTOs.isEmpty()) {
|
||||
menuDTO.setParent(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,6 +1,6 @@
|
||||
server:
|
||||
port: 7001
|
||||
url: http://192.168.0.103:7001/usercenter
|
||||
url: http://127.0.0.1:7001/usercenter
|
||||
# ws: ws://192.168.0.103:7001/usercenter/ws
|
||||
title: 统一用户管理平台
|
||||
login-page-name: 统一用户管理平台
|
||||
@ -28,14 +28,14 @@ spring:
|
||||
max-request-size: 1GB
|
||||
datasource:
|
||||
druid:
|
||||
url: jdbc:mysql://49.233.36.36:6688/db_cloud?useUnicode=true&characterEncoding=utf8&characterSetResults=utf8&autoReconnect=true&failOverReadOnly=false&useSSL=false&serverTimezone=UTC
|
||||
# url: jdbc:mysql://127.0.0.1:3306/db_cloud_v2_inspection?useUnicode=true&characterEncoding=utf8&characterSetResults=utf8&autoReconnect=true&failOverReadOnly=false&useSSL=false&serverTimezone=UTC
|
||||
# url: jdbc:mysql://49.233.36.36:6688/db_cloud?useUnicode=true&characterEncoding=utf8&characterSetResults=utf8&autoReconnect=true&failOverReadOnly=false&useSSL=false&serverTimezone=UTC
|
||||
url: jdbc:mysql://127.0.0.1:3306/db_cloud_v2_city?useUnicode=true&characterEncoding=utf8&characterSetResults=utf8&autoReconnect=true&failOverReadOnly=false&useSSL=false&serverTimezone=UTC
|
||||
db-type: mysql
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
username: wanggeng
|
||||
# username: root
|
||||
password: WenG>2132997
|
||||
# password: root
|
||||
# username: wanggeng
|
||||
username: root
|
||||
# password: WenG>2132997
|
||||
password: root
|
||||
initial-size: 2
|
||||
min-idle: 2
|
||||
max-active: 10
|
||||
@ -99,7 +99,7 @@ swagger:
|
||||
swagger-base-package: com.cm
|
||||
|
||||
file:
|
||||
uploadPath: /Users/wanggeng/Desktop/UploadFiles/
|
||||
uploadPath: C:\Users\wenc0\Desktop\UploadFiles\
|
||||
imageTypes: png,jpg,jpeg,gif,blob
|
||||
videoTypes: mp4,rmvb
|
||||
audioTypes: mp3,wmv
|
||||
|
@ -141,6 +141,10 @@
|
||||
AND
|
||||
menu_parent_id = #{menuParentId}
|
||||
</if>
|
||||
<if test="menuStatus != null">
|
||||
AND
|
||||
menu_status = #{menuStatus}
|
||||
</if>
|
||||
ORDER BY
|
||||
menu_order asc
|
||||
</select>
|
||||
|
Loading…
Reference in New Issue
Block a user