From c56e1e74426238939f229f0005828d05089715ff Mon Sep 17 00:00:00 2001
From: feiyu02 <risaku@163.com>
Date: 星期四, 03 七月 2025 17:30:58 +0800
Subject: [PATCH] 2025.7.3 1. 新增动态污染溯源新的判定逻辑

---
 src/main/kotlin/com/flightfeather/uav/biz/dataanalysis/BaseExceptionContinuous.kt |   52 ++++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 44 insertions(+), 8 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 658c621..7193e08 100644
--- a/src/main/kotlin/com/flightfeather/uav/biz/dataanalysis/BaseExceptionContinuous.kt
+++ b/src/main/kotlin/com/flightfeather/uav/biz/dataanalysis/BaseExceptionContinuous.kt
@@ -37,7 +37,7 @@
     /**
      * 绔嬪嵆鍒ゆ柇锛氬綋鍑虹幇寮傚父鏃讹紝缂撳瓨寮傚父鏁版嵁鐨勫悓鏃讹紝绔嬪嵆瀵瑰凡鏈夊紓甯歌繘琛屽垽鏂槸鍚︽弧瓒冲紓甯哥粨鏋滆姹�
      */
-    open fun immeExcCheck(tag: T): Boolean {
+    open fun immeExcCheck(tag: T, factorType: FactorType): Boolean {
         return false
     }
 
@@ -53,6 +53,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>
@@ -61,11 +71,24 @@
      * 鍒ゆ柇寮傚父鍑虹幇鐨勮繛缁釜鏁版槸鍚︽弧瓒虫潯浠�
      * @param tag 寮傚父鏁版嵁瀵硅薄
      */
-    abstract fun judgeExceptionCount(tag: T): Boolean
+    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 榛樿涓嶉渶瑕佹埅鍙�
+     * @return
      */
     open fun needCut(tag: T, hasException: Boolean?): Boolean {
         // 榛樿鍒ゆ柇鏉′欢涓� 褰撳紓甯镐笉鍐嶉噸澶嶅嚭鐜版椂锛屽舰鎴愬紓甯哥粨鏋�
@@ -83,10 +106,12 @@
 
     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 {
+                it.addHistoryData(data)
+
                 it.eIndex++
                 // 璧峰鏁版嵁
                 it.endData = data
@@ -105,9 +130,14 @@
                     // 鏈夊紓甯稿嚭鐜版椂锛岃褰曞紓甯告暟鎹�
                     it.addExceptionData(data)
                     // 褰撶珛鍗冲垽鏂�氳繃鏃讹紝褰㈡垚寮傚父缁撴灉
-                    if (immeExcCheck(it)) {
+                    if (immeExcCheck(it, f)) {
                         recordException(s, it, data)
                     }
+                }
+                // 3. 鏁版嵁姝e父锛屾棤浠讳綍寮傚父鏃禿
+                // TODO("2025.6.3锛氬叾浠栧瓙绫荤殑姝ゅ鍒锋柊閫昏緫寰呭畬鎴愨��)
+                else {
+                    it.refreshWithNextException(data)
                 }
             }
         }
@@ -136,13 +166,13 @@
     ) {
         val tag = tagMap[factor?.main]
         if (factor != null && tag != null) {
-            if (tag.exceptionExisted && judgeExceptionCount(tag)) {
+            if (tag.exceptionExisted && judgeExceptionCount(tag, factor.main)) {
                 onNewException(tag, factor, exceptionStatus)
             }
         } else {
             config.factorFilter.selectedList.forEach { f ->
                 val tag1 = tagMap[f.main] ?: return@forEach
-                if (tag1.exceptionExisted && judgeExceptionCount(tag1)) {
+                if (tag1.exceptionExisted && judgeExceptionCount(tag1, f.main)) {
                     onNewException(tag1, f, exceptionStatus)
                 }
             }
@@ -154,7 +184,8 @@
      */
     open fun onNewException(tag: T, factor: FactorFilter.SelectedFactor, exceptionStatus: ExceptionStatusType) {
         if (tag.startData == null) return
-        val ex = newResult(tag.startData!!, lastData, factor, tag.exceptionData)
+//        val ex = newResult(tag.startData!!, tag.endData, factor, tag.exceptionData)
+        val ex = newResult(tag, factor)
             .apply { status = exceptionStatus.value }
         // 寮傚父宸插垱寤烘椂锛屾洿鏂板紓甯镐俊鎭�
         if (tag.exceptionCreated) {
@@ -172,4 +203,9 @@
         }
     }
 
+    /**
+     * 鐢熸垚涓�鏉″紓甯稿垎鏋愮粨鏋�
+     */
+    abstract fun newResult(tag:T, factor: FactorFilter.SelectedFactor): Y
+
 }
\ No newline at end of file

--
Gitblit v1.9.3