From 9ce22eba3c561d353e12c66c509fb91ca241409f Mon Sep 17 00:00:00 2001
From: 648540858 <456panlinlin>
Date: 星期二, 26 四月 2022 17:24:41 +0800
Subject: [PATCH] 行政区划作为级联数据的处理,修复设备树的显示

---
 web_src/src/components/devicePosition.vue                                      |   19 ++++++---
 src/main/java/com/genersoft/iot/vmp/storager/IVideoManagerStorage.java         |    2 
 src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStorageImpl.java |    9 +++-
 web_src/src/components/service/DeviceService.js                                |   15 ++++---
 src/main/java/com/genersoft/iot/vmp/gb28181/utils/XmlUtil.java                 |   27 +++++++++++--
 web_src/src/components/common/DeviceTree.vue                                   |    4 +-
 src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/device/DeviceQuery.java   |    6 ++-
 7 files changed, 57 insertions(+), 25 deletions(-)

diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/utils/XmlUtil.java b/src/main/java/com/genersoft/iot/vmp/gb28181/utils/XmlUtil.java
index 6ae09bd..1a87996 100644
--- a/src/main/java/com/genersoft/iot/vmp/gb28181/utils/XmlUtil.java
+++ b/src/main/java/com/genersoft/iot/vmp/gb28181/utils/XmlUtil.java
@@ -204,6 +204,7 @@
         deviceChannel.setCivilCode(XmlUtil.getText(itemDevice, "CivilCode"));
         deviceChannel.setBlock(XmlUtil.getText(itemDevice, "Block"));
         deviceChannel.setAddress(XmlUtil.getText(itemDevice, "Address"));
+        String businessGroupID = XmlUtil.getText(itemDevice, "BusinessGroupID");
         if (XmlUtil.getText(itemDevice, "Parental") == null
                 || XmlUtil.getText(itemDevice, "Parental") == "") {
             deviceChannel.setParental(0);
@@ -212,11 +213,27 @@
         }
         deviceChannel.setParentId(XmlUtil.getText(itemDevice, "ParentID"));
         String parentId = XmlUtil.getText(itemDevice, "ParentID");
-        if (parentId != null && parentId.contains("/")) {
-            String lastParentId = parentId.substring(parentId.lastIndexOf("/") + 1);
-            deviceChannel.setParentId(lastParentId);
+        if (parentId != null) {
+            if (parentId.contains("/")) {
+                String lastParentId = parentId.substring(parentId.lastIndexOf("/") + 1);
+                deviceChannel.setParentId(lastParentId);
+            }else {
+                deviceChannel.setParentId(parentId);
+            }
         }else {
-            deviceChannel.setParentId(parentId);
+            if (deviceChannel.getChannelId().length() <= 10) { // 姝ゆ椂涓鸿鏀垮尯鍒�, 涓婁笅绾ц鏀垮尯鍒掍娇鐢―eviceId鍏宠仈
+                deviceChannel.setParentId(deviceChannel.getChannelId().substring(0, deviceChannel.getChannelId().length() - 2));
+            }else if (deviceChannel.getChannelId().length() == 20) {
+                if (Integer.parseInt(deviceChannel.getChannelId().substring(10, 13)) == 216) { // 铏氭嫙缁勭粐
+                    deviceChannel.setParentId(businessGroupID);
+                }else if (deviceChannel.getCivilCode() != null) {
+                    // 璁惧锛� 鏃爌arentId鐨�20浣嶆槸浣跨敤CivilCode琛ㄧず涓婄骇鐨勮澶囷紝
+                    // 娉細215 涓氬姟鍒嗙粍鏄渶瑕佹湁parentId鐨�
+                    deviceChannel.setParentId(deviceChannel.getCivilCode());
+                }
+            }else {
+                deviceChannel.setParentId(deviceChannel.getDeviceId());
+            }
         }
 
         if (XmlUtil.getText(itemDevice, "SafetyWay") == null
@@ -277,4 +294,4 @@
         deviceChannel.setHasAudio(true); // 榛樿鍚湁闊抽锛屾挱鏀炬椂鍐嶆鏌ユ槸鍚︽湁闊抽鍙婃槸鍚AC
         return deviceChannel;
     }
-}
+}
\ No newline at end of file
diff --git a/src/main/java/com/genersoft/iot/vmp/storager/IVideoManagerStorage.java b/src/main/java/com/genersoft/iot/vmp/storager/IVideoManagerStorage.java
index d3a9ae9..a29b7ae 100644
--- a/src/main/java/com/genersoft/iot/vmp/storager/IVideoManagerStorage.java
+++ b/src/main/java/com/genersoft/iot/vmp/storager/IVideoManagerStorage.java
@@ -89,7 +89,7 @@
 	 * @param count 姣忛〉鏁伴噺
 	 * @return
 	 */
