Browse Source

服务授权申请修改

mazq 1 year ago
parent
commit
35d9386ea5

+ 16 - 6
dcuc-auth-service/src/main/java/com/dragoninfo/dcuc/auth/business/impl/zerotrust/ZeroTrustAuthApplyBusinessImpl.java

@@ -282,6 +282,7 @@ public class ZeroTrustAuthApplyBusinessImpl implements IZeroTrustAuthApplyBusine
     private Result<List<ServiceResourceDTO>> validateServiceInfos(List<ServiceResourceDTO> serviceInfos, List<ApiServiceAuthContentVo> contents) {
     private Result<List<ServiceResourceDTO>> validateServiceInfos(List<ServiceResourceDTO> serviceInfos, List<ApiServiceAuthContentVo> contents) {
         Map<String, List<ServiceResourceDTO>> collect = serviceInfos.stream()
         Map<String, List<ServiceResourceDTO>> collect = serviceInfos.stream()
                 .collect(Collectors.groupingBy(ServiceResourceDTO::getAppCode));
                 .collect(Collectors.groupingBy(ServiceResourceDTO::getAppCode));
+        List<ServiceResourceDTO> errList = new ArrayList<>();
         for (ApiServiceAuthContentVo authVo : contents) {
         for (ApiServiceAuthContentVo authVo : contents) {
             String appCode = authVo.getAppCode();
             String appCode = authVo.getAppCode();
             List<ServiceResourceDTO> exist = collect.get(appCode);
             List<ServiceResourceDTO> exist = collect.get(appCode);
@@ -292,7 +293,7 @@ public class ZeroTrustAuthApplyBusinessImpl implements IZeroTrustAuthApplyBusine
                     dto.setServiceCode(e);
                     dto.setServiceCode(e);
                     return dto;
                     return dto;
                 }).collect(Collectors.toList());
                 }).collect(Collectors.toList());
-                return Result.fail(ResultEnum.FAIL.getValue(), AuthApplyRespEnum.SERVICE_NOT_EXIST.getValue(), notExist);
+                errList.addAll(notExist);
             }
             }
             Set<String> existCodes = exist.stream().map(ServiceResourceDTO::getServiceCode).collect(Collectors.toSet());
             Set<String> existCodes = exist.stream().map(ServiceResourceDTO::getServiceCode).collect(Collectors.toSet());
             List<ServiceResourceDTO> notExist = authServiceCodes.stream().filter(e -> !existCodes.contains(e)).map(e -> {
             List<ServiceResourceDTO> notExist = authServiceCodes.stream().filter(e -> !existCodes.contains(e)).map(e -> {
@@ -301,10 +302,14 @@ public class ZeroTrustAuthApplyBusinessImpl implements IZeroTrustAuthApplyBusine
                 return dto;
                 return dto;
             }).collect(Collectors.toList());
             }).collect(Collectors.toList());
             if (CollectionUtils.isNotEmpty(notExist)) {
             if (CollectionUtils.isNotEmpty(notExist)) {
-                return Result.fail(ResultEnum.FAIL.getValue(), AuthApplyRespEnum.SERVICE_NOT_EXIST.getValue(), notExist);
+                errList.addAll(notExist);
             }
             }
         }
         }
