From a549d6bbd7cb6f2a0dda1234c1b4df072a9e1d61 Mon Sep 17 00:00:00 2001 From: riku <risaku@163.com> Date: 星期一, 18 十月 2021 09:34:05 +0800 Subject: [PATCH] 1. 新增车载、无人机和网格化三个单独的实时数据存储表 2. 新增数据转存方法,后续待补充转换中的数据预处理逻辑 --- src/main/kotlin/com/flightfeather/uav/repository/impl/AirDataRepositoryImpl.kt | 128 +++++++++++++++++++++++++++++++++++++++++- 1 files changed, 123 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/com/flightfeather/uav/repository/impl/AirDataRepositoryImpl.kt b/src/main/kotlin/com/flightfeather/uav/repository/impl/AirDataRepositoryImpl.kt index 34532fc..68975de 100644 --- a/src/main/kotlin/com/flightfeather/uav/repository/impl/AirDataRepositoryImpl.kt +++ b/src/main/kotlin/com/flightfeather/uav/repository/impl/AirDataRepositoryImpl.kt @@ -1,22 +1,33 @@ package com.flightfeather.uav.repository.impl -import com.flightfeather.uav.domain.entity.RealTimeData +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.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 { +class AirDataRepositoryImpl( + private val realTimeDataMapper: RealTimeDataMapper, + private val realTimeDataVehicleMapper: RealTimeDataVehicleMapper, + private val realTimeDataUavMapper: RealTimeDataUavMapper, + private val realTimeDataGridMapper: RealTimeDataGridMapper +): AirDataRepository { override fun saveAirData(dataPackage: AirDataPackage): Int { val data = RealTimeData().apply { @@ -45,10 +56,117 @@ } } } - - realTimeDataMapper.insert(data) return 0 } + + override fun savePrepData(dataPackage: AirDataPackage): Int { + var mapper: MyMapper<out BaseRealTimeData?>? = null + when (UWDeviceType.getType(dataPackage.deviceCode)) { + UWDeviceType.VEHICLE -> { + mapper = realTimeDataVehicleMapper + RealTimeDataVehicle() + } + UWDeviceType.UAV -> { + mapper = realTimeDataUavMapper + RealTimeDataUav() + } + UWDeviceType.GRID -> { + mapper = realTimeDataGridMapper + RealTimeDataGrid() + } + else -> null + }?.run { + 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) + } + } + } + } + +// mapper?.insert(this) + return 1 + } + return 0 + } + + 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 + } + + 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() + } + } + + } + } } \ No newline at end of file -- Gitblit v1.9.3