From c5f380b69707a9a09fe988a2f4bd98e142bf64ae Mon Sep 17 00:00:00 2001
From: feiyu02 <risaku@163.com>
Date: 星期四, 10 七月 2025 17:29:48 +0800
Subject: [PATCH] 2025.7.10 1. 修改动态溯源异常判断逻辑

---
 src/main/kotlin/com/flightfeather/uav/biz/sourcetrace/model/PollutedData.kt |   32 ++++++++++++++++++++++++++++++++
 1 files changed, 32 insertions(+), 0 deletions(-)

diff --git a/src/main/kotlin/com/flightfeather/uav/biz/sourcetrace/model/PollutedData.kt b/src/main/kotlin/com/flightfeather/uav/biz/sourcetrace/model/PollutedData.kt
index d9adf45..e38d254 100644
--- a/src/main/kotlin/com/flightfeather/uav/biz/sourcetrace/model/PollutedData.kt
+++ b/src/main/kotlin/com/flightfeather/uav/biz/sourcetrace/model/PollutedData.kt
@@ -6,7 +6,9 @@
 import com.flightfeather.uav.common.utils.DateUtil
 import com.flightfeather.uav.domain.entity.BaseRealTimeData
 import com.flightfeather.uav.lightshare.bean.DataVo
+import com.flightfeather.uav.socket.eunm.FactorType
 import java.util.Date
+import kotlin.math.round
 
 /**
  * 姹℃煋鏁版嵁
@@ -61,6 +63,11 @@
 
         calPer()
         calRate()
+
+        val s = dataSummary(exceptionData, factor.main)
+        avg = s.first
+        min = s.second
+        max = s.third
     }
 
     var deviceCode: String? = null
@@ -89,6 +96,10 @@
     var avgPer: Double? = null
     // 鍥犲瓙閲忕骇骞冲潎鍙樺寲閫熺巼
     var avgRate: Double? = null
+
+    var avg: Double? = null
+    var min: Double? = null
+    var max: Double? = null
 
     // 鍙戠敓娆℃暟
     var times: Int? = null
@@ -127,4 +138,25 @@
         }
         avgRate = total / (list.size - 1)
     }
+
+    private fun dataSummary(exceptionData: List<BaseRealTimeData?>, factorType: FactorType): Triple<Double, Double,
+            Double> {
+        var min = -1.0
+        var max = -1.0
+        var total = .0
+        var count = 0
+        exceptionData.forEach {
+            val value = it?.getByFactorType(factorType)?.toDouble() ?: return@forEach
+            if (min == -1.0 || min > value) {
+                min = round(value * 1000) / 1000
+            }
+            if (max == -1.0 || max < value) {
+                max = round(value * 1000) / 1000
+            }
+            total += value
+            count++
+        }
+        val avg = if (count == 0) .0 else round(total / count * 1000) / 1000
+        return Triple(avg, min, max)
+    }
 }
\ No newline at end of file

--
Gitblit v1.9.3