-        return Result.success();
+        if (!errList.isEmpty()) {
+            return Result.fail(ResultEnum.FAIL.getValue(), AuthApplyRespEnum.SERVICE_NOT_EXIST.getValue(), errList);
+        } else {
+            return Result.success();
+        }
     }
     }
 
 
     private ZeroTrustDataRespVO<AuthApplyRespVo> getErrorApplyResp(AuthApplyRespEnum authApplyRespEnum, Object content) {
     private ZeroTrustDataRespVO<AuthApplyRespVo> getErrorApplyResp(AuthApplyRespEnum authApplyRespEnum, Object content) {
@@ -399,6 +404,7 @@ public class ZeroTrustAuthApplyBusinessImpl implements IZeroTrustAuthApplyBusine
     private Result<List<RoleInfo>> validateApplyRoles(List<ApplyInfoVo> applyInfoVos, List<RoleInfo> roleInfos, List<ApiRoleAuthContentVo> contents) {
     private Result<List<RoleInfo>> validateApplyRoles(List<ApplyInfoVo> applyInfoVos, List<RoleInfo> roleInfos, List<ApiRoleAuthContentVo> contents) {
         Map<String, ApplyInfoVo> appMap = applyInfoVos.stream().collect(Collectors.toMap(ApplyInfoVo::getApplyCode, e -> e));
         Map<String, ApplyInfoVo> appMap = applyInfoVos.stream().collect(Collectors.toMap(ApplyInfoVo::getApplyCode, e -> e));
         Map<String, List<RoleInfo>> roleMap = roleInfos.stream().collect(Collectors.groupingBy(RoleInfo::getAppId));
         Map<String, List<RoleInfo>> roleMap = roleInfos.stream().collect(Collectors.groupingBy(RoleInfo::getAppId));
+        List<RoleInfo> errList = new ArrayList<>();
         for (ApiRoleAuthContentVo authVo : contents) {
         for (ApiRoleAuthContentVo authVo : contents) {
             String appCode = authVo.getAppCode();
             String appCode = authVo.getAppCode();
             List<String> appRoleCodes = authVo.getRoleCodes();
             List<String> appRoleCodes = authVo.getRoleCodes();
@@ -406,16 +412,20 @@ public class ZeroTrustAuthApplyBusinessImpl implements IZeroTrustAuthApplyBusine
             List<RoleInfo> roles = roleMap.get(applyInfoVo.getId());
             List<RoleInfo> roles = roleMap.get(applyInfoVo.getId());
             if (CollectionUtils.isEmpty(roles)) {
             if (CollectionUtils.isEmpty(roles)) {
                 List<RoleInfo> notExistRoles = mapNotExistRoles(appRoleCodes, applyInfoVo);
                 List<RoleInfo> notExistRoles = mapNotExistRoles(appRoleCodes, applyInfoVo);
-                return Result.fail(ResultEnum.FAIL.getValue(), AuthApplyRespEnum.ROLE_NOT_EXIST.getValue(), notExistRoles);
+                errList.addAll(notExistRoles);
             }
             }
             Set<String> exist = roles.stream().map(RoleInfo::getCode).collect(Collectors.toSet());
             Set<String> exist = roles.stream().map(RoleInfo::getCode).collect(Collectors.toSet());
             List<String> notExist = appRoleCodes.stream().filter(e -> !exist.contains(e)).collect(Collectors.toList());
             List<String> notExist = appRoleCodes.stream().filter(e -> !exist.contains(e)).collect(Collectors.toList());
             if (CollectionUtils.isEmpty(notExist)) {
             if (CollectionUtils.isEmpty(notExist)) {
                 List<RoleInfo> notExistRoles = mapNotExistRoles(notExist, applyInfoVo);
                 List<RoleInfo> notExistRoles = mapNotExistRoles(notExist, applyInfoVo);
-                return Result.fail(ResultEnum.FAIL.getValue(), AuthApplyRespEnum.ROLE_NOT_EXIST.getValue(), notExistRoles);
+                errList.addAll(notExistRoles);
             }
             }
         }
         }
-        return Result.success();
+        if (!errList.isEmpty()) {
+            return Result.fail(ResultEnum.FAIL.getValue(), AuthApplyRespEnum.ROLE_NOT_EXIST.getValue(), errList);
+        } else {
+            return Result.success();
+        }
     }
     }
 
 
     private static List<RoleInfo> mapNotExistRoles(List<String> appRoleCodes, ApplyInfoVo applyInfoVo) {
     private static List<RoleInfo> mapNotExistRoles(List<String> appRoleCodes, ApplyInfoVo applyInfoVo) {