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/resources/generator/generatorConfig.xml                                             |    3 
 src/main/kotlin/com/flightfeather/uav/common/Contanst.kt                                     |   33 ++++++++++
 src/main/kotlin/com/flightfeather/uav/domain/mapper/RealTimeDataGridOptMapper.kt             |    8 ++
 src/main/resources/mapper/RealTimeDataGridOptMapper.xml                                      |   39 +++++++++++++
 src/test/kotlin/com/flightfeather/uav/lightshare/service/impl/RealTimeDataServiceImplTest.kt |    6 ++
 src/main/kotlin/com/flightfeather/uav/domain/entity/RealTimeDataGridOpt.java                 |   10 +++
 src/main/kotlin/com/flightfeather/uav/lightshare/service/impl/RealTimeDataServiceImpl.kt     |   37 +++++++++---
 7 files changed, 124 insertions(+), 12 deletions(-)

diff --git a/src/main/kotlin/com/flightfeather/uav/common/Contanst.kt b/src/main/kotlin/com/flightfeather/uav/common/Contanst.kt
index 6321329..8db1652 100644
--- a/src/main/kotlin/com/flightfeather/uav/common/Contanst.kt
+++ b/src/main/kotlin/com/flightfeather/uav/common/Contanst.kt
@@ -6,4 +6,35 @@
  */
 //鍓嶇璁惧浼犺緭鐨勬棤鏁堝��
 const val INVALID_DATA_4_BYTE = "FFFFFFFF"
-const val INVALID_DATA_2_BYTE = "FFFF"
\ No newline at end of file
+const val INVALID_DATA_2_BYTE = "FFFF"
+
+/**
+ * 2021-11-17 缃戞牸鍖栫洃娴嬪洜瀛愪紭鍖栫郴鏁帮紙鍩轰簬棰勫鐞嗘暟鎹級
+ */
+val scaleMap = mutableMapOf<Int, List<Float>>().apply {
+    //  hour       NO2	         CO	           H2S	         SO2	       O3	         PM25  PM10  VOC
+    put(0 , listOf(1.260820655f, 1.216667552f, 1.125932298f, 1.156929588f, 0.856318541f, 1.0f, 1.0f, 1.019853828f))
+    put(1 , listOf(1.216383597f, 1.227863417f, 1.136368119f, 1.150858195f, 0.864118430f, 1.0f, 1.0f, 1.021218796f))
+    put(2 , listOf(1.210361269f, 1.227450386f, 1.150780492f, 1.168038461f, 0.865243847f, 1.0f, 1.0f, 1.020880802f))
+    put(3 , listOf(1.163439204f, 1.189908110f, 1.235243547f, 1.211935503f, 0.874802600f, 1.0f, 1.0f, 1.021633591f))
+    put(4 , listOf(1.170443945f, 1.177190080f, 1.233442915f, 1.216684222f, 0.873063632f, 1.0f, 1.0f, 1.022230877f))
+    put(5 , listOf(1.258022303f, 1.128902342f, 1.326003848f, 1.263151458f, 0.856416663f, 1.0f, 1.0f, 1.022758145f))
+    put(6 , listOf(1.403632463f, 1.018045753f, 1.348386592f, 1.424135126f, 0.833216869f, 1.0f, 1.0f, 1.018346466f))
+    put(7 , listOf(1.122379332f, 0.921730659f, 1.413365730f, 1.469299523f, 0.884801243f, 1.0f, 1.0f, 1.004337859f))
+    put(8 , listOf(0.713145787f, 0.891658820f, 1.254278025f, 1.275998356f, 1.031824600f, 1.0f, 1.0f, 0.988160256f))
+    put(9 , listOf(0.523493283f, 0.840459016f, 1.136001943f, 0.992222358f, 1.180035037f, 1.0f, 1.0f, 0.977086373f))
+    put(10, listOf(0.436882489f, 0.785553638f, 0.902852651f, 0.745412781f, 1.295137300f, 1.0f, 1.0f, 0.969271259f))
+    put(11, listOf(0.385539681f, 0.788473715f, 0.810406932f, 0.585739873f, 1.390259619f, 1.0f, 1.0f, 0.965946441f))
+    put(12, listOf(0.378202225f, 0.766903352f, 0.882086383f, 0.502122477f, 1.409121756f, 1.0f, 1.0f, 0.963580572f))
+    put(13, listOf(0.393040546f, 0.728230590f, 0.782751681f, 0.438597765f, 1.378133348f, 1.0f, 1.0f, 0.963818142f))
+    put(14, listOf(0.434686411f, 0.772791882f, 0.642479738f, 0.443393658f, 1.301282617f, 1.0f, 1.0f, 0.968305562f))
+    put(15, listOf(0.522808107f, 0.831631952f, 0.557282786f, 0.554966933f, 1.182584786f, 1.0f, 1.0f, 0.977440538f))
+    put(16, listOf(0.727836191f, 0.889160481f, 0.594713483f, 0.832742429f, 1.024609679f, 1.0f, 1.0f, 0.990246259f))
+    put(17, listOf(1.028024212f, 0.938403996f, 0.671609876f, 1.070428218f, 0.911547286f, 1.0f, 1.0f, 0.999249061f))
+    put(18, listOf(1.330053971f, 1.016668065f, 0.743443154f, 1.095625581f, 0.847713841f, 1.0f, 1.0f, 1.006336597f))
+    put(19, listOf(1.630871928f, 1.071485305f, 0.933527520f, 1.040253374f, 0.806748833f, 1.0f, 1.0f, 1.011638015f))
+    put(20, listOf(1.559280145f, 1.092548718f, 1.022834535f, 1.079664302f, 0.815339533f, 1.0f, 1.0f, 1.014308338f))
+    put(21, listOf(1.460621712f, 1.131760740f, 1.121104299f, 1.088876154f, 0.827697109f, 1.0f, 1.0f, 1.015988031f))
+    put(22, listOf(1.357157189f, 1.155444400f, 1.184586476f, 1.085940877f, 0.841801847f, 1.0f, 1.0f, 1.018320115f))
+    put(23, listOf(1.312873355f, 1.191067031f, 1.189618093f, 1.106982786f, 0.848180982f, 1.0f, 1.0f, 1.019044077f))
+}
\ No newline at end of file
diff --git a/src/main/kotlin/com/flightfeather/uav/domain/entity/RealTimeDataGridOpt.java b/src/main/kotlin/com/flightfeather/uav/domain/entity/RealTimeDataGridOpt.java
new file mode 100644
index 0000000..8a7642a
--- /dev/null
+++ b/src/main/kotlin/com/flightfeather/uav/domain/entity/RealTimeDataGridOpt.java
@@ -0,0 +1,10 @@
+package com.flightfeather.uav.domain.entity;
+
+import java.math.BigDecimal;
+import java.util.Date;
+import javax.persistence.*;
+
+@Table(name = "real_time_data_grid_opt")
+public class RealTimeDataGridOpt extends BaseRealTimeData {
+
+}
\ No newline at end of file
diff --git a/src/main/kotlin/com/flightfeather/uav/domain/mapper/RealTimeDataGridOptMapper.kt b/src/main/kotlin/com/flightfeather/uav/domain/mapper/RealTimeDataGridOptMapper.kt
new file mode 100644
index 0000000..1e640ba
--- /dev/null
+++ b/src/main/kotlin/com/flightfeather/uav/domain/mapper/RealTimeDataGridOptMapper.kt
@@ -0,0 +1,8 @@
+package com.flightfeather.uav.domain.mapper
+
+import com.flightfeather.uav.domain.MyMapper
+import com.flightfeather.uav.domain.entity.RealTimeDataGridOpt
+import org.apache.ibatis.annotations.Mapper
+
+@Mapper
+interface RealTimeDataGridOptMapper : MyMapper<RealTimeDataGridOpt?>
\ No newline at end of file
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 30e9a0b..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,6 +16,7 @@
 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
