Kaynağa Gözat

同步服务 修改

zhanghao 1 ay önce
ebeveyn
işleme
6d83053d89

+ 3 - 14
src/main/java/com/sckj/project/service/task/BuildingTaskService.java

@@ -35,23 +35,12 @@ public class BuildingTaskService {
     @Autowired
     private HttpRequestUtil httpRequestUtil;
 
-    public JSONArray callExternalApi(String url) {
-        try {
-            ResponseEntity<String> response = httpRequestUtil.get(url);
-            if (StringUtils.isEmpty(response.getBody())){
-                return null;
-            }
-            return JSONUtil.parseObj(response.getBody()).getJSONArray("data");
-        } catch (RestClientException e) {
-            return null;
-        }
-    }
 
     public void myTask(){
 
         /*楼宇表*/
         try {
-            JSONArray array = callExternalApi(ApiUrlConfig.getBuildingUrl());
+            JSONArray array = httpRequestUtil.callExternalApi(ApiUrlConfig.getBuildingUrl());
             if (array == null){
                 return;
             }
@@ -67,7 +56,7 @@ public class BuildingTaskService {
 
         /*楼宇中控*/
         try {
-            JSONArray array = callExternalApi(ApiUrlConfig.getBuildingControlUrl());
+            JSONArray array = httpRequestUtil.callExternalApi(ApiUrlConfig.getBuildingControlUrl());
             if (array == null){
                 return;
             }
@@ -83,7 +72,7 @@ public class BuildingTaskService {
 
         /*楼宇中控电表明细表*/
         try {
-            JSONArray array = callExternalApi(ApiUrlConfig.getBuildingAmmeterDetailUrl());
+            JSONArray array = httpRequestUtil.callExternalApi(ApiUrlConfig.getBuildingAmmeterDetailUrl());
             if (array == null){
                 return;
             }

+ 4 - 16
src/main/java/com/sckj/project/service/task/CarTaskService.java

@@ -39,26 +39,14 @@ public class CarTaskService {
     @Autowired
     private HttpRequestUtil httpRequestUtil;
 
-    public JSONArray callExternalApi(String url) {
-        try {
-            ResponseEntity<String> response = httpRequestUtil.get(url);
-            if (StringUtils.isEmpty(response.getBody())){
-                return null;
-            }
-            return JSONUtil.parseObj(response.getBody()).getJSONArray("data");
-        } catch (RestClientException e) {
-            return null;
-        }
-    }
-
     public void myTask(){
 
         /*公务用车表*/
-        largeCarService.saveOrUpdate(callExternalApi(ApiUrlConfig.getCarUrl()));
+        largeCarService.saveOrUpdate(httpRequestUtil.callExternalApi(ApiUrlConfig.getCarUrl()));
 
         /*公务用车年度增加减少表*/
         try {
-            JSONArray array = callExternalApi(ApiUrlConfig.getCarChangeUrl());
+            JSONArray array = httpRequestUtil.callExternalApi(ApiUrlConfig.getCarChangeUrl());
             if (array == null){
                 return;
             }
@@ -74,7 +62,7 @@ public class CarTaskService {
 
         /*公务用车预警明细表*/
         try {
-            JSONArray array = callExternalApi(ApiUrlConfig.getCarWarnUrl());
+            JSONArray array = httpRequestUtil.callExternalApi(ApiUrlConfig.getCarWarnUrl());
             if (array == null){
                 return;
             }
@@ -90,7 +78,7 @@ public class CarTaskService {
 
         /*公务用车单车活跃排名表*/
         try {
-            JSONArray array = callExternalApi(ApiUrlConfig.getCarRankUrl());
+            JSONArray array = httpRequestUtil.callExternalApi(ApiUrlConfig.getCarRankUrl());
             if (array == null){
                 return;
             }

+ 3 - 14
src/main/java/com/sckj/project/service/task/EngineeringTaskService.java

@@ -36,23 +36,12 @@ public class EngineeringTaskService {
     @Autowired
     private HttpRequestUtil httpRequestUtil;
 
-    public JSONArray callExternalApi(String url) {
-        try {
-            ResponseEntity<String> response = httpRequestUtil.get(url);
-            if (StringUtils.isEmpty(response.getBody())){
-                return null;
-            }
-            return JSONUtil.parseObj(response.getBody()).getJSONArray("data");
-        } catch (RestClientException e) {
-            return null;
-        }
-    }
 
     public void myTask(){
 
         /*监控表*/
         try {
-            JSONArray array = callExternalApi(ApiUrlConfig.getEngineerCameraUrl());
+            JSONArray array = httpRequestUtil.callExternalApi(ApiUrlConfig.getEngineerCameraUrl());
             if (array == null){
                 return;
             }
@@ -68,7 +57,7 @@ public class EngineeringTaskService {
 
         /*上报问题表*/
         try {
-            JSONArray array = callExternalApi(ApiUrlConfig.getEngineerIssueUrl());
+            JSONArray array = httpRequestUtil.callExternalApi(ApiUrlConfig.getEngineerIssueUrl());
             if (array == null){
                 return;
             }
@@ -84,7 +73,7 @@ public class EngineeringTaskService {
 
         /*项目表*/
         try {
-            JSONArray array = callExternalApi(ApiUrlConfig.getEngineerProjectUrl());
+            JSONArray array = httpRequestUtil.callExternalApi(ApiUrlConfig.getEngineerProjectUrl());
             if (array == null){
                 return;
             }

+ 6 - 16
src/main/java/com/sckj/project/service/task/LogisticsTaskService.java

@@ -40,23 +40,13 @@ public class LogisticsTaskService {
     @Autowired
     private HttpRequestUtil httpRequestUtil;
 
-    public JSONArray callExternalApi(String url) {
-        try {
-            ResponseEntity<String> response = httpRequestUtil.get(url);
-            if (StringUtils.isEmpty(response.getBody())){
-                return null;
-            }
-            return JSONUtil.parseObj(response.getBody()).getJSONArray("data");
-        } catch (RestClientException e) {
-            return null;
-        }
-    }
+
 
     public void myTask(){
 
         /*房产土地表*/
         try {
-            JSONArray array = callExternalApi(ApiUrlConfig.getLogisticsHousingUrl());
+            JSONArray array = httpRequestUtil.callExternalApi(ApiUrlConfig.getLogisticsHousingUrl());
             if (array == null){
                 return;
             }
@@ -71,11 +61,11 @@ public class LogisticsTaskService {
         }
 
         /*后勤运行监控中心表*/
-        largePlatLogisticsService.saveOrUpdate(callExternalApi(ApiUrlConfig.getLogisticsUrl()));
+        largePlatLogisticsService.saveOrUpdate(httpRequestUtil.callExternalApi(ApiUrlConfig.getLogisticsUrl()));
 
         /*楼宇设备表*/
         try {
-            JSONArray array = callExternalApi(ApiUrlConfig.getLogisticsBuildingAssetUrl());
+            JSONArray array = httpRequestUtil.callExternalApi(ApiUrlConfig.getLogisticsBuildingAssetUrl());
             if (array == null){
                 return;
             }
@@ -91,7 +81,7 @@ public class LogisticsTaskService {
 
         /*办公资产表*/
         try {
-            JSONArray array = callExternalApi(ApiUrlConfig.getLogisticsOfficeAssetUrl());
+            JSONArray array = httpRequestUtil.callExternalApi(ApiUrlConfig.getLogisticsOfficeAssetUrl());
             if (array == null){
                 return;
             }
@@ -107,7 +97,7 @@ public class LogisticsTaskService {
 
         /*服务设备表*/
         try {
-            JSONArray array = callExternalApi(ApiUrlConfig.getLogisticsServiceAssetUrl());
+            JSONArray array = httpRequestUtil.callExternalApi(ApiUrlConfig.getLogisticsServiceAssetUrl());
             if (array == null){
                 return;
             }

+ 19 - 32
src/main/java/com/sckj/project/service/task/ServiceTaskService.java

@@ -79,36 +79,23 @@ public class ServiceTaskService {
     @Autowired
     private HttpRequestUtil httpRequestUtil;
 
-
-    public JSONArray callExternalApi(String url) {
-        try {
-            ResponseEntity<String> response = httpRequestUtil.get(url);
-            if (StringUtils.isEmpty(response.getBody())){
-                return null;
-            }
-            return JSONUtil.parseObj(response.getBody()).getJSONArray("data");
-        } catch (RestClientException e) {
-            return null;
-        }
-    }
-
     public void myTask(){
 
         /*便捷出入*/
-        largePlatAccessService.saveOrUpdate(callExternalApi(ApiUrlConfig.getAccessUrl()));
+        largePlatAccessService.saveOrUpdate(httpRequestUtil.callExternalApi(ApiUrlConfig.getAccessUrl()));
 
         /*基础运行数据*/
-        largePlatBasicsService.saveOrUpdate(callExternalApi(ApiUrlConfig.getBasicsApiUrl()));
+        largePlatBasicsService.saveOrUpdate(httpRequestUtil.callExternalApi(ApiUrlConfig.getBasicsApiUrl()));
 
         /*公司活跃人数*/
-        largePlatBasicsCompanyService.saveOrUpdate(callExternalApi(ApiUrlConfig.getBasicsCompanyUrl()));
+        largePlatBasicsCompanyService.saveOrUpdate(httpRequestUtil.callExternalApi(ApiUrlConfig.getBasicsCompanyUrl()));
 
         /*服务信息*/
-        largePlatBasicsServerService.saveOrUpdate(callExternalApi(ApiUrlConfig.getBasicsServerUrl()));
+        largePlatBasicsServerService.saveOrUpdate(httpRequestUtil.callExternalApi(ApiUrlConfig.getBasicsServerUrl()));
 
         /*系统运行峰值情况分析*/
         try {
-            JSONArray array = callExternalApi(ApiUrlConfig.getBasicsSystemUrl());
+            JSONArray array = httpRequestUtil.callExternalApi(ApiUrlConfig.getBasicsSystemUrl());
             if (array == null){
                 return;
             }
@@ -123,11 +110,11 @@ public class ServiceTaskService {
         }
 
         /*员工健康*/
-        largePlatEmployeeHealthService.saveOrUpdate(callExternalApi(ApiUrlConfig.getHealthUrl()));
+        largePlatEmployeeHealthService.saveOrUpdate(httpRequestUtil.callExternalApi(ApiUrlConfig.getHealthUrl()));
 
         /*多发疾病排行*/
         try {
-            JSONArray array = callExternalApi(ApiUrlConfig.getHealthIllnessUrl());
+            JSONArray array = httpRequestUtil.callExternalApi(ApiUrlConfig.getHealthIllnessUrl());
             if (array == null){
                 return;
             }
@@ -142,11 +129,11 @@ public class ServiceTaskService {
         }
 
         /*员工概况*/
-        largePlatEmployeeTypeService.saveOrUpdate(callExternalApi(ApiUrlConfig.getEmployeeTypeUrl()));
+        largePlatEmployeeTypeService.saveOrUpdate(httpRequestUtil.callExternalApi(ApiUrlConfig.getEmployeeTypeUrl()));
 
         /*近一周人流量统计*/
         try {
-            JSONArray array = callExternalApi(ApiUrlConfig.getEmployeeTypeFlowUrl());
+            JSONArray array = httpRequestUtil.callExternalApi(ApiUrlConfig.getEmployeeTypeFlowUrl());
             if (array == null){
                 return;
             }
@@ -161,17 +148,17 @@ public class ServiceTaskService {
         }
 
         /*菜谱数据*/
-        largePlatGreenFoodsService.saveOrUpdate(callExternalApi(ApiUrlConfig.getGreenFoodsUrl()));
+        largePlatGreenFoodsService.saveOrUpdate(httpRequestUtil.callExternalApi(ApiUrlConfig.getGreenFoodsUrl()));
 
         /*绿智食堂*/
-        largePlatGreenSmartService.saveOrUpdate(callExternalApi(ApiUrlConfig.getGreenSmartUrl()));
+        largePlatGreenSmartService.saveOrUpdate(httpRequestUtil.callExternalApi(ApiUrlConfig.getGreenSmartUrl()));
 
         /*绿智食堂 其他参数*/
-        largePlatGreenSmartOtherService.saveOrUpdate(callExternalApi(ApiUrlConfig.getGreenSmartOtherUrl()));
+        largePlatGreenSmartOtherService.saveOrUpdate(httpRequestUtil.callExternalApi(ApiUrlConfig.getGreenSmartOtherUrl()));
 
         /*绿智食堂 排名*/
         try {
-            JSONArray array = callExternalApi(ApiUrlConfig.getGreenSmartRankUrl());
+            JSONArray array = httpRequestUtil.callExternalApi(ApiUrlConfig.getGreenSmartRankUrl());
             if (array == null){
                 return;
             }
@@ -186,14 +173,14 @@ public class ServiceTaskService {
         }
 
         /*食堂安全管理*/
-        largePlatGreenSmartSafetyService.saveOrUpdate(callExternalApi(ApiUrlConfig.getGreenSmartSafetyUrl()));
+        largePlatGreenSmartSafetyService.saveOrUpdate(httpRequestUtil.callExternalApi(ApiUrlConfig.getGreenSmartSafetyUrl()));
 
         /*物业服务*/
-        largePlatPostStationService.saveOrUpdate(callExternalApi(ApiUrlConfig.getPostStationUrl()));
+        largePlatPostStationService.saveOrUpdate(httpRequestUtil.callExternalApi(ApiUrlConfig.getPostStationUrl()));
 
         /*近六个月报修分类占比*/
         try {
-            JSONArray array = callExternalApi(ApiUrlConfig.getPostStationChartUrl());
+            JSONArray array = httpRequestUtil.callExternalApi(ApiUrlConfig.getPostStationChartUrl());
             if (array == null){
                 return;
             }
@@ -208,13 +195,13 @@ public class ServiceTaskService {
         }
 
         /*共享驿站*/
-        largePlatPropertyService.saveOrUpdate(callExternalApi(ApiUrlConfig.getPropertyUrl()));
+        largePlatPropertyService.saveOrUpdate(httpRequestUtil.callExternalApi(ApiUrlConfig.getPropertyUrl()));
 
         /*驿站列表*/
-        largePlatPropertyListService.saveOrUpdate(callExternalApi(ApiUrlConfig.getPropertyListUrl()));
+        largePlatPropertyListService.saveOrUpdate(httpRequestUtil.callExternalApi(ApiUrlConfig.getPropertyListUrl()));
 
         /*工具表列表*/
-        largePlatPropertyToolsService.saveOrUpdate(callExternalApi(ApiUrlConfig.getPropertyToolsUrl()));
+        largePlatPropertyToolsService.saveOrUpdate(httpRequestUtil.callExternalApi(ApiUrlConfig.getPropertyToolsUrl()));
 
     }
 }

+ 17 - 6
src/main/java/com/sckj/project/util/HttpRequestUtil.java

@@ -1,12 +1,16 @@
 package com.sckj.project.util;
 
+import cn.hutool.json.JSONArray;
+import cn.hutool.json.JSONUtil;
 import com.sckj.project.constants.Constants;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.HttpEntity;
 import org.springframework.http.HttpHeaders;
 import org.springframework.http.HttpMethod;
 import org.springframework.http.ResponseEntity;
 import org.springframework.stereotype.Component;
+import org.springframework.web.client.RestClientException;
 import org.springframework.web.client.RestTemplate;
 
 /**
@@ -24,12 +28,19 @@ public class HttpRequestUtil {
     /**
      * 发送GET请求
      */
-    public ResponseEntity<String>  get(String url) {
-        HttpHeaders headers = new HttpHeaders();
-        headers.set(Constants.REQUEST_HEAD, AESUtil.encrypt(Constants.REQUEST_HEAD_SCR));
-        HttpEntity<String> entity = new HttpEntity<>(null, headers);
-        ResponseEntity<String> responseEntity = restTemplate.exchange(url, HttpMethod.GET, entity, String.class);
-        return responseEntity;
+    public JSONArray callExternalApi(String url) {
+        try {
+            HttpHeaders headers = new HttpHeaders();
+            headers.set(Constants.REQUEST_HEAD, AESUtil.encrypt(Constants.REQUEST_HEAD_SCR));
+            HttpEntity<String> entity = new HttpEntity<>(null, headers);
+            ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.GET, entity, String.class);
+            if (StringUtils.isEmpty(response.getBody()) || !response.getStatusCode().is2xxSuccessful()){
+                return null;
+            }
+            return JSONUtil.parseObj(response.getBody()).getJSONArray("data");
+        } catch (RestClientException e) {
+            return null;
+        }
     }
 
 }