From 1f356649ce536b19b903d6f3a533983d4b8222bc Mon Sep 17 00:00:00 2001
From: riku <risaku@163.com>
Date: 星期五, 25 十月 2019 18:16:39 +0800
Subject: [PATCH] 新增接口: 1. 获取所有设备的最新一条数据 新增数据库表: 1. 车辆信息表

---
 src/main/kotlin/com/flightfeather/obd/lightshare/service/VehicleService.kt          |   17 ++
 src/main/kotlin/com/flightfeather/obd/lightshare/web/VehicleInfoController.kt       |   22 ++
 src/main/kotlin/com/flightfeather/obd/domain/mapper/VehicleInfoMapper.kt            |    8 +
 src/main/kotlin/com/flightfeather/obd/repository/impl/ObdInfoDaoImpl.kt             |   13 -
 src/main/resources/mapper/VehicleInfoMapper.xml                                     |   20 ++
 src/main/kotlin/com/flightfeather/obd/repository/ObdInfoRepository.kt               |    4 
 src/main/kotlin/com/flightfeather/obd/repository/impl/DataStreamDaoImpl.kt          |   45 ++++-
 src/main/kotlin/com/flightfeather/obd/lightshare/service/impl/VehicleServiceImpl.kt |   28 +++
 src/main/kotlin/com/flightfeather/obd/repository/DataStreamRepository.kt            |    6 
 src/main/kotlin/com/flightfeather/obd/domain/entity/VehicleInfo.java                |   98 ++++++++++++
 src/main/kotlin/com/flightfeather/obd/repository/VehicleRepository.kt               |   15 +
 /dev/null                                                                           |    0 
 src/main/kotlin/com/flightfeather/obd/lightshare/bean/LatLngVo.kt                   |    8 
 src/main/resources/generator/generatorConfig.xml                                    |    3 
 src/main/kotlin/com/flightfeather/obd/lightshare/service/impl/ObdDataServiceImpl.kt |   54 ++++++
 src/main/kotlin/com/flightfeather/obd/lightshare/eunm/CarStatus.kt                  |   17 ++
 src/main/kotlin/com/flightfeather/obd/lightshare/eunm/CarType.kt                    |   12 +
 src/main/kotlin/com/flightfeather/obd/lightshare/bean/VehicleInfoVo.kt              |   20 ++
 src/main/kotlin/com/flightfeather/obd/lightshare/web/ObdDataController.kt           |    6 
 src/main/kotlin/com/flightfeather/obd/repository/impl/VehicleRepositoryImpl.kt      |   24 +++
 src/main/kotlin/com/flightfeather/obd/lightshare/service/ObdDataService.kt          |    8 
 21 files changed, 401 insertions(+), 27 deletions(-)

