| | |
| | | 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.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) |
| | |
| | | } |
| | | |
| | | if (dataList.isNotEmpty()) { |
| | | val workbook = HSSFWorkbook() |
| | | val workbook = SXSSFWorkbook() |
| | | val heads = mutableListOf<Array<String>>() |
| | | heads.add(dataList[0].toRowTitle()) |
| | | val contents = mutableListOf<Array<Any>>() |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | @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) |
| | | } |
| | | } |
| | | } |