From c8831bc58fd967a4215cbe3ea8c89d753b4d31f7 Mon Sep 17 00:00:00 2001
From: wangyimeng <421132955@qq.com>
Date: 星期五, 06 五月 2022 11:56:29 +0800
Subject: [PATCH] 更新同步wvp

---
 src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStorageImpl.java |   98 ++++++++++++++++++++++++++----------------------
 1 files changed, 53 insertions(+), 45 deletions(-)

diff --git a/src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStoragerImpl.java b/src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStorageImpl.java
similarity index 92%
rename from src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStoragerImpl.java
rename to src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStorageImpl.java
index feabbf1..2dc88f8 100644
--- a/src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStoragerImpl.java
+++ b/src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStorageImpl.java
@@ -5,18 +5,14 @@
 import com.genersoft.iot.vmp.gb28181.bean.*;
 import com.genersoft.iot.vmp.gb28181.event.EventPublisher;
 import com.genersoft.iot.vmp.gb28181.event.subscribe.catalog.CatalogEvent;
-import com.genersoft.iot.vmp.gb28181.session.VideoStreamSessionManager;
-import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
 import com.genersoft.iot.vmp.media.zlm.dto.StreamProxyItem;
 import com.genersoft.iot.vmp.media.zlm.dto.StreamPushItem;
 import com.genersoft.iot.vmp.service.IGbStreamService;
 import com.genersoft.iot.vmp.service.bean.GPSMsgInfo;
 import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
-import com.genersoft.iot.vmp.storager.IVideoManagerStorager;
+import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
 import com.genersoft.iot.vmp.storager.dao.*;
 import com.genersoft.iot.vmp.storager.dao.dto.ChannelSourceInfo;
-import com.genersoft.iot.vmp.utils.node.ForestNodeMerger;
-import com.genersoft.iot.vmp.vmanager.bean.DeviceChannelTree;
 import com.genersoft.iot.vmp.vmanager.gb28181.platform.bean.ChannelReduce;
 import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageInfo;
@@ -40,9 +36,9 @@
  */
 @SuppressWarnings("rawtypes")
 @Component
