Commit 269ad8cedbb07ca207a6f33af23085894dab4aa6

Authored by 648540858
1 parent 22deb206

修身目录刷新,优化公网下远程IP端口的获取

src/main/java/com/genersoft/iot/vmp/gb28181/conf/ServerLoggerImpl.java
... ... @@ -27,7 +27,7 @@ public class ServerLoggerImpl implements ServerLogger {
27 27 return;
28 28 }
29 29 StringBuilder stringBuilder = new StringBuilder();
30   - stringBuilder.append(!sender? "发送:目标--->" + from:"接收:来自--->" + to)
  30 + stringBuilder.append(sender? "发送:目标--->" + from:"接收:来自--->" + to)
31 31 .append("\r\n")
32 32 .append(message);
33 33 this.stackLogger.logInfo(stringBuilder.toString());
... ... @@ -40,7 +40,7 @@ public class ServerLoggerImpl implements ServerLogger {
40 40 return;
41 41 }
42 42 StringBuilder stringBuilder = new StringBuilder();
43   - stringBuilder.append(!sender? "发送: 目标->" + from :"接收:来自->" + to)
  43 + stringBuilder.append(sender? "发送: 目标->" + from :"接收:来自->" + to)
44 44 .append("\r\n")
45 45 .append(message);
46 46 this.stackLogger.logInfo(stringBuilder.toString());
... ... @@ -52,7 +52,7 @@ public class ServerLoggerImpl implements ServerLogger {
52 52 return;
53 53 }
54 54 StringBuilder stringBuilder = new StringBuilder();
55   - stringBuilder.append(!sender? "发送: 目标->" + from :"接收:来自->" + to)
  55 + stringBuilder.append(sender? "发送: 目标->" + from :"接收:来自->" + to)
56 56 .append("\r\n")
57 57 .append(message);
58 58 this.stackLogger.logInfo(stringBuilder.toString());
... ... @@ -87,6 +87,4 @@ public class ServerLoggerImpl implements ServerLogger {
87 87 this.stackLogger = this.sipStack.getStackLogger();
88 88 }
89 89 }
90   -
91   -
92 90 }
... ...
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/RegisterRequestProcessor.java
... ... @@ -96,7 +96,7 @@ public class RegisterRequestProcessor extends SIPRequestProcessorParent implemen
96 96  
97 97 RemoteAddressInfo remoteAddressInfo = SipUtils.getRemoteAddressFromRequest(request,
98 98 userSetting.getSipUseSourceIpAsRemoteAddress());
99   -
  99 + logger.info("[注册请求] 设备:{}, 远程地址为: {}:{}", deviceId, remoteAddressInfo.getIp(), remoteAddressInfo.getPort());
