feiyu02
2025-07-23 344d9006faa27ea65e3eaf5e8f9173aad2266038
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
package com.flightfeather.uav.lightshare.bean
 
import com.fasterxml.jackson.annotation.JsonInclude
import com.flightfeather.uav.domain.entity.BaseRealTimeData
import com.flightfeather.uav.model.BaseMData
import com.flightfeather.uav.socket.bean.AirData
import com.flightfeather.uav.socket.eunm.FactorType
import java.text.SimpleDateFormat
import java.util.Date
 
/**
 * @author riku
 * Date: 2020/9/10
 */
@JsonInclude(JsonInclude.Include.NON_NULL)
data class DataVo(
    //时间,  yyyy-MM-dd HH:mm:ss
    var time: String? = null,
    //站点编号
    var deviceCode: String? = null,
    //数据值
    var values: List<AirData>? = null,
    //经度
    var lng: Double? = null,
    //纬度
    var lat: Double? = null,
) : BaseMData() {
    override fun getFactorData(type: FactorType): Double? {
        if (values == null) throw IllegalStateException(this.javaClass.name + ": 监测数据数组为null")
        for (d in values!!) {
            if (d.factorName == type.name) {
                return d.factorData
            }
        }
        return null
    }
 
    fun toRowContent(): Array<Any> {
        val row = mutableListOf<Any>()
        row.add(deviceCode ?: "")
        row.add(time ?: "")
        row.add(lng ?: -1.0)
        row.add(lat ?: -1.0)
        values?.forEach {
            if (FactorType.outputFactor(it.factorName)) {
                row.add(it.factorData ?: -1.0)
//                                row.add(it.physicalQuantity ?: -1.0)
            }
        }
        return row.toTypedArray()
    }
 
    fun toRowTitle(): Array<String> {
        val list = mutableListOf<String>()
        list.add("编号")
        list.add("采样时间")
        list.add("经度")
        list.add("纬度")
        values?.forEach {
            if (FactorType.outputFactor(it.factorName)) {
                val name = it.factorName ?: ""
                list.add(name)
//                        list.add("$name(物理量)")
            }
        }
        return list.toTypedArray()
    }
 
    fun <T : BaseRealTimeData> toBaseRealTimeData(clz:Class<T>): T {
        return clz.newInstance().apply {
            deviceCode = this@DataVo.deviceCode
            latitude = this@DataVo.lat?.toBigDecimal()
            longitude = this@DataVo.lng?.toBigDecimal()
            dataTime = SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(this@DataVo.time)
            createTime = Date()
            this@DataVo.values?.forEach {
                when (it.factorId?.toInt()) {
                    FactorType.NO2.value -> no2 = it.factorData?.toFloat()
                    FactorType.CO.value -> co = it.factorData?.toFloat()
                    FactorType.H2S.value -> h2s = it.factorData?.toFloat()
                    FactorType.SO2.value -> so2 = it.factorData?.toFloat()
                    FactorType.O3.value -> o3 = it.factorData?.toFloat()
 
                    FactorType.PM25.value -> pm25 = it.factorData?.toFloat()
                    FactorType.PM10.value -> pm10 = it.factorData?.toFloat()
                    FactorType.TEMPERATURE.value -> temperature = it.factorData?.toFloat()
                    FactorType.HUMIDITY.value -> humidity = it.factorData?.toFloat()
                    FactorType.VOC.value -> voc = it.factorData?.toFloat()
 
                    FactorType.NOI.value -> noi = it.factorData?.toFloat()
                    FactorType.VELOCITY.value -> velocity = it.factorData?.toFloat()
                    FactorType.WIND_SPEED.value -> windSpeed = it.factorData?.toFloat()
                    FactorType.WIND_DIRECTION.value -> windDirection = it.factorData?.toFloat()
                    FactorType.HEIGHT.value -> height = it.factorData?.toFloat()
                }
            }
        }
    }
}