diff --git a/README.md b/README.md index 7ba443fe1..1b8b985c7 100644 --- a/README.md +++ b/README.md @@ -163,6 +163,7 @@ QQ私信一般不回, 精力有限.欢迎大家在群里讨论.觉得项目对 [hotcoffie](https://github.com/hotcoffie) [xiaomu](https://github.com/nikmu) [TristingChen](https://github.com/TristingChen) [chenparty](https://github.com/chenparty) [Hotleave](https://github.com/hotleave) [ydwxb](https://github.com/ydwxb) [ydpd](https://github.com/ydpd) [szy833](https://github.com/szy833) [ydwxb](https://github.com/ydwxb) [Albertzhu666](https://github.com/Albertzhu666) +[mk1990](https://github.com/mk1990) ps: 刚增加了这个名单,肯定遗漏了一些大佬,欢迎大佬联系我添加。 diff --git a/pom.xml b/pom.xml index 1546e39cc..9ad41c7f1 100644 --- a/pom.xml +++ b/pom.xml @@ -159,9 +159,10 @@ com.alibaba fastjson - 1.2.73 + 1.2.83 + com.squareup.okhttp3 diff --git a/src/main/java/com/genersoft/iot/vmp/conf/security/LoginSuccessHandler.java b/src/main/java/com/genersoft/iot/vmp/conf/security/LoginSuccessHandler.java index 9690c6d1e..2d7e8a1b0 100644 --- a/src/main/java/com/genersoft/iot/vmp/conf/security/LoginSuccessHandler.java +++ b/src/main/java/com/genersoft/iot/vmp/conf/security/LoginSuccessHandler.java @@ -11,6 +11,9 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; +/** + * @author lin + */ @Component public class LoginSuccessHandler implements AuthenticationSuccessHandler { diff --git a/src/main/java/com/genersoft/iot/vmp/conf/security/WebSecurityConfig.java b/src/main/java/com/genersoft/iot/vmp/conf/security/WebSecurityConfig.java index 47cfdaba4..a4bbdbac6 100644 --- a/src/main/java/com/genersoft/iot/vmp/conf/security/WebSecurityConfig.java +++ b/src/main/java/com/genersoft/iot/vmp/conf/security/WebSecurityConfig.java @@ -20,6 +20,7 @@ import java.util.List; /** * 配置Spring Security + * @author lin */ @Configuration @EnableWebSecurity @@ -132,15 +133,19 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter { .anyRequest().authenticated() // 异常处理(权限拒绝、登录失效等) .and().exceptionHandling() - .authenticationEntryPoint(anonymousAuthenticationEntryPoint)//匿名用户访问无权限资源时的异常处理 + //匿名用户访问无权限资源时的异常处理 + .authenticationEntryPoint(anonymousAuthenticationEntryPoint) // .accessDeniedHandler(accessDeniedHandler)//登录用户没有权限访问资源 - // 登入 - .and().formLogin().permitAll()//允许所有用户 - .successHandler(loginSuccessHandler)//登录成功处理逻辑 - .failureHandler(loginFailureHandler)//登录失败处理逻辑 + // 登入 允许所有用户 + .and().formLogin().permitAll() + //登录成功处理逻辑 + .successHandler(loginSuccessHandler) + //登录失败处理逻辑 + .failureHandler(loginFailureHandler) // 登出 - .and().logout().logoutUrl("/api/user/logout").permitAll()//允许所有用户 - .logoutSuccessHandler(logoutHandler)//登出成功处理逻辑 + .and().logout().logoutUrl("/api/user/logout").permitAll() + //登出成功处理逻辑 + .logoutSuccessHandler(logoutHandler) .deleteCookies("JSESSIONID") // 会话管理 // .and().sessionManagement().invalidSessionStrategy(invalidSessionHandler) // 超时处理 diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/session/VideoStreamSessionManager.java b/src/main/java/com/genersoft/iot/vmp/gb28181/session/VideoStreamSessionManager.java index 85bc39dc7..a22d24d68 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/session/VideoStreamSessionManager.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/session/VideoStreamSessionManager.java @@ -99,8 +99,8 @@ public class VideoStreamSessionManager { return dialog; } - public SIPDialog getDialogByCallId(String deviceId, String channelId, String callID){ - SsrcTransaction ssrcTransaction = getSsrcTransaction(deviceId, channelId, callID, null); + public SIPDialog getDialogByCallId(String deviceId, String channelId, String callId){ + SsrcTransaction ssrcTransaction = getSsrcTransaction(deviceId, channelId, callId, null); if (ssrcTransaction == null) { return null; } @@ -108,11 +108,17 @@ public class VideoStreamSessionManager { if (dialogByteArray == null) { return null; } - SIPDialog dialog = (SIPDialog)SerializeUtils.deSerialize(dialogByteArray); - return dialog; + return (SIPDialog)SerializeUtils.deSerialize(dialogByteArray); } public SsrcTransaction getSsrcTransaction(String deviceId, String channelId, String callId, String stream){ + + if (StringUtils.isEmpty(deviceId)) { + deviceId ="*"; + } + if (StringUtils.isEmpty(channelId)) { + channelId ="*"; + } if (StringUtils.isEmpty(callId)) { callId ="*"; } @@ -179,7 +185,7 @@ public class VideoStreamSessionManager { public List getAllSsrc() { - List ssrcTransactionKeys = redisUtil.scan(String.format("%s_*_*_*_*", VideoManagerConstants.MEDIA_TRANSACTION_USED_PREFIX+ userSetting.getServerId() + "_" )); + List ssrcTransactionKeys = redisUtil.scan(String.format("%s_*_*_*_*", VideoManagerConstants.MEDIA_TRANSACTION_USED_PREFIX+ userSetting.getServerId())); List result= new ArrayList<>(); for (int i = 0; i < ssrcTransactionKeys.size(); i++) { String key = (String)ssrcTransactionKeys.get(i); diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java index f2e524e47..f51437d19 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java @@ -708,22 +708,22 @@ public class SIPCommander implements ISIPCommander { } SIPDialog dialog; if (callId != null) { - dialog = streamSession.getDialogByCallId(deviceId, channelId, callId); + dialog = streamSession.getDialogByCallId(ssrcTransaction.getDeviceId(), ssrcTransaction.getChannelId(), callId); }else { - if (stream == null) { + if (stream == null && ssrcTransaction == null && ssrcTransaction.getStream() == null) { return; } - dialog = streamSession.getDialogByStream(deviceId, channelId, stream); + dialog = streamSession.getDialogByStream(ssrcTransaction.getDeviceId(), ssrcTransaction.getChannelId(), ssrcTransaction.getStream()); } if (ssrcTransaction != null) { MediaServerItem mediaServerItem = mediaServerService.getOne(ssrcTransaction.getMediaServerId()); mediaServerService.releaseSsrc(mediaServerItem.getId(), ssrcTransaction.getSsrc()); - mediaServerService.closeRTPServer(deviceId, channelId, ssrcTransaction.getStream()); - streamSession.remove(deviceId, channelId, ssrcTransaction.getStream()); + mediaServerService.closeRTPServer(ssrcTransaction.getDeviceId(), ssrcTransaction.getChannelId(), ssrcTransaction.getStream()); + streamSession.remove(ssrcTransaction.getDeviceId(), ssrcTransaction.getChannelId(), ssrcTransaction.getStream()); } if (dialog == null) { - logger.warn("[ {} -> {}]停止视频流的时候发现对话已丢失", deviceId, channelId); + logger.warn("[ {} -> {}]停止视频流的时候发现对话已丢失", ssrcTransaction.getDeviceId(), ssrcTransaction.getChannelId()); return; } SipStack sipStack = udpSipProvider.getSipStack(); diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/NotifyRequestProcessor.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/NotifyRequestProcessor.java index e923a54a2..40b9a9ae1 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/NotifyRequestProcessor.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/NotifyRequestProcessor.java @@ -18,6 +18,7 @@ import com.genersoft.iot.vmp.gb28181.utils.SipUtils; import com.genersoft.iot.vmp.gb28181.utils.XmlUtil; import com.genersoft.iot.vmp.storager.IRedisCatchStorage; import com.genersoft.iot.vmp.storager.IVideoManagerStorage; +import com.genersoft.iot.vmp.utils.DateUtil; import com.genersoft.iot.vmp.utils.redis.RedisUtil; import org.dom4j.DocumentException; import org.dom4j.Element; @@ -188,6 +189,7 @@ public class NotifyRequestProcessor extends SIPRequestProcessorParent implements Device device = redisCatchStorage.getDevice(deviceId); if (device == null) { + responseAck(evt, Response.NOT_FOUND, "device is not found"); return; } rootElement = getRootElement(evt, device.getCharset()); @@ -195,7 +197,12 @@ public class NotifyRequestProcessor extends SIPRequestProcessorParent implements deviceAlarm.setDeviceId(deviceId); deviceAlarm.setAlarmPriority(XmlUtil.getText(rootElement, "AlarmPriority")); deviceAlarm.setAlarmMethod(XmlUtil.getText(rootElement, "AlarmMethod")); - deviceAlarm.setAlarmTime(XmlUtil.getText(rootElement, "AlarmTime")); + String alarmTime = XmlUtil.getText(rootElement, "AlarmTime"); + if (alarmTime == null) { + responseAck(evt, Response.BAD_REQUEST, "AlarmTime cannot be null"); + return; + } + deviceAlarm.setAlarmTime(DateUtil.ISO8601Toyyyy_MM_dd_HH_mm_ss(alarmTime)); if (XmlUtil.getText(rootElement, "AlarmDescription") == null) { deviceAlarm.setAlarmDescription(""); } else { diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/RegisterRequestProcessor.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/RegisterRequestProcessor.java index 47a4e008b..cebc2edae 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/RegisterRequestProcessor.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/RegisterRequestProcessor.java @@ -1,17 +1,13 @@ package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl; -import com.genersoft.iot.vmp.common.VideoManagerConstants; import com.genersoft.iot.vmp.conf.SipConfig; -import com.genersoft.iot.vmp.gb28181.auth.DigestServerAuthenticationHelper; import com.genersoft.iot.vmp.gb28181.bean.Device; import com.genersoft.iot.vmp.gb28181.bean.WvpSipDate; -import com.genersoft.iot.vmp.gb28181.event.EventPublisher; import com.genersoft.iot.vmp.gb28181.transmit.SIPProcessorObserver; import com.genersoft.iot.vmp.gb28181.transmit.event.request.ISIPRequestProcessor; import com.genersoft.iot.vmp.gb28181.transmit.event.request.SIPRequestProcessorParent; +import com.genersoft.iot.vmp.gb28181.auth.DigestServerAuthenticationHelper; import com.genersoft.iot.vmp.service.IDeviceService; -import com.genersoft.iot.vmp.storager.IRedisCatchStorage; -import com.genersoft.iot.vmp.storager.IVideoManagerStorage; import com.genersoft.iot.vmp.utils.DateUtil; import gov.nist.javax.sip.RequestEventExt; import gov.nist.javax.sip.address.AddressImpl; @@ -50,15 +46,6 @@ public class RegisterRequestProcessor extends SIPRequestProcessorParent implemen @Autowired private SipConfig sipConfig; - @Autowired - private IRedisCatchStorage redisCatchStorage; - - @Autowired - private IVideoManagerStorage storager; - - @Autowired - private EventPublisher publisher; - @Autowired private SIPProcessorObserver sipProcessorObserver; @@ -86,7 +73,7 @@ public class RegisterRequestProcessor extends SIPRequestProcessorParent implemen ExpiresHeader expiresHeader = (ExpiresHeader) request.getHeader(Expires.NAME); Response response = null; boolean passwordCorrect = false; - // 注册标志 0:未携带授权头或者密码错误 1:注册成功 2:注销成功 + // 注册标志 boolean registerFlag = false; FromHeader fromHeader = (FromHeader) request.getHeader(FromHeader.NAME); AddressImpl address = (AddressImpl) fromHeader.getAddress(); @@ -105,7 +92,6 @@ public class RegisterRequestProcessor extends SIPRequestProcessorParent implemen // 校验密码是否正确 passwordCorrect = StringUtils.isEmpty(sipConfig.getPassword()) || new DigestServerAuthenticationHelper().doAuthenticatePlainTextPassword(request, sipConfig.getPassword()); - // 未携带授权头或者密码错误 回复401 if (!passwordCorrect) { // 注册失败 diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/MessageRequestProcessor.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/MessageRequestProcessor.java index 136b91206..cd858896c 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/MessageRequestProcessor.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/MessageRequestProcessor.java @@ -72,7 +72,7 @@ public class MessageRequestProcessor extends SIPRequestProcessorParent implement String deviceId = SipUtils.getUserIdFromFromHeader(evt.getRequest()); CallIdHeader callIdHeader = (CallIdHeader)evt.getRequest().getHeader(CallIdHeader.NAME); // 先从会话内查找 - SsrcTransaction ssrcTransaction = sessionManager.getSsrcTransaction(null, null, null, callIdHeader.getCallId()); + SsrcTransaction ssrcTransaction = sessionManager.getSsrcTransaction(null, null, callIdHeader.getCallId(), null); if (ssrcTransaction != null) { // 兼容海康 媒体通知 消息from字段不是设备ID的问题 deviceId = ssrcTransaction.getDeviceId(); } diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/AlarmNotifyMessageHandler.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/AlarmNotifyMessageHandler.java index d0cda6f63..172795cbb 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/AlarmNotifyMessageHandler.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/AlarmNotifyMessageHandler.java @@ -11,10 +11,12 @@ import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.IMessag import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.notify.NotifyMessageHandler; import com.genersoft.iot.vmp.gb28181.utils.Coordtransform; import com.genersoft.iot.vmp.gb28181.utils.NumericUtil; +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.IVideoManagerStorage; import okhttp3.*; +import com.genersoft.iot.vmp.utils.DateUtil; import org.dom4j.Element; import org.jetbrains.annotations.NotNull; import org.slf4j.Logger; @@ -94,7 +96,11 @@ public class AlarmNotifyMessageHandler extends SIPRequestProcessorParent impleme deviceAlarm.setChannelId(channelId); deviceAlarm.setAlarmPriority(getText(rootElement, "AlarmPriority")); deviceAlarm.setAlarmMethod(getText(rootElement, "AlarmMethod")); - deviceAlarm.setAlarmTime(getText(rootElement, "AlarmTime")); + String alarmTime = XmlUtil.getText(rootElement, "AlarmTime"); + if (alarmTime == null) { + return; + } + deviceAlarm.setAlarmTime(DateUtil.ISO8601Toyyyy_MM_dd_HH_mm_ss(alarmTime)); String alarmDescription = getText(rootElement, "AlarmDescription"); if (alarmDescription == null) { deviceAlarm.setAlarmDescription(""); @@ -187,7 +193,11 @@ public class AlarmNotifyMessageHandler extends SIPRequestProcessorParent impleme deviceAlarm.setChannelId(channelId); deviceAlarm.setAlarmPriority(getText(rootElement, "AlarmPriority")); deviceAlarm.setAlarmMethod(getText(rootElement, "AlarmMethod")); - deviceAlarm.setAlarmTime(getText(rootElement, "AlarmTime")); + String alarmTime = XmlUtil.getText(rootElement, "AlarmTime"); + if (alarmTime == null) { + return; + } + deviceAlarm.setAlarmTime(DateUtil.ISO8601Toyyyy_MM_dd_HH_mm_ss(alarmTime)); String alarmDescription = getText(rootElement, "AlarmDescription"); if (alarmDescription == null) { deviceAlarm.setAlarmDescription(""); diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/KeepaliveNotifyMessageHandler.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/KeepaliveNotifyMessageHandler.java index cf07250d9..c4294576a 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/KeepaliveNotifyMessageHandler.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/KeepaliveNotifyMessageHandler.java @@ -64,16 +64,14 @@ public class KeepaliveNotifyMessageHandler extends SIPRequestProcessorParent imp device.setHostAddress(received.concat(":").concat(String.valueOf(rPort))); } device.setKeepaliveTime(DateUtil.getNow()); + // 回复200 OK + responseAck(evt, Response.OK); if (device.getOnline() == 1) { - // 回复200 OK - responseAck(evt, Response.OK); deviceService.updateDevice(device); }else { // 对于已经离线的设备判断他的注册是否已经过期 if (!deviceService.expire(device)){ deviceService.online(device); - // 回复200 OK - responseAck(evt, Response.OK); } } } catch (SipException e) { diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/MediaStatusNotifyMessageHandler.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/MediaStatusNotifyMessageHandler.java index 4cf976855..5cb39734d 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/MediaStatusNotifyMessageHandler.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/MediaStatusNotifyMessageHandler.java @@ -3,6 +3,8 @@ package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.notify import com.genersoft.iot.vmp.common.StreamInfo; import com.genersoft.iot.vmp.gb28181.bean.Device; import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform; +import com.genersoft.iot.vmp.gb28181.bean.SsrcTransaction; +import com.genersoft.iot.vmp.gb28181.session.VideoStreamSessionManager; import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander; import com.genersoft.iot.vmp.gb28181.transmit.event.request.SIPRequestProcessorParent; import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.IMessageHandler; @@ -39,6 +41,9 @@ public class MediaStatusNotifyMessageHandler extends SIPRequestProcessorParent i @Autowired private IRedisCatchStorage redisCatchStorage; + @Autowired + private VideoStreamSessionManager sessionManager; + @Override public void afterPropertiesSet() throws Exception { notifyMessageHandler.addHandler(cmdType, this); @@ -61,13 +66,19 @@ public class MediaStatusNotifyMessageHandler extends SIPRequestProcessorParent i String NotifyType =getText(rootElement, "NotifyType"); if (NotifyType.equals("121")){ logger.info("[录像流]推送完毕,收到关流通知"); - String channelId =getText(rootElement, "DeviceID"); // 查询是设备 - StreamInfo streamInfo = redisCatchStorage.queryDownload(device.getDeviceId(), channelId, null, callIdHeader.getCallId()); - // 设置进度100% - streamInfo.setProgress(1); - redisCatchStorage.startDownload(streamInfo, callIdHeader.getCallId()); - cmder.streamByeCmd(device.getDeviceId(), channelId, null, callIdHeader.getCallId()); + StreamInfo streamInfo = redisCatchStorage.queryDownload(null, null, null, callIdHeader.getCallId()); + if (streamInfo != null) { + // 设置进度100% + streamInfo.setProgress(1); + redisCatchStorage.startDownload(streamInfo, callIdHeader.getCallId()); + } + + // 先从会话内查找 + SsrcTransaction ssrcTransaction = sessionManager.getSsrcTransaction(null, null, callIdHeader.getCallId(), null); + if (ssrcTransaction != null) { // 兼容海康 媒体通知 消息from字段不是设备ID的问题 + cmder.streamByeCmd(device.getDeviceId(), ssrcTransaction.getChannelId(), null, callIdHeader.getCallId()); + } // TODO 如果级联播放,需要给上级发送此通知 } diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/RecordInfoResponseMessageHandler.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/RecordInfoResponseMessageHandler.java index 4509e424f..1f701715b 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/RecordInfoResponseMessageHandler.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/RecordInfoResponseMessageHandler.java @@ -70,15 +70,20 @@ public class RecordInfoResponseMessageHandler extends SIPRequestProcessorParent rootElement = getRootElement(evt, device.getCharset()); String sn = getText(rootElement, "SN"); - + RecordInfo recordInfo = new RecordInfo(); + recordInfo.setDeviceId(device.getDeviceId()); + recordInfo.setSn(sn); + recordInfo.setName(getText(rootElement, "Name")); String sumNumStr = getText(rootElement, "SumNum"); int sumNum = 0; if (!StringUtils.isEmpty(sumNumStr)) { sumNum = Integer.parseInt(sumNumStr); } + recordInfo.setSumNum(sumNum); Element recordListElement = rootElement.element("RecordList"); if (recordListElement == null || sumNum == 0) { logger.info("无录像数据"); + eventPublisher.recordEndEventPush(recordInfo); recordDataCatch.put(device.getDeviceId(), sn, sumNum, new ArrayList<>()); releaseRequest(device.getDeviceId(), sn); } else { @@ -112,6 +117,9 @@ public class RecordInfoResponseMessageHandler extends SIPRequestProcessorParent record.setRecorderId(getText(itemRecord, "RecorderID")); recordList.add(record); } + recordInfo.setRecordList(recordList); + // 发送消息,如果是上级查询此录像,则会通过这里通知给上级 + eventPublisher.recordEndEventPush(recordInfo); int count = recordDataCatch.put(device.getDeviceId(), sn, sumNum, recordList); logger.info("[国标录像], {}->{}: {}/{}", device.getDeviceId(), sn, count, sumNum); } diff --git a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java index 7f62968a8..3694fdf2b 100644 --- a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java +++ b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java @@ -11,7 +11,6 @@ import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel; import com.genersoft.iot.vmp.gb28181.bean.GbStream; import com.genersoft.iot.vmp.gb28181.bean.SsrcTransaction; import com.genersoft.iot.vmp.gb28181.event.EventPublisher; -import com.genersoft.iot.vmp.gb28181.event.subscribe.catalog.CatalogEvent; import com.genersoft.iot.vmp.gb28181.session.VideoStreamSessionManager; import com.genersoft.iot.vmp.media.zlm.dto.*; import com.genersoft.iot.vmp.service.*; diff --git a/src/main/java/com/genersoft/iot/vmp/media/zlm/event/ZLMStatusEventListener.java b/src/main/java/com/genersoft/iot/vmp/media/zlm/event/ZLMStatusEventListener.java index f4a9febbb..223ef13f2 100644 --- a/src/main/java/com/genersoft/iot/vmp/media/zlm/event/ZLMStatusEventListener.java +++ b/src/main/java/com/genersoft/iot/vmp/media/zlm/event/ZLMStatusEventListener.java @@ -42,7 +42,7 @@ public class ZLMStatusEventListener { logger.info("[ZLM] 上线 ID:" + event.getMediaServerId()); streamPushService.zlmServerOnline(event.getMediaServerId()); streamProxyService.zlmServerOnline(event.getMediaServerId()); - + playService.zlmServerOnline(event.getMediaServerId()); } @Async diff --git a/src/main/java/com/genersoft/iot/vmp/service/IPlayService.java b/src/main/java/com/genersoft/iot/vmp/service/IPlayService.java index 9e764931e..0b758d85c 100644 --- a/src/main/java/com/genersoft/iot/vmp/service/IPlayService.java +++ b/src/main/java/com/genersoft/iot/vmp/service/IPlayService.java @@ -40,4 +40,6 @@ public interface IPlayService { DeferredResult> download(MediaServerItem mediaServerItem, SSRCInfo ssrcInfo,String deviceId, String channelId, String startTime, String endTime, int downloadSpeed, InviteStreamCallback infoCallBack, PlayBackCallback hookCallBack); StreamInfo getDownLoadInfo(String deviceId, String channelId, String stream); + + void zlmServerOnline(String mediaServerId); } diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/DeviceServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/DeviceServiceImpl.java index 3eba5db1f..d5fa417df 100644 --- a/src/main/java/com/genersoft/iot/vmp/service/impl/DeviceServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/service/impl/DeviceServiceImpl.java @@ -73,7 +73,6 @@ public class DeviceServiceImpl implements IDeviceService { if (deviceInRedis != null && deviceInDb == null) { // redis 存在脏数据 redisCatchStorage.clearCatchByDeviceId(device.getDeviceId()); - } device.setUpdateTime(now); device.setOnline(1); @@ -82,13 +81,15 @@ public class DeviceServiceImpl implements IDeviceService { if (device.getCreateTime() == null) { device.setCreateTime(now); logger.info("[设备上线,首次注册]: {},查询设备信息以及通道信息", device.getDeviceId()); + deviceMapper.add(device); + redisCatchStorage.updateDevice(device); commander.deviceInfoQuery(device); sync(device); - deviceMapper.add(device); }else { deviceMapper.update(device); + redisCatchStorage.updateDevice(device); } - redisCatchStorage.updateDevice(device); + // 上线添加订阅 if (device.getSubscribeCycleForCatalog() > 0) { // 查询在线设备那些开启了订阅,为设备开启定时的目录订阅 diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/MediaServerServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/MediaServerServiceImpl.java index 5468faefc..8ad57e85f 100644 --- a/src/main/java/com/genersoft/iot/vmp/service/impl/MediaServerServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/service/impl/MediaServerServiceImpl.java @@ -6,6 +6,7 @@ import com.alibaba.fastjson.JSONObject; import com.genersoft.iot.vmp.common.VideoManagerConstants; import com.genersoft.iot.vmp.conf.SipConfig; import com.genersoft.iot.vmp.conf.UserSetting; +import com.genersoft.iot.vmp.gb28181.bean.SsrcTransaction; import com.genersoft.iot.vmp.gb28181.event.EventPublisher; import com.genersoft.iot.vmp.gb28181.session.SsrcConfig; import com.genersoft.iot.vmp.gb28181.session.VideoStreamSessionManager; @@ -35,7 +36,9 @@ import org.springframework.util.StringUtils; import java.text.ParseException; import java.text.SimpleDateFormat; +import java.time.LocalDateTime; import java.util.*; +import java.util.stream.Collectors; /** * 媒体服务器节点管理 @@ -189,6 +192,7 @@ public class MediaServerServiceImpl implements IMediaServerService { public void clearRTPServer(MediaServerItem mediaServerItem) { mediaServerItem.setSsrcConfig(new SsrcConfig(mediaServerItem.getId(), null, sipConfig.getDomain())); redisUtil.zAdd(VideoManagerConstants.MEDIA_SERVERS_ONLINE_PREFIX + userSetting.getServerId(), mediaServerItem.getId(), 0); + } @@ -229,11 +233,10 @@ public class MediaServerServiceImpl implements IMediaServerService { } result.sort((serverItem1, serverItem2)->{ int sortResult = 0; - try { - sortResult = DateUtil.format.parse(serverItem1.getCreateTime()).compareTo(DateUtil.format.parse(serverItem2.getCreateTime())); - } catch (ParseException e) { - e.printStackTrace(); - } + LocalDateTime localDateTime1 = LocalDateTime.parse(serverItem1.getCreateTime(), DateUtil.formatter); + LocalDateTime localDateTime2 = LocalDateTime.parse(serverItem2.getCreateTime(), DateUtil.formatter); + + sortResult = localDateTime1.compareTo(localDateTime2); return sortResult; }); return result; diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java index be66b0ede..b16449290 100644 --- a/src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java @@ -19,17 +19,16 @@ import com.genersoft.iot.vmp.media.zlm.ZLMHttpHookSubscribe; import com.genersoft.iot.vmp.media.zlm.ZLMRESTfulUtils; import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; import com.genersoft.iot.vmp.service.IMediaServerService; +import com.genersoft.iot.vmp.service.IMediaService; +import com.genersoft.iot.vmp.service.IPlayService; import com.genersoft.iot.vmp.service.bean.InviteTimeOutCallback; import com.genersoft.iot.vmp.service.bean.PlayBackCallback; import com.genersoft.iot.vmp.service.bean.PlayBackResult; import com.genersoft.iot.vmp.service.bean.SSRCInfo; import com.genersoft.iot.vmp.storager.IRedisCatchStorage; import com.genersoft.iot.vmp.storager.IVideoManagerStorage; -import com.genersoft.iot.vmp.utils.redis.RedisUtil; import com.genersoft.iot.vmp.vmanager.bean.WVPResult; import com.genersoft.iot.vmp.vmanager.gb28181.play.bean.PlayResult; -import com.genersoft.iot.vmp.service.IMediaService; -import com.genersoft.iot.vmp.service.IPlayService; import gov.nist.javax.sip.stack.SIPDialog; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -43,6 +42,7 @@ import org.springframework.web.context.request.async.DeferredResult; import javax.sip.ResponseEvent; import java.io.FileNotFoundException; import java.math.BigDecimal; +import java.math.RoundingMode; import java.util.*; @SuppressWarnings(value = {"rawtypes", "unchecked"}) @@ -63,9 +63,6 @@ public class PlayServiceImpl implements IPlayService { @Autowired private IRedisCatchStorage redisCatchStorage; - @Autowired - private RedisUtil redis; - @Autowired private DeferredResultHolder resultHolder; @@ -591,7 +588,7 @@ public class PlayServiceImpl implements IPlayService { BigDecimal currentCount = new BigDecimal(duration/1000); BigDecimal totalCount = new BigDecimal(end-start); - BigDecimal divide = currentCount.divide(totalCount,2, BigDecimal.ROUND_HALF_UP); + BigDecimal divide = currentCount.divide(totalCount,2, RoundingMode.HALF_UP); double process = divide.doubleValue(); streamInfo.setProgress(process); } @@ -651,4 +648,9 @@ public class PlayServiceImpl implements IPlayService { } } } + + @Override + public void zlmServerOnline(String mediaServerId) { + // 似乎没啥需要做的 + } } diff --git a/src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStorageImpl.java b/src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStorageImpl.java index 1f3591142..3bb3d9f08 100644 --- a/src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStorageImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStorageImpl.java @@ -30,7 +30,7 @@ import org.springframework.util.StringUtils; import java.util.*; import java.util.concurrent.ConcurrentHashMap; -/** +/** * 视频设备数据存储-jdbc实现 * swwheihei * 2020年5月6日 下午2:31:42 @@ -315,6 +315,9 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage { List all; if (catalogUnderDevice != null && catalogUnderDevice) { all = deviceChannelMapper.queryChannels(deviceId, deviceId, query, hasSubChannel, online); + // 海康设备的parentId是SIP id + List deviceChannels = deviceChannelMapper.queryChannels(deviceId, sipConfig.getId(), query, hasSubChannel, online); + all.addAll(deviceChannels); }else { all = deviceChannelMapper.queryChannels(deviceId, null, query, hasSubChannel, online); } diff --git a/src/main/java/com/genersoft/iot/vmp/utils/DateUtil.java b/src/main/java/com/genersoft/iot/vmp/utils/DateUtil.java index 9d37dcd31..3235a49f0 100644 --- a/src/main/java/com/genersoft/iot/vmp/utils/DateUtil.java +++ b/src/main/java/com/genersoft/iot/vmp/utils/DateUtil.java @@ -1,7 +1,6 @@ package com.genersoft.iot.vmp.utils; -import java.text.SimpleDateFormat; import java.time.Instant; import java.time.LocalDate; import java.time.LocalDateTime; @@ -18,35 +17,61 @@ import java.util.Locale; */ public class DateUtil { - private static final String yyyy_MM_dd_T_HH_mm_ss_SSSXXX = "yyyy-MM-dd'T'HH:mm:ss"; - public static final String yyyy_MM_dd_HH_mm_ss = "yyyy-MM-dd HH:mm:ss"; + /** + * 兼容不规范的iso8601时间格式 + */ + private static final String ISO8601_COMPATIBLE_PATTERN = "yyyy-M-d'T'H:m:s"; - public static final SimpleDateFormat formatISO8601 = new SimpleDateFormat(yyyy_MM_dd_T_HH_mm_ss_SSSXXX, Locale.getDefault()); - public static final SimpleDateFormat format = new SimpleDateFormat(yyyy_MM_dd_HH_mm_ss, Locale.getDefault()); + /** + * 用以输出标准的iso8601时间格式 + */ + private static final String ISO8601_PATTERN = "yyyy-MM-dd'T'HH:mm:ss"; - public static final DateTimeFormatter formatterISO8601 = DateTimeFormatter.ofPattern(yyyy_MM_dd_T_HH_mm_ss_SSSXXX, Locale.getDefault()).withZone(ZoneId.systemDefault()); - public static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern(yyyy_MM_dd_HH_mm_ss, Locale.getDefault()).withZone(ZoneId.systemDefault()); + /** + * wvp内部统一时间格式 + */ + public static final String PATTERN = "yyyy-MM-dd HH:mm:ss"; + + + public static final DateTimeFormatter formatterCompatibleISO8601 = DateTimeFormatter.ofPattern(ISO8601_COMPATIBLE_PATTERN, Locale.getDefault()).withZone(ZoneId.systemDefault()); + public static final DateTimeFormatter formatterISO8601 = DateTimeFormatter.ofPattern(ISO8601_PATTERN, Locale.getDefault()).withZone(ZoneId.systemDefault()); + public static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern(PATTERN, Locale.getDefault()).withZone(ZoneId.systemDefault()); public static String yyyy_MM_dd_HH_mm_ssToISO8601(String formatTime) { return formatterISO8601.format(formatter.parse(formatTime)); } public static String ISO8601Toyyyy_MM_dd_HH_mm_ss(String formatTime) { - return formatter.format(formatterISO8601.parse(formatTime)); + return formatter.format(formatterCompatibleISO8601.parse(formatTime)); } - + + /** + * yyyy_MM_dd_HH_mm_ss 转时间戳 + * @param formatTime + * @return + */ public static long yyyy_MM_dd_HH_mm_ssToTimestamp(String formatTime) { TemporalAccessor temporalAccessor = formatter.parse(formatTime); Instant instant = Instant.from(temporalAccessor); return instant.getEpochSecond(); } + /** + * 获取当前时间 + * @return + */ public static String getNow() { LocalDateTime nowDateTime = LocalDateTime.now(); return formatter.format(nowDateTime); } + /** + * 格式校验 + * @param timeStr 时间字符串 + * @param dateTimeFormatter 待校验的格式 + * @return + */ public static boolean verification(String timeStr, DateTimeFormatter dateTimeFormatter) { try { LocalDate.parse(timeStr, dateTimeFormatter); diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/alarm/AlarmController.java b/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/alarm/AlarmController.java index 56864dbcd..509c988c0 100644 --- a/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/alarm/AlarmController.java +++ b/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/alarm/AlarmController.java @@ -24,6 +24,7 @@ import org.springframework.util.StringUtils; import org.springframework.web.bind.annotation.*; import java.text.ParseException; +import java.time.LocalDateTime; import java.util.Arrays; import java.util.List; @@ -68,8 +69,8 @@ public class AlarmController { @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), + @ApiImplicitParam(name="startTime", value = "开始时间" ,dataTypeClass = String.class), + @ApiImplicitParam(name="endTime", value = "结束时间" ,dataTypeClass = String.class), }) public ResponseEntity> getAll( @RequestParam int page, @@ -98,14 +99,7 @@ public class AlarmController { } - try { - if (startTime != null) { - DateUtil.format.parse(startTime); - } - if (endTime != null) { - DateUtil.format.parse(endTime); - } - } catch (ParseException e) { + if (!DateUtil.verification(startTime, DateUtil.formatter) || !DateUtil.verification(endTime, DateUtil.formatter)){ return new ResponseEntity<>(null, HttpStatus.BAD_REQUEST); } @@ -144,11 +138,7 @@ public class AlarmController { if (StringUtils.isEmpty(time)) { time = null; } - try { - if (time != null) { - DateUtil.format.parse(time); - } - } catch (ParseException e) { + if (!DateUtil.verification(time, DateUtil.formatter) ){ return new ResponseEntity<>(null, HttpStatus.BAD_REQUEST); } List deviceIdList = null; @@ -189,7 +179,7 @@ public class AlarmController { deviceAlarm.setAlarmDescription("test"); deviceAlarm.setAlarmMethod("1"); deviceAlarm.setAlarmPriority("1"); - deviceAlarm.setAlarmTime(DateUtil.formatISO8601.format(System.currentTimeMillis())); + deviceAlarm.setAlarmTime(DateUtil.formatterISO8601.format(LocalDateTime.now())); deviceAlarm.setAlarmType("1"); deviceAlarm.setLongitude(115.33333); deviceAlarm.setLatitude(39.33333); diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/record/GBRecordController.java b/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/record/GBRecordController.java index 8cb923a77..f0f2eb2b8 100644 --- a/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/record/GBRecordController.java +++ b/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/record/GBRecordController.java @@ -72,7 +72,7 @@ public class GBRecordController { if (!DateUtil.verification(startTime, DateUtil.formatter)){ WVPResult wvpResult = new WVPResult<>(); wvpResult.setCode(-1); - wvpResult.setMsg("startTime error, format is " + DateUtil.yyyy_MM_dd_HH_mm_ss); + wvpResult.setMsg("startTime error, format is " + DateUtil.PATTERN); ResponseEntity> resultResponseEntity = new ResponseEntity<>(wvpResult, HttpStatus.OK); result.setResult(resultResponseEntity); @@ -81,7 +81,7 @@ public class GBRecordController { if (!DateUtil.verification(endTime, DateUtil.formatter)){ WVPResult wvpResult = new WVPResult<>(); wvpResult.setCode(-1); - wvpResult.setMsg("endTime error, format is " + DateUtil.yyyy_MM_dd_HH_mm_ss); + wvpResult.setMsg("endTime error, format is " + DateUtil.PATTERN); ResponseEntity> resultResponseEntity = new ResponseEntity<>(wvpResult, HttpStatus.OK); result.setResult(resultResponseEntity); return result; diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/log/LogController.java b/src/main/java/com/genersoft/iot/vmp/vmanager/log/LogController.java index 65f5f7c70..a9b23eff8 100644 --- a/src/main/java/com/genersoft/iot/vmp/vmanager/log/LogController.java +++ b/src/main/java/com/genersoft/iot/vmp/vmanager/log/LogController.java @@ -76,14 +76,7 @@ public class LogController { logger.warn("自动记录日志功能已关闭,查询结果可能不完整。"); } - try { - if (startTime != null) { - DateUtil.format.parse(startTime); - } - if (endTime != null) { - DateUtil.format.parse(endTime); - } - } catch (ParseException e) { + if (!DateUtil.verification(startTime, DateUtil.formatter) || !DateUtil.verification(endTime, DateUtil.formatter)){ return new ResponseEntity<>(null, HttpStatus.BAD_REQUEST); } diff --git a/src/test/java/com/genersoft/iot/vmp/service/impl/DeviceAlarmServiceImplTest.java b/src/test/java/com/genersoft/iot/vmp/service/impl/DeviceAlarmServiceImplTest.java index 6d6ff37ff..c627511a7 100644 --- a/src/test/java/com/genersoft/iot/vmp/service/impl/DeviceAlarmServiceImplTest.java +++ b/src/test/java/com/genersoft/iot/vmp/service/impl/DeviceAlarmServiceImplTest.java @@ -8,6 +8,10 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; import javax.annotation.Resource; +import java.time.Instant; +import java.time.LocalDateTime; +import java.time.ZoneOffset; +import java.time.temporal.TemporalAccessor; import java.util.Date; @@ -64,8 +68,8 @@ class DeviceAlarmServiceImplTest { * * 7其他报警;可以为直接组合如12为电话报警或 设备报警- */ deviceAlarm.setAlarmMethod((int)(Math.random()*7 + 1) + ""); - Date date = randomDate("2021-01-01 00:00:00", "2021-06-01 00:00:00"); - deviceAlarm.setAlarmTime(DateUtil.format.format(date)); + Instant date = randomDate("2021-01-01 00:00:00", "2021-06-01 00:00:00"); + deviceAlarm.setAlarmTime(DateUtil.formatter.format(date)); /** * 报警级别, 1为一级警情, 2为二级警情, 3为三级警情, 4为四级 警情- */ @@ -85,17 +89,20 @@ class DeviceAlarmServiceImplTest { - private Date randomDate(String beginDate, String endDate) { + private Instant randomDate(String beginDate, String endDate) { try { - Date start = DateUtil.format.parse(beginDate);//构造开始日期 - Date end = DateUtil.format.parse(endDate);//构造结束日期 + //构造开始日期 + LocalDateTime start = LocalDateTime.parse(beginDate, DateUtil.formatter); + + //构造结束日期 + LocalDateTime end = LocalDateTime.parse(endDate, DateUtil.formatter); //getTime()表示返回自 1970 年 1 月 1 日 00:00:00 GMT 以来此 Date 对象表示的毫秒数。 - if (start.getTime() >= end.getTime()) { + if (start.isAfter(end)) { return null; } - long date = random(start.getTime(), end.getTime()); - return new Date(date); + long date = random(start.toInstant(ZoneOffset.of("+8")).toEpochMilli(), end.toInstant(ZoneOffset.of("+8")).toEpochMilli()); + return Instant.ofEpochMilli(date); } catch (Exception e) { e.printStackTrace(); } diff --git a/web_src/package.json b/web_src/package.json index 1e7f0432d..b825f8403 100644 --- a/web_src/package.json +++ b/web_src/package.json @@ -52,7 +52,7 @@ "postcss-url": "^7.2.1", "rimraf": "^2.6.0", "semver": "^5.3.0", - "shelljs": "^0.7.6", + "shelljs": "^0.8.5", "uglifyjs-webpack-plugin": "^1.1.1", "url-loader": "^0.5.8", "vue-loader": "^13.3.0", diff --git a/web_src/src/components/dialog/devicePlayer.vue b/web_src/src/components/dialog/devicePlayer.vue index aba35ddb0..9c254c9b7 100644 --- a/web_src/src/components/dialog/devicePlayer.vue +++ b/web_src/src/components/dialog/devicePlayer.vue @@ -605,12 +605,12 @@ export default { url: '/api/playback/start/' + this.deviceId + '/' + this.channelId + '?startTime=' + row.startTime + '&endTime=' + row.endTime }).then(function (res) { - var streamInfo = res.data; - that.app = streamInfo.app; - that.streamId = streamInfo.stream; - that.mediaServerId = streamInfo.mediaServerId; - that.ssrc = streamInfo.ssrc; - that.videoUrl = that.getUrlByStreamInfo(streamInfo); + that.streamInfo = res.data; + that.app = that.streamInfo.app; + that.streamId = that.streamInfo.stream; + that.mediaServerId = that.streamInfo.mediaServerId; + that.ssrc = that.streamInfo.ssrc; + that.videoUrl = that.getUrlByStreamInfo(); that.recordPlay = true; }); } diff --git a/web_src/src/components/service/DeviceService.js b/web_src/src/components/service/DeviceService.js index dbe10d189..4700e7938 100644 --- a/web_src/src/components/service/DeviceService.js +++ b/web_src/src/components/service/DeviceService.js @@ -21,47 +21,47 @@ class DeviceService{ if (typeof (errorCallback) == "function") errorCallback(error) }); } - getAllDeviceList(callback, errorCallback) { + getAllDeviceList(callback,endCallback, errorCallback) { let currentPage = 1; let count = 100; let deviceList = [] - this.getAllDeviceListIteration(deviceList, currentPage, count, (data) => { - if (typeof (callback) == "function") callback(data) - }, errorCallback) + this.getAllDeviceListIteration(deviceList, currentPage, count, callback, endCallback, errorCallback) } - getAllDeviceListIteration(deviceList, currentPage, count, callback, errorCallback) { + getAllDeviceListIteration(deviceList, currentPage, count, callback, endCallback, errorCallback) { this.getDeviceList(currentPage, count, (data) => { if (data.list) { + if (typeof (callback) == "function") callback(data.list) deviceList = deviceList.concat(data.list); if (deviceList.length < data.total) { currentPage ++ - this.getAllDeviceListIteration(deviceList, currentPage, count, callback, errorCallback) + this.getAllDeviceListIteration(deviceList, currentPage, count, callback, endCallback, errorCallback) }else { - if (typeof (callback) == "function") callback(deviceList) + if (typeof (endCallback) == "function") endCallback(deviceList) } } }, errorCallback) } - getAllChannel(isCatalog, catalogUnderDevice, deviceId, callback, errorCallback) { + getAllChannel(isCatalog, catalogUnderDevice, deviceId, callback, endCallback, errorCallback) { let currentPage = 1; let count = 100; let catalogList = [] - this.getAllChannelIteration(isCatalog, catalogUnderDevice, deviceId, catalogList, currentPage, count, callback, errorCallback) + this.getAllChannelIteration(isCatalog, catalogUnderDevice, deviceId, catalogList, currentPage, count, callback, endCallback, errorCallback) } - getAllChannelIteration(isCatalog, catalogUnderDevice, deviceId, catalogList, currentPage, count, callback, errorCallback) { + getAllChannelIteration(isCatalog, catalogUnderDevice, deviceId, catalogList, currentPage, count, callback, endCallback, errorCallback) { this.getChanel(isCatalog, catalogUnderDevice, deviceId, currentPage, count, (data) => { if (data.list) { + if (typeof (callback) == "function") callback(data.list) catalogList = catalogList.concat(data.list); if (catalogList.length < data.total) { currentPage ++ this.getAllChannelIteration(isCatalog,catalogUnderDevice, deviceId, catalogList, currentPage, count, callback, errorCallback) }else { console.log(1) - if (typeof (callback) == "function") callback(catalogList) + if (typeof (endCallback) == "function") endCallback(catalogList) } } }, errorCallback) @@ -84,22 +84,23 @@ class DeviceService{ } - getAllSubChannel(isCatalog, deviceId, channelId, callback, errorCallback) { + getAllSubChannel(isCatalog, deviceId, channelId, callback, endCallback, errorCallback) { let currentPage = 1; let count = 100; let catalogList = [] - this.getAllSubChannelIteration(isCatalog, deviceId, channelId, catalogList, currentPage, count, callback, errorCallback) + this.getAllSubChannelIteration(isCatalog, deviceId, channelId, catalogList, currentPage, count, callback, endCallback, errorCallback) } - getAllSubChannelIteration(isCatalog, deviceId,channelId, catalogList, currentPage, count, callback, errorCallback) { + getAllSubChannelIteration(isCatalog, deviceId,channelId, catalogList, currentPage, count, callback, endCallback, errorCallback) { this.getSubChannel(isCatalog, deviceId, channelId, currentPage, count, (data) => { if (data.list) { + if (typeof (callback) == "function") callback(data.list) catalogList = catalogList.concat(data.list); if (catalogList.length < data.total) { currentPage ++ - this.getAllSubChannelIteration(isCatalog, deviceId, channelId, catalogList, currentPage, count, callback, errorCallback) + this.getAllSubChannelIteration(isCatalog, deviceId, channelId, catalogList, currentPage, count, callback, endCallback, errorCallback) }else { - if (typeof (callback) == "function") callback(catalogList) + if (typeof (endCallback) == "function") endCallback(catalogList) } } }, errorCallback)