100 100 if (device != null &&
101 101 device.getSipTransactionInfo() != null &&
102 102 request.getCallIdHeader().getCallId().equals(device.getSipTransactionInfo().getCallId())) {
... ...
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
69 69  
70 70 RemoteAddressInfo remoteAddressInfo = SipUtils.getRemoteAddressFromRequest(request, userSetting.getSipUseSourceIpAsRemoteAddress());
71 71 if (!device.getIp().equalsIgnoreCase(remoteAddressInfo.getIp()) || device.getPort() != remoteAddressInfo.getPort()) {
  72 + logger.info("[心跳] 设备{}地址变化, 远程地址为: {}:{}", device.getDeviceId(), remoteAddressInfo.getIp(), remoteAddressInfo.getPort());
72 73 device.setPort(remoteAddressInfo.getPort());
73 74 device.setHostAddress(remoteAddressInfo.getIp().concat(":").concat(String.valueOf(remoteAddressInfo.getPort())));
74 75 device.setIp(remoteAddressInfo.getIp());
... ...
src/main/java/com/genersoft/iot/vmp/gb28181/utils/SipUtils.java
... ... @@ -133,8 +133,9 @@ public class SipUtils {
133 133 String remoteAddress;
134 134 int remotePort;
135 135 if (sipUseSourceIpAsRemoteAddress) {
136   - remoteAddress = request.getRemoteAddress().getHostAddress();
137   - remotePort = request.getRemotePort();
  136 + remoteAddress = request.getPeerPacketSourceAddress().getHostAddress();
  137 + remotePort = request.getPeerPacketSourcePort();
  138 +
138 139 }else {
139 140 // 判断RPort是否改变,改变则说明路由nat信息变化,修改设备信息
140 141 // 获取到通信地址等信息
... ... @@ -142,8 +143,8 @@ public class SipUtils {
142 143 remotePort = request.getTopmostViaHeader().getRPort();
143 144 // 解析本地地址替代
144 145 if (ObjectUtils.isEmpty(remoteAddress) || remotePort == -1) {
145   - remoteAddress = request.getRemoteAddress().getHostAddress();
146   - remotePort = request.getRemotePort();
  146 + remoteAddress = request.getPeerPacketSourceAddress().getHostAddress();
  147 + remotePort = request.getPeerPacketSourcePort();
147 148 }
148 149 }
149 150  
... ...
src/main/java/com/genersoft/iot/vmp/storager/dao/DeviceChannelMapper.java
... ... @@ -271,6 +271,60 @@ public interface DeviceChannelMapper {
271 271 "</script>")
272 272 int batchAdd(List<DeviceChannel> addChannels);
273 273  
  274 +
  275 + @Insert("<script> " +
  276 + "insert into device_channel " +
  277 + "(channelId, deviceId, name, manufacture, model, owner, civilCode, block, subCount, " +
  278 + " address, parental, parentId, safetyWay, registerWay, certNum, certifiable, errCode, secrecy, " +
  279 + " ipAddress, port, password, PTZType, status, streamId, longitude, latitude, longitudeGcj02, latitudeGcj02, " +
  280 + " longitudeWgs84, latitudeWgs84, hasAudio, createTime, updateTime, businessGroupId, gpsTime) " +
  281 + "values " +
  282 + "<foreach collection='addChannels' index='index' item='item' separator=','> " +
  283 + "(#{item.channelId}, #{item.deviceId}, #{item.name}, #{item.manufacture}, #{item.model}, " +
  284 + "#{item.owner}, #{item.civilCode}, #{item.block},#{item.subCount}," +
  285 + "#{item.address}, #{item.parental}, #{item.parentId}, #{item.safetyWay}, #{item.registerWay}, " +
  286 + "#{item.certNum}, #{item.certifiable}, #{item.errCode}, #{item.secrecy}, " +
  287 + "#{item.ipAddress}, #{item.port}, #{item.password}, #{item.PTZType}, #{item.status}, " +
  288 + "#{item.streamId}, #{item.longitude}, #{item.latitude},#{item.longitudeGcj02}, " +
  289 + "#{item.latitudeGcj02},#{item.longitudeWgs84}, #{item.latitudeWgs84}, #{item.hasAudio}, now(), now(), " +
  290 + "#{item.businessGroupId}, #{item.gpsTime}) " +
  291 + "</foreach> " +
  292 + "ON DUPLICATE KEY UPDATE " +
  293 + "updateTime=VALUES(updateTime), " +
  294 + "name=VALUES(name), " +
  295 + "manufacture=VALUES(manufacture), " +
  296 + "model=VALUES(model), " +
  297 + "owner=VALUES(owner), " +
  298 + "civilCode=VALUES(civilCode), " +
  299 + "block=VALUES(block), " +
  300 + "subCount=VALUES(subCount), " +
  301 + "address=VALUES(address), " +
  302 + "parental=VALUES(parental), " +
  303 + "parentId=VALUES(parentId), " +
  304 + "safetyWay=VALUES(safetyWay), " +
  305 + "registerWay=VALUES(registerWay), " +
  306 + "certNum=VALUES(certNum), " +
  307 + "certifiable=VALUES(certifiable), " +
  308 + "errCode=VALUES(errCode), " +
  309 + "secrecy=VALUES(secrecy), " +
  310 + "ipAddress=VALUES(ipAddress), " +
  311 + "port=VALUES(port), " +
  312 + "password=VALUES(password), " +
  313 + "PTZType=VALUES(PTZType), " +
  314 + "status=VALUES(status), " +
  315 + "streamId=VALUES(streamId), " +
  316 + "longitude=VALUES(longitude), " +
  317 + "latitude=VALUES(latitude), " +
  318 + "longitudeGcj02=VALUES(longitudeGcj02), " +
  319 + "latitudeGcj02=VALUES(latitudeGcj02), " +
  320 + "longitudeWgs84=VALUES(longitudeWgs84), " +
  321 + "latitudeWgs84=VALUES(latitudeWgs84), " +
  322 + "hasAudio=VALUES(hasAudio), " +
  323 + "businessGroupId=VALUES(businessGroupId), " +
  324 + "gpsTime=VALUES(gpsTime)" +
  325 + "</script>")
  326 + int batchAddOrUpdate(List<DeviceChannel> addChannels);
  327 +
274 328 @Update(value = {"UPDATE device_channel SET status=1 WHERE deviceId=#{deviceId} AND channelId=#{channelId}"})
275 329 void online(String deviceId, String channelId);
276 330  
... ...
src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStorageImpl.java
... ... @@ -184,10 +184,10 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage {
184 184 if (i + limitCount > channels.size()) {
185 185 toIndex = channels.size();
186 186 }
187   - result = result || deviceChannelMapper.batchAdd(channels.subList(i, toIndex)) < 0;
  187 + result = result || deviceChannelMapper.batchAddOrUpdate(channels.subList(i, toIndex)) < 0;
188 188 }
189 189 }else {
190   - result = result || deviceChannelMapper.batchAdd(channels) < 0;
  190 + result = result || deviceChannelMapper.batchAddOrUpdate(channels) < 0;
191 191 }
192 192 }
193 193 if (result) {
... ... @@ -285,10 +285,10 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage {
285 285 if (i + limitCount > addChannels.size()) {
286 286 toIndex = addChannels.size();
287 287 }
288   - result = result || deviceChannelMapper.batchAdd(addChannels.subList(i, toIndex)) < 0;
  288 + result = result || deviceChannelMapper.batchAddOrUpdate(addChannels.subList(i, toIndex)) < 0;
289 289 }
290 290 }else {
291   - result = result || deviceChannelMapper.batchAdd(addChannels) < 0;
  291 + result = result || deviceChannelMapper.batchAddOrUpdate(addChannels) < 0;
292 292 }
293 293 }
294 294 if (updateChannels.size() > 0) {
... ...