|
|
@ -1,9 +1,13 @@ |
|
|
|
package com.zc.business.task; |
|
|
|
|
|
|
|
import cn.hutool.core.date.DateTime; |
|
|
|
import cn.hutool.core.date.DateUtil; |
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
import com.alibaba.fastjson.JSONArray; |
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper; |
|
|
|
import com.ruoyi.common.core.domain.AjaxResult; |
|
|
|
import com.ruoyi.common.core.redis.RedisCache; |
|
|
|
import com.ruoyi.common.utils.uuid.IdUtils; |
|
|
|
import com.ruoyi.system.service.ISysConfigService; |
|
|
|
import com.zc.business.controller.DcNmcController; |
|
|
@ -14,16 +18,26 @@ 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 okhttp3.Response; |
|
|
|
import okhttp3.ResponseBody; |
|
|
|
import io.swagger.annotations.ApiParam; |
|
|
|
import okhttp3.*; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.scheduling.annotation.Scheduled; |
|
|
|
import org.springframework.stereotype.Component; |
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.Map; |
|
|
|
import java.io.BufferedReader; |
|
|
|
import java.io.ByteArrayInputStream; |
|
|
|
import java.io.IOException; |
|
|
|
import java.io.InputStreamReader; |
|
|
|
import java.nio.charset.StandardCharsets; |
|
|
|
import java.time.LocalDate; |
|
|
|
import java.time.LocalDateTime; |
|
|
|
import java.time.ZoneId; |
|
|
|
import java.time.format.DateTimeFormatter; |
|
|
|
import java.util.*; |
|
|
|
import java.util.zip.GZIPInputStream; |
|
|
|
|
|
|
|
/** |
|
|
|
* 外部接口监控 |
|
|
@ -33,7 +47,9 @@ public class ExternalInterfaceMonitoringTask { |
|
|
|
|
|
|
|
@Resource |
|
|
|
private ExternalInterfaceMonitoringMapper externalInterfaceMonitoringMapper; |
|
|
|
|
|
|
|
@Resource |
|
|
|
private RedisCache redisCache; |
|
|
|
public static final MediaType JSO= MediaType.get("application/json; charset=utf-8"); |
|
|
|
@Resource |
|
|
|
private WeatherForecastController weatherForecastController; |
|
|
|
|
|
|
@ -53,8 +69,22 @@ public class ExternalInterfaceMonitoringTask { |
|
|
|
dcTrafficStatisticsCurrency(UniversalEnum.GETS_THE_URI_OF_THE_CURRENT_CONGESTION_EVENT.getValue(), |
|
|
|
"获取当前拥堵事件信息"); |
|
|
|
// 交通流 - 获取车道占有率信息 ------------- 有起始桩号、结束桩号
|
|
|
|
dcTrafficStatisticsCurrencyVehicle(UniversalEnum.GETS_THE_LANE_OCCUPANCY_URI.getValue(),"获取车道占有率信息"); |
|
|
|
|
|
|
|
// 交通流 - 获取门架指标数据 ------------- 有开始时间、结束时间
|
|
|
|
obtainTheShelfIndicatorData(UniversalEnum.OBTAIN_THE_SHELF_INDICATOR_DATA.getValue(),"获取门架指标数据"); |
|
|
|
|
|
|
|
// 交通流 - 断面小时车流量分车型 ------------ 有开始时间、结束时间
|
|
|
|
dcTrafficStatisticsCurrencyVehicle(UniversalEnum.SECTION_HOURLY_TRAFFIC_FLOW_BY_VEHICLE_TYPE.getValue(),"断面小时车流量分车型"); |
|
|
|
// 交通流 - 各收费站入口分车型 ------------ 有开始时间、结束时间 ,出入口 1,2
|
|
|
|
dcTrafficStatisticsCurrencyTollStation(UniversalEnum.EACH_TOLL_STATION_ENTRANCE_BY_TYPE_OF_HOURLY_TRAFFIC_FLOW.getValue(),"各收费站入口分车型",UniversalEnum.ONE.getValue()); |
|
|
|
//边坡数据 获取边坡测点列表
|
|
|
|
Response response = getMeasurePointList(); |
|
|
|
getMeasure(response,"获取边坡测点列表"); |
|
|
|
//获取边坡历史数据
|
|
|
|
|
|
|
|
Response response1 = GetPointDataListAsync(); |
|
|
|
getMeasure(response1,"获取边坡历史数据"); |
|
|
|
|
|
|
|
// 全国气象数据 - 雷达数据
|
|
|
|
getRadarData(); |
|
|
@ -69,6 +99,43 @@ public class ExternalInterfaceMonitoringTask { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
private void getMeasure(Response response, String operationName) throws Exception { |
|
|
|
// 构造
|
|
|
|
ExternalInterfaceMonitoring externalInterfaceMonitoring = new ExternalInterfaceMonitoring(); |
|
|
|
externalInterfaceMonitoring.setInterfaceOwnership(InterfaceOwnershipEnum.SIDE_SLOPE.getCode()); |
|
|
|
externalInterfaceMonitoring.setInterfaceName(operationName); |
|
|
|
// 插入
|
|
|
|
insertIntoExternalInterface(externalInterfaceMonitoring, response); |
|
|
|
} |
|
|
|
//获取边坡历史数据
|
|
|
|
private Response getMeasurePointList() throws HttpException, IOException { |
|
|
|
JSONObject jsonResult = null; |
|
|
|
OkHttp okHttp = new OkHttp(); |
|
|
|
|
|
|
|
RequestParams requestParams = new RequestParams(); |
|
|
|
requestParams.put("proCode", configService.selectConfigByKey("proCode")); |
|
|
|
requestParams.put("unitCode", configService.selectConfigByKey("unitCode")); |
|
|
|
|
|
|
|
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秒
|
|
|
|
} |
|
|
|
|
|
|
|
// http://jsgl.sdgsbim.com:8616/api/RoadMajorPlatform/GetMeasurePointList?proCode=JHGKJ&unitCode=60-01.0002.00.00
|
|
|
|
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; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 交通流通用 |
|
|
|
*/ |
|
|
@ -90,6 +157,107 @@ public class ExternalInterfaceMonitoringTask { |
|
|
|
// 插入
|
|
|
|
insertIntoExternalInterface(externalInterfaceMonitoring,response); |
|
|
|
} |
|
|
|
//车辆
|
|
|
|
public void dcTrafficStatisticsCurrencyVehicle(String path, String operationName) throws Exception { |
|
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(UniversalEnum.TIME_FORMAT_YEARS_MONTH_DAY.getValue()); |
|
|
|
LocalDate currentDate = LocalDate.now(); |
|
|
|
String nowYear = currentDate.format(formatter); |
|
|
|
// 参数
|
|
|
|
RequestParams requestParams = new RequestParams(); |
|
|
|
|
|
|
|
requestParams.put("sysid", UniversalEnum.SYS_ID.getValue()); |
|
|
|
|
|
|
|
JSONObject parameters = new JSONObject() { |
|
|
|
{ |
|
|
|
put("start_date", nowYear); |
|
|
|
put("end_date", nowYear); |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
requestParams.put("parameters", parameters.toJSONString()); |
|
|
|
|
|
|
|
Map<String, String> headers = new HashMap<>(); |
|
|
|
headers.put("Authorization", DcTrafficStatisticsServiceImpl.getAccessToken()); |
|
|
|
String url = UniversalEnum.DATA_CENTER_TRAFFIC_STATISTICS_IP_PORT.getValue() + path; |
|
|
|
// 请求
|
|
|
|
Response response = postRequestByHeadersAndParams(headers, url, requestParams); |
|
|
|
// 构造
|
|
|
|
ExternalInterfaceMonitoring externalInterfaceMonitoring = new ExternalInterfaceMonitoring(); |
|
|
|
externalInterfaceMonitoring.setInterfaceOwnership(InterfaceOwnershipEnum.TRAFFIC_FLOW.getCode()); |
|
|
|
externalInterfaceMonitoring.setInterfaceName(operationName); |
|
|
|
// 插入
|
|
|
|
insertIntoExternalInterface(externalInterfaceMonitoring,response); |
|
|
|
} |
|
|
|
//获取门架指标数据
|
|
|
|
public void obtainTheShelfIndicatorData(String path, String operationName) throws Exception { |
|
|
|
// 计算一小时前的时间点
|
|
|
|
DateTime lastHour = DateUtil.offsetHour(new Date(), UniversalEnum.MINUS_ONE.getNumber()); |
|
|
|
|
|
|
|
String startTime = DateUtil.beginOfHour(lastHour).toString(); |
|
|
|
String endTime = DateUtil.endOfHour(lastHour).toString(); |
|
|
|
OkHttp okHttp = new OkHttp(); |
|
|
|
|
|
|
|
RequestParams requestParams = new RequestParams(); |
|
|
|
|
|
|
|
requestParams.put("sysid", UniversalEnum.SYS_ID.getValue()); |
|
|
|
|
|
|
|
JSONObject parameters = new JSONObject() { |
|
|
|
{ |
|
|
|
put("start_time", startTime); |
|
|
|
put("end_time", endTime); |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
requestParams.put("parameters", parameters.toJSONString()); |
|
|
|
|
|
|
|
Map<String, String> headers = new HashMap<>(); |
|
|
|
headers.put("Authorization", DcTrafficStatisticsServiceImpl.getAccessToken()); |
|
|
|
|
|
|
|
Response response // 请求响应
|
|
|
|
= okHttp |
|
|
|
.headers(headers) |
|
|
|
.url(UniversalEnum.DATA_CENTER_TRAFFIC_STATISTICS_IP_PORT.getValue() + path) // 请求地址
|
|
|
|
.data(requestParams) // 请求参数
|
|
|
|
.post(); // 请求方法
|
|
|
|
// 构造
|
|
|
|
ExternalInterfaceMonitoring externalInterfaceMonitoring = new ExternalInterfaceMonitoring(); |
|
|
|
externalInterfaceMonitoring.setInterfaceOwnership(InterfaceOwnershipEnum.TRAFFIC_FLOW.getCode()); |
|
|
|
externalInterfaceMonitoring.setInterfaceName(operationName); |
|
|
|
// 插入
|
|
|
|
insertIntoExternalInterface(externalInterfaceMonitoring,response); |
|
|
|
} |
|
|
|
//收费站 TollStation
|
|
|
|
public void dcTrafficStatisticsCurrencyTollStation(String path, String operationName, String stationType) throws Exception { |
|
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(UniversalEnum.TIME_FORMAT_YEARS_MONTH_DAY.getValue()); |
|
|
|
LocalDate currentDate = LocalDate.now(); |
|
|
|
String nowYear = currentDate.format(formatter); |
|
|
|
// 参数
|
|
|
|
RequestParams requestParams = new RequestParams(); |
|
|
|
|
|
|
|
requestParams.put("sysid", UniversalEnum.SYS_ID.getValue()); |
|
|
|
|
|
|
|
JSONObject parameters = new JSONObject() { |
|
|
|
{ |
|
|
|
put("start_date", nowYear); |
|
|
|
put("end_date", nowYear); |
|
|
|
put("station_type", stationType); |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
requestParams.put("parameters", parameters.toJSONString()); |
|
|
|
|
|
|
|
Map<String, String> headers = new HashMap<>(); |
|
|
|
headers.put("Authorization", DcTrafficStatisticsServiceImpl.getAccessToken()); |
|
|
|
String url = UniversalEnum.DATA_CENTER_TRAFFIC_STATISTICS_IP_PORT.getValue() + path; |
|
|
|
// 请求
|
|
|
|
Response response = postRequestByHeadersAndParams(headers, url, requestParams); |
|
|
|
// 构造
|
|
|
|
ExternalInterfaceMonitoring externalInterfaceMonitoring = new ExternalInterfaceMonitoring(); |
|
|
|
externalInterfaceMonitoring.setInterfaceOwnership(InterfaceOwnershipEnum.TRAFFIC_FLOW.getCode()); |
|
|
|
externalInterfaceMonitoring.setInterfaceName(operationName); |
|
|
|
// 插入
|
|
|
|
insertIntoExternalInterface(externalInterfaceMonitoring,response); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 全国气象数据 - 雷达数据 |
|
|
@ -233,4 +401,141 @@ public class ExternalInterfaceMonitoringTask { |
|
|
|
externalInterfaceMonitoring.setOperationResult(ajaxResult.get("msg").toString()); |
|
|
|
} |
|
|
|
} |
|
|
|
//边坡获取token
|
|
|
|
public JSONObject authenticate() throws IOException { |
|
|
|
OkHttpClient client = new OkHttpClient(); |
|
|
|
|
|
|
|
// 构造请求体
|
|
|
|
Map<String, String> map = new LinkedHashMap<>(); |
|
|
|
map.put("UserNameOrEmailAddress", configService.selectConfigByKey("UserNameOrEmailAddress"));//用户名
|
|
|
|
map.put("Password", configService.selectConfigByKey("Password"));//登录密码
|
|
|
|
ObjectMapper objectMapper = new ObjectMapper(); |
|
|
|
String jsonInput = objectMapper.writeValueAsString(map); |
|
|
|
RequestBody requestBody = RequestBody.create(JSO, jsonInput); |
|
|
|
|
|
|
|
// 创建请求
|
|
|
|
Request request = new Request.Builder() |
|
|
|
.url(configService.selectConfigByKey("accessTokenApi")) |
|
|
|
.post(requestBody) |
|
|
|
.build(); |
|
|
|
|
|
|
|
// 发送请求并处理响应
|
|
|
|
try (Response response = client.newCall(request).execute()) { |
|
|
|
if (!response.isSuccessful()) { |
|
|
|
throw new IOException("Unexpected code " + response); |
|
|
|
} |
|
|
|
// 正确解析响应体中的JSON数据
|
|
|
|
String responseBody = response.body().string(); |
|
|
|
JSONObject jsonResult = JSONObject.parseObject(responseBody); |
|
|
|
return jsonResult; |
|
|
|
} |
|
|
|
} |
|
|
|
//获取边坡测点列表
|
|
|
|
public Response GetMeasurePointList() throws IOException, HttpException { |
|
|
|
JSONObject jsonResult = null; |
|
|
|
OkHttp okHttp = new OkHttp(); |
|
|
|
|
|
|
|
RequestParams requestParams = new RequestParams(); |
|
|
|
requestParams.put("proCode", configService.selectConfigByKey("proCode")); |
|
|
|
requestParams.put("unitCode", configService.selectConfigByKey("unitCode")); |
|
|
|
|
|
|
|
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秒
|
|
|
|
} |
|
|
|
|
|
|
|
// http://jsgl.sdgsbim.com:8616/api/RoadMajorPlatform/GetMeasurePointList?proCode=JHGKJ&unitCode=60-01.0002.00.00
|
|
|
|
Map<String, String> header = new HashMap<>(); |
|
|
|
header.put("Authorization", "Bearer "+accessToken.toString()); |
|
|
|
Response response // 请求响应
|
|
|
|
= okHttp |
|
|
|
.headers(header) |
|
|
|
.url(configService.selectConfigByKey("GetMeasurePointListAPI")) // 请求地址
|
|
|
|
.data(requestParams) // 请求参数
|
|
|
|
.get(); // 请求方法
|
|
|
|
|
|
|
|
// 正确解析响应体中的JSON数据
|
|
|
|
return response ; |
|
|
|
} |
|
|
|
public Response GetPointDataListAsync() throws IOException, HttpException { |
|
|
|
//今天零点的时间戳
|
|
|
|
long todayStartTimestamp = getTodayStartTimestamp(); |
|
|
|
// 获取当前时间的时间戳(毫秒数)
|
|
|
|
long currentTimestamp = getCurrentTimestamp(); |
|
|
|
|
|
|
|
JSONObject jsonResult = null; |
|
|
|
JSONArray jsonArray = null; |
|
|
|
OkHttp okHttp = new OkHttp(); |
|
|
|
|
|
|
|
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秒
|
|
|
|
} |
|
|
|
|
|
|
|
// http://jsgl.sdgsbim.com:8616/api/RoadMajorPlatform/GetMeasurePointList?proCode=JHGKJ&unitCode=60-01.0002.00.00
|
|
|
|
Map<String, String> header = new HashMap<>(); |
|
|
|
header.put("Authorization", "Bearer "+accessToken.toString()); |
|
|
|
Response response // 请求响应
|
|
|
|
= okHttp |
|
|
|
.headers(header) |
|
|
|
.url(configService.selectConfigByKey("GetPointDataListAsyncAPI")) // 请求地址
|
|
|
|
.data(requestParams) // 请求参数
|
|
|
|
.get(); // 请求方法
|
|
|
|
|
|
|
|
/* if (response.body() != null) { |
|
|
|
jsonResult = JSONObject.parseObject(response.body().string()); |
|
|
|
String jsonObjec =jsonResult.getString("result").replace("\r\n", UniversalEnum.EMPTY_STRING.getValue()); |
|
|
|
jsonArray = extracted(jsonObjec); |
|
|
|
}*/ |
|
|
|
// 正确解析响应体中的JSON数据
|
|
|
|
return response; |
|
|
|
} |
|
|
|
/** |
|
|
|
* Base64解码 |
|
|
|
*/ |
|
|
|
private JSONArray extracted(String base64EncodedCompressedData) throws IOException { |
|
|
|
// Base64解码
|
|
|
|
byte[] compressedData = Base64.getDecoder().decode(base64EncodedCompressedData); |
|
|
|
StringBuilder output = new StringBuilder(); |
|
|
|
// 解压缩
|
|
|
|
try (ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(compressedData); |
|
|
|
GZIPInputStream gzipInputStream = new GZIPInputStream(byteArrayInputStream); |
|
|
|
InputStreamReader inputStreamReader = new InputStreamReader(gzipInputStream, StandardCharsets.UTF_8); |
|
|
|
BufferedReader bufferedReader = new BufferedReader(inputStreamReader)) { |
|
|
|
|
|
|
|
String line; |
|
|
|
while ((line = bufferedReader.readLine()) != null) { |
|
|
|
output.append(line); |
|
|
|
} |
|
|
|
} |
|
|
|
// 将StringBuilder转换为字符串
|
|
|
|
String jsonString = output.toString(); |
|
|
|
// 将字符串转换为JSONObject
|
|
|
|
JSONArray jsonObject = JSONArray.parseArray(jsonString); |
|
|
|
return jsonObject; |
|
|
|
} |
|
|
|
// 获取今天零点的时间戳(毫秒数)
|
|
|
|
public static long getTodayStartTimestamp() { |
|
|
|
LocalDate today = LocalDate.now(); |
|
|
|
LocalDateTime todayStart = today.atStartOfDay(); |
|
|
|
return todayStart.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli(); |
|
|
|
} |
|
|
|
|
|
|
|
// 获取当前时间的时间戳(毫秒数)
|
|
|
|
public static long getCurrentTimestamp() { |
|
|
|
return System.currentTimeMillis(); |
|
|
|
} |
|
|
|
} |
|
|
|