-public class VideoManagerStoragerImpl implements IVideoManagerStorager {
+public class VideoManagerStorageImpl implements IVideoManagerStorage {
 
-	private final Logger logger = LoggerFactory.getLogger(VideoManagerStoragerImpl.class);
+	private final Logger logger = LoggerFactory.getLogger(VideoManagerStorageImpl.class);
 
 	@Autowired
 	EventPublisher eventPublisher;
@@ -85,7 +81,6 @@
 
 	@Autowired
     private PlatformCatalogMapper catalogMapper;
-;
 
 	@Autowired
     private PlatformGbStreamMapper platformGbStreamMapper;
@@ -96,13 +91,7 @@
 	@Autowired
     private ParentPlatformMapper parentPlatformMapper;
 
-	@Autowired
-    private VideoStreamSessionManager streamSession;
-
-	@Autowired
-    private MediaServerMapper mediaServerMapper;
-
-	private SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+	private final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
 
 
 	/**
@@ -141,6 +130,7 @@
 		String now = this.format.format(System.currentTimeMillis());
 		device.setUpdateTime(now);
 		Device deviceByDeviceId = deviceMapper.getDeviceByDeviceId(device.getDeviceId());
+		device.setCharset(device.getCharset().toUpperCase());
 		if (deviceByDeviceId == null) {
 			device.setCreateTime(now);
 			redisCatchStorage.updateDevice(device);
@@ -246,12 +236,15 @@
 
 	@Override
 	public boolean resetChannels(String deviceId, List<DeviceChannel> deviceChannelList) {
+		if (deviceChannelList == null) {
+			return false;
+		}
 		TransactionStatus transactionStatus = dataSourceTransactionManager.getTransaction(transactionDefinition);
 		// 鏁版嵁鍘婚噸
 		List<DeviceChannel> channels = new ArrayList<>();
 		StringBuilder stringBuilder = new StringBuilder();
 		Map<String, Integer> subContMap = new HashMap<>();
-		if (deviceChannelList.size() > 1) {
+		if (deviceChannelList != null && deviceChannelList.size() > 1) {
 			// 鏁版嵁鍘婚噸
 			Set<String> gbIdSet = new HashSet<>();
 			for (DeviceChannel deviceChannel : deviceChannelList) {
@@ -267,7 +260,7 @@
 						}
 					}
 				}else {
-					stringBuilder.append(deviceChannel.getChannelId() + ",");
+					stringBuilder.append(deviceChannel.getChannelId()).append(",");
 				}
 			}
 			if (channels.size() > 0) {
@@ -282,10 +275,9 @@
 			channels = deviceChannelList;
 		}
 		if (stringBuilder.length() > 0) {
-			logger.debug("[鐩綍鏌ヨ]鏀跺埌鐨勬暟鎹瓨鍦ㄩ噸澶嶏細 {}" , stringBuilder);
+			logger.info("[鐩綍鏌ヨ]鏀跺埌鐨勬暟鎹瓨鍦ㄩ噸澶嶏細 {}" , stringBuilder);
 		}
 		try {
-//			int cleanChannelsResult = deviceChannelMapper.cleanChannelsByDeviceId(deviceId);
 			int cleanChannelsResult = deviceChannelMapper.cleanChannelsNotInList(deviceId, channels);
 			int limitCount = 300;
 			boolean result = cleanChannelsResult < 0;
@@ -309,6 +301,7 @@
 			dataSourceTransactionManager.commit(transactionStatus);     //鎵嬪姩鎻愪氦
 			return true;
 		}catch (Exception e) {
+			e.printStackTrace();
 			dataSourceTransactionManager.rollback(transactionStatus);
 			return false;
 		}
@@ -347,10 +340,15 @@
 	}
 
 	@Override
-	public PageInfo queryChannelsByDeviceId(String deviceId, String query, Boolean hasSubChannel, Boolean online, int page, int count) {
+	public PageInfo queryChannelsByDeviceId(String deviceId, String query, Boolean hasSubChannel, Boolean online, Boolean catalogUnderDevice, int page, int count) {
 		// 鑾峰彇鍒版墍鏈夋鍦ㄦ挱鏀剧殑娴�
 		PageHelper.startPage(page, count);
-		List<DeviceChannel> all = deviceChannelMapper.queryChannels(deviceId, null, query, hasSubChannel, online);
+		List<DeviceChannel> all;
+		if (catalogUnderDevice != null && catalogUnderDevice) {
+			all = deviceChannelMapper.queryChannels(deviceId, deviceId, query, hasSubChannel, online);
+		}else {
+			all = deviceChannelMapper.queryChannels(deviceId, null, query, hasSubChannel, online);
+		}
 		return new PageInfo<>(all);
 	}
 
@@ -359,10 +357,6 @@
 		return deviceChannelMapper.queryChannelsByDeviceIdWithStartAndLimit(deviceId, null, query, hasSubChannel, online, start, limit);
 	}
 
-	@Override
-	public List<DeviceChannelTree> tree(String deviceId) {
-		return ForestNodeMerger.merge(deviceChannelMapper.tree(deviceId));
-	}
 
 	@Override
 	public List<DeviceChannel> queryChannelsByDeviceId(String deviceId) {
@@ -370,9 +364,9 @@
 	}
 
 	@Override
-	public PageInfo<DeviceChannel> querySubChannels(String deviceId, String parentChannelId, String query, Boolean hasSubChannel, String online, int page, int count) {
+	public PageInfo<DeviceChannel> querySubChannels(String deviceId, String parentChannelId, String query, Boolean hasSubChannel, Boolean online, int page, int count) {
 		PageHelper.startPage(page, count);
-		List<DeviceChannel> all = deviceChannelMapper.queryChannels(deviceId, parentChannelId, null, null, null);
+		List<DeviceChannel> all = deviceChannelMapper.queryChannels(deviceId, parentChannelId, query, hasSubChannel, online);
 		return new PageInfo<>(all);
 	}
 
@@ -424,10 +418,9 @@
 		TransactionStatus transactionStatus = dataSourceTransactionManager.getTransaction(transactionDefinition);
 		boolean result = false;
 		try {
-			if (platformChannelMapper.delChannelForDeviceId(deviceId) <0  // 鍒犻櫎涓庡浗鏍囧钩鍙扮殑鍏宠仈
-					|| deviceChannelMapper.cleanChannelsByDeviceId(deviceId) < 0 // 鍒犻櫎浠栫殑閫氶亾
-					|| deviceMapper.del(deviceId) < 0 // 绉婚櫎璁惧淇℃伅
-			) {
+			platformChannelMapper.delChannelForDeviceId(deviceId);
+			deviceChannelMapper.cleanChannelsByDeviceId(deviceId);
+			if ( deviceMapper.del(deviceId) < 0 ) {
 				//浜嬪姟鍥炴粴
 				dataSourceTransactionManager.rollback(transactionStatus);
 			}
@@ -454,8 +447,6 @@
 		device.setOnline(1);
 		logger.info("鏇存柊璁惧鍦ㄧ嚎: " + deviceId);
 		redisCatchStorage.updateDevice(device);
-		List<DeviceChannel> deviceChannelList = deviceChannelMapper.queryOnlineChannelsByDeviceId(deviceId);
-		eventPublisher.catalogEventPublish(null, deviceChannelList, CatalogEvent.ON);
 		return deviceMapper.update(device) > 0;
 	}
 
@@ -469,7 +460,9 @@
 	public synchronized boolean outline(String deviceId) {
 		logger.info("鏇存柊璁惧绂荤嚎: " + deviceId);
 		Device device = deviceMapper.getDeviceByDeviceId(deviceId);
-		if (device == null) return false;
+		if (device == null) {
+			return false;
+		}
 		device.setOnline(0);
 		redisCatchStorage.updateDevice(device);
 		return deviceMapper.update(device) > 0;
@@ -512,8 +505,8 @@
 	 * @param endTime
 	 */
 	@Override
-	public synchronized List<MobilePosition> queryMobilePositions(String deviceId, String startTime, String endTime) {
-		return deviceMobilePositionMapper.queryPositionByDeviceIdAndTime(deviceId, startTime, endTime);
+	public synchronized List<MobilePosition> queryMobilePositions(String deviceId, String channelId, String startTime, String endTime) {
+		return deviceMobilePositionMapper.queryPositionByDeviceIdAndTime(deviceId, channelId, startTime, endTime);
 	}
 
 	@Override
@@ -528,6 +521,12 @@
 	@Override
 	public boolean updateParentPlatform(ParentPlatform parentPlatform) {
 		int result = 0;
+		if (parentPlatform.getCatalogGroup() == 0) {
+			parentPlatform.setCatalogGroup(1);
+		}
+		if (parentPlatform.getAdministrativeDivision() == null) {
+			parentPlatform.setAdministrativeDivision(parentPlatform.getAdministrativeDivision());
+		}
 		ParentPlatformCatch parentPlatformCatch = redisCatchStorage.queryPlatformCatchInfo(parentPlatform.getServerGBId()); // .getDeviceGBId());
 		if (parentPlatform.getId() == null ) {
 			if (parentPlatform.getCatalogId() == null) {
@@ -547,6 +546,7 @@
 				parentPlatformCatch.setId(parentPlatform.getServerGBId());
 				redisCatchStorage.delPlatformCatchInfo(parentPlatById.getServerGBId());
 			}
+
 			result = platformMapper.updateParentPlatform(parentPlatform);
 		}
 		// 鏇存柊缂撳瓨
@@ -611,9 +611,9 @@
 	}
 
 	@Override
-	public List<ChannelReduce> queryChannelListInParentPlatform(String platformId) {
+	public List<DeviceChannelInPlatform> queryChannelListInParentPlatform(String platformId) {
 
-		return deviceChannelMapper.queryChannelListInAll(null, null, null, platformId, platformId);
+		return deviceChannelMapper.queryChannelByPlatformId(platformId);
 	}
 
 	@Override
@@ -716,6 +716,7 @@
 	 * 鍒犻櫎鎸囧畾璁惧鐨勬墍鏈夌Щ鍔ㄤ綅缃�
 	 * @param deviceId
 	 */
+	@Override
 	public int clearMobilePositionsByDeviceId(String deviceId) {
 		return deviceMobilePositionMapper.clearMobilePositionsByDeviceId(deviceId);
 	}
@@ -772,7 +773,7 @@
 		try {
 			if (streamProxyMapper.update(streamProxyItem) > 0) {
 				if (!StringUtils.isEmpty(streamProxyItem.getGbId())) {
-					if (gbStreamMapper.update(streamProxyItem) < 0) {
+					if (gbStreamMapper.updateByAppAndStream(streamProxyItem) == 0) {
 						//浜嬪姟鍥炴粴
 						dataSourceTransactionManager.rollback(transactionStatus);
 						return false;
@@ -861,7 +862,9 @@
 
 	@Override
 	public void updateMediaList(List<StreamPushItem> streamPushItems) {
-		if (streamPushItems == null || streamPushItems.size() == 0) return;
+		if (streamPushItems == null || streamPushItems.size() == 0) {
+			return;
+		}
 		logger.info("updateMediaList:  " + streamPushItems.size());
 		streamPushMapper.addAll(streamPushItems);
 		// TODO 寰呬紭鍖�
@@ -885,9 +888,9 @@
 			List<ParentPlatform> parentPlatforms = parentPlatformMapper.selectAllAhareAllLiveStream();
 			if (parentPlatforms.size() > 0) {
 				for (ParentPlatform parentPlatform : parentPlatforms) {
-					StreamProxyItem streamProxyItems = platformGbStreamMapper.selectOne(streamPushItem.getApp(), streamPushItem.getStream(),
+					StreamProxyItem streamProxyItem = platformGbStreamMapper.selectOne(streamPushItem.getApp(), streamPushItem.getStream(),
 							parentPlatform.getServerGBId());
-					if (streamProxyItems == null) {
+					if (streamProxyItem == null) {
 						streamPushItem.setCatalogId(parentPlatform.getCatalogId());
 						streamPushItem.setPlatformId(parentPlatform.getServerGBId());
 						platformGbStreamMapper.add(streamPushItem);
@@ -920,8 +923,8 @@
 	}
 
 	@Override
-	public List<StreamProxyItem> getStreamProxyListForEnableInMediaServer(String id, boolean enable, boolean status) {
-		return streamProxyMapper.selectForEnableInMediaServer(id, enable, status);
+	public List<StreamProxyItem> getStreamProxyListForEnableInMediaServer(String id, boolean enable) {
+		return streamProxyMapper.selectForEnableInMediaServer(id, enable);
 	}
 
 
@@ -1082,7 +1085,7 @@
 		deviceChannel.setParentId(catalog.getParentId());
 		deviceChannel.setRegisterWay(1);
 		// 琛屾斂鍖哄垝搴旇鏄疍omain鐨勫墠鍏綅
-		deviceChannel.setCivilCode(sipConfig.getDomain().substring(0, sipConfig.getDomain().length() - 2));
+		deviceChannel.setCivilCode(parentPlatByServerGBId.getAdministrativeDivision());
 		deviceChannel.setModel("live");
 		deviceChannel.setOwner("wvp-pro");
 		deviceChannel.setSecrecy("0");
@@ -1132,4 +1135,9 @@
 	public List<ChannelSourceInfo> getChannelSource(String platformId, String gbId) {
 		return platformMapper.getChannelSource(platformId, gbId);
 	}
+
+	@Override
+	public void updateChannelPotion(String deviceId, String channelId, double longitude, double latitude) {
+		deviceChannelMapper.updatePotion(deviceId, channelId, longitude, latitude);
+	}
 }

--
Gitblit v1.8.0