按照角色进行菜单过滤
This commit is contained in:
+46
@@ -8,6 +8,7 @@ import com.linke.product.domain.appMenu.repository.po.AppModulePO;
|
|||||||
import com.linke.product.domain.appMenu.repository.todo.AppMenuDO;
|
import com.linke.product.domain.appMenu.repository.todo.AppMenuDO;
|
||||||
import com.linke.product.domain.appMenu.service.AppMenuDomainService;
|
import com.linke.product.domain.appMenu.service.AppMenuDomainService;
|
||||||
import com.linke.product.domain.menu.repository.po.MenuPo;
|
import com.linke.product.domain.menu.repository.po.MenuPo;
|
||||||
|
import com.linke.product.domain.menu.service.UserFeignService;
|
||||||
import com.linke.product.infrastructure.feign.UserServiceFeign;
|
import com.linke.product.infrastructure.feign.UserServiceFeign;
|
||||||
import com.mhd.common.core.domain.entity.R;
|
import com.mhd.common.core.domain.entity.R;
|
||||||
import com.mhd.common.core.domain.po.UserConfigSwitchPo;
|
import com.mhd.common.core.domain.po.UserConfigSwitchPo;
|
||||||
@@ -45,6 +46,8 @@ public class AppMenuApplicationService {
|
|||||||
private UserServiceFeign userServiceFeign;
|
private UserServiceFeign userServiceFeign;
|
||||||
@Autowired
|
@Autowired
|
||||||
private CommonApplicationService commonApplicationService;
|
private CommonApplicationService commonApplicationService;
|
||||||
|
@Autowired
|
||||||
|
private UserFeignService userFeignService;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -90,6 +93,9 @@ public class AppMenuApplicationService {
|
|||||||
appMenuDO.setTopOrganizationId(SecurityUtils.getLoginUser().getUserPo().getTopOrganizationId());
|
appMenuDO.setTopOrganizationId(SecurityUtils.getLoginUser().getUserPo().getTopOrganizationId());
|
||||||
}
|
}
|
||||||
List<MenuPo> menuPos = appMenuDomainService.queryMenuListByApp(appMenuDO);
|
List<MenuPo> menuPos = appMenuDomainService.queryMenuListByApp(appMenuDO);
|
||||||
|
// 车队主管显示「订单调度」;业务主管显示「订单审核」
|
||||||
|
List<UserRoleMenuPO> userRoles = userFeignService.selectUserRoles(appMenuDO.getUserId());
|
||||||
|
menuPos = filterMenuByRole(menuPos, userRoles);
|
||||||
//判断控制推广码是否显示
|
//判断控制推广码是否显示
|
||||||
if (menuPos != null){
|
if (menuPos != null){
|
||||||
//获取配置判断是否开启推广码
|
//获取配置判断是否开启推广码
|
||||||
@@ -102,6 +108,46 @@ public class AppMenuApplicationService {
|
|||||||
return menuPos;
|
return menuPos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 按角色过滤互斥菜单:
|
||||||
|
* 车队主管隐藏「订单审核」;业务主管隐藏「订单调度」
|
||||||
|
*/
|
||||||
|
private List<MenuPo> filterMenuByRole(List<MenuPo> menuPos, List<UserRoleMenuPO> userRoles) {
|
||||||
|
if (menuPos == null || menuPos.isEmpty()) {
|
||||||
|
return menuPos;
|
||||||
|
}
|
||||||
|
boolean isFleetSupervisor = hasRole(userRoles, "车队主管");
|
||||||
|
boolean isBusinessSupervisor = hasRole(userRoles, "业务主管");
|
||||||
|
if (!isFleetSupervisor && !isBusinessSupervisor) {
|
||||||
|
return menuPos;
|
||||||
|
}
|
||||||
|
return menuPos.stream()
|
||||||
|
.filter(menu -> !(isFleetSupervisor && isOrderReviewMenu(menu)))
|
||||||
|
.filter(menu -> !(isBusinessSupervisor && isOrderDispatchMenu(menu)))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean hasRole(List<UserRoleMenuPO> userRoles, String roleName) {
|
||||||
|
return userRoles.stream().anyMatch(role ->
|
||||||
|
roleName.equals(role.getRoleName()) || roleName.equals(role.getRoleCode()));
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isOrderDispatchMenu(MenuPo menu) {
|
||||||
|
return matchMenuName(menu, "订单调度", "运力调度");
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isOrderReviewMenu(MenuPo menu) {
|
||||||
|
return matchMenuName(menu, "订单审核");
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean matchMenuName(MenuPo menu, String... menuNames) {
|
||||||
|
for (String menuName : menuNames) {
|
||||||
|
if (menuName.equals(menu.getMenuName()) || menuName.equals(menu.getMenuShowName())) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 保存app/菜单权限
|
* 保存app/菜单权限
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户中心微服务 防腐层
|
* 用户中心微服务 防腐层
|
||||||
@@ -85,4 +86,16 @@ public class UserFeignService {
|
|||||||
}
|
}
|
||||||
return menus;
|
return menus;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询用户所属角色列表
|
||||||
|
*/
|
||||||
|
public List<UserRoleMenuPO> selectUserRoles(Long userId) {
|
||||||
|
AjaxResult ajaxResult = userServiceFeign.selectRolesByUserId(userId);
|
||||||
|
if (!"200".equals(String.valueOf(ajaxResult.get("code")))) {
|
||||||
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
|
List<UserRoleMenuPO> userRoles = JSON.parseArray(JSONObject.toJSONString(ajaxResult.get("data")), UserRoleMenuPO.class);
|
||||||
|
return userRoles != null ? userRoles : new ArrayList<>();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user