Commit a030d00c8819612de2c280b75abdc90573eb52ce
1 parent
3cd1378d
修复代码
Showing
7 changed files
with
75 additions
and
97 deletions
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/DeviceInfoResponseMessageHandler.java
| ... | ... | @@ -10,6 +10,7 @@ import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage; |
| 10 | 10 | import com.genersoft.iot.vmp.gb28181.transmit.event.request.SIPRequestProcessorParent; |
| 11 | 11 | import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.IMessageHandler; |
| 12 | 12 | import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.response.ResponseMessageHandler; |
| 13 | +import com.genersoft.iot.vmp.service.IDeviceService; | |
| 13 | 14 | import com.genersoft.iot.vmp.storager.IRedisCatchStorage; |
| 14 | 15 | import com.genersoft.iot.vmp.storager.IVideoManagerStorage; |
| 15 | 16 | import org.dom4j.DocumentException; |
| ... | ... | @@ -56,6 +57,9 @@ public class DeviceInfoResponseMessageHandler extends SIPRequestProcessorParent |
| 56 | 57 | @Autowired |
| 57 | 58 | private EventPublisher publisher; |
| 58 | 59 | |
| 60 | + @Autowired | |
| 61 | + private IDeviceService deviceService; | |
| 62 | + | |
| 59 | 63 | @Override |
| 60 | 64 | public void afterPropertiesSet() throws Exception { |
| 61 | 65 | responseMessageHandler.addHandler(cmdType, this); |
| ... | ... | @@ -82,7 +86,8 @@ public class DeviceInfoResponseMessageHandler extends SIPRequestProcessorParent |
| 82 | 86 | if (StringUtils.isEmpty(device.getStreamMode())) { |
| 83 | 87 | device.setStreamMode("UDP"); |
| 84 | 88 | } |
| 85 | - storager.updateDevice(device); | |
| 89 | + deviceService.updateDevice(device); | |
| 90 | +// storager.updateDevice(device); | |
| 86 | 91 | |
| 87 | 92 | RequestMessage msg = new RequestMessage(); |
| 88 | 93 | msg.setKey(key); | ... | ... |
src/main/java/com/genersoft/iot/vmp/service/IDeviceService.java
src/main/java/com/genersoft/iot/vmp/service/impl/DeviceServiceImpl.java
| ... | ... | @@ -21,6 +21,7 @@ import org.springframework.beans.factory.annotation.Autowired; |
| 21 | 21 | import org.springframework.beans.factory.annotation.Qualifier; |
| 22 | 22 | import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; |
| 23 | 23 | import org.springframework.stereotype.Service; |
| 24 | +import org.springframework.util.StringUtils; | |
| 24 | 25 | |
| 25 | 26 | import javax.sip.DialogState; |
| 26 | 27 | import javax.sip.TimeoutEvent; |
| ... | ... | @@ -248,4 +249,61 @@ public class DeviceServiceImpl implements IDeviceService { |
| 248 | 249 | public Device getDeviceByHostAndPort(String host, int port) { |
| 249 | 250 | return deviceMapper.getDeviceByHostAndPort(host, port); |
| 250 | 251 | } |
| 252 | + | |
| 253 | + @Override | |
| 254 | + public void updateDevice(Device device) { | |
| 255 | + | |
| 256 | + Device deviceInStore = deviceMapper.getDeviceByDeviceId(device.getDeviceId()); | |
| 257 | + if (deviceInStore == null) { | |
| 258 | + logger.warn("更新设备时未找到设备信息"); | |
| 259 | + return; | |
| 260 | + } | |
| 261 | + if (!StringUtils.isEmpty(device.getName())) { | |
| 262 | + deviceInStore.setName(device.getName()); | |
| 263 | + } | |
| 264 | + if (!StringUtils.isEmpty(device.getCharset())) { | |
| 265 | + deviceInStore.setCharset(device.getCharset()); | |
| 266 | + } | |
| 267 | + if (!StringUtils.isEmpty(device.getMediaServerId())) { | |
| 268 | + deviceInStore.setMediaServerId(device.getMediaServerId()); | |
| 269 | + } | |
| 270 | + | |
| 271 | + // 目录订阅相关的信息 | |
| 272 | + if (device.getSubscribeCycleForCatalog() > 0) { | |
| 273 | + if (deviceInStore.getSubscribeCycleForCatalog() == 0 || deviceInStore.getSubscribeCycleForCatalog() != device.getSubscribeCycleForCatalog()) { | |
| 274 | + deviceInStore.setSubscribeCycleForCatalog(device.getSubscribeCycleForCatalog()); | |
| 275 | + // 开启订阅 | |
| 276 | + addCatalogSubscribe(deviceInStore); | |
| 277 | + } | |
| 278 | + }else if (device.getSubscribeCycleForCatalog() == 0) { | |
| 279 | + if (deviceInStore.getSubscribeCycleForCatalog() != 0) { | |
| 280 | + deviceInStore.setSubscribeCycleForCatalog(device.getSubscribeCycleForCatalog()); | |
| 281 | + // 取消订阅 | |
| 282 | + removeCatalogSubscribe(deviceInStore); | |
| 283 | + } | |
| 284 | + } | |
| 285 | + | |
| 286 | + // 移动位置订阅相关的信息 | |
| 287 | + if (device.getSubscribeCycleForMobilePosition() > 0) { | |
| 288 | + if (deviceInStore.getSubscribeCycleForMobilePosition() == 0 || deviceInStore.getSubscribeCycleForMobilePosition() != device.getSubscribeCycleForMobilePosition()) { | |
| 289 | + deviceInStore.setMobilePositionSubmissionInterval(device.getMobilePositionSubmissionInterval()); | |
| 290 | + deviceInStore.setSubscribeCycleForMobilePosition(device.getSubscribeCycleForMobilePosition()); | |
| 291 | + // 开启订阅 | |
| 292 | + addMobilePositionSubscribe(deviceInStore); | |
| 293 | + } | |
| 294 | + }else if (device.getSubscribeCycleForMobilePosition() == 0) { | |
| 295 | + if (deviceInStore.getSubscribeCycleForMobilePosition() != 0) { | |
| 296 | + // 取消订阅 | |
| 297 | + removeMobilePositionSubscribe(deviceInStore); | |
| 298 | + } | |
| 299 | + } | |
| 300 | + | |
| 301 | + String now = DateUtil.getNow(); | |
| 302 | + device.setUpdateTime(now); | |
| 303 | + device.setCharset(device.getCharset().toUpperCase()); | |
| 304 | + device.setUpdateTime(DateUtil.getNow()); | |
| 305 | + if (deviceMapper.update(device) > 0) { | |
| 306 | + redisCatchStorage.updateDevice(device); | |
| 307 | + } | |
| 308 | + } | |
| 251 | 309 | } | ... | ... |
src/main/java/com/genersoft/iot/vmp/storager/IVideoManagerStorage.java
| ... | ... | @@ -25,22 +25,6 @@ public interface IVideoManagerStorage { |
| 25 | 25 | * @return true:存在 false:不存在 |
| 26 | 26 | */ |
| 27 | 27 | public boolean exists(String deviceId); |
| 28 | - | |
| 29 | - /** | |
| 30 | - * 视频设备创建 | |
| 31 | - * | |
| 32 | - * @param device 设备对象 | |
| 33 | - * @return true:创建成功 false:创建失败 | |
| 34 | - */ | |
| 35 | - public boolean create(Device device); | |
| 36 | - | |
| 37 | - /** | |
| 38 | - * 视频设备更新 | |
| 39 | - * | |
| 40 | - * @param device 设备对象 | |
| 41 | - * @return true:创建成功 false:创建失败 | |
| 42 | - */ | |
| 43 | - public boolean updateDevice(Device device); | |
| 44 | 28 | |
| 45 | 29 | /** |
| 46 | 30 | * 添加设备通道 | ... | ... |
src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStorageImpl.java
| ... | ... | @@ -102,43 +102,6 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage { |
| 102 | 102 | return deviceMapper.getDeviceByDeviceId(deviceId) != null; |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | - /** | |
| 106 | - * 视频设备创建 | |
| 107 | - * | |
| 108 | - * @param device 设备对象 | |
| 109 | - * @return true:创建成功 false:创建失败 | |
| 110 | - */ | |
| 111 | - @Override | |
| 112 | - public synchronized boolean create(Device device) { | |
| 113 | - redisCatchStorage.updateDevice(device); | |
| 114 | - return deviceMapper.add(device) > 0; | |
| 115 | - } | |
| 116 | - | |
| 117 | - | |
| 118 | - | |
| 119 | - /** | |
| 120 | - * 视频设备更新 | |
| 121 | - * | |
| 122 | - * @param device 设备对象 | |
| 123 | - * @return true:更新成功 false:更新失败 | |
| 124 | - */ | |
| 125 | - @Override | |
| 126 | - public synchronized boolean updateDevice(Device device) { | |
| 127 | - String now = DateUtil.getNow(); | |
| 128 | - device.setUpdateTime(now); | |
| 129 | - Device deviceByDeviceId = deviceMapper.getDeviceByDeviceId(device.getDeviceId()); | |
| 130 | - device.setCharset(device.getCharset().toUpperCase()); | |
| 131 | - if (deviceByDeviceId == null) { | |
| 132 | - device.setCreateTime(now); | |
| 133 | - redisCatchStorage.updateDevice(device); | |
| 134 | - return deviceMapper.add(device) > 0; | |
| 135 | - }else { | |
| 136 | - redisCatchStorage.updateDevice(device); | |
| 137 | - | |
| 138 | - return deviceMapper.update(device) > 0; | |
| 139 | - } | |
| 140 | - } | |
| 141 | - | |
| 142 | 105 | @Override |
| 143 | 106 | public synchronized void updateChannel(String deviceId, DeviceChannel channel) { |
| 144 | 107 | String channelId = channel.getChannelId(); | ... | ... |
src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/MobilePosition/MobilePositionController.java
| ... | ... | @@ -169,7 +169,7 @@ public class MobilePositionController { |
| 169 | 169 | Device device = storager.queryVideoDevice(deviceId); |
| 170 | 170 | device.setSubscribeCycleForMobilePosition(Integer.parseInt(expires)); |
| 171 | 171 | device.setMobilePositionSubmissionInterval(Integer.parseInt(interval)); |
| 172 | - storager.updateDevice(device); | |
| 172 | + deviceService.updateDevice(device); | |
| 173 | 173 | String result = msg; |
| 174 | 174 | if (deviceService.removeMobilePositionSubscribe(device)) { |
| 175 | 175 | result += ",成功"; | ... | ... |
src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/device/DeviceQuery.java
| ... | ... | @@ -288,7 +288,8 @@ public class DeviceQuery { |
| 288 | 288 | public ResponseEntity<PageInfo> updateTransport(@PathVariable String deviceId, @PathVariable String streamMode){ |
| 289 | 289 | Device device = storager.queryVideoDevice(deviceId); |
| 290 | 290 | device.setStreamMode(streamMode); |
| 291 | - storager.updateDevice(device); | |
| 291 | +// storager.updateDevice(device); | |
| 292 | + deviceService.updateDevice(device); | |
| 292 | 293 | return new ResponseEntity<>(null,HttpStatus.OK); |
| 293 | 294 | } |
| 294 | 295 | |
| ... | ... | @@ -305,51 +306,12 @@ public class DeviceQuery { |
| 305 | 306 | public ResponseEntity<WVPResult<String>> updateDevice(Device device){ |
| 306 | 307 | |
| 307 | 308 | if (device != null && device.getDeviceId() != null) { |
| 308 | - Device deviceInStore = storager.queryVideoDevice(device.getDeviceId()); | |
| 309 | - if (!StringUtils.isEmpty(device.getName())) { | |
| 310 | - deviceInStore.setName(device.getName()); | |
| 311 | - } | |
| 312 | - if (!StringUtils.isEmpty(device.getCharset())) { | |
| 313 | - deviceInStore.setCharset(device.getCharset()); | |
| 314 | - } | |
| 315 | - if (!StringUtils.isEmpty(device.getMediaServerId())) { | |
| 316 | - deviceInStore.setMediaServerId(device.getMediaServerId()); | |
| 317 | - } | |
| 318 | - | |
| 319 | - // 目录订阅相关的信息 | |
| 320 | - if (device.getSubscribeCycleForCatalog() > 0) { | |
| 321 | - if (deviceInStore.getSubscribeCycleForCatalog() == 0 || deviceInStore.getSubscribeCycleForCatalog() != device.getSubscribeCycleForCatalog()) { | |
| 322 | - deviceInStore.setSubscribeCycleForCatalog(device.getSubscribeCycleForCatalog()); | |
| 323 | - // 开启订阅 | |
| 324 | - deviceService.addCatalogSubscribe(deviceInStore); | |
| 325 | - } | |
| 326 | - }else if (device.getSubscribeCycleForCatalog() == 0) { | |
| 327 | - if (deviceInStore.getSubscribeCycleForCatalog() != 0) { | |
| 328 | - deviceInStore.setSubscribeCycleForCatalog(device.getSubscribeCycleForCatalog()); | |
| 329 | - // 取消订阅 | |
| 330 | - deviceService.removeCatalogSubscribe(deviceInStore); | |
| 331 | - } | |
| 332 | - } | |
| 333 | 309 | |
| 334 | - // 移动位置订阅相关的信息 | |
| 335 | - if (device.getSubscribeCycleForMobilePosition() > 0) { | |
| 336 | - if (deviceInStore.getSubscribeCycleForMobilePosition() == 0 || deviceInStore.getSubscribeCycleForMobilePosition() != device.getSubscribeCycleForMobilePosition()) { | |
| 337 | - deviceInStore.setMobilePositionSubmissionInterval(device.getMobilePositionSubmissionInterval()); | |
| 338 | - deviceInStore.setSubscribeCycleForMobilePosition(device.getSubscribeCycleForMobilePosition()); | |
| 339 | - // 开启订阅 | |
| 340 | - deviceService.addMobilePositionSubscribe(deviceInStore); | |
| 341 | - } | |
| 342 | - }else if (device.getSubscribeCycleForMobilePosition() == 0) { | |
| 343 | - if (deviceInStore.getSubscribeCycleForMobilePosition() != 0) { | |
| 344 | - // 取消订阅 | |
| 345 | - deviceService.removeMobilePositionSubscribe(deviceInStore); | |
| 346 | - } | |
| 347 | - } | |
| 348 | 310 | |
| 349 | 311 | // TODO 报警订阅相关的信息 |
| 350 | 312 | |
| 351 | - storager.updateDevice(device); | |
| 352 | - cmder.deviceInfoQuery(device); | |
| 313 | + deviceService.updateDevice(device); | |
| 314 | +// cmder.deviceInfoQuery(device); | |
| 353 | 315 | } |
| 354 | 316 | WVPResult<String> result = new WVPResult<>(); |
| 355 | 317 | result.setCode(0); | ... | ... |