diff --git a/src/main/kotlin/com/flightfeather/obd/common/packgeinfo b/src/main/kotlin/com/flightfeather/obd/common/packgeinfo
deleted file mode 100644
index e69de29..0000000
--- a/src/main/kotlin/com/flightfeather/obd/common/packgeinfo
+++ /dev/null
diff --git a/src/main/kotlin/com/flightfeather/obd/domain/entity/VehicleInfo.java b/src/main/kotlin/com/flightfeather/obd/domain/entity/VehicleInfo.java
new file mode 100644
index 0000000..4aced95
--- /dev/null
+++ b/src/main/kotlin/com/flightfeather/obd/domain/entity/VehicleInfo.java
@@ -0,0 +1,98 @@
+package com.flightfeather.obd.domain.entity;
+
+import javax.persistence.*;
+
+@Table(name = "obd_vehicle_info")
+public class VehicleInfo {
+    @Id
+    private Integer id;
+
+    @Column(name = "obd_device_code")
+    private String obdDeviceCode;
+
+    @Column(name = "obd_vin")
+    private String obdVin;
+
+    @Column(name = "obd_licence_plate")
+    private String obdLicencePlate;
+
+    /**
+     * 0: 闆嗗崱锛� 1锛氭福鍦熻溅
+     */
+    @Column(name = "obd_vehicle_type")
+    private Integer obdVehicleType;
+
+    /**
+     * @return id
+     */
+    public Integer getId() {
+        return id;
+    }
+
+    /**
+     * @param id
+     */
+    public void setId(Integer id) {
+        this.id = id;
+    }
+
+    /**
+     * @return obd_device_code
+     */
+    public String getObdDeviceCode() {
+        return obdDeviceCode;
+    }
+
+    /**
+     * @param obdDeviceCode
+     */
+    public void setObdDeviceCode(String obdDeviceCode) {
+        this.obdDeviceCode = obdDeviceCode == null ? null : obdDeviceCode.trim();
+    }
+
+    /**
+     * @return obd_vin
+     */
+    public String getObdVin() {
+        return obdVin;
+    }
+
+    /**
+     * @param obdVin
+     */
+    public void setObdVin(String obdVin) {
+        this.obdVin = obdVin == null ? null : obdVin.trim();
+    }
+
+    /**
+     * @return obd_licence_plate
+     */
+    public String getObdLicencePlate() {
+        return obdLicencePlate;
+    }
+
+    /**
+     * @param obdLicencePlate
+     */
+    public void setObdLicencePlate(String obdLicencePlate) {
+        this.obdLicencePlate = obdLicencePlate == null ? null : obdLicencePlate.trim();
+    }
+
+    /**
+     * 鑾峰彇1: 闆嗗崱锛� 2锛氭福鍦熻溅
+     *
+     * @return obd_vehicle_type - 1: 闆嗗崱锛� 2锛氭福鍦熻溅
+     */
+    public Integer getObdVehicleType() {
+        return obdVehicleType;
+    }
+
+    /**
+     * 璁剧疆1: 闆嗗崱锛� 2锛氭福鍦熻溅
+     *
+     * @param obdVehicleType 1: 闆嗗崱锛� 2锛氭福鍦熻溅
+     */
+    public void setObdVehicleType(Integer obdVehicleType) {
+        this.obdVehicleType = obdVehicleType;
+    }
+}
\ No newline at end of file
diff --git a/src/main/kotlin/com/flightfeather/obd/domain/mapper/VehicleInfoMapper.kt b/src/main/kotlin/com/flightfeather/obd/domain/mapper/VehicleInfoMapper.kt
new file mode 100644
index 0000000..7147ed6
--- /dev/null
+++ b/src/main/kotlin/com/flightfeather/obd/domain/mapper/VehicleInfoMapper.kt
@@ -0,0 +1,8 @@
+package com.flightfeather.obd.domain.mapper
+
+import com.flightfeather.obd.domain.MyMapper
+import com.flightfeather.obd.domain.entity.VehicleInfo
+import org.apache.ibatis.annotations.Mapper
+
+@Mapper
+interface VehicleInfoMapper : MyMapper<VehicleInfo>
\ 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
index 6f2ba15..d1f5d03 100644
--- a/src/main/kotlin/com/flightfeather/obd/lightshare/bean/LatLngVo.kt
+++ b/src/main/kotlin/com/flightfeather/obd/lightshare/bean/LatLngVo.kt
@@ -8,7 +8,13 @@
  */
 class LatLngVo : BaseJson() {
     var deviceCode: String? = null
-    var obdDataTime: Date?= null
+    var vin: String? = null
+    var license: String? = null
+    var obdDataTime: Date? = null
+    //杞﹁締绫诲瀷
+    var carType: Int? = null
+    //杞﹁締鐘舵��
+    var status: Int = 0
     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/VehicleInfoVo.kt b/src/main/kotlin/com/flightfeather/obd/lightshare/bean/VehicleInfoVo.kt
new file mode 100644
index 0000000..4e1cb1c
--- /dev/null
+++ b/src/main/kotlin/com/flightfeather/obd/lightshare/bean/VehicleInfoVo.kt
@@ -0,0 +1,20 @@
+package com.flightfeather.obd.lightshare.bean
+
+/**
+ * @author riku
+ * Date: 2019/10/25
+ */
+class VehicleInfoVo : BaseJson() {
+    var id: Int? = null
+
+    var obdDeviceCode: String? = null
+
+    var obdVin: String? = null
+
+    var obdLicencePlate: String? = null
+
+    /**
+     * 0: 闆嗗崱锛� 1锛氭福鍦熻溅
+     */
+    var obdVehicleType: Int? = null
+}
\ No newline at end of file
diff --git a/src/main/kotlin/com/flightfeather/obd/lightshare/eunm/CarStatus.kt b/src/main/kotlin/com/flightfeather/obd/lightshare/eunm/CarStatus.kt
new file mode 100644
index 0000000..ff22756
--- /dev/null
+++ b/src/main/kotlin/com/flightfeather/obd/lightshare/eunm/CarStatus.kt
@@ -0,0 +1,17 @@
+package com.flightfeather.obd.lightshare.eunm
+
+/**
+ * @author riku
+ * Date: 2019/9/26
+ * 杞﹁締鐘舵��
+ * 0锛氱绾�
+ * 1锛氬湪绾�
+ * 2锛氳鎶�
+ * 3锛氳秴鏍�
+ */
+enum class CarStatus(val value: Int) {
+    OffLine(0),
+    OnLine(1),
+    Warn(2),
+    Exceed(3)
+}
\ No newline at end of file
diff --git a/src/main/kotlin/com/flightfeather/obd/lightshare/eunm/CarType.kt b/src/main/kotlin/com/flightfeather/obd/lightshare/eunm/CarType.kt
new file mode 100644
index 0000000..26528b6
--- /dev/null
+++ b/src/main/kotlin/com/flightfeather/obd/lightshare/eunm/CarType.kt
@@ -0,0 +1,12 @@
+package com.flightfeather.obd.lightshare.eunm
+
+/**
+ * @author riku
+ * Date: 2019/9/26
+ */
+enum class CarType(val value: Int){
+    //闆嗚绠卞崱杞�
+    ContainerTruck(0),
+    //娓e湡杞�
+    SlagCar(1)
+}
\ 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 00d5915..dbcd2e2 100644
--- a/src/main/kotlin/com/flightfeather/obd/lightshare/service/ObdDataService.kt
+++ b/src/main/kotlin/com/flightfeather/obd/lightshare/service/ObdDataService.kt
@@ -44,6 +44,12 @@
     fun getCoordinate(deviceCode: String): LatLngVo
 
     /**
-     * 鏍规嵁缁堢璁惧鐮佸強鏃堕棿娈碉紝缁欏嚭姝ゆ鏃堕棿鍐�
+     * 鑾峰彇鏈�鏂扮殑杞﹁締鍧愭爣淇℃伅
      */
+    fun getLatestCoordinate(pageNum: Int?, pageSize: Int?): List<LatLngVo>
+
+    /**
+     * 鏍规嵁缁堢璁惧鐮佸強鏃堕棿娈碉紝缁欏嚭姝ゆ鏃堕棿鍐呯殑鍧愭爣
+     */
+    //TODO
 }
