package com.flightfeather.uav.model.epw
|
|
import com.flightfeather.uav.common.utils.DateUtil
|
import com.flightfeather.uav.common.utils.ExcelUtil
|
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
|
import org.springframework.beans.factory.annotation.Autowired
|
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)
|
@SpringBootTest
|
class EPWDataPrepTest {
|
|
@Autowired
|
lateinit var realTimeDataService: RealTimeDataService
|
|
@Test
|
fun foo1() {
|
val timeSet = listOf(
|
// 网格化监测每日
|
// Pair("2021-06-18 15:00:00", "2021-06-18 23:59:59"),
|
// Pair("2021-06-19 00:00:00", "2021-06-19 23:59:59"),
|
// Pair("2021-06-20 00:00:00", "2021-06-20 23:59:59"),
|
// Pair("2021-06-21 00:00:00", "2021-06-21 23:59:59"),
|
// Pair("2021-06-22 00:00:00", "2021-06-22 23:59:59"),
|
// Pair("2021-06-23 00:00:00", "2021-06-23 23:59:59"),
|
// Pair("2021-06-24 00:00:00", "2021-06-24 23:59:59"),
|
// Pair("2021-06-25 00:00:00", "2021-06-25 23:59:59"),
|
// Pair("2021-06-26 00:00:00", "2021-06-26 23:59:59"),
|
// Pair("2021-06-27 00:00:00", "2021-06-27 23:59:59"),
|
// Pair("2021-06-28 00:00:00", "2021-06-28 23:59:59"),
|
// Pair("2021-06-29 00:00:00", "2021-06-29 23:59:59"),
|
// Pair("2021-06-30 00:00:00", "2021-06-30 23:59:59"),
|
// Pair("2021-07-01 00:00:00", "2021-07-01 23:59:59"),
|
// Pair("2021-07-02 00:00:00", "2021-07-02 23:59:59"),
|
// Pair("2021-07-03 00:00:00", "2021-07-03 23:59:59"),
|
// Pair("2021-07-04 00:00:00", "2021-07-04 23:59:59"),
|
// Pair("2021-07-05 00:00:00", "2021-07-05 23:59:59"),
|
// Pair("2021-07-06 00:00:00", "2021-07-06 23:59:59"),
|
// Pair("2021-07-07 00:00:00", "2021-07-07 23:59:59"),
|
Pair("2021-07-08 00:00:00", "2021-07-08 23:59:59"),
|
Pair("2021-07-09 00:00:00", "2021-07-09 23:59:59"),
|
Pair("2021-07-10 00:00:00", "2021-07-10 23:59:59"),
|
Pair("2021-07-11 00:00:00", "2021-07-11 23:59:59"),
|
Pair("2021-07-12 00:00:00", "2021-07-12 23:59:59"),
|
Pair("2021-07-13 00:00:00", "2021-07-13 23:59:59"),
|
|
// Pair("2021-06-18 15:00:00", "2021-07-13 23:59:59"),
|
)
|
|
val prep = EPWDataPrep()
|
val deviceCode = "0d0000000001"
|
|
for (i in timeSet.indices) {
|
val it = timeSet[i]
|
var page = 1
|
var totalPage = -1
|
val dataList = mutableListOf<DataVo>()
|
while (totalPage == -1 || page <= totalPage) {
|
realTimeDataService.getSecondData(deviceCode, it.first, it.second, 0, page, 50000).apply {
|
if (totalPage == -1) {
|
totalPage = head?.totalPage ?: 0
|
}
|
|
val list = data ?: emptyList()
|
|
val prepList = prep.mDataPrep(list)
|
|
dataList.addAll(prepList)
|
|
page++
|
}
|
}
|
|
if (dataList.isNotEmpty()) {
|
val workbook = SXSSFWorkbook()
|
val heads = mutableListOf<Array<String>>()
|
heads.add(dataList[0].toRowTitle())
|
val contents = mutableListOf<Array<Any>>()
|
dataList.forEach {
|
contents.add(it.toRowContent())
|
}
|
ExcelUtil.write(heads, contents, workbook)
|
|
val fileName = "网格化预处理数据${it.first.substring(0, 10)}.xls"
|
val filePath = "E:\\work\\export\\预处理\\$fileName"
|
val out = FileOutputStream(File(filePath))
|
workbook.write(out)
|
workbook.close()
|
out.flush()
|
out.close()
|
}
|
}
|
}
|
|
@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)
|
}
|
}
|
}
|