feiyu02
2025-09-12 61871594dfa0a5ac2c4d895d9ec4034feba57094
src/main/kotlin/com/flightfeather/uav/biz/report/MissionSummary.kt
@@ -2,11 +2,9 @@
import com.flightfeather.uav.biz.sourcetrace.model.PollutedClue
import com.flightfeather.uav.domain.entity.Mission
import com.flightfeather.uav.domain.repository.MissionRep
import com.flightfeather.uav.lightshare.bean.AreaVo
import com.flightfeather.uav.socket.eunm.FactorType
import com.flightfeather.uav.socket.sender.MsgType
import org.springframework.stereotype.Component
import java.util.*
import kotlin.math.round
@@ -16,6 +14,10 @@
 * @author feiyu02
 */
class MissionSummary() {
    companion object {
        private const val FOCUS_AREA_COUNT = 2
    }
    data class Summary(
        // 汇总周期开始时间
@@ -37,7 +39,9 @@
        // 高风险场景总数
        val highRiskSceneCount:Int,
        // 问题按监测因子类型分布情况, <因子类型,次数,占比>
        val probByFactor:List<Triple<String, Int, Double>>
        val probByFactor: List<Triple<String, Int, Double>>,
        // 聚焦区域或场景
        val focusRegion: List<String>,
    )
    /**
@@ -61,7 +65,8 @@
                countByDegree = emptyList(),
                probCount = 0,
                highRiskSceneCount = 0,
                probByFactor = emptyList()
                probByFactor = emptyList(),
                focusRegion = emptyList()
            )
        }
@@ -100,7 +105,10 @@
        val highRiskSceneCount = clueRes.second // 需关联场景表统计
        val probByFactor = clueRes.third
        // 7. 构建并返回统计结果
        // 7. 从异常所在地区和溯源的场景中统计聚焦区域
        val focusRegion = calFocusRegion(clues)
        // 8. 构建并返回统计结果
        return Summary(
            startTime = startTime,
            endTime = endTime,
@@ -111,7 +119,8 @@
            countByDegree = countByDegree,
            probCount = probCount,
            highRiskSceneCount = highRiskSceneCount,
            probByFactor = probByFactor
            probByFactor = probByFactor,
            focusRegion = focusRegion
        )
    }
@@ -137,4 +146,32 @@
        }
        return Triple(probCount, highRiskSceneCount, probByFactor)
    }
    private fun calFocusRegion(clues: List<PollutedClue?>): List<String> {
        // 统计每个区域或场景出现的次数
        val focusArea = mutableMapOf<String, Int>()
        val focusScene = mutableMapOf<String, Int>()
        clues.forEach { c->
            if (c?.msgType == MsgType.PolClue.value) {
                if (!c.pollutedArea?.address.isNullOrBlank()) {
                    if (focusArea.containsKey(c.pollutedArea?.address)) {
                        focusArea[c.pollutedArea?.address!!] = focusArea[c.pollutedArea?.address]!! + 1
                    } else {
                        focusArea[c.pollutedArea?.address!!] = 1
                    }
                }
                c.pollutedSource?.sceneList?.forEach { s->
                    if (s.name != null) {
                        if (focusScene.containsKey(s.name!!)) {
                            focusScene[s.name!!] = focusScene[s.name!!]!! + 1
                        } else {
                            focusScene[s.name!!] = 1
                        }
                    }
                }
            }
        }
        return focusArea.entries.sortedByDescending { it.value }.map { it.key }.take(FOCUS_AREA_COUNT) +
                focusScene.entries.sortedByDescending { it.value }.map { it.key }.take(FOCUS_AREA_COUNT)
    }
}