\ No newline at end of file
diff --git a/src/main/kotlin/com/flightfeather/obd/lightshare/service/VehicleService.kt b/src/main/kotlin/com/flightfeather/obd/lightshare/service/VehicleService.kt
new file mode 100644
index 0000000..fb3eb61
--- /dev/null
+++ b/src/main/kotlin/com/flightfeather/obd/lightshare/service/VehicleService.kt
@@ -0,0 +1,17 @@
+package com.flightfeather.obd.lightshare.service
+
+import com.flightfeather.obd.lightshare.bean.VehicleInfoVo
+
+/**
+ * @author riku
+ * Date: 2019/10/25
+ * 杞﹁締鐩稿叧淇℃伅鎺ュ彛
+ */
+interface VehicleService {
+
+    /**
+     * 鑾峰彇杞﹁締淇℃伅
+     */
+    fun getVehicleInfo(pageNum: Int?, pageSize: Int?): List<VehicleInfoVo>
+
+}
\ 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 c2babe3..f843a60 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,9 +1,14 @@
 package com.flightfeather.obd.lightshare.service.impl
 
 import com.flightfeather.obd.lightshare.bean.*
+import com.flightfeather.obd.lightshare.eunm.CarStatus
 import com.flightfeather.obd.lightshare.service.ObdDataService
 import com.flightfeather.obd.repository.*
+import org.springframework.beans.BeanUtils
 import org.springframework.stereotype.Service
