From b7ad984df43f95251375984516e7b0760dcd15cd Mon Sep 17 00:00:00 2001
From: riku <risaku@163.com>
Date: 星期三, 17 十一月 2021 16:01:50 +0800
Subject: [PATCH] 1. 新增网格化数据优化逻辑

---
 src/main/kotlin/com/flightfeather/uav/lightshare/service/impl/RealTimeDataServiceImpl.kt |   59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 59 insertions(+), 0 deletions(-)

diff --git a/src/main/kotlin/com/flightfeather/uav/lightshare/service/impl/RealTimeDataServiceImpl.kt b/src/main/kotlin/com/flightfeather/uav/lightshare/service/impl/RealTimeDataServiceImpl.kt
index 48aff07..ae0a015 100644
--- a/src/main/kotlin/com/flightfeather/uav/lightshare/service/impl/RealTimeDataServiceImpl.kt
+++ b/src/main/kotlin/com/flightfeather/uav/lightshare/service/impl/RealTimeDataServiceImpl.kt
@@ -1,5 +1,6 @@
 package com.flightfeather.uav.lightshare.service.impl
 
+import com.flightfeather.uav.common.scaleMap
 import com.flightfeather.uav.common.utils.DateUtil
 import com.flightfeather.uav.common.utils.ExcelUtil
 import com.flightfeather.uav.common.utils.FileExchange
@@ -15,12 +16,14 @@
 import com.flightfeather.uav.socket.eunm.UWDeviceType
 import com.github.pagehelper.PageHelper
 import org.apache.poi.xssf.streaming.SXSSFWorkbook
+import org.springframework.beans.BeanUtils
 import org.springframework.stereotype.Service
 import org.springframework.web.multipart.MultipartFile
 import tk.mybatis.mapper.entity.Example
 import java.io.ByteArrayInputStream
 import java.text.SimpleDateFormat
 import java.time.LocalDateTime
+import java.time.ZoneId
 import java.time.format.DateTimeFormatter
 import java.util.*
 import javax.servlet.http.HttpServletResponse
@@ -33,6 +36,7 @@
     private val realTimeDataVehicleMapper: RealTimeDataVehicleMapper,
     private val realTimeDataUavMapper: RealTimeDataUavMapper,
     private val realTimeDataGridMapper: RealTimeDataGridMapper,
+    private val realTimeDataGridOptMapper: RealTimeDataGridOptMapper,
     private val realTimeDataGridMinMapper: RealTimeDataGridMinMapper
 ) : RealTimeDataService {
 
@@ -317,4 +321,59 @@
 
         return BaseResponse(count > 0, data = "鎻掑叆鏁版嵁: ${count}鏉�")
     }
+
+    override fun dataCalibration(): BaseResponse<String> {
+        var page = 1
+        var total = -1
+        var count = 0
+        val sT = "2021-06-19 00:00:00"
+        val eT = "2021-10-21 00:00:00"
+
+        println("------鏁版嵁浼樺寲start------")
+        while (total == -1 || page <= total) {
+            // 棰勫鐞嗗悗鐨勭綉鏍煎寲鏁版嵁
+            val p = PageHelper.startPage<RealTimeDataGrid>(page, 50000)
+            val dataList1 = realTimeDataGridMapper.selectByExample(Example(RealTimeDataGrid::class.java).apply {
+                createCriteria().andBetween("dataTime", sT, eT)
+            })
+            // 鍘熷鏁版嵁锛圚2S锛�
+            val res = getOriginData("0d0000000001", sT, eT, page, 50000)
+            val dataList2 = res.data ?: emptyList()
+
+            total = p.pages
+
+            if (page == 1) {
+                println("鎬婚〉鏁帮細$total")
+            }
+            println("褰撳墠椤垫暟锛�$page")
+
+            for (i in dataList1.indices) {
+                if (i >= dataList2.size) break
+                val d1 = dataList1[i]
+                val d2 = dataList2[i]
+                // 鍒ゆ柇灏忔椂锛岃幏鍙栧搴旀椂娈电殑浼樺寲绯绘暟
+                val h = LocalDateTime.ofInstant(d1.dataTime?.toInstant(), ZoneId.systemDefault()).hour
+                val scaleList = scaleMap[h] ?: continue
+                d1.apply {
+                    // 鍚勯澶勭悊鍚庣殑鍥犲瓙锛堥櫎H2S锛変箻绯绘暟
+                    no2 = no2?.times(scaleList[0])
+                    co = co?.times(scaleList[1])
+                    so2 = so2?.times(scaleList[3])
+                    o3 = o3?.times(scaleList[4])
+                    voc = voc?.times(scaleList[7])
+
+                    // 鍗曠嫭鎶婂師濮嬬殑H2S涔樹互绯绘暟
+                    h2s = d2.values?.get(2)?.factorData?.toFloat()?.times(scaleList[2])
+                }
+
+                // 鏇存柊绉掔骇鍊�
+                val opt = RealTimeDataGridOpt()
+                BeanUtils.copyProperties(d1, opt)
+                count += realTimeDataGridOptMapper.insert(opt)
+            }
+            page++
+        }
+
+        return BaseResponse(count > 0, data = "鎻掑叆鏁版嵁: ${count}鏉�")
+    }
 }
\ No newline at end of file

--
Gitblit v1.9.3