feiyu02
2025-09-12 61871594dfa0a5ac2c4d895d9ec4034feba57094
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
package com.flightfeather.uav.model.epw
 
import com.flightfeather.uav.common.utils.DateUtil
import com.flightfeather.uav.domain.mapper.CompanyMapper
import com.flightfeather.uav.lightshare.bean.CompanySOP
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.junit.Test
import org.junit.runner.RunWith
import org.springframework.beans.BeanUtils
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.test.context.junit4.SpringRunner
import java.io.FileOutputStream
import java.util.*
import kotlin.math.ceil
import kotlin.math.floor
 
@RunWith(SpringRunner::class)
@SpringBootTest
class EPWModelTest {
 
    @Autowired
    lateinit var realTimeDataService: RealTimeDataService
 
    @Autowired
    lateinit var companyMapper: CompanyMapper
 
    @Test
    fun test1() {
        val company = companyMapper
            .selectAll()
//            .selectByExample(Example(Company::class.java).apply {
//            createCriteria()
//                .orEqualTo("ciGuid", "Dp5iDYfKY7qi04Ze")
//                .orEqualTo("ciGuid", "C9ZzWbc49AHuxa0U")
//                .orEqualTo("ciGuid", "15xCtnjxa9pfmDSj")
//                .orEqualTo("ciGuid", "mbd8mRmpRtcUsT61")
//                .orEqualTo("ciGuid", "xh7fpulnFQDQjb3e")
//                .orEqualTo("ciGuid", "mXef1NeDZyguGDLN")
//                .orEqualTo("ciGuid", "LEU330ksO54BEH8A")
//                .orEqualTo("ciGuid", "aZpHXOktTEuzUcTX")
//                .orEqualTo("ciGuid", "dNDMoJfresNn5hPU")
//                .orEqualTo("ciGuid", "J3euwNl19WZvH7iE")
//                .orEqualTo("ciGuid", "eb2kbFjhCZN2s9If")
//                .orEqualTo("ciGuid", "0PjZXFkpp1KT6hEM")
//                .orEqualTo("ciGuid", "ymXoupcbVMa1bBF1")
//        })
        val companySOPList = mutableListOf<CompanySOP>()
        company.forEach {
            val companySOP = CompanySOP(it.ciGuid, it.ciName, it.ciExtension1)
            BeanUtils.copyProperties(it, companySOP)
            companySOPList.add(companySOP)
        }
 
        val dataSet = mutableListOf<DataVo>()
        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 08:00:00"),
 
//            网格化监测
            Pair("2021-06-18 15:00:00", "2021-06-30 08:00:00"),
 
//            走航监测
//            Pair("2021-03-26 11:28:12", "2021-03-26 21:30:00"),
//            Pair("2021-04-09 07:18:12", "2021-04-09 22:04:39"),
//            Pair("2021-04-10 08:00:02", "2021-04-10 09:44:18"),
//            Pair("2021-04-21 16:46:12", "2021-04-21 21:18:35"),
//            Pair("2021-05-24 11:10:12", "2021-05-24 19:31:02"),
//            Pair("2021-06-04 09:02:40", "2021-06-04 20:14:18"),
        )
 
        val deviceCode = "0d0000000001"
 
        val epwModel = EPWModel()
        var workbook: SXSSFWorkbook? = null
        var out: FileOutputStream? = null
 
        for (i in timeSet.indices) {
            val it = timeSet[i]
 
            var page = 1
            var totalPage = -1
            while (totalPage == -1 || page <= totalPage) {
                realTimeDataService.getSecondData(null, deviceCode, it.first, it.second, page, 0, 10000).apply {
                    if (totalPage == -1) {
                        totalPage = head?.totalPage ?: 0
                    }
 
                    val dataList = data ?: emptyList()
 
                    dataList.forEach {
                        if (it.lng == 0.0 && it.lat == 0.0) {
                            it.lng = 121.235813
                            it.lat = 30.835898
                        }
                    }
 
                    dataSet.addAll(dataList)
//                    println()
//                    println("[${page}]数据量: ${dataList.size}")
 
                    epwModel.execute(dataList, companySOPList, true)
 
                    page++
                }
            }
 
            val p = epwModel.outputToExcel(
                "污染权重分析结果-综合-${DateUtil.instance.dateToString(Date(), "yyyy-MM-ddHHmmss")}.xls",
//                "污染权重分析结果-${it.first.substring(0, 10)}.xls",
//                "污染权重分析结果-网格化-${it.first.substring(0, 10)}.xls",
                workbook,
                out,
                it.first.substring(0, 10),
//                false
//                i == timeSet.size - 1
            )
//            p?.first?.let { workbook = it }
//            p?.second?.let { out = it }
        }
 
//        var page = 1
//        var totalPage = ceil(dataSet.size.toDouble() / 5000)
//        println(dataSet.size)
 
//        val epwModel1 = EPWModel()
//        epwModel1.execute(dataSet, companySOPList)
//        epwModel1.outputToExcel("污染权重分析结果-综合-${DateUtil.instance.dateToString(Date(), "yyyy-MM-ddHHmmss")}.xls", workbook, out, "综合")
    }
}