+import java.time.LocalDateTime
+import java.time.ZoneId
+import java.util.*
 
 /**
  * @author riku
@@ -15,7 +20,8 @@
         val carLoginRepository: CarLoginRepository,
         val carLogoutRepository: CarLogoutRepository,
         val obdInfoRepository: ObdInfoRepository,
-        val dataStreamRepository: DataStreamRepository
+        val dataStreamRepository: DataStreamRepository,
+        val vehicleRepository: VehicleRepository
 ) : ObdDataService {
 
     override fun getDataByVinCode(vinCode: String, pageNum: Int?, pageSize: Int?): MutableList<ObdDataVo>
@@ -27,8 +33,15 @@
     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 getObdInfo(deviceCode: String, pageNum: Int?, pageSize: Int?): List<ObdInfoVo>{
+        val resultList = mutableListOf<ObdInfoVo>()
+        obdInfoRepository.getObdInfo(deviceCode, pageNum, pageSize).forEach {
+            val vo = ObdInfoVo()
+            BeanUtils.copyProperties(it, vo)
+            resultList.add(vo)
+        }
+        return resultList
+    }
 
     override fun getDataStream(deviceCode: String, pageNum: Int?, pageSize: Int?, startTime: String?, endTime: String?): List<DataStreamVo>
             = dataStreamRepository.getDataStream(deviceCode, pageNum, pageSize, startTime, endTime)
@@ -38,4 +51,39 @@
 
     override fun getCoordinate(deviceCode: String): LatLngVo
             = dataStreamRepository.getCoordinate(deviceCode)
+
+    override fun getLatestCoordinate(pageNum: Int?, pageSize: Int?): List<LatLngVo> {
+        val resultList = mutableListOf<LatLngVo>()
+
+        val now = LocalDateTime.now()
+
+        vehicleRepository.getVehicleInfo(pageNum, pageSize).forEach { vehicleInfo ->
+            val dataStream = dataStreamRepository.getLatestDataStream(vehicleInfo.obdDeviceCode)
+            val obdInfo = obdInfoRepository.getObdInfo(vehicleInfo.obdDeviceCode, 1, 1).takeIf { it.isNotEmpty() }?.get(0)
+
+            //鑾峰彇鏁版嵁閲囨牱鏃堕棿锛屽鏋滀负绌猴紝鍒欏彇褰撳墠鏃堕棿鐨勫墠24灏忔椂
+            val dataTime = dataStream?.obdDataTime?.toInstant()?.atZone(ZoneId.systemDefault())?.toLocalDateTime()
+                    ?: LocalDateTime.now().minusDays(1)
+
+            resultList.add(LatLngVo().apply {
+                deviceCode = vehicleInfo.obdDeviceCode
+                vin = obdInfo?.obdVin
+                license = vehicleInfo.obdLicencePlate
+                obdDataTime = dataStream?.obdDataTime
+                carType = vehicleInfo.obdVehicleType
+                //閲囨牱鏃堕棿鍜屽綋鍓嶆椂闂寸浉宸秴杩�10鍒嗛挓璁や负璁惧澶勪簬绂荤嚎鐘舵��
+                //todo 2019.10.25 鍏朵綑涓ょ杞﹁締鐘舵�侊紝鍚庣画闇�澶勭悊
+                status = if (now.minusMinutes(10).isAfter(dataTime)) {
+                    CarStatus.OffLine.value
+                } else {
+                    CarStatus.OnLine.value
+                }
+                lat = dataStream?.obdLat
+                lng = dataStream?.obdLong
+            })
+        }
+
+        return resultList
+
+    }
 }
\ No newline at end of file
diff --git a/src/main/kotlin/com/flightfeather/obd/lightshare/service/impl/VehicleServiceImpl.kt b/src/main/kotlin/com/flightfeather/obd/lightshare/service/impl/VehicleServiceImpl.kt
new file mode 100644
index 0000000..8a8c948
--- /dev/null
+++ b/src/main/kotlin/com/flightfeather/obd/lightshare/service/impl/VehicleServiceImpl.kt
@@ -0,0 +1,28 @@
+package com.flightfeather.obd.lightshare.service.impl
+
+import com.flightfeather.obd.lightshare.bean.VehicleInfoVo
+import com.flightfeather.obd.lightshare.service.VehicleService
+import com.flightfeather.obd.repository.VehicleRepository
+import org.springframework.beans.BeanUtils
+import org.springframework.stereotype.Service
+
+/**
+ * @author riku
+ * Date: 2019/10/25
+ */
+@Service
+class VehicleServiceImpl(val vehicleRepository: VehicleRepository) : VehicleService {
+    override fun getVehicleInfo(pageNum: Int?, pageSize: Int?): List<VehicleInfoVo> {
+        val dbResult = vehicleRepository.getVehicleInfo(pageNum, pageSize)
+
+        val resultList = mutableListOf<VehicleInfoVo>()
+
+        dbResult.forEach {
+            val vo = VehicleInfoVo()
+            BeanUtils.copyProperties(it, vo)
+            resultList.add(vo)
+        }
+
+        return resultList
+    }
+}
\ 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 e6bcaff..8c902e4 100644
--- a/src/main/kotlin/com/flightfeather/obd/lightshare/web/ObdDataController.kt
+++ b/src/main/kotlin/com/flightfeather/obd/lightshare/web/ObdDataController.kt
@@ -63,4 +63,10 @@
     fun getCoordinate(
             @PathVariable("deviceCode") deviceCode: String
     ) = obdDataService.getCoordinate(deviceCode)
