修复代码

This commit is contained in:
648540858 2022-05-12 10:48:50 +08:00
parent cf933d7d5e
commit 277c6ea039
7 changed files with 75 additions and 97 deletions

View File

@ -10,6 +10,7 @@ import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage;
import com.genersoft.iot.vmp.gb28181.transmit.event.request.SIPRequestProcessorParent;
import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.IMessageHandler;
import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.response.ResponseMessageHandler;
import com.genersoft.iot.vmp.service.IDeviceService;
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
import org.dom4j.DocumentException;
@ -56,6 +57,9 @@ public class DeviceInfoResponseMessageHandler extends SIPRequestProcessorParent
@Autowired
private EventPublisher publisher;
@Autowired
private IDeviceService deviceService;
@Override
public void afterPropertiesSet() throws Exception {
responseMessageHandler.addHandler(cmdType, this);
@ -82,7 +86,8 @@ public class DeviceInfoResponseMessageHandler extends SIPRequestProcessorParent
if (StringUtils.isEmpty(device.getStreamMode())) {
device.setStreamMode("UDP");
}
storager.updateDevice(device);
deviceService.updateDevice(device);
// storager.updateDevice(device);
RequestMessage msg = new RequestMessage();
msg.setKey(key);

View File

@ -104,4 +104,10 @@ public interface IDeviceService {
* @return 设备信息
*/
Device getDeviceByHostAndPort(String host, int port);
/**
* 更新设备
* @param device 设备信息
*/
void updateDevice(Device device);
}

View File

@ -21,6 +21,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import javax.sip.DialogState;
import javax.sip.TimeoutEvent;
@ -248,4 +249,61 @@ public class DeviceServiceImpl implements IDeviceService {
public Device getDeviceByHostAndPort(String host, int port) {
return deviceMapper.getDeviceByHostAndPort(host, port);
}
@Override
public void updateDevice(Device device) {
Device deviceInStore = deviceMapper.getDeviceByDeviceId(device.getDeviceId());
if (deviceInStore == null) {
logger.warn("更新设备时未找到设备信息");
return;
}
if (!StringUtils.isEmpty(device.getName())) {
deviceInStore.setName(device.getName());
}
if (!StringUtils.isEmpty(device.getCharset())) {
deviceInStore.setCharset(device.getCharset());
}
if (!StringUtils.isEmpty(device.getMediaServerId())) {
deviceInStore.setMediaServerId(device.getMediaServerId());
}
// 目录订阅相关的信息
if (device.getSubscribeCycleForCatalog() > 0) {
if (deviceInStore.getSubscribeCycleForCatalog() == 0 || deviceInStore.getSubscribeCycleForCatalog() != device.getSubscribeCycleForCatalog()) {
deviceInStore.setSubscribeCycleForCatalog(device.getSubscribeCycleForCatalog());
// 开启订阅
addCatalogSubscribe(deviceInStore);
}
}else if (device.getSubscribeCycleForCatalog() == 0) {
if (deviceInStore.getSubscribeCycleForCatalog() != 0) {
deviceInStore.setSubscribeCycleForCatalog(device.getSubscribeCycleForCatalog());
// 取消订阅
removeCatalogSubscribe(deviceInStore);
}
}
// 移动位置订阅相关的信息
if (device.getSubscribeCycleForMobilePosition() > 0) {
if (deviceInStore.getSubscribeCycleForMobilePosition() == 0 || deviceInStore.getSubscribeCycleForMobilePosition() != device.getSubscribeCycleForMobilePosition()) {
deviceInStore.setMobilePositionSubmissionInterval(device.getMobilePositionSubmissionInterval());
deviceInStore.setSubscribeCycleForMobilePosition(device.getSubscribeCycleForMobilePosition());
// 开启订阅
addMobilePositionSubscribe(deviceInStore);
}
}else if (device.getSubscribeCycleForMobilePosition() == 0) {
if (deviceInStore.getSubscribeCycleForMobilePosition() != 0) {
// 取消订阅
removeMobilePositionSubscribe(deviceInStore);
}
}
String now = DateUtil.getNow();
device.setUpdateTime(now);
device.setCharset(device.getCharset().toUpperCase());
device.setUpdateTime(DateUtil.getNow());
if (deviceMapper.update(device) > 0) {
redisCatchStorage.updateDevice(device);
}
}
}

View File

@ -26,22 +26,6 @@ public interface IVideoManagerStorage {
*/
public boolean exists(String deviceId);
/**
* 视频设备创建
*
* @param device 设备对象
* @return true创建成功 false创建失败
*/
public boolean create(Device device);
/**
* 视频设备更新
*
* @param device 设备对象
* @return true创建成功 false创建失败
*/
public boolean updateDevice(Device device);
/**
* 添加设备通道
*

View File

@ -102,43 +102,6 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage {
return deviceMapper.getDeviceByDeviceId(deviceId) != null;
}
/**
* 视频设备创建
*
* @param device 设备对象
* @return true创建成功 false创建失败
*/
@Override
public synchronized boolean create(Device device) {
redisCatchStorage.updateDevice(device);
return deviceMapper.add(device) > 0;
}
/**
* 视频设备更新
*
* @param device 设备对象
* @return true更新成功 false更新失败
*/
@Override
public synchronized boolean updateDevice(Device device) {
String now = DateUtil.getNow();
device.setUpdateTime(now);
Device deviceByDeviceId = deviceMapper.getDeviceByDeviceId(device.getDeviceId());
device.setCharset(device.getCharset().toUpperCase());
if (deviceByDeviceId == null) {
device.setCreateTime(now);
redisCatchStorage.updateDevice(device);
return deviceMapper.add(device) > 0;
}else {
redisCatchStorage.updateDevice(device);
return deviceMapper.update(device) > 0;
}
}
@Override
public synchronized void updateChannel(String deviceId, DeviceChannel channel) {
String channelId = channel.getChannelId();

View File

@ -169,7 +169,7 @@ public class MobilePositionController {
Device device = storager.queryVideoDevice(deviceId);
device.setSubscribeCycleForMobilePosition(Integer.parseInt(expires));
device.setMobilePositionSubmissionInterval(Integer.parseInt(interval));
storager.updateDevice(device);
deviceService.updateDevice(device);
String result = msg;
if (deviceService.removeMobilePositionSubscribe(device)) {
result += ",成功";

View File

@ -288,7 +288,8 @@ public class DeviceQuery {
public ResponseEntity<PageInfo> updateTransport(@PathVariable String deviceId, @PathVariable String streamMode){
Device device = storager.queryVideoDevice(deviceId);
device.setStreamMode(streamMode);
storager.updateDevice(device);
// storager.updateDevice(device);
deviceService.updateDevice(device);
return new ResponseEntity<>(null,HttpStatus.OK);
}
@ -305,51 +306,12 @@ public class DeviceQuery {
public ResponseEntity<WVPResult<String>> updateDevice(Device device){
if (device != null && device.getDeviceId() != null) {
Device deviceInStore = storager.queryVideoDevice(device.getDeviceId());
if (!StringUtils.isEmpty(device.getName())) {
deviceInStore.setName(device.getName());
}
if (!StringUtils.isEmpty(device.getCharset())) {
deviceInStore.setCharset(device.getCharset());
}
if (!StringUtils.isEmpty(device.getMediaServerId())) {
deviceInStore.setMediaServerId(device.getMediaServerId());
}
// 目录订阅相关的信息
if (device.getSubscribeCycleForCatalog() > 0) {
if (deviceInStore.getSubscribeCycleForCatalog() == 0 || deviceInStore.getSubscribeCycleForCatalog() != device.getSubscribeCycleForCatalog()) {
deviceInStore.setSubscribeCycleForCatalog(device.getSubscribeCycleForCatalog());
// 开启订阅
deviceService.addCatalogSubscribe(deviceInStore);
}
}else if (device.getSubscribeCycleForCatalog() == 0) {
if (deviceInStore.getSubscribeCycleForCatalog() != 0) {
deviceInStore.setSubscribeCycleForCatalog(device.getSubscribeCycleForCatalog());
// 取消订阅
deviceService.removeCatalogSubscribe(deviceInStore);
}
}
// 移动位置订阅相关的信息
if (device.getSubscribeCycleForMobilePosition() > 0) {
if (deviceInStore.getSubscribeCycleForMobilePosition() == 0 || deviceInStore.getSubscribeCycleForMobilePosition() != device.getSubscribeCycleForMobilePosition()) {
deviceInStore.setMobilePositionSubmissionInterval(device.getMobilePositionSubmissionInterval());
deviceInStore.setSubscribeCycleForMobilePosition(device.getSubscribeCycleForMobilePosition());
// 开启订阅
deviceService.addMobilePositionSubscribe(deviceInStore);
}
}else if (device.getSubscribeCycleForMobilePosition() == 0) {
if (deviceInStore.getSubscribeCycleForMobilePosition() != 0) {
// 取消订阅
deviceService.removeMobilePositionSubscribe(deviceInStore);
}
}
// TODO 报警订阅相关的信息
storager.updateDevice(device);
cmder.deviceInfoQuery(device);
deviceService.updateDevice(device);
// cmder.deviceInfoQuery(device);
}
WVPResult<String> result = new WVPResult<>();
result.setCode(0);