@@ -34,6 +36,7 @@
     private val realTimeDataVehicleMapper: RealTimeDataVehicleMapper,
     private val realTimeDataUavMapper: RealTimeDataUavMapper,
     private val realTimeDataGridMapper: RealTimeDataGridMapper,
+    private val realTimeDataGridOptMapper: RealTimeDataGridOptMapper,
     private val realTimeDataGridMinMapper: RealTimeDataGridMinMapper
 ) : RealTimeDataService {
 
@@ -323,14 +326,18 @@
         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", "2021-06-19 00:00:00", "2021-10-21 00:00:00")
+                createCriteria().andBetween("dataTime", sT, eT)
             })
-            val res = getOriginData("0d0000000001", "2021-06-19 00:00:00", "2021-10-21 00:00:00", page, 50000)
+            // 鍘熷鏁版嵁锛圚2S锛�
+            val res = getOriginData("0d0000000001", sT, eT, page, 50000)
             val dataList2 = res.data ?: emptyList()
 
             total = p.pages
@@ -344,16 +351,26 @@
                 if (i >= dataList2.size) break
                 val d1 = dataList1[i]
                 val d2 = dataList2[i]
-                // 鍒ゆ柇灏忔椂
+                // 鍒ゆ柇灏忔椂锛岃幏鍙栧搴旀椂娈电殑浼樺寲绯绘暟
                 val h = LocalDateTime.ofInstant(d1.dataTime?.toInstant(), ZoneId.systemDefault()).hour
-                val scale =
-                // 鍚勯澶勭悊鍚庣殑鍥犲瓙锛堥櫎H2S锛変箻绯绘暟
-                // 鍗曠嫭鎶婂師濮嬬殑H2S涔樹互绯绘暟
-                // 鏇存柊绉掔骇鍊�
-            }
-//            val result = epwDataPrep.mDataPrep2(dataList)
-//            count += airDataRepository.savePrepData2(result)
+                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++
         }
 