+
+    @GetMapping("/coordinate/latest")
+    fun getCoordinate(
+            @RequestParam("page", required = false) pageNum: Int?,
+            @RequestParam("per_page", required = false) pageSize: Int?
+    ) = obdDataService.getLatestCoordinate(pageNum, pageSize)
 }
\ No newline at end of file
diff --git a/src/main/kotlin/com/flightfeather/obd/lightshare/web/VehicleInfoController.kt b/src/main/kotlin/com/flightfeather/obd/lightshare/web/VehicleInfoController.kt
new file mode 100644
index 0000000..ffaf2b4
--- /dev/null
+++ b/src/main/kotlin/com/flightfeather/obd/lightshare/web/VehicleInfoController.kt
@@ -0,0 +1,22 @@
+package com.flightfeather.obd.lightshare.web
+
+import com.flightfeather.obd.lightshare.service.VehicleService
+import org.springframework.web.bind.annotation.GetMapping
+import org.springframework.web.bind.annotation.RequestMapping
+import org.springframework.web.bind.annotation.RequestParam
+import org.springframework.web.bind.annotation.RestController
+
+/**
+ * @author riku
+ * Date: 2019/10/25
+ */
+@RestController
+@RequestMapping("obd/vehicle")
+class VehicleInfoController(val vehicleService: VehicleService) {
+
+    @GetMapping("/info")
+    fun getVehicleInfo(
+            @RequestParam("page", required = false) pageNum: Int?,
+            @RequestParam("per_page", required = false) pageSize: Int?
+    ) = vehicleService.getVehicleInfo(pageNum, pageSize)
+}
\ 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 fb4570f..2e3bf1c 100644
--- a/src/main/kotlin/com/flightfeather/obd/repository/DataStreamRepository.kt
+++ b/src/main/kotlin/com/flightfeather/obd/repository/DataStreamRepository.kt
@@ -1,5 +1,6 @@
 package com.flightfeather.obd.repository
 
+import com.flightfeather.obd.domain.entity.DataStream
 import com.flightfeather.obd.lightshare.bean.DataStreamVo
 import com.flightfeather.obd.lightshare.bean.LatLngVo
 import com.flightfeather.obd.socket.bean.ObdPackageData
@@ -29,4 +30,9 @@
      * 鏍规嵁缁堢璁惧鐮佽幏鍙栨渶鏂扮粡绾害
      */
     fun getCoordinate(deviceCode: String): LatLngVo
+
+    /**
+     * 鑾峰彇涓�杈嗚溅鏈�鏂扮殑涓�鏉$姸鎬佷俊鎭�
+     */
+    fun getLatestDataStream(deviceCode: String): DataStream?
 }
\ 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 99a6d1b..63d47eb 100644
--- a/src/main/kotlin/com/flightfeather/obd/repository/ObdInfoRepository.kt
+++ b/src/main/kotlin/com/flightfeather/obd/repository/ObdInfoRepository.kt
@@ -20,5 +20,7 @@
     /**
      * 鏍规嵁缁堢璁惧鐮佽幏鍙杘bd鏁版嵁
      */
-    fun getObdInfo(deviceCode: String, pageNum: Int?, pageSize: Int?): List<ObdInfoVo>
+    fun getObdInfo(deviceCode: String, pageNum: Int?, pageSize: Int?): List<com.flightfeather.obd.domain.entity.ObdInfo>
+
+
 }
