package com.flightfeather.uav.domain.entity
|
|
import com.flightfeather.uav.common.utils.DateUtil
|
import com.flightfeather.uav.common.utils.GsonUtils
|
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 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
|
},
|
)
|
}
|