-	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);
 	
 	public List<DeviceChannel> queryChannelsByDeviceIdWithStartAndLimit(String deviceId, String query, Boolean hasSubChannel, Boolean online, int start, int limit);
 
diff --git a/src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStorageImpl.java b/src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStorageImpl.java
index 661a69b..070e312 100644
--- a/src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStorageImpl.java
+++ b/src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStorageImpl.java
@@ -340,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);
 	}
 
diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/device/DeviceQuery.java b/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/device/DeviceQuery.java
index ab153ad..708008e 100644
--- a/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/device/DeviceQuery.java
+++ b/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/device/DeviceQuery.java
@@ -128,12 +128,14 @@
 			@ApiImplicitParam(name="query", value = "鏌ヨ鍐呭" ,dataTypeClass = String.class),
 			@ApiImplicitParam(name="online", value = "鏄惁鍦ㄧ嚎"  ,dataTypeClass = Boolean.class),
 			@ApiImplicitParam(name="channelType", value = "璁惧/瀛愮洰褰�-> false/true" ,dataTypeClass = Boolean.class),
+			@ApiImplicitParam(name="catalogUnderDevice", value = "鏄惁鐩村睘涓庤澶囩殑鐩綍" ,dataTypeClass = Boolean.class),
 	})
 	public ResponseEntity<PageInfo> channels(@PathVariable String deviceId,
 											   int page, int count,
 											   @RequestParam(required = false) String query,
 											   @RequestParam(required = false) Boolean online,
-											   @RequestParam(required = false) Boolean channelType) {
+											   @RequestParam(required = false) Boolean channelType,
+											   @RequestParam(required = false) Boolean catalogUnderDevice) {
 //		if (logger.isDebugEnabled()) {
 //			logger.debug("鏌ヨ瑙嗛璁惧閫氶亾API璋冪敤");
 //		}
@@ -141,7 +143,7 @@
 			query = null;
 		}
 
-		PageInfo pageResult = storager.queryChannelsByDeviceId(deviceId, query, channelType, online, page, count);
+		PageInfo pageResult = storager.queryChannelsByDeviceId(deviceId, query, channelType, online, catalogUnderDevice, page, count);
 		return new ResponseEntity<>(pageResult,HttpStatus.OK);
 	}
 
