Browse Source

优化内存溢出的问题

优化zlm集群默认zlm的存储
添加报警的存储以及相关接口
添加单元测试
pull/151/head
648540858 3 years ago
parent
commit
724b288232
  1. 6
      pom.xml
  2. 5
      src/main/java/com/genersoft/iot/vmp/VManageBootstrap.java
  3. 13
      src/main/java/com/genersoft/iot/vmp/gb28181/bean/DeviceAlarm.java
  4. 5
      src/main/java/com/genersoft/iot/vmp/gb28181/transmit/SIPProcessorFactory.java
  5. 10
      src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/ByeRequestProcessor.java
  6. 17
      src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/InviteRequestProcessor.java
  7. 30
      src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/MessageRequestProcessor.java
  8. 5
      src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/NotifyRequestProcessor.java
  9. 9
      src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/RegisterRequestProcessor.java
  10. 4
      src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/SubscribeRequestProcessor.java
  11. 2
      src/main/java/com/genersoft/iot/vmp/gb28181/transmit/response/impl/ByeResponseProcessor.java
  12. 32
      src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRunner.java
  13. 43
      src/main/java/com/genersoft/iot/vmp/service/IDeviceAlarmService.java
  14. 2
      src/main/java/com/genersoft/iot/vmp/service/IMediaServerService.java
  15. 37
      src/main/java/com/genersoft/iot/vmp/service/impl/DeviceAlarmServiceImpl.java
  16. 22
      src/main/java/com/genersoft/iot/vmp/service/impl/MediaServerServiceImpl.java
  17. 48
      src/main/java/com/genersoft/iot/vmp/storager/dao/DeviceAlarmMapper.java
  18. 6
      src/main/java/com/genersoft/iot/vmp/storager/dao/MediaServerMapper.java
  19. 131
      src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/alarm/AlarmController.java
  20. BIN
      src/main/resources/wvp.sqlite
  21. 18930
      web_src/package-lock.json

6
pom.xml

@ -221,6 +221,12 @@
<scope>system</scope> <scope>system</scope>
<systemPath>${project.basedir}/libs/onvif-java-1.0.2.jar</systemPath> <systemPath>${project.basedir}/libs/onvif-java-1.0.2.jar</systemPath>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<!-- <scope>test</scope>-->
</dependency>
</dependencies> </dependencies>

5
src/main/java/com/genersoft/iot/vmp/VManageBootstrap.java

@ -8,6 +8,9 @@ import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.EnableScheduling;
import springfox.documentation.oas.annotations.EnableOpenApi; import springfox.documentation.oas.annotations.EnableOpenApi;
/**
*
*/
@SpringBootApplication @SpringBootApplication
@EnableScheduling @EnableScheduling
@EnableOpenApi @EnableOpenApi
@ -22,7 +25,7 @@ public class VManageBootstrap extends LogManager {
public static void restart() { public static void restart() {
context.close(); context.close();
VManageBootstrap.context = SpringApplication.run(VManageBootstrap.class, args); VManageBootstrap.context = SpringApplication.run(VManageBootstrap.class, args);
} }
} }

13
src/main/java/com/genersoft/iot/vmp/gb28181/bean/DeviceAlarm.java

