| | |
| | | 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.domain.mapper.* |
| | | import com.flightfeather.uav.lightshare.bean.DataVo |
| | | import com.flightfeather.uav.repository.AirDataRepository |
| | | import com.flightfeather.uav.socket.bean.AirData |
| | |
| | | import tk.mybatis.mapper.entity.Example |
| | | import java.math.BigDecimal |
| | | import java.text.SimpleDateFormat |
| | | import java.time.LocalDateTime |
| | | import java.time.ZoneId |
| | | import java.util.* |
| | | import kotlin.math.abs |
| | | import kotlin.math.sqrt |
| | | |
| | | /** |
| | | * @author riku |
| | |
| | | private val realTimeDataMapper: RealTimeDataMapper, |
| | | private val realTimeDataVehicleMapper: RealTimeDataVehicleMapper, |
| | | private val realTimeDataUavMapper: RealTimeDataUavMapper, |
| | | private val realTimeDataGridMapper: RealTimeDataGridMapper |
| | | private val realTimeDataGridMapper: RealTimeDataGridMapper, |
| | | private val factorCalibrationMapper: FactorCalibrationMapper |
| | | ): AirDataRepository { |
| | | |
| | | // FIXME: 2021/10/25 临时车载数据,由于无人机部分监测因子数据无效,因此暂时采用车载数据作为填充 |
| | | private val tmpVehicleDataList = mutableListOf<BaseRealTimeData>() |
| | | |
| | | // 走航监测校准系数 |
| | | private val calibrationMap = mutableMapOf<String, MutableMap<Int, Float>>() |
| | | // 走航监测校准系数更新时间 |
| | | private var cUpdateTime = LocalDateTime.now() |
| | | // 走航监测校准系数更新时间间隔(分钟) |
| | | private val cInterval = 5L |
| | | |
| | | override fun saveAirData(dataPackage: AirDataPackage): Int { |
| | | val data = RealTimeData().apply { |
| | |
| | | realTimeDataGridMapper.insert(d) |
| | | count++ |
| | | } |
| | | else -> Unit |
| | | } |
| | | return count |
| | | } |
| | |
| | | realTimeDataGridMapper.insert(d) |
| | | count++ |
| | | } |
| | | else -> Unit |
| | | } |
| | | } |
| | | return count |
| | |
| | | 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) |
| | | // FIXME: 2021/10/27 车载监测部分因子量级调整 |
| | | calibration(d, UWDeviceType.VEHICLE) |
| | | /***************************************************************************************************/ |
| | | realTimeDataVehicleMapper.insert(d) |
| | | count++ |
| | |
| | | UWDeviceType.GRID -> { |
| | | val d = RealTimeDataGrid() |
| | | dataTransform(vo, d) |
| | | /**************************************************************************/ |
| | | // FIXME: 2021/11/8 针对历史网格化原始数据,进行临时校准处理 |
| | | // val dTime = LocalDateTime.ofInstant(d.dataTime?.toInstant(), ZoneId.systemDefault()) |
| | | // // CO: 2021.8.28 17:27起 *0.25 |
| | | // val coTime = LocalDateTime.of(2021, 8, 28, 17, 27, 0) |
| | | // if (dTime.isAfter(coTime)) { |
| | | // d.co = d.co?.times(0.25f) |
| | | // } |
| | | // |
| | | // // NO2 |
| | | // d.no2 = d.no2?.times(0.6f) |
| | | // |
| | | // // O3 |
| | | // d.o3 = abs(d.o3?.minus(d.no2?.div(2) ?: 0f) ?: 0f) * 1.5f |
| | | // |
| | | // // SO2: *0.2, 2021.8.29 6:00起 *0.08 |
| | | // val so2Time = LocalDateTime.of(2021, 8, 29, 6, 0, 0) |
| | | // d.so2 = if (dTime.isAfter(so2Time)) { |
| | | // d.so2?.times(0.08f) |
| | | // } else { |
| | | // d.so2?.times(0.2f) |
| | | // } |
| | | // |
| | | // // H2S |
| | | // d.h2s = d.h2s?.let { sqrt(it) * 2 } |
| | | /**************************************************************************/ |
| | | realTimeDataGridMapper.insert(d) |
| | | count++ |
| | | } |
| | | UWDeviceType.BOAT -> { |
| | | |
| | | } |
| | | else -> Unit |
| | | } |
| | | } |
| | | return count |
| | |
| | | } |
| | | } |
| | | |
| | | private fun dataTransform(vo: DataVo, bean: BaseRealTimeData) { |
| | | fun dataTransform(vo: DataVo, bean: BaseRealTimeData) { |
| | | bean.apply { |
| | | deviceCode = vo.deviceCode |
| | | latitude = vo.lat?.toBigDecimal() |
| | |
| | | |
| | | } |
| | | } |
| | | |
| | | private fun calibration(data: BaseRealTimeData, type: UWDeviceType) { |
| | | //1. 校准系数按照一定时间间隔进行刷新 |
| | | val now = LocalDateTime.now() |
| | | if (calibrationMap.isEmpty() || now.minusMinutes(cInterval).isAfter(cUpdateTime)) { |
| | | cUpdateTime = now |
| | | calibrationMap[type.value] = mutableMapOf() |
| | | factorCalibrationMapper.selectByExample(Example(FactorCalibration::class.java).apply { |
| | | createCriteria().andEqualTo("deviceType", type.value) |
| | | }).forEach { |
| | | calibrationMap[type.value]?.put(it.factorId, it.factorScale) |
| | | } |
| | | } |
| | | //2. 根据校准系数计算 |
| | | calibrationMap[type.value]?.let{ |
| | | data.voc = data.voc?.times(it[FactorType.VOC.value] ?: 1f) |
| | | data.co = data.co?.times(it[FactorType.CO.value] ?: 1f) |
| | | data.pm25 = data.pm25?.times(it[FactorType.PM25.value] ?: 1f) |
| | | data.pm10 = data.pm10?.times(it[FactorType.PM10.value] ?: 1f) |
| | | |
| | | data.no2 = data.no2?.times(it[FactorType.NO2.value] ?: 1f) |
| | | data.h2s = data.h2s?.times(it[FactorType.H2S.value] ?: 1f) |
| | | data.so2 = data.so2?.times(it[FactorType.SO2.value] ?: 1f) |
| | | data.o3 = data.o3?.times(it[FactorType.O3.value] ?: 1f) |
| | | } |
| | | } |
| | | } |