From 85909f9a78a328de2bc3efc0d1d184320cb8970b Mon Sep 17 00:00:00 2001
From: feiyu02 <risaku@163.com>
Date: 星期五, 11 七月 2025 17:22:54 +0800
Subject: [PATCH] 2025.7.11 1. 修改动态溯源异常判断逻辑

---
 src/main/kotlin/com/flightfeather/uav/biz/dataanalysis/BaseExceptionContinuous.kt |   97 +++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 79 insertions(+), 18 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 2bfe2be..0336e02 100644
--- a/src/main/kotlin/com/flightfeather/uav/biz/dataanalysis/BaseExceptionContinuous.kt
+++ b/src/main/kotlin/com/flightfeather/uav/biz/dataanalysis/BaseExceptionContinuous.kt
@@ -27,12 +27,11 @@
     // 鏈熬鏁版嵁瀵硅薄
     protected var lastData: BaseRealTimeData? = null
 
-    /**
-     * 鍚庣疆鍒ゆ柇锛氬綋鐩搁偦鏁版嵁鏃堕棿涓嶈繛缁椂锛屾垨鑰呮弧瓒宠嚜瀹氫箟鏉′欢鏃讹紝瀵逛箣鍓嶅凡鏈夌殑寮傚父杩涜璁板綍
-     */
-    open fun afterExcCheck(isContinue: Boolean, tag: T, hasException: Boolean?): Boolean {
-        return !isContinue || needCut(tag, hasException)
-    }
+    // 鏈�鏂扮殑涓�缁勫紓甯革紝鏍规嵁璁惧畾鍙傛暟锛屽皢鐩稿叧鑱旂殑鍥犲瓙浜х敓鐨勫紓甯稿悎骞�
+    protected val latestExceptionResult = mutableListOf<BaseExceptionResult>()
+
+    // 鏈�鏂扮殑涓�缁勫悎骞跺紓甯�
+    protected val latestCombinedResult = mutableListOf<List<BaseExceptionResult>>()
 
     /**
      * 绔嬪嵆鍒ゆ柇锛氬綋鍑虹幇寮傚父鏃讹紝缂撳瓨寮傚父鏁版嵁鐨勫悓鏃讹紝绔嬪嵆瀵瑰凡鏈夊紓甯歌繘琛屽垽鏂槸鍚︽弧瓒冲紓甯哥粨鏋滆姹�
@@ -53,6 +52,16 @@
     }
 
     /**
+     * 鍒ゆ柇鏁版嵁閲忕骇鍦ㄥ紓甯稿垽鏂殑鑼冨洿鍐�
+     * 榛樿鎵�鏈夐噺绾ч兘鍦ㄥ紓甯稿垽鏂殑鑼冨洿鍐�
+     */
+    open fun judgeDataScale(p: BaseRealTimeData?, n: BaseRealTimeData): MutableMap<FactorType, Boolean> {
+        val res = mutableMapOf<FactorType, Boolean>()
+        config.factorFilter.mainList().forEach { f -> res[f] = true }
+        return res
+    }
+
+    /**
      * 鍒ゆ柇鍓嶅悗鏁版嵁鏄惁婊¤冻寮傚父鏉′欢
      */
     abstract fun judgeException(p: BaseRealTimeData?, n: BaseRealTimeData): MutableMap<FactorType, Boolean>
@@ -64,10 +73,23 @@
     abstract fun judgeExceptionCount(tag: T, factorType: FactorType?): Boolean
 
     /**
+     * 鍒ゆ柇鐩戞祴鍥犲瓙鏄惁鍑虹幇寮傚父
+     */
+    open fun judge(p: BaseRealTimeData?, n: BaseRealTimeData): MutableMap<FactorType, Boolean> {
+        val jds = judgeDataScale(p, n)
+        val jex = judgeException(p, n)
+        val res = mutableMapOf<FactorType, Boolean>()
+        jds.forEach { (t, u) ->
+            res[t] = u && jex[t] ?: false
+        }
+        return res
+    }
+
+    /**
      * 寮傚父鏁版嵁鐨勬埅鍙栧垽鏂�
      * @return
      */
