feiyu02
2025-03-21 e5bdf2e02090357cbd580d54e6cd2406dd541760
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
package com.flightfeather.uav.domain.entity
 
import com.flightfeather.uav.common.utils.DateUtil
import com.flightfeather.uav.common.utils.GsonUtils
import com.flightfeather.uav.lightshare.bean.DataVo
import com.flightfeather.uav.socket.bean.AirData
import com.flightfeather.uav.socket.eunm.FactorType
 
/**
 * 数据库表实体扩展方法
 */
fun RealTimeData.toRowTitle(): Array<String> {
    val list = mutableListOf<String>()
    list.add("编号")
    list.add("采样时间")
    list.add("经度")
    list.add("纬度")
    val values = GsonUtils.parserJsonToArrayBeans(factors, AirData::class.java)
    values.forEach {
        if (FactorType.outputFactor(it.factorName)) {
            val name = it.factorName ?: ""
            list.add(name)
//            list.add("$name(物理量)")
        }
    }
    return list.toTypedArray()
}
 
fun RealTimeData.toRowContent(): Array<Any> {
    val row = mutableListOf<Any>()
    row.add(deviceCode ?: "")
    row.add(DateUtil.instance.dateToString(dataTime, "yyyy-MM-dd HH:mm:ss") ?: "")
    if (longitude == null) {
        row.add(-1.0)
    } else {
        row.add(longitude.toDouble())
    }
    if (latitude == null) {
        row.add(-1.0)
    } else {
        row.add(latitude.toDouble())
    }
    val values = GsonUtils.parserJsonToArrayBeans(factors, AirData::class.java)
    values.forEach {
        if (FactorType.outputFactor(it.factorName)) {
            row.add(it.factorData ?: -1.0)
//            row.add(it.physicalQuantity ?: -1.0)
        }
    }
    return row.toTypedArray()
}
 
fun RealTimeData.toDataVo() = DataVo(
    DateUtil.instance.dateToString(dataTime, DateUtil.DateStyle.YYYY_MM_DD_HH_MM_SS),
    deviceCode,
    GsonUtils.parserJsonToArrayBeans(factors, AirData::class.java),
    longitude?.toDouble(), latitude?.toDouble()
)
 
fun ElectricMinuteValue.toAirData(): List<AirData> {
    return listOf(
        AirData().apply {
            factorId = "1"
            factorName = "EA"
            factorData = mvElectricityA
        },
        AirData().apply {
            factorId = "2"
            factorName = "EB"
            factorData = mvElectricityB
        },
        AirData().apply {
            factorId = "3"
            factorName = "EC"
            factorData = mvElectricityC
        },
        AirData().apply {
            factorId = "4"
            factorName = "VA"
            factorData = mvVoltageA
        },
        AirData().apply {
            factorId = "5"
            factorName = "VB"
            factorData = mvVoltageB
        },
        AirData().apply {
            factorId = "6"
            factorName = "VC"
            factorData = mvVoltageC
        },
        AirData().apply {
            factorId = "7"
            factorName = "PA"
            factorData = mvPowerA
        },
        AirData().apply {
            factorId = "8"
            factorName = "PB"
            factorData = mvPowerB
        },
        AirData().apply {
            factorId = "9"
            factorName = "PC"
            factorData = mvPowerC
        },
    )
}