From 66032f62b4a3b6a649fc02b392ae41278399b58b Mon Sep 17 00:00:00 2001
From: wangjuncheng <1>
Date: 星期二, 08 七月 2025 15:23:19 +0800
Subject: [PATCH] 添加打印加坝数据代码, 但调用被注释

---
 src/views/left/KGSimOption/RealTimeSimulation.vue |  205 +++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 166 insertions(+), 39 deletions(-)

diff --git a/src/views/left/KGSimOption/RealTimeSimulation.vue b/src/views/left/KGSimOption/RealTimeSimulation.vue
index 4dc917b..288a377 100644
--- a/src/views/left/KGSimOption/RealTimeSimulation.vue
+++ b/src/views/left/KGSimOption/RealTimeSimulation.vue
@@ -81,7 +81,8 @@
 import { useSimStore } from "@/store/simulation.js";
 import { EventBus } from "@/eventBus"; // 寮曞叆浜嬩欢鎬荤嚎
 import { getDeviceInfoSHG, getYLJData } from "@/api/hpApi";
-import { getSimStart, getSimDataById } from "@/api/trApi";
+import { getSimStart, getSimDataById, getSimresult } from "@/api/trApi";
+import { ControlSchemeType } from "@/assets/js/lib-pixelstreamingfrontend.esm";
 
 // 鑾峰彇 Store 瀹炰緥
 const simAPIStore = SimAPIStore();
@@ -209,6 +210,8 @@
     updateSelectedGauges();
     formData.geom = props.selectedArea;
     await simAPIStore.addSimCheme(formData);
+    // 鎵撳嵃鎷︽尅鍧濇墍闇�瑕佺殑鏁版嵁
+    // printDamEntities();
     resetForm();
     EventBus.emit("close-selectArea");
   } catch (err) {}
@@ -219,14 +222,15 @@
 
 // 瀹炴椂妯℃嫙瀹氭椂鍣�
 let pollingInterval = null;
+// 鐢ㄤ簬璁板綍涓婃鏁版嵁鏉℃暟
+let lastDataLength = 0;
+
+let pollingTimer = null; // 鐢ㄤ簬淇濆瓨瀹氭椂鍣ㄥ紩鐢�
 
 async function startPlay() {
-  // 寮�濮嬫ā鎷熷墠闇�瑕佸厛淇濆瓨鏂规
   updateSelectedGauges();
-
   formData.geom = props.selectedArea;
 
-  // 淇濆瓨鏂规
   const resApi = await simAPIStore.addSimCheme(formData);
   const schemeId = resApi.data?.data?.id;
 
@@ -237,7 +241,6 @@
 
   EventBus.emit("close-selectArea");
 
-  // 鏄剧ず鍔犺浇涓彁绀�
   const loadingMessage = ElMessage({
     type: "info",
     message: "姝e湪鍚姩妯℃嫙...",
@@ -246,58 +249,130 @@
   });
 
   try {
-    // 璋冪敤姹傝В鍣ㄥ苟鍒濆鍖栨ā鎷�
-    const resStart = await getSimStart(schemeId);
+    await getSimStart(schemeId);
 
-    // 璇锋眰瀹屾垚鍚庡叧闂姞杞芥彁绀�
-    loadingMessage.close();
-
-    if (resStart.code === 200) {
-      const res = await getSimDataById(schemeId);
-      simStore.setSelectedScheme(res.data[0]);
-
-      simStore.layerDate = resStart.data;
-      initeWaterPrimitiveView();
-
+    // 瀹氫箟涓�涓嚱鏁扮敤浜庤疆璇㈣幏鍙栨暟鎹�
+    const pollForResult = async () => {
       try {
-        startSimulate(); // 杩欓噷鍙兘浼氭姤閿�
-      } catch (error) {
-        console.error("璋冪敤 startSimulate 鍑洪敊锛�", error);
-      }
+        const res = await getSimresult(schemeId);
+        console.log(res.data, "瀹炴椂妯℃嫙 - 杞缁撴灉");
 
-      // 寮�濮嬭疆璇换鍔★細姣� 5 鍒嗛挓璋冪敤涓�娆� getSimStart 骞舵洿鏂版柟妗堟暟鎹�
-      startPolling(schemeId);
-    } else {
-      ElMessage.error(resStart.message || "璋冪敤姹傝В鍣ㄥけ璐�");
-    }
+        if (res.code === 200 && res.data.length > 0) {
+          // 鎴愬姛鎷垮埌鏁版嵁
+          loadingMessage.close();
+          handleNewData(res.data, schemeId);
+          startPolling(schemeId);
+
+          // 鉁� 娓呴櫎瀹氭椂鍣�
+          if (pollingTimer) {
+            clearTimeout(pollingTimer);
+            pollingTimer = null;
+          }
+        } else {
+          // 鏁版嵁鏃犳晥锛岀户缁疆璇�
+          pollingTimer = setTimeout(pollForResult, 10 * 1000);
+        }
+      } catch (error) {
+        console.error("璇锋眰妯℃嫙缁撴灉澶辫触", error);
+        pollingTimer = setTimeout(pollForResult, 10 * 1000); // 璇锋眰鍑洪敊涔熺户缁疆璇�
+      }
+    };
+
+    // 棣栨寤惰繜 2 鍒嗛挓寮�濮嬭疆璇�
+    pollingTimer = setTimeout(async () => {
+      await pollForResult(); // 寮�濮嬬涓�娆¤疆璇�
+    }, 3 * 60 * 1000); // 3鍒嗛挓鍚庣涓�娆¤姹�
   } catch (error) {
     loadingMessage.close();
     ElMessage.error("璇锋眰澶辫触锛�" + (error.message || "鏈煡閿欒"));
     console.error("璋冪敤 getSimStart 鍑洪敊锛�", error);
+
+    if (pollingTimer) {
+      clearTimeout(pollingTimer);
+      pollingTimer = null;
+    }
   }
 }
 
