From 1fa0e57df26dcbf9f7c936806b5f4f0744e1d543 Mon Sep 17 00:00:00 2001
From: riku <risaku@163.com>
Date: 星期一, 15 十一月 2021 17:42:01 +0800
Subject: [PATCH] 1. 网格化数据查询添加秒级值和分钟值的选择

---
 src/test/kotlin/com/flightfeather/uav/model/epw/EPWDataPrepTest.kt |   79 ++++++++++++++++++++++++++++++++++++++-
 1 files changed, 76 insertions(+), 3 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..69db2a2 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)
@@ -65,12 +70,12 @@
             var totalPage = -1
             val dataList = mutableListOf<DataVo>()
             while (totalPage == -1 || page <= totalPage) {
-                realTimeDataService.getSecondData(deviceCode, it.first, it.second, page, 50000).apply {
+                realTimeDataService.getSecondData(deviceCode, it.first, it.second, 0, page, 50000).apply {
                     if (totalPage == -1) {
                         totalPage = head?.totalPage ?: 0
                     }
 
-                    val list = data?: emptyList()
+                    val list = data ?: emptyList()
 
                     val prepList = prep.mDataPrep(list)
 
@@ -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, 0, 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