1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
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.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.FileOutputStream
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, 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 = HSSFWorkbook()
                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()
            }
        }
    }
}