From ef9692dd7a43e0620632e48ef295da738da50f90 Mon Sep 17 00:00:00 2001 From: riku <risaku@163.com> Date: 星期三, 27 十月 2021 16:10:15 +0800 Subject: [PATCH] 1. 监测数据根据设备类型不同分别存储不同数据表 2. 车载数据部分监测因子进行量级调整 3. 无人机监测数据部分监测因子由于偏差较大采用车载数据填充 4. 监测数据存储之前先进行平滑预处理,矫正异常值 --- src/main/kotlin/com/flightfeather/uav/repository/impl/AirDataRepositoryImpl.kt | 233 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 225 insertions(+), 8 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 5c548e2..f0ec25c 100644 --- a/src/main/kotlin/com/flightfeather/uav/repository/impl/AirDataRepositoryImpl.kt +++ b/src/main/kotlin/com/flightfeather/uav/repository/impl/AirDataRepositoryImpl.kt @@ -1,13 +1,24 @@ 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.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.* /** @@ -15,13 +26,21 @@ * 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 { + + // FIXME: 2021/10/25 涓存椂杞﹁浇鏁版嵁锛岀敱浜庢棤浜烘満閮ㄥ垎鐩戞祴鍥犲瓙鏁版嵁鏃犳晥锛屽洜姝ゆ殏鏃堕噰鐢ㄨ溅杞芥暟鎹綔涓哄~鍏� + private val tmpVehicleDataList = mutableListOf<BaseRealTimeData>() override fun saveAirData(dataPackage: AirDataPackage): Int { val data = RealTimeData().apply { deviceCode = dataPackage.deviceCode - latitude - longitude + latitude = BigDecimal.ZERO + longitude = BigDecimal.ZERO altitude height factors = Gson().toJson(dataPackage.dataUnit) @@ -37,17 +56,215 @@ data.longitude = it.factorData?.toBigDecimal() } FactorType.TIME.value -> { - it.factorData?.let { f-> Date(f)}?.let {d -> - data.dataTime = d + 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 杞﹁浇鐩戞祴閮ㄥ垎鍥犲瓙閲忕骇璋冩暣锛歂O2*0.6锛孒2S*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() + } + } + + } + } } \ No newline at end of file -- Gitblit v1.9.3