From 0ddfab15b32dc054464d75c695999fa76c3b9b78 Mon Sep 17 00:00:00 2001
From: feiyu02 <risaku@163.com>
Date: 星期五, 03 一月 2025 17:33:50 +0800
Subject: [PATCH] 1. 卫星遥测数据的融合

---
 src/main/kotlin/com/flightfeather/uav/lightshare/service/impl/SatelliteTelemetryServiceImpl.kt |   30 ++++++++++++++++++++++++++++--
 1 files changed, 28 insertions(+), 2 deletions(-)

diff --git a/src/main/kotlin/com/flightfeather/uav/lightshare/service/impl/SatelliteTelemetryServiceImpl.kt b/src/main/kotlin/com/flightfeather/uav/lightshare/service/impl/SatelliteTelemetryServiceImpl.kt
index db1be82..97e4c67 100644
--- a/src/main/kotlin/com/flightfeather/uav/lightshare/service/impl/SatelliteTelemetryServiceImpl.kt
+++ b/src/main/kotlin/com/flightfeather/uav/lightshare/service/impl/SatelliteTelemetryServiceImpl.kt
@@ -1,5 +1,6 @@
 package com.flightfeather.uav.lightshare.service.impl
 
+import com.flightfeather.uav.biz.satellite.SatelliteDataMix
 import com.flightfeather.uav.common.exception.BizException
 import com.flightfeather.uav.common.utils.FileExchange
 import com.flightfeather.uav.domain.entity.GridAod
@@ -14,6 +15,7 @@
 import com.flightfeather.uav.lightshare.service.SatelliteTelemetryService
 import com.github.pagehelper.PageHelper
 import org.springframework.stereotype.Service
+import org.springframework.transaction.annotation.Transactional
 import org.springframework.web.multipart.MultipartFile
 import java.io.ByteArrayInputStream
 import java.io.File
@@ -21,6 +23,7 @@
 import java.time.ZoneId
 import java.util.*
 import javax.servlet.http.HttpServletResponse
+import kotlin.math.round
 
 /**
  *
@@ -28,7 +31,10 @@
  * @author feiyu02
  */
 @Service
-class SatelliteTelemetryServiceImpl(private val satelliteGridRep: SatelliteGridRep) : SatelliteTelemetryService {
+class SatelliteTelemetryServiceImpl(
+    private val satelliteGridRep: SatelliteGridRep,
+    private val satelliteDataMix: SatelliteDataMix,
+) : SatelliteTelemetryService {
 
     private val fileExchange = FileExchange()
     override fun fetchGridGroup(areaVo: AreaVo, page: Int?, perPage: Int?): Pair<DataHead, List<GridGroup?>> {
@@ -50,7 +56,27 @@
     }
 
     override fun fetchGridDataDetail(dataId: Int, groupId: Int?, cellId: Int?): List<GridDataDetail?> {
-        return satelliteGridRep.fetchGridDataDetail(dataId, groupId, cellId)
+        val res =  satelliteGridRep.fetchGridDataDetail(dataId, groupId, cellId)
+        res.forEach {
+            if (it?.pm25 != null) {
+                it.pm25 = round(it.pm25 * 100) / 100
+            }
+        }
+        return res
+    }
+
+    @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(",")
+        })
+        // 2. 鑻ヨ瀺鍚堟暟鎹凡瀛樺湪锛岀洿鎺ヨ繑鍥�
+        return exist.ifEmpty {
+            listOf(satelliteDataMix.mixData(dataIdList).first)
+        }
     }
 
     override fun importGridData(groupId: Int, dataTime: LocalDateTime?, update: Boolean, file: MultipartFile): GridDataImportResult? {

--
Gitblit v1.9.3