From 8fc27dba6719041402e3e3c099e2f3e01d9d52c7 Mon Sep 17 00:00:00 2001
From: feiyu02 <risaku@163.com>
Date: 星期三, 16 七月 2025 17:30:56 +0800
Subject: [PATCH] 2025.7.16 1. 修改动态溯源异常判断逻辑

---
 src/main/kotlin/com/flightfeather/uav/biz/dataanalysis/BaseExceptionContinuous.kt |   99 +++++++++++++++++++++++++++++++++----------------
 1 files changed, 66 insertions(+), 33 deletions(-)

diff --git a/src/main/kotlin/com/flightfeather/uav/biz/dataanalysis/BaseExceptionContinuous.kt b/src/main/kotlin/com/flightfeather/uav/biz/dataanalysis/BaseExceptionContinuous.kt
index 0336e02..733641e 100644
--- a/src/main/kotlin/com/flightfeather/uav/biz/dataanalysis/BaseExceptionContinuous.kt
+++ b/src/main/kotlin/com/flightfeather/uav/biz/dataanalysis/BaseExceptionContinuous.kt
@@ -5,13 +5,14 @@
 import com.flightfeather.uav.domain.entity.BaseRealTimeData
 import com.flightfeather.uav.lightshare.eunm.ExceptionStatusType
 import com.flightfeather.uav.socket.eunm.FactorType
