| | |
| | | import com.flightfeather.uav.model.epw.EPWDataPrep |
| | | import com.flightfeather.uav.domain.repository.AirDataRep |
| | | import com.flightfeather.uav.domain.repository.SceneInfoRep |
| | | import com.flightfeather.uav.domain.repository.SourceTraceRep |
| | | import com.flightfeather.uav.lightshare.bean.DataVo |
| | | import com.flightfeather.uav.socket.bean.AirDataPackage |
| | | import com.flightfeather.uav.socket.decoder.AirDataDecoder |
| | | import com.flightfeather.uav.socket.decoder.DataPackageDecoder |
| | | import com.flightfeather.uav.socket.eunm.AirCommandUnit |
| | | import com.flightfeather.uav.socket.eunm.UWDeviceType |
| | | import io.netty.channel.ChannelHandlerContext |
| | | import org.springframework.format.annotation.DateTimeFormat |
| | | import org.springframework.stereotype.Component |
| | | import java.text.SimpleDateFormat |
| | | import java.time.LocalDateTime |
| | | import java.time.format.DateTimeFormatter |
| | | import java.util.* |
| | | |
| | | /** |
| | |
| | | class UnderwayProcessor( |
| | | private val airDataRep: AirDataRep, |
| | | private val sceneInfoRep: SceneInfoRep, |
| | | private val sourceTraceRep: SourceTraceRep |
| | | ) : BaseProcessor() { |
| | | |
| | | companion object { |
| | |
| | | //保存 |
| | | deviceSession.saveDevice(packageData.deviceCode, ctx) |
| | | saveToTxt(msg) |
| | | saveToDataBase(packageData)?.takeIf { it.isNotEmpty() }?.get(0)?.let { |
| | | val res = saveToDataBase(packageData) |
| | | println("----写入完成") |
| | | res?.takeIf { it.isNotEmpty() }?.get(0)?.let { |
| | | // 每台设备有各自单独的异常数据处理器 |
| | | if (!sourceTraceMap.containsKey(it.deviceCode)) { |
| | | sourceTraceMap[it.deviceCode] = SourceTraceController(sceneInfoRep) |
| | | sourceTraceMap[it.deviceCode] = SourceTraceController(sceneInfoRep, sourceTraceRep) |
| | | } |
| | | // 将走航数据传入异常处理器 |
| | | sourceTraceMap[it.deviceCode]?.addOneData(it) |
| | | println("----动态溯源完成") |
| | | } |
| | | |
| | | } else { |
| | | println("------${TAG}数据BCC校验失败,舍弃 [${SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Date())}]") |
| | | } |
| | |
| | | fun saveToDataBase(dataPackage: AirDataPackage): List<BaseRealTimeData>? { |
| | | when (dataPackage.commandUnit) { |
| | | AirCommandUnit.AirData.value -> { |
| | | val dataVo = dataPackage.toDataVo() |
| | | // 存储前判断数据是否有效 |
| | | if (!isValid(dataVo)) return null |
| | | // 以json格式存储原始数据 |
| | | airDataRep.saveAirData(dataPackage) |
| | | // 进行预处理后,存储至对应数据表 |
| | |
| | | dataProcessMap[dataPackage.deviceCode] = EPWDataPrep(UWDeviceType.getType(dataPackage.deviceCode)) |
| | | } |
| | | return dataProcessMap[dataPackage.deviceCode]?.run { |
| | | val list = this.mDataPrep2(dataPackage)// 数据平滑处理 |
| | | val list = this.mDataPrep2(dataVo)// 数据平滑处理 |
| | | airDataRep.savePrepData2(list)// 按照设备类型存储至对应数据表 |
| | | } |
| | | } |
| | |
| | | |
| | | return sb.toString() |
| | | } |
| | | |
| | | /** |
| | | * 数据有效性判断 |
| | | */ |
| | | private fun isValid(dataVo: DataVo): Boolean { |
| | | if (dataVo.time == null) return false |
| | | val check1 = LocalDateTime.parse(dataVo.time!!, DateTimeFormatter.ofPattern("yyy-MM-dd HH:mm:ss")) |
| | | .isBefore(LocalDateTime.now()) |
| | | return check1 |
| | | } |
| | | } |