src/main/kotlin/com/flightfeather/uav/lightshare/bean/DataVo.kt
@@ -1,9 +1,12 @@
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
@@ -20,7 +23,7 @@
        //经度
        var lng: Double? = null,
        //纬度
        var lat: Double? = null
    var lat: Double? = null,
) : BaseMData() {
        override fun getFactorData(type: FactorType): Double? {
                if (values == null) throw IllegalStateException(this.javaClass.name + ": 监测数据数组为null")
@@ -62,4 +65,35 @@
                }
                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()
                }
            }
        }
    }
}