package com.flightfeather.uav.biz.report
|
|
import com.flightfeather.uav.common.net.AMapService
|
import com.flightfeather.uav.common.utils.MapUtil
|
import com.flightfeather.uav.domain.entity.GridCell
|
import com.flightfeather.uav.domain.entity.SceneInfo
|
import com.flightfeather.uav.domain.entity.getByFactorType
|
import com.flightfeather.uav.domain.repository.SceneInfoRep
|
import com.flightfeather.uav.lightshare.bean.GridDataDetailMixVo
|
import com.flightfeather.uav.lightshare.eunm.PollutionDegree
|
import com.flightfeather.uav.socket.eunm.FactorType
|
|
/**
|
* 走航网格叠加
|
* @date 2025/9/4
|
* @author feiyu02
|
*/
|
class MissionGridFusion(private val sceneInfoRep: SceneInfoRep) {
|
|
/**
|
* 按AQI等级叠加网格
|
*/
|
class GridFusionByAQI {
|
var pollutionDegree: String? = null
|
var gridLen:Int? = null
|
var missionList: MutableList<MissionInventory.MissionInfo> = mutableListOf()
|
var gridFusionList: MutableList<FusionGrid> = mutableListOf()
|
var highRiskGridList: MutableList<HighRiskGridByFactor> = mutableListOf()
|
}
|
|
/**
|
* 叠加网格
|
*/
|
class FusionGrid(
|
val cell: GridCell,
|
val data: GridDataDetailMixVo,
|
)
|
|
/**
|
* 监测因子的高风险叠加网格
|
*/
|
class HighRiskGridByFactor{
|
// 因子类型
|
var factorType: FactorType? = null
|
// 高风险网格信息
|
var highRiskGrid: FusionGrid? = null
|
// 因子值
|
var factorValue: Float? = null
|
// 涉及的街镇
|
var town: String? = null
|
// 四至范围,顺序为最小经度,最大经度, 最小纬度,最大纬度
|
var bounds: List<Double>? = null
|
// 高风险场景列表
|
var highRiskScenes:List<SceneInfo?>? = null
|
}
|
|
/**
|
* 生成网格融合数据,按AQI等级分组并计算各监测因子的高风险区域
|
*
|
* @param factorTypes 需要分析的监测因子类型列表
|
* @param gridLen 网格边长(米)
|
* @param gridCells 网格单元列表,包含网格的地理信息和索引
|
* @param dataList 三元组列表,每个元素包含:
|
* - 污染等级(PollutionDegree)
|
* - 走航任务详情列表(MissionDetail)
|
* - 网格数据详情列表(GridDataDetailMixVo)
|
* @return 按AQI等级分组的网格融合结果列表,每个元素包含该等级下的所有网格数据和高风险分析
|
*/
|
fun generateGridFusion(
|
factorTypes: List<FactorType>,
|
gridLen: Int,
|
gridCells: List<GridCell>,
|
dataList: List<Triple<PollutionDegree, List<MissionInventory.MissionInfo>, List<GridDataDetailMixVo>>>,
|
): List<GridFusionByAQI> {
|
return dataList.map {
|
GridFusionByAQI().apply {
|
pollutionDegree = it.first.des
|
this.gridLen = gridLen
|
missionList.addAll(it.second)
|
gridFusionList.addAll(it.third.map { gdm ->
|
val grid = gridCells.find { it.cellIndex == gdm.cellId }
|
?: throw IllegalArgumentException("网格组${gdm.groupId}中,单元ID: ${gdm.cellId} 不存在")
|
FusionGrid(grid, gdm)
|
})
|
highRiskGridList.addAll(factorTypes.map { f->
|
HighRiskGridByFactor().apply {
|
factorType = f
|
highRiskGrid = gridFusionList.maxByOrNull { gf->gf.data.getByFactorType(f) ?: 0f }
|
if (highRiskGrid != null) {
|
factorValue = highRiskGrid!!.data.getByFactorType(f)
|
if (highRiskGrid!!.cell.longitude != null && highRiskGrid!!.cell.latitude != null) {
|
Thread.sleep(50)
|
val address = AMapService.reGeo(MapUtil.wgs84ToGcj02(
|
highRiskGrid!!.cell.longitude.toDouble()
|
to highRiskGrid!!.cell.latitude.toDouble()
|
))
|
town = address.township + address.street
|
}
|
val polygon = listOf(
|
highRiskGrid!!.cell.point1Lon.toDouble() to highRiskGrid!!.cell.point1Lat.toDouble(),
|
highRiskGrid!!.cell.point2Lon.toDouble() to highRiskGrid!!.cell.point2Lat.toDouble(),
|
highRiskGrid!!.cell.point3Lon.toDouble() to highRiskGrid!!.cell.point3Lat.toDouble(),
|
highRiskGrid!!.cell.point4Lon.toDouble() to highRiskGrid!!.cell.point4Lat.toDouble(),
|
)
|
bounds = MapUtil.calFourBoundaries(polygon)
|
highRiskScenes = sceneInfoRep.findByPolygon(polygon)
|
}
|
}
|
})
|
}
|
}
|
}
|
}
|