From 9c797fa0d704ef8ffb65cd1716b8eb694b4c46c3 Mon Sep 17 00:00:00 2001
From: feiyu02 <risaku@163.com>
Date: 星期五, 04 七月 2025 17:28:00 +0800
Subject: [PATCH] 2025.7.4 1. 新增动态污染溯源新的判定逻辑

---
 src/main/kotlin/com/flightfeather/uav/biz/sourcetrace/model/PollutedData.kt |   36 +++++++++++++++++++++++++++++-------
 1 files changed, 29 insertions(+), 7 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 56190ed..d9adf45 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,6 +6,7 @@
 import com.flightfeather.uav.common.utils.DateUtil
 import com.flightfeather.uav.domain.entity.BaseRealTimeData
 import com.flightfeather.uav.lightshare.bean.DataVo
+import java.util.Date
 
 /**
  * 姹℃煋鏁版嵁
@@ -28,8 +29,9 @@
         end: BaseRealTimeData?,
         factor: FactorFilter.SelectedFactor,
         exceptionData: List<BaseRealTimeData>,
+        historyData: List<BaseRealTimeData>,
         eType: ExceptionType,
-        windLevelCondition: RTExcWindLevelConfig.WindLevelCondition,
+        windLevelCondition: RTExcWindLevelConfig.WindLevelCondition?,
     ) : this() {
         exception = eType.des
         exceptionType = eType.value
@@ -39,24 +41,26 @@
         subFactorName = factor.subs.map { it.des }
         selectedFactor = factor
 
-        startTime = DateUtil.instance.dateToString(start.dataTime, DateUtil.DateStyle.HH_MM_SS)
-        endTime = DateUtil.instance.dateToString(end?.dataTime, DateUtil.DateStyle.HH_MM_SS) ?: startTime
+        startTime = start.dataTime
+        endTime = end?.dataTime
 //        startData = start.getByFactorType(factor.main)
 //        endData = end?.getByFactorType(factor.main) ?: startData
         startData = start
         endData = end
 
         windSpeed = exceptionData.first().windSpeed?.toDouble()
-        percentage = windLevelCondition.mutationRate.first
-        times = windLevelCondition.countLimit
+        percentage = windLevelCondition?.mutationRate?.first
+        times = windLevelCondition?.countLimit
 
         dataList.add(start)
         exceptionData.forEach {
             dataList.add(it)
         }
         dataVoList.addAll(dataList.map { it.toDataVo() })
+        historyDataList.addAll(historyData.map { it.toDataVo() })
 
         calPer()
+        calRate()
     }
 
     var deviceCode: String? = null
@@ -70,8 +74,8 @@
     var subFactorName: List<String>? = null
     var selectedFactor: FactorFilter.SelectedFactor? = null
 
-    var startTime: String? = null
-    var endTime: String? = null
+    var startTime: Date? = null
+    var endTime: Date? = null
 
     var startData: BaseRealTimeData? = null
     var endData: BaseRealTimeData? = null
@@ -83,10 +87,13 @@
     var percentage: Double? = null
     // 鍥犲瓙閲忕骇骞冲潎鍙樺寲骞呭害
     var avgPer: Double? = null
+    // 鍥犲瓙閲忕骇骞冲潎鍙樺寲閫熺巼
+    var avgRate: Double? = null
 
     // 鍙戠敓娆℃暟
     var times: Int? = null
 
+    var historyDataList = mutableListOf<DataVo>()
     // 寮傚父鐩戞祴鏁版嵁
     var dataList: MutableList<BaseRealTimeData> = mutableListOf()
     var dataVoList: MutableList<DataVo> = mutableListOf()
@@ -105,4 +112,19 @@
         }
         avgPer = total / (list.size - 1)
     }
+
+    private fun calRate() {
+        val list = dataList
+//        list.add(startData)
+//        list.addAll(dataList)
+        if (list.size < 2) return
+
+        var total = .0
+        for (i in 0 until list.size - 1) {
+            val p = list[i]?.getByFactorType(selectedFactor!!.main)!!
+            val n = list[i + 1]?.getByFactorType(selectedFactor!!.main)!!
+            total += (n - p) / 4
+        }
+        avgRate = total / (list.size - 1)
+    }
 }
\ No newline at end of file

--
Gitblit v1.9.3