Browse Source

修改外部接口监测-边坡接口异常处理

develop
Mr.Wang 4 months ago
parent
commit
c2046766ed
  1. 121
      zc-business/src/main/java/com/zc/business/task/ExternalInterfaceMonitoringTask.java

121
zc-business/src/main/java/com/zc/business/task/ExternalInterfaceMonitoringTask.java

@ -25,7 +25,6 @@ import com.zc.business.enums.UniversalEnum;
import com.zc.business.mapper.ExternalInterfaceMonitoringMapper;
import com.zc.business.service.impl.DcTrafficStatisticsServiceImpl;
import com.zc.common.core.httpclient.OkHttp;
import com.zc.common.core.httpclient.exception.HttpException;
import com.zc.common.core.httpclient.request.RequestParams;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@ -151,12 +150,11 @@ public class ExternalInterfaceMonitoringTask extends BaseController {
dcTrafficStatisticsCurrencyTollStation(UniversalEnum.EACH_TOLL_STATION_ENTRANCE_BY_TYPE_OF_HOURLY_TRAFFIC_FLOW.getValue(), "各收费站入口分车型", UniversalEnum.ONE.getValue());
//边坡数据 获取边坡测点列表
Response response = getMeasurePointList();
getMeasure(response, "获取边坡测点列表");
getMeasurePointList();
//获取边坡历史数据
Response response1 = GetPointDataListAsync();
getMeasure(response1, "获取边坡历史数据");
GetPointDataListAsync();
// 全国气象数据 - 雷达数据
getRadarData();
@ -194,30 +192,43 @@ public class ExternalInterfaceMonitoringTask extends BaseController {
}
//获取边坡历史数据
private Response getMeasurePointList() throws HttpException, IOException {
private void getMeasurePointList() {
OkHttp okHttp = new OkHttp();
RequestParams requestParams = new RequestParams();
requestParams.put("proCode", configService.selectConfigByKey("proCode"));
requestParams.put("unitCode", configService.selectConfigByKey("unitCode"));
try {
Object accessToken = redisCache.getCacheObject("accessToken");
if (accessToken == null) {
JSONObject authenticate = authenticate();
accessToken = authenticate.getJSONObject("result").getString("accessToken");
redisCache.setCacheObject("accessToken", accessToken);
redisCache.expire("accessToken", UniversalEnum.THREE.getNumber() * UniversalEnum.TWENTY_FOUR.getNumber() * UniversalEnum.THREE_THOUSAND_SIX_HUNDRED.getNumber());//设置过期时间s秒
}
Object accessToken = redisCache.getCacheObject("accessToken");
if (accessToken == null) {
JSONObject authenticate = authenticate();
accessToken = authenticate.getJSONObject("result").getString("accessToken");
redisCache.setCacheObject("accessToken", accessToken);
redisCache.expire("accessToken", UniversalEnum.THREE.getNumber() * UniversalEnum.TWENTY_FOUR.getNumber() * UniversalEnum.THREE_THOUSAND_SIX_HUNDRED.getNumber());//设置过期时间s秒
Map<String, String> header = new HashMap<>();
header.put("Authorization", "Bearer " + accessToken.toString());
Response response // 请求响应
= okHttp
.headers(header)
.url(configService.selectConfigByKey("GetMeasurePointListAPI")) // 请求地址
.data(requestParams) // 请求参数
.get(); // 请求方法
getMeasure(response, "获取边坡测点列表");
} catch (Exception e) {
ExternalInterfaceMonitoring externalInterfaceMonitoring = new ExternalInterfaceMonitoring();
externalInterfaceMonitoring.setOperationResult(e.getMessage());
externalInterfaceMonitoring.setOperationStatus(UniversalEnum.ZERO.getNumber());
externalInterfaceMonitoring.setId(IdUtils.fastSimpleUUID());
externalInterfaceMonitoring.setOperatorName("系统");
externalInterfaceMonitoring.setOperationTime(new Date());
externalInterfaceMonitoring.setInterfaceOwnership(InterfaceOwnershipEnum.SIDE_SLOPE.getCode());
externalInterfaceMonitoring.setInterfaceName("获取边坡测点列表");
externalInterfaceMonitoringMapper.insert(externalInterfaceMonitoring);
}
Map<String, String> header = new HashMap<>();
header.put("Authorization", "Bearer " + accessToken.toString());
Response response // 请求响应
= okHttp
.headers(header)
.url(configService.selectConfigByKey("GetMeasurePointListAPI")) // 请求地址
.data(requestParams) // 请求参数
.get(); // 请求方法
return response;
}
/**
@ -240,7 +251,7 @@ public class ExternalInterfaceMonitoringTask extends BaseController {
Response response = postRequestByHeadersAndParams(headers, url, requestParams);
// 插入
trafficFlowResultProcessing(externalInterfaceMonitoring, response);
}catch (Exception e) {
} catch (Exception e) {
externalInterfaceMonitoring.setOperationResult(e.getMessage());
externalInterfaceMonitoring.setOperationStatus(UniversalEnum.ZERO.getNumber());
externalInterfaceMonitoring.setId(IdUtils.fastSimpleUUID());
@ -413,7 +424,7 @@ public class ExternalInterfaceMonitoringTask extends BaseController {
} catch (Exception e) {
externalInterfaceMonitoring.setOperationResult(e.getMessage());
externalInterfaceMonitoring.setOperationStatus(UniversalEnum.ZERO.getNumber());
}finally {
} finally {
externalInterfaceMonitoring.setId(IdUtils.fastSimpleUUID());
externalInterfaceMonitoring.setOperatorName("系统");
externalInterfaceMonitoring.setOperationTime(new Date());
@ -471,7 +482,7 @@ public class ExternalInterfaceMonitoringTask extends BaseController {
} catch (Exception e) {
externalInterfaceMonitoring.setOperationResult(e.getMessage());
externalInterfaceMonitoring.setOperationStatus(UniversalEnum.ZERO.getNumber());
}finally {
} finally {
externalInterfaceMonitoringMapper.insert(externalInterfaceMonitoring);
}
}
@ -914,40 +925,50 @@ public class ExternalInterfaceMonitoringTask extends BaseController {
}
}
public Response GetPointDataListAsync() throws IOException, HttpException {
public void GetPointDataListAsync() {
//今天零点的时间戳
long todayStartTimestamp = getTodayStartTimestamp();
// 获取当前时间的时间戳(毫秒数)
long currentTimestamp = getCurrentTimestamp();
OkHttp okHttp = new OkHttp();
ExternalInterfaceMonitoring externalInterfaceMonitoring = new ExternalInterfaceMonitoring();
try {
RequestParams requestParams = new RequestParams();
requestParams.put("projCode", configService.selectConfigByKey("proCode"));//项目编号 如 JHGKJ
requestParams.put("unitCode", configService.selectConfigByKey("unitCode"));//项目单位工程编号 如 60-01.0002.00.00
requestParams.put("meaPointNum", "PR-YLJ01-067441-05/05");//测点编号如 PR-YLJ01-067441-05/05
requestParams.put("starttime", todayStartTimestamp);//开始时间如 1713369599000
requestParams.put("endtime", currentTimestamp);//结束时间 如 1713887999000
Object accessToken = redisCache.getCacheObject("accessToken");
if (accessToken == null) {
JSONObject authenticate = authenticate();
accessToken = authenticate.getJSONObject("result").getString("accessToken");
redisCache.setCacheObject("accessToken", accessToken);
redisCache.expire("accessToken", UniversalEnum.THREE.getNumber() * UniversalEnum.TWENTY_FOUR.getNumber() * UniversalEnum.THREE_THOUSAND_SIX_HUNDRED.getNumber());//设置过期时间s秒
}
RequestParams requestParams = new RequestParams();
requestParams.put("projCode", configService.selectConfigByKey("proCode"));//项目编号 如 JHGKJ
requestParams.put("unitCode", configService.selectConfigByKey("unitCode"));//项目单位工程编号 如 60-01.0002.00.00
requestParams.put("meaPointNum", "PR-YLJ01-067441-05/05");//测点编号如 PR-YLJ01-067441-05/05
requestParams.put("starttime", todayStartTimestamp);//开始时间如 1713369599000
requestParams.put("endtime", currentTimestamp);//结束时间 如 1713887999000
Object accessToken = redisCache.getCacheObject("accessToken");
if (accessToken == null) {
JSONObject authenticate = authenticate();
accessToken = authenticate.getJSONObject("result").getString("accessToken");
redisCache.setCacheObject("accessToken", accessToken);
redisCache.expire("accessToken", UniversalEnum.THREE.getNumber() * UniversalEnum.TWENTY_FOUR.getNumber() * UniversalEnum.THREE_THOUSAND_SIX_HUNDRED.getNumber());//设置过期时间s秒
}
Map<String, String> header = new HashMap<>();
header.put("Authorization", "Bearer " + accessToken.toString());
Map<String, String> header = new HashMap<>();
header.put("Authorization", "Bearer " + accessToken.toString());
Response response // 请求响应
= okHttp
.headers(header)
.url(configService.selectConfigByKey("GetPointDataListAsyncAPI")) // 请求地址
.data(requestParams) // 请求参数
.get(); // 请求方法
Response response // 请求响应
= okHttp
.headers(header)
.url(configService.selectConfigByKey("GetPointDataListAsyncAPI")) // 请求地址
.data(requestParams) // 请求参数
.get(); // 请求方法
getMeasure(response, "获取边坡历史数据");
} catch (Exception e) {
externalInterfaceMonitoring.setOperationResult(e.getMessage());
externalInterfaceMonitoring.setOperationStatus(UniversalEnum.ZERO.getNumber());
externalInterfaceMonitoring.setId(IdUtils.fastSimpleUUID());
externalInterfaceMonitoring.setOperatorName("系统");
externalInterfaceMonitoring.setOperationTime(new Date());
externalInterfaceMonitoring.setInterfaceOwnership(InterfaceOwnershipEnum.SIDE_SLOPE.getCode());
externalInterfaceMonitoring.setInterfaceName("获取边坡历史数据");
externalInterfaceMonitoringMapper.insert(externalInterfaceMonitoring);
}
// 正确解析响应体中的JSON数据
return response;
}
// 获取今天零点的时间戳(毫秒数)

Loading…
Cancel
Save