From 14ce5d2ccfae554497763da846ffb9eb39cd6d34 Mon Sep 17 00:00:00 2001
From: riku <risaku@163.com>
Date: 星期一, 23 九月 2019 12:55:26 +0800
Subject: [PATCH] 1. 修改实时数据各项的转换逻辑
---
src/main/kotlin/com/flightfeather/obd/repository/CarLoginRepository.kt | 6
src/main/kotlin/com/flightfeather/obd/repository/impl/ObdInfoDaoImpl.kt | 26 ++
src/test/kotlin/com/flightfeather/obd/Test.kt | 8
src/main/kotlin/com/flightfeather/obd/repository/impl/CarLoginDaoImpl.kt | 28 +++
src/main/kotlin/com/flightfeather/obd/lightshare/bean/DataStreamVo.kt | 42 ++++
src/main/kotlin/com/flightfeather/obd/repository/ObdInfoRepository.kt | 6
src/main/kotlin/com/flightfeather/obd/repository/impl/DataStreamDaoImpl.kt | 62 ++++++
src/main/kotlin/com/flightfeather/obd/repository/DataStreamRepository.kt | 12 +
src/main/kotlin/com/flightfeather/obd/lightshare/bean/LatLngVo.kt | 14 +
src/main/kotlin/com/flightfeather/obd/common/Contanst.kt | 9 +
src/main/kotlin/com/flightfeather/obd/socket/decoder/impl/RealTimeDataDecoderImpl.kt | 73 +++++---
src/main/kotlin/com/flightfeather/obd/lightshare/bean/CarLoginVo.kt | 16 +
src/main/kotlin/com/flightfeather/obd/lightshare/bean/CarLogoutVo.kt | 15 +
src/main/kotlin/com/flightfeather/obd/lightshare/service/impl/ObdDataServiceImpl.kt | 31 ++
src/main/kotlin/com/flightfeather/obd/socket/decoder/impl/DataUnitDecoderImpl.kt | 5
src/test/kotlin/com/flightfeather/obd/socket/decoder/VehicleDataDecoderTest.kt | 2
src/main/kotlin/com/flightfeather/obd/repository/impl/CarLogoutDaoImpl.kt | 28 +++
src/main/kotlin/com/flightfeather/obd/lightshare/web/ObdDataController.kt | 39 ++++
src/main/kotlin/com/flightfeather/obd/lightshare/bean/ObdInfoVo.kt | 26 ++
src/main/kotlin/com/flightfeather/obd/repository/CarLogoutRepository.kt | 6
src/main/resources/application.yml | 6
src/main/kotlin/com/flightfeather/obd/lightshare/service/ObdDataService.kt | 27 ++
22 files changed, 441 insertions(+), 46 deletions(-)
diff --git a/src/main/kotlin/com/flightfeather/obd/common/Contanst.kt b/src/main/kotlin/com/flightfeather/obd/common/Contanst.kt
new file mode 100644
index 0000000..28ef37b
--- /dev/null
+++ b/src/main/kotlin/com/flightfeather/obd/common/Contanst.kt
@@ -0,0 +1,9 @@
+package com.flightfeather.obd.common
+
+/**
+ * @author riku
+ * Date: 2019/9/20
+ */
+//鍓嶇璁惧浼犺緭鐨勬棤鏁堝��
+const val INVALID_DATA_4_BYTE = "FFFFFFFF"
+const val INVALID_DATA_2_BYTE = "FFFF"
\ No newline at end of file
diff --git a/src/main/kotlin/com/flightfeather/obd/lightshare/bean/CarLoginVo.kt b/src/main/kotlin/com/flightfeather/obd/lightshare/bean/CarLoginVo.kt
new file mode 100644
index 0000000..96bbed5
--- /dev/null
+++ b/src/main/kotlin/com/flightfeather/obd/lightshare/bean/CarLoginVo.kt
@@ -0,0 +1,16 @@
+package com.flightfeather.obd.lightshare.bean
+
+import java.util.*
+
+/**
+ * @author riku
+ * Date: 2019/9/19
+ */
+class CarLoginVo : BaseJson() {
+ var id: Int? = null
+ var obdDeviceCode: String? = null
+ var loginCreateTime: Date? = null
+ var loginDataTime: Date? = null
+ var loginSerialNum: Int? = null
+ var loginSimCode: String? = null
+}
\ No newline at end of file
diff --git a/src/main/kotlin/com/flightfeather/obd/lightshare/bean/CarLogoutVo.kt b/src/main/kotlin/com/flightfeather/obd/lightshare/bean/CarLogoutVo.kt
new file mode 100644
index 0000000..b5b81c5
--- /dev/null
+++ b/src/main/kotlin/com/flightfeather/obd/lightshare/bean/CarLogoutVo.kt
@@ -0,0 +1,15 @@
+package com.flightfeather.obd.lightshare.bean
+
+import java.util.*
+
+/**
+ * @author riku
+ * Date: 2019/9/19
+ */
+class CarLogoutVo : BaseJson() {
+ var id: Int? = null
+ var obdDeviceCode: String? = null
+ var loginCreateTime: Date? = null
+ var loginDataTime: Date? = null
+ var loginSerialNum: Int? = null
+}
\ No newline at end of file
diff --git a/src/main/kotlin/com/flightfeather/obd/lightshare/bean/DataStreamVo.kt b/src/main/kotlin/com/flightfeather/obd/lightshare/bean/DataStreamVo.kt
new file mode 100644
index 0000000..e512424
--- /dev/null
+++ b/src/main/kotlin/com/flightfeather/obd/lightshare/bean/DataStreamVo.kt
@@ -0,0 +1,42 @@
+package com.flightfeather.obd.lightshare.bean
+
+import java.util.*
+
+/**
+ * @author riku
+ * Date: 2019/9/19
+ */
+class DataStreamVo : BaseJson() {
+ var id: Int?= null
+ var obdDeviceCode: String?= null
+ var obdCreateTime: Date?= null
+ var obdDataTime: Date?= null
+ var obdSerialNum: Int?= null
+ var obdSpeed: Double?= null
+ var obdAirPressure: Double?= null
+ var obdEngineTorque: Double?= null
+ var obdFrictionTorque: Double?= null
+ var obdEngineRpm: Double?= null
+ var obdEngineFuelFlow: Double?= null
+ var obdScrUpstreamNox: Double?= null
+ var obdScrDownstreamNox: Double?= null
+ var obdRemainReactant: Double?= null
+ var obdAirInput: Double?= null
+ var obdScrInputTemp: Double?= null
+ var obdScrOutputTemp: Double?= null
+ var obdDpf: Double?= null
+ var obdEngineCoolantTemp: Double?= null
+ var obdFuelLevel: Double?= null
+ var obdLocationStatus: String?= null
+ var obdLong: Double?= null
+ var obdLat: Double?= null
+ var obdTotalMileage: Double?= null
+ var obdEngineTorqueMode: Int?= null
+ var obdAcceleratorPedal: Double?= null
+ var obdTotalOilConsumption: Double?= null
+ var obdUreaBoxTemp: Double?= null
+ var obdUreaVolume: Double?= null
+ var obdTotalUreaConsume: Double?= null
+ var obdDpfTemp: Double?= null
+ var obdStatus: Boolean?= null
+}
\ No newline at end of file
diff --git a/src/main/kotlin/com/flightfeather/obd/lightshare/bean/LatLngVo.kt b/src/main/kotlin/com/flightfeather/obd/lightshare/bean/LatLngVo.kt
new file mode 100644
index 0000000..6f2ba15
--- /dev/null
+++ b/src/main/kotlin/com/flightfeather/obd/lightshare/bean/LatLngVo.kt
@@ -0,0 +1,14 @@
+package com.flightfeather.obd.lightshare.bean
+
+import java.util.*
+
+/**
+ * @author riku
+ * Date: 2019/9/19
+ */
+class LatLngVo : BaseJson() {
+ var deviceCode: String? = null
+ var obdDataTime: Date?= null
+ var lat: Double? = null
+ var lng: Double? = null
+}
\ No newline at end of file
diff --git a/src/main/kotlin/com/flightfeather/obd/lightshare/bean/ObdInfoVo.kt b/src/main/kotlin/com/flightfeather/obd/lightshare/bean/ObdInfoVo.kt
new file mode 100644
index 0000000..731a77a
--- /dev/null
+++ b/src/main/kotlin/com/flightfeather/obd/lightshare/bean/ObdInfoVo.kt
@@ -0,0 +1,26 @@
+package com.flightfeather.obd.lightshare.bean
+
+import java.util.*
+
+/**
+ * @author riku
+ * Date: 2019/9/19
+ */
+class ObdInfoVo : BaseJson() {
+ var id: Int?= null
+ var obdDeviceCode: String?= null
+ var obdCreateTime: Date?= null
+ var obdDataTime: Date?= null
+ var obdSerialNum: Int?= null
+ var obdProtocol: Int?= null
+ var obdMil: Int?= null
+ var obdDiagnosisSupportStatus: String?= null
+ var obdDiagnosisReadyStatus: String?= null
+ var obdVin: String?= null
+ var obdCrn: String?= null
+ var obdCvn: String?= null
+ var obdIupr: String?= null
+ var obdFaultCodeNum: Int?= null
+ var obdFaultCode: String?= null
+ var obdStatus: Boolean?= null
+}
\ No newline at end of file
diff --git a/src/main/kotlin/com/flightfeather/obd/lightshare/service/ObdDataService.kt b/src/main/kotlin/com/flightfeather/obd/lightshare/service/ObdDataService.kt
index 2df9280..751500b 100644
--- a/src/main/kotlin/com/flightfeather/obd/lightshare/service/ObdDataService.kt
+++ b/src/main/kotlin/com/flightfeather/obd/lightshare/service/ObdDataService.kt
@@ -1,6 +1,6 @@
package com.flightfeather.obd.lightshare.service
-import com.flightfeather.obd.lightshare.bean.ObdDataVo
+import com.flightfeather.obd.lightshare.bean.*
/**
* @author riku
@@ -13,4 +13,29 @@
*/
fun getDataByVinCode(vinCode: String, pageNum: Int?, pageSize: Int?): MutableList<ObdDataVo>
+ /**
+ * 鏍规嵁缁堢璁惧鐮佽幏鍙栫櫥褰曟暟鎹�
+ */
+ fun getLoginData(deviceCode: String, pageNum: Int?, pageSize: Int?, startTime: String?, endTime: String?): List<CarLoginVo>
+
+ /**
+ * 鏍规嵁缁堢璁惧鐮佽幏鍙栫櫥鍑烘暟鎹�
+ */
+ fun getLogoutData(deviceCode: String, pageNum: Int?, pageSize: Int?, startTime: String?, endTime: String?): List<CarLogoutVo>
+
+ /**
+ * 鏍规嵁缁堢璁惧鐮佽幏鍙杘bd鏁版嵁
+ */
+ fun getObdInfo(deviceCode: String, pageNum: Int?, pageSize: Int?): List<ObdInfoVo>
+
+ /**
+ * 鏍规嵁缁堢璁惧鐮佽幏鍙栨暟鎹祦鏁版嵁
+ */
+ fun getDataStream(deviceCode: String, pageNum: Int?, pageSize: Int?, startTime: String?, endTime: String?): List<DataStreamVo>
+
+ /**
+ * 鏍规嵁缁堢璁惧鐮佽幏鍙栨渶鏂扮粡绾害
+ */
+ fun getCoordinate(deviceCode: String): LatLngVo
+
}
\ No newline at end of file
diff --git a/src/main/kotlin/com/flightfeather/obd/lightshare/service/impl/ObdDataServiceImpl.kt b/src/main/kotlin/com/flightfeather/obd/lightshare/service/impl/ObdDataServiceImpl.kt
index 592810c..afe9da7 100644
--- a/src/main/kotlin/com/flightfeather/obd/lightshare/service/impl/ObdDataServiceImpl.kt
+++ b/src/main/kotlin/com/flightfeather/obd/lightshare/service/impl/ObdDataServiceImpl.kt
@@ -1,8 +1,8 @@
package com.flightfeather.obd.lightshare.service.impl
-import com.flightfeather.obd.lightshare.bean.ObdDataVo
+import com.flightfeather.obd.lightshare.bean.*
import com.flightfeather.obd.lightshare.service.ObdDataService
-import com.flightfeather.obd.repository.ObdDataRepository
+import com.flightfeather.obd.repository.*
import org.springframework.stereotype.Service
/**
@@ -10,10 +10,29 @@
* Date: 2019/8/27
*/
@Service
-class ObdDataServiceImpl(val obdDataRepository: ObdDataRepository) : ObdDataService {
+class ObdDataServiceImpl(
+ val obdDataRepository: ObdDataRepository,
+ val carLoginRepository: CarLoginRepository,
+ val carLogoutRepository: CarLogoutRepository,
+ val obdInfoRepository: ObdInfoRepository,
+ val dataStreamRepository: DataStreamRepository
+) : ObdDataService {
- override fun getDataByVinCode(vinCode: String, pageNum: Int?, pageSize: Int?): MutableList<ObdDataVo> {
- return obdDataRepository.getDataByVinCode(vinCode, pageNum, pageSize)
- }
+ override fun getDataByVinCode(vinCode: String, pageNum: Int?, pageSize: Int?): MutableList<ObdDataVo>
+ = obdDataRepository.getDataByVinCode(vinCode, pageNum, pageSize)
+ override fun getLoginData(deviceCode: String, pageNum: Int?, pageSize: Int?, startTime: String?, endTime: String?): List<CarLoginVo>
+ = carLoginRepository.getLoginData(deviceCode, pageNum, pageSize, startTime, endTime)
+
+ override fun getLogoutData(deviceCode: String, pageNum: Int?, pageSize: Int?, startTime: String?, endTime: String?): List<CarLogoutVo>
+ = carLogoutRepository.getLogoutData(deviceCode, pageNum, pageSize, startTime, endTime)
+
+ override fun getObdInfo(deviceCode: String, pageNum: Int?, pageSize: Int?): List<ObdInfoVo>
+ = obdInfoRepository.getObdInfo(deviceCode, pageNum, pageSize)
+
+ override fun getDataStream(deviceCode: String, pageNum: Int?, pageSize: Int?, startTime: String?, endTime: String?): List<DataStreamVo>
+ = dataStreamRepository.getDataStream(deviceCode, pageNum, pageSize, startTime, endTime)
+
+ override fun getCoordinate(deviceCode: String): LatLngVo
+ = dataStreamRepository.getCoordinate(deviceCode)
}
\ No newline at end of file
diff --git a/src/main/kotlin/com/flightfeather/obd/lightshare/web/ObdDataController.kt b/src/main/kotlin/com/flightfeather/obd/lightshare/web/ObdDataController.kt
index 31b2e7c..04ebc19 100644
--- a/src/main/kotlin/com/flightfeather/obd/lightshare/web/ObdDataController.kt
+++ b/src/main/kotlin/com/flightfeather/obd/lightshare/web/ObdDataController.kt
@@ -17,4 +17,43 @@
@RequestParam("page", required = false) pageNum: Int?,
@RequestParam("per_page", required = false) pageSize: Int?
) = obdDataService.getDataByVinCode(vinCode, pageNum, pageSize)
+
+ @GetMapping("/login/{deviceCode}")
+ fun getLoginData(
+ @PathVariable("deviceCode") deviceCode: String,
+ @RequestParam("page", required = false) pageNum: Int?,
+ @RequestParam("per_page", required = false) pageSize: Int?,
+ @RequestParam("startTime", required = false) startTime: String?,
+ @RequestParam("endTime", required = false) endTime: String?
+ ) = obdDataService.getLoginData(deviceCode, pageNum, pageSize, startTime, endTime)
+
+ @GetMapping("/logout/{deviceCode}")
+ fun getLogoutData(
+ @PathVariable("deviceCode") deviceCode: String,
+ @RequestParam("page", required = false) pageNum: Int?,
+ @RequestParam("per_page", required = false) pageSize: Int?,
+ @RequestParam("startTime", required = false) startTime: String?,
+ @RequestParam("endTime", required = false) endTime: String?
+ ) = obdDataService.getLogoutData(deviceCode, pageNum, pageSize, startTime, endTime)
+
+ @GetMapping("/obdInfo/{deviceCode}")
+ fun getObdInfo(
+ @PathVariable("deviceCode") deviceCode: String,
+ @RequestParam("page", required = false) pageNum: Int?,
+ @RequestParam("per_page", required = false) pageSize: Int?
+ ) = obdDataService.getObdInfo(deviceCode, pageNum, pageSize)
+
+ @GetMapping("/dataStream/{deviceCode}")
+ fun getDataStream(
+ @PathVariable("deviceCode") deviceCode: String,
+ @RequestParam("page", required = false) pageNum: Int?,
+ @RequestParam("per_page", required = false) pageSize: Int?,
+ @RequestParam("startTime", required = false) startTime: String?,
+ @RequestParam("endTime", required = false) endTime: String?
+ ) = obdDataService.getDataStream(deviceCode, pageNum, pageSize, startTime, endTime)
+
+ @GetMapping("/coordinate/{deviceCode}")
+ fun getCoordinate(
+ @PathVariable("deviceCode") deviceCode: String
+ ) = obdDataService.getCoordinate(deviceCode)
}
\ No newline at end of file
diff --git a/src/main/kotlin/com/flightfeather/obd/repository/CarLoginRepository.kt b/src/main/kotlin/com/flightfeather/obd/repository/CarLoginRepository.kt
index 19898a1..fc586ec 100644
--- a/src/main/kotlin/com/flightfeather/obd/repository/CarLoginRepository.kt
+++ b/src/main/kotlin/com/flightfeather/obd/repository/CarLoginRepository.kt
@@ -1,5 +1,6 @@
package com.flightfeather.obd.repository
+import com.flightfeather.obd.lightshare.bean.CarLoginVo
import com.flightfeather.obd.socket.bean.ObdPackageData
/**
@@ -12,4 +13,9 @@
* 淇濆瓨杞﹁締鐧诲叆淇℃伅
*/
fun saveCarLogin(packageData: ObdPackageData): Boolean
+
+ /**
+ * 鏍规嵁缁堢璁惧鐮佽幏鍙栫櫥褰曟暟鎹�
+ */
+ fun getLoginData(deviceCode: String, pageNum: Int?, pageSize: Int?, startTime: String?, endTime: String?): List<CarLoginVo>
}
\ No newline at end of file
diff --git a/src/main/kotlin/com/flightfeather/obd/repository/CarLogoutRepository.kt b/src/main/kotlin/com/flightfeather/obd/repository/CarLogoutRepository.kt
index 937408d..e8653ab 100644
--- a/src/main/kotlin/com/flightfeather/obd/repository/CarLogoutRepository.kt
+++ b/src/main/kotlin/com/flightfeather/obd/repository/CarLogoutRepository.kt
@@ -1,5 +1,6 @@
package com.flightfeather.obd.repository
+import com.flightfeather.obd.lightshare.bean.CarLogoutVo
import com.flightfeather.obd.socket.bean.ObdPackageData
/**
@@ -12,4 +13,9 @@
* 淇濆瓨 杞﹁締鐧诲嚭鍏ヤ俊鎭�
*/
fun saveCarLogout(packageData: ObdPackageData): Boolean
+
+ /**
+ * 鏍规嵁缁堢璁惧鐮佽幏鍙栫櫥鍑烘暟鎹�
+ */
+ fun getLogoutData(deviceCode: String, pageNum: Int?, pageSize: Int?, startTime: String?, endTime: String?): List<CarLogoutVo>
}
\ No newline at end of file
diff --git a/src/main/kotlin/com/flightfeather/obd/repository/DataStreamRepository.kt b/src/main/kotlin/com/flightfeather/obd/repository/DataStreamRepository.kt
index 3270ce4..45a2dcb 100644
--- a/src/main/kotlin/com/flightfeather/obd/repository/DataStreamRepository.kt
+++ b/src/main/kotlin/com/flightfeather/obd/repository/DataStreamRepository.kt
@@ -1,5 +1,7 @@
package com.flightfeather.obd.repository
+import com.flightfeather.obd.lightshare.bean.DataStreamVo
+import com.flightfeather.obd.lightshare.bean.LatLngVo
import com.flightfeather.obd.socket.bean.ObdPackageData
/**
@@ -12,4 +14,14 @@
* 淇濆瓨 瀹炴椂淇℃伅鎴栬ˉ浼犱俊鎭� 涓殑 鏁版嵁娴佷俊鎭� 鍜� 琛ュ厖鏁版嵁娴�
*/
fun saveDataStream(packageData: ObdPackageData): Boolean
+
+ /**
+ * 鏍规嵁缁堢璁惧鐮佽幏鍙栨暟鎹祦鏁版嵁
+ */
+ fun getDataStream(deviceCode: String, pageNum: Int?, pageSize: Int?, startTime: String?, endTime: String?): List<DataStreamVo>
+
+ /**
+ * 鏍规嵁缁堢璁惧鐮佽幏鍙栨渶鏂扮粡绾害
+ */
+ fun getCoordinate(deviceCode: String): LatLngVo
}
\ No newline at end of file
diff --git a/src/main/kotlin/com/flightfeather/obd/repository/ObdInfoRepository.kt b/src/main/kotlin/com/flightfeather/obd/repository/ObdInfoRepository.kt
index fb07c09..99a6d1b 100644
--- a/src/main/kotlin/com/flightfeather/obd/repository/ObdInfoRepository.kt
+++ b/src/main/kotlin/com/flightfeather/obd/repository/ObdInfoRepository.kt
@@ -1,5 +1,6 @@
package com.flightfeather.obd.repository
+import com.flightfeather.obd.lightshare.bean.ObdInfoVo
import com.flightfeather.obd.socket.bean.ObdInfo
import com.flightfeather.obd.socket.bean.ObdPackageData
import com.flightfeather.obd.socket.bean.RealTimeData
@@ -15,4 +16,9 @@
* 淇濆瓨 瀹炴椂淇℃伅 @see [RealTimeData] 鎴栬ˉ浼犱俊鎭� @see [ReplacementData] 涓殑 obd 鏁版嵁 @see [ObdInfo]
*/
fun saveObdInfo(packageData: ObdPackageData): Boolean
+
+ /**
+ * 鏍规嵁缁堢璁惧鐮佽幏鍙杘bd鏁版嵁
+ */
+ fun getObdInfo(deviceCode: String, pageNum: Int?, pageSize: Int?): List<ObdInfoVo>
}
\ No newline at end of file
diff --git a/src/main/kotlin/com/flightfeather/obd/repository/impl/CarLoginDaoImpl.kt b/src/main/kotlin/com/flightfeather/obd/repository/impl/CarLoginDaoImpl.kt
index 2142299..a86b8f8 100644
--- a/src/main/kotlin/com/flightfeather/obd/repository/impl/CarLoginDaoImpl.kt
+++ b/src/main/kotlin/com/flightfeather/obd/repository/impl/CarLoginDaoImpl.kt
@@ -2,11 +2,15 @@
import com.flightfeather.obd.domain.entity.CarLogin
import com.flightfeather.obd.domain.mapper.CarLoginMapper
+import com.flightfeather.obd.lightshare.bean.CarLoginVo
import com.flightfeather.obd.repository.CarLoginRepository
import com.flightfeather.obd.socket.bean.CarRegisterData
import com.flightfeather.obd.socket.bean.ObdPackageData
import com.flightfeather.obd.socket.eunm.ObdCommandUnit
+import com.github.pagehelper.PageHelper
+import org.springframework.beans.BeanUtils
import org.springframework.stereotype.Repository
+import tk.mybatis.mapper.entity.Example
/**
* @author riku
@@ -37,4 +41,28 @@
false
}
}
+
+ override fun getLoginData(deviceCode: String, pageNum: Int?, pageSize: Int?, startTime: String?, endTime: String?): List<CarLoginVo> {
+ val example = Example(CarLogin::class.java).apply {
+ createCriteria().andEqualTo("obdDeviceCode", deviceCode).run {
+ startTime?.let { andGreaterThanOrEqualTo("loginDataTime", it) }
+ endTime?.let { andLessThanOrEqualTo("loginDataTime", it) }
+ orderBy("loginDataTime").desc()
+ }
+ }
+
+ //鍒嗛〉
+ val offset = (pageSize?.times(pageNum?.minus(1) ?: 0)) ?: 0
+ PageHelper.offsetPage<CarLogin>(offset, pageSize ?: 10)
+ val result = carLoginMapper.selectByExample(example)
+
+ val resultList = mutableListOf<CarLoginVo>()
+ result.forEach {
+ val vo = CarLoginVo()
+ BeanUtils.copyProperties(it, vo)
+ resultList.add(vo)
+ }
+
+ return resultList
+ }
}
\ No newline at end of file
diff --git a/src/main/kotlin/com/flightfeather/obd/repository/impl/CarLogoutDaoImpl.kt b/src/main/kotlin/com/flightfeather/obd/repository/impl/CarLogoutDaoImpl.kt
index 303ff03..43f6201 100644
--- a/src/main/kotlin/com/flightfeather/obd/repository/impl/CarLogoutDaoImpl.kt
+++ b/src/main/kotlin/com/flightfeather/obd/repository/impl/CarLogoutDaoImpl.kt
@@ -2,11 +2,15 @@
import com.flightfeather.obd.domain.entity.CarLogout
import com.flightfeather.obd.domain.mapper.CarLogoutMapper
+import com.flightfeather.obd.lightshare.bean.CarLogoutVo
import com.flightfeather.obd.repository.CarLogoutRepository
import com.flightfeather.obd.socket.bean.CarLogOutData
import com.flightfeather.obd.socket.bean.ObdPackageData
import com.flightfeather.obd.socket.eunm.ObdCommandUnit
+import com.github.pagehelper.PageHelper
+import org.springframework.beans.BeanUtils
import org.springframework.stereotype.Repository
+import tk.mybatis.mapper.entity.Example
/**
* @author riku
@@ -34,4 +38,28 @@
false
}
}
+
+ override fun getLogoutData(deviceCode: String, pageNum: Int?, pageSize: Int?, startTime: String?, endTime: String?): List<CarLogoutVo> {
+ val example = Example(CarLogout::class.java).apply {
+ createCriteria().andEqualTo("obdDeviceCode", deviceCode).run {
+ startTime?.let { andGreaterThanOrEqualTo("loginDataTime", it) }
+ endTime?.let { andLessThanOrEqualTo("loginDataTime", it) }
+ orderBy("loginDataTime").desc()
+ }
+ }
+
+ //鍒嗛〉
+ val offset = (pageSize?.times(pageNum?.minus(1) ?: 0)) ?: 0
+ PageHelper.offsetPage<CarLogout>(offset, pageSize ?: 10)
+ val result = carLogoutMapper.selectByExample(example)
+
+ val resultList = mutableListOf<CarLogoutVo>()
+ result.forEach {
+ val vo = CarLogoutVo()
+ BeanUtils.copyProperties(it, vo)
+ resultList.add(vo)
+ }
+
+ return resultList
+ }
}
\ No newline at end of file
diff --git a/src/main/kotlin/com/flightfeather/obd/repository/impl/DataStreamDaoImpl.kt b/src/main/kotlin/com/flightfeather/obd/repository/impl/DataStreamDaoImpl.kt
index 12d1583..927f206 100644
--- a/src/main/kotlin/com/flightfeather/obd/repository/impl/DataStreamDaoImpl.kt
+++ b/src/main/kotlin/com/flightfeather/obd/repository/impl/DataStreamDaoImpl.kt
@@ -2,13 +2,19 @@
import com.flightfeather.obd.domain.entity.DataStream
import com.flightfeather.obd.domain.mapper.DataStreamMapper
+import com.flightfeather.obd.lightshare.bean.DataStreamVo
+import com.flightfeather.obd.lightshare.bean.LatLngVo
import com.flightfeather.obd.repository.DataStreamRepository
import com.flightfeather.obd.socket.bean.EngineDataStream
import com.flightfeather.obd.socket.bean.ObdPackageData
import com.flightfeather.obd.socket.bean.ReplacementData
import com.flightfeather.obd.socket.bean.SupplementDataStream
import com.flightfeather.obd.socket.eunm.ObdCommandUnit
+import com.github.pagehelper.PageHelper
+import org.springframework.beans.BeanUtils
import org.springframework.stereotype.Repository
+import tk.mybatis.mapper.entity.Example
+import java.text.SimpleDateFormat
/**
* @author riku
@@ -73,4 +79,60 @@
}
}
+ override fun getDataStream(deviceCode: String, pageNum: Int?, pageSize: Int?, startTime: String?, endTime: String?): List<DataStreamVo> {
+ val sf = SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
+ val example = Example(DataStream::class.java).apply {
+ createCriteria().andEqualTo("obdDeviceCode", deviceCode).run {
+ startTime?.let {
+ val st = sf.parse(startTime)
+ andGreaterThanOrEqualTo("obdDataTime", st)
+ }
+ endTime?.let {
+ val et = sf.parse(endTime)
+ andLessThanOrEqualTo("obdDataTime", et)
+ }
+ orderBy("obdDataTime").desc()
+ }
+ }
+
+ //鍒嗛〉
+ val offset = (pageSize?.times(pageNum?.minus(1) ?: 0)) ?: 0
+ PageHelper.offsetPage<DataStream>(offset, pageSize ?: 10)
+ val result = dataStreamMapper.selectByExample(example)
+
+ val resultList = mutableListOf<DataStreamVo>()
+ result.forEach {
+ val vo = DataStreamVo()
+ BeanUtils.copyProperties(it, vo)
+ resultList.add(vo)
+ }
+
+ return resultList
+ }
+
+ override fun getCoordinate(deviceCode: String): LatLngVo {
+ val example = Example(DataStream::class.java).apply {
+ createCriteria().andEqualTo("obdDeviceCode", deviceCode).run {
+ orderBy("obdDataTime").desc()
+ }
+ }
+
+ //鑾峰彇鏈�鏂扮殑涓�涓�
+ PageHelper.offsetPage<DataStream>(0, 1)
+ val result = dataStreamMapper.selectByExample(example)
+
+ val latLngVo = LatLngVo()
+ if (result.isNotEmpty()) {
+ result[0].let {
+ latLngVo.apply {
+ this.deviceCode = it.obdDeviceCode
+ obdDataTime = it.obdDataTime
+ lat = it.obdLat
+ lng = it.obdLong
+ }
+ }
+ }
+
+ return latLngVo
+ }
}
\ No newline at end of file
diff --git a/src/main/kotlin/com/flightfeather/obd/repository/impl/ObdInfoDaoImpl.kt b/src/main/kotlin/com/flightfeather/obd/repository/impl/ObdInfoDaoImpl.kt
index 99fe315..69d464f 100644
--- a/src/main/kotlin/com/flightfeather/obd/repository/impl/ObdInfoDaoImpl.kt
+++ b/src/main/kotlin/com/flightfeather/obd/repository/impl/ObdInfoDaoImpl.kt
@@ -2,10 +2,14 @@
import com.flightfeather.obd.domain.entity.ObdInfo
import com.flightfeather.obd.domain.mapper.ObdInfoMapper
+import com.flightfeather.obd.lightshare.bean.ObdInfoVo
import com.flightfeather.obd.repository.ObdInfoRepository
import com.flightfeather.obd.socket.bean.ObdPackageData
import com.flightfeather.obd.socket.eunm.ObdCommandUnit
+import com.github.pagehelper.PageHelper
+import org.springframework.beans.BeanUtils
import org.springframework.stereotype.Repository
+import tk.mybatis.mapper.entity.Example
/**
* @author riku
@@ -49,7 +53,27 @@
} else {
false
}
-
}
+ override fun getObdInfo(deviceCode: String, pageNum: Int?, pageSize: Int?): List<ObdInfoVo> {
+ val example = Example(ObdInfo::class.java).apply {
+ createCriteria().andEqualTo("obdDeviceCode", deviceCode).run {
+ orderBy("obdDataTime").desc()
+ }
+ }
+
+ //鍒嗛〉
+ val offset = (pageSize?.times(pageNum?.minus(1) ?: 0)) ?: 0
+ PageHelper.offsetPage<ObdInfo>(offset, pageSize ?: 10)
+ val result = obdInfoMapper.selectByExample(example)
+
+ val resultList = mutableListOf<ObdInfoVo>()
+ result.forEach {
+ val vo = ObdInfoVo()
+ BeanUtils.copyProperties(it, vo)
+ resultList.add(vo)
+ }
+
+ return resultList
+ }
}
\ No newline at end of file
diff --git a/src/main/kotlin/com/flightfeather/obd/socket/decoder/impl/DataUnitDecoderImpl.kt b/src/main/kotlin/com/flightfeather/obd/socket/decoder/impl/DataUnitDecoderImpl.kt
index a2875b4..ecc85ab 100644
--- a/src/main/kotlin/com/flightfeather/obd/socket/decoder/impl/DataUnitDecoderImpl.kt
+++ b/src/main/kotlin/com/flightfeather/obd/socket/decoder/impl/DataUnitDecoderImpl.kt
@@ -4,6 +4,7 @@
import com.flightfeather.obd.socket.decoder.DataUnitDecoder
import com.flightfeather.obd.socket.decoder.RealTimeDataDecoder
import com.flightfeather.obd.socket.eunm.ObdDataType
+import org.slf4j.LoggerFactory
import java.lang.StringBuilder
import java.util.*
@@ -13,6 +14,7 @@
*/
class DataUnitDecoderImpl : DataUnitDecoder {
+ private val logger = LoggerFactory.getLogger(javaClass.name)
private var realTimeDataDecoder: RealTimeDataDecoder = RealTimeDataDecoderImpl()
override fun getCarRegisterData(b: List<String>): List<CarRegisterData> {
@@ -83,7 +85,8 @@
}
}else if (dataList.isNotEmpty()) {
//鎸夌収瑙勫垯娌℃湁鍙栧埌淇℃伅浣擄紝骞朵笖鍘熸暟鎹笉涓虹┖锛岃〃绀哄師鏁版嵁鏍煎紡閿欒锛岄��鍑哄惊鐜�
-// break
+ logger.error("-------鏁版嵁淇℃伅娴佹垨琛ュ厖鏁版嵁娴佹牸寮忛敊璇�")
+ break
}
}
diff --git a/src/main/kotlin/com/flightfeather/obd/socket/decoder/impl/RealTimeDataDecoderImpl.kt b/src/main/kotlin/com/flightfeather/obd/socket/decoder/impl/RealTimeDataDecoderImpl.kt
index ce920ae..7c401c1 100644
--- a/src/main/kotlin/com/flightfeather/obd/socket/decoder/impl/RealTimeDataDecoderImpl.kt
+++ b/src/main/kotlin/com/flightfeather/obd/socket/decoder/impl/RealTimeDataDecoderImpl.kt
@@ -1,5 +1,6 @@
package com.flightfeather.obd.socket.decoder.impl
+import com.flightfeather.obd.common.INVALID_DATA_4_BYTE
import com.flightfeather.obd.socket.bean.EngineDataStream
import com.flightfeather.obd.socket.bean.ObdInfo
import com.flightfeather.obd.socket.bean.SupplementDataStream
@@ -72,25 +73,31 @@
return if (dataList.size >= 37) {
EngineDataStream(time, serialNum).apply {
- obdSpeed = "${dataList[0]}${dataList[1]}".toIntOrNull(16)?.toDouble()?.times((1 / 256).toDouble())
+ obdSpeed = "${dataList[0]}${dataList[1]}".toIntOrNull(16)?.toDouble()?.div(256)
obdAirPressure = dataList[2].toIntOrNull(16)?.toDouble()?.times(0.5)
obdEngineTorque = dataList[3].toIntOrNull(16)?.minus(125)?.toDouble()?.div(100)
obdFrictionTorque = dataList[4].toIntOrNull(16)?.minus(125)?.toDouble()?.div(100)
obdEngineRpm = "${dataList[5]}${dataList[6]}".toIntOrNull(16)?.toDouble()?.times(0.125)
obdEngineFuelFlow = "${dataList[7]}${dataList[8]}".toIntOrNull(16)?.toDouble()?.times(0.05)
- obdScrUpstreamNox = "${dataList[9]}${dataList[10]}".toIntOrNull(16)?.minus(200)?.toDouble()?.times(0.05)
- obdScrDownstreamNox = "${dataList[11]}${dataList[12]}".toIntOrNull(16)?.minus(200)?.toDouble()?.times(0.05)
+ obdScrUpstreamNox = "${dataList[9]}${dataList[10]}".toIntOrNull(16)?.times(0.05)?.minus(200)
+ obdScrDownstreamNox = "${dataList[11]}${dataList[12]}".toIntOrNull(16)?.times(0.05)?.minus(200)
obdRemainReactant = dataList[13].toIntOrNull(16)?.toDouble()?.times(0.4)?.div(100)
obdAirInput = "${dataList[14]}${dataList[15]}".toIntOrNull(16)?.toDouble()?.times(0.05)
- obdScrInputTemp = "${dataList[16]}${dataList[17]}".toIntOrNull(16)?.minus(273)?.toDouble()?.times(0.03125)
- obdScrOutputTemp = "${dataList[18]}${dataList[19]}".toIntOrNull(16)?.minus(273)?.toDouble()?.times(0.03125)
+ obdScrInputTemp = "${dataList[16]}${dataList[17]}".toIntOrNull(16)?.times(0.03125)?.minus(273)
+ obdScrOutputTemp = "${dataList[18]}${dataList[19]}".toIntOrNull(16)?.times(0.03125)?.minus(273)
obdDpf = "${dataList[20]}${dataList[21]}".toIntOrNull(16)?.toDouble()?.times(0.1)
obdEngineCoolantTemp = dataList[22].toIntOrNull(16)?.minus(40)?.toDouble()
obdFuelLevel = dataList[23].toIntOrNull(16)?.toDouble()?.times(0.4)
obdLocationStatus = dataList[24].toIntOrNull(16)
- obdLong = "${dataList[25]}${dataList[26]}${dataList[27]}${dataList[28]}".toIntOrNull(16)?.toDouble()?.times(0.000001)
- obdLat = "${dataList[29]}${dataList[30]}${dataList[31]}${dataList[32]}".toIntOrNull(16)?.toDouble()?.times(0.000001)
- obdTotalMileage = "${dataList[33]}${dataList[34]}${dataList[35]}${dataList[36]}".toIntOrNull(16)?.toDouble()?.times(0.1)
+ with("${dataList[25]}${dataList[26]}${dataList[27]}${dataList[28]}") {
+ obdLong = if (toUpperCase() == INVALID_DATA_4_BYTE) { -1.0 } else { toBigIntegerOrNull(16)?.toDouble()?.times(0.000001) }
+ }
+ with("${dataList[29]}${dataList[30]}${dataList[31]}${dataList[32]}") {
+ obdLat = if (toUpperCase() == INVALID_DATA_4_BYTE) { -1.0 } else { toBigIntegerOrNull(16)?.toDouble()?.times(0.000001) }
+ }
+ with("${dataList[33]}${dataList[34]}${dataList[35]}${dataList[36]}") {
+ obdTotalMileage = if (toUpperCase() == INVALID_DATA_4_BYTE) { -1.0 } else { toBigIntegerOrNull(16)?.toDouble()?.times(0.1) }
+ }
}
} else {
null
@@ -108,11 +115,17 @@
SupplementDataStream(time, serialNum).apply {
obdEngineTorqueMode = dataList[0].toIntOrNull(16)
obdAcceleratorPedal = dataList[1].toIntOrNull(16)?.toDouble()?.times(0.4)?.div(100)
- obdTotalOilConsumption = "${dataList[2]}${dataList[3]}${dataList[4]}${dataList[5]}".toIntOrNull(16)?.toDouble()?.times(0.5)
+ with("${dataList[2]}${dataList[3]}${dataList[4]}${dataList[5]}") {
+ obdTotalOilConsumption = if (toUpperCase() == INVALID_DATA_4_BYTE) -1.0 else toBigIntegerOrNull(16)?.toDouble()?.times(0.5)
+ }
obdUreaBoxTemp = dataList[6].toIntOrNull(16)?.toDouble()?.minus(40)
- obdUreaVolume = "${dataList[7]}${dataList[8]}${dataList[9]}${dataList[10]}".toIntOrNull(16)?.toDouble()?.times(0.01)
- obdTotalUreaConsume = "${dataList[11]}${dataList[12]}${dataList[13]}${dataList[14]}".toIntOrNull(16)?.toDouble()
- obdDpfTemp = "${dataList[15]}${dataList[16]}".toIntOrNull(16)?.minus(273)?.toDouble()?.times(0.03125)
+ with("${dataList[7]}${dataList[8]}${dataList[9]}${dataList[10]}") {
+ obdUreaVolume = if (toUpperCase() == INVALID_DATA_4_BYTE) -1.0 else toBigIntegerOrNull(16)?.toDouble()?.times(0.01)
+ }
+ with("${dataList[11]}${dataList[12]}${dataList[13]}${dataList[14]}") {
+ obdTotalUreaConsume = if (toUpperCase() == INVALID_DATA_4_BYTE) -1.0 else toBigIntegerOrNull(16)?.toDouble()
+ }
+ obdDpfTemp = "${dataList[15]}${dataList[16]}".toIntOrNull(16)?.times(0.03125)?.minus(273)
}
} else {
null
@@ -131,31 +144,37 @@
when (list[0].toIntOrNull(16)) {
ObdDataType.ObdData.value -> {
- //浠庤捣濮嬪瓧鑺� 1 寮�濮嬶紝鍥哄畾鏈�97涓瓧鑺傜殑鏁版嵁
- for (i in 1..96) {
- resultList.add(list[i])
- }
-
- val faultCodeNum = list[96].toIntOrNull() ?: 0//鏁呴殰鐮佹�绘暟
- //鏍规嵁鏁呴殰鐮佹�绘暟锛屾瘡涓晠闅滅爜4涓瓧鑺傦紝寰楀埌鏁呴殰鐮佹�诲瓧鑺傛暟
- if (faultCodeNum in 0..253) {
- for (i in 97..(96 + faultCodeNum * 4)) {
+ if (list.size >= 97) {
+ //浠庤捣濮嬪瓧鑺� 1 寮�濮嬶紝鍥哄畾鏈�96涓瓧鑺傜殑鏁版嵁
+ for (i in 1..96) {
resultList.add(list[i])
+ }
+
+ val faultCodeNum = list[96].toIntOrNull() ?: 0//鏁呴殰鐮佹�绘暟
+ //鏍规嵁鏁呴殰鐮佹�绘暟锛屾瘡涓晠闅滅爜4涓瓧鑺傦紝寰楀埌鏁呴殰鐮佹�诲瓧鑺傛暟
+ if (faultCodeNum in 0..253) {
+ for (i in 97..(96 + faultCodeNum * 4)) {
+ resultList.add(list[i])
+ }
}
}
}
ObdDataType.EngineDataFlow.value -> {
- //浠庤捣濮嬪瓧鑺� 1 寮�濮嬶紝鍥哄畾鏈�37涓瓧鑺傜殑鏁版嵁
- for (i in 1..37) {
- resultList.add(list[i])
+ if (list.size >= 38) {
+ //浠庤捣濮嬪瓧鑺� 1 寮�濮嬶紝鍥哄畾鏈�37涓瓧鑺傜殑鏁版嵁
+ for (i in 1..37) {
+ resultList.add(list[i])
+ }
}
}
ObdDataType.SupplementDataFlow.value -> {
- //浠庤捣濮嬪瓧鑺� 1 寮�濮嬶紝鍥哄畾鏈�17涓瓧鑺傜殑鏁版嵁
- for (i in 1..17) {
- resultList.add(list[i])
+ if (list.size>= 18) {
+ //浠庤捣濮嬪瓧鑺� 1 寮�濮嬶紝鍥哄畾鏈�17涓瓧鑺傜殑鏁版嵁
+ for (i in 1..17) {
+ resultList.add(list[i])
+ }
}
}
}
diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml
index 00493e3..895d090 100644
--- a/src/main/resources/application.yml
+++ b/src/main/resources/application.yml
@@ -1,9 +1,9 @@
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
- url: jdbc:mysql://47.100.191.150:3306/obd?serverTimezone=Asia/Shanghai&prepStmtCacheSize=517&cachePrepStmts=true&autoReconnect=true&characterEncoding=utf-8&allowMultiQueries=true&useSSL=false
- username: obd
- password: obd2019
+ url: jdbc:mysql://192.168.0.200:3306/obd?serverTimezone=Asia/Shanghai&prepStmtCacheSize=517&cachePrepStmts=true&autoReconnect=true&characterEncoding=utf-8&allowMultiQueries=true&useSSL=false
+ username: root
+ password: cn.FLIGHTFEATHER
mybatis:
type-aliases-package: com.flightfeather.obd.domain.entity
diff --git a/src/test/kotlin/com/flightfeather/obd/Test.kt b/src/test/kotlin/com/flightfeather/obd/Test.kt
index 7a7ca8f..f16c654 100644
--- a/src/test/kotlin/com/flightfeather/obd/Test.kt
+++ b/src/test/kotlin/com/flightfeather/obd/Test.kt
@@ -131,12 +131,8 @@
@Test
fun f0012() {
- ByteArray(3).forEach {
- println(it)
- return
- }
-
- println("end")
+ val a = "80ffffff".toBigInteger(16)
+ val b = a?.toDouble()
}
}
\ No newline at end of file
diff --git a/src/test/kotlin/com/flightfeather/obd/socket/decoder/VehicleDataDecoderTest.kt b/src/test/kotlin/com/flightfeather/obd/socket/decoder/VehicleDataDecoderTest.kt
index c9cfda5..261acfa 100644
--- a/src/test/kotlin/com/flightfeather/obd/socket/decoder/VehicleDataDecoderTest.kt
+++ b/src/test/kotlin/com/flightfeather/obd/socket/decoder/VehicleDataDecoderTest.kt
@@ -15,7 +15,7 @@
@Test
fun decode() {
- val msg = "23 23 02 31 37 36 39 31 35 33 31 39 30 39 31 32 30 30 30 32 01 01 00 85 13 09 12 15 01 2d 00 08 01 00 01 60 00 00 00 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 07 00 00 04 20 00 00 04 20 00 00 c1 13 00 00 00 73 00 00 30 28 00 00 30 25 00 00 30 56 1d"
+ val msg = "23 23 02 31 37 36 39 31 35 33 31 39 30 39 31 32 30 30 31 36 01 01 00 40 13 09 17 09 05 29 00 cd 02 17 00 da fd ff 12 c0 ff ff 00 c8 04 ec ff 15 a9 ff ff ff ff ff ff 73 00 00 07 43 ec 88 01 d6 de cc ff ff ff ff 80 ff 00 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff f6"
val msg2 = "23 23 02 31 37 36 39 31 35 33 31 39 30 39 31 32 30 30 30 36 01 01 00 42 13 09 11 08 3b 36 02 00 3b 00 00 d4 00 00 12 c0 09 5e 00 c8 00 c8 00 15 a9 00 00 00 00 00 00 73 00 00 00 b9 1b c7 00 2e e1 25 00 00 00 00 80 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 dc"
val packageData = vehicleDataDecoder.decode(msg)
--
Gitblit v1.9.3