feiyu02
7 天以前 594de76ed51fd49fb79b912212bb0052a63e7671
src/main/kotlin/com/flightfeather/uav/domain/repository/impl/AirDataRepImpl.kt
@@ -35,11 +35,11 @@
    private val tmpVehicleDataList = mutableListOf<BaseRealTimeData>()
    // 走航监测校准系数
    private val calibrationMap = mutableMapOf<String, MutableMap<Int, Float>>()
    private val calibrationMap = mutableMapOf<String?, MutableMap<Int, Float>>()
    // 走航监测校准系数更新时间
    private var cUpdateTime = LocalDateTime.now()
    // 走航监测校准系数更新时间间隔(分钟)
    private val cInterval = 5L
    private val cInterval = 1L
    override fun saveAirData(dataPackage: AirDataPackage): Int {
        val data = RealTimeData().apply {
@@ -135,7 +135,7 @@
                    val d = vo.toBaseRealTimeData(RealTimeDataVehicle::class.java)
                    /***************************************************************************************************/
                    // FIXME: 2021/10/27 车载监测部分因子量级调整
                    calibration(d, UWDeviceType.VEHICLE)
                    calibration(d, d.deviceCode)
                    /***************************************************************************************************/
                    realTimeDataVehicleMapper.insert(d)
                    res.add(d)
@@ -267,20 +267,20 @@
        }
    }
    private fun calibration(data: BaseRealTimeData, type: UWDeviceType) {
    private fun calibration(data: BaseRealTimeData, deviceCode: String?) {
        //1. 校准系数按照一定时间间隔进行刷新
        val now = LocalDateTime.now()
        if (calibrationMap.isEmpty() || now.minusMinutes(cInterval).isAfter(cUpdateTime)) {
        if (calibrationMap[deviceCode].isNullOrEmpty() || now.minusMinutes(cInterval).isAfter(cUpdateTime)) {
            cUpdateTime = now
            calibrationMap[type.value] = mutableMapOf()
            calibrationMap[deviceCode] = mutableMapOf()
            factorCalibrationMapper.selectByExample(Example(FactorCalibration::class.java).apply {
                createCriteria().andEqualTo("deviceType", type.value)
                createCriteria().andEqualTo("deviceType", deviceCode)
            }).forEach {
                calibrationMap[type.value]?.put(it.factorId, it.factorScale)
                calibrationMap[deviceCode]?.put(it.factorId, it.factorScale)
            }
        }
        //2. 根据校准系数计算
        calibrationMap[type.value]?.let{
        calibrationMap[deviceCode]?.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)