feiyu02
2025-03-07 db447bb757b51f8d03e62d6ae4f183b4608723ef
src/main/kotlin/com/flightfeather/uav/lightshare/service/impl/SatelliteTelemetryServiceImpl.kt
@@ -4,15 +4,12 @@
import com.flightfeather.uav.biz.satellite.SatelliteGridManage
import com.flightfeather.uav.common.exception.BizException
import com.flightfeather.uav.common.utils.FileExchange
import com.flightfeather.uav.domain.entity.GridAod
import com.flightfeather.uav.domain.entity.GridCell
import com.flightfeather.uav.domain.entity.GridData
import com.flightfeather.uav.domain.entity.GridDataDetail
import com.flightfeather.uav.domain.entity.GridGroup
import com.flightfeather.uav.domain.entity.*
import com.flightfeather.uav.domain.repository.SatelliteGridRep
import com.flightfeather.uav.lightshare.bean.AreaVo
import com.flightfeather.uav.lightshare.bean.DataHead
import com.flightfeather.uav.lightshare.bean.GridDataImportResult
import com.flightfeather.uav.lightshare.eunm.SatelliteDataType
import com.flightfeather.uav.lightshare.service.SatelliteTelemetryService
import com.github.pagehelper.PageHelper
import org.springframework.stereotype.Service
@@ -38,10 +35,15 @@
) : SatelliteTelemetryService {
    private val fileExchange = FileExchange()
    override fun fetchGridGroup(areaVo: AreaVo, page: Int?, perPage: Int?): Pair<DataHead, List<GridGroup?>> {
    override fun fetchGridGroup(areaVo: AreaVo, type: String?, page: Int?, perPage: Int?): Pair<DataHead,
            List<GridGroup?>> {
        val pageInfo = PageHelper.startPage<GridGroup>(page ?: 1, perPage ?: 100)
        val res = satelliteGridRep.fetchGridGroup(areaVo)
        val res = satelliteGridRep.fetchGridGroup(areaVo, type)
        return DataHead(pageInfo.pageNum, pageInfo.pages) to res
    }
    override fun deleteGridGroup(groupId: Int) {
        satelliteGridRep.deleteGridGroup(groupId)
    }
    override fun fetchGridCell(groupId: Int): List<GridCell?> {
@@ -50,10 +52,6 @@
    override fun fetchGridData(groupId: Int, dataTime: LocalDateTime?, type: Int?): List<GridData?> {
        return satelliteGridRep.fetchGridData(groupId, dataTime, type)
    }
    override fun fetchGridAod(groupId: Int, dataTime: LocalDateTime?): List<GridAod?> {
        return satelliteGridRep.fetchGridAod(groupId, dataTime)
    }
    override fun fetchGridDataDetail(dataId: Int, groupId: Int?, cellId: Int?): List<GridDataDetail?> {
@@ -67,12 +65,44 @@
    }
    @Transactional
    override fun createGridDataAndDataDetail(
        groupId: Int,
        dataTime: LocalDateTime?,
        gridDataDetail: List<GridDataDetail>,
    ): Boolean {
        // 保存拟合的卫星遥测数据 type始终为0
        val type = SatelliteDataType.Original.value
        // 查找是否有历史记录
        val gridData = satelliteGridRep.fetchGridData(groupId, dataTime, type)
        // 无历史记录则创建数据索引GridData,之后再存入拟合的数据
        if (gridData.isEmpty()) {
            val gridDataEntity = GridData()
            gridDataEntity.groupId = groupId
            gridDataEntity.dataTime = dataTime?.atZone(ZoneId.systemDefault())?.toInstant()?.toEpochMilli()
                ?.let { Date(it) }
            gridDataEntity.type = type.toByte()
            satelliteGridRep.insertGridDataAndDetail(gridDataEntity, gridDataDetail)
        }
        // 更新历史数据
        else {
            gridDataDetail.forEach {
                it.dataId = gridData[0]?.id
                it.groupId = gridData[0]?.groupId
            }
            satelliteGridRep.updatePM25Batch(gridDataDetail)
        }
        return true
    }
    @Transactional
    override fun mixGridData(dataIdList: List<Int>): List<GridData?> {
        if (dataIdList.isEmpty()) throw BizException("融合所需数据id不能为空")
        // 1. 根据数据主键id数组,查询该组合下是否已有数据融合记录
        val exist = satelliteGridRep.fetchGridData(GridData().apply {
            type = 1
            mixDataId = dataIdList.joinToString(",")
            mixDataId = dataIdList.sorted().joinToString(",")
        })
        // 2. 若融合数据已存在,直接返回
        return exist.ifEmpty {
@@ -234,4 +264,12 @@
        return cellList
    }
    override fun fetchGridAod(groupId: Int, dataTime: LocalDateTime?): List<GridAod?> {
        return satelliteGridRep.fetchGridAod(groupId, dataTime)
    }
    override fun fetchGridAODDetail(aodId: Int, groupId: Int?, cellId: Int?): List<GridAodDetail?> {
        return satelliteGridRep.fetchGridAodDetail(aodId, groupId, cellId)
    }
}