648540858
2022-05-26 dc6769664e36ffc70ea3af597e4f3dbb93c2b6bf
兼容不规范的时间格式iso8601格式;升级fastjson版本
15个文件已修改
164 ■■■■■ 已修改文件
README.md 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pom.xml 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/genersoft/iot/vmp/gb28181/session/VideoStreamSessionManager.java 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/genersoft/iot/vmp/media/zlm/event/ZLMStatusEventListener.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/genersoft/iot/vmp/service/IPlayService.java 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/genersoft/iot/vmp/service/impl/DeviceServiceImpl.java 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/genersoft/iot/vmp/service/impl/MediaServerServiceImpl.java 13 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/genersoft/iot/vmp/utils/DateUtil.java 42 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/alarm/AlarmController.java 18 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/record/GBRecordController.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/genersoft/iot/vmp/vmanager/log/LogController.java 9 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/test/java/com/genersoft/iot/vmp/service/impl/DeviceAlarmServiceImplTest.java 23 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
web_src/src/components/service/DeviceService.js 33 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
README.md
@@ -163,6 +163,7 @@
[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: 刚增加了这个名单,肯定遗漏了一些大佬,欢迎大佬联系我添加。
pom.xml
@@ -159,9 +159,10 @@
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>fastjson</artifactId>
            <version>1.2.73</version>
            <version>1.2.83</version>
        </dependency>
        <!-- okhttp -->
        <dependency>
            <groupId>com.squareup.okhttp3</groupId>
src/main/java/com/genersoft/iot/vmp/gb28181/session/VideoStreamSessionManager.java
@@ -99,8 +99,8 @@
        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 @@
        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){
src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java
@@ -11,7 +11,6 @@
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.*;
src/main/java/com/genersoft/iot/vmp/media/zlm/event/ZLMStatusEventListener.java
@@ -42,7 +42,7 @@
        logger.info("[ZLM] 上线 ID:" + event.getMediaServerId());
        streamPushService.zlmServerOnline(event.getMediaServerId());
        streamProxyService.zlmServerOnline(event.getMediaServerId());
        playService.zlmServerOnline(event.getMediaServerId());
    }
    @Async
src/main/java/com/genersoft/iot/vmp/service/IPlayService.java
@@ -40,4 +40,6 @@
    DeferredResult<ResponseEntity<String>> 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);
}
src/main/java/com/genersoft/iot/vmp/service/impl/DeviceServiceImpl.java
@@ -68,7 +68,6 @@
        if (deviceInRedis != null && deviceInDb == null) {
            // redis 存在脏数据
            redisCatchStorage.clearCatchByDeviceId(device.getDeviceId());
        }
        device.setUpdateTime(now);
        device.setOnline(1);
src/main/java/com/genersoft/iot/vmp/service/impl/MediaServerServiceImpl.java
@@ -6,6 +6,7 @@
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 java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;
/**
 * 媒体服务器节点管理
@@ -189,6 +192,7 @@
    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 @@
        }
        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;
src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java
@@ -648,4 +648,9 @@
            }
        }
    }
    @Override
    public void zlmServerOnline(String mediaServerId) {
        // 似乎没啥需要做的
    }
}
src/main/java/com/genersoft/iot/vmp/utils/DateUtil.java
@@ -18,35 +18,61 @@
 */
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);
src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/alarm/AlarmController.java
@@ -24,6 +24,7 @@
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 @@
        }
        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 @@
        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<String> deviceIdList = null;
@@ -189,7 +179,7 @@
        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);
src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/record/GBRecordController.java
@@ -72,7 +72,7 @@
        if (!DateUtil.verification(startTime, DateUtil.formatter)){
            WVPResult<RecordInfo> 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<WVPResult<RecordInfo>> resultResponseEntity = new ResponseEntity<>(wvpResult, HttpStatus.OK);
            result.setResult(resultResponseEntity);
@@ -81,7 +81,7 @@
        if (!DateUtil.verification(endTime, DateUtil.formatter)){
            WVPResult<RecordInfo> 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<WVPResult<RecordInfo>> resultResponseEntity = new ResponseEntity<>(wvpResult, HttpStatus.OK);
            result.setResult(resultResponseEntity);
            return result;
src/main/java/com/genersoft/iot/vmp/vmanager/log/LogController.java
@@ -76,14 +76,7 @@
            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);
        }
src/test/java/com/genersoft/iot/vmp/service/impl/DeviceAlarmServiceImplTest.java
@@ -8,6 +8,10 @@
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 @@
             *      * 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 @@
    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();
        }
web_src/src/components/service/DeviceService.js
@@ -21,47 +21,47 @@
      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 @@
  }
  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)