ludc
2024-02-02 52fd1e55b71fa38ffe89db738acc4e6c7e4da0df
Source/UBCS/ubcs-service/ubcs-system/src/main/java/com/vci/ubcs/system/service/impl/ClassifyAuthServiceImpl.java
@@ -2,7 +2,6 @@
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.vci.ubcs.code.feign.ICodeClassifyClient;
@@ -14,15 +13,12 @@
import com.vci.ubcs.system.service.IClassifyAuthService;
import com.vci.ubcs.system.service.IMenuService;
import com.vci.ubcs.system.vo.ClassifyAuthVO;
import com.vci.ubcs.system.vo.MenuVO;
import com.vci.ubcs.system.wrapper.ClassifyAuthWrapper;
import lombok.AllArgsConstructor;
import org.springblade.core.log.exception.ServiceException;
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;
@@ -55,10 +51,12 @@
      // 是清空授权列表
      if(classifyAuthListDTO.getIsCLear()){
         if(Func.isEmpty(classifyAuthListDTO.getClassifyId())){
            return R.fail("清空授权列表时,未获取的分类id");
            return R.fail("清空授权列表时,未获取到分类id");
         }
         this.classifyAuthMapper.delete(Wrappers.<ClassifyAuth>update()
         this.classifyAuthMapper.delete(
            Wrappers.<ClassifyAuth>update()
            .lambda().eq(ClassifyAuth::getClassifyId, classifyAuthListDTO.getClassifyId())
            .eq(ClassifyAuth::getAuthType,classifyAuthListDTO.getAuthType())
         );
         return R.success("授权列表清空成功");
      }
@@ -82,6 +80,7 @@
      // 删除
      LambdaUpdateWrapper<ClassifyAuth> updateWrapper = Wrappers.<ClassifyAuth>update()
         .lambda().eq(ClassifyAuth::getClassifyId, classifyAuthListDTO.getClassifyAuthList().get(0).getClassifyId())
         .eq(ClassifyAuth::getAuthType,classifyAuthListDTO.getAuthType())
         .notIn(ClassifyAuth::getRoleId, roleIds);
      try {
         this.classifyAuthMapper.delete(updateWrapper);
@@ -168,15 +167,23 @@
                  .eq(ClassifyAuth::getAuthType,authType)
                  .in(ClassifyAuth::getRoleId, roleIds)
            );
            //只要当前节点的上层节点中找到了分类授权信息就不再继续网上找了
            //只要当前节点的上层节点中找到了分类授权信息就不再继续往上找了
            if(!classifyAuths.isEmpty()){
               break;
            }
         }
      }
      //出现了错误数据,同一个角色和同一个分类id存在多条授权记录
      //出现了多条数据
      if(classifyAuths.size()>1){
         throw new ServiceException("角色和分类配置存在多条记录,请联系管理人员清理错误配置!");
         // 校验是否存在错误数据,同一个角色和同一个分类id存在多条授权记录
         List<ClassifyAuth> finalClassifyAuths = classifyAuths;
         boolean hasDuplicate = classifyAuths.stream()
            .anyMatch(auth1 -> finalClassifyAuths.stream()
               .filter(auth2 -> auth1 != auth2)
               .anyMatch(auth2 -> auth1.getRoleId().equals(auth2.getRoleId()) && auth1.getClassifyId().equals(auth2.getClassifyId())));
         if (hasDuplicate) {
            throw new ServiceException("角色和分类配置存在多条记录,请联系管理人员清理错误配置!");
         }
      }
      // 是否为超管
      Boolean isAdmin = VciBaseUtil.checkAdminTenant();
@@ -187,7 +194,10 @@
      List<String> ids = new ArrayList<>();
      // 如果不是超管用户
      if(!isAdmin){
         ids.addAll(Arrays.asList(classifyAuths.get(0).getButtonIds().split(",")));
         String concatenatedButtonIds = classifyAuths.stream()
            .map(ClassifyAuth::getButtonIds) // 获取每个classifyAuths对象的buttonIds
            .collect(Collectors.joining(",")); // 用逗号分隔拼接成一个字符串
         ids.addAll(Arrays.asList(concatenatedButtonIds.split(",")));
      }
      return menuService.getMenuListByCode(ids,menuCode,roleIds);
   }