Browse Source

机构类型

TRX 1 year ago
parent
commit
3fa2587d53

+ 9 - 9
FullCardServer/src/main/java/com/zhongshu/card/server/core/httpRequest/ApiRequestService.java

@@ -41,14 +41,14 @@ public class ApiRequestService extends SuperService {
             responseModel.setIsFailed("未配置物联网平台URL");
             return responseModel;
         }
+        ApiConfParam apiConfParam = IotCenterAPIConfig.getApiConfParam(apiName);
+        if (ObjectUtils.isEmpty(apiConfParam)) {
+            responseModel.setIsFailed("未找到API配置");
+            return responseModel;
+        }
+        StopWatch stopWatch = new StopWatch();
+        stopWatch.start();
         try {
-            ApiConfParam apiConfParam = IotCenterAPIConfig.getApiConfParam(apiName);
-            if (ObjectUtils.isEmpty(apiConfParam)) {
-                responseModel.setIsFailed("未找到API配置");
-                return responseModel;
-            }
-            StopWatch stopWatch = new StopWatch();
-            stopWatch.start();
             String json = JSONUtil.toJsonStr(data);
             String url = iotCenterConf.getUrl() + apiConfParam.getApiName();
             ResponseModel request = HttpClientUtil.request(HttpModel.builder()
@@ -59,13 +59,13 @@ public class ApiRequestService extends SuperService {
                 responseModel = BeanUtil.copyProperties(request.getBody(), APIResponseModel.class);
             }
             responseModel.setParam(apiConfParam);
-            stopWatch.stop();
-            responseModel.setMillis(stopWatch.getTotalTimeMillis());
         } catch (Exception e) {
             e.printStackTrace();
             responseModel.setIsFailed(String.format("请求出错:%s", e.getMessage()));
             return responseModel;
         }
+        stopWatch.stop();
+        responseModel.setMillis(stopWatch.getTotalTimeMillis());
         return responseModel;
     }