diff --git a/README.md b/README.md index 7ba443fe..1b8b985c 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 1546e39c..9ad41c7f 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/gb28181/session/VideoStreamSessionManager.java b/src/main/java/com/genersoft/iot/vmp/gb28181/session/VideoStreamSessionManager.java index 85bc39dc..2b76ff78 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,8 +108,7 @@ 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){ 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 7f62968a..3694fdf2 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 f4a9febb..223ef13f 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 9e764931..0b758d85 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 e4a2a19c..77c7c617 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 @@ -68,7 +68,6 @@ public class DeviceServiceImpl implements IDeviceService { if (deviceInRedis != null && deviceInDb == null) { // redis 存在脏数据 redisCatchStorage.clearCatchByDeviceId(device.getDeviceId()); - } device.setUpdateTime(now); device.setOnline(1); 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 5468faef..8ad57e85 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 2521a069..b1644929 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 @@ -648,4 +648,9 @@ public class PlayServiceImpl implements IPlayService { } } } + + @Override + public void zlmServerOnline(String mediaServerId) { + // 似乎没啥需要做的 + } } 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 9d37dcd3..787bdae9 100644 --- a/src/main/java/com/genersoft/iot/vmp/utils/DateUtil.java +++ b/src/main/java/com/genersoft/iot/vmp/utils/DateUtil.java @@ -18,35 +18,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 56864dbc..0edec510 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; @@ -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 8cb923a7..f0f2eb2b 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 65f5f7c7..a9b23eff 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 6d6ff37f..c627511a 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/src/components/service/DeviceService.js b/web_src/src/components/service/DeviceService.js index dbe10d18..4700e793 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)