diff --git a/src/main/resources/generator/generatorConfig.xml b/src/main/resources/generator/generatorConfig.xml
index 0f54203..258b953 100644
--- a/src/main/resources/generator/generatorConfig.xml
+++ b/src/main/resources/generator/generatorConfig.xml
@@ -48,7 +48,7 @@
 <!--        <table tableName="air_real_time_data" domainObjectName="RealTimeData" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"/>-->
 <!--        <table tableName="mission" domainObjectName="Mission" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"/>-->
 <!--        <table tableName="el_minutevalue" domainObjectName="ElectricMinuteValue" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"/>-->
-        <table tableName="el_company_device" domainObjectName="CompanyDevice" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"/>
+<!--        <table tableName="el_company_device" domainObjectName="CompanyDevice" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"/>-->
 <!--        <table tableName="co_complaint" domainObjectName="Complaint" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"/>-->
 <!--        <table tableName="co_assessment" domainObjectName="Assessment" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"/>-->
 <!--        <table tableName="real_time_data_grid" domainObjectName="RealTimeDataGrid" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"/>-->
@@ -57,5 +57,6 @@
 <!--        <table tableName="device_info" domainObjectName="DeviceInfo" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"/>-->
 <!--        <table tableName="factor_calibration" domainObjectName="FactorCalibration" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"/>-->
 <!--        <table tableName="real_time_data_grid_min" domainObjectName="RealTimeDataGridMin" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"/>-->
+        <table tableName="real_time_data_grid_opt" domainObjectName="RealTimeDataGridOpt" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"/>
     </context>
 </generatorConfiguration>
\ No newline at end of file
diff --git a/src/main/resources/mapper/RealTimeDataGridOptMapper.xml b/src/main/resources/mapper/RealTimeDataGridOptMapper.xml
new file mode 100644
index 0000000..88eec71
--- /dev/null
+++ b/src/main/resources/mapper/RealTimeDataGridOptMapper.xml
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.flightfeather.uav.domain.mapper.RealTimeDataGridOptMapper">
+  <resultMap id="BaseResultMap" type="com.flightfeather.uav.domain.entity.RealTimeDataGridOpt">
+    <!--
+      WARNING - @mbg.generated
+    -->
+    <id column="id" jdbcType="INTEGER" property="id" />
+    <result column="device_code" jdbcType="VARCHAR" property="deviceCode" />
+    <result column="latitude" jdbcType="DECIMAL" property="latitude" />
+    <result column="longitude" jdbcType="DECIMAL" property="longitude" />
+    <result column="altitude" jdbcType="REAL" property="altitude" />
+    <result column="data_time" jdbcType="TIMESTAMP" property="dataTime" />
+    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
+    <result column="NO2" jdbcType="REAL" property="no2" />
+    <result column="CO" jdbcType="REAL" property="co" />
+    <result column="H2S" jdbcType="REAL" property="h2s" />
+    <result column="SO2" jdbcType="REAL" property="so2" />
+    <result column="O3" jdbcType="REAL" property="o3" />
+    <result column="PM25" jdbcType="REAL" property="pm25" />
+    <result column="PM10" jdbcType="REAL" property="pm10" />
+    <result column="temperature" jdbcType="REAL" property="temperature" />
+    <result column="humidity" jdbcType="REAL" property="humidity" />
+    <result column="VOC" jdbcType="REAL" property="voc" />
+    <result column="NOI" jdbcType="REAL" property="noi" />
+    <result column="velocity" jdbcType="REAL" property="velocity" />
+    <result column="wind_speed" jdbcType="REAL" property="windSpeed" />
+    <result column="wind_direction" jdbcType="REAL" property="windDirection" />
+    <result column="height" jdbcType="REAL" property="height" />
+  </resultMap>
+  <sql id="Base_Column_List">
+    <!--
+      WARNING - @mbg.generated
+    -->
+    id, device_code, latitude, longitude, altitude, data_time, create_time, NO2, CO, 
+    H2S, SO2, O3, PM25, PM10, temperature, humidity, VOC, NOI, velocity, wind_speed, 
+    wind_direction, height
+  </sql>
+</mapper>
\ No newline at end of file
diff --git a/src/test/kotlin/com/flightfeather/uav/lightshare/service/impl/RealTimeDataServiceImplTest.kt b/src/test/kotlin/com/flightfeather/uav/lightshare/service/impl/RealTimeDataServiceImplTest.kt
index 9060825..e306742 100644
--- a/src/test/kotlin/com/flightfeather/uav/lightshare/service/impl/RealTimeDataServiceImplTest.kt
+++ b/src/test/kotlin/com/flightfeather/uav/lightshare/service/impl/RealTimeDataServiceImplTest.kt
@@ -131,4 +131,10 @@
         val r = realTimeDataService.averageData()
         println(r.data)
     }
+
+    @Test
+    fun dataCalibration() {
+        val r = realTimeDataService.dataCalibration()
+        println(r.data)
+    }
 }
\ No newline at end of file

--
Gitblit v1.9.3