From 83455446544f89b0663a3f520744331ad8259289 Mon Sep 17 00:00:00 2001
From: feiyu02 <risaku@163.com>
Date: 星期五, 02 二月 2024 17:49:43 +0800
Subject: [PATCH] 1. 新增导入静安监测数据功能模块

---
 src/main/kotlin/com/flightfeather/uav/common/utils/FileExchange.kt |   84 +++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 82 insertions(+), 2 deletions(-)

diff --git a/src/main/kotlin/com/flightfeather/uav/common/utils/FileExchange.kt b/src/main/kotlin/com/flightfeather/uav/common/utils/FileExchange.kt
index 380b3dd..c2cde2f 100644
--- a/src/main/kotlin/com/flightfeather/uav/common/utils/FileExchange.kt
+++ b/src/main/kotlin/com/flightfeather/uav/common/utils/FileExchange.kt
@@ -1,7 +1,9 @@
 package com.flightfeather.uav.common.utils
 
 import com.alibaba.fastjson.JSONObject
+import com.flightfeather.uav.common.exception.ResponseErrorException
 import com.flightfeather.uav.domain.entity.RealTimeData
+import com.flightfeather.uav.domain.entity.RealTimeDataVehicle
 import com.flightfeather.uav.socket.bean.AirData
 import org.apache.poi.hssf.usermodel.HSSFWorkbook
 import org.apache.poi.xssf.streaming.SXSSFWorkbook
@@ -13,7 +15,7 @@
 import java.util.*
 
 /**
- * 鏃犱汉鑸归噰闆嗘暟鎹牸寮忚浆鎹�
+ * 閲囬泦鏁版嵁鏍煎紡杞崲
  */
 class FileExchange {
 
@@ -27,6 +29,76 @@
         private val format = SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
     }
 
+    fun exchangeJinanData(deviceCode: String, file: InputStream): List<RealTimeDataVehicle> {
+        val headers = listOf(
+            "data_time",
+            "longitude",
+            "latitude",
+            "NO2",
+            "CO",
+            "H2S",
+            "SO2",
+            "O3",
+            "PM25",
+            "PM10",
+            "temperature",
+            "humidity",
+            "VOC",
+            "NOI",
+            "velocity",
+            "wind_speed",
+            "wind_direction"
+        )
+        val result = mutableListOf<RealTimeDataVehicle>()
+        try {
+            ExcelUtil.read(file, headerCheck = {
+                val cellIterator = it.cellIterator()
+                val headIterator = headers.iterator()
+                while (headIterator.hasNext()) {
+                    val head = headIterator.next()
+                    if (cellIterator.hasNext()) {
+                        val cellText = cellIterator.next().stringCellValue
+                        if (!cellText.equals(head)) {
+                            throw ResponseErrorException("鏂囦欢鏍煎紡閿欒, 琛ㄥご[${head}]搴旇涓篬${cellText}]")
+                        }
+                    } else {
+                        throw ResponseErrorException("鏂囦欢鏍煎紡閿欒, 琛ㄥご[${head}]缂哄け")
+                    }
+                }
+                true
+            }, onRow = {
+                val data = RealTimeDataVehicle().apply {
+                    this.deviceCode = deviceCode
+                    dataTime = it.getCell(0).dateCellValue
+                    longitude = it.getCell(1).numericCellValue.toBigDecimal()
+                    latitude = it.getCell(2).numericCellValue.toBigDecimal()
+                    no2 = it.getCell(3).numericCellValue.toFloat()
+                    co = it.getCell(4).numericCellValue.toFloat()
+                    h2s = it.getCell(5).numericCellValue.toFloat()
+                    so2 = it.getCell(6).numericCellValue.toFloat()
+                    o3 = it.getCell(7).numericCellValue.toFloat()
+                    pm25 = it.getCell(8).numericCellValue.toFloat()
+                    pm10 = it.getCell(9).numericCellValue.toFloat()
+                    temperature = it.getCell(10).numericCellValue.toFloat()
+                    humidity = it.getCell(11).numericCellValue.toFloat()
+                    voc = it.getCell(12).numericCellValue.toFloat()
+                    noi = it.getCell(13).numericCellValue.toFloat()
+                    velocity = it.getCell(14).numericCellValue.toFloat()
+                    windSpeed = it.getCell(15).numericCellValue.toFloat()
+                    windDirection = it.getCell(16).numericCellValue.toFloat()
+                }
+                result.add(data)
+            })
+        } catch (e: Exception) {
+            e.printStackTrace()
+            throw ResponseErrorException("excel鏂囦欢鍐呭閿欒锛屾暟鎹浆鎹㈠け璐ワ紒", e)
+        }
+        return result
+    }
+
+    /**
+     * 杞崲鏃犱汉鑸圭殑姘磋川鐩戞祴鏁版嵁
+     */
     fun exchangeBoatData(deviceCode: String, file: InputStream): List<RealTimeData> {
         val workbook = HSSFWorkbook(file)
         val sheet = workbook.getSheetAt(0)
@@ -205,7 +277,15 @@
         val filePath = "e:/$fileName"
         val out = FileOutputStream(File(filePath))
 
-        val heads = listOf("id", "device_code", "latitude", "longitude", "altitude", "height", "factors", "data_time", "create_time")
+        val heads = listOf("id",
+            "device_code",
+            "latitude",
+            "longitude",
+            "altitude",
+            "height",
+            "factors",
+            "data_time",
+            "create_time")
         val contents = mutableListOf<Array<Any>>()
 
         for (i in 1..sheet.lastRowNum) {

--
Gitblit v1.9.3