@ -3,6 +3,11 @@ package com.genersoft.iot.vmp.gb28181.bean;
public class DeviceAlarm { public class DeviceAlarm {
/**
* 数据库id
*/
private String id;
/** /**
* 设备Id * 设备Id
*/ */
@ -45,6 +50,14 @@ public class DeviceAlarm {
private String alarmType; private String alarmType;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getDeviceId() { public String getDeviceId() {
return deviceId; return deviceId;
} }

5
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/SIPProcessorFactory.java

@ -9,6 +9,7 @@ import javax.sip.message.Response;
import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommanderFroPlatform; import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommanderFroPlatform;
import com.genersoft.iot.vmp.media.zlm.ZLMRTPServerFactory; import com.genersoft.iot.vmp.media.zlm.ZLMRTPServerFactory;
import com.genersoft.iot.vmp.service.IDeviceAlarmService;
import com.genersoft.iot.vmp.service.IMediaServerService; import com.genersoft.iot.vmp.service.IMediaServerService;
import com.genersoft.iot.vmp.storager.IRedisCatchStorage; import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
import com.genersoft.iot.vmp.gb28181.transmit.response.impl.*; import com.genersoft.iot.vmp.gb28181.transmit.response.impl.*;
@ -73,6 +74,9 @@ public class SIPProcessorFactory {
@Autowired @Autowired
private SIPCommanderFroPlatform cmderFroPlatform; private SIPCommanderFroPlatform cmderFroPlatform;
@Autowired
private IDeviceAlarmService deviceAlarmService;
@Autowired @Autowired
private RedisUtil redis; private RedisUtil redis;
@ -178,6 +182,7 @@ public class SIPProcessorFactory {
processor.setOffLineDetector(offLineDetector); processor.setOffLineDetector(offLineDetector);
processor.setCmder(cmder); processor.setCmder(cmder);
processor.setCmderFroPlatform(cmderFroPlatform); processor.setCmderFroPlatform(cmderFroPlatform);
processor.setDeviceAlarmService(deviceAlarmService);
processor.setStorager(storager); processor.setStorager(storager);
processor.setRedisCatchStorage(redisCatchStorage); processor.setRedisCatchStorage(redisCatchStorage);
return processor; return processor;

10
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/ByeRequestProcessor.java

@ -1,11 +1,7 @@
package com.genersoft.iot.vmp.gb28181.transmit.request.impl; package com.genersoft.iot.vmp.gb28181.transmit.request.impl;
import javax.sip.*;
import javax.sip.address.SipURI; import javax.sip.address.SipURI;
import javax.sip.Dialog;
import javax.sip.DialogState;
import javax.sip.InvalidArgumentException;
import javax.sip.RequestEvent;
import javax.sip.SipException;
import javax.sip.header.FromHeader; import javax.sip.header.FromHeader;
import javax.sip.header.HeaderAddress; import javax.sip.header.HeaderAddress;
import javax.sip.header.ToHeader; import javax.sip.header.ToHeader;
@ -107,7 +103,9 @@ public class ByeRequestProcessor extends SIPRequestAbstractProcessor {
*/ */
private void responseAck(RequestEvent evt) throws SipException, InvalidArgumentException, ParseException { private void responseAck(RequestEvent evt) throws SipException, InvalidArgumentException, ParseException {
Response response = getMessageFactory().createResponse(Response.OK, evt.getRequest()); Response response = getMessageFactory().createResponse(Response.OK, evt.getRequest());
getServerTransaction(evt).sendResponse(response); ServerTransaction serverTransaction = getServerTransaction(evt);
serverTransaction.sendResponse(response);
if (serverTransaction.getDialog() != null) serverTransaction.getDialog().delete();
} }
public IRedisCatchStorage getRedisCatchStorage() { public IRedisCatchStorage getRedisCatchStorage() {

17
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/InviteRequestProcessor.java

@ -1,10 +1,7 @@
package com.genersoft.iot.vmp.gb28181.transmit.request.impl; package com.genersoft.iot.vmp.gb28181.transmit.request.impl;
import javax.sdp.*; import javax.sdp.*;
import javax.sip.InvalidArgumentException; import javax.sip.*;
import javax.sip.RequestEvent;
import javax.sip.SipException;
import javax.sip.SipFactory;
import javax.sip.address.Address; import javax.sip.address.Address;
import javax.sip.address.SipURI; import javax.sip.address.SipURI;
import javax.sip.header.*; import javax.sip.header.*;
@ -239,7 +236,9 @@ public class InviteRequestProcessor extends SIPRequestAbstractProcessor {
Response response = null; Response response = null;
try { try {
response = getMessageFactory().createResponse(event.getResponse().getStatusCode(), evt.getRequest()); response = getMessageFactory().createResponse(event.getResponse().getStatusCode(), evt.getRequest());
getServerTransaction(evt).sendResponse(response); ServerTransaction serverTransaction = getServerTransaction(evt);
serverTransaction.sendResponse(response);
if (serverTransaction.getDialog() != null) serverTransaction.getDialog().delete();
} catch (ParseException | SipException | InvalidArgumentException e) { } catch (ParseException | SipException | InvalidArgumentException e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -384,13 +383,17 @@ public class InviteRequestProcessor extends SIPRequestAbstractProcessor {
*/ */
private void responseAck(RequestEvent evt, int statusCode) throws SipException, InvalidArgumentException, ParseException { private void responseAck(RequestEvent evt, int statusCode) throws SipException, InvalidArgumentException, ParseException {
Response response = getMessageFactory().createResponse(statusCode, evt.getRequest()); Response response = getMessageFactory().createResponse(statusCode, evt.getRequest());
getServerTransaction(evt).sendResponse(response); ServerTransaction serverTransaction = getServerTransaction(evt);
serverTransaction.sendResponse(response);
if (serverTransaction.getDialog() != null) serverTransaction.getDialog().delete();
} }
private void responseAck(RequestEvent evt, int statusCode, String msg) throws SipException, InvalidArgumentException, ParseException { private void responseAck(RequestEvent evt, int statusCode, String msg) throws SipException, InvalidArgumentException, ParseException {
Response response = getMessageFactory().createResponse(statusCode, evt.getRequest()); Response response = getMessageFactory().createResponse(statusCode, evt.getRequest());
response.setReasonPhrase(msg); response.setReasonPhrase(msg);
getServerTransaction(evt).sendResponse(response); ServerTransaction serverTransaction = getServerTransaction(evt);
serverTransaction.sendResponse(response);
if (serverTransaction.getDialog() != null) serverTransaction.getDialog().delete();
} }
/** /**

30
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/MessageRequestProcessor.java

@ -4,17 +4,12 @@ import java.io.ByteArrayInputStream;
import java.text.ParseException; import java.text.ParseException;
import java.util.*; import java.util.*;
import javax.sip.*;
import javax.sip.address.SipURI; import javax.sip.address.SipURI;
import javax.sip.header.FromHeader; import javax.sip.header.FromHeader;
import javax.sip.header.HeaderAddress; import javax.sip.header.HeaderAddress;
import javax.sip.header.ToHeader; import javax.sip.header.ToHeader;
import javax.sip.InvalidArgumentException;
import javax.sip.ListeningPoint;
import javax.sip.ObjectInUseException;
import javax.sip.RequestEvent;
import javax.sip.SipException;
import javax.sip.SipProvider;
import javax.sip.message.Request; import javax.sip.message.Request;
import javax.sip.message.Response; import javax.sip.message.Response;
@ -35,6 +30,7 @@ import com.genersoft.iot.vmp.gb28181.transmit.request.SIPRequestAbstractProcesso
import com.genersoft.iot.vmp.gb28181.utils.DateUtil; import com.genersoft.iot.vmp.gb28181.utils.DateUtil;
import com.genersoft.iot.vmp.gb28181.utils.NumericUtil; import com.genersoft.iot.vmp.gb28181.utils.NumericUtil;
import com.genersoft.iot.vmp.gb28181.utils.XmlUtil; import com.genersoft.iot.vmp.gb28181.utils.XmlUtil;
import com.genersoft.iot.vmp.service.IDeviceAlarmService;
import com.genersoft.iot.vmp.storager.IRedisCatchStorage; import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
import com.genersoft.iot.vmp.storager.IVideoManagerStorager; import com.genersoft.iot.vmp.storager.IVideoManagerStorager;
import com.genersoft.iot.vmp.utils.GpsUtil; import com.genersoft.iot.vmp.utils.GpsUtil;
@ -84,6 +80,8 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor {
private DeviceOffLineDetector offLineDetector; private DeviceOffLineDetector offLineDetector;
private IDeviceAlarmService deviceAlarmService;
private final static String CACHE_RECORDINFO_KEY = "CACHE_RECORDINFO_"; private final static String CACHE_RECORDINFO_KEY = "CACHE_RECORDINFO_";
private static final String MESSAGE_KEEP_ALIVE = "Keepalive"; private static final String MESSAGE_KEEP_ALIVE = "Keepalive";
@ -738,7 +736,9 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor {
storager.insertMobilePosition(mobilePosition); storager.insertMobilePosition(mobilePosition);
} }
} }
// TODO: 需要实现存储报警信息、报警分类 System.out.println("存储报警信息、报警分类");
// 存储报警信息、报警分类
deviceAlarmService.add(deviceAlarm);
if (offLineDetector.isOnline(deviceId)) { if (offLineDetector.isOnline(deviceId)) {
publisher.deviceAlarmEventPublish(deviceAlarm); publisher.deviceAlarmEventPublish(deviceAlarm);
@ -779,7 +779,9 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor {
}else{ }else{
logger.warn("收到[ "+deviceId+" ]心跳信息, 但是设备不存在, 回复404"); logger.warn("收到[ "+deviceId+" ]心跳信息, 但是设备不存在, 回复404");
Response response = getMessageFactory().createResponse(Response.NOT_FOUND, evt.getRequest()); Response response = getMessageFactory().createResponse(Response.NOT_FOUND, evt.getRequest());
getServerTransaction(evt).sendResponse(response); ServerTransaction serverTransaction = getServerTransaction(evt);
serverTransaction.sendResponse(response);
if (serverTransaction.getDialog() != null) serverTransaction.getDialog().delete();
} }
// if (device != null && device.getOnline() == 1) { // if (device != null && device.getOnline() == 1) {
@ -987,7 +989,9 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor {
*/ */
private void responseAck(RequestEvent evt) throws SipException, InvalidArgumentException, ParseException { private void responseAck(RequestEvent evt) throws SipException, InvalidArgumentException, ParseException {
Response response = getMessageFactory().createResponse(Response.OK, evt.getRequest()); Response response = getMessageFactory().createResponse(Response.OK, evt.getRequest());
getServerTransaction(evt).sendResponse(response); ServerTransaction serverTransaction = getServerTransaction(evt);
serverTransaction.sendResponse(response);
if (serverTransaction.getDialog() != null) serverTransaction.getDialog().delete();
} }
/*** /***
@ -999,7 +1003,9 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor {
*/ */
private void response404Ack(RequestEvent evt) throws SipException, InvalidArgumentException, ParseException { private void response404Ack(RequestEvent evt) throws SipException, InvalidArgumentException, ParseException {
Response response = getMessageFactory().createResponse(Response.NOT_FOUND, evt.getRequest()); Response response = getMessageFactory().createResponse(Response.NOT_FOUND, evt.getRequest());
getServerTransaction(evt).sendResponse(response); ServerTransaction serverTransaction = getServerTransaction(evt);
serverTransaction.sendResponse(response);
if (serverTransaction.getDialog() != null) serverTransaction.getDialog().delete();
} }
private Element getRootElement(RequestEvent evt) throws DocumentException { private Element getRootElement(RequestEvent evt) throws DocumentException {
@ -1049,4 +1055,8 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor {
public void setCmderFroPlatform(SIPCommanderFroPlatform cmderFroPlatform) { public void setCmderFroPlatform(SIPCommanderFroPlatform cmderFroPlatform) {
this.cmderFroPlatform = cmderFroPlatform; this.cmderFroPlatform = cmderFroPlatform;
} }
public void setDeviceAlarmService(IDeviceAlarmService deviceAlarmService) {
this.deviceAlarmService = deviceAlarmService;
}
} }

5
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/NotifyRequestProcessor.java

@ -6,6 +6,7 @@ import java.util.Iterator;
import javax.sip.InvalidArgumentException; import javax.sip.InvalidArgumentException;
import javax.sip.RequestEvent; import javax.sip.RequestEvent;
import javax.sip.ServerTransaction;
import javax.sip.SipException; import javax.sip.SipException;
import javax.sip.message.Request; import javax.sip.message.Request;
import javax.sip.message.Response; import javax.sip.message.Response;
@ -342,7 +343,9 @@ public class NotifyRequestProcessor extends SIPRequestAbstractProcessor {
*/ */
private void response200Ok(RequestEvent evt) throws SipException, InvalidArgumentException, ParseException { private void response200Ok(RequestEvent evt) throws SipException, InvalidArgumentException, ParseException {
Response response = getMessageFactory().createResponse(Response.OK, evt.getRequest()); Response response = getMessageFactory().createResponse(Response.OK, evt.getRequest());
getServerTransaction(evt).sendResponse(response); ServerTransaction serverTransaction = getServerTransaction(evt);
serverTransaction.sendResponse(response);
if (serverTransaction.getDialog() != null) serverTransaction.getDialog().delete();
} }
private Element getRootElement(RequestEvent evt) throws DocumentException { private Element getRootElement(RequestEvent evt) throws DocumentException {

9
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/RegisterRequestProcessor.java

@ -7,6 +7,7 @@ import java.util.Locale;
import javax.sip.InvalidArgumentException; import javax.sip.InvalidArgumentException;
import javax.sip.RequestEvent; import javax.sip.RequestEvent;
import javax.sip.ServerTransaction;
import javax.sip.SipException; import javax.sip.SipException;
import javax.sip.header.AuthorizationHeader; import javax.sip.header.AuthorizationHeader;
import javax.sip.header.ContactHeader; import javax.sip.header.ContactHeader;
@ -112,7 +113,9 @@ public class RegisterRequestProcessor extends SIPRequestAbstractProcessor {
ExpiresHeader expiresHeader = (ExpiresHeader) request.getHeader(Expires.NAME); ExpiresHeader expiresHeader = (ExpiresHeader) request.getHeader(Expires.NAME);
if (expiresHeader == null) { if (expiresHeader == null) {
response = getMessageFactory().createResponse(Response.BAD_REQUEST, request); response = getMessageFactory().createResponse(Response.BAD_REQUEST, request);
getServerTransaction(evt).sendResponse(response); ServerTransaction serverTransaction = getServerTransaction(evt);
serverTransaction.sendResponse(response);
if (serverTransaction.getDialog() != null) serverTransaction.getDialog().delete();
return; return;
} }
// 添加Contact头 // 添加Contact头
@ -159,7 +162,9 @@ public class RegisterRequestProcessor extends SIPRequestAbstractProcessor {
} }
} }
getServerTransaction(evt).sendResponse(response); ServerTransaction serverTransaction = getServerTransaction(evt);
serverTransaction.sendResponse(response);
if (serverTransaction.getDialog() != null) serverTransaction.getDialog().delete();
// 注册成功 // 注册成功
// 保存到redis // 保存到redis
// 下发catelog查询目录 // 下发catelog查询目录

4
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/SubscribeRequestProcessor.java

@ -27,9 +27,6 @@ public class SubscribeRequestProcessor extends SIPRequestAbstractProcessor {
* 处理SUBSCRIBE请求 * 处理SUBSCRIBE请求
* *
* @param evt * @param evt
* @param layer
* @param transaction
* @param config
*/ */
@Override @Override
public void process(RequestEvent evt) { public void process(RequestEvent evt) {
@ -46,6 +43,7 @@ public class SubscribeRequestProcessor extends SIPRequestAbstractProcessor {
ServerTransaction transaction = getServerTransaction(evt); ServerTransaction transaction = getServerTransaction(evt);
if (transaction != null) { if (transaction != null) {
transaction.sendResponse(response); transaction.sendResponse(response);
transaction.getDialog().delete();
transaction.terminate(); transaction.terminate();
} else { } else {
logger.info("processRequest serverTransactionId is null."); logger.info("processRequest serverTransactionId is null.");

2
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/response/impl/ByeResponseProcessor.java

@ -21,13 +21,11 @@ public class ByeResponseProcessor implements ISIPResponseProcessor {
* *
* @param evt * @param evt
* @param layer * @param layer
* @param transaction
* @param config * @param config
*/ */
@Override @Override
public void process(ResponseEvent evt, SipLayer layer, SipConfig config) { public void process(ResponseEvent evt, SipLayer layer, SipConfig config) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
System.out.println( );
} }
} }

32
src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRunner.java

@ -45,18 +45,18 @@ public class ZLMRunner implements CommandLineRunner {
mediaServerService.clearMediaServerForOnline(); mediaServerService.clearMediaServerForOnline();
// 将配置文件的meida配置写入数据库 // 将配置文件的meida配置写入数据库
MediaServerItem presetMediaServer = mediaServerService.getOneByHostAndPort( // MediaServerItem presetMediaServer = mediaServerService.getOneByHostAndPort(
mediaConfig.getIp(), mediaConfig.getHttpPort()); // mediaConfig.getIp(), mediaConfig.getHttpPort());
if (presetMediaServer != null) { // if (presetMediaServer != null) {
MediaServerItem mediaSerItem = mediaConfig.getMediaSerItem(); // MediaServerItem mediaSerItem = mediaConfig.getMediaSerItem();
mediaSerItem.setId(presetMediaServer.getId()); // mediaSerItem.setId(presetMediaServer.getId());
mediaServerService.update(mediaSerItem); // mediaServerService.update(mediaSerItem);
}else { // }else {
if (mediaConfig.getId() != null) { // if (mediaConfig.getId() != null) {
MediaServerItem mediaSerItem = mediaConfig.getMediaSerItem(); // MediaServerItem mediaSerItem = mediaConfig.getMediaSerItem();
mediaServerService.add(mediaSerItem); // mediaServerService.add(mediaSerItem);
} // }
} // }
// 订阅 zlm启动事件, 新的zlm也会从这里进入系统 // 订阅 zlm启动事件, 新的zlm也会从这里进入系统
hookSubscribe.addSubscribe(ZLMHttpHookSubscribe.HookType.on_server_started,null, hookSubscribe.addSubscribe(ZLMHttpHookSubscribe.HookType.on_server_started,null,
@ -73,8 +73,8 @@ public class ZLMRunner implements CommandLineRunner {
logger.info("等待默认zlm接入..."); logger.info("等待默认zlm接入...");
// 获取所有的zlm, 并开启主动连接 // 获取所有的zlm, 并开启主动连接
List<MediaServerItem> all = mediaServerService.getAll(); List<MediaServerItem> all = mediaServerService.getAllFromDatabase();
if (presetMediaServer == null) { if (all.size() == 0) {
all.add(mediaConfig.getMediaSerItem()); all.add(mediaConfig.getMediaSerItem());
} }
for (MediaServerItem mediaServerItem : all) { for (MediaServerItem mediaServerItem : all) {
@ -99,14 +99,16 @@ public class ZLMRunner implements CommandLineRunner {
Set<String> allZlmId = startGetMedia.keySet(); Set<String> allZlmId = startGetMedia.keySet();
for (String id : allZlmId) { for (String id : allZlmId) {
logger.error("[ {} ]]主动连接失败,不再主动连接", id); logger.error("[ {} ]]主动连接失败,不再主动连接", id);
startGetMedia.put(id, false);
} }
startGetMedia = null;
} }
// TODO 清理数据库中与redis不匹配的zlm
} }
}, 60 * 1000 * 2); }, 60 * 1000 * 2);
} }
public ZLMServerConfig getMediaServerConfig(MediaServerItem mediaServerItem) { public ZLMServerConfig getMediaServerConfig(MediaServerItem mediaServerItem) {
if (startGetMedia == null) return null;
if ( startGetMedia.get(mediaServerItem.getId()) == null || !startGetMedia.get(mediaServerItem.getId())) return null; if ( startGetMedia.get(mediaServerItem.getId()) == null || !startGetMedia.get(mediaServerItem.getId())) return null;
JSONObject responseJSON = zlmresTfulUtils.getMediaServerConfig(mediaServerItem); JSONObject responseJSON = zlmresTfulUtils.getMediaServerConfig(mediaServerItem);
ZLMServerConfig ZLMServerConfig = null; ZLMServerConfig ZLMServerConfig = null;

43
src/main/java/com/genersoft/iot/vmp/service/IDeviceAlarmService.java

@ -0,0 +1,43 @@
package com.genersoft.iot.vmp.service;
import com.genersoft.iot.vmp.gb28181.bean.DeviceAlarm;
import com.github.pagehelper.PageInfo;
import java.util.List;
/**
* 报警相关业务处理
*/
public interface IDeviceAlarmService {
/**
* 根据多个添加获取报警列表
* @param page 当前页
* @param count 每页数量
* @param deviceId 设备id
* @param alarmPriority 报警级别, 1为一级警情, 2为二级警情, 3为三级警情, 4为四级 警情-
* @param alarmMethod 报警方式 , 1为电话报警, 2为设备报警, 3为短信报警, 4为 GPS报警, 5为视频报警, 6为设备故障报警,
* 7其他报警;可以为直接组合如12为电话报警或 设备报警-
* @param alarmType 报警类型
* @param startTime 开始时间
* @param endTime 结束时间
* @return 报警列表
*/
PageInfo<DeviceAlarm> getAllAlarm(int page, int count, String deviceId, String alarmPriority, String alarmMethod,
String alarmType, String startTime, String endTime);
/**
* 添加一个报警
* @param deviceAlarm 添加报警
*/
void add(DeviceAlarm deviceAlarm);
/**
* 清空时间以前的报警
* @param id 数据库id
* @param deviceIdList 制定需要清理的设备id
* @param time 不写时间则清空所有时间的
*/
void clearAlarmBeforeTime(Integer id, List<String> deviceIdList, String time);
}

2
src/main/java/com/genersoft/iot/vmp/service/IMediaServerService.java

@ -14,6 +14,8 @@ public interface IMediaServerService {
List<MediaServerItem> getAll(); List<MediaServerItem> getAll();
List<MediaServerItem> getAllFromDatabase();
List<MediaServerItem> getAllOnline(); List<MediaServerItem> getAllOnline();
MediaServerItem getOne(String generalMediaServerId); MediaServerItem getOne(String generalMediaServerId);

37
src/main/java/com/genersoft/iot/vmp/service/impl/DeviceAlarmServiceImpl.java

@ -0,0 +1,37 @@
package com.genersoft.iot.vmp.service.impl;
import com.genersoft.iot.vmp.gb28181.bean.DeviceAlarm;
import com.genersoft.iot.vmp.media.zlm.dto.StreamProxyItem;
import com.genersoft.iot.vmp.service.IDeviceAlarmService;
import com.genersoft.iot.vmp.storager.dao.DeviceAlarmMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class DeviceAlarmServiceImpl implements IDeviceAlarmService {
@Autowired
private DeviceAlarmMapper deviceAlarmMapper;
@Override
public PageInfo<DeviceAlarm> getAllAlarm(int page, int count, String deviceId, String alarmPriority, String alarmMethod, String alarmType, String startTime, String endTime) {
PageHelper.startPage(page, count);
List<DeviceAlarm> all = deviceAlarmMapper.query(deviceId, alarmPriority, alarmMethod, alarmType, startTime, endTime);
return new PageInfo<>(all);
}
@Override
public void add(DeviceAlarm deviceAlarm) {
deviceAlarmMapper.add(deviceAlarm);
}
@Override
public void clearAlarmBeforeTime(Integer id, List<String> deviceIdList, String time) {
deviceAlarmMapper.clearAlarmBeforeTime(id, deviceIdList, time);
}
}

22
src/main/java/com/genersoft/iot/vmp/service/impl/MediaServerServiceImpl.java

@ -181,6 +181,12 @@ public class MediaServerServiceImpl implements IMediaServerService, CommandLineR
return result; return result;
} }
@Override
public List<MediaServerItem> getAllFromDatabase() {
return mediaServerMapper.queryAll();
}
@Override @Override
public List<MediaServerItem> getAllOnline() { public List<MediaServerItem> getAllOnline() {
String key = VideoManagerConstants.MEDIA_SERVERS_ONLINE_PREFIX; String key = VideoManagerConstants.MEDIA_SERVERS_ONLINE_PREFIX;
@ -251,18 +257,16 @@ public class MediaServerServiceImpl implements IMediaServerService, CommandLineR
if (mediaConfig.getRtspSSLPort() == 0) serverItemFromConfig.setRtspSSLPort(zlmServerConfig.getRtspSSlport()); if (mediaConfig.getRtspSSLPort() == 0) serverItemFromConfig.setRtspSSLPort(zlmServerConfig.getRtspSSlport());
if (mediaConfig.getRtpProxyPort() == 0) serverItemFromConfig.setRtpProxyPort(zlmServerConfig.getRtpProxyPort()); if (mediaConfig.getRtpProxyPort() == 0) serverItemFromConfig.setRtpProxyPort(zlmServerConfig.getRtpProxyPort());
if (serverItem != null){ if (serverItem != null){
// 可能是同一个zlm但id发生了变化 mediaServerMapper.delDefault();
if (!serverItem.getId().equals(zlmServerConfig.getGeneralMediaServerId())) {
mediaServerMapper.delOne(serverItem.getId());
redisUtil.del(VideoManagerConstants.MEDIA_SERVER_PREFIX + serverItem.getId());
String key = VideoManagerConstants.MEDIA_SERVER_PREFIX + serverItemFromConfig.getId();
serverItemFromConfig.setSsrcConfig(new SsrcConfig(serverItemFromConfig.getId(), null, sipConfig.getSipDomain()));
redisUtil.set(key, serverItemFromConfig);
mediaServerMapper.add(serverItemFromConfig); mediaServerMapper.add(serverItemFromConfig);
String key = VideoManagerConstants.MEDIA_SERVER_PREFIX + serverItemFromConfig.getId();
MediaServerItem serverItemInRedis = (MediaServerItem)redisUtil.get(key);
if (serverItemInRedis != null) {
serverItemFromConfig.setSsrcConfig(serverItemInRedis.getSsrcConfig());
}else { }else {
mediaServerMapper.update(serverItemFromConfig); serverItemFromConfig.setSsrcConfig(new SsrcConfig(serverItemFromConfig.getId(), null, sipConfig.getSipDomain()));
} }
redisUtil.set(key, serverItemFromConfig);
}else { }else {
String key = VideoManagerConstants.MEDIA_SERVER_PREFIX + serverItemFromConfig.getId(); String key = VideoManagerConstants.MEDIA_SERVER_PREFIX + serverItemFromConfig.getId();
serverItemFromConfig.setSsrcConfig(new SsrcConfig(serverItemFromConfig.getId(), null, sipConfig.getSipDomain())); serverItemFromConfig.setSsrcConfig(new SsrcConfig(serverItemFromConfig.getId(), null, sipConfig.getSipDomain()));

48
src/main/java/com/genersoft/iot/vmp/storager/dao/DeviceAlarmMapper.java

@ -0,0 +1,48 @@
package com.genersoft.iot.vmp.storager.dao;
import com.genersoft.iot.vmp.gb28181.bean.DeviceAlarm;
import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
import com.genersoft.iot.vmp.vmanager.gb28181.platform.bean.ChannelReduce;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;
import java.util.List;
/**
* 用于存储设备的报警信息
*/
@Mapper
@Repository
public interface DeviceAlarmMapper {
@Insert("INSERT INTO device_alarm (deviceId, alarmPriority, alarmMethod, alarmTime, alarmDescription, longitude, latitude, alarmType ) " +
"VALUES ('${deviceId}', '${alarmPriority}', '${alarmMethod}', '${alarmTime}', '${alarmDescription}', ${longitude}, ${latitude}, '${alarmType}')")
int add(DeviceAlarm alarm);
@Select(value = {" <script>" +
" SELECT * FROM device_alarm " +
" WHERE 1=1 " +
" <if test=\"deviceId != null\" > AND deviceId = '${deviceId}'</if>" +
" <if test=\"alarmPriority != null\" > AND alarmPriority = '${alarmPriority}' </if>" +
" <if test=\"alarmMethod != null\" > AND alarmMethod = '${alarmMethod}' </if>" +
" <if test=\"alarmType != null\" > AND alarmType = '${alarmType}' </if>" +
" <if test=\"startTime != null\" > AND alarmTime &gt;= '${startTime}' </if>" +
" <if test=\"endTime != null\" > AND alarmTime &lt;= '${endTime}' </if>" +
" ORDER BY alarmTime ASC " +
" </script>"})
List<DeviceAlarm> query(String deviceId, String alarmPriority, String alarmMethod,
String alarmType, String startTime, String endTime);
@Delete(" <script>" +
"DELETE FROM device_alarm WHERE 1=1 " +
" <if test=\"deviceIdList != null and id == null \" > AND deviceId in " +
"<foreach collection='deviceIdList' item='item' open='(' separator=',' close=')' > '${item}'</foreach>" +
"</if>" +
" <if test=\"time != null and id == null \" > AND alarmTime &lt;= '${time}'</if>" +
" <if test=\"id != null\" > AND id = ${id}</if>" +
" </script>"
)
int clearAlarmBeforeTime(Integer id, List<String> deviceIdList, String time);
}

6
src/main/java/com/genersoft/iot/vmp/storager/dao/MediaServerMapper.java

@ -94,6 +94,12 @@ public interface MediaServerMapper {
@Select("DELETE FROM media_server WHERE id='${id}'") @Select("DELETE FROM media_server WHERE id='${id}'")
void delOne(String id); void delOne(String id);
@Select("DELETE FROM media_server WHERE ip='${host}' and httpPort=${port}")
void delOneByIPAndPort(String host, int port);
@Select("DELETE FROM media_server WHERE defaultServer=1;")
void delDefault();
@Select("SELECT * FROM media_server WHERE ip='${host}' and httpPort=${port}") @Select("SELECT * FROM media_server WHERE ip='${host}' and httpPort=${port}")
MediaServerItem queryOneByHostAndPort(String host, int port); MediaServerItem queryOneByHostAndPort(String host, int port);
} }

131
src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/alarm/AlarmController.java

@ -0,0 +1,131 @@
package com.genersoft.iot.vmp.vmanager.gb28181.alarm;
import com.genersoft.iot.vmp.gb28181.bean.DeviceAlarm;
import com.genersoft.iot.vmp.service.IDeviceAlarmService;
import com.genersoft.iot.vmp.service.IGbStreamService;
import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
@Api(tags = "报警信息管理")
@CrossOrigin
@RestController
@RequestMapping("/api/alarm")
public class AlarmController {
@Autowired
private IDeviceAlarmService deviceAlarmService;
private SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
/**
* 分页查询报警
*
* @param deviceId 设备id
* @param page 当前页
* @param count 每页查询数量
* @param alarmPriority 报警级别
* @param alarmMethod 报警方式
* @param alarmType 报警类型
* @param startTime 开始时间
* @param endTime 结束时间
* @return
*/
@ApiOperation("分页查询报警")
@GetMapping("/all")
@ApiImplicitParams({
@ApiImplicitParam(name="deviceId", value = "设备id", dataTypeClass = String.class),
@ApiImplicitParam(name="page", value = "当前页", required = true ,dataTypeClass = Integer.class),
@ApiImplicitParam(name="count", value = "每页查询数量", required = true ,dataTypeClass = Integer.class),
@ApiImplicitParam(name="alarmPriority", value = "查询内容" ,dataTypeClass = String.class),
@ApiImplicitParam(name="alarmMethod", value = "查询内容" ,dataTypeClass = String.class),
@ApiImplicitParam(name="alarmMethod", value = "查询内容" ,dataTypeClass = String.class),
@ApiImplicitParam(name="alarmType", value = "查询内容" ,dataTypeClass = String.class),
@ApiImplicitParam(name="startTime", value = "查询内容" ,dataTypeClass = String.class),
@ApiImplicitParam(name="endTime", value = "查询内容" ,dataTypeClass = String.class),
})
public ResponseEntity<PageInfo<DeviceAlarm>> getAll(
int page, int count,
@RequestParam(required = false) String deviceId,
@RequestParam(required = false) String alarmPriority,
@RequestParam(required = false) String alarmMethod,
@RequestParam(required = false) String alarmType,
@RequestParam(required = false) String startTime,
@RequestParam(required = false) String endTime
) {
if (StringUtils.isEmpty(alarmPriority)) alarmPriority = null;
if (StringUtils.isEmpty(alarmMethod)) alarmMethod = null;
if (StringUtils.isEmpty(alarmType)) alarmType = null;
if (StringUtils.isEmpty(startTime)) startTime = null;
if (StringUtils.isEmpty(endTime)) endTime = null;
try {
format.parse(startTime);
format.parse(endTime);
} catch (ParseException e) {
return new ResponseEntity<>(null, HttpStatus.BAD_REQUEST);
}
PageInfo<DeviceAlarm> allAlarm = deviceAlarmService.getAllAlarm(page, count, deviceId, alarmPriority, alarmMethod,
alarmType, startTime, endTime);
return new ResponseEntity<>(allAlarm, HttpStatus.OK);
}
/**
* 删除报警
*
* @param id 报警id
* @param deviceIds 多个设备id,逗号分隔
* @param time 结束时间(这个时间之前的报警会被删除)
* @return
*/
@ApiOperation("分页查询报警")
@DeleteMapping("/delete")
@ApiImplicitParams({
@ApiImplicitParam(name="id", value = "ID", required = false ,dataTypeClass = Integer.class),
@ApiImplicitParam(name="deviceIds", value = "多个设备id,逗号分隔", required = false ,dataTypeClass = String.class),
@ApiImplicitParam(name="time", value = "结束时间", required = false ,dataTypeClass = String.class),
})
public ResponseEntity<WVPResult<String>> delete(
@RequestParam(required = false) Integer id,
@RequestParam(required = false) String deviceIds,
@RequestParam(required = false) String time
) {
if (StringUtils.isEmpty(id)) id = null;
if (StringUtils.isEmpty(deviceIds)) deviceIds = null;
if (StringUtils.isEmpty(time)) time = null;
try {
if (time != null) {
format.parse(time);
}
} catch (ParseException e) {
return new ResponseEntity<>(null, HttpStatus.BAD_REQUEST);
}
String[] deviceIdArray = deviceIds.split(",");
List<String> deviceIdList = Arrays.asList(deviceIdArray);
deviceAlarmService.clearAlarmBeforeTime(id, deviceIdList, time);
WVPResult wvpResult = new WVPResult();
wvpResult.setCode(0);
wvpResult.setMsg("success");
return new ResponseEntity<WVPResult<String>>(wvpResult, HttpStatus.OK);
}
}

BIN
src/main/resources/wvp.sqlite

Binary file not shown.

18930
web_src/package-lock.json

File diff suppressed because it is too large
Loading…
Cancel
Save