riku
2019-10-30 57b3b0851b2144073522a43640c2acc9452e1719
新增接口:
1. 获取车辆轨迹
已修改5个文件
77 ■■■■■ 文件已修改
src/main/kotlin/com/flightfeather/obd/lightshare/service/ObdDataService.kt 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/kotlin/com/flightfeather/obd/lightshare/service/impl/ObdDataServiceImpl.kt 30 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/kotlin/com/flightfeather/obd/lightshare/web/ObdDataController.kt 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/kotlin/com/flightfeather/obd/repository/DataStreamRepository.kt 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/kotlin/com/flightfeather/obd/repository/impl/DataStreamDaoImpl.kt 29 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/kotlin/com/flightfeather/obd/lightshare/service/ObdDataService.kt
@@ -44,6 +44,11 @@
    fun getCoordinate(deviceCode: String): LatLngVo
    /**
     * 根据终端设备码以及时长t 获取t之前到现在的所有轨迹坐标
     */
    fun getTrack(deviceCode: String, startTime: String, endTime: String): List<LatLngVo>
    /**
     * 获取最新的车辆坐标信息
     */
    fun getLatestCoordinate(pageNum: Int?, pageSize: Int?): List<LatLngVo>
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>()
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?,
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?
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? {