+import org.springframework.beans.BeanUtils
 import java.time.Duration
 
 /**
  * 杩炵画绫诲瀷鐨勫紓甯稿垎鏋愬熀绫�,閫傜敤浜庡綋鍓嶆暟鎹笌鐩搁偦鏁版嵁涔嬮棿鏈夊叧鑱斿叧绯荤殑鎯呭喌
  */
 abstract class BaseExceptionContinuous<T : ExceptionTag, V : BaseAnalysisConfig, Y : BaseExceptionResult>(
-    config: V, private val tagClz: Class<T>
+    config: V, private val tagClz: Class<T>,
 ) : BaseExceptionAnalysis<V, Y>(config) {
 
     companion object {
@@ -27,11 +28,18 @@
     // 鏈熬鏁版嵁瀵硅薄
     protected var lastData: BaseRealTimeData? = null
 
-    // 鏈�鏂扮殑涓�缁勫紓甯革紝鏍规嵁璁惧畾鍙傛暟锛屽皢鐩稿叧鑱旂殑鍥犲瓙浜х敓鐨勫紓甯稿悎骞�
-    protected val latestExceptionResult = mutableListOf<BaseExceptionResult>()
+    // 鏈�鏂扮殑涓�缁勫紓甯革紝璁板綍鍗曞洜瀛愬紓甯�
+    protected val latestExceptions = mutableListOf<Pair<FactorFilter.SelectedFactor, T>>()
 
-    // 鏈�鏂扮殑涓�缁勫悎骞跺紓甯�
-    protected val latestCombinedResult = mutableListOf<List<BaseExceptionResult>>()
+    /**
+     * 鏈�鏂扮殑涓�缁勫悎骞跺紓甯革紝鏍规嵁閰嶇疆鍙傛暟浠嶽latestExceptions]鍗曞洜瀛愬紓甯镐腑锛屽悎骞跺紓甯�
+     */
+    protected val latestCombinedExc = mutableListOf<List<Pair<FactorFilter.SelectedFactor, T>>>()
+
+    /**
+     * 寮傚父缁撴灉
+     */
+    protected val result = mutableListOf<Y>()
 
     /**
      * 绔嬪嵆鍒ゆ柇锛氬綋鍑虹幇寮傚父鏃讹紝缂撳瓨寮傚父鏁版嵁鐨勫悓鏃讹紝绔嬪嵆瀵瑰凡鏈夊紓甯歌繘琛屽垽鏂槸鍚︽弧瓒冲紓甯哥粨鏋滆姹�
@@ -148,6 +156,7 @@
         lastData = data
 
         mergeExceptionResult()
+        clearExceptions(data)
     }
 
     override fun onDone() {
@@ -160,7 +169,7 @@
      */
     fun recordException(factor: FactorFilter.SelectedFactor, tag: T, data: BaseRealTimeData) {
         checkResult(factor, ExceptionStatusType.Ended)
-        tag.refreshWithNextException(data)
+//        tag.refreshWithNextException(data)
     }
 
     /**
@@ -168,7 +177,7 @@
      */
     open fun checkResult(
         factor: FactorFilter.SelectedFactor? = null,
-        exceptionStatus: ExceptionStatusType = ExceptionStatusType.InProgress
+        exceptionStatus: ExceptionStatusType = ExceptionStatusType.InProgress,
     ) {
         val tag = tagMap[factor?.main]
         if (factor != null && tag != null) {
@@ -191,23 +200,24 @@
     open fun onNewException(tag: T, factor: FactorFilter.SelectedFactor, exceptionStatus: ExceptionStatusType) {
         if (tag.startData == null) return
 //        val ex = newResult(tag.startData!!, tag.endData, factor, tag.exceptionData)
-        val ex = newResult(tag, factor)
-            .apply { status = exceptionStatus.value }
-        // 寮傚父宸插垱寤烘椂锛屾洿鏂板紓甯镐俊鎭�
-        if (tag.exceptionCreated) {
-            // 灏嗘渶鏂扮殑寮傚父鐨刧uid璧嬪�肩粰ex
-            val lastEx = tag.exceptionResult.last()
-            ex.guid = lastEx.guid
-            tag.exceptionResult.removeLast()
-            tag.exceptionResult.add(ex)
-        }
-        // 寮傚父鏈垱寤烘椂锛屾柊寤哄紓甯镐俊鎭�
-        else {
-            tag.exceptionResult.add(ex)
-            tag.exceptionCreated = true
-        }
-
-        latestExceptionResult.add(ex)
+//        val ex = newResult(tag, factor)
+//            .apply { status = exceptionStatus.value }
+//        // 寮傚父宸插垱寤烘椂锛屾洿鏂板紓甯镐俊鎭�
+//        if (tag.exceptionCreated) {
+//            // 灏嗘渶鏂扮殑寮傚父鐨刧uid璧嬪�肩粰ex
+//            val lastEx = tag.exceptionResult.last()
+//            ex.guid = lastEx.guid
+//            tag.exceptionResult.removeLast()
+//            tag.exceptionResult.add(ex)
+//        }
+//        // 寮傚父鏈垱寤烘椂锛屾柊寤哄紓甯镐俊鎭�
+//        else {
+//            tag.exceptionResult.add(ex)
+//            tag.exceptionCreated = true
+//        }
+//        val tagClone = tagClz.newInstance()
+//        BeanUtils.copyProperties(tag, tagClone)
+        latestExceptions.add(factor to tag)
     }
 
     /**
@@ -215,13 +225,13 @@
      */
     open fun mergeExceptionResult() {
         // 閬嶅巻鎵�鏈夌殑鍥犲瓙缁勫悎
-        config.combination?.forEach {c ->
-            val res = mutableListOf<BaseExceptionResult>()
+        config.factorFilter.combination.forEach { c ->
+            val res = mutableListOf<Pair<FactorFilter.SelectedFactor, T>>()
             var exist = true
             // 鏌ョ湅缁勫悎鍐呯殑鎵�鏈夊洜瀛愭槸鍚﹂兘鍚屾椂鍑虹幇寮傚父
-            c.forEach { f->
-                val r = latestExceptionResult.find { e->
-                    e.factorId == f.value
+            c.forEach { f ->
+                val r = latestExceptions.find { e ->
+                    e.first.main == f
                 }
                 if (r != null) {
                     res.add(r)
@@ -232,18 +242,41 @@
             // 濡傛灉缁勫悎鍐呯殑鎵�鏈夊洜瀛愰兘瀛樺湪寮傚父锛屽垯瀛樺偍涓哄悎骞跺紓甯�
             if (exist) {
                 // 灏嗗悎骞跺紓甯镐粠鍗曚釜寮傚父闆嗗悎涓幓闄�
-                res.forEach { r->
-                    latestExceptionResult.removeIf { e-> e.factorId == r.factorId }
+                res.forEach { r ->
+                    latestExceptions.removeIf { e -> e.first.main == r.first.main }
                 }
                 // 灏嗗悎骞跺紓甯稿瓨鍌�
-                latestCombinedResult.add(res)
+                latestCombinedExc.add(res)
             }
         }
+        // 瀛樺偍寮傚父缁撴灉
+        latestExceptions.forEach {
+            result.add(newResult(listOf(it)))
+        }
+        latestCombinedExc.forEach {
+            result.add(newResult(it))
+        }
+    }
+
+    private fun clearExceptions(data: BaseRealTimeData) {
+        latestExceptions.forEach {
+            it.second.refreshWithNextException(data)
+        }
+        latestExceptions.clear()
+        latestCombinedExc.forEach {
+            it.forEach { e ->
+                e.second.refreshWithNextException(data)
+            }
+        }
+        latestCombinedExc.clear()
+        result.clear()
     }
 
     /**
      * 鐢熸垚涓�鏉″紓甯稿垎鏋愮粨鏋�
      */
-    abstract fun newResult(tag:T, factor: FactorFilter.SelectedFactor): Y
+    abstract fun newResult(tag: T, factor: FactorFilter.SelectedFactor): Y
+
+    abstract fun newResult(exceptions: List<Pair<FactorFilter.SelectedFactor, ExceptionTag>>): Y
 
 }
\ No newline at end of file

--
Gitblit v1.9.3