Pārlūkot izejas kodu

change:
1. catalog 根据设备 autoUpdate 字段来确定是否保留name字段
2. 设备在离线状态下收到心跳也更新心跳包
3. 离线检测宽容值从5分钟改为2分钟

kindring 2 gadi atpakaļ
vecāks
revīzija
b5d170cd3c

+ 2 - 0
src/main/java/com/genersoft/iot/vmp/gb28181/bean/CmdType.java

@@ -5,4 +5,6 @@ public class CmdType {
     public static final String CATALOG = "Catalog";
     public static final String ALARM = "Alarm";
     public static final String MOBILE_POSITION = "MobilePosition";
+
+    public static final String Keepalive = "Keepalive";
 }

+ 12 - 0
src/main/java/com/genersoft/iot/vmp/gb28181/bean/Device.java

@@ -142,6 +142,11 @@ public class Device {
 	@Schema(description = "目录订阅周期,0为不订阅")
 	private int subscribeCycleForCatalog;
 
+
+
+	@Schema(description = "是否自动更新设备")
+	private int autoUpdate;
+
 	/**
 	 * 移动设备位置订阅周期,0为不订阅
 	 */
@@ -450,4 +455,11 @@ public class Device {
 	public void setAudioEncodePt(String audioEncodePt) {
 		this.audioEncodePt = audioEncodePt;
 	}
+	public int getAutoUpdate() {
+		return autoUpdate;
+	}
+
+	public void setAutoUpdate(int autoUpdate) {
+		this.autoUpdate = autoUpdate;
+	}
 }

+ 1 - 1
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/NotifyRequestProcessor.java

@@ -118,7 +118,7 @@ public class NotifyRequestProcessor extends SIPRequestProcessorParent implements
 						} else if (CmdType.MOBILE_POSITION.equals(cmd)) {
 							logger.info("接收到MobilePosition通知");
 							processNotifyMobilePosition(take.getEvt());
-						} else {
+						}  else {
 							logger.info("接收到消息:" + cmd);
 						}
 					} catch (DocumentException e) {

+ 1 - 1
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/SubscribeRequestProcessor.java

@@ -79,7 +79,7 @@ public class SubscribeRequestProcessor extends SIPRequestProcessorParent impleme
 			} else if (CmdType.CATALOG.equals(cmd)) {
 				processNotifyCatalogList(request, rootElement);
 			} else {
-				logger.info("接收到消息:" + cmd);
+//				logger.info("接收到消息:" + cmd);
 
 				Response response = getMessageFactory().createResponse(200, request);
 				if (response != null) {

+ 1 - 1
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/MessageRequestProcessor.java

@@ -67,7 +67,7 @@ public class MessageRequestProcessor extends SIPRequestProcessorParent implement
     @Override
     public void process(RequestEvent evt) {
         SIPRequest sipRequest = (SIPRequest)evt.getRequest();
-        logger.debug("接收到消息:" + evt.getRequest());
+        logger.info("接收到消息:" + evt.getRequest());
         String deviceId = SipUtils.getUserIdFromFromHeader(evt.getRequest());
         CallIdHeader callIdHeader = sipRequest.getCallIdHeader();
         // 先从会话内查找

+ 2 - 1
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/KeepaliveNotifyMessageHandler.java

@@ -60,6 +60,7 @@ public class KeepaliveNotifyMessageHandler extends SIPRequestProcessorParent imp
             logger.warn("[{}]未注册设备,不做处理", evt.getRequest().getRequestURI().toString());
             return;
         }
+//        logger.info("[{}]设备心跳", device.getDeviceId());
         // 收到设备心跳包
         SIPRequest request = (SIPRequest) evt.getRequest();
         // 回复200 OK
@@ -83,7 +84,7 @@ public class KeepaliveNotifyMessageHandler extends SIPRequestProcessorParent imp
         }
 
         device.setKeepaliveTime(DateUtil.getNow());
-
+        device.setOnline(1);
         if (device.getOnline() == 1) {
             deviceService.updateDevice(device);
         }else {

+ 8 - 3
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/DeviceInfoResponseMessageHandler.java

@@ -79,14 +79,19 @@ public class DeviceInfoResponseMessageHandler extends SIPRequestProcessorParent
             Element deviceIdElement = rootElement.element("DeviceID");
             String channelId = deviceIdElement.getTextTrim();
             String key = DeferredResultHolder.CALLBACK_CMD_DEVICEINFO + device.getDeviceId() + channelId;
-            device.setName(getText(rootElement, "DeviceName"));
 
-            device.setManufacturer(getText(rootElement, "Manufacturer"));
-            device.setModel(getText(rootElement, "Model"));
+            if(device.getAutoUpdate() == 1){
+                logger.info("[device change] 更新设备信息");
+                device.setName(getText(rootElement, "DeviceName"));
+                device.setManufacturer(getText(rootElement, "Manufacturer"));
+                device.setModel(getText(rootElement, "Model"));
+            }
+            // 设备固件版本此项需要动态更新
             device.setFirmware(getText(rootElement, "Firmware"));
             if (ObjectUtils.isEmpty(device.getStreamMode())) {
                 device.setStreamMode("UDP");
             }
+            // todo 检查设备是否开启自动更新数据,默认为开启状态
             deviceService.updateDevice(device);
 
             RequestMessage msg = new RequestMessage();

+ 2 - 0
src/main/java/com/genersoft/iot/vmp/gb28181/utils/XmlUtil.java

@@ -242,8 +242,10 @@ public class XmlUtil {
 
         Element channdelNameElement = itemDevice.element("Name");
         String channelName = channdelNameElement != null ? channdelNameElement.getTextTrim() : "";
+
         deviceChannel.setName(channelName);
 
+
         String civilCode = XmlUtil.getText(itemDevice, "CivilCode");
         deviceChannel.setCivilCode(civilCode);
         if (channelType == ChannelType.CivilCode && civilCode == null) {

+ 8 - 0
src/main/java/com/genersoft/iot/vmp/service/impl/DeviceServiceImpl.java

@@ -317,6 +317,9 @@ public class DeviceServiceImpl implements IDeviceService {
     public boolean expire(Device device) {
         Instant registerTimeDate = Instant.from(DateUtil.formatter.parse(device.getRegisterTime()));
         Instant expireInstant = registerTimeDate.plusMillis(TimeUnit.SECONDS.toMillis(device.getExpires()));
+//      // 多添加2分钟,用于心跳包更新
+        expireInstant = expireInstant.plusMillis(TimeUnit.MINUTES.toMillis(2));
+
         return expireInstant.isBefore(Instant.now());
     }
 
@@ -599,6 +602,8 @@ public class DeviceServiceImpl implements IDeviceService {
             }
         }
 
+
+
         // 移动位置订阅相关的信息
         if (device.getSubscribeCycleForMobilePosition() > 0) {
             if (deviceInStore.getSubscribeCycleForMobilePosition() == 0 || deviceInStore.getSubscribeCycleForMobilePosition() != device.getSubscribeCycleForMobilePosition()) {
@@ -617,6 +622,9 @@ public class DeviceServiceImpl implements IDeviceService {
         if (!deviceInStore.getGeoCoordSys().equals(device.getGeoCoordSys())) {
             updateDeviceChannelGeoCoordSys(device);
         }
+
+
+
         // 更新redis
         redisCatchStorage.updateDevice(device);
         deviceMapper.updateCustom(device);

+ 13 - 3
src/main/java/com/genersoft/iot/vmp/storager/dao/DeviceMapper.java

@@ -44,7 +44,8 @@ public interface DeviceMapper {
             "treeType," +
             "mediaServerId," +
             "audioEncodePt," +
-            "online" +
+            "online," +
+            "autoUpdate" +
             " FROM device WHERE deviceId = #{deviceId}")
     Device getDeviceByDeviceId(String deviceId);
 
@@ -128,6 +129,7 @@ public interface DeviceMapper {
                 "<if test=\"expires != null\">, expires=#{expires}</if>" +
                 "<if test=\"mediaServerId != null\">, mediaServerId=#{mediaServerId}</if>" +
                 "<if test=\"audioEncodePt != null\">, audioEncodePt=#{audioEncodePt}</if>" +
+            "<if test=\"autoUpdate != null\">, autoUpdate=#{autoUpdate}</if>" +
                 "WHERE deviceId=#{deviceId}"+
             " </script>"})
     int update(Device device);
@@ -165,6 +167,7 @@ public interface DeviceMapper {
             "online," +
             "audioEncodePt," +
             "mediaServerId," +
+            "autoUpdate," +
             "(SELECT count(0) FROM device_channel WHERE deviceId=de.deviceId) as channelCount  FROM device de" +
             "<if test=\"online != null\"> where online=${online}</if>"+
             " </script>"
@@ -207,7 +210,8 @@ public interface DeviceMapper {
             "treeType," +
             "online," +
             "mediaServerId," +
-            "audioEncodePt" +
+            "audioEncodePt," +
+            "autoUpdate" +
             " FROM device WHERE online = 1")
     List<Device> getOnlineDevices();
     @Select("SELECT " +
@@ -240,7 +244,8 @@ public interface DeviceMapper {
             "treeType," +
             "online," +
             "mediaServerId," +
-            "audioEncodePt" +
+            "audioEncodePt," +
+            "autoUpdate" +
             " FROM device WHERE ip = #{host} AND port=#{port}")
     Device getDeviceByHostAndPort(String host, int port);
 
@@ -264,6 +269,7 @@ public interface DeviceMapper {
             "<if test=\"treeType != null\">, treeType=#{treeType}</if>" +
             "<if test=\"mediaServerId != null\">, mediaServerId=#{mediaServerId}</if>" +
             "<if test=\"audioEncodePt != null\">, audioEncodePt=#{audioEncodePt}</if>" +
+            "<if test=\"autoUpdate != null\">, autoUpdate=#{autoUpdate}</if>" +
             "WHERE deviceId=#{deviceId}"+
             " </script>"})
     int updateCustom(Device device);
@@ -305,4 +311,8 @@ public interface DeviceMapper {
 
     @Select("select * from device where  asMessageChannel = 1")
     List<Device> queryDeviceWithAsMessageChannel();
+
+    // 根据设备id查询autoUpdate字段
+    @Select("select autoUpdate from device where deviceId = #{deviceId}")
+    Integer getAutoUpdateByDeviceId(String deviceId);
 }

+ 19 - 0
src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStorageImpl.java

@@ -121,11 +121,16 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage {
 	@Override
 	public boolean resetChannels(String deviceId, List<DeviceChannel> deviceChannelList) {
 		if (CollectionUtils.isEmpty(deviceChannelList)) {
+			logger.error("[fn: resetChannels] 设备通道列表为空,deviceId:" + deviceId);
 			return false;
 		}
+		// 获取设备autoUpdate 字段  Integer getAutoUpdateByDeviceId
+		Integer autoUpdate = deviceMapper.getAutoUpdateByDeviceId(deviceId);
+
 		List<DeviceChannel> allChannels = deviceChannelMapper.queryAllChannels(deviceId);
 		Map<String,DeviceChannel> allChannelMap = new ConcurrentHashMap<>();
 		if (allChannels.size() > 0) {
+			// 数据添加至map中
 			for (DeviceChannel deviceChannel : allChannels) {
 				allChannelMap.put(deviceChannel.getChannelId(), deviceChannel);
 			}
@@ -139,9 +144,11 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage {
 			// 数据去重
 			Set<String> gbIdSet = new HashSet<>();
 			for (DeviceChannel deviceChannel : deviceChannelList) {
+				// 遇到相同通道id的数据,只保留第一条
 				if (!gbIdSet.contains(deviceChannel.getChannelId())) {
 					gbIdSet.add(deviceChannel.getChannelId());
 					if (allChannelMap.containsKey(deviceChannel.getChannelId())) {
+						logger.info("[通道更新] 通道:{} 将会继承部分旧数据", deviceChannel.getChannelId());
 						deviceChannel.setStreamId(allChannelMap.get(deviceChannel.getChannelId()).getStreamId());
 						deviceChannel.setHasAudio(allChannelMap.get(deviceChannel.getChannelId()).isHasAudio());
 						if (allChannelMap.get(deviceChannel.getChannelId()).getStatus() !=deviceChannel.getStatus()){
@@ -153,8 +160,12 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage {
 							}
 
 						}
+						if(autoUpdate == 0){
+							deviceChannel.setName(allChannelMap.get(deviceChannel.getChannelId()).getName());
+						}
 					}
 					channels.add(deviceChannel);
+
 					if (!ObjectUtils.isEmpty(deviceChannel.getParentId())) {
 						if (subContMap.get(deviceChannel.getParentId()) == null) {
 							subContMap.put(deviceChannel.getParentId(), 1);
@@ -167,12 +178,14 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage {
 					stringBuilder.append(deviceChannel.getChannelId()).append(",");
 				}
 			}
+
 			if (channels.size() > 0) {
 				for (DeviceChannel channel : channels) {
 					if (subContMap.get(channel.getChannelId()) != null){
 						channel.setSubCount(subContMap.get(channel.getChannelId()));
 					}
 				}
+
 			}
 
 		}
@@ -184,9 +197,13 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage {
 			return false;
 		}
 		try {
+			// 删除旧通道
 			int cleanChannelsResult = deviceChannelMapper.cleanChannelsNotInList(deviceId, channels);
 			int limitCount = 300;
 			boolean result = cleanChannelsResult < 0;
+
+			logger.info("[测试] 数据通道更新" );
+			// 新增通道
 			if (!result && channels.size() > 0) {
 				if (channels.size() > limitCount) {
 					for (int i = 0; i < channels.size(); i += limitCount) {
@@ -194,9 +211,11 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage {
 						if (i + limitCount > channels.size()) {
 							toIndex = channels.size();
 						}
+//						logger.info("[测试1] 新增设备通道{}", i + " - " + toIndex + " 之间的数据" );
 						result = result || deviceChannelMapper.batchAdd(channels.subList(i, toIndex)) < 0;
 					}
 				}else {
+//					logger.info("[测试2] 新增设备通道{}", channels.size() + " 之间的数据" );
 					result = result || deviceChannelMapper.batchAdd(channels) < 0;
 				}
 			}

+ 2 - 2
web_src/src/components/DeviceList.vue

@@ -246,10 +246,10 @@ export default {
       }
       res = res.data;
       console.log("刷新设备结果:" + JSON.stringify(res));
-      if (res.data.code !== 0) {
+      if (res.code !== 0) {
         this.$message({
           showClose: true,
-          message: res.data.msg,
+          message: res.msg,
           type: 'error'
         });
       } else {

+ 16 - 1
web_src/src/components/dialog/deviceEdit.vue

@@ -78,6 +78,7 @@
           <el-form-item label="其他选项">
             <el-checkbox label="SSRC校验" v-model="form.ssrcCheck" style="float: left"></el-checkbox>
             <el-checkbox label="作为消息通道" v-model="form.asMessageChannel" style="float: left"></el-checkbox>
+            <el-checkbox :label="form.autoUpdate?'跟随sip更新':'不跟随sip更新'" v-model="form.autoUpdate" style="float: left"></el-checkbox>
           </el-form-item>
           <el-form-item>
             <div style="float: right;">
@@ -130,6 +131,15 @@ export default {
         this.form = row;
         if(this.form.audioEncodePt){
           this.form.audioEncodePt = this.form.audioEncodePt.split(",");
+        }else{
+          // 设置初始值
+          this.form.audioEncodePt = [];
+        }
+        // autoUpdate 项更改为 true false
+        if(this.form.autoUpdate == 1){
+          this.form.autoUpdate = true;
+        }else{
+          this.form.autoUpdate = false;
         }
       }
       this.getMediaServerList();
@@ -147,7 +157,12 @@ export default {
       this.form.subscribeCycleForMobilePosition = this.form.subscribeCycleForMobilePosition||0
       this.form.mobilePositionSubmissionInterval = this.form.mobilePositionSubmissionInterval||0
       this.form.audioEncodePt = this.form.audioEncodePt.join(',');
-
+      // auto update 项更改为 0 1
+      if(this.form.autoUpdate){
+        this.form.autoUpdate = 1;
+      }else{
+        this.form.autoUpdate = 0;
+      }
       this.$axios.axios({
         method: 'post',
         url:`/api/device/query/device/${this.isEdit?'update':'add'}`,