|
|
@ -1,9 +1,16 @@ |
|
|
|
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.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper; |
|
|
|
import com.ruoyi.common.core.controller.BaseController; |
|
|
|
import com.ruoyi.common.core.domain.AjaxResult; |
|
|
|
import com.ruoyi.common.core.page.TableDataInfo; |
|
|
|
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,32 +21,74 @@ 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.Api; |
|
|
|
import io.swagger.annotations.ApiOperation; |
|
|
|
import okhttp3.*; |
|
|
|
import org.springframework.scheduling.annotation.Scheduled; |
|
|
|
import org.springframework.stereotype.Component; |
|
|
|
import org.springframework.web.bind.annotation.GetMapping; |
|
|
|
import org.springframework.web.bind.annotation.RequestMapping; |
|
|
|
import org.springframework.web.bind.annotation.RestController; |
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.Map; |
|
|
|
import java.io.IOException; |
|
|
|
import java.time.LocalDate; |
|
|
|
import java.time.LocalDateTime; |
|
|
|
import java.time.ZoneId; |
|
|
|
import java.time.format.DateTimeFormatter; |
|
|
|
import java.util.*; |
|
|
|
|
|
|
|
/** |
|
|
|
* 外部接口监控 |
|
|
|
*/ |
|
|
|
@Api(tags = "外部接口监控") |
|
|
|
@RestController |
|
|
|
@Component |
|
|
|
public class ExternalInterfaceMonitoringTask { |
|
|
|
@RequestMapping("/externalInterface") |
|
|
|
public class ExternalInterfaceMonitoringTask extends BaseController { |
|
|
|
|
|
|
|
// 视频平台token
|
|
|
|
private static String videoTOKEN; |
|
|
|
|
|
|
|
// 语音广播token
|
|
|
|
private static String voiceBroadcastingToken; |
|
|
|
|
|
|
|
@Resource |
|
|
|
private ExternalInterfaceMonitoringMapper externalInterfaceMonitoringMapper; |
|
|
|
|
|
|
|
@Resource |
|
|
|
private RedisCache redisCache; |
|
|
|
public static final MediaType JSO = MediaType.get("application/json; charset=utf-8"); |
|
|
|
@Resource |
|
|
|
private WeatherForecastController weatherForecastController; |
|
|
|
|
|
|
|
@Resource |
|
|
|
private ISysConfigService configService; |
|
|
|
|
|
|
|
/** |
|
|
|
* 外部接口监控信息列表 |
|
|
|
*/ |
|
|
|
@ApiOperation("外部接口监控信息列表") |
|
|
|
@GetMapping("/list") |
|
|
|
public TableDataInfo list(ExternalInterfaceMonitoring externalInterfaceMonitoring) |
|
|
|
{ |
|
|
|
startPage(); |
|
|
|
LambdaQueryWrapper<ExternalInterfaceMonitoring> lambdaQueryWrapper = new LambdaQueryWrapper<>(); |
|
|
|
if (externalInterfaceMonitoring.getInterfaceOwnership() != null) { |
|
|
|
lambdaQueryWrapper.eq(ExternalInterfaceMonitoring::getInterfaceOwnership, externalInterfaceMonitoring.getInterfaceOwnership()); |
|
|
|
} |
|
|
|
if (externalInterfaceMonitoring.getOperationStatus() != null) { |
|
|
|
lambdaQueryWrapper.eq(ExternalInterfaceMonitoring::getOperationStatus, externalInterfaceMonitoring.getOperationStatus()); |
|
|
|
} |
|
|
|
if (externalInterfaceMonitoring.getInterfaceName() != null) { |
|
|
|
lambdaQueryWrapper.like(ExternalInterfaceMonitoring::getInterfaceName, externalInterfaceMonitoring.getInterfaceName()); |
|
|
|
} |
|
|
|
lambdaQueryWrapper.orderByDesc(ExternalInterfaceMonitoring::getOperationTime); |
|
|
|
List<ExternalInterfaceMonitoring> list = externalInterfaceMonitoringMapper.selectList(lambdaQueryWrapper); |
|
|
|
return getDataTable(list); |
|
|
|
} |
|
|
|
|
|
|
|
@Scheduled(cron = "0 0/15 * * * ?") |
|
|
|
public void externalInterfaceDataMonitoring() throws Exception { |
|
|
|
|
|
|
@ -53,8 +102,23 @@ 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(); |
|
|
@ -66,9 +130,58 @@ public class ExternalInterfaceMonitoringTask { |
|
|
|
// 天气预报 - 当前气象预警信息查询
|
|
|
|
currentWeatherWarningInformationQuery(); |
|
|
|
|
|
|
|
// 视频平台 - 查询同步相机数据接口
|
|
|
|
querySynchronizationCameraDataInterface(); |
|
|
|
// 视频平台 - 获取视频流信息
|
|
|
|
getVideoStreamInformation(); |
|
|
|
// 视频平台 - 查询预置位列表
|
|
|
|
queryPresetPositionList(); |
|
|
|
// 视频平台 - 根据组织机构获取摄像机信息
|
|
|
|
obtainCameraInformationBasedOnOrganizationalStructure(); |
|
|
|
// 视频平台 - 云平台控制
|
|
|
|
cloudPlatformControl(); |
|
|
|
|
|
|
|
// 语音广播 - 查询终端
|
|
|
|
queryTerminal(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
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 { |
|
|
|
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秒
|
|
|
|
} |
|
|
|
|
|
|
|
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; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 交通流通用 |
|
|
|
*/ |
|
|
@ -88,7 +201,111 @@ public class ExternalInterfaceMonitoringTask { |
|
|
|
externalInterfaceMonitoring.setInterfaceOwnership(InterfaceOwnershipEnum.TRAFFIC_FLOW.getCode()); |
|
|
|
externalInterfaceMonitoring.setInterfaceName(operationName); |
|
|
|
// 插入
|
|
|
|
insertIntoExternalInterface(externalInterfaceMonitoring,response); |
|
|
|
trafficFlowResultProcessing(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); |
|
|
|
// 插入
|
|
|
|
trafficFlowResultProcessing(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); |
|
|
|
// 插入
|
|
|
|
trafficFlowResultProcessing(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); |
|
|
|
// 插入
|
|
|
|
trafficFlowResultProcessing(externalInterfaceMonitoring, response); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
@ -111,7 +328,7 @@ public class ExternalInterfaceMonitoringTask { |
|
|
|
} |
|
|
|
} else { |
|
|
|
externalInterfaceMonitoring.setOperationStatus(UniversalEnum.ZERO.getNumber()); |
|
|
|
externalInterfaceMonitoring.setOperationResult(response.message()); |
|
|
|
externalInterfaceMonitoring.setOperationResult(response.toString()); |
|
|
|
} |
|
|
|
externalInterfaceMonitoring.setId(IdUtils.fastSimpleUUID()); |
|
|
|
externalInterfaceMonitoring.setOperatorName("系统"); |
|
|
@ -179,19 +396,265 @@ public class ExternalInterfaceMonitoringTask { |
|
|
|
insertIntoExternalInterface(externalInterfaceMonitoring, response); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 查询同步相机数据 |
|
|
|
*/ |
|
|
|
public void querySynchronizationCameraDataInterface() throws Exception { |
|
|
|
JSONObject cameraInfo = JSONObject.parseObject(configService.selectConfigByKey("dc.cameraInfo")); |
|
|
|
|
|
|
|
Map<String, String> header = new HashMap<>(); |
|
|
|
|
|
|
|
if (ExternalInterfaceMonitoringTask.videoTOKEN == null) { |
|
|
|
getVideoToken(); |
|
|
|
} |
|
|
|
|
|
|
|
header.put("Authorization", videoTOKEN); |
|
|
|
|
|
|
|
Response response = getRequestByHeaders(header, |
|
|
|
cameraInfo.getString("URL") + UniversalEnum.EXAMPLE_QUERY_SYNC_CAMERA_DATA.getValue()); |
|
|
|
//构造
|
|
|
|
ExternalInterfaceMonitoring externalInterfaceMonitoring = new ExternalInterfaceMonitoring(); |
|
|
|
externalInterfaceMonitoring.setInterfaceOwnership(InterfaceOwnershipEnum.VIDEO.getCode()); |
|
|
|
externalInterfaceMonitoring.setInterfaceName("查询同步相机数据"); |
|
|
|
//插入
|
|
|
|
videoResultInsertInto(externalInterfaceMonitoring, response); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 获取视频流信息 |
|
|
|
*/ |
|
|
|
public void getVideoStreamInformation() throws Exception { |
|
|
|
JSONObject cameraInfo = JSONObject.parseObject(configService.selectConfigByKey("dc.cameraInfo")); |
|
|
|
RequestParams requestParams = new RequestParams(); |
|
|
|
requestParams.put("type", UniversalEnum.ONE.getValue()); |
|
|
|
requestParams.put("camId", "57941"); |
|
|
|
|
|
|
|
Map<String, String> header = new HashMap<>(); |
|
|
|
|
|
|
|
if (ExternalInterfaceMonitoringTask.videoTOKEN == null) { |
|
|
|
getVideoToken(); |
|
|
|
} |
|
|
|
|
|
|
|
header.put("Authorization", videoTOKEN); |
|
|
|
|
|
|
|
Response response = postRequestByHeadersAndParams(header, |
|
|
|
cameraInfo.getString("URL") + UniversalEnum.GET_VIDEO_STREAM_INFORMATION.getValue(), |
|
|
|
requestParams); |
|
|
|
//构造
|
|
|
|
ExternalInterfaceMonitoring externalInterfaceMonitoring = new ExternalInterfaceMonitoring(); |
|
|
|
externalInterfaceMonitoring.setInterfaceOwnership(InterfaceOwnershipEnum.VIDEO.getCode()); |
|
|
|
externalInterfaceMonitoring.setInterfaceName("获取视频流信息"); |
|
|
|
//插入
|
|
|
|
videoResultInsertInto(externalInterfaceMonitoring, response); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 查询预置位列表 |
|
|
|
*/ |
|
|
|
public void queryPresetPositionList() throws Exception { |
|
|
|
JSONObject cameraInfo = JSONObject.parseObject(configService.selectConfigByKey("dc.cameraInfo")); |
|
|
|
|
|
|
|
OkHttp okHttp = new OkHttp(); |
|
|
|
|
|
|
|
RequestParams requestParams = new RequestParams(); |
|
|
|
requestParams.put("camId", "57941"); |
|
|
|
|
|
|
|
Map<String, String> header = new HashMap<>(); |
|
|
|
|
|
|
|
if (ExternalInterfaceMonitoringTask.videoTOKEN == null) { |
|
|
|
getVideoToken(); |
|
|
|
} |
|
|
|
|
|
|
|
header.put("Authorization", videoTOKEN); |
|
|
|
|
|
|
|
Response response = getRequestByHeadersByParam(header, |
|
|
|
cameraInfo.getString("URL") + UniversalEnum.EXAMPLE_QUERY_THE_PRESET_BIT_LIST.getValue(), |
|
|
|
requestParams); |
|
|
|
|
|
|
|
//构造
|
|
|
|
ExternalInterfaceMonitoring externalInterfaceMonitoring = new ExternalInterfaceMonitoring(); |
|
|
|
externalInterfaceMonitoring.setInterfaceOwnership(InterfaceOwnershipEnum.VIDEO.getCode()); |
|
|
|
externalInterfaceMonitoring.setInterfaceName("查询预置位列表"); |
|
|
|
//插入
|
|
|
|
videoResultInsertInto(externalInterfaceMonitoring, response); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 根据组织机构获取摄像机信息 |
|
|
|
*/ |
|
|
|
public void obtainCameraInformationBasedOnOrganizationalStructure() throws Exception { |
|
|
|
JSONObject cameraInfo = JSONObject.parseObject(configService.selectConfigByKey("dc.cameraInfo")); |
|
|
|
|
|
|
|
RequestParams requestParams = new RequestParams(); |
|
|
|
requestParams.put("deptId", cameraInfo.getString("CAM_DEPT_ID")); |
|
|
|
|
|
|
|
Map<String, String> header = new HashMap<>(); |
|
|
|
|
|
|
|
if (ExternalInterfaceMonitoringTask.videoTOKEN == null) { |
|
|
|
getVideoToken(); |
|
|
|
} |
|
|
|
header.put("Authorization", videoTOKEN); |
|
|
|
|
|
|
|
Response response = getRequestByHeadersByParam(header, |
|
|
|
cameraInfo.getString("URL") + UniversalEnum.GET_CAMERA_INFORMATION_BY_ORGANIZATION.getValue(), |
|
|
|
requestParams); |
|
|
|
//构造
|
|
|
|
ExternalInterfaceMonitoring externalInterfaceMonitoring = new ExternalInterfaceMonitoring(); |
|
|
|
externalInterfaceMonitoring.setInterfaceOwnership(InterfaceOwnershipEnum.VIDEO.getCode()); |
|
|
|
externalInterfaceMonitoring.setInterfaceName("根据组织机构获取摄像机信息"); |
|
|
|
//插入
|
|
|
|
videoResultInsertInto(externalInterfaceMonitoring, response); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 云平台控制 |
|
|
|
*/ |
|
|
|
public void cloudPlatformControl() throws Exception { |
|
|
|
JSONObject cameraInfo = JSONObject.parseObject(configService.selectConfigByKey("dc.cameraInfo")); |
|
|
|
|
|
|
|
RequestParams requestParams = new RequestParams(); |
|
|
|
requestParams.put("msgType", UniversalEnum.THREE.getValue()); |
|
|
|
requestParams.put("camId", "57941"); |
|
|
|
// (关雨刷)
|
|
|
|
requestParams.put("cmdType", "48"); |
|
|
|
requestParams.put("speed", "10"); |
|
|
|
|
|
|
|
Map<String, String> header = new HashMap<>(); |
|
|
|
|
|
|
|
header.put("Authorization", videoTOKEN); |
|
|
|
|
|
|
|
Response response = getRequestByHeadersByParam(header, |
|
|
|
cameraInfo.getString("URL") + UniversalEnum.CLOUD_PLATFORM_CONTROL.getValue(), |
|
|
|
requestParams); |
|
|
|
//构造
|
|
|
|
ExternalInterfaceMonitoring externalInterfaceMonitoring = new ExternalInterfaceMonitoring(); |
|
|
|
externalInterfaceMonitoring.setInterfaceOwnership(InterfaceOwnershipEnum.VIDEO.getCode()); |
|
|
|
externalInterfaceMonitoring.setInterfaceName("云平台控制"); |
|
|
|
//插入
|
|
|
|
videoResultInsertInto(externalInterfaceMonitoring, response); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 查询终端 |
|
|
|
*/ |
|
|
|
public void queryTerminal() { |
|
|
|
|
|
|
|
JSONObject broadcast = JSONObject.parseObject(configService.selectConfigByKey("broadcast")); |
|
|
|
//构造
|
|
|
|
ExternalInterfaceMonitoring externalInterfaceMonitoring = new ExternalInterfaceMonitoring(); |
|
|
|
externalInterfaceMonitoring.setInterfaceOwnership(InterfaceOwnershipEnum.RADIO_BROADCAST.getCode()); |
|
|
|
externalInterfaceMonitoring.setInterfaceName("查询终端"); |
|
|
|
try { |
|
|
|
if (voiceBroadcastingToken == null) { |
|
|
|
getVoiceBroadcastingToken(); |
|
|
|
} |
|
|
|
RequestParams requestParams = new RequestParams(); |
|
|
|
requestParams.put("zoneId", UniversalEnum.ASTERISK_ASTERISK_SIX_THOUSAND_AND_ONE.getValue()); |
|
|
|
requestParams.put("termDN", UniversalEnum.EMPTY_STRING.getValue()); |
|
|
|
|
|
|
|
OkHttp okHttp = new OkHttp(15); |
|
|
|
Response response // 请求响应
|
|
|
|
= okHttp |
|
|
|
.headers(new HashMap<>()) |
|
|
|
.data(requestParams) // 请求参数
|
|
|
|
.url(broadcast.getString("URL") + UniversalEnum.QUERY_TERM_DO_ACCESS_TOKEN.getValue() + voiceBroadcastingToken) // 请求地址
|
|
|
|
.post(); // 请求方法
|
|
|
|
|
|
|
|
//插入
|
|
|
|
ResponseBody body = response.body(); |
|
|
|
if (body != null) { |
|
|
|
JSONObject jsonResult = JSONObject.parseObject(body.string()); |
|
|
|
|
|
|
|
if (jsonResult.get("retCode").equals(UniversalEnum.ZERO.getValue())) { |
|
|
|
externalInterfaceMonitoring.setOperationStatus(UniversalEnum.ONE.getNumber()); |
|
|
|
} else { |
|
|
|
externalInterfaceMonitoring.setOperationStatus(UniversalEnum.ZERO.getNumber()); |
|
|
|
} |
|
|
|
externalInterfaceMonitoring.setOperationResult(JSON.toJSONString(jsonResult)); |
|
|
|
} else { |
|
|
|
externalInterfaceMonitoring.setOperationStatus(UniversalEnum.ZERO.getNumber()); |
|
|
|
externalInterfaceMonitoring.setOperationResult(response.toString()); |
|
|
|
} |
|
|
|
|
|
|
|
}catch (Exception e) { |
|
|
|
externalInterfaceMonitoring.setOperationStatus(UniversalEnum.ZERO.getNumber()); |
|
|
|
externalInterfaceMonitoring.setOperationResult(e.toString()); |
|
|
|
}finally { |
|
|
|
externalInterfaceMonitoring.setId(IdUtils.fastSimpleUUID()); |
|
|
|
externalInterfaceMonitoring.setOperatorName("系统"); |
|
|
|
externalInterfaceMonitoring.setOperationTime(new Date()); |
|
|
|
externalInterfaceMonitoringMapper.insert(externalInterfaceMonitoring); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 交通流结果处理 |
|
|
|
*/ |
|
|
|
public void trafficFlowResultProcessing(ExternalInterfaceMonitoring externalInterfaceMonitoring, Response response) throws Exception { |
|
|
|
ResponseBody body = response.body(); |
|
|
|
|
|
|
|
externalInterfaceMonitoring.setOperationStatus(UniversalEnum.ZERO.getNumber()); |
|
|
|
if (body != null) { |
|
|
|
JSONObject jsonResult = JSONObject.parseObject(body.string()); |
|
|
|
if (jsonResult.containsKey("code") && jsonResult.get("code").equals(UniversalEnum.TWO_HUNDRED.getNumber())) { |
|
|
|
externalInterfaceMonitoring.setOperationStatus(UniversalEnum.ONE.getNumber()); |
|
|
|
} |
|
|
|
externalInterfaceMonitoring.setOperationResult(body.string()); |
|
|
|
} else { |
|
|
|
externalInterfaceMonitoring.setOperationResult(response.toString()); |
|
|
|
} |
|
|
|
|
|
|
|
externalInterfaceMonitoring.setId(IdUtils.fastSimpleUUID()); |
|
|
|
externalInterfaceMonitoring.setOperatorName("系统"); |
|
|
|
externalInterfaceMonitoring.setOperationTime(new Date()); |
|
|
|
externalInterfaceMonitoringMapper.insert(externalInterfaceMonitoring); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 存储外部接口监测数据 |
|
|
|
*/ |
|
|
|
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()); |
|
|
|
} else { |
|
|
|
externalInterfaceMonitoring.setOperationStatus(UniversalEnum.ZERO.getNumber()); |
|
|
|
} |
|
|
|
|
|
|
|
if (body != null) { |
|
|
|
externalInterfaceMonitoring.setOperationResult(body.string()); |
|
|
|
} |
|
|
|
} else { |
|
|
|
externalInterfaceMonitoring.setOperationResult(response.toString()); |
|
|
|
} |
|
|
|
|
|
|
|
externalInterfaceMonitoring.setId(IdUtils.fastSimpleUUID()); |
|
|
|
externalInterfaceMonitoring.setOperatorName("系统"); |
|
|
|
externalInterfaceMonitoring.setOperationTime(new Date()); |
|
|
|
externalInterfaceMonitoringMapper.insert(externalInterfaceMonitoring); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 视频流结果处理 |
|
|
|
* |
|
|
|
* @param externalInterfaceMonitoring |
|
|
|
* @param response |
|
|
|
* @throws Exception |
|
|
|
*/ |
|
|
|
public void videoResultInsertInto(ExternalInterfaceMonitoring externalInterfaceMonitoring, Response response) throws Exception { |
|
|
|
ResponseBody body = response.body(); |
|
|
|
externalInterfaceMonitoring.setOperationStatus(UniversalEnum.ZERO.getNumber()); |
|
|
|
externalInterfaceMonitoring.setOperationResult(response.message()); |
|
|
|
if (body != null) { |
|
|
|
JSONObject jsonResult = JSONObject.parseObject(body.string()); |
|
|
|
if (jsonResult.containsKey("code") && jsonResult.get("code").equals(UniversalEnum.TWO_HUNDRED.getNumber())) { |
|
|
|
externalInterfaceMonitoring.setOperationStatus(UniversalEnum.ONE.getNumber()); |
|
|
|
} |
|
|
|
externalInterfaceMonitoring.setOperationResult(JSON.toJSONString(jsonResult)); |
|
|
|
} else { |
|
|
|
externalInterfaceMonitoring.setOperationResult(response.toString()); |
|
|
|
} |
|
|
|
externalInterfaceMonitoring.setId(IdUtils.fastSimpleUUID()); |
|
|
|
externalInterfaceMonitoring.setOperatorName("系统"); |
|
|
@ -209,6 +672,17 @@ public class ExternalInterfaceMonitoringTask { |
|
|
|
.get(); // 请求方法
|
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Get请求 有头 有参 |
|
|
|
*/ |
|
|
|
public Response getRequestByHeadersByParam(Map<String, String> headers, String url, RequestParams requestParams) throws Exception { |
|
|
|
OkHttp okHttp = new OkHttp(); |
|
|
|
return okHttp.headers(headers) |
|
|
|
.url(url) // 请求地址
|
|
|
|
.data(requestParams) |
|
|
|
.get(); // 请求方法
|
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Post请求 有头 有参 |
|
|
|
*/ |
|
|
@ -233,4 +707,122 @@ 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 GetPointDataListAsync() throws IOException, HttpException { |
|
|
|
//今天零点的时间戳
|
|
|
|
long todayStartTimestamp = getTodayStartTimestamp(); |
|
|
|
// 获取当前时间的时间戳(毫秒数)
|
|
|
|
long currentTimestamp = getCurrentTimestamp(); |
|
|
|
|
|
|
|
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秒
|
|
|
|
} |
|
|
|
|
|
|
|
Map<String, String> header = new HashMap<>(); |
|
|
|
header.put("Authorization", "Bearer " + accessToken.toString()); |
|
|
|
Response response // 请求响应
|
|
|
|
= okHttp |
|
|
|
.headers(header) |
|
|
|
.url(configService.selectConfigByKey("GetPointDataListAsyncAPI")) // 请求地址
|
|
|
|
.data(requestParams) // 请求参数
|
|
|
|
.get(); // 请求方法
|
|
|
|
|
|
|
|
// 正确解析响应体中的JSON数据
|
|
|
|
return response; |
|
|
|
} |
|
|
|
|
|
|
|
// 获取今天零点的时间戳(毫秒数)
|
|
|
|
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(); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 获取视频平台 token |
|
|
|
* |
|
|
|
* @throws Exception |
|
|
|
*/ |
|
|
|
public void getVideoToken() throws Exception { |
|
|
|
|
|
|
|
JSONObject cameraInfo = JSONObject.parseObject(configService.selectConfigByKey("dc.cameraInfo")); |
|
|
|
RequestParams requestParams = new RequestParams(); |
|
|
|
requestParams.put("username", cameraInfo.getString("USERNAME")); |
|
|
|
requestParams.put("password", cameraInfo.getString("PASSWORD")); |
|
|
|
|
|
|
|
Response response = postRequestByHeadersAndParams(new HashMap<>(), |
|
|
|
cameraInfo.getString("URL") + UniversalEnum.GET_THE_CAMERA_TOKEN.getValue(), |
|
|
|
requestParams); |
|
|
|
|
|
|
|
if (response.body() != null) { |
|
|
|
JSONObject jsonResult = JSONObject.parseObject(response.body().string()); |
|
|
|
if (jsonResult.containsKey("token")) { |
|
|
|
ExternalInterfaceMonitoringTask.videoTOKEN = jsonResult.getString("token"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 获取语音广播token |
|
|
|
*/ |
|
|
|
public void getVoiceBroadcastingToken() throws Exception { |
|
|
|
|
|
|
|
JSONObject broadcast = JSONObject.parseObject(configService.selectConfigByKey("broadcast")); |
|
|
|
RequestParams requestParams = new RequestParams(); |
|
|
|
requestParams.put("id", broadcast.getString("ID")); |
|
|
|
requestParams.put("secret", broadcast.getString("SECRET")); |
|
|
|
requestParams.put("callbackUrl", broadcast.getString("CALLBACKURL")); |
|
|
|
Response response = postRequestByHeadersAndParams(new HashMap<>(), UniversalEnum.BROADCAST_LOG_URL.getValue(), requestParams); |
|
|
|
if (response.body() != null) { |
|
|
|
voiceBroadcastingToken = JSONObject.parseObject(response.body().string()).getString("accessToken"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|