diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/conf/ServerLoggerImpl.java b/src/main/java/com/genersoft/iot/vmp/gb28181/conf/ServerLoggerImpl.java index 3fc1d374..19e1906c 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/conf/ServerLoggerImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/conf/ServerLoggerImpl.java @@ -27,7 +27,7 @@ public class ServerLoggerImpl implements ServerLogger { return; } StringBuilder stringBuilder = new StringBuilder(); - stringBuilder.append(!sender? "发送:目标--->" + from:"接收:来自--->" + to) + stringBuilder.append(sender? "发送:目标--->" + from:"接收:来自--->" + to) .append("\r\n") .append(message); this.stackLogger.logInfo(stringBuilder.toString()); @@ -40,7 +40,7 @@ public class ServerLoggerImpl implements ServerLogger { return; } StringBuilder stringBuilder = new StringBuilder(); - stringBuilder.append(!sender? "发送: 目标->" + from :"接收:来自->" + to) + stringBuilder.append(sender? "发送: 目标->" + from :"接收:来自->" + to) .append("\r\n") .append(message); this.stackLogger.logInfo(stringBuilder.toString()); @@ -52,7 +52,7 @@ public class ServerLoggerImpl implements ServerLogger { return; } StringBuilder stringBuilder = new StringBuilder(); - stringBuilder.append(!sender? "发送: 目标->" + from :"接收:来自->" + to) + stringBuilder.append(sender? "发送: 目标->" + from :"接收:来自->" + to) .append("\r\n") .append(message); this.stackLogger.logInfo(stringBuilder.toString()); @@ -87,6 +87,4 @@ public class ServerLoggerImpl implements ServerLogger { this.stackLogger = this.sipStack.getStackLogger(); } } - - } 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 9f69950f..81e7fa65 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 @@ -96,7 +96,7 @@ public class RegisterRequestProcessor extends SIPRequestProcessorParent implemen RemoteAddressInfo remoteAddressInfo = SipUtils.getRemoteAddressFromRequest(request, userSetting.getSipUseSourceIpAsRemoteAddress()); - + logger.info("[注册请求] 设备:{}, 远程地址为: {}:{}", deviceId, remoteAddressInfo.getIp(), remoteAddressInfo.getPort()); if (device != null && device.getSipTransactionInfo() != null && request.getCallIdHeader().getCallId().equals(device.getSipTransactionInfo().getCallId())) { 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 865b6623..4d1a58e2 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 @@ -69,6 +69,7 @@ public class KeepaliveNotifyMessageHandler extends SIPRequestProcessorParent imp RemoteAddressInfo remoteAddressInfo = SipUtils.getRemoteAddressFromRequest(request, userSetting.getSipUseSourceIpAsRemoteAddress()); if (!device.getIp().equalsIgnoreCase(remoteAddressInfo.getIp()) || device.getPort() != remoteAddressInfo.getPort()) { + logger.info("[心跳] 设备{}地址变化, 远程地址为: {}:{}", device.getDeviceId(), remoteAddressInfo.getIp(), remoteAddressInfo.getPort()); device.setPort(remoteAddressInfo.getPort()); device.setHostAddress(remoteAddressInfo.getIp().concat(":").concat(String.valueOf(remoteAddressInfo.getPort()))); device.setIp(remoteAddressInfo.getIp()); diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/utils/SipUtils.java b/src/main/java/com/genersoft/iot/vmp/gb28181/utils/SipUtils.java index 1f4632ea..d6037a11 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/utils/SipUtils.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/utils/SipUtils.java @@ -133,8 +133,9 @@ public class SipUtils { String remoteAddress; int remotePort; if (sipUseSourceIpAsRemoteAddress) { - remoteAddress = request.getRemoteAddress().getHostAddress(); - remotePort = request.getRemotePort(); + remoteAddress = request.getPeerPacketSourceAddress().getHostAddress(); + remotePort = request.getPeerPacketSourcePort(); + }else { // 判断RPort是否改变,改变则说明路由nat信息变化,修改设备信息 // 获取到通信地址等信息 @@ -142,8 +143,8 @@ public class SipUtils { remotePort = request.getTopmostViaHeader().getRPort(); // 解析本地地址替代 if (ObjectUtils.isEmpty(remoteAddress) || remotePort == -1) { - remoteAddress = request.getRemoteAddress().getHostAddress(); - remotePort = request.getRemotePort(); + remoteAddress = request.getPeerPacketSourceAddress().getHostAddress(); + remotePort = request.getPeerPacketSourcePort(); } } diff --git a/src/main/java/com/genersoft/iot/vmp/storager/dao/DeviceChannelMapper.java b/src/main/java/com/genersoft/iot/vmp/storager/dao/DeviceChannelMapper.java index 3f4d804c..f81d1f87 100644 --- a/src/main/java/com/genersoft/iot/vmp/storager/dao/DeviceChannelMapper.java +++ b/src/main/java/com/genersoft/iot/vmp/storager/dao/DeviceChannelMapper.java @@ -271,6 +271,60 @@ public interface DeviceChannelMapper { "") int batchAdd(List addChannels); + + @Insert("") + int batchAddOrUpdate(List addChannels); + @Update(value = {"UPDATE device_channel SET status=1 WHERE deviceId=#{deviceId} AND channelId=#{channelId}"}) void online(String deviceId, String channelId); 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 206456d9..cee613db 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 @@ -184,10 +184,10 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage { if (i + limitCount > channels.size()) { toIndex = channels.size(); } - result = result || deviceChannelMapper.batchAdd(channels.subList(i, toIndex)) < 0; + result = result || deviceChannelMapper.batchAddOrUpdate(channels.subList(i, toIndex)) < 0; } }else { - result = result || deviceChannelMapper.batchAdd(channels) < 0; + result = result || deviceChannelMapper.batchAddOrUpdate(channels) < 0; } } if (result) { @@ -285,10 +285,10 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage { if (i + limitCount > addChannels.size()) { toIndex = addChannels.size(); } - result = result || deviceChannelMapper.batchAdd(addChannels.subList(i, toIndex)) < 0; + result = result || deviceChannelMapper.batchAddOrUpdate(addChannels.subList(i, toIndex)) < 0; } }else { - result = result || deviceChannelMapper.batchAdd(addChannels) < 0; + result = result || deviceChannelMapper.batchAddOrUpdate(addChannels) < 0; } } if (updateChannels.size() > 0) {