package com.flightfeather.uav.repository.impl
|
|
import com.flightfeather.uav.domain.entity.RealTimeData
|
import com.flightfeather.uav.domain.mapper.RealTimeDataMapper
|
import com.flightfeather.uav.repository.AirDataRepository
|
import com.flightfeather.uav.socket.bean.AirData
|
import com.flightfeather.uav.socket.bean.AirDataPackage
|
import com.flightfeather.uav.socket.eunm.FactorType
|
import com.google.gson.Gson
|
import org.springframework.stereotype.Repository
|
import java.text.SimpleDateFormat
|
import java.util.*
|
|
/**
|
* @author riku
|
* Date: 2020/6/11
|
*/
|
@Repository
|
class AirDataRepositoryImpl(private val realTimeDataMapper: RealTimeDataMapper): AirDataRepository {
|
|
override fun saveAirData(dataPackage: AirDataPackage): Int {
|
val data = RealTimeData().apply {
|
deviceCode = dataPackage.deviceCode
|
latitude
|
longitude
|
altitude
|
height
|
factors = Gson().toJson(dataPackage.dataUnit)
|
dataTime = dataPackage.dataTime
|
}
|
dataPackage.dataUnit.forEach {
|
if (it is AirData) {
|
when (it.factorId?.toInt()) {
|
FactorType.LAT.value -> {
|
data.latitude = it.factorData?.toBigDecimal()
|
}
|
FactorType.LNG.value -> {
|
data.longitude = it.factorData?.toBigDecimal()
|
}
|
FactorType.TIME.value -> {
|
it.statusList?.takeIf {l-> l.isNotEmpty() }?.get(0)?.let {d ->
|
data.dataTime = SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(d)
|
}
|
}
|
}
|
}
|
}
|
|
|
realTimeDataMapper.insert(data)
|
|
return 0
|
}
|
}
|