riku
2019-09-23 14ce5d2ccfae554497763da846ffb9eb39cd6d34
1. 修改实时数据各项的转换逻辑
已修改16个文件
已添加6个文件
487 ■■■■■ 文件已修改
src/main/kotlin/com/flightfeather/obd/common/Contanst.kt 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/kotlin/com/flightfeather/obd/lightshare/bean/CarLoginVo.kt 16 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/kotlin/com/flightfeather/obd/lightshare/bean/CarLogoutVo.kt 15 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/kotlin/com/flightfeather/obd/lightshare/bean/DataStreamVo.kt 42 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/kotlin/com/flightfeather/obd/lightshare/bean/LatLngVo.kt 14 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/kotlin/com/flightfeather/obd/lightshare/bean/ObdInfoVo.kt 26 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/kotlin/com/flightfeather/obd/lightshare/service/ObdDataService.kt 27 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/kotlin/com/flightfeather/obd/lightshare/service/impl/ObdDataServiceImpl.kt 31 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/kotlin/com/flightfeather/obd/lightshare/web/ObdDataController.kt 39 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/kotlin/com/flightfeather/obd/repository/CarLoginRepository.kt 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/kotlin/com/flightfeather/obd/repository/CarLogoutRepository.kt 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/kotlin/com/flightfeather/obd/repository/DataStreamRepository.kt 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/kotlin/com/flightfeather/obd/repository/ObdInfoRepository.kt 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/kotlin/com/flightfeather/obd/repository/impl/CarLoginDaoImpl.kt 28 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/kotlin/com/flightfeather/obd/repository/impl/CarLogoutDaoImpl.kt 28 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/kotlin/com/flightfeather/obd/repository/impl/DataStreamDaoImpl.kt 62 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/kotlin/com/flightfeather/obd/repository/impl/ObdInfoDaoImpl.kt 26 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/kotlin/com/flightfeather/obd/socket/decoder/impl/DataUnitDecoderImpl.kt 5 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/kotlin/com/flightfeather/obd/socket/decoder/impl/RealTimeDataDecoderImpl.kt 73 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/application.yml 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/test/kotlin/com/flightfeather/obd/Test.kt 8 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/test/kotlin/com/flightfeather/obd/socket/decoder/VehicleDataDecoderTest.kt 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
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"
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
}
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
}
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
}
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
}
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
}
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>
    /**
     * æ ¹æ®ç»ˆç«¯è®¾å¤‡ç èŽ·å–obd数据
     */
    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
}
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)
}
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)
}
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>
}
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>
}
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
}
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
    /**
     * æ ¹æ®ç»ˆç«¯è®¾å¤‡ç èŽ·å–obd数据
     */
    fun getObdInfo(deviceCode: String, pageNum: Int?, pageSize: Int?): List<ObdInfoVo>
}
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
    }
}
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
    }
}
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
    }
}
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
    }
}
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
            }
        }
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])
                    }
                }
            }
        }
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
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()
    }
}
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)