xiejun
2024-01-23 f09e05514d9a9e2623cfa73c4de1ffa98bb30bf8
Source/UBCS/ubcs-service/ubcs-system/src/main/java/com/vci/ubcs/system/service/impl/ClassifyAuthServiceImpl.java
@@ -19,6 +19,8 @@
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;
@@ -26,7 +28,7 @@
import java.util.stream.Collectors;
/**
 * 分类授权
 * 分类授权,数据授权
 * @author ludc
 * @date 2023/12/25 15:35
 */
@@ -87,7 +89,8 @@
         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>();
@@ -98,9 +101,33 @@
   /**
    * 查询该分类下,当前登录的角色有哪些按钮权限
    * @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不能为空!");
      }
@@ -115,6 +142,7 @@
      // 先查询按钮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);
      //如果当前分类没有找到授权配置,就依次从当前节点往上层节点找授权配置,找到了就停止,没找到就一直找到最后
@@ -139,20 +167,14 @@
      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);
   }
   /**
@@ -161,11 +183,11 @@
    * @return
    */
   @Override
   public List<String> getViewClassByRoleIds(List<String> roleIds) {
   public List<String> getViewClassByRoleIds(List<String> roleIds,String authType,String buttonCode,String menuCode) {
      if(roleIds.isEmpty()){
         return new ArrayList<>();
      }
      return this.classifyAuthMapper.getViewClassByRoleIds(roleIds);
      return this.classifyAuthMapper.getViewClassByRoleIds(roleIds, authType,buttonCode,menuCode);
   }
}