| | |
| | | import org.springblade.core.secure.utils.AuthUtil; |
| | | import org.springblade.core.tool.api.R; |
| | | import org.springblade.core.tool.utils.Func; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.context.annotation.Lazy; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * 分类授权 |
| | | * 分类授权,数据授权 |
| | | * @author ludc |
| | | * @date 2023/12/25 15:35 |
| | | */ |
| | |
| | | throw new ServiceException("缺少必传参数分类id"); |
| | | } |
| | | LambdaQueryWrapper<ClassifyAuth> wrapper = Wrappers.<ClassifyAuth>query() |
| | | .lambda().eq(ClassifyAuth::getClassifyId,classifyAuthVO.getClassifyId()); |
| | | .lambda().eq(ClassifyAuth::getClassifyId,classifyAuthVO.getClassifyId()) |
| | | .eq(ClassifyAuth::getAuthType,classifyAuthVO.getAuthType()); |
| | | List<ClassifyAuth> classifyAuths = this.classifyAuthMapper.selectList(wrapper); |
| | | if(classifyAuths.isEmpty()){ |
| | | return new ArrayList<ClassifyAuthVO>(); |
| | |
| | | /** |
| | | * 查询该分类下,当前登录的角色有哪些按钮权限 |
| | | * @param classifyId |
| | | * @param menuCode |
| | | * @param authType |
| | | * @return |
| | | */ |
| | | public Map<String,Boolean> getAuthButtonList(String classifyId){ |
| | | public Map<String,Boolean> getAuthButtonList(String classifyId,String menuCode,String authType){ |
| | | List<Menu> menuList = this.getButtonList(classifyId, menuCode, authType); |
| | | if(menuList.isEmpty()){ |
| | | return new HashMap<>(); |
| | | } |
| | | Map<String, Boolean> buttonMaps = menuList.stream() |
| | | .collect(Collectors.toMap(Menu::getCode, menu -> true)); |
| | | return buttonMaps; |
| | | } |
| | | |
| | | /** |
| | | * 查询该主数据下,当前登录的角色有哪些按钮菜单权限 |
| | | * @param classifyId |
| | | * @param menuCode |
| | | * @param authType |
| | | * @return |
| | | */ |
| | | public List<Menu> getAuthMenuButtonList(String classifyId,String menuCode,String authType){ |
| | | List<Menu> buttonList = getButtonList(classifyId, menuCode, authType); |
| | | return buttonList; |
| | | } |
| | | |
| | | private List<Menu> getButtonList(String classifyId,String menuCode,String authType){ |
| | | if(Func.isBlank(classifyId)){ |
| | | throw new ServiceException("必传参数分类oid不能为空!"); |
| | | } |
| | |
| | | // 先查询按钮id列表 |
| | | LambdaQueryWrapper<ClassifyAuth> wrapper = Wrappers.<ClassifyAuth>query() |
| | | .lambda().eq(ClassifyAuth::getClassifyId, classifyId) |
| | | .eq(ClassifyAuth::getAuthType,authType) |
| | | .in(ClassifyAuth::getRoleId, roleIds); |
| | | List<ClassifyAuth> classifyAuths = this.classifyAuthMapper.selectList(wrapper); |
| | | //如果当前分类没有找到授权配置,就依次从当前节点往上层节点找授权配置,找到了就停止,没找到就一直找到最后 |
| | |
| | | Boolean isAdmin = VciBaseUtil.checkAdminTenant(); |
| | | // 未配置按钮权限 |
| | | if(!isAdmin && (classifyAuths.isEmpty() || Func.isBlank(classifyAuths.get(0).getButtonIds()))){ |
| | | return new HashMap<>(); |
| | | return new ArrayList<>(); |
| | | } |
| | | List<String> condition1 = new ArrayList<>(); |
| | | List<String> ids = new ArrayList<>(); |
| | | // 如果不是超管用户 |
| | | if(!isAdmin){ |
| | | condition1.addAll(Arrays.asList(classifyAuths.get(0).getButtonIds().split(","))); |
| | | ids.addAll(Arrays.asList(classifyAuths.get(0).getButtonIds().split(","))); |
| | | } |
| | | List<Menu> menuList = menuService.getMenuListById(condition1,"1648879284590858241"); |
| | | if(menuList.isEmpty()){ |
| | | return new HashMap<>(); |
| | | } |
| | | Map<String, Boolean> buttonMaps = menuList.stream() |
| | | .collect(Collectors.toMap(Menu::getCode, menu -> true)); |
| | | return buttonMaps; |
| | | return menuService.getMenuListByCode(ids,menuCode,roleIds); |
| | | } |
| | | |
| | | /** |
| | |
| | | * @return |
| | | */ |
| | | @Override |
| | | public List<String> getViewClassByRoleIds(List<String> roleIds) { |
| | | public List<String> getViewClassByRoleIds(List<String> roleIds,String authType,String menuCode) { |
| | | if(roleIds.isEmpty()){ |
| | | return new ArrayList<>(); |
| | | } |
| | | return this.classifyAuthMapper.getViewClassByRoleIds(roleIds); |
| | | return this.classifyAuthMapper.getViewClassByRoleIds(roleIds, authType,menuCode); |
| | | } |
| | | |
| | | } |