-    open fun needCut(tag: T, hasException: Boolean?): Boolean {
+    open fun needCut(tag: T, hasException: Boolean?, data: BaseRealTimeData): Boolean {
         // 榛樿鍒ゆ柇鏉′欢涓� 褰撳紓甯镐笉鍐嶉噸澶嶅嚭鐜版椂锛屽舰鎴愬紓甯哥粨鏋�
         return tag.exceptionExisted && hasException == false
     }
@@ -83,7 +105,7 @@
 
     override fun onNextData(data: BaseRealTimeData) {
         val isContinue = isContinuous(lastData, data)
-        val hasException = judgeException(lastData, data)
+        val hasException = judge(lastData, data)
         config.factorFilter.selectedList.forEach { s ->
             val f = s.main
             tagMap[f]?.let {
@@ -98,12 +120,17 @@
 
                 // 瀵逛簬寮傚父鐨勭敓鎴愬垎鍒墽琛屽悗缃垽鏂�佸拰绔嬪嵆鍒ゆ柇
                 // 1. 鍚庣疆鍒ゆ柇锛氬綋鐩搁偦鏁版嵁鏃堕棿涓嶈繛缁椂锛屾垨鑰呮弧瓒宠嚜瀹氫箟鏉′欢鏃讹紝瀵逛箣鍓嶅凡鏈夌殑寮傚父杩涜璁板綍锛屽舰鎴愬紓甯哥粨鏋�
-                if (afterExcCheck(isContinue, it, hasException[f])) {
-                    // 鏁版嵁涓嶈繛缁椂鎴栬�呮弧瓒充富鍔ㄦ埅鏂潯浠舵椂锛岃褰曞紓甯告儏鍐�
-                    recordException(s, it, data)
-                }
+//                if (afterExcCheck(isContinue, it, hasException[f])) {
+//                    // 鏁版嵁涓嶈繛缁椂鎴栬�呮弧瓒充富鍔ㄦ埅鏂潯浠舵椂锛岃褰曞紓甯告儏鍐�
+//                    recordException(s, it, data)
+//                }
                 // 2. 绔嬪嵆鍒ゆ柇锛氬綋鍑虹幇寮傚父鏃讹紝缂撳瓨寮傚父鏁版嵁鐨勫悓鏃讹紝绔嬪嵆瀵瑰凡鏈夊紓甯歌繘琛屽垽鏂槸鍚︽弧瓒冲紓甯哥粨鏋滆姹�
-                else if (hasException[f] == true) {
+                if (hasException[f] == true) {
+
+//                    afterExcCheck(isContinue, it, hasException[f])
+                    if (needCut(it, hasException[f], data)) {
+                        it.refreshWithNextException(data)
+                    }
                     // 鏈夊紓甯稿嚭鐜版椂锛岃褰曞紓甯告暟鎹�
                     it.addExceptionData(data)
                     // 褰撶珛鍗冲垽鏂�氳繃鏃讹紝褰㈡垚寮傚父缁撴灉
@@ -113,12 +140,14 @@
                 }
                 // 3. 鏁版嵁姝e父锛屾棤浠讳綍寮傚父鏃禿
                 // TODO("2025.6.3锛氬叾浠栧瓙绫荤殑姝ゅ鍒锋柊閫昏緫寰呭畬鎴愨��)
-                else {
-                    it.refreshWithNoException(data)
-                }
+//                else {
+//                    it.refreshWithNextException(data)
+//                }
             }
         }
         lastData = data
+
+        mergeExceptionResult()
     }
 
     override fun onDone() {
@@ -149,7 +178,7 @@
         } else {
             config.factorFilter.selectedList.forEach { f ->
                 val tag1 = tagMap[f.main] ?: return@forEach
-                if (tag1.exceptionExisted && judgeExceptionCount(tag1, null)) {
+                if (tag1.exceptionExisted && judgeExceptionCount(tag1, f.main)) {
                     onNewException(tag1, f, exceptionStatus)
                 }
             }
@@ -175,9 +204,41 @@
         // 寮傚父鏈垱寤烘椂锛屾柊寤哄紓甯镐俊鎭�
         else {
             tag.exceptionResult.add(ex)
-//            resultList.add(ex)
             tag.exceptionCreated = true
         }
+
+        latestExceptionResult.add(ex)
+    }
+
+    /**
+     * 鍚堝苟寮傚父
+     */
+    open fun mergeExceptionResult() {
+        // 閬嶅巻鎵�鏈夌殑鍥犲瓙缁勫悎
+        config.combination?.forEach {c ->
+            val res = mutableListOf<BaseExceptionResult>()
+            var exist = true
+            // 鏌ョ湅缁勫悎鍐呯殑鎵�鏈夊洜瀛愭槸鍚﹂兘鍚屾椂鍑虹幇寮傚父
+            c.forEach { f->
+                val r = latestExceptionResult.find { e->
+                    e.factorId == f.value
+                }
+                if (r != null) {
+                    res.add(r)
+                } else {
+                    exist = false
+                }
+            }
+            // 濡傛灉缁勫悎鍐呯殑鎵�鏈夊洜瀛愰兘瀛樺湪寮傚父锛屽垯瀛樺偍涓哄悎骞跺紓甯�
+            if (exist) {
+                // 灏嗗悎骞跺紓甯镐粠鍗曚釜寮傚父闆嗗悎涓幓闄�
+                res.forEach { r->
+                    latestExceptionResult.removeIf { e-> e.factorId == r.factorId }
+                }
+                // 灏嗗悎骞跺紓甯稿瓨鍌�
+                latestCombinedResult.add(res)
+            }
+        }
     }
 
     /**

--
Gitblit v1.9.3