package com.flightfeather.uav.biz.dataprocess
|
|
import com.flightfeather.uav.common.location.TrackSegment
|
import com.flightfeather.uav.common.net.AMapService
|
import com.flightfeather.uav.domain.entity.BaseRealTimeData
|
import com.flightfeather.uav.domain.entity.Mission
|
import com.flightfeather.uav.domain.entity.SegmentInfo
|
import com.flightfeather.uav.domain.entity.avg
|
import com.flightfeather.uav.domain.repository.RealTimeDataRep
|
import com.flightfeather.uav.domain.repository.SegmentInfoRep
|
import org.springframework.stereotype.Component
|
import java.math.BigDecimal
|
|
/**
|
* 走航轨迹按照路段进行分割
|
* @date 2024/7/4
|
* @author feiyu02
|
*/
|
@Component
|
class RoadSegment(
|
private val realTimeDataRep: RealTimeDataRep,
|
private val segmentInfoRep: SegmentInfoRep,
|
) {
|
|
fun handle(mission: Mission) {
|
// 获取数据分段
|
val data = mutableListOf<BaseRealTimeData>()
|
realTimeDataRep.fetchData(mission).forEach {
|
// 去除无效经纬度
|
if ((it.longitude != null && it.longitude != BigDecimal.ZERO)
|
&& (it.latitude != null && it.latitude != BigDecimal.ZERO)
|
) {
|
data.add(it)
|
}
|
}
|
val sData = TrackSegment.segmentWithRoad(data)
|
// 根据每个分段的GPS坐标均值通过高德API转换为高德坐标
|
val avgGPS = mutableListOf<Pair<Double, Double>>()
|
sData.forEach {
|
val d = it.avg()
|
if (d.longitude != null && d.latitude != null) {
|
avgGPS.add(d.longitude!!.toDouble() to d.latitude!!.toDouble())
|
}
|
}
|
val gdGPS = AMapService.coordinateConvert(avgGPS)
|
// 通过高德API查询坐标对应的路段
|
val segmentInfoList = mutableListOf<SegmentInfo>()
|
gdGPS.forEachIndexed { i, pair ->
|
val address = AMapService.reGeo(pair)
|
segmentInfoList.add(SegmentInfo().apply {
|
missionCode = mission.missionCode
|
deviceCode = mission.deviceCode
|
startTime = sData[i][0].dataTime
|
endTime = sData[i].last().dataTime
|
provinceName = address.province
|
cityCode = address.citycode
|
districtCode = address.adcode
|
districtName = address.district
|
townCode = address.towncode
|
towmName = address.township
|
street = address.street
|
})
|
}
|
// 结果入库
|
segmentInfoRep.insert(segmentInfoList)
|
}
|
}
|