Browse Source

雷达关联监控点查询接口

develop
王兴琳 4 months ago
parent
commit
89ce6d2d23
  1. 7
      zc-business/pom.xml
  2. 11
      zc-business/src/main/java/com/zc/business/controller/DcWarningController.java
  3. 37
      zc-business/src/main/java/com/zc/business/controller/VideoController.java
  4. 4
      zc-business/src/main/java/com/zc/business/enums/UniversalEnum.java
  5. 4
      zc-business/src/main/java/com/zc/business/message/device/handler/DeviceMessageHandler.java
  6. 4
      zc-business/src/main/java/com/zc/business/service/IDcWarningService.java
  7. 168
      zc-business/src/main/java/com/zc/business/service/impl/DcWarningServiceImpl.java

7
zc-business/pom.xml

@ -21,6 +21,13 @@
<artifactId>org.eclipse.paho.client.mqttv3</artifactId> <artifactId>org.eclipse.paho.client.mqttv3</artifactId>
<version>1.2.2</version> <version>1.2.2</version>
</dependency> </dependency>
<!-- 雷达关联监控点-->
<dependency>
<groupId>com.hikvision.ga</groupId>
<artifactId>artemis-http-client</artifactId>
<version>1.1.12.RELEASE</version>
</dependency>
<!-- FTTP--> <!-- FTTP-->
<dependency> <dependency>
<groupId>commons-net</groupId> <groupId>commons-net</groupId>

11
zc-business/src/main/java/com/zc/business/controller/DcWarningController.java

@ -238,5 +238,16 @@ public class DcWarningController extends BaseController
return toAjax(dcWarningService.falseAlarmResolution(dcWarning)); return toAjax(dcWarningService.falseAlarmResolution(dcWarning));
} }
/**
* 获取雷达事件视频
*
*
*/
@GetMapping("/video/{id}")
public AjaxResult getRadarIncidentVideo(@PathVariable("id") String id)throws Exception{
return AjaxResult.success(dcWarningService.getRadarIncidentVideo(id));
}
} }

37
zc-business/src/main/java/com/zc/business/controller/VideoController.java

