12 changed files with 335 additions and 10 deletions
@ -0,0 +1,46 @@ |
|||||
|
package com.zc.business.domain; |
||||
|
|
||||
|
import io.swagger.annotations.ApiModel; |
||||
|
import io.swagger.annotations.ApiModelProperty; |
||||
|
import lombok.AllArgsConstructor; |
||||
|
import lombok.Data; |
||||
|
import lombok.NoArgsConstructor; |
||||
|
|
||||
|
import java.util.Date; |
||||
|
|
||||
|
@ApiModel("外部接口监控实体") |
||||
|
@Data |
||||
|
@AllArgsConstructor |
||||
|
@NoArgsConstructor |
||||
|
public class ExternalInterfaceMonitoring { |
||||
|
|
||||
|
@ApiModelProperty("外部接口监控id") |
||||
|
private String id; |
||||
|
|
||||
|
/* |
||||
|
1 广播接口 |
||||
|
2 视频接口 |
||||
|
3 全国气象数据 |
||||
|
4 边坡数据接口 |
||||
|
5 天气预报接口 |
||||
|
6 交通流 |
||||
|
7 飞机预警接口 |
||||
|
*/ |
||||
|
@ApiModelProperty("接口所属") |
||||
|
private Integer interfaceOwnership; |
||||
|
|
||||
|
@ApiModelProperty("接口名称") |
||||
|
private String interfaceName; |
||||
|
|
||||
|
@ApiModelProperty("操作人") |
||||
|
private String operatorName; |
||||
|
|
||||
|
@ApiModelProperty("操作状态") |
||||
|
private Integer operationStatus; |
||||
|
|
||||
|
@ApiModelProperty("操作结果") |
||||
|
private String operationResult; |
||||
|
|
||||
|
@ApiModelProperty("操作时间") |
||||
|
private Date operationTime; |
||||
|
} |
@ -0,0 +1,29 @@ |
|||||
|
package com.zc.business.enums; |
||||
|
|
||||
|
/** |
||||
|
* 接口所属枚举 |
||||
|
*/ |
||||
|
public enum InterfaceOwnershipEnum { |
||||
|
RADIO_BROADCAST(1, "广播"), |
||||
|
VIDEO(2,"视频"), |
||||
|
NATIONAL_METEOROLOGY(3,"全国气象"), |
||||
|
SIDE_SLOPE(4,"边坡"), |
||||
|
WEATHER(5,"天气"), |
||||
|
TRAFFIC_FLOW(6,"交通流"); |
||||
|
private final Integer code; |
||||
|
private final String ownershipName; |
||||
|
|
||||
|
InterfaceOwnershipEnum(Integer code, String ownershipName) { |
||||
|
this.code = code; |
||||
|
this.ownershipName = ownershipName; |
||||
|
} |
||||
|
|
||||
|
public Integer getCode() |
||||
|
{ |
||||
|
return code; |
||||
|
} |
||||
|
|
||||
|
public String getOwnershipName() { |
||||
|
return ownershipName; |
||||
|
} |
||||
|
} |
@ -0,0 +1,14 @@ |
|||||
|
package com.zc.business.mapper; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
|
import com.zc.business.domain.ExternalInterfaceMonitoring; |
||||
|
import org.apache.ibatis.annotations.Mapper; |
||||
|
|
||||
|
/** |
||||
|
* 外部接口监控Mapper |
||||
|
* |
||||
|
*/ |
||||
|
@Mapper |
||||
|
public interface ExternalInterfaceMonitoringMapper extends BaseMapper<ExternalInterfaceMonitoring> { |
||||
|
|
||||
|
} |
@ -0,0 +1,236 @@ |
|||||
|
package com.zc.business.task; |
||||
|
|
||||
|
import com.alibaba.fastjson.JSON; |
||||
|
import com.alibaba.fastjson.JSONArray; |
||||
|
import com.alibaba.fastjson.JSONObject; |
||||
|
import com.ruoyi.common.core.domain.AjaxResult; |
||||
|
import com.ruoyi.common.utils.uuid.IdUtils; |
||||
|
import com.ruoyi.system.service.ISysConfigService; |
||||
|
import com.zc.business.controller.DcNmcController; |
||||
|
import com.zc.business.controller.WeatherForecastController; |
||||
|
import com.zc.business.domain.ExternalInterfaceMonitoring; |
||||
|
import com.zc.business.enums.InterfaceOwnershipEnum; |
||||
|
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.request.RequestParams; |
||||
|
import okhttp3.Response; |
||||
|
import okhttp3.ResponseBody; |
||||
|
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; |
||||
|
|
||||
|
/** |
||||
|
* 外部接口监控 |
||||
|
*/ |
||||
|
@Component |
||||
|
public class ExternalInterfaceMonitoringTask { |
||||
|
|
||||
|
@Resource |
||||
|
private ExternalInterfaceMonitoringMapper externalInterfaceMonitoringMapper; |
||||
|
|
||||
|
@Resource |
||||
|
private WeatherForecastController weatherForecastController; |
||||
|
|
||||
|
@Resource |
||||
|
private ISysConfigService configService; |
||||
|
|
||||
|
@Scheduled(cron = "0 0/15 * * * ?") |
||||
|
public void externalInterfaceDataMonitoring() throws Exception { |
||||
|
|
||||
|
// 交通流 - 获取在途车辆流量(分车型)
|
||||
|
dcTrafficStatisticsCurrency(UniversalEnum.GETS_THE_VEHICLE_TRAFFIC_URI_IN_TRANSIT.getValue(), |
||||
|
"获取在途车辆流量(分车型)"); |
||||
|
// 交通流 - 在途车路段门架平均车速
|
||||
|
dcTrafficStatisticsCurrency(UniversalEnum.AVERAGE_SPEED_URI_OF_GANTRY_IN_TRANSIT.getValue(), |
||||
|
"在途车路段门架平均车速"); |
||||
|
// 交通流 - 获取当前拥堵事件信息
|
||||
|
dcTrafficStatisticsCurrency(UniversalEnum.GETS_THE_URI_OF_THE_CURRENT_CONGESTION_EVENT.getValue(), |
||||
|
"获取当前拥堵事件信息"); |
||||
|
// 交通流 - 获取车道占有率信息 ------------- 有起始桩号、结束桩号
|
||||
|
// 交通流 - 获取门架指标数据 ------------- 有开始时间、结束时间
|
||||
|
// 交通流 - 断面小时车流量分车型 ------------ 有开始时间、结束时间
|
||||
|
|
||||
|
// 全国气象数据 - 雷达数据
|
||||
|
getRadarData(); |
||||
|
// 全国气象数据 - 雷达图
|
||||
|
getRadarChart(); |
||||
|
|
||||
|
// 天气预报 - 当前气象及预报信息查询
|
||||
|
currentWeatherAndForecastInformation(); |
||||
|
// 天气预报 - 当前气象预警信息查询
|
||||
|
currentWeatherWarningInformationQuery(); |
||||
|
|
||||
|
|
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 交通流通用 |
||||
|
*/ |
||||
|
public void dcTrafficStatisticsCurrency(String path, String operationName) throws Exception { |
||||
|
// 参数
|
||||
|
RequestParams requestParams = new RequestParams(); |
||||
|
|
||||
|
requestParams.put("sysid", UniversalEnum.SYS_ID.getValue()); |
||||
|
|
||||
|
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 getRadarData() throws Exception { |
||||
|
ExternalInterfaceMonitoring externalInterfaceMonitoring = new ExternalInterfaceMonitoring(); |
||||
|
OkHttp okHttp = new OkHttp(); |
||||
|
Response response // 请求响应
|
||||
|
= okHttp |
||||
|
.url(UniversalEnum.RADAR_DATA.getValue()) // 请求地址
|
||||
|
.get(); // 请求方法
|
||||
|
externalInterfaceMonitoring.setInterfaceOwnership(InterfaceOwnershipEnum.NATIONAL_METEOROLOGY.getCode()); |
||||
|
externalInterfaceMonitoring.setInterfaceName("雷达数据"); |
||||
|
if (response.code() == UniversalEnum.TWO_HUNDRED.getNumber()) { |
||||
|
externalInterfaceMonitoring.setOperationStatus(UniversalEnum.ONE.getNumber()); |
||||
|
if (response.body() != null) { |
||||
|
JSONArray array = DcNmcController.parseHtmlContent(response.body().string()); |
||||
|
externalInterfaceMonitoring.setOperationResult(JSON.toJSONString(array)); |
||||
|
} |
||||
|
} else { |
||||
|
externalInterfaceMonitoring.setOperationStatus(UniversalEnum.ZERO.getNumber()); |
||||
|
externalInterfaceMonitoring.setOperationResult(response.message()); |
||||
|
} |
||||
|
externalInterfaceMonitoring.setId(IdUtils.fastSimpleUUID()); |
||||
|
externalInterfaceMonitoring.setOperatorName("系统"); |
||||
|
externalInterfaceMonitoring.setOperationTime(new Date()); |
||||
|
externalInterfaceMonitoringMapper.insert(externalInterfaceMonitoring); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 全国气象数据 - 雷达图 |
||||
|
*/ |
||||
|
public void getRadarChart() throws Exception { |
||||
|
Map<String, String> headers = new HashMap<>(); |
||||
|
headers.put("Referer", UniversalEnum.RADAR_MAP_WEATHER.getValue()); |
||||
|
Response response = getRequestByHeaders(headers, UniversalEnum.RADAR_MAP.getValue() + new Date().getTime()); |
||||
|
|
||||
|
ExternalInterfaceMonitoring externalInterfaceMonitoring = new ExternalInterfaceMonitoring(); |
||||
|
externalInterfaceMonitoring.setInterfaceOwnership(InterfaceOwnershipEnum.NATIONAL_METEOROLOGY.getCode()); |
||||
|
externalInterfaceMonitoring.setInterfaceName("雷达图"); |
||||
|
insertIntoExternalInterface(externalInterfaceMonitoring, response); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 天气预报 - 当前气象及预报信息查询 |
||||
|
*/ |
||||
|
public void currentWeatherAndForecastInformation() { |
||||
|
// 参数
|
||||
|
HashMap<String, Object> parameter = new HashMap<>(); |
||||
|
parameter.put("roadId", UniversalEnum.ROAD_ID.getValue()); |
||||
|
parameter.put("stakeNum", UniversalEnum.STAKE_NUM.getValue()); |
||||
|
parameter.put("forecastHour", UniversalEnum.STAKE_NUM.getNumber()); |
||||
|
parameter.put("managerId", UniversalEnum.MANAGER_ID.getValue()); |
||||
|
// 结果
|
||||
|
AjaxResult ajaxResult = weatherForecastController.currentWeatherAndForecastInformation(parameter); |
||||
|
|
||||
|
// 构造
|
||||
|
ExternalInterfaceMonitoring externalInterfaceMonitoring = new ExternalInterfaceMonitoring(); |
||||
|
externalInterfaceMonitoring.setInterfaceOwnership(InterfaceOwnershipEnum.WEATHER.getCode()); |
||||
|
externalInterfaceMonitoring.setInterfaceName("当前气象及预报信息查询"); |
||||
|
resultAnalysis(ajaxResult, externalInterfaceMonitoring); |
||||
|
externalInterfaceMonitoring.setId(IdUtils.fastSimpleUUID()); |
||||
|
externalInterfaceMonitoring.setOperatorName("系统"); |
||||
|
externalInterfaceMonitoring.setOperationTime(new Date()); |
||||
|
// 插入
|
||||
|
externalInterfaceMonitoringMapper.insert(externalInterfaceMonitoring); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 天气预报 - 当前气象预警信息查询 |
||||
|
*/ |
||||
|
public void currentWeatherWarningInformationQuery() throws Exception { |
||||
|
// 参数
|
||||
|
JSONObject weather = JSONObject.parseObject(configService.selectConfigByKey("weather")); |
||||
|
HashMap<String, Object> parameter = new HashMap<>(); |
||||
|
parameter.put("roadId", UniversalEnum.ROAD_ID.getValue()); |
||||
|
parameter.put("earlyWorningLevel", UniversalEnum.EARLY_WORNING_LEVEL.getValue()); |
||||
|
String url = weather.getString("get_earlyworning_info"); |
||||
|
RequestParams requestParams = new RequestParams(parameter); |
||||
|
//结果
|
||||
|
Response response = postRequestByHeadersAndParams(new HashMap<>(), url, requestParams); |
||||
|
//构造
|
||||
|
ExternalInterfaceMonitoring externalInterfaceMonitoring = new ExternalInterfaceMonitoring(); |
||||
|
externalInterfaceMonitoring.setInterfaceOwnership(InterfaceOwnershipEnum.WEATHER.getCode()); |
||||
|
externalInterfaceMonitoring.setInterfaceName("当前气象预警信息查询"); |
||||
|
//插入
|
||||
|
insertIntoExternalInterface(externalInterfaceMonitoring, response); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 存储外部接口监测数据 |
||||
|
*/ |
||||
|
public void insertIntoExternalInterface(ExternalInterfaceMonitoring externalInterfaceMonitoring, Response response) throws Exception { |
||||
|
ResponseBody body = response.body(); |
||||
|
if (response.code() == UniversalEnum.TWO_HUNDRED.getNumber()) { |
||||
|
externalInterfaceMonitoring.setOperationStatus(UniversalEnum.ONE.getNumber()); |
||||
|
if (body != null) { |
||||
|
externalInterfaceMonitoring.setOperationResult(body.string()); |
||||
|
} |
||||
|
} else { |
||||
|
externalInterfaceMonitoring.setOperationStatus(UniversalEnum.ZERO.getNumber()); |
||||
|
externalInterfaceMonitoring.setOperationResult(response.message()); |
||||
|
} |
||||
|
externalInterfaceMonitoring.setId(IdUtils.fastSimpleUUID()); |
||||
|
externalInterfaceMonitoring.setOperatorName("系统"); |
||||
|
externalInterfaceMonitoring.setOperationTime(new Date()); |
||||
|
externalInterfaceMonitoringMapper.insert(externalInterfaceMonitoring); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get请求 有头 |
||||
|
*/ |
||||
|
public Response getRequestByHeaders(Map<String, String> headers, String url) throws Exception { |
||||
|
OkHttp okHttp = new OkHttp(); |
||||
|
return okHttp.headers(headers) |
||||
|
.url(url) // 请求地址
|
||||
|
.get(); // 请求方法
|
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Post请求 有头 有参 |
||||
|
*/ |
||||
|
public Response postRequestByHeadersAndParams(Map<String, String> headers, String url, RequestParams requestParams) throws Exception { |
||||
|
OkHttp okHttp = new OkHttp(); |
||||
|
return okHttp |
||||
|
.headers(headers) |
||||
|
.url(url) // 请求地址
|
||||
|
.data(requestParams) // 请求参数
|
||||
|
.post(); // 请求方法
|
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* AjaxResult的结果分析 |
||||
|
*/ |
||||
|
public void resultAnalysis(AjaxResult ajaxResult, ExternalInterfaceMonitoring externalInterfaceMonitoring) { |
||||
|
if (ajaxResult.get("code").equals(UniversalEnum.TWO_HUNDRED.getNumber())) { |
||||
|
externalInterfaceMonitoring.setOperationStatus(UniversalEnum.ONE.getNumber()); |
||||
|
externalInterfaceMonitoring.setOperationResult(JSON.toJSONString(ajaxResult.get("data"))); |
||||
|
} else { |
||||
|
externalInterfaceMonitoring.setOperationStatus(UniversalEnum.ZERO.getNumber()); |
||||
|
externalInterfaceMonitoring.setOperationResult(ajaxResult.get("msg").toString()); |
||||
|
} |
||||
|
} |
||||
|
} |
Loading…
Reference in new issue