Riku
2025-06-04 7d33080998a2c5b38e8a74dbed2b0f40d39bbe47
1. 新增动态污染溯源新的判定逻辑(待完成)
已修改2个文件
74 ■■■■■ 文件已修改
src/main/kotlin/com/flightfeather/uav/biz/sourcetrace/model/PollutedSummary.kt 26 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/kotlin/com/flightfeather/uav/common/net/AMapService.kt 48 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/kotlin/com/flightfeather/uav/biz/sourcetrace/model/PollutedSummary.kt
@@ -1,9 +1,13 @@
package com.flightfeather.uav.biz.sourcetrace.model
import com.flightfeather.uav.biz.sourcetrace.config.RTExcWindLevelConfig
import com.flightfeather.uav.common.net.AMapService
import com.flightfeather.uav.common.utils.MapUtil
import com.flightfeather.uav.domain.entity.BaseRealTimeData
import com.flightfeather.uav.domain.entity.SceneInfo
import java.math.BigDecimal
import java.time.LocalDateTime
import java.util.Date
import java.util.Timer
import java.util.TimerTask
@@ -30,6 +34,9 @@
    inner class AnalysisResult{
        // 按照被扫描次数降序排列的污染源列表
        var sortedSceneList: List<Pair<SceneInfo?, Int>>? = null
        var time: Date? = null
        var advice:String?= null
        var direction: AMapService.AMapDirection? = null
    }
    /**
@@ -154,8 +161,27 @@
        result.sortedSceneList = res.map { it.value }
        // 当前的走航数据的定位和污染源距离是否是逐渐接近,若走航远离了主要污染源,提示用户调整走航路线
        if (!result.sortedSceneList.isNullOrEmpty()) {
            val sT = clueList.first().pollutedData?.startTime
            val closetScene = result.sortedSceneList?.first()
            result.advice = "根据${sT}起的${clueList.size}条最新污染线索,污染源[${closetScene?.first?.name}]被多次溯源,具有较高污染风险,现提供新的走航推荐路线,可经过该污染源。"
            val lastP = realTimeDataList.last()
            if (lastP.longitude != null && lastP.latitude != null &&
                lastP.longitude!! > BigDecimal.ZERO && lastP.latitude!! > BigDecimal.ZERO
                && closetScene?.first?.longitude != null && closetScene.first?.latitude != null &&
                closetScene.first?.longitude!! > BigDecimal.ZERO && closetScene.first?.latitude!! > BigDecimal.ZERO) {
                val origin = MapUtil.wgs84ToGcj02(lastP.longitude!!.toDouble() to lastP.latitude!!.toDouble())
                val destination = closetScene.first!!.longitude.toDouble() to closetScene.first!!.latitude.toDouble()
                result.direction = AMapService.directionDriving(origin, destination)
            }
        }
        result.time = realTimeDataList.last().dataTime
        // 线索分析完成后,移动至历史线索列表
        historyClueList.addAll(clueList)
        clueList.clear()
src/main/kotlin/com/flightfeather/uav/common/net/AMapService.kt
@@ -32,6 +32,54 @@
        val street: String,
    )
    data class AMapDirection(
        // 路线类型,driving: 驾车;
        val type: String,
        // 起点经纬度
        val origin: Pair<Double, Double>,
        // 终点经纬度
        val destination: Pair<Double, Double>,
        // 途径路线经纬度(不包括起点终点)
        val paths: List<Pair<Double, Double>>,
        // 方案距离,单位:米
        val distance: String
    )
    /**
     * 驾车路线规划
     */
    fun directionDriving(origin: Pair<Double, Double>, destination: Pair<Double, Double>):AMapDirection {
        val res = httpMethod.get(
            "/v5/direction/driving", listOf(
                "key" to KEY,
                "origin" to "${origin.first},${origin.second}",
                "destination" to "${destination.first},${destination.second}",
                "show_fields" to "polyline"
            )
        )
        val obj = handleRes(res)
        try {
            val count = obj["count"].asString.toIntOrNull()
            if (count != null && count > 0) {
                val path = obj["route"].asJsonObject["paths"].asJsonArray.get(0).asJsonObject
                val finalPaths = mutableListOf<Pair<Double,Double>>()
                path["steps"].asJsonArray.forEach {
                    finalPaths.addAll(
                        it.asJsonObject["polyline"].asString.split(";").map { str->
                            val strArr = str.split(",")
                            strArr[0].toDouble() to strArr[1].toDouble()
                        }
                    )
                }
                return AMapDirection("driving", origin, destination, finalPaths, path["distance"].asString)
            } else {
                throw BizException("高德API驾车路线规划失败,没有找到可行的路线")
            }
        } catch (e: Exception) {
            throw BizException("高德API驾车路线规划错误,${e.message}")
        }
    }
    /**
     * 地理逆编码
     * @param location 坐标点