-// 鍚姩杞鍑芥暟
+// 瀹氭椂浜斿垎閽熻姹�
 function startPolling(schemeId) {
-  stopPolling(); // 閬垮厤閲嶅鍚姩
+  stopPolling(); // 纭繚涓嶄細閲嶅鍚姩
 
   pollingInterval = setInterval(async () => {
     try {
-      const resStart = await getSimStart(schemeId);
+      const res = await getSimresult(schemeId);
 
-      if (resStart.code === 200) {
-        const res = await getSimDataById(schemeId);
-        simStore.setSelectedScheme(res.data[0]); // 鏇存柊鏂规鏁版嵁
-        simStore.layerDate = resStart.data; // 鏇存柊 layer 鏁版嵁
+      if (res.data && res.data.length > 0) {
+        if (res.data.length === lastDataLength) {
+          console.log("涓昏疆璇細鏃犳柊鏁版嵁锛屽垏鎹负 10 绉掗珮棰戣疆璇�");
 
-        console.log("杞鑾峰彇鏈�鏂版暟鎹垚鍔�");
-      } else {
-        console.warn("杞璇锋眰澶辫触锛�", resStart.message);
+          clearInterval(pollingInterval);
+          pollingInterval = null;
+
+          startFastPolling(schemeId); // 鍚姩楂橀杞
+        } else {
+          handleNewData(res.data, schemeId);
+        }
       }
     } catch (error) {
-      console.error("杞璇锋眰寮傚父锛�", error);
+      console.error("杞鑾峰彇妯℃嫙缁撴灉澶辫触", error);
     }
-  }, 5 * 60 * 1000); // 姣� 5 鍒嗛挓鎵ц涓�娆�
+  }, 5.6 * 60 * 1000); // 姣� 5.5 鍒嗛挓鎵ц涓�娆�
+}
+
+let fastPollingInterval = null;
+// 濡傛灉浜斿垎閽熸病鎷垮埌鏈�鏂扮殑鏁版嵁锛屽垯寮�鍚崄绉掗挓璋冪敤涓�娆★紝鎷垮埌鏈�鏂扮殑鏁版嵁灏卞仠姝�
+function startFastPolling(schemeId) {
+  fastPollingInterval = setInterval(async () => {
+    try {
+      const res = await getSimresult(schemeId);
+
+      if (res.data && res.data.length > 0) {
+        if (res.data.length !== lastDataLength) {
+          console.log("楂橀杞锛氭娴嬪埌鏂版暟鎹紝鎭㈠涓昏疆璇�");
+
+          clearInterval(fastPollingInterval);
+          fastPollingInterval = null;
+
+          handleNewData(res.data, schemeId);
+
+          startPolling(schemeId); // 閲嶆柊鍚姩涓昏疆璇�
+        }
+      }
+    } catch (error) {
+      console.error("楂橀杞鑾峰彇妯℃嫙缁撴灉澶辫触", error);
+    }
+  }, 10 * 1000); // 姣� 10 绉掓墽琛屼竴娆�
+}
+
+// 鎷垮彇鏈�鏂扮殑layer.json瀛樺偍鍒皃inia涓�
+async function handleNewData(dataArray, schemeId) {
+  // 鎷挎湇鍔″悕绉�
+  const res = await getSimDataById(schemeId);
+  simStore.setSelectedScheme(res.data[0]); // 鏇存柊鏂规鏁版嵁
+
+  const latestItem = dataArray[dataArray.length - 1];
+  const currentLength = dataArray.length;
+
+  if (currentLength <= lastDataLength) {
+    console.log("鏈疆鏃犳柊鏁版嵁锛堥暱搴︽湭鍙樺寲锛�");
+    return;
+  }
+
+  // 鏇存柊鏍囪瘑
+  lastDataLength = currentLength;
+
+  // 鎵ц鏇存柊閫昏緫
+  console.log("妫�娴嬪埌鏂版暟鎹紝鏇存柊涓�...");
+  console.log(latestItem, "last");
+  simStore.layerDate = latestItem;
+  initeWaterPrimitiveView();
+
+  try {
+    startSimulate();
+  } catch (error) {
+    console.error("璋冪敤 startSimulate 鍑洪敊锛�", error);
+  }
 }
 
 // 鍋滄杞鍑芥暟