@ -699,6 +699,43 @@ public class VideoController extends BaseController {
return getJsonResult(response,okHttp); return getJsonResult(response,okHttp);
} }
/**
* 获取视频流信息
* camId string 相机编号
* startTime Date 相机开始时间 yyyy-MM-dd HH:mm:ss
* duration 是Int 下载时长/分钟 不能超过五分钟
*/
@ApiOperation("下载相机录像")
@GetMapping(value = "/downloadCameraVideo")
public JSONObject downloadCameraVideo( String camId,String startTime,int duration) throws HttpException, IOException {
JSONObject cameraInfo = JSONObject.parseObject(configService.selectConfigByKey("dc.cameraInfo"));
OkHttp okHttp = new OkHttp();
RequestParams requestParams = new RequestParams();
requestParams.put("camId", camId);
requestParams.put("startTime", startTime);
requestParams.put("duration", duration);
Map<String, String> header = new HashMap<>();
if (VideoController.TOKEN == null) {
getToken();
}
header.put("Authorization", TOKEN);
Response response // 请求响应
= okHttp
.headers(header)
.url(cameraInfo.getString("URL") + UniversalEnum.DOWNLOAD_CAMERA_VIDEO.getValue()) // 请求地址
.data(requestParams) // 请求参数
.get(); // 请求方法
return getJsonResult(response,okHttp);
}
public void getToken() throws HttpException, IOException { public void getToken() throws HttpException, IOException {

4
zc-business/src/main/java/com/zc/business/enums/UniversalEnum.java

@ -1732,6 +1732,10 @@ public enum UniversalEnum {
// 获取视频流信息 /videoInfo/api/externalVideoStreaming // 获取视频流信息 /videoInfo/api/externalVideoStreaming
GET_VIDEO_STREAM_INFORMATION(0, "/videoInfo/api/externalVideoStreaming"), GET_VIDEO_STREAM_INFORMATION(0, "/videoInfo/api/externalVideoStreaming"),
//下载相机录像
DOWNLOAD_CAMERA_VIDEO(0,"/videoInfo/api/downloadVideotape"),
//雷达关联监控点查询接口
RADAR_ASSOCIATED_MONITORING_POINT_QUERY_INTERFACE(0,"/api/radar/v1/selectRelateByPage"),
// 云平台控制 /videoInfo/api/PTZControl // 云平台控制 /videoInfo/api/PTZControl
CLOUD_PLATFORM_CONTROL(0, "/videoInfo/api/PTZControl"), CLOUD_PLATFORM_CONTROL(0, "/videoInfo/api/PTZControl"),

4
zc-business/src/main/java/com/zc/business/message/device/handler/DeviceMessageHandler.java

@ -317,12 +317,12 @@ public class DeviceMessageHandler {
} }
dcWarning.setLane(String.valueOf(relatedLaneNo)); dcWarning.setLane(String.valueOf(relatedLaneNo));
String title = direction + WarningSubclassEnum.getDecorateInfo(warningSubclass); String title = direction+UniversalEnum.BLANK_SPACE.getValue() + WarningSubclassEnum.getDecorateInfo(warningSubclass);
// 标题 // 标题
dcWarning.setWarningTitle(title); dcWarning.setWarningTitle(title);
SimpleDateFormat sdf = new SimpleDateFormat(UniversalEnum.CHINESE_CHARACTER_TIME_FORMAT.getValue()); SimpleDateFormat sdf = new SimpleDateFormat(UniversalEnum.CHINESE_CHARACTER_TIME_FORMAT.getValue());
String formattedDate = sdf.format(new Date()); String formattedDate = sdf.format(new Date());
dcWarning.setRemark(formattedDate + UniversalEnum.BLANK_SPACE.getValue() + title); dcWarning.setRemark(formattedDate + UniversalEnum.BLANK_SPACE.getValue() +data.getString("stakeMark")+UniversalEnum.BLANK_SPACE.getValue()+ title);
// 影响车道 // 影响车道
// 物联设备id // 物联设备id

4
zc-business/src/main/java/com/zc/business/service/IDcWarningService.java

@ -108,4 +108,8 @@ public interface IDcWarningService
public Integer insertDispatch(DcDispatch dcDispatch); public Integer insertDispatch(DcDispatch dcDispatch);
//误报解除 //误报解除
public Integer falseAlarmResolution(DcWarning dcWarning); public Integer falseAlarmResolution(DcWarning dcWarning);
/**
* 获取雷达事件视频
*/
String getRadarIncidentVideo(String id)throws Exception;
} }

168
zc-business/src/main/java/com/zc/business/service/impl/DcWarningServiceImpl.java

