feiyu02
2025-09-12 61871594dfa0a5ac2c4d895d9ec4034feba57094
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package com.flightfeather.uav.biz.report
 
import com.flightfeather.uav.biz.sourcetrace.model.PollutedClue
import com.flightfeather.uav.common.utils.MapUtil
import com.flightfeather.uav.domain.entity.SceneInfo
import com.flightfeather.uav.domain.entity.avg
import com.flightfeather.uav.socket.eunm.AggregatedFactorType
 
/**
 * 走航典型隐患区域
 * @date 2025/8/25 14:18
 * @author feiyu
 */
class MissionRiskArea {
 
    class ClueByArea {
        var sceneInfo: SceneInfo? = null
        var clueByFactorList: MutableList<ClueByFactor>? = null
    }
 
    class ClueByFactor {
        var factor: String? = null
        var clues: MutableList<PollutedClue>? = null
    }
 
    fun generateClueByRiskArea(keyScenes: List<SceneInfo?>, pollutedClues: List<PollutedClue?>): List<ClueByArea> {
        val result = mutableListOf<ClueByArea>()
        
        pollutedClues.forEach { pollutedClue ->
            if (pollutedClue == null) return@forEach
            val dataList = pollutedClue.pollutedData?.dataList ?: emptyList()
            if (dataList.isEmpty()) return@forEach
            
            // 计算单个PollutedClue的均值经纬度
            val avgData = dataList.avg()
            val wgs84Lng = avgData.longitude?.toDouble() ?: return@forEach
            val wgs84Lat = avgData.latitude?.toDouble() ?: return@forEach
            
            // 坐标转换
            val gcj02Point = MapUtil.wgs84ToGcj02(wgs84Lng to wgs84Lat)
            
            // 查找最近场景
            var minDistance = Double.MAX_VALUE
            var closestScene: SceneInfo? = null
            keyScenes.forEach { scene ->
                scene?.let { s ->
                    val sceneLng = s.longitude?.toDouble() ?: return@let
                    val sceneLat = s.latitude?.toDouble() ?: return@let
                    val distance = MapUtil.getDistance(gcj02Point.first, gcj02Point.second, sceneLng, sceneLat)
                    if (distance < minDistance) {
                        minDistance = distance
                        closestScene = s
                    }
                }
            }
            
            // 按场景和因子分组线索
            closestScene?.let { scene ->
                var clueByArea = result.find { it.sceneInfo?.guid == scene.guid }
                if (clueByArea == null) {
                    clueByArea = ClueByArea().apply {
                        this.sceneInfo = scene
                        this.clueByFactorList = mutableListOf()
                    }
                    result.add(clueByArea)
                }
 
                val firstFactorType = pollutedClue.pollutedData?.statisticMap?.keys?.first()
                val afType =  AggregatedFactorType.getAFType(firstFactorType)
                val factorName = afType?.des ?: firstFactorType?.des
                var clueByFactor = clueByArea.clueByFactorList?.find { it.factor == factorName }
                if (clueByFactor == null) {
                    clueByFactor = ClueByFactor().apply {
                        this.factor = factorName
                        this.clues = mutableListOf()
                    }
                    clueByArea.clueByFactorList?.add(clueByFactor)
                }
                
                clueByFactor.clues?.add(pollutedClue)
            }
        }
        
        return result
    }
}