From 01ac08186355e85cab4a7c6f4403180184894f23 Mon Sep 17 00:00:00 2001
From: riku <risaku@163.com>
Date: 星期六, 09 十月 2021 14:38:44 +0800
Subject: [PATCH] 1. 新增网格化数据统计功能

---
 src/test/kotlin/com/flightfeather/uav/model/epw/EPWDataPrepTest.kt |   75 +++++++++++++++++++++++++++++++++++++
 1 files changed, 74 insertions(+), 1 deletions(-)

diff --git a/src/test/kotlin/com/flightfeather/uav/model/epw/EPWDataPrepTest.kt b/src/test/kotlin/com/flightfeather/uav/model/epw/EPWDataPrepTest.kt
index c060c14..5b8301e 100644
--- a/src/test/kotlin/com/flightfeather/uav/model/epw/EPWDataPrepTest.kt
+++ b/src/test/kotlin/com/flightfeather/uav/model/epw/EPWDataPrepTest.kt
@@ -5,6 +5,8 @@
 import com.flightfeather.uav.lightshare.bean.DataVo
 import com.flightfeather.uav.lightshare.service.RealTimeDataService
 import org.apache.poi.hssf.usermodel.HSSFWorkbook
+import org.apache.poi.xssf.streaming.SXSSFWorkbook
+import org.apache.poi.xssf.usermodel.XSSFWorkbook
 import org.junit.Assert.*
 import org.junit.Test
 import org.junit.runner.RunWith
@@ -12,7 +14,10 @@
 import org.springframework.boot.test.context.SpringBootTest
 import org.springframework.test.context.junit4.SpringRunner
 import java.io.File
+import java.io.FileInputStream
 import java.io.FileOutputStream
+import java.time.LocalDateTime
+import java.time.format.DateTimeFormatter
 import java.util.*
 
 @RunWith(SpringRunner::class)
@@ -81,7 +86,7 @@
             }
 
             if (dataList.isNotEmpty()) {
-                val workbook = HSSFWorkbook()
+                val workbook = SXSSFWorkbook()
                 val heads = mutableListOf<Array<String>>()
                 heads.add(dataList[0].toRowTitle())
                 val contents = mutableListOf<Array<Any>>()
@@ -100,4 +105,72 @@
             }
         }
     }
+
+    @Test
+    fun foo2() {
+        var fileName = "缃戞牸鍖栫洃娴嬮澶勭悊杩炵画鏁版嵁${Date().time}.xls"
+        var filePath = "C:\\work\\宸ヤ綔\\璧拌埅鐩戞祴\\棰勫鐞嗚繛缁暟鎹甛\$fileName"
+        var workBook = SXSSFWorkbook(1000)
+        var out: FileOutputStream
+        var input: FileInputStream
+        var row = 0
+        val maxRow = 100000
+        var hasHead = false
+
+        val ePWDataPrep = EPWDataPrep()
+
+        val endDateTime = LocalDateTime.now()
+        var sTime = LocalDateTime.of(2021, 6, 19, 0, 0, 0)
+        var eTime = LocalDateTime.of(2021, 6, 19, 23, 59, 59)
+
+        while (sTime.isBefore(endDateTime)) {
+            val deviceCode = "0d0000000001"
+            val dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")
+            val s = sTime.format(dateFormatter)
+            val e = eTime.format(dateFormatter)
+            val data = realTimeDataService.getSecondData(deviceCode, s, e, 1, 30000).data
+
+            data?.let {
+                val dataList = ePWDataPrep.mDataPrep(it)
+
+                if (row + dataList.size > maxRow) {
+                    fileName = "缃戞牸鍖栫洃娴嬮澶勭悊杩炵画鏁版嵁${Date().time}.xls"
+                    filePath = "C:\\work\\宸ヤ綔\\璧拌埅鐩戞祴\\棰勫鐞嗚繛缁暟鎹甛\$fileName"
+                    workBook = SXSSFWorkbook(1000)
+                    row = 0
+                    hasHead = false
+                }
+
+                if (!hasHead) {
+                    out = FileOutputStream(filePath)
+                    val heads = mutableListOf<Array<String>>()
+                    heads.add(dataList[0].toRowTitle())
+                    row = ExcelUtil.write(heads, emptyList(), workBook, row = row)
+                    workBook.write(out)
+                    workBook.close()
+                    out.flush()
+                    out.close()
+                    hasHead = true
+                }
+
+                input = FileInputStream(filePath)
+                workBook = SXSSFWorkbook(XSSFWorkbook(input), 1000)
+                out = FileOutputStream(filePath)
+
+                val contents = mutableListOf<Array<Any>>()
+                dataList.forEach {d ->
+                    contents.add(d.toRowContent())
+                }
+                row = ExcelUtil.write(emptyList(), contents, workBook, row = row)
+
+                workBook.write(out)
+                workBook.close()
+                input.close()
+                out.flush()
+                out.close()
+            }
+            sTime = sTime.plusDays(1)
+            eTime = eTime.plusDays(1)
+        }
+    }
 }
\ No newline at end of file

--
Gitblit v1.9.3