Selaa lähdekoodia

v1.0.0-feature: 增加网关的异常和服务消息提示和非空判断

sckw-developer 1 kuukausi sitten
vanhempi
commit
6efb0d36f6

+ 0 - 1
sckw-gateway/src/main/java/com/sckw/gateway/exception/GatewayGlobalExceptionHandler.java

@@ -83,7 +83,6 @@ public class GatewayGlobalExceptionHandler implements ErrorWebExceptionHandler {
         HttpResult result = GatewayExceptionUtil.buildServiceUnavailableResponse(request, throwable);
         response.setStatusCode(HttpStatus.OK);
         response.getHeaders().setContentType(MediaType.APPLICATION_JSON);
-
         // 记录异常日志
         log.warn("网关统一异常处理: 路径={}, 方法={}, 响应={}", path, method, result);
 

+ 4 - 2
sckw-gateway/src/main/java/com/sckw/gateway/utils/GatewayExceptionUtil.java

@@ -29,12 +29,14 @@ public class GatewayExceptionUtil {
             org.springframework.web.server.ResponseStatusException statusException =
                     (org.springframework.web.server.ResponseStatusException) throwable;
             if (statusException.getStatusCode().value() == 503) {
-                return HttpResult.error(60500, "服务暂时不可用,请稍后重试");
+                return HttpResult.error(60500, "服务请求异常,请稍后重试");
+            }else{
+                return HttpResult.error(60500, "服务请求异常,请稍后重试["+statusException.getStatusCode().value()+"]");
             }
         }
 
         // 默认返回服务不可用
-        return HttpResult.error(60500, "服务暂时不可用,请稍后重试");
+        return HttpResult.error(60500, "服务请求异常,请稍后重试");
     }
 
     /**

+ 17 - 9
sckw-modules/sckw-system/src/main/java/com/sckw/system/service/KwsEnterpriseService.java

@@ -995,11 +995,13 @@ public class KwsEnterpriseService {
 
 
         List<KwsEntCheckTrack> list = kwsEntCheckTrackDao.findList(id);
+        boolean isValid = false;
         if (CollectionUtils.isNotEmpty(list)) {
-            entDetailResVo.setValid(list.stream().anyMatch(item -> item.getStatus().equals(Global.NO)));
-        } else {
-            entDetailResVo.setValid(false);
+            isValid = list.stream()
+                    .filter(item -> item.getStatus() != null)
+                    .anyMatch(item -> item.getStatus().equals(Global.NO));
         }
+        entDetailResVo.setValid(isValid);
         return entDetailResVo;
     }
 
@@ -1282,18 +1284,24 @@ public class KwsEnterpriseService {
 
         //企业资质有效性判断  1、当前资质没过期,且状态是已认证  2、只要有认证过一次就算有效  参数判断
         String checkType = String.valueOf(Global.NUMERICAL_TWO);
+        entCacheResDto.setValid(false); // 设置默认值
         if (checkType.equals(Global.NUMERICAL_ONE)) {
             List<CertificateResVo> certificates = queryCertificate(entId);
-            for (CertificateResVo certificate : certificates) {
-                Date expireTime = certificate.getExpireTime();
-                entCacheResDto.setValid(DateUtil.compare(new Date(), expireTime) <= 0);
+            if (CollectionUtils.isNotEmpty(certificates)) {
+                // 只要有一个证书有效,则企业有效
+                boolean hasValidCertificate = certificates.stream()
+                        .filter(cert -> cert.getExpireTime() != null)
+                        .anyMatch(certificate -> DateUtil.compare(new Date(), certificate.getExpireTime()) <= 0);
+                entCacheResDto.setValid(hasValidCertificate);
             }
         } else {
             List<KwsEntCheckTrack> entCheckTrackResDtoList = entCheck(entId);
-            if (CollectionUtils.isEmpty(entCheckTrackResDtoList)) {
-                entCacheResDto.setValid(false);
+            if (CollectionUtils.isNotEmpty(entCheckTrackResDtoList)) {
+                boolean hasApprovedRecord = entCheckTrackResDtoList.stream()
+                        .filter(item -> item.getStatus() != null)
+                        .anyMatch(item -> item.getStatus() == Global.NO);
+                entCacheResDto.setValid(hasApprovedRecord);
             }
-            entCacheResDto.setValid(entCheckTrackResDtoList.stream().anyMatch(item -> item.getStatus() == Global.NO));
         }
 
         return entCacheResDto;