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 |  106 ++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 101 insertions(+), 5 deletions(-)

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..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
@@ -1,19 +1,115 @@
 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.eunm.CarStatus
 import com.flightfeather.obd.lightshare.service.ObdDataService
-import com.flightfeather.obd.repository.ObdDataRepository
+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
  * 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,
+        val vehicleRepository: VehicleRepository
+) : 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>{
+        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)
+
+    override fun getDataStreamCount(deviceCode: String, startTime: String?, endTime: String?): Int
+            = dataStreamRepository.getDataStreamCount(deviceCode, startTime, endTime)
+
+    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>()
+
+        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

--
Gitblit v1.9.3