@@ -305,8 +380,14 @@
   if (pollingInterval) {
     clearInterval(pollingInterval);
     pollingInterval = null;
-    console.log("杞宸插仠姝�");
   }
+
+  if (fastPollingInterval) {
+    clearInterval(fastPollingInterval);
+    fastPollingInterval = null;
+  }
+
+  console.log("杞宸插仠姝�");
 }
 
 EventBus.on("close-time", () => {
@@ -325,6 +406,52 @@
   EventBus.off("close-time");
   stopPolling();
 });
+// ========================================鎷︽尅鍧�===============================================================
+// 鑾峰彇鎷︽尅鍧濇暟鎹�
+function printDamEntities() {
+  const entities = viewer.entities.values;
+  const damDataList = [];
+
+  for (let i = 0; i < entities.length; i++) {
+    const entity = entities[i];
+
+    if (entity.name && (entity.name === '鏍忔。鍧�1' || entity.name === '鏍忔。鍧�2')) {
+      damDataList.push({
+        name: entity.name,
+        position: entity.position?._value,
+        heading: entity.heading?._value ?? entity.heading,
+        pitch: entity.pitch?._value ?? entity.pitch,
+        roll: entity.roll?._value ?? entity.roll,
+        modelScale: entity.model?.scale?._value ?? entity.model?.scale
+      });
+    }
+  }
+  if (damDataList.length > 0) {
+    console.log("銆愭爮妗e潩瀹炰綋鏁版嵁鍒楄〃銆戯細", damDataList);
+    deleteDamEntitiesAfterDelay();
+  } else {
+    console.log("鏈壘鍒颁换浣曞悕涓� '鏍忔。鍧�1' 鎴� '鏍忔。鍧�2' 鐨勫疄浣�");
+  }
+}
+// 淇濆瓨鏂规鍚庡畾鏃舵竻闄ゆ柊寤虹殑鎷︽尅鍧濇暟鎹�
+function deleteDamEntitiesAfterDelay() {
+  setTimeout(() => {
+    const entities = Array.from(viewer.entities.values);
+    const damsToDelete = entities.filter(
+      entity => entity.name === '鏍忔。鍧�1' || entity.name === '鏍忔。鍧�2'
+    );
+
+    damsToDelete.forEach(entity => {
+      viewer.entities.remove(entity);
+    });
+
+    if (damsToDelete.length > 0) {
+      console.log(`銆愬凡鍒犻櫎銆戝叡 ${damsToDelete.length} 涓爮妗e潩瀹炰綋`);
+    } else {
+      console.log("鏈壘鍒颁换浣曞彲鍒犻櫎鐨勬爮妗e潩瀹炰綋");
+    }
+  }, 5000);
+}
 </script>
 
 <style scoped>

--
Gitblit v1.9.3