From 1074bb5c8473dcb99d6edea5fa67ae7aa78af248 Mon Sep 17 00:00:00 2001 From: riku <risaku@163.com> Date: 星期二, 17 九月 2019 15:54:59 +0800 Subject: [PATCH] 1. 按照数据分类添加新的数据库表格 2. 完成数据分表存储逻辑并debug完成 --- src/main/kotlin/com/flightfeather/obd/socket/MessageManager.kt | 29 ++++++++++++++++++++++++++--- 1 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/com/flightfeather/obd/socket/MessageManager.kt b/src/main/kotlin/com/flightfeather/obd/socket/MessageManager.kt index 626194f..e413f7d 100644 --- a/src/main/kotlin/com/flightfeather/obd/socket/MessageManager.kt +++ b/src/main/kotlin/com/flightfeather/obd/socket/MessageManager.kt @@ -1,10 +1,11 @@ package com.flightfeather.obd.socket import com.flightfeather.obd.common.utils.FileUtil -import com.flightfeather.obd.repository.ObdDataRepository +import com.flightfeather.obd.repository.* import com.flightfeather.obd.socket.bean.ObdPackageData import com.flightfeather.obd.socket.decoder.VehicleDataDecoder import com.flightfeather.obd.socket.decoder.impl.DataPackageDecoderImpl +import com.flightfeather.obd.socket.eunm.ObdCommandUnit import io.netty.channel.ChannelHandlerContext import org.springframework.beans.factory.annotation.Autowired import org.springframework.stereotype.Component @@ -27,6 +28,16 @@ @Autowired lateinit var obdDataRepository: ObdDataRepository + @Autowired + lateinit var originDataRepository: OriginDataRepository + @Autowired + lateinit var obdInfoRepository: ObdInfoRepository + @Autowired + lateinit var dataStreamRepository: DataStreamRepository + @Autowired + lateinit var carLogoutRepository: CarLogoutRepository + @Autowired + lateinit var carLoginRepository: CarLoginRepository val vehicleDataDecoder = VehicleDataDecoder() val dataPackageDecoder = DataPackageDecoderImpl() @@ -35,6 +46,11 @@ fun init() { instance = this instance.obdDataRepository = this.obdDataRepository + instance.originDataRepository = this.originDataRepository + instance.obdInfoRepository = this.obdInfoRepository + instance.dataStreamRepository = this.dataStreamRepository + instance.carLogoutRepository = this.carLogoutRepository + instance.carLoginRepository = this.carLoginRepository } fun dealStringMsg(msg: String, ctx: ChannelHandlerContext?) { @@ -45,7 +61,7 @@ val packageData = vehicleDataDecoder.decode(msg) //淇濆瓨 DeviceSession.saveDevice(packageData.deviceCode, ctx) - saveToDataBase(packageData) + saveToDataBase(packageData, msg) } else { println("------鏁版嵁BCC鏍¢獙澶辫触锛岃垗寮� [${SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Date())}]") } @@ -62,8 +78,15 @@ /** * 淇濆瓨鑷虫暟鎹簱 */ - fun saveToDataBase(packageData: ObdPackageData) { + fun saveToDataBase(packageData: ObdPackageData, msg: String) { instance.obdDataRepository.saveObdData(packageData) + instance.originDataRepository.saveOriginData(packageData, msg) + when (packageData.commandUnit) { + ObdCommandUnit.CarRegister.value -> instance.carLoginRepository.saveCarLogin(packageData) + ObdCommandUnit.RealTimeData.value, + ObdCommandUnit.ReplacementData.value -> instance.dataStreamRepository.saveDataStream(packageData) + ObdCommandUnit.CarLogOut.value-> instance.carLogoutRepository.saveCarLogout(packageData) + } } /** -- Gitblit v1.9.3