\ No newline at end of file
diff --git a/src/main/kotlin/com/flightfeather/obd/repository/VehicleRepository.kt b/src/main/kotlin/com/flightfeather/obd/repository/VehicleRepository.kt
new file mode 100644
index 0000000..1df424e
--- /dev/null
+++ b/src/main/kotlin/com/flightfeather/obd/repository/VehicleRepository.kt
@@ -0,0 +1,15 @@
+package com.flightfeather.obd.repository
+
+import com.flightfeather.obd.domain.entity.VehicleInfo
+
+/**
+ * @author riku
+ * Date: 2019/10/25
+ */
+interface VehicleRepository {
+
+    /**
+     * 鑾峰彇杞﹁締淇℃伅
+     */
+    fun getVehicleInfo(pageNum: Int?, pageSize: Int?): List<VehicleInfo>
+}
\ 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 a72cc1a..9fcd476 100644
--- a/src/main/kotlin/com/flightfeather/obd/repository/impl/DataStreamDaoImpl.kt
+++ b/src/main/kotlin/com/flightfeather/obd/repository/impl/DataStreamDaoImpl.kt
@@ -2,6 +2,7 @@
 
 import com.flightfeather.obd.domain.entity.DataStream
 import com.flightfeather.obd.domain.mapper.DataStreamMapper
+import com.flightfeather.obd.domain.mapper.VehicleInfoMapper
 import com.flightfeather.obd.lightshare.bean.DataStreamVo
 import com.flightfeather.obd.lightshare.bean.LatLngVo
 import com.flightfeather.obd.repository.DataStreamRepository
@@ -21,7 +22,7 @@
  * Date: 2019/9/17
  */
 @Repository
