Commit 724b288232e1614de1b789d0910fe3e3db765e52
1 parent
6560a7ad
优化内存溢出的问题
优化zlm集群默认zlm的存储 添加报警的存储以及相关接口 添加单元测试
Showing
20 changed files
with
372 additions
and
57 deletions
Too many changes to show.
To preserve performance only 20 of 21 files are displayed.
pom.xml
| ... | ... | @@ -221,6 +221,12 @@ |
| 221 | 221 | <scope>system</scope> |
| 222 | 222 | <systemPath>${project.basedir}/libs/onvif-java-1.0.2.jar</systemPath> |
| 223 | 223 | </dependency> |
| 224 | + | |
| 225 | + <dependency> | |
| 226 | + <groupId>org.springframework.boot</groupId> | |
| 227 | + <artifactId>spring-boot-starter-test</artifactId> | |
| 228 | +<!-- <scope>test</scope>--> | |
| 229 | + </dependency> | |
| 224 | 230 | </dependencies> |
| 225 | 231 | |
| 226 | 232 | ... | ... |
src/main/java/com/genersoft/iot/vmp/VManageBootstrap.java
| ... | ... | @@ -8,6 +8,9 @@ import org.springframework.context.ConfigurableApplicationContext; |
| 8 | 8 | import org.springframework.scheduling.annotation.EnableScheduling; |
| 9 | 9 | import springfox.documentation.oas.annotations.EnableOpenApi; |
| 10 | 10 | |
| 11 | +/** | |
| 12 | + * | |
| 13 | + */ | |
| 11 | 14 | @SpringBootApplication |
| 12 | 15 | @EnableScheduling |
| 13 | 16 | @EnableOpenApi |
| ... | ... | @@ -22,7 +25,7 @@ public class VManageBootstrap extends LogManager { |
| 22 | 25 | public static void restart() { |
| 23 | 26 | context.close(); |
| 24 | 27 | VManageBootstrap.context = SpringApplication.run(VManageBootstrap.class, args); |
| 25 | - | |
| 26 | 28 | } |
| 29 | + | |
| 27 | 30 | |
| 28 | 31 | } | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/bean/DeviceAlarm.java
| ... | ... | @@ -4,6 +4,11 @@ package com.genersoft.iot.vmp.gb28181.bean; |
| 4 | 4 | public class DeviceAlarm { |
| 5 | 5 | |
| 6 | 6 | /** |
| 7 | + * 数据库id | |
| 8 | + */ | |
| 9 | + private String id; | |
| 10 | + | |
| 11 | + /** | |
| 7 | 12 | * 设备Id |
| 8 | 13 | */ |
| 9 | 14 | private String deviceId; |
| ... | ... | @@ -45,6 +50,14 @@ public class DeviceAlarm { |
| 45 | 50 | private String alarmType; |
| 46 | 51 | |
| 47 | 52 | |
| 53 | + public String getId() { | |
| 54 | + return id; | |
| 55 | + } | |
| 56 | + | |
| 57 | + public void setId(String id) { | |
| 58 | + this.id = id; | |
| 59 | + } | |
| 60 | + | |
| 48 | 61 | public String getDeviceId() { |
| 49 | 62 | return deviceId; |
| 50 | 63 | } | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/SIPProcessorFactory.java
| ... | ... | @@ -9,6 +9,7 @@ import javax.sip.message.Response; |
| 9 | 9 | |
| 10 | 10 | import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommanderFroPlatform; |
| 11 | 11 | import com.genersoft.iot.vmp.media.zlm.ZLMRTPServerFactory; |
| 12 | +import com.genersoft.iot.vmp.service.IDeviceAlarmService; | |
| 12 | 13 | import com.genersoft.iot.vmp.service.IMediaServerService; |
| 13 | 14 | import com.genersoft.iot.vmp.storager.IRedisCatchStorage; |
| 14 | 15 | import com.genersoft.iot.vmp.gb28181.transmit.response.impl.*; |
| ... | ... | @@ -74,6 +75,9 @@ public class SIPProcessorFactory { |
| 74 | 75 | private SIPCommanderFroPlatform cmderFroPlatform; |
| 75 | 76 | |
| 76 | 77 | @Autowired |
| 78 | + private IDeviceAlarmService deviceAlarmService; | |
| 79 | + | |
| 80 | + @Autowired | |
| 77 | 81 | private RedisUtil redis; |
| 78 | 82 | |
| 79 | 83 | @Autowired |
| ... | ... | @@ -178,6 +182,7 @@ public class SIPProcessorFactory { |
| 178 | 182 | processor.setOffLineDetector(offLineDetector); |
| 179 | 183 | processor.setCmder(cmder); |
| 180 | 184 | processor.setCmderFroPlatform(cmderFroPlatform); |
| 185 | + processor.setDeviceAlarmService(deviceAlarmService); | |
| 181 | 186 | processor.setStorager(storager); |
| 182 | 187 | processor.setRedisCatchStorage(redisCatchStorage); |
| 183 | 188 | return processor; | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/ByeRequestProcessor.java
| 1 | 1 | package com.genersoft.iot.vmp.gb28181.transmit.request.impl; |
| 2 | 2 | |
| 3 | +import javax.sip.*; | |
| 3 | 4 | import javax.sip.address.SipURI; |
| 4 | -import javax.sip.Dialog; | |
| 5 | -import javax.sip.DialogState; | |
| 6 | -import javax.sip.InvalidArgumentException; | |
| 7 | -import javax.sip.RequestEvent; | |
| 8 | -import javax.sip.SipException; | |
| 9 | 5 | import javax.sip.header.FromHeader; |
| 10 | 6 | import javax.sip.header.HeaderAddress; |
| 11 | 7 | import javax.sip.header.ToHeader; |
| ... | ... | @@ -107,7 +103,9 @@ public class ByeRequestProcessor extends SIPRequestAbstractProcessor { |
| 107 | 103 | */ |
| 108 | 104 | private void responseAck(RequestEvent evt) throws SipException, InvalidArgumentException, ParseException { |
| 109 | 105 | Response response = getMessageFactory().createResponse(Response.OK, evt.getRequest()); |
| 110 | - getServerTransaction(evt).sendResponse(response); | |
| 106 | + ServerTransaction serverTransaction = getServerTransaction(evt); | |
| 107 | + serverTransaction.sendResponse(response); | |
| 108 | + if (serverTransaction.getDialog() != null) serverTransaction.getDialog().delete(); | |
| 111 | 109 | } |
| 112 | 110 | |
| 113 | 111 | public IRedisCatchStorage getRedisCatchStorage() { | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/InviteRequestProcessor.java
| 1 | 1 | package com.genersoft.iot.vmp.gb28181.transmit.request.impl; |
| 2 | 2 | |
| 3 | 3 | import javax.sdp.*; |
| 4 | -import javax.sip.InvalidArgumentException; | |
| 5 | -import javax.sip.RequestEvent; | |
| 6 | -import javax.sip.SipException; | |
| 7 | -import javax.sip.SipFactory; | |
| 4 | +import javax.sip.*; | |
| 8 | 5 | import javax.sip.address.Address; |
| 9 | 6 | import javax.sip.address.SipURI; |
| 10 | 7 | import javax.sip.header.*; |
| ... | ... | @@ -239,7 +236,9 @@ public class InviteRequestProcessor extends SIPRequestAbstractProcessor { |
| 239 | 236 | Response response = null; |
| 240 | 237 | try { |
| 241 | 238 | response = getMessageFactory().createResponse(event.getResponse().getStatusCode(), evt.getRequest()); |
| 242 | - getServerTransaction(evt).sendResponse(response); | |
| 239 | + ServerTransaction serverTransaction = getServerTransaction(evt); | |
| 240 | + serverTransaction.sendResponse(response); | |
| 241 | + if (serverTransaction.getDialog() != null) serverTransaction.getDialog().delete(); | |
| 243 | 242 | } catch (ParseException | SipException | InvalidArgumentException e) { |
| 244 | 243 | e.printStackTrace(); |
| 245 | 244 | } |
| ... | ... | @@ -384,13 +383,17 @@ public class InviteRequestProcessor extends SIPRequestAbstractProcessor { |
| 384 | 383 | */ |
| 385 | 384 | private void responseAck(RequestEvent evt, int statusCode) throws SipException, InvalidArgumentException, ParseException { |
| 386 | 385 | Response response = getMessageFactory().createResponse(statusCode, evt.getRequest()); |
| 387 | - getServerTransaction(evt).sendResponse(response); | |
| 386 | + ServerTransaction serverTransaction = getServerTransaction(evt); | |
| 387 | + serverTransaction.sendResponse(response); | |
| 388 | + if (serverTransaction.getDialog() != null) serverTransaction.getDialog().delete(); | |
| 388 | 389 | } |
| 389 | 390 | |
| 390 | 391 | private void responseAck(RequestEvent evt, int statusCode, String msg) throws SipException, InvalidArgumentException, ParseException { |
| 391 | 392 | Response response = getMessageFactory().createResponse(statusCode, evt.getRequest()); |
| 392 | 393 | response.setReasonPhrase(msg); |
| 393 | - getServerTransaction(evt).sendResponse(response); | |
| 394 | + ServerTransaction serverTransaction = getServerTransaction(evt); | |
| 395 | + serverTransaction.sendResponse(response); | |
| 396 | + if (serverTransaction.getDialog() != null) serverTransaction.getDialog().delete(); | |
| 394 | 397 | } |
| 395 | 398 | |
| 396 | 399 | /** | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/MessageRequestProcessor.java
| ... | ... | @@ -4,17 +4,12 @@ import java.io.ByteArrayInputStream; |
| 4 | 4 | import java.text.ParseException; |
| 5 | 5 | import java.util.*; |
| 6 | 6 | |
| 7 | +import javax.sip.*; | |
| 7 | 8 | import javax.sip.address.SipURI; |
| 8 | 9 | |
| 9 | 10 | import javax.sip.header.FromHeader; |
| 10 | 11 | import javax.sip.header.HeaderAddress; |
| 11 | 12 | import javax.sip.header.ToHeader; |
| 12 | -import javax.sip.InvalidArgumentException; | |
| 13 | -import javax.sip.ListeningPoint; | |
| 14 | -import javax.sip.ObjectInUseException; | |
| 15 | -import javax.sip.RequestEvent; | |
| 16 | -import javax.sip.SipException; | |
| 17 | -import javax.sip.SipProvider; | |
| 18 | 13 | import javax.sip.message.Request; |
| 19 | 14 | import javax.sip.message.Response; |
| 20 | 15 | |
| ... | ... | @@ -35,6 +30,7 @@ import com.genersoft.iot.vmp.gb28181.transmit.request.SIPRequestAbstractProcesso |
| 35 | 30 | import com.genersoft.iot.vmp.gb28181.utils.DateUtil; |
| 36 | 31 | import com.genersoft.iot.vmp.gb28181.utils.NumericUtil; |
| 37 | 32 | import com.genersoft.iot.vmp.gb28181.utils.XmlUtil; |
| 33 | +import com.genersoft.iot.vmp.service.IDeviceAlarmService; | |
| 38 | 34 | import com.genersoft.iot.vmp.storager.IRedisCatchStorage; |
| 39 | 35 | import com.genersoft.iot.vmp.storager.IVideoManagerStorager; |
| 40 | 36 | import com.genersoft.iot.vmp.utils.GpsUtil; |
| ... | ... | @@ -84,6 +80,8 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor { |
| 84 | 80 | |
| 85 | 81 | private DeviceOffLineDetector offLineDetector; |
| 86 | 82 | |
| 83 | + private IDeviceAlarmService deviceAlarmService; | |
| 84 | + | |
| 87 | 85 | private final static String CACHE_RECORDINFO_KEY = "CACHE_RECORDINFO_"; |
| 88 | 86 | |
| 89 | 87 | private static final String MESSAGE_KEEP_ALIVE = "Keepalive"; |
| ... | ... | @@ -738,7 +736,9 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor { |
| 738 | 736 | storager.insertMobilePosition(mobilePosition); |
| 739 | 737 | } |
| 740 | 738 | } |
| 741 | - // TODO: 需要实现存储报警信息、报警分类 | |
| 739 | + System.out.println("存储报警信息、报警分类"); | |
| 740 | + // 存储报警信息、报警分类 | |
| 741 | + deviceAlarmService.add(deviceAlarm); | |
| 742 | 742 | |
| 743 | 743 | if (offLineDetector.isOnline(deviceId)) { |
| 744 | 744 | publisher.deviceAlarmEventPublish(deviceAlarm); |
| ... | ... | @@ -779,7 +779,9 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor { |
| 779 | 779 | }else{ |
| 780 | 780 | logger.warn("收到[ "+deviceId+" ]心跳信息, 但是设备不存在, 回复404"); |
| 781 | 781 | Response response = getMessageFactory().createResponse(Response.NOT_FOUND, evt.getRequest()); |
| 782 | - getServerTransaction(evt).sendResponse(response); | |
| 782 | + ServerTransaction serverTransaction = getServerTransaction(evt); | |
| 783 | + serverTransaction.sendResponse(response); | |
| 784 | + if (serverTransaction.getDialog() != null) serverTransaction.getDialog().delete(); | |
| 783 | 785 | } |
| 784 | 786 | |
| 785 | 787 | // if (device != null && device.getOnline() == 1) { |
| ... | ... | @@ -987,7 +989,9 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor { |
| 987 | 989 | */ |
| 988 | 990 | private void responseAck(RequestEvent evt) throws SipException, InvalidArgumentException, ParseException { |
| 989 | 991 | Response response = getMessageFactory().createResponse(Response.OK, evt.getRequest()); |
| 990 | - getServerTransaction(evt).sendResponse(response); | |
| 992 | + ServerTransaction serverTransaction = getServerTransaction(evt); | |
| 993 | + serverTransaction.sendResponse(response); | |
| 994 | + if (serverTransaction.getDialog() != null) serverTransaction.getDialog().delete(); | |
| 991 | 995 | } |
| 992 | 996 | |
| 993 | 997 | /*** |
| ... | ... | @@ -999,7 +1003,9 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor { |
| 999 | 1003 | */ |
| 1000 | 1004 | private void response404Ack(RequestEvent evt) throws SipException, InvalidArgumentException, ParseException { |
| 1001 | 1005 | Response response = getMessageFactory().createResponse(Response.NOT_FOUND, evt.getRequest()); |
| 1002 | - getServerTransaction(evt).sendResponse(response); | |
| 1006 | + ServerTransaction serverTransaction = getServerTransaction(evt); | |
| 1007 | + serverTransaction.sendResponse(response); | |
| 1008 | + if (serverTransaction.getDialog() != null) serverTransaction.getDialog().delete(); | |
| 1003 | 1009 | } |
| 1004 | 1010 | |
| 1005 | 1011 | private Element getRootElement(RequestEvent evt) throws DocumentException { |
| ... | ... | @@ -1049,4 +1055,8 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor { |
| 1049 | 1055 | public void setCmderFroPlatform(SIPCommanderFroPlatform cmderFroPlatform) { |
| 1050 | 1056 | this.cmderFroPlatform = cmderFroPlatform; |
| 1051 | 1057 | } |
| 1058 | + | |
| 1059 | + public void setDeviceAlarmService(IDeviceAlarmService deviceAlarmService) { | |
| 1060 | + this.deviceAlarmService = deviceAlarmService; | |
| 1061 | + } | |
| 1052 | 1062 | } | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/NotifyRequestProcessor.java
| ... | ... | @@ -6,6 +6,7 @@ import java.util.Iterator; |
| 6 | 6 | |
| 7 | 7 | import javax.sip.InvalidArgumentException; |
| 8 | 8 | import javax.sip.RequestEvent; |
| 9 | +import javax.sip.ServerTransaction; | |
| 9 | 10 | import javax.sip.SipException; |
| 10 | 11 | import javax.sip.message.Request; |
| 11 | 12 | import javax.sip.message.Response; |
| ... | ... | @@ -342,7 +343,9 @@ public class NotifyRequestProcessor extends SIPRequestAbstractProcessor { |
| 342 | 343 | */ |
| 343 | 344 | private void response200Ok(RequestEvent evt) throws SipException, InvalidArgumentException, ParseException { |
| 344 | 345 | Response response = getMessageFactory().createResponse(Response.OK, evt.getRequest()); |
| 345 | - getServerTransaction(evt).sendResponse(response); | |
| 346 | + ServerTransaction serverTransaction = getServerTransaction(evt); | |
| 347 | + serverTransaction.sendResponse(response); | |
| 348 | + if (serverTransaction.getDialog() != null) serverTransaction.getDialog().delete(); | |
| 346 | 349 | } |
| 347 | 350 | |
| 348 | 351 | private Element getRootElement(RequestEvent evt) throws DocumentException { | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/RegisterRequestProcessor.java
| ... | ... | @@ -7,6 +7,7 @@ import java.util.Locale; |
| 7 | 7 | |
| 8 | 8 | import javax.sip.InvalidArgumentException; |
| 9 | 9 | import javax.sip.RequestEvent; |
| 10 | +import javax.sip.ServerTransaction; | |
| 10 | 11 | import javax.sip.SipException; |
| 11 | 12 | import javax.sip.header.AuthorizationHeader; |
| 12 | 13 | import javax.sip.header.ContactHeader; |
| ... | ... | @@ -112,7 +113,9 @@ public class RegisterRequestProcessor extends SIPRequestAbstractProcessor { |
| 112 | 113 | ExpiresHeader expiresHeader = (ExpiresHeader) request.getHeader(Expires.NAME); |
| 113 | 114 | if (expiresHeader == null) { |
| 114 | 115 | response = getMessageFactory().createResponse(Response.BAD_REQUEST, request); |
| 115 | - getServerTransaction(evt).sendResponse(response); | |
| 116 | + ServerTransaction serverTransaction = getServerTransaction(evt); | |
| 117 | + serverTransaction.sendResponse(response); | |
| 118 | + if (serverTransaction.getDialog() != null) serverTransaction.getDialog().delete(); | |
| 116 | 119 | return; |
| 117 | 120 | } |
| 118 | 121 | // 添加Contact头 |
| ... | ... | @@ -159,7 +162,9 @@ public class RegisterRequestProcessor extends SIPRequestAbstractProcessor { |
| 159 | 162 | } |
| 160 | 163 | } |
| 161 | 164 | |
| 162 | - getServerTransaction(evt).sendResponse(response); | |
| 165 | + ServerTransaction serverTransaction = getServerTransaction(evt); | |
| 166 | + serverTransaction.sendResponse(response); | |
| 167 | + if (serverTransaction.getDialog() != null) serverTransaction.getDialog().delete(); | |
| 163 | 168 | // 注册成功 |
| 164 | 169 | // 保存到redis |
| 165 | 170 | // 下发catelog查询目录 | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/SubscribeRequestProcessor.java
| ... | ... | @@ -27,9 +27,6 @@ public class SubscribeRequestProcessor extends SIPRequestAbstractProcessor { |
| 27 | 27 | * 处理SUBSCRIBE请求 |
| 28 | 28 | * |
| 29 | 29 | * @param evt |
| 30 | - * @param layer | |
| 31 | - * @param transaction | |
| 32 | - * @param config | |
| 33 | 30 | */ |
| 34 | 31 | @Override |
| 35 | 32 | public void process(RequestEvent evt) { |
| ... | ... | @@ -46,6 +43,7 @@ public class SubscribeRequestProcessor extends SIPRequestAbstractProcessor { |
| 46 | 43 | ServerTransaction transaction = getServerTransaction(evt); |
| 47 | 44 | if (transaction != null) { |
| 48 | 45 | transaction.sendResponse(response); |
| 46 | + transaction.getDialog().delete(); | |
| 49 | 47 | transaction.terminate(); |
| 50 | 48 | } else { |
| 51 | 49 | logger.info("processRequest serverTransactionId is null."); | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/response/impl/ByeResponseProcessor.java
| ... | ... | @@ -21,13 +21,11 @@ public class ByeResponseProcessor implements ISIPResponseProcessor { |
| 21 | 21 | * |
| 22 | 22 | * @param evt |
| 23 | 23 | * @param layer |
| 24 | - * @param transaction | |
| 25 | 24 | * @param config |
| 26 | 25 | */ |
| 27 | 26 | @Override |
| 28 | 27 | public void process(ResponseEvent evt, SipLayer layer, SipConfig config) { |
| 29 | 28 | // TODO Auto-generated method stub |
| 30 | - System.out.println( ); | |
| 31 | 29 | } |
| 32 | 30 | |
| 33 | 31 | } | ... | ... |
src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRunner.java
| ... | ... | @@ -45,18 +45,18 @@ public class ZLMRunner implements CommandLineRunner { |
| 45 | 45 | mediaServerService.clearMediaServerForOnline(); |
| 46 | 46 | |
| 47 | 47 | // 将配置文件的meida配置写入数据库 |
| 48 | - MediaServerItem presetMediaServer = mediaServerService.getOneByHostAndPort( | |
| 49 | - mediaConfig.getIp(), mediaConfig.getHttpPort()); | |
| 50 | - if (presetMediaServer != null) { | |
| 51 | - MediaServerItem mediaSerItem = mediaConfig.getMediaSerItem(); | |
| 52 | - mediaSerItem.setId(presetMediaServer.getId()); | |
| 53 | - mediaServerService.update(mediaSerItem); | |
| 54 | - }else { | |
| 55 | - if (mediaConfig.getId() != null) { | |
| 56 | - MediaServerItem mediaSerItem = mediaConfig.getMediaSerItem(); | |
| 57 | - mediaServerService.add(mediaSerItem); | |
| 58 | - } | |
| 59 | - } | |
| 48 | +// MediaServerItem presetMediaServer = mediaServerService.getOneByHostAndPort( | |
| 49 | +// mediaConfig.getIp(), mediaConfig.getHttpPort()); | |
| 50 | +// if (presetMediaServer != null) { | |
| 51 | +// MediaServerItem mediaSerItem = mediaConfig.getMediaSerItem(); | |
| 52 | +// mediaSerItem.setId(presetMediaServer.getId()); | |
| 53 | +// mediaServerService.update(mediaSerItem); | |
| 54 | +// }else { | |
| 55 | +// if (mediaConfig.getId() != null) { | |
| 56 | +// MediaServerItem mediaSerItem = mediaConfig.getMediaSerItem(); | |
| 57 | +// mediaServerService.add(mediaSerItem); | |
| 58 | +// } | |
| 59 | +// } | |
| 60 | 60 | |
| 61 | 61 | // 订阅 zlm启动事件, 新的zlm也会从这里进入系统 |
| 62 | 62 | hookSubscribe.addSubscribe(ZLMHttpHookSubscribe.HookType.on_server_started,null, |
| ... | ... | @@ -73,8 +73,8 @@ public class ZLMRunner implements CommandLineRunner { |
| 73 | 73 | logger.info("等待默认zlm接入..."); |
| 74 | 74 | |
| 75 | 75 | // 获取所有的zlm, 并开启主动连接 |
| 76 | - List<MediaServerItem> all = mediaServerService.getAll(); | |
| 77 | - if (presetMediaServer == null) { | |
| 76 | + List<MediaServerItem> all = mediaServerService.getAllFromDatabase(); | |
| 77 | + if (all.size() == 0) { | |
| 78 | 78 | all.add(mediaConfig.getMediaSerItem()); |
| 79 | 79 | } |
| 80 | 80 | for (MediaServerItem mediaServerItem : all) { |
| ... | ... | @@ -99,14 +99,16 @@ public class ZLMRunner implements CommandLineRunner { |
| 99 | 99 | Set<String> allZlmId = startGetMedia.keySet(); |
| 100 | 100 | for (String id : allZlmId) { |
| 101 | 101 | logger.error("[ {} ]]主动连接失败,不再主动连接", id); |
| 102 | - startGetMedia.put(id, false); | |
| 103 | 102 | } |
| 103 | + startGetMedia = null; | |
| 104 | 104 | } |
| 105 | + // TODO 清理数据库中与redis不匹配的zlm | |
| 105 | 106 | } |
| 106 | 107 | }, 60 * 1000 * 2); |
| 107 | 108 | } |
| 108 | 109 | |
| 109 | 110 | public ZLMServerConfig getMediaServerConfig(MediaServerItem mediaServerItem) { |
| 111 | + if (startGetMedia == null) return null; | |
| 110 | 112 | if ( startGetMedia.get(mediaServerItem.getId()) == null || !startGetMedia.get(mediaServerItem.getId())) return null; |
| 111 | 113 | JSONObject responseJSON = zlmresTfulUtils.getMediaServerConfig(mediaServerItem); |
| 112 | 114 | ZLMServerConfig ZLMServerConfig = null; | ... | ... |
src/main/java/com/genersoft/iot/vmp/service/IDeviceAlarmService.java
0 → 100644
| 1 | +package com.genersoft.iot.vmp.service; | |
| 2 | + | |
| 3 | +import com.genersoft.iot.vmp.gb28181.bean.DeviceAlarm; | |
| 4 | +import com.github.pagehelper.PageInfo; | |
| 5 | + | |
| 6 | +import java.util.List; | |
| 7 | + | |
| 8 | +/** | |
| 9 | + * 报警相关业务处理 | |
| 10 | + */ | |
| 11 | +public interface IDeviceAlarmService { | |
| 12 | + | |
| 13 | + /** | |
| 14 | + * 根据多个添加获取报警列表 | |
| 15 | + * @param page 当前页 | |
| 16 | + * @param count 每页数量 | |
| 17 | + * @param deviceId 设备id | |
| 18 | + * @param alarmPriority 报警级别, 1为一级警情, 2为二级警情, 3为三级警情, 4为四级 警情- | |
| 19 | + * @param alarmMethod 报警方式 , 1为电话报警, 2为设备报警, 3为短信报警, 4为 GPS报警, 5为视频报警, 6为设备故障报警, | |
| 20 | + * 7其他报警;可以为直接组合如12为电话报警或 设备报警- | |
| 21 | + * @param alarmType 报警类型 | |
| 22 | + * @param startTime 开始时间 | |
| 23 | + * @param endTime 结束时间 | |
| 24 | + * @return 报警列表 | |
| 25 | + */ | |
| 26 | + PageInfo<DeviceAlarm> getAllAlarm(int page, int count, String deviceId, String alarmPriority, String alarmMethod, | |
| 27 | + String alarmType, String startTime, String endTime); | |
| 28 | + | |
| 29 | + /** | |
| 30 | + * 添加一个报警 | |
| 31 | + * @param deviceAlarm 添加报警 | |
| 32 | + */ | |
| 33 | + void add(DeviceAlarm deviceAlarm); | |
| 34 | + | |
| 35 | + /** | |
| 36 | + * 清空时间以前的报警 | |
| 37 | + * @param id 数据库id | |
| 38 | + * @param deviceIdList 制定需要清理的设备id | |
| 39 | + * @param time 不写时间则清空所有时间的 | |
| 40 | + */ | |
| 41 | + void clearAlarmBeforeTime(Integer id, List<String> deviceIdList, String time); | |
| 42 | + | |
| 43 | +} | ... | ... |
src/main/java/com/genersoft/iot/vmp/service/IMediaServerService.java
src/main/java/com/genersoft/iot/vmp/service/impl/DeviceAlarmServiceImpl.java
0 → 100644
| 1 | +package com.genersoft.iot.vmp.service.impl; | |
| 2 | + | |
| 3 | +import com.genersoft.iot.vmp.gb28181.bean.DeviceAlarm; | |
| 4 | +import com.genersoft.iot.vmp.media.zlm.dto.StreamProxyItem; | |
| 5 | +import com.genersoft.iot.vmp.service.IDeviceAlarmService; | |
| 6 | +import com.genersoft.iot.vmp.storager.dao.DeviceAlarmMapper; | |
| 7 | +import com.github.pagehelper.PageHelper; | |
| 8 | +import com.github.pagehelper.PageInfo; | |
| 9 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 10 | +import org.springframework.stereotype.Service; | |
| 11 | + | |
| 12 | +import java.util.List; | |
| 13 | + | |
| 14 | +@Service | |
| 15 | +public class DeviceAlarmServiceImpl implements IDeviceAlarmService { | |
| 16 | + | |
| 17 | + @Autowired | |
| 18 | + private DeviceAlarmMapper deviceAlarmMapper; | |
| 19 | + | |
| 20 | + | |
| 21 | + @Override | |
| 22 | + public PageInfo<DeviceAlarm> getAllAlarm(int page, int count, String deviceId, String alarmPriority, String alarmMethod, String alarmType, String startTime, String endTime) { | |
| 23 | + PageHelper.startPage(page, count); | |
| 24 | + List<DeviceAlarm> all = deviceAlarmMapper.query(deviceId, alarmPriority, alarmMethod, alarmType, startTime, endTime); | |
| 25 | + return new PageInfo<>(all); | |
| 26 | + } | |
| 27 | + | |
| 28 | + @Override | |
| 29 | + public void add(DeviceAlarm deviceAlarm) { | |
| 30 | + deviceAlarmMapper.add(deviceAlarm); | |
| 31 | + } | |
| 32 | + | |
| 33 | + @Override | |
| 34 | + public void clearAlarmBeforeTime(Integer id, List<String> deviceIdList, String time) { | |
| 35 | + deviceAlarmMapper.clearAlarmBeforeTime(id, deviceIdList, time); | |
| 36 | + } | |
| 37 | +} | ... | ... |
src/main/java/com/genersoft/iot/vmp/service/impl/MediaServerServiceImpl.java
| ... | ... | @@ -181,6 +181,12 @@ public class MediaServerServiceImpl implements IMediaServerService, CommandLineR |
| 181 | 181 | return result; |
| 182 | 182 | } |
| 183 | 183 | |
| 184 | + | |
| 185 | + @Override | |
| 186 | + public List<MediaServerItem> getAllFromDatabase() { | |
| 187 | + return mediaServerMapper.queryAll(); | |
| 188 | + } | |
| 189 | + | |
| 184 | 190 | @Override |
| 185 | 191 | public List<MediaServerItem> getAllOnline() { |
| 186 | 192 | String key = VideoManagerConstants.MEDIA_SERVERS_ONLINE_PREFIX; |
| ... | ... | @@ -251,18 +257,16 @@ public class MediaServerServiceImpl implements IMediaServerService, CommandLineR |
| 251 | 257 | if (mediaConfig.getRtspSSLPort() == 0) serverItemFromConfig.setRtspSSLPort(zlmServerConfig.getRtspSSlport()); |
| 252 | 258 | if (mediaConfig.getRtpProxyPort() == 0) serverItemFromConfig.setRtpProxyPort(zlmServerConfig.getRtpProxyPort()); |
| 253 | 259 | if (serverItem != null){ |
| 254 | - // 可能是同一个zlm但id发生了变化 | |
| 255 | - if (!serverItem.getId().equals(zlmServerConfig.getGeneralMediaServerId())) { | |
| 256 | - mediaServerMapper.delOne(serverItem.getId()); | |
| 257 | - redisUtil.del(VideoManagerConstants.MEDIA_SERVER_PREFIX + serverItem.getId()); | |
| 258 | - | |
| 259 | - String key = VideoManagerConstants.MEDIA_SERVER_PREFIX + serverItemFromConfig.getId(); | |
| 260 | - serverItemFromConfig.setSsrcConfig(new SsrcConfig(serverItemFromConfig.getId(), null, sipConfig.getSipDomain())); | |
| 261 | - redisUtil.set(key, serverItemFromConfig); | |
| 262 | - mediaServerMapper.add(serverItemFromConfig); | |
| 260 | + mediaServerMapper.delDefault(); | |
| 261 | + mediaServerMapper.add(serverItemFromConfig); | |
| 262 | + String key = VideoManagerConstants.MEDIA_SERVER_PREFIX + serverItemFromConfig.getId(); | |
| 263 | + MediaServerItem serverItemInRedis = (MediaServerItem)redisUtil.get(key); | |
| 264 | + if (serverItemInRedis != null) { | |
| 265 | + serverItemFromConfig.setSsrcConfig(serverItemInRedis.getSsrcConfig()); | |
| 263 | 266 | }else { |
| 264 | - mediaServerMapper.update(serverItemFromConfig); | |
| 267 | + serverItemFromConfig.setSsrcConfig(new SsrcConfig(serverItemFromConfig.getId(), null, sipConfig.getSipDomain())); | |
| 265 | 268 | } |
| 269 | + redisUtil.set(key, serverItemFromConfig); | |
| 266 | 270 | }else { |
| 267 | 271 | String key = VideoManagerConstants.MEDIA_SERVER_PREFIX + serverItemFromConfig.getId(); |
| 268 | 272 | serverItemFromConfig.setSsrcConfig(new SsrcConfig(serverItemFromConfig.getId(), null, sipConfig.getSipDomain())); | ... | ... |
src/main/java/com/genersoft/iot/vmp/storager/dao/DeviceAlarmMapper.java
0 → 100644
| 1 | +package com.genersoft.iot.vmp.storager.dao; | |
| 2 | + | |
| 3 | +import com.genersoft.iot.vmp.gb28181.bean.DeviceAlarm; | |
| 4 | +import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel; | |
| 5 | +import com.genersoft.iot.vmp.vmanager.gb28181.platform.bean.ChannelReduce; | |
| 6 | +import org.apache.ibatis.annotations.*; | |
| 7 | +import org.springframework.stereotype.Repository; | |
| 8 | + | |
| 9 | +import java.util.List; | |
| 10 | + | |
| 11 | +/** | |
| 12 | + * 用于存储设备的报警信息 | |
| 13 | + */ | |
| 14 | +@Mapper | |
| 15 | +@Repository | |
| 16 | +public interface DeviceAlarmMapper { | |
| 17 | + | |
| 18 | + @Insert("INSERT INTO device_alarm (deviceId, alarmPriority, alarmMethod, alarmTime, alarmDescription, longitude, latitude, alarmType ) " + | |
| 19 | + "VALUES ('${deviceId}', '${alarmPriority}', '${alarmMethod}', '${alarmTime}', '${alarmDescription}', ${longitude}, ${latitude}, '${alarmType}')") | |
| 20 | + int add(DeviceAlarm alarm); | |
| 21 | + | |
| 22 | + | |
| 23 | + @Select(value = {" <script>" + | |
| 24 | + " SELECT * FROM device_alarm " + | |
| 25 | + " WHERE 1=1 " + | |
| 26 | + " <if test=\"deviceId != null\" > AND deviceId = '${deviceId}'</if>" + | |
| 27 | + " <if test=\"alarmPriority != null\" > AND alarmPriority = '${alarmPriority}' </if>" + | |
| 28 | + " <if test=\"alarmMethod != null\" > AND alarmMethod = '${alarmMethod}' </if>" + | |
| 29 | + " <if test=\"alarmType != null\" > AND alarmType = '${alarmType}' </if>" + | |
| 30 | + " <if test=\"startTime != null\" > AND alarmTime >= '${startTime}' </if>" + | |
| 31 | + " <if test=\"endTime != null\" > AND alarmTime <= '${endTime}' </if>" + | |
| 32 | + " ORDER BY alarmTime ASC " + | |
| 33 | + " </script>"}) | |
| 34 | + List<DeviceAlarm> query(String deviceId, String alarmPriority, String alarmMethod, | |
| 35 | + String alarmType, String startTime, String endTime); | |
| 36 | + | |
| 37 | + | |
| 38 | + @Delete(" <script>" + | |
| 39 | + "DELETE FROM device_alarm WHERE 1=1 " + | |
| 40 | + " <if test=\"deviceIdList != null and id == null \" > AND deviceId in " + | |
| 41 | + "<foreach collection='deviceIdList' item='item' open='(' separator=',' close=')' > '${item}'</foreach>" + | |
| 42 | + "</if>" + | |
| 43 | + " <if test=\"time != null and id == null \" > AND alarmTime <= '${time}'</if>" + | |
| 44 | + " <if test=\"id != null\" > AND id = ${id}</if>" + | |
| 45 | + " </script>" | |
| 46 | + ) | |
| 47 | + int clearAlarmBeforeTime(Integer id, List<String> deviceIdList, String time); | |
| 48 | +} | ... | ... |
src/main/java/com/genersoft/iot/vmp/storager/dao/MediaServerMapper.java
| ... | ... | @@ -94,6 +94,12 @@ public interface MediaServerMapper { |
| 94 | 94 | @Select("DELETE FROM media_server WHERE id='${id}'") |
| 95 | 95 | void delOne(String id); |
| 96 | 96 | |
| 97 | + @Select("DELETE FROM media_server WHERE ip='${host}' and httpPort=${port}") | |
| 98 | + void delOneByIPAndPort(String host, int port); | |
| 99 | + | |
| 100 | + @Select("DELETE FROM media_server WHERE defaultServer=1;") | |
| 101 | + void delDefault(); | |
| 102 | + | |
| 97 | 103 | @Select("SELECT * FROM media_server WHERE ip='${host}' and httpPort=${port}") |
| 98 | 104 | MediaServerItem queryOneByHostAndPort(String host, int port); |
| 99 | 105 | } | ... | ... |
src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/alarm/AlarmController.java
0 → 100644
| 1 | +package com.genersoft.iot.vmp.vmanager.gb28181.alarm; | |
| 2 | + | |
| 3 | +import com.genersoft.iot.vmp.gb28181.bean.DeviceAlarm; | |
| 4 | +import com.genersoft.iot.vmp.service.IDeviceAlarmService; | |
| 5 | +import com.genersoft.iot.vmp.service.IGbStreamService; | |
| 6 | +import com.genersoft.iot.vmp.vmanager.bean.WVPResult; | |
| 7 | +import com.github.pagehelper.PageInfo; | |
| 8 | +import io.swagger.annotations.Api; | |
| 9 | +import io.swagger.annotations.ApiImplicitParam; | |
| 10 | +import io.swagger.annotations.ApiImplicitParams; | |
| 11 | +import io.swagger.annotations.ApiOperation; | |
| 12 | +import io.swagger.models.auth.In; | |
| 13 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 14 | +import org.springframework.http.HttpStatus; | |
| 15 | +import org.springframework.http.ResponseEntity; | |
| 16 | +import org.springframework.util.StringUtils; | |
| 17 | +import org.springframework.web.bind.annotation.*; | |
| 18 | + | |
| 19 | +import java.text.ParseException; | |
| 20 | +import java.text.SimpleDateFormat; | |
| 21 | +import java.util.Arrays; | |
| 22 | +import java.util.Date; | |
| 23 | +import java.util.List; | |
| 24 | + | |
| 25 | +@Api(tags = "报警信息管理") | |
| 26 | +@CrossOrigin | |
| 27 | +@RestController | |
| 28 | +@RequestMapping("/api/alarm") | |
| 29 | +public class AlarmController { | |
| 30 | + | |
| 31 | + @Autowired | |
| 32 | + private IDeviceAlarmService deviceAlarmService; | |
| 33 | + | |
| 34 | + private SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | |
| 35 | + | |
| 36 | + /** | |
| 37 | + * 分页查询报警 | |
| 38 | + * | |
| 39 | + * @param deviceId 设备id | |
| 40 | + * @param page 当前页 | |
| 41 | + * @param count 每页查询数量 | |
| 42 | + * @param alarmPriority 报警级别 | |
| 43 | + * @param alarmMethod 报警方式 | |
| 44 | + * @param alarmType 报警类型 | |
| 45 | + * @param startTime 开始时间 | |
| 46 | + * @param endTime 结束时间 | |
| 47 | + * @return | |
| 48 | + */ | |
| 49 | + @ApiOperation("分页查询报警") | |
| 50 | + @GetMapping("/all") | |
| 51 | + @ApiImplicitParams({ | |
| 52 | + @ApiImplicitParam(name="deviceId", value = "设备id", dataTypeClass = String.class), | |
| 53 | + @ApiImplicitParam(name="page", value = "当前页", required = true ,dataTypeClass = Integer.class), | |
| 54 | + @ApiImplicitParam(name="count", value = "每页查询数量", required = true ,dataTypeClass = Integer.class), | |
| 55 | + @ApiImplicitParam(name="alarmPriority", value = "查询内容" ,dataTypeClass = String.class), | |
| 56 | + @ApiImplicitParam(name="alarmMethod", value = "查询内容" ,dataTypeClass = String.class), | |
| 57 | + @ApiImplicitParam(name="alarmMethod", value = "查询内容" ,dataTypeClass = String.class), | |
| 58 | + @ApiImplicitParam(name="alarmType", value = "查询内容" ,dataTypeClass = String.class), | |
| 59 | + @ApiImplicitParam(name="startTime", value = "查询内容" ,dataTypeClass = String.class), | |
| 60 | + @ApiImplicitParam(name="endTime", value = "查询内容" ,dataTypeClass = String.class), | |
| 61 | + }) | |
| 62 | + public ResponseEntity<PageInfo<DeviceAlarm>> getAll( | |
| 63 | + int page, int count, | |
| 64 | + @RequestParam(required = false) String deviceId, | |
| 65 | + @RequestParam(required = false) String alarmPriority, | |
| 66 | + @RequestParam(required = false) String alarmMethod, | |
| 67 | + @RequestParam(required = false) String alarmType, | |
| 68 | + @RequestParam(required = false) String startTime, | |
| 69 | + @RequestParam(required = false) String endTime | |
| 70 | + ) { | |
| 71 | + if (StringUtils.isEmpty(alarmPriority)) alarmPriority = null; | |
| 72 | + if (StringUtils.isEmpty(alarmMethod)) alarmMethod = null; | |
| 73 | + if (StringUtils.isEmpty(alarmType)) alarmType = null; | |
| 74 | + if (StringUtils.isEmpty(startTime)) startTime = null; | |
| 75 | + if (StringUtils.isEmpty(endTime)) endTime = null; | |
| 76 | + | |
| 77 | + | |
| 78 | + try { | |
| 79 | + format.parse(startTime); | |
| 80 | + format.parse(endTime); | |
| 81 | + } catch (ParseException e) { | |
| 82 | + return new ResponseEntity<>(null, HttpStatus.BAD_REQUEST); | |
| 83 | + } | |
| 84 | + | |
| 85 | + PageInfo<DeviceAlarm> allAlarm = deviceAlarmService.getAllAlarm(page, count, deviceId, alarmPriority, alarmMethod, | |
| 86 | + alarmType, startTime, endTime); | |
| 87 | + return new ResponseEntity<>(allAlarm, HttpStatus.OK); | |
| 88 | + } | |
| 89 | + | |
| 90 | + | |
| 91 | + /** | |
| 92 | + * 删除报警 | |
| 93 | + * | |
| 94 | + * @param id 报警id | |
| 95 | + * @param deviceIds 多个设备id,逗号分隔 | |
| 96 | + * @param time 结束时间(这个时间之前的报警会被删除) | |
| 97 | + * @return | |
| 98 | + */ | |
| 99 | + @ApiOperation("分页查询报警") | |
| 100 | + @DeleteMapping("/delete") | |
| 101 | + @ApiImplicitParams({ | |
| 102 | + @ApiImplicitParam(name="id", value = "ID", required = false ,dataTypeClass = Integer.class), | |
| 103 | + @ApiImplicitParam(name="deviceIds", value = "多个设备id,逗号分隔", required = false ,dataTypeClass = String.class), | |
| 104 | + @ApiImplicitParam(name="time", value = "结束时间", required = false ,dataTypeClass = String.class), | |
| 105 | + }) | |
| 106 | + public ResponseEntity<WVPResult<String>> delete( | |
| 107 | + @RequestParam(required = false) Integer id, | |
| 108 | + @RequestParam(required = false) String deviceIds, | |
| 109 | + @RequestParam(required = false) String time | |
| 110 | + ) { | |
| 111 | + if (StringUtils.isEmpty(id)) id = null; | |
| 112 | + if (StringUtils.isEmpty(deviceIds)) deviceIds = null; | |
| 113 | + if (StringUtils.isEmpty(time)) time = null; | |
| 114 | + try { | |
| 115 | + if (time != null) { | |
| 116 | + format.parse(time); | |
| 117 | + } | |
| 118 | + } catch (ParseException e) { | |
| 119 | + return new ResponseEntity<>(null, HttpStatus.BAD_REQUEST); | |
| 120 | + } | |
| 121 | + String[] deviceIdArray = deviceIds.split(","); | |
| 122 | + List<String> deviceIdList = Arrays.asList(deviceIdArray); | |
| 123 | + deviceAlarmService.clearAlarmBeforeTime(id, deviceIdList, time); | |
| 124 | + WVPResult wvpResult = new WVPResult(); | |
| 125 | + wvpResult.setCode(0); | |
| 126 | + wvpResult.setMsg("success"); | |
| 127 | + return new ResponseEntity<WVPResult<String>>(wvpResult, HttpStatus.OK); | |
| 128 | + } | |
| 129 | + | |
| 130 | + | |
| 131 | +} | ... | ... |
src/main/resources/wvp.sqlite
No preview for this file type