From 6f6c35f0e0881d2bbf32ad62f6c59f0ab1504854 Mon Sep 17 00:00:00 2001
From: riku <risaku@163.com>
Date: 星期一, 16 九月 2019 20:30:16 +0800
Subject: [PATCH] 修改采样时间的存储问题

---
 src/test/kotlin/com/flightfeather/obd/Test.kt                           |   28 ++++++++++++++
 src/main/kotlin/com/flightfeather/obd/repository/impl/ObdDataDaoImpl.kt |   36 +++++++++++++++---
 2 files changed, 58 insertions(+), 6 deletions(-)

diff --git a/src/main/kotlin/com/flightfeather/obd/repository/impl/ObdDataDaoImpl.kt b/src/main/kotlin/com/flightfeather/obd/repository/impl/ObdDataDaoImpl.kt
index 0781b69..0ecfaae 100644
--- a/src/main/kotlin/com/flightfeather/obd/repository/impl/ObdDataDaoImpl.kt
+++ b/src/main/kotlin/com/flightfeather/obd/repository/impl/ObdDataDaoImpl.kt
@@ -4,9 +4,7 @@
 import com.flightfeather.obd.domain.mapper.ObdDataMapper
 import com.flightfeather.obd.lightshare.bean.ObdDataVo
 import com.flightfeather.obd.repository.ObdDataRepository
-import com.flightfeather.obd.socket.bean.EngineDataFlow
-import com.flightfeather.obd.socket.bean.ObdPackageData
-import com.flightfeather.obd.socket.bean.SupplementDataFlow
+import com.flightfeather.obd.socket.bean.*
 import com.flightfeather.obd.socket.eunm.ObdCommandUnit
 import com.github.pagehelper.PageHelper
 import org.springframework.beans.BeanUtils
@@ -54,7 +52,15 @@
         }
         when (packageData.commandUnit) {
             ObdCommandUnit.CarRegister.value -> {
-
+                packageData.dataUnit.forEach {
+                    when (it) {
+                        is CarRegisterData -> {
+                            obdData.apply {
+                                obdTime = it.time
+                            }
+                        }
+                    }
+                }
             }
             ObdCommandUnit.RealTimeData.value,
             ObdCommandUnit.ReplacementData.value -> {
@@ -73,6 +79,7 @@
                         }
                         is EngineDataFlow -> {
                             obdData.apply {
+                                obdTime = it.time
                                 obdLng = it.obdLong
                                 obdLat = it.obdLat
                                 obdSpeed = it.obdSpeed?.toInt()
@@ -96,6 +103,7 @@
                         }
                         is SupplementDataFlow -> {
                             obdData.apply {
+                                obdTime = it.time
                                 obdEngineTorqueMode = it.obdEngineTorqueMode?.toString()
                                 obdAcceleratorPedal = it.obdAcceleratorPedal
                                 obdTotalOilConsumption = it.obdTotalOilConsumption
@@ -111,10 +119,26 @@
 
             }
             ObdCommandUnit.CarLogOut.value -> {
-
+                packageData.dataUnit.forEach {
+                    when (it) {
+                        is CarLogOutData -> {
+                            obdData.apply {
+                                obdTime = it.time
+                            }
+                        }
+                    }
+                }
             }
             ObdCommandUnit.TimeCalibration.value -> {
-
+                packageData.dataUnit.forEach {
+                    when (it) {
+                        is TimeCalibrationData -> {
+                            obdData.apply {
+                                obdTime = it.time
+                            }
+                        }
+                    }
+                }
             }
         }
 
diff --git a/src/test/kotlin/com/flightfeather/obd/Test.kt b/src/test/kotlin/com/flightfeather/obd/Test.kt
index aa2c994..0693195 100644
--- a/src/test/kotlin/com/flightfeather/obd/Test.kt
+++ b/src/test/kotlin/com/flightfeather/obd/Test.kt
@@ -99,4 +99,32 @@
         }
         println(bcc.toString(16))
     }
+
+    @Test
+    fun foo11() {
+        val b = mutableListOf<String>().apply {
+            add("13")
+            add("09")
+            add("10")
+            add("10")
+            add("2b")
+            add("2f")
+        }
+        if (b.size < 6) {
+            println("null")
+        }
+
+        val year = b[0].toInt(16) + 2000
+        if (year < 2000 || year > 2099) println("null")
+        val month = b[1].toInt(16)
+        val day = b[2].toInt(16)
+        val hour = b[3].toInt(16)
+        val min = b[4].toInt(16)
+        val sec = b[5].toInt(16)
+        val cal  = Calendar.getInstance().apply {
+            set(year, month - 1, day, hour, min, sec)
+        }
+
+        println(SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(cal.time))
+    }
 }
\ No newline at end of file

--
Gitblit v1.9.3