package com.flightfeather.uav.repository.impl
|
|
import com.flightfeather.uav.common.utils.GsonUtils
|
import com.flightfeather.uav.domain.MyMapper
|
import com.flightfeather.uav.domain.entity.*
|
import com.flightfeather.uav.domain.mapper.RealTimeDataGridMapper
|
import com.flightfeather.uav.domain.mapper.RealTimeDataMapper
|
import com.flightfeather.uav.domain.mapper.RealTimeDataUavMapper
|
import com.flightfeather.uav.domain.mapper.RealTimeDataVehicleMapper
|
import com.flightfeather.uav.lightshare.bean.DataVo
|
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.flightfeather.uav.socket.eunm.UWDeviceType
|
import com.github.pagehelper.PageHelper
|
import com.google.gson.Gson
|
import org.springframework.stereotype.Repository
|
import tk.mybatis.mapper.entity.Example
|
import java.math.BigDecimal
|
import java.text.SimpleDateFormat
|
import java.util.*
|
|
/**
|
* @author riku
|
* Date: 2020/6/11
|
*/
|
@Repository
|
class AirDataRepositoryImpl(
|
private val realTimeDataMapper: RealTimeDataMapper,
|
private val realTimeDataVehicleMapper: RealTimeDataVehicleMapper,
|
private val realTimeDataUavMapper: RealTimeDataUavMapper,
|
private val realTimeDataGridMapper: RealTimeDataGridMapper
|
): AirDataRepository {
|
|
// FIXME: 2021/10/25 临时车载数据,由于无人机部分监测因子数据无效,因此暂时采用车载数据作为填充
|
private val tmpVehicleDataList = mutableListOf<BaseRealTimeData>()
|
|
override fun saveAirData(dataPackage: AirDataPackage): Int {
|
val data = RealTimeData().apply {
|
deviceCode = dataPackage.deviceCode
|
latitude = BigDecimal.ZERO
|
longitude = BigDecimal.ZERO
|
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
|
}
|
|
override fun savePrepData(dataPackage: AirDataPackage): Int {
|
var count = 0
|
when (UWDeviceType.getType(dataPackage.deviceCode)) {
|
UWDeviceType.VEHICLE -> {
|
val d = RealTimeDataVehicle()
|
dataTransform(dataPackage, d)
|
realTimeDataVehicleMapper.insert(d)
|
count++
|
}
|
UWDeviceType.UAV -> {
|
val d = RealTimeDataUav()
|
dataTransform(dataPackage, d)
|
realTimeDataUavMapper.insert(d)
|
count++
|
}
|
UWDeviceType.GRID -> {
|
val d = RealTimeDataGrid()
|
dataTransform(dataPackage, d)
|
realTimeDataGridMapper.insert(d)
|
count++
|
}
|
}
|
return count
|
}
|
|
override fun savePrepData(dataList: List<RealTimeData>): Int {
|
var count = 0
|
dataList.forEach {vo ->
|
when (UWDeviceType.getType(vo.deviceCode)) {
|
UWDeviceType.VEHICLE -> {
|
val d = RealTimeDataVehicle()
|
dataTransform(vo, d)
|
realTimeDataVehicleMapper.insert(d)
|
count++
|
}
|
UWDeviceType.UAV -> {
|
val d = RealTimeDataUav()
|
dataTransform(vo, d)
|
realTimeDataUavMapper.insert(d)
|
count++
|
}
|
UWDeviceType.GRID -> {
|
val d = RealTimeDataGrid()
|
dataTransform(vo, d)
|
realTimeDataGridMapper.insert(d)
|
count++
|
}
|
}
|
}
|
return count
|
}
|
|
override fun savePrepData2(dataList: List<DataVo>): Int {
|
var count = 0
|
dataList.forEach {vo ->
|
when (UWDeviceType.getType(vo.deviceCode)) {
|
UWDeviceType.VEHICLE -> {
|
val d = RealTimeDataVehicle()
|
dataTransform(vo, d)
|
/***************************************************************************************************/
|
// FIXME: 2021/10/27 车载监测部分因子量级调整:NO2*0.6,H2S*0.3, SO2*0.2, O3*0.5,其他要素不变
|
d.no2 = d.no2?.times(0.6f)
|
d.h2s = d.h2s?.times(0.3f)
|
d.so2 = d.so2?.times(0.2f)
|
d.o3 = d.o3?.times(0.5f)
|
/***************************************************************************************************/
|
realTimeDataVehicleMapper.insert(d)
|
count++
|
}
|
UWDeviceType.UAV -> {
|
val d = RealTimeDataUav()
|
dataTransform(vo, d)
|
/***************************************************************************************************/
|
// FIXME: 2021/10/25 无人机部分因子采用车载数据填充,取最新的15分钟的数据
|
if (tmpVehicleDataList.isEmpty()) {
|
val p = PageHelper.startPage<RealTimeDataVehicle>(1, 225)
|
realTimeDataVehicleMapper.selectByExample(Example(RealTimeDataVehicle::class.java).apply {
|
orderBy("dataTime").desc()
|
}).let { tmpVehicleDataList.addAll(it) }
|
}
|
if (tmpVehicleDataList.isNotEmpty()) {
|
tmpVehicleDataList[0].let {
|
d.no2 = it.no2
|
d.co = it.co
|
d.h2s = it.h2s
|
d.so2 = it.so2
|
d.o3 = it.o3
|
}
|
tmpVehicleDataList.removeFirst()
|
}
|
/***************************************************************************************************/
|
realTimeDataUavMapper.insert(d)
|
count++
|
}
|
UWDeviceType.GRID -> {
|
val d = RealTimeDataGrid()
|
dataTransform(vo, d)
|
realTimeDataGridMapper.insert(d)
|
count++
|
}
|
}
|
}
|
return count
|
}
|
|
private fun dataTransform(vo: RealTimeData, bean: BaseRealTimeData) {
|
bean.apply {
|
deviceCode = vo.deviceCode
|
latitude = vo.latitude
|
longitude = vo.longitude
|
dataTime = vo.dataTime
|
createTime = vo.createTime
|
GsonUtils.parserJsonToArrayBeans(vo.factors, AirData::class.java).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()
|
}
|
}
|
|
}
|
}
|
|
private fun dataTransform(dataPackage: AirDataPackage, bean: BaseRealTimeData) {
|
bean.apply {
|
deviceCode = dataPackage.deviceCode
|
dataPackage.dataUnit.forEach {
|
if (it is AirData) {
|
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()
|
|
FactorType.LAT.value -> latitude = it.factorData?.toBigDecimal()
|
FactorType.LNG.value -> longitude = it.factorData?.toBigDecimal()
|
FactorType.TIME.value -> it.statusList?.takeIf { l -> l.isNotEmpty() }?.get(0)?.let { d ->
|
dataTime = SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(d)
|
}
|
}
|
}
|
}
|
}
|
}
|
|
private fun dataTransform(vo: DataVo, bean: BaseRealTimeData) {
|
bean.apply {
|
deviceCode = vo.deviceCode
|
latitude = vo.lat?.toBigDecimal()
|
longitude = vo.lng?.toBigDecimal()
|
dataTime = SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(vo.time)
|
createTime = Date()
|
vo.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()
|
}
|
}
|
|
}
|
}
|
}
|