From 8eb584869b4fd4de0f51c93f2616f12e51df9193 Mon Sep 17 00:00:00 2001
From: feiyu02 <risaku@163.com>
Date: 星期四, 18 十二月 2025 17:48:29 +0800
Subject: [PATCH] 2025.12.18 1. 动态溯源相关分析逻辑调整; 2. 走航报告接口参数调整;
---
src/main/kotlin/com/flightfeather/uav/biz/sourcetrace/model/PollutedSource.kt | 186 +++++++++++++++++++++++++++++++++++++---------
1 files changed, 150 insertions(+), 36 deletions(-)
diff --git a/src/main/kotlin/com/flightfeather/uav/biz/sourcetrace/model/PollutedSource.kt b/src/main/kotlin/com/flightfeather/uav/biz/sourcetrace/model/PollutedSource.kt
index c948fe3..a6e9311 100644
--- a/src/main/kotlin/com/flightfeather/uav/biz/sourcetrace/model/PollutedSource.kt
+++ b/src/main/kotlin/com/flightfeather/uav/biz/sourcetrace/model/PollutedSource.kt
@@ -1,7 +1,9 @@
package com.flightfeather.uav.biz.sourcetrace.model
-import com.flightfeather.uav.biz.FactorFilter
+import com.flightfeather.uav.biz.dataanalysis.model.ExceptionType
+import com.flightfeather.uav.common.utils.DateUtil
import com.flightfeather.uav.common.utils.MapUtil
+import com.flightfeather.uav.domain.entity.BaseRealTimeData
import com.flightfeather.uav.domain.entity.SceneInfo
import com.flightfeather.uav.domain.repository.SceneInfoRep
import com.flightfeather.uav.lightshare.bean.AreaVo
@@ -10,7 +12,6 @@
import com.flightfeather.uav.socket.eunm.FactorType
import org.springframework.beans.BeanUtils
import org.springframework.web.context.ContextLoader
-import kotlin.math.min
/**
* 姹℃煋鏉ユ簮
@@ -26,61 +27,114 @@
*/
// 婧簮浼佷笟
- var sceneList:List<SceneInfoVo?>? = null
+ var sceneList: List<SceneInfoVo>? = null
- init {
+ // 婧簮鎺ㄧ悊缁撹
+ var conclusion: String? = null
- }
-
- fun searchScenes(pollutedArea: PollutedArea, factor: FactorFilter.SelectedFactor) {
+ fun searchScenes(pollutedArea: PollutedArea, pollutedData: PollutedData) {
ContextLoader.getCurrentWebApplicationContext()?.getBean(SceneInfoRep::class.java)?.run {
- searchScenes(pollutedArea, this, factor)
+ searchScenes(pollutedArea, this, pollutedData)
}
}
/**
* 鏌ユ壘绯荤粺鍐呴儴婧簮鑼冨洿鍐呯殑姹℃煋浼佷笟
*/
- fun searchScenes(pollutedArea: PollutedArea, sceneInfoRep: SceneInfoRep, factor: FactorFilter.SelectedFactor) {
+ fun searchScenes(pollutedArea: PollutedArea, sceneInfoRep: SceneInfoRep, pollutedData: PollutedData) {
// Fixme 2025.5.14: 姹℃煋婧愮殑鍧愭爣鏄珮寰峰湴鍥惧潗鏍囩郴锛堢伀鏄熷潗鏍囩郴锛夛紝鑰岃蛋鑸暟鎹槸WGS84鍧愭爣绯�
// 鎸夌収鍖哄煙妫�绱㈠唴閮ㄦ薄鏌撴簮淇℃伅
- // 1. 棣栧厛鎸夌収鍥涜嚦鑼冨洿浠庢暟鎹簱鍒濇绛涢�夋薄鏌撴簮锛岄渶瑕佸厛灏嗗潗鏍囪浆鎹负gcj02锛堢伀鏄熷潗鏍囩郴锛夛紝鍥犱负姹℃煋婧愬満鏅俊鎭兘涓烘鍧愭爣绯�
-// val polygonTmp = pollutedArea.polygon!!.map {
-// MapUtil.gcj02ToWgs84(it)
-// }
- val polygonTmp = pollutedArea.polygon!!
- val fb = MapUtil.calFourBoundaries(polygonTmp)
- val sceneList = sceneInfoRep.findByCoordinateRange(fb)
- // 2. 鍐嶇簿纭垽鏂槸鍚﹀湪鍙嶅悜婧簮鍖哄煙澶氳竟褰㈠唴閮�
- val result = mutableListOf<SceneInfo>()
- sceneList.forEach {
- val point = it!!.longitude.toDouble() to it.latitude.toDouble()
- if (MapUtil.isPointInPolygon(point, polygonTmp)) {
- result.add(it)
+ var result = mutableListOf<SceneInfo>()
+ val polygonTmp = pollutedArea.polygon
+ this.sceneList = emptyList()
+
+ if (polygonTmp != null) {
+ val fb = MapUtil.calFourBoundaries(polygonTmp)
+ // 1. 棣栧厛鎸夌収鍥涜嚦鑼冨洿浠庢暟鎹簱鍒濇绛涢�夋薄鏌撴簮锛屾澶勭殑鍖哄煙鍧愭爣宸茶浆鎹负鐏槦鍧愭爣绯�
+ val sceneList = sceneInfoRep.findByCoordinateRange(fb)
+ // 2. 鍐嶇簿纭垽鏂槸鍚﹀湪鍙嶅悜婧簮鍖哄煙澶氳竟褰㈠唴閮�
+ sceneList.forEach {
+ val point = it!!.longitude.toDouble() to it.latitude.toDouble()
+ if (MapUtil.isPointInPolygon(point, polygonTmp)) {
+ result.add(it)
+ }
}
+
+ // 3. 鍐嶇粺涓�妫�绱㈣繎璺濈姹℃煋鍦嗗舰鍖哄煙鍐呴儴鐨勬薄鏌撴簮
+ val closePolygonTmp = pollutedArea.closePolygon!!
+ val closeFb = MapUtil.calFourBoundaries(closePolygonTmp)
+ val closeSceneList = sceneInfoRep.findByCoordinateRange(closeFb)
+ closeSceneList.forEach {
+ val point = it!!.longitude.toDouble() to it.latitude.toDouble()
+ if (MapUtil.isPointInPolygon(point, closePolygonTmp)) {
+ result.add(it)
+ }
+ }
+ // 4. 鍘婚噸
+ result = result.distinctBy { it.guid }.toMutableList()
+
+ // 5. 鏍规嵁姹℃煋鍥犲瓙鐨勯噺绾э紝璁$畻涓昏鐨勬薄鏌撳満鏅被鍨嬶紝绛涢�夌粨鏋�
+ val mainSceneType = calSceneType(pollutedData)
+ result = result.filter {
+ val r = mainSceneType.find { s ->
+ s.value == it.typeId.toInt()
+ }
+ r != null
+ }.toMutableList()
+ this.sceneList = findClosestStation(sceneInfoRep, result)
}
- findClosestStation(sceneInfoRep, result)
-
-
-// TODO("鎸夌収鎵�閫夌洃娴嬪洜瀛愮被鍨嬶紝鍖哄垎姹℃煋婧愮被鍨�")
-
+ val txt = summaryTxt(pollutedData, this.sceneList!!)
+ this.conclusion = txt
}
/**
- * 璁$畻鍙兘鐨勭浉鍏虫薄鏌撳満鏅被鍨�
+ * 璁$畻鍙兘鐨勭浉鍏虫薄鏌撳満鏅被鍨嬩互鍙婃帹鐞嗙粨璁�
*/
- private fun calFactorType(factor: FactorFilter.SelectedFactor) {
-// when (factor.main) {
-// FactorType.PM25 -> {}
-//
-// }
+ @Throws(Exception::class)
+ private fun calSceneType(pollutedData: PollutedData): List<SceneType> {
+ val sceneTypes = mutableListOf<SceneType>()
+ pollutedData.statisticMap.entries.forEach { s ->
+ val res = when (s.key) {
+ // 姘哀鍖栧悎鐗╋紝涓�鑸敱浜庢満鍔ㄨ溅灏炬皵锛屽悓姝ヨ绠桟O
+ FactorType.NO,
+ FactorType.NO2,
+ -> {
+ listOf(SceneType.TYPE1, SceneType.TYPE6, SceneType.TYPE10, SceneType.TYPE17)
+ }
+
+ FactorType.CO -> listOf(SceneType.TYPE6, SceneType.TYPE10, SceneType.TYPE17)
+ FactorType.H2S -> null
+ FactorType.SO2 -> null
+ FactorType.O3 -> null
+ FactorType.PM25,
+ FactorType.PM10,
+ -> {
+ listOf(
+ SceneType.TYPE1,
+ SceneType.TYPE2,
+ SceneType.TYPE3,
+ SceneType.TYPE14,
+ SceneType.TYPE5,
+ SceneType.TYPE18
+ )
+ }
+
+ FactorType.VOC -> {
+ listOf(SceneType.TYPE5, SceneType.TYPE6, SceneType.TYPE17, SceneType.TYPE12, SceneType.TYPE18)
+ }
+
+ else -> null
+ }
+ res?.let { sceneTypes.addAll(it) }
+ }
+ return sceneTypes.distinct()
}
/**
* 璁$畻鏈�杩戠殑鐩戞祴绔欑偣
*/
- private fun findClosestStation(sceneInfoRep: SceneInfoRep, sceneList: List<SceneInfo>) {
+ private fun findClosestStation(sceneInfoRep: SceneInfoRep, sceneList: List<SceneInfo>): List<SceneInfoVo> {
val res1 = sceneInfoRep.findByArea(AreaVo().apply {
sceneTypeId = SceneType.TYPE19.value.toString()
})
@@ -90,10 +144,10 @@
})
val res = res1.toMutableList().apply { addAll(res2) }
- this.sceneList = sceneList.map {
+ return sceneList.map {
var minLen = -1.0
var selectedRes: SceneInfo? = null
- res.forEach { r->
+ res.forEach { r ->
val dis = MapUtil.getDistance(
it.longitude.toDouble(),
it.latitude.toDouble(),
@@ -113,4 +167,64 @@
return@map vo
}
}
+
+ /**
+ * 婧簮瑙f瀽
+ * @param pollutedData 姹℃煋鏁版嵁
+ * @param sceneList 椋庨櫓婧愬垪琛�
+ * @return 婧簮鎻忚堪
+ */
+ private fun summaryTxt(pollutedData: PollutedData, sceneList: List<SceneInfoVo>): String {
+ val st = DateUtil.instance.getTime(pollutedData.startTime)
+ val et = DateUtil.instance.getTime(pollutedData.endTime)
+
+ // 1. 鎻忚堪寮傚父鍙戠敓鐨勬椂闂村拰寮傚父绫诲瀷
+ var txt = "鍦�${st}鑷�${et}涔嬮棿锛屽嚭鐜�${pollutedData.exception}${pollutedData.times}娆�"
+
+ // 2. 鎻忚堪寮傚父鏁版嵁鐨勫彉鍖栨儏鍐�
+ val statArr = mutableListOf<String>()
+ pollutedData.statisticMap.entries.forEach { s ->
+ val txtArr = mutableListOf<String>()
+ s.value.excGroup?.forEach exception@{ p ->
+ val preValue = p.getFirstDataValue()
+ val curValue = p.getLastDataValue()
+ val per = p.per?.times(100)
+ val rate = p.rate
+ if (preValue == null || curValue == null || per == null) return@exception
+ when (pollutedData.exceptionType) {
+ // 閲忕骇绐佸彉
+ ExceptionType.TYPE4.value -> {
+ txtArr.add("浠�${preValue}渭g/m鲁绐佸彉鑷�${curValue}渭g/m鲁锛屽彉鍖栫巼涓�${per}%")
+ }
+ // 蹇�熶笂鍗�
+ ExceptionType.TYPE9.value -> {
+ txtArr.add("浠�${preValue}渭g/m鲁蹇�熶笂鍗囪嚦${curValue}渭g/m鲁锛屽彉鍖栭�熺巼涓�${rate}渭g/m鲁/绉掞紝鍙樺寲鐜囦负${per}%")
+ }
+ }
+ }
+ statArr.add("${s.key.getTxt()}閲忕骇${txtArr.joinToString("锛�")}")
+ }
+ txt += "锛�${statArr.joinToString("锛�")}"
+
+ // 3. 鎻忚堪鍙戠幇鐨勯闄╂簮鎯呭喌
+ if (sceneList.isEmpty()) {
+ txt += ("锛屽彲鑳藉瓨鍦ㄩ殣钘忛闄╂簮銆�")
+ } else {
+ txt += ("锛屽彂鐜�${sceneList.size}涓闄╂簮锛屽寘鍚�")
+
+ val sizeMap = mutableMapOf<String, Int>()
+ sceneList.forEach {
+ if (!sizeMap.containsKey(it.type)) {
+ sizeMap[it.type] = 0
+ }
+ sizeMap[it.type] = sizeMap[it.type]!! + 1
+ }
+ sizeMap.forEach { (t, u) ->
+ txt += ("${u}涓�${t}锛�")
+ }
+ txt = txt.replaceRange(txt.length - 1, txt.length, "銆�")
+ }
+
+ return txt
+ }
}
\ No newline at end of file
--
Gitblit v1.9.3