From 57b3b0851b2144073522a43640c2acc9452e1719 Mon Sep 17 00:00:00 2001
From: riku <risaku@163.com>
Date: 星期三, 30 十月 2019 14:52:34 +0800
Subject: [PATCH] 新增接口: 1. 获取车辆轨迹

---
 src/main/kotlin/com/flightfeather/obd/lightshare/service/impl/ObdDataServiceImpl.kt |   30 ++++++++++++++-
 src/main/kotlin/com/flightfeather/obd/lightshare/web/ObdDataController.kt           |    8 ++++
 src/main/kotlin/com/flightfeather/obd/repository/impl/DataStreamDaoImpl.kt          |   29 +-------------
 src/main/kotlin/com/flightfeather/obd/lightshare/service/ObdDataService.kt          |    5 ++
 src/main/kotlin/com/flightfeather/obd/repository/DataStreamRepository.kt            |    5 --
 5 files changed, 43 insertions(+), 34 deletions(-)

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 dbcd2e2..51d6d79 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,11 @@
     fun getCoordinate(deviceCode: String): LatLngVo
 
     /**
+     * 鏍规嵁缁堢璁惧鐮佷互鍙婃椂闀縯 鑾峰彇t涔嬪墠鍒扮幇鍦ㄧ殑鎵�鏈夎建杩瑰潗鏍�
+     */
+    fun getTrack(deviceCode: String, startTime: String, endTime: String): List<LatLngVo>
+
+    /**
      * 鑾峰彇鏈�鏂扮殑杞﹁締鍧愭爣淇℃伅
      */
     fun getLatestCoordinate(pageNum: Int?, pageSize: Int?): List<LatLngVo>
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 f843a60..1c1ccfa 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
@@ -49,8 +49,34 @@
     override fun getDataStreamCount(deviceCode: String, startTime: String?, endTime: String?): Int
             = dataStreamRepository.getDataStreamCount(deviceCode, startTime, endTime)
 
-    override fun getCoordinate(deviceCode: String): LatLngVo
-            = dataStreamRepository.getCoordinate(deviceCode)
+    override fun getCoordinate(deviceCode: String): LatLngVo{
+        val latLngVo = LatLngVo()
+        dataStreamRepository.getLatestDataStream(deviceCode)?.let {
+            latLngVo.apply {
+                this.deviceCode = it.obdDeviceCode
+                obdDataTime = it.obdDataTime
+                lat = it.obdLat
+                lng = it.obdLong
+            }
+        }
+
+        return latLngVo
+    }
+
+    override fun getTrack(deviceCode: String, startTime: String, endTime: String): List<LatLngVo> {
+        val resultList = mutableListOf<LatLngVo>()
+        //2019.10.30 鐩墠鍓嶇瀹夊崜璁惧畾鏈�闀胯幏鍙栫殑鏃堕暱涓�6灏忔椂鍓嶈嚦鐜板湪鐨勬暟鎹紝鎸夌収obd 姣�10绉掍腑浜х敓涓�鏉℃暟鎹紝鏈�澶�4 * 360 = 1440 鏉�
+        dataStreamRepository.getDataStream(deviceCode, 1, 1500, startTime, endTime).forEach {
+            val latLngVo = LatLngVo().apply {
+                this.deviceCode = it.obdDeviceCode
+                obdDataTime = it.obdDataTime
+                lat = it.obdLat
+                lng = it.obdLong
+            }
+            resultList.add(latLngVo)
+        }
+        return resultList
+    }
 
     override fun getLatestCoordinate(pageNum: Int?, pageSize: Int?): List<LatLngVo> {
         val resultList = mutableListOf<LatLngVo>()
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 8c902e4..37fb916 100644
--- a/src/main/kotlin/com/flightfeather/obd/lightshare/web/ObdDataController.kt
+++ b/src/main/kotlin/com/flightfeather/obd/lightshare/web/ObdDataController.kt
@@ -2,6 +2,7 @@
 
 import com.flightfeather.obd.lightshare.service.ObdDataService
 import org.springframework.web.bind.annotation.*
+import java.time.Duration
 
 /**
  * @author riku
@@ -64,6 +65,13 @@
             @PathVariable("deviceCode") deviceCode: String
     ) = obdDataService.getCoordinate(deviceCode)
 
+    @GetMapping("/coordinate/track")
+    fun getTrack(
+            @RequestParam("deviceCode") deviceCode: String,
+            @RequestParam("startTime") startTime: String,
+            @RequestParam("endTime") endTime: String
+    ) = obdDataService.getTrack(deviceCode, startTime, endTime)
+
     @GetMapping("/coordinate/latest")
     fun getCoordinate(
             @RequestParam("page", required = false) pageNum: Int?,
diff --git a/src/main/kotlin/com/flightfeather/obd/repository/DataStreamRepository.kt b/src/main/kotlin/com/flightfeather/obd/repository/DataStreamRepository.kt
index 2e3bf1c..9f2df62 100644
--- a/src/main/kotlin/com/flightfeather/obd/repository/DataStreamRepository.kt
+++ b/src/main/kotlin/com/flightfeather/obd/repository/DataStreamRepository.kt
@@ -27,11 +27,6 @@
     fun getDataStreamCount(deviceCode: String, startTime: String?, endTime: String?): Int
 
     /**
-     * 鏍规嵁缁堢璁惧鐮佽幏鍙栨渶鏂扮粡绾害
-     */
-    fun getCoordinate(deviceCode: String): LatLngVo
-
-    /**
      * 鑾峰彇涓�杈嗚溅鏈�鏂扮殑涓�鏉$姸鎬佷俊鎭�
      */
     fun getLatestDataStream(deviceCode: String): DataStream?
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 9fcd476..dfe8583 100644
--- a/src/main/kotlin/com/flightfeather/obd/repository/impl/DataStreamDaoImpl.kt
+++ b/src/main/kotlin/com/flightfeather/obd/repository/impl/DataStreamDaoImpl.kt
@@ -16,6 +16,7 @@
 import org.springframework.stereotype.Repository
 import tk.mybatis.mapper.entity.Example
 import java.text.SimpleDateFormat
+import java.util.*
 
 /**
  * @author riku
@@ -120,7 +121,7 @@
     }
 
     override fun getDataStreamCount(deviceCode: String, startTime: String?, endTime: String?): Int {
-        val sf = SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
+        val sf = SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA)
         val example = Example(DataStream::class.java).apply {
             createCriteria().andEqualTo("obdDeviceCode", deviceCode).run {
                 startTime?.let {
@@ -144,32 +145,6 @@
         }
 
         return dataStreamMapper.selectCountByExample(example)
-    }
-
-    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
     }
 
     override fun getLatestDataStream(deviceCode: String): DataStream? {

--
Gitblit v1.9.3