riku
2025-08-25 2de612e9b260df2e76d4dd620ca739aa3b6e8c57
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
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(null, 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(null, 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)
        }
    }
 
    @Test
    fun foo3() {
 
    }
}