Browse Source

远程调用失败结果统一处理方法类

gaodm 6 years ago
parent
commit
c2e8e468e5

+ 44 - 4
common/src/main/java/com/diagbot/util/RespDTOUtil.java

@@ -2,6 +2,7 @@ package com.diagbot.util;
 
 import com.diagbot.dto.RespDTO;
 import com.diagbot.exception.CommonErrorCode;
+import com.diagbot.exception.CommonException;
 
 /**
  * @Description: 结果验证工具类
@@ -12,11 +13,12 @@ public class RespDTOUtil {
 
     /**
      * 远程调度是否成功
+     *
      * @param respDTO 返回结果
-     * @param <T> 泛型
+     * @param <T>     泛型
      * @return 是否成功
      */
-    public static <T> boolean respIsOK(RespDTO<T> respDTO){
+    public static <T> boolean respIsOK(RespDTO<T> respDTO) {
         if (null == respDTO
                 || null == respDTO.data
                 || !CommonErrorCode.OK.getCode().equals(respDTO.code)) {
@@ -28,11 +30,12 @@ public class RespDTOUtil {
 
     /**
      * 远程调度是否不成功
+     *
      * @param respDTO 返回结果
-     * @param <T> 泛型
+     * @param <T>     泛型
      * @return 是否成功
      */
-    public static <T> boolean respIsNG(RespDTO<T> respDTO){
+    public static <T> boolean respIsNG(RespDTO<T> respDTO) {
         if (null == respDTO
                 || null == respDTO.data
                 || !CommonErrorCode.OK.getCode().equals(respDTO.code)) {
@@ -40,4 +43,41 @@ public class RespDTOUtil {
         }
         return false;
     }
+
+
+    /**
+     * 远程调度不成功错误处理(错误不直接覆盖)
+     *
+     * @param respDTO 返回结果
+     * @param errmsg  错误信息
+     * @param <T>     泛型
+     */
+    public static <T> void respNGDeal(RespDTO<T> respDTO, String errmsg) {
+        respNGDeal(respDTO, false,errmsg);
+    }
+
+    /**
+     * 远程调度不成功错误处理(错误直接覆盖)
+     *
+     * @param respDTO 返回结果
+     * @param errmsg  错误信息
+     * @param <T>     泛型
+     */
+    public static <T> void respNGDealCover(RespDTO<T> respDTO, String errmsg) {
+        respNGDeal(respDTO, true,errmsg);
+    }
+
+
+    private static <T> void respNGDeal(RespDTO<T> respDTO, Boolean isCover, String errmsg) {
+        if (null == respDTO
+                || null == respDTO.data
+                || !CommonErrorCode.OK.getCode().equals(respDTO.code)) {
+            if (!isCover){
+                if (StringUtil.isNotBlank(respDTO.msg)) {
+                    throw new CommonException(CommonErrorCode.RPC_ERROR, respDTO.msg);
+                }
+            }
+            throw new CommonException(CommonErrorCode.RPC_ERROR, errmsg);
+        }
+    }
 }

+ 1 - 5
icss-service/src/main/java/com/diagbot/facade/DisScaleFacade.java

@@ -3,8 +3,6 @@ package com.diagbot.facade;
 import com.diagbot.client.AiptServiceClient;
 import com.diagbot.dto.DisScaleDTO;
 import com.diagbot.dto.RespDTO;
-import com.diagbot.exception.CommonErrorCode;
-import com.diagbot.exception.CommonException;
 import com.diagbot.service.impl.DisScaleServiceImpl;
 import com.diagbot.util.RespDTOUtil;
 import com.diagbot.vo.DisScaleVO;
@@ -32,9 +30,7 @@ public class DisScaleFacade extends DisScaleServiceImpl {
      */
     public List<DisScaleDTO> getDisScaleFac(DisScaleVO disScaleVO) {
         RespDTO<List<DisScaleDTO>> res = aiptServiceClient.getList(disScaleVO);
-        if (RespDTOUtil.respIsNG(res)) {
-            throw new CommonException(CommonErrorCode.RPC_ERROR, "远程调用诊断量表列表失败");
-        }
+        RespDTOUtil.respNGDeal(res, "远程调用诊断量表列表失败");
         return res.data;
     }
 }