-class DataStreamDaoImpl(val dataStreamMapper: DataStreamMapper): DataStreamRepository {
+class DataStreamDaoImpl(val dataStreamMapper: DataStreamMapper, val vehicleInfoMapper: VehicleInfoMapper): DataStreamRepository {
 
     override fun saveDataStream(packageData: ObdPackageData): Boolean {
 
@@ -84,12 +85,20 @@
         val example = Example(DataStream::class.java).apply {
             createCriteria().andEqualTo("obdDeviceCode", deviceCode).run {
                 startTime?.let {
-                    val st = sf.parse(startTime)
-                    andGreaterThanOrEqualTo("obdDataTime", st)
+                    try {
+                        val st = sf.parse(startTime)
+                        andGreaterThanOrEqualTo("obdDataTime", st)
+                    } catch (e: Throwable) {
+                        e.printStackTrace()
+                    }
                 }
                 endTime?.let {
-                    val et = sf.parse(endTime)
-                    andLessThanOrEqualTo("obdDataTime", et)
+                    try {
+                        val et = sf.parse(endTime)
+                        andLessThanOrEqualTo("obdDataTime", et)
+                    } catch (e: Throwable) {
+                        e.printStackTrace()
+                    }
                 }
                 orderBy("obdDataTime").desc()
             }
@@ -115,12 +124,20 @@
         val example = Example(DataStream::class.java).apply {
             createCriteria().andEqualTo("obdDeviceCode", deviceCode).run {
                 startTime?.let {
-                    val st = sf.parse(startTime)
-                    andGreaterThanOrEqualTo("obdDataTime", st)
+                    try {
+                        val st = sf.parse(startTime)
+                        andGreaterThanOrEqualTo("obdDataTime", st)
+                    } catch (e: Throwable) {
+                        e.printStackTrace()
+                    }
                 }
                 endTime?.let {
-                    val et = sf.parse(endTime)
-                    andLessThanOrEqualTo("obdDataTime", et)
+                    try {
+                        val et = sf.parse(endTime)
+                        andLessThanOrEqualTo("obdDataTime", et)
+                    } catch (e: Throwable) {
+                        e.printStackTrace()
+                    }
                 }
                 orderBy("obdDataTime").desc()
             }
@@ -154,4 +171,14 @@
 
         return latLngVo
     }
+
+    override fun getLatestDataStream(deviceCode: String): DataStream? {
+        val example = Example(DataStream::class.java).apply {
+            createCriteria().andEqualTo("obdDeviceCode", deviceCode)
+            orderBy("obdDataTime").desc()
+        }
+        //鑾峰彇鏈�鏂扮殑涓�涓�
+        PageHelper.offsetPage<DataStream>(0, 1)
+        return dataStreamMapper.selectByExample(example).takeIf { it.isNotEmpty() }?.get(0)
+    }
 }
\ 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 69d464f..d14f9f9 100644
--- a/src/main/kotlin/com/flightfeather/obd/repository/impl/ObdInfoDaoImpl.kt
+++ b/src/main/kotlin/com/flightfeather/obd/repository/impl/ObdInfoDaoImpl.kt
@@ -55,7 +55,7 @@
         }
     }
 
-    override fun getObdInfo(deviceCode: String, pageNum: Int?, pageSize: Int?): List<ObdInfoVo> {
+    override fun getObdInfo(deviceCode: String, pageNum: Int?, pageSize: Int?): List<ObdInfo> {
         val example = Example(ObdInfo::class.java).apply {
             createCriteria().andEqualTo("obdDeviceCode", deviceCode).run {
                 orderBy("obdDataTime").desc()
@@ -65,15 +65,6 @@
         //鍒嗛〉
         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
+        return obdInfoMapper.selectByExample(example)
     }
 }
\ No newline at end of file
diff --git a/src/main/kotlin/com/flightfeather/obd/repository/impl/VehicleRepositoryImpl.kt b/src/main/kotlin/com/flightfeather/obd/repository/impl/VehicleRepositoryImpl.kt
new file mode 100644
index 0000000..96255e3
--- /dev/null
+++ b/src/main/kotlin/com/flightfeather/obd/repository/impl/VehicleRepositoryImpl.kt
@@ -0,0 +1,24 @@
+package com.flightfeather.obd.repository.impl
+
+import com.flightfeather.obd.domain.entity.DataStream
+import com.flightfeather.obd.domain.entity.VehicleInfo
+import com.flightfeather.obd.domain.mapper.VehicleInfoMapper
+import com.flightfeather.obd.repository.VehicleRepository
+import com.github.pagehelper.PageHelper
+import org.springframework.stereotype.Repository
+
+/**
+ * @author riku
+ * Date: 2019/10/25
+ */
+@Repository
+class VehicleRepositoryImpl(val vehicleInfoMapper: VehicleInfoMapper):VehicleRepository {
+    override fun getVehicleInfo(pageNum: Int?, pageSize: Int?): List<VehicleInfo> {
+
+        //鍒嗛〉
+        val offset = (pageSize?.times(pageNum?.minus(1) ?: 0)) ?: 0
+        PageHelper.offsetPage<DataStream>(offset, pageSize ?: 10)
+
+        return vehicleInfoMapper.selectAll()
+    }
+}
\ No newline at end of file
diff --git a/src/main/resources/generator/generatorConfig.xml b/src/main/resources/generator/generatorConfig.xml
index 9b7a1a8..e7aa4d9 100644
--- a/src/main/resources/generator/generatorConfig.xml
+++ b/src/main/resources/generator/generatorConfig.xml
@@ -52,7 +52,8 @@
         <!--<table tableName="obd_origin_data" domainObjectName="OriginData" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"/>-->
         <!--<table tableName="obd_car_login" domainObjectName="CarLogin" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"/>-->
         <!--<table tableName="obd_car_logout" domainObjectName="CarLogout" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"/>-->
-        <table tableName="obd_data_stream" domainObjectName="DataStream" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"/>
+        <!--<table tableName="obd_data_stream" domainObjectName="DataStream" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"/>-->
         <!--<table tableName="obd_info" domainObjectName="ObdInfo" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"/>-->
+        <table tableName="obd_vehicle_info" domainObjectName="VehicleInfo" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"/>
     </context>
 </generatorConfiguration>
\ No newline at end of file
diff --git a/src/main/resources/mapper/VehicleInfoMapper.xml b/src/main/resources/mapper/VehicleInfoMapper.xml
new file mode 100644
index 0000000..1a709d6
--- /dev/null
+++ b/src/main/resources/mapper/VehicleInfoMapper.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.flightfeather.obd.domain.mapper.VehicleInfoMapper">
+  <resultMap id="BaseResultMap" type="com.flightfeather.obd.domain.entity.VehicleInfo">
+    <!--
+      WARNING - @mbg.generated
+    -->
+    <id column="id" jdbcType="INTEGER" property="id" />
+    <result column="obd_device_code" jdbcType="VARCHAR" property="obdDeviceCode" />
+    <result column="obd_vin" jdbcType="VARCHAR" property="obdVin" />
+    <result column="obd_licence_plate" jdbcType="VARCHAR" property="obdLicencePlate" />
+    <result column="obd_vehicle_type" jdbcType="INTEGER" property="obdVehicleType" />
+  </resultMap>
+  <sql id="Base_Column_List">
+    <!--
+      WARNING - @mbg.generated
+    -->
+    id, obd_device_code, obd_vin, obd_licence_plate, obd_vehicle_type
+  </sql>
+</mapper>
\ No newline at end of file

--
Gitblit v1.9.3