From f34eb9c9e6b61b596d0085e9a2baec48628b23e1 Mon Sep 17 00:00:00 2001
From: Lawrence <1934378145@qq.com>
Date: 星期四, 14 一月 2021 23:53:57 +0800
Subject: [PATCH] 通道查询排序输出,避免列表杂乱无章

---
 src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStoragerImpl.java |   57 +++++++++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 49 insertions(+), 8 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/VideoManagerStoragerImpl.java
index ee7ccec..93d8c83 100644
--- a/src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStoragerImpl.java
+++ b/src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStoragerImpl.java
@@ -9,6 +9,7 @@
 import com.genersoft.iot.vmp.storager.dao.DeviceChannelMapper;
 import com.genersoft.iot.vmp.storager.dao.DeviceMapper;
 import com.genersoft.iot.vmp.storager.dao.ParentPlatformMapper;
+import com.genersoft.iot.vmp.storager.dao.PatformChannelMapper;
 import com.genersoft.iot.vmp.vmanager.platform.bean.ChannelReduce;
 import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageInfo;
@@ -38,6 +39,9 @@
 
 	@Autowired
     private IRedisCatchStorage redisCatchStorage;
+
+	@Autowired
+    private PatformChannelMapper patformChannelMapper;
 
 
 
@@ -119,7 +123,7 @@
 	@Override
 	public PageInfo queryChannelsByDeviceId(String deviceId, String query, Boolean hasSubChannel, Boolean online, int page, int count) {
 		// 鑾峰彇鍒版墍鏈夋鍦ㄦ挱鏀剧殑娴�
-		PageHelper.startPage(page+1, count);
+		PageHelper.startPage(page, count);
 		List<DeviceChannel> all = deviceChannelMapper.queryChannelsByDeviceId(deviceId, null, query, hasSubChannel, online);
 		return new PageInfo<>(all);
 	}
@@ -131,7 +135,7 @@
 
 	@Override
 	public PageInfo<DeviceChannel> querySubChannels(String deviceId, String parentChannelId, String query, Boolean hasSubChannel, String online, int page, int count) {
-		PageHelper.startPage(page+1, count);
+		PageHelper.startPage(page, count);
 		List<DeviceChannel> all = deviceChannelMapper.queryChannelsByDeviceId(deviceId, parentChannelId, null, null, null);
 		return new PageInfo<>(all);
 	}
@@ -151,7 +155,7 @@
 	 */
 	@Override
 	public PageInfo<Device> queryVideoDeviceList(int page, int count) {
-		PageHelper.startPage(page+1, count);
+		PageHelper.startPage(page, count);
 		List<Device> all = deviceMapper.getDevices();
 		return new PageInfo<>(all);
 	}
@@ -245,9 +249,12 @@
 		return result > 0;
 	}
 
+	@Transactional
 	@Override
 	public boolean deleteParentPlatform(ParentPlatform parentPlatform) {
 		int result = platformMapper.delParentPlatform(parentPlatform);
+		// 鍒犻櫎鍏宠仈鐨勯�氶亾
+		patformChannelMapper.cleanChannelForGB(parentPlatform.getDeviceGBId());
 		return result > 0;
 	}
 
@@ -275,17 +282,51 @@
 
 
 	@Override
-	public PageInfo<ChannelReduce> queryChannelListInAll(int page, int count, String query, Boolean online,
-														 Boolean channelType, String parentChannelId) {
+	public PageInfo<ChannelReduce> queryAllChannelList(int page, int count, String query, Boolean online,
+														 Boolean channelType, String platformId, Boolean inPlatform) {
 		PageHelper.startPage(page, count);
-		List<ChannelReduce> all = deviceChannelMapper.queryChannelListInAll(query, online, channelType, parentChannelId);
+		List<ChannelReduce> all = deviceChannelMapper.queryChannelListInAll(query, online, channelType, platformId, inPlatform);
 		return new PageInfo<>(all);
 	}
 
+	@Override
+	public List<ChannelReduce> queryChannelListInParentPlatform(String platformId) {
 
-	@Transactional
+		return deviceChannelMapper.queryChannelListInAll(null, null, null, platformId, true);
+	}
+
 	@Override
 	public int updateChannelForGB(String platformId, List<ChannelReduce> channelReduces) {
-		return 0;
+
+		Map<String, ChannelReduce> deviceAndChannels = new HashMap<>();
+		for (ChannelReduce channelReduce : channelReduces) {
+			deviceAndChannels.put(channelReduce.getDeviceId() + "_" + channelReduce.getChannelId(), channelReduce);
+		}
+		List<String> deviceAndChannelList = new ArrayList<>(deviceAndChannels.keySet());
+		// 鏌ヨ褰撳墠宸茬粡瀛樺湪鐨�
+		List<String> relatedPlatformchannels = patformChannelMapper.findChannelRelatedPlatform(platformId, deviceAndChannelList);
+		if (relatedPlatformchannels != null) {
+			deviceAndChannelList.removeAll(relatedPlatformchannels);
+		}
+		for (String relatedPlatformchannel : relatedPlatformchannels) {
+			deviceAndChannels.remove(relatedPlatformchannel);
+		}
+		List<ChannelReduce> channelReducesToAdd = new ArrayList<>(deviceAndChannels.values());
+		// 瀵瑰墿涓嬬殑鏁版嵁杩涜瀛樺偍
+		int result = 0;
+		if (channelReducesToAdd.size() > 0) {
+			result = patformChannelMapper.addChannels(platformId, channelReducesToAdd);
+		}
+
+		return result;
+	}
+
+
+	@Override
+	public int delChannelForGB(String platformId, List<ChannelReduce> channelReduces) {
+
+		int result = patformChannelMapper.delChannelForGB(platformId, channelReduces);
+
+		return result;
 	}
 }

--
Gitblit v1.8.0