diff --git a/web_src/src/components/common/DeviceTree.vue b/web_src/src/components/common/DeviceTree.vue
index fab895f..31e49bd 100644
--- a/web_src/src/components/common/DeviceTree.vue
+++ b/web_src/src/components/common/DeviceTree.vue
@@ -89,8 +89,8 @@
           })
         }
         if (node.level === 1) {
-          this.deviceService.getAllChannel(true, node.data.id, (catalogData) => {
-            this.deviceService.getAllChannel(false, node.data.id, (channelData) => {
+          this.deviceService.getAllChannel(true, true, node.data.id, (catalogData) => {
+            this.deviceService.getAllChannel(false, true, node.data.id, (channelData) => {
               let data = catalogData.concat(channelData)
               this.channelDataHandler(data, resolve)
             })
diff --git a/web_src/src/components/devicePosition.vue b/web_src/src/components/devicePosition.vue
index a807363..16675c9 100644
--- a/web_src/src/components/devicePosition.vue
+++ b/web_src/src/components/devicePosition.vue
@@ -14,13 +14,14 @@
       <div ref="infobox" v-if="channel != null " >
         <div v-if="channel != null" class="infobox-content">
           <el-descriptions class="margin-top" :title="channel.name" :column="1" :colon="true" size="mini" :labelStyle="labelStyle" >
-            <el-descriptions-item label="鐢熶骇鍘傚晢">{{channel.manufacture}}</el-descriptions-item>
+            <el-descriptions-item label="缂栧彿" >{{channel.channelId}}</el-descriptions-item>
             <el-descriptions-item label="鍨嬪彿">{{channel.model}}</el-descriptions-item>
-            <el-descriptions-item label="璁惧褰掑睘" >{{channel.owner}}</el-descriptions-item>
+            <el-descriptions-item label="缁忕含搴�" >{{channel.longitude}},{{channel.latitude}}</el-descriptions-item>
+            <el-descriptions-item label="鐢熶骇鍘傚晢">{{channel.manufacture}}</el-descriptions-item>
             <el-descriptions-item label="琛屾斂鍖哄煙" >{{channel.civilCode}}</el-descriptions-item>
+            <el-descriptions-item label="璁惧褰掑睘" >{{channel.owner}}</el-descriptions-item>
             <el-descriptions-item label="瀹夎鍦板潃" >{{channel.address == null?'鏈煡': channel.address}}</el-descriptions-item>
             <el-descriptions-item label="浜戝彴绫诲瀷" >{{channel.ptztypeText}}</el-descriptions-item>
-            <el-descriptions-item label="缁忕含搴�" >{{channel.longitude}},{{channel.latitude}}</el-descriptions-item>
             <el-descriptions-item label="鐘舵��">
               <el-tag size="small" v-if="channel.status === 1">鍦ㄧ嚎</el-tag>
               <el-tag size="small" type="info" v-if="channel.status === 0">绂荤嚎</el-tag>
@@ -75,7 +76,7 @@
       console.log(this.$route.query.deviceId)
       // this.$refs.deviceTree.openByDeivceId(this.$route.query.deivceId)
       setTimeout(()=>{ // 寤惰繜浠ョ瓑寰呭湴鍥惧姞杞藉畬鎴� TODO 鍚庣画淇敼涓洪�氳繃鏄疄闄呰繖锛涚姸鎬佸姞鍥炶皟瀹屾垚
-        this.deviceService.getAllChannel(false, this.$route.query.deviceId, this.channelsHandler)
+        this.deviceService.getAllChannel(false, false, this.$route.query.deviceId, this.channelsHandler)
       }, 1000)
 
     }
@@ -141,7 +142,13 @@
           zIndex: 3000, // 鑿滃崟鏍峰紡 z-index
         });
       } else {
-        this.deviceOrSubChannelMenu(event, data)
+        if (typeof data.channelId === "undefined") {
+          this.deviceOrSubChannelMenu(event, data)
+        }else {
+          // TODO 瀛愮洰褰曟殏鏃朵笉鏀寔鏌ヨ浠栦笅闈㈡墍鏈夎澶�, 鏀寔鏀寔鏌ヨ鐩村睘浜庤繖涓洰褰曠殑璁惧
+          this.deviceOrSubChannelMenu(event, data)
+        }
+
       }
 
     },
@@ -155,7 +162,7 @@
             disabled: false,
             onClick: () => {
               if (!data.channelId) {
-                this.deviceService.getAllChannel(false, data.deviceId, this.channelsHandler)
+                this.deviceService.getAllChannel(false, false, data.deviceId, this.channelsHandler)
               }
               if (data.channelId && data.subCount > 0) {
                 // 鐐瑰嚮瀛愮洰褰�
diff --git a/web_src/src/components/service/DeviceService.js b/web_src/src/components/service/DeviceService.js
index 6149579..dbe10d1 100644
--- a/web_src/src/components/service/DeviceService.js
+++ b/web_src/src/components/service/DeviceService.js
@@ -45,20 +45,20 @@
   }
 
 
-  getAllChannel(isCatalog, deviceId, callback, errorCallback) {
+  getAllChannel(isCatalog, catalogUnderDevice, deviceId, callback, errorCallback) {
     let currentPage = 1;
     let count = 100;
     let catalogList = []
-    this.getAllChannelIteration(isCatalog, deviceId, catalogList, currentPage, count, callback, errorCallback)
+    this.getAllChannelIteration(isCatalog, catalogUnderDevice, deviceId, catalogList, currentPage, count, callback, errorCallback)
   }
 
-  getAllChannelIteration(isCatalog, deviceId, catalogList, currentPage, count, callback, errorCallback) {
-    this.getChanel(isCatalog, deviceId, currentPage, count, (data) => {
+  getAllChannelIteration(isCatalog, catalogUnderDevice, deviceId, catalogList, currentPage, count, callback, errorCallback) {
+    this.getChanel(isCatalog, catalogUnderDevice, deviceId, currentPage, count, (data) => {
       if (data.list) {
         catalogList = catalogList.concat(data.list);
         if (catalogList.length < data.total) {
           currentPage ++
-          this.getAllChannelIteration(isCatalog, deviceId, catalogList, currentPage, count, callback, errorCallback)
+          this.getAllChannelIteration(isCatalog,catalogUnderDevice, deviceId, catalogList, currentPage, count, callback, errorCallback)
         }else {
           console.log(1)
           if (typeof (callback) == "function") callback(catalogList)
@@ -66,7 +66,7 @@
       }
     }, errorCallback)
   }
-  getChanel(isCatalog, deviceId, currentPage, count, callback, errorCallback) {
+  getChanel(isCatalog, catalogUnderDevice, deviceId, currentPage, count, callback, errorCallback) {
     this.$axios({
       method: 'get',
       url: `/api/device/query/devices/${deviceId}/channels`,
@@ -75,7 +75,8 @@
         count: count,
         query: "",
         online: "",
-        channelType: isCatalog
+        channelType: isCatalog,
+        catalogUnderDevice: catalogUnderDevice
       }
     }).then((res) =>{
       if (typeof (callback) == "function") callback(res.data)

--
Gitblit v1.8.0