@ -2,13 +2,17 @@ package com.zc.business.service.impl;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.google.gson.JsonObject; import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.hikvision.artemis.sdk.ArtemisHttpUtil;
import com.hikvision.artemis.sdk.config.ArtemisConfig;
import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.redis.RedisCache; import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.utils.DateUtils; import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils; import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.uuid.IdUtils; import com.ruoyi.common.utils.uuid.IdUtils;
import com.ruoyi.system.service.ISysConfigService; import com.ruoyi.system.service.ISysConfigService;
import com.zc.business.controller.VideoController;
import com.zc.business.domain.*; import com.zc.business.domain.*;
import com.zc.business.enums.UniversalEnum; import com.zc.business.enums.UniversalEnum;
import com.zc.business.enums.ValueConverter; import com.zc.business.enums.ValueConverter;
@ -22,7 +26,6 @@ import com.zc.business.service.IDcWarningService;
import com.zc.business.utils.StakeMarkUtils; import com.zc.business.utils.StakeMarkUtils;
import com.zc.common.core.httpclient.OkHttp; import com.zc.common.core.httpclient.OkHttp;
import com.zc.common.core.httpclient.exception.HttpException; import com.zc.common.core.httpclient.exception.HttpException;
import com.zc.common.core.httpclient.request.RequestParams;
import com.zc.common.core.websocket.WebSocketService; import com.zc.common.core.websocket.WebSocketService;
import com.zc.common.core.websocket.constant.WebSocketEvent; import com.zc.common.core.websocket.constant.WebSocketEvent;
import okhttp3.Response; import okhttp3.Response;
@ -35,10 +38,15 @@ import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.io.IOException; import java.io.IOException;
import java.time.Duration;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.*; import java.util.*;
import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
* 预警信息Service业务层处理 * 预警信息Service业务层处理
* *
@ -46,8 +54,7 @@ import java.util.stream.Collectors;
* @date 2024-01-26 * @date 2024-01-26
*/ */
@Service @Service
public class DcWarningServiceImpl implements IDcWarningService public class DcWarningServiceImpl implements IDcWarningService {
{
@Autowired @Autowired
private DcWarningMapper dcWarningMapper; private DcWarningMapper dcWarningMapper;
//事件 //事件
@ -63,6 +70,8 @@ public class DcWarningServiceImpl implements IDcWarningService
private DcProcessConfigMapper dcProcessConfigMapper; private DcProcessConfigMapper dcProcessConfigMapper;
@Autowired @Autowired
private ISysConfigService configService; private ISysConfigService configService;
@Autowired
private VideoController videoController;
@Resource @Resource
private RedisCache redisCache; private RedisCache redisCache;
private final String HAPPEN = UniversalEnum.TAKE_PLACE.getValue(); private final String HAPPEN = UniversalEnum.TAKE_PLACE.getValue();
@ -71,9 +80,11 @@ public class DcWarningServiceImpl implements IDcWarningService
private static final String WARNINGSTRATEGY = UniversalEnum.WARNING_STRATEGY.getValue();//redis策略缓存的key private static final String WARNINGSTRATEGY = UniversalEnum.WARNING_STRATEGY.getValue();//redis策略缓存的key
private static final String WARNINGDATA = UniversalEnum.WARNING_DATA.getValue();//redis事件缓存的key private static final String WARNINGDATA = UniversalEnum.WARNING_DATA.getValue();//redis事件缓存的key
//private static String JUDGE = "1"; //自定义判断参数,1为满足0为不满足 //private static String JUDGE = "1"; //自定义判断参数,1为满足0为不满足
private static final String ARTEMIS_PATH = "/artemis";
/** /**
* 感知事件数据统计 * 感知事件数据统计
*
* @return * @return
*/ */
@Override @Override
@ -88,8 +99,7 @@ public class DcWarningServiceImpl implements IDcWarningService
* @return 预警信息 * @return 预警信息
*/ */
@Override @Override
public HashMap<String, Object> selectDcWarningById(String id) public HashMap<String, Object> selectDcWarningById(String id) {
{
return dcWarningMapper.selectDcWarningById(id); return dcWarningMapper.selectDcWarningById(id);
} }
@ -100,8 +110,7 @@ public class DcWarningServiceImpl implements IDcWarningService
* @return 预警信息 * @return 预警信息
*/ */
@Override @Override
public HashMap<String, Object> selectAlarmById(String id) public HashMap<String, Object> selectAlarmById(String id) {
{
return dcWarningMapper.selectAlarmById(id); return dcWarningMapper.selectAlarmById(id);
} }
@ -112,10 +121,10 @@ public class DcWarningServiceImpl implements IDcWarningService
* @return 预警信息 * @return 预警信息
*/ */
@Override @Override
public List<HashMap<String,Object>> selectDcWarningList(DcWarning dcWarning) public List<HashMap<String, Object>> selectDcWarningList(DcWarning dcWarning) {
{
return dcWarningMapper.selectDcWarningList(dcWarning); return dcWarningMapper.selectDcWarningList(dcWarning);
} }
//导出 //导出
@Override @Override
public List<DcWarning> export(DcWarning dcWarning) { public List<DcWarning> export(DcWarning dcWarning) {
@ -129,8 +138,7 @@ public class DcWarningServiceImpl implements IDcWarningService
* @return 结果 * @return 结果
*/ */
@Override @Override
public int insertDcWarning(DcWarning dcWarning) public int insertDcWarning(DcWarning dcWarning) {
{
dcWarning.setCreateTime(DateUtils.getNowDate()); dcWarning.setCreateTime(DateUtils.getNowDate());
//设置事件Id UUID无下划线格式32 //设置事件Id UUID无下划线格式32
String uuid = IdUtils.fastSimpleUUID(); String uuid = IdUtils.fastSimpleUUID();
@ -259,6 +267,7 @@ public class DcWarningServiceImpl implements IDcWarningService
/** /**
* 事件推送至 Websocket * 事件推送至 Websocket
*
* @param dcWarning * @param dcWarning
*/ */
private void extracted(DcWarning dcWarning) { private void extracted(DcWarning dcWarning) {
@ -496,6 +505,7 @@ public class DcWarningServiceImpl implements IDcWarningService
} }
return jsonObjectOne; return jsonObjectOne;
} }
/** /**
* 修改预警信息 * 修改预警信息
* *
@ -503,8 +513,7 @@ public class DcWarningServiceImpl implements IDcWarningService
* @return 结果 * @return 结果
*/ */
@Override @Override
public int updateDcWarning(DcWarning dcWarning) public int updateDcWarning(DcWarning dcWarning) {
{
dcWarning.setUpdateTime(DateUtils.getNowDate()); dcWarning.setUpdateTime(DateUtils.getNowDate());
return dcWarningMapper.updateDcWarning(dcWarning); return dcWarningMapper.updateDcWarning(dcWarning);
} }
@ -516,8 +525,7 @@ public class DcWarningServiceImpl implements IDcWarningService
* @return 结果 * @return 结果
*/ */
@Override @Override
public int deleteDcWarningByIds(String id) public int deleteDcWarningByIds(String id) {
{
return dcWarningMapper.deleteDcWarningByIds(id); return dcWarningMapper.deleteDcWarningByIds(id);
} }
@ -528,10 +536,10 @@ public class DcWarningServiceImpl implements IDcWarningService
* @return 结果 * @return 结果
*/ */
@Override @Override
public int deleteDcWarningById(Integer id) public int deleteDcWarningById(Integer id) {
{
return dcWarningMapper.deleteDcWarningById(id); return dcWarningMapper.deleteDcWarningById(id);
} }
//感知事件转交通事件(感知事件状态改为处置中,把感知事件的数据整理新增到交通事件) //感知事件转交通事件(感知事件状态改为处置中,把感知事件的数据整理新增到交通事件)
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@ -626,19 +634,18 @@ public class DcWarningServiceImpl implements IDcWarningService
public int deleteDcWarningByStringId(DcWarning dcWarning) { public int deleteDcWarningByStringId(DcWarning dcWarning) {
return dcWarningMapper.deleteDcWarningByStringId(dcWarning); return dcWarningMapper.deleteDcWarningByStringId(dcWarning);
} }
@Override @Override
public List<HashMap<String,Object>> selectDcWarningoTherConfig(DcWarning dcWarning) public List<HashMap<String, Object>> selectDcWarningoTherConfig(DcWarning dcWarning) {
{
return dcWarningMapper.selectDcWarningoTherConfig(dcWarning); return dcWarningMapper.selectDcWarningoTherConfig(dcWarning);
} }
/** /**
* @param dcWarningBatchConvert
* @return com.ruoyi.common.core.domain.AjaxResult
* @Description 感知事件批量转换 * @Description 感知事件批量转换
*
* @author liuwenge * @author liuwenge
* @date 2024/3/16 16:36 * @date 2024/3/16 16:36
* @param dcWarningBatchConvert
* @return com.ruoyi.common.core.domain.AjaxResult
*/ */
@Override @Override
@Transactional @Transactional
@ -752,7 +759,8 @@ public class DcWarningServiceImpl implements IDcWarningService
hashMaps.add(map); hashMaps.add(map);
} }
List<HashMap<String, Object>> sortedHashMaps = hashMaps.stream().sorted(Comparator.comparing(map -> { List<HashMap<String, Object>> sortedHashMaps = hashMaps.stream().sorted(Comparator.comparing(map -> {
return (Double) map.get("difference"); })).collect(Collectors.toList()); return (Double) map.get("difference");
})).collect(Collectors.toList());
mapAll.put("listData", sortedHashMaps); mapAll.put("listData", sortedHashMaps);
if (!sortedHashMaps.isEmpty()) { if (!sortedHashMaps.isEmpty()) {
HashMap<String, Object> map = sortedHashMaps.get(UniversalEnum.ZERO.getNumber()); HashMap<String, Object> map = sortedHashMaps.get(UniversalEnum.ZERO.getNumber());
@ -784,6 +792,7 @@ public class DcWarningServiceImpl implements IDcWarningService
} }
return AjaxResult.success(mapAll); return AjaxResult.success(mapAll);
} }
//指挥调度,当调度信息为空的时候调用智能分配资源 //指挥调度,当调度信息为空的时候调用智能分配资源
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@ -816,7 +825,8 @@ public class DcWarningServiceImpl implements IDcWarningService
} }
mapAll.put("selectData", hashMaps); mapAll.put("selectData", hashMaps);
List<HashMap<String, Object>> sortedHashMaps = hashMaps.stream().sorted(Comparator.comparing(map -> { List<HashMap<String, Object>> sortedHashMaps = hashMaps.stream().sorted(Comparator.comparing(map -> {
return (Double) map.get("difference"); })).collect(Collectors.toList()); return (Double) map.get("difference");
})).collect(Collectors.toList());
if (!sortedHashMaps.isEmpty()) { if (!sortedHashMaps.isEmpty()) {
HashMap<String, Object> map = sortedHashMaps.get(UniversalEnum.ZERO.getNumber()); HashMap<String, Object> map = sortedHashMaps.get(UniversalEnum.ZERO.getNumber());
Long id = Long.parseLong(map.get("organizationId").toString());//取出最近的机构id Long id = Long.parseLong(map.get("organizationId").toString());//取出最近的机构id
@ -851,6 +861,7 @@ public class DcWarningServiceImpl implements IDcWarningService
} }
return AjaxResult.success(mapAll); return AjaxResult.success(mapAll);
} }
//3.指挥调度新增资源 //3.指挥调度新增资源
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@ -926,6 +937,7 @@ public class DcWarningServiceImpl implements IDcWarningService
} }
return dcWarningMapper.updateDcDispatch(dcDispatch); return dcWarningMapper.updateDcDispatch(dcDispatch);
} }
//4.新增指挥调度资源记录 //4.新增指挥调度资源记录
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@ -1061,4 +1073,110 @@ public class DcWarningServiceImpl implements IDcWarningService
return i; return i;
} }
/**
* 获取雷达事件视频
*/
@Override
public String getRadarIncidentVideo(String id) throws Exception {
String msg = "";
HashMap<String, Object> stringObjectHashMap = dcWarningMapper.selectDcWarningById(id);
// 给定的时间
String givenTime = (String) stringObjectHashMap.get("warningTime");
// 定义日期时间格式
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
// 解析给定的时间
LocalDateTime currentTime = LocalDateTime.parse(givenTime, formatter);
// 计算 30 秒后的时间
LocalDateTime timeAfter30Seconds = currentTime.plus(Duration.ofSeconds(30));
// 获取当前时间
LocalDateTime now = LocalDateTime.now();
// 判断时间与当前时间不能超过两个月
boolean isWithinTwoMonths = ChronoUnit.MONTHS.between(now, currentTime) <= 2;
if (isWithinTwoMonths) {
// 格式化时间
String formattedTime = timeAfter30Seconds.format(formatter);
Object otherConfig = stringObjectHashMap.get("otherConfig");
ObjectMapper objectMapper = new ObjectMapper();
JsonNode rootNode = objectMapper.readTree(otherConfig.toString());
// 提取 cameraIndexCode 的值
String cameraIndexCode = extractCameraIndexCode(rootNode);
//雷达关联监控点查询接口
String callPostApiGetRegions = callPostApiGetRegions(cameraIndexCode);
JsonNode roocallPostApiGetRegionstNode = objectMapper.readTree(callPostApiGetRegions);
JsonNode jsonNode = roocallPostApiGetRegionstNode.get("data");
JsonNode jsonNodelist = jsonNode.get("list");
JsonNode code = jsonNodelist.get(0).get("cameraIndexCode");
// 使用 textValue() 方法获取纯字符串
String codestring = code.textValue();
com.alibaba.fastjson.JSONObject jsonObject = videoController.downloadCameraVideo(codestring, formattedTime, 1);
JsonNode data = objectMapper.readTree(jsonObject.get("data").toString());
// 使用 textValue() 方法获取纯字符串
String fileUrl = data.get("fileUrl").textValue();
return fileUrl;
} else {
return null;
}
}
/**
* 雷达关联监控点查询接口
*
* @throws HttpException
* @throws IOException
*/
private String extractCameraIndexCode(JsonNode rootNode) {
JsonNode dataNode = rootNode.get("data");
JsonNode otherConfigurationNode = dataNode.get("otherConfiguration");
JsonNode paramsNode = otherConfigurationNode.get("params");
JsonNode eventsNode = paramsNode.get("events");
// 假设只有一个事件,我们只处理第一个事件
JsonNode eventDataNode = eventsNode.get(0);
JsonNode dataNode2 = eventDataNode.get("data");
JsonNode vehicleRcogResultNode = dataNode2.get("vehicleRcogResult");
// 假设只有一个 vehicleRcogResult 对象
JsonNode targetAttrsNode = vehicleRcogResultNode.get(0).get("targetAttrs");
return targetAttrsNode.get("cameraIndexCode").asText();
}
/**
* 调用POST请求类型接口这里以分页获取区域列表为例
* 接口实际urlhttps://ip:port/artemis/api/api/resource/v1/regions
*
* @return
*/
public String callPostApiGetRegions(String cameraIndexCode) throws Exception {
/**
* https://ip:port/artemis/api/resource/v1/regions
* 过查阅AI Cloud开放平台文档或网关门户的文档可以看到分页获取区域列表的定义,这是一个POST请求的Rest接口, 入参为JSON字符串接口协议为https
* ArtemisHttpUtil工具类提供了doPostStringArtemis调用POST请求的方法入参可传JSON字符串, 请阅读开发指南了解方法入参没有的参数可传null
*/
com.alibaba.fastjson.JSONObject radarCorrelation = com.alibaba.fastjson.JSONObject.parseObject(configService.selectConfigByKey("radarCorrelation"));
ArtemisConfig config = new ArtemisConfig();
config.setHost(radarCorrelation.getString("url")); // 雷达关联监控点查询接口
config.setAppKey(radarCorrelation.getString("appkey")); // 秘钥appkey
config.setAppSecret(radarCorrelation.getString("appSecret"));// 秘钥appSecret
final String getCamsApi = ARTEMIS_PATH + UniversalEnum.RADAR_ASSOCIATED_MONITORING_POINT_QUERY_INTERFACE.getValue();
Map<String, String> paramMap = new HashMap<String, String>();// post请求Form表单参数
paramMap.put("pageNo", "1");
paramMap.put("pageSize", "20");
paramMap.put("radarIndexCode", cameraIndexCode);
String body = JSON.toJSON(paramMap).toString();
Map<String, String> path = new HashMap<String, String>(2) {
{
put("https://", getCamsApi);
}
};
return ArtemisHttpUtil.doPostStringArtemis(config, path, body, null, null, "application/json");
}
} }
Loading…
Cancel
Save