feiyu02
2025-09-30 94fee0b511279679b43e210878d3d36e5a14384b
src/main/kotlin/com/flightfeather/uav/biz/report/MissionInventory.kt
@@ -19,20 +19,28 @@
    // 走航清单信息
    class MissionInfo : Mission() {
        // 首要污染物
        var mainFactor: String? = null
//        var mainFactor: String? = null
        // 监测异常因子
        var abnormalFactors: List<FactorType>? = null
        // 溯源问题场景数
        var sceneCount: Int = 0
        // 溯源问题场景
        var scenes: List<SceneInfo>? = null
        // 走航涉及区域
        var keyScene: List<SceneInfo>? = null
        var exceptionCount: Int = 0
    }
    // 走航详情信息
    class MissionDetail : Mission() {
        var keyScene: List<SceneInfo>? = null
//        var keyScene: List<SceneInfo>? = null
        var dataStatistics: List<FactorStatistics>? = null
        var exceptionCount: Int = 0
//        var exceptionCount: Int = 0
    }
    /**
@@ -48,7 +56,7 @@
            var sceneCount = 0
            clue.forEach {
                if (it?.msgType == MsgType.PolClue.value) {
                    it.pollutedData?.statisticMap?.keys?.forEach { k->
                    it.pollutedData?.statisticMap?.keys?.forEach { k ->
                        // 计算每个走航任务的所有异常因子
                        if (!abnormalFactors.contains(k)) {
                            abnormalFactors.add(k)
@@ -66,12 +74,93 @@
            val missionInfo = MissionInfo()
            BeanUtils.copyProperties(mission, missionInfo)
            missionInfo.apply {
                mainFactor = factorMap.maxByOrNull { it.value }?.key?.name
//                mainFactor = factorMap.maxByOrNull { it.value }?.key?.name
                this.abnormalFactors = abnormalFactors
                this.sceneCount = sceneCount
            }
        }
        return result
    }
    fun generateMissionInfo(
        keyScenes: List<SceneInfo?>,
        mission: Mission,
        pollutedClues: List<PollutedClue?>,
        data: List<BaseRealTimeData>,
        minDis: Double = 100.0,
    ): MissionInfo {
        val factorMap = mutableMapOf<FactorType, Int>()
        val abnormalFactors = mutableListOf<FactorType>()
        var sceneCount = 0
        val scenes = mutableListOf<SceneInfo>()
        // 提取途径关键场景信息(计算走航路线是否与关键场景距离较近)
        val relatedScenes = mutableListOf<SceneInfo>()
        data.forEach { d ->
            // 跳过缺少经纬度的数据点
            if (d.longitude == null || d.latitude == null) {
                return@forEach
            }
            // 转换为GCJ02坐标系
            val point = MapUtil.wgs84ToGcj02(d.longitude!!.toDouble() to d.latitude!!.toDouble())
            keyScenes.forEach ks@{ k ->
                // 跳过缺少经纬度的场景
                if (k?.longitude == null || k.latitude == null) {
                    return@ks
                }
                // 检查是否未添加过
                if (!relatedScenes.contains(k)) {
                    // 计算距离
                    val distance = MapUtil.getDistance(
                        k.longitude!!.toDouble(),
                        k.latitude!!.toDouble(),
                        point.first,
                        point.second
                    )
                    // 检查是否距离小于阈值
                    if (distance < minDis) {
                        relatedScenes.add(k)
                    }
                }
            }
        }
        pollutedClues.forEach {
            if (it?.msgType == MsgType.PolClue.value) {
                it.pollutedData?.statisticMap?.keys?.forEach { k ->
                    // 计算每个走航任务的所有异常因子
                    if (!abnormalFactors.contains(k)) {
                        abnormalFactors.add(k)
                    }
                    // 计算每个走航任务的首要污染物
                    if (!factorMap.containsKey(k)) {
                        factorMap[k] = 0
                    }
                    factorMap[k] = factorMap[k]!! + 1
                }
                // 计算每个走航任务的溯源场景数量
                sceneCount += it.pollutedSource?.sceneList?.size ?: 0
                it.pollutedSource?.sceneList?.forEach { s->
                    if (scenes.find { s1 -> s1.guid == s.guid } == null) {
                        scenes.add(s)
                    }
                }
            }
        }
        // 异常数据点数量统计
        val clues = pollutedClues.filter { it?.msgType == MsgType.PolClue.value }
        val missionInfo = MissionInfo()
        BeanUtils.copyProperties(mission, missionInfo)
        missionInfo.apply {
//            mainFactor = factorMap.maxByOrNull { it.value }?.key?.name
            this.abnormalFactors = abnormalFactors
            this.sceneCount = sceneCount
            this.scenes = scenes
            keyScene = relatedScenes
            exceptionCount = clues.size
        }
        return missionInfo
    }
    /**
@@ -93,44 +182,52 @@
        mission: Mission,
        pollutedClues: List<PollutedClue?>,
        data: List<BaseRealTimeData>,
        minDis:Double = 100.0
        minDis: Double = 100.0,
    ): MissionDetail {
        // 创建任务详情对象并复制基本信息
        val missionDetail = MissionDetail()
        BeanUtils.copyProperties(mission, missionDetail)
        // 提取途径关键场景信息(计算走航路线是否与关键场景距离较近)
        val relatedScenes = mutableListOf<SceneInfo>()
        data.forEach { d->
            // 跳过缺少经纬度的数据点
            if (d.longitude == null || d.latitude == null) {
                return@forEach
            }
            // 转换为GCJ02坐标系
            val point = MapUtil.wgs84ToGcj02(d.longitude!!.toDouble() to d.latitude!!.toDouble())
            keyScenes.forEach ks@ { k->
                // 跳过缺少经纬度的场景
                if (k?.longitude == null || k.latitude == null) {
                    return@ks
                }
                // 计算距离
                val distance = MapUtil.getDistance(k.longitude!!.toDouble(), k.latitude!!.toDouble(), point.first, point.second)
                // 检查是否距离小于阈值且未添加过
                if (distance < minDis && !relatedScenes.contains(k)) {
                    relatedScenes.add(k)
                }
            }
        }
//        val relatedScenes = mutableListOf<SceneInfo>()
//        data.forEach { d ->
//            // 跳过缺少经纬度的数据点
//            if (d.longitude == null || d.latitude == null) {
//                return@forEach
//            }
//            // 转换为GCJ02坐标系
//            val point = MapUtil.wgs84ToGcj02(d.longitude!!.toDouble() to d.latitude!!.toDouble())
//            keyScenes.forEach ks@{ k ->
//                // 跳过缺少经纬度的场景
//                if (k?.longitude == null || k.latitude == null) {
//                    return@ks
//                }
//                // 检查是否未添加过
//                if (!relatedScenes.contains(k)) {
//                    // 计算距离
//                    val distance = MapUtil.getDistance(
//                        k.longitude!!.toDouble(),
//                        k.latitude!!.toDouble(),
//                        point.first,
//                        point.second
//                    )
//                    // 检查是否距离小于阈值
//                    if (distance < minDis) {
//                        relatedScenes.add(k)
//                    }
//                }
//            }
//        }
        // 存储与任务相关联的关键场景信息
        missionDetail.keyScene = relatedScenes
//        missionDetail.keyScene = relatedScenes
        // 计算环境因子统计数据(平均值、最小值、最大值)
        missionDetail.dataStatistics = data.calDataStatistics()
        // 异常数据点数量统计
        val clues = pollutedClues.filter { it?.msgType == MsgType.PolClue.value }
        missionDetail.exceptionCount = clues.size
//        val clues = pollutedClues.filter { it?.msgType == MsgType.PolClue.value }
//        missionDetail.exceptionCount = clues.size
        return missionDetail
    }
}