From df881fabbfbde09b9ec53b53e500d43ac314d736 Mon Sep 17 00:00:00 2001
From: riku <risaku@163.com>
Date: 星期三, 03 二月 2021 10:38:12 +0800
Subject: [PATCH] 1. 调整获取数据的排序为按时间升序
---
src/main/kotlin/com/flightfeather/uav/common/utils/TimeUtil.kt | 3 +++
src/main/kotlin/com/flightfeather/uav/lightshare/web/RealTimeDataController.kt | 4 +++-
src/test/kotlin/com/flightfeather/uav/UAVApplicationTests.kt | 10 ++++++++++
src/main/kotlin/com/flightfeather/uav/lightshare/service/RealTimeDataService.kt | 2 +-
src/main/kotlin/com/flightfeather/uav/lightshare/service/impl/RealTimeDataServiceImpl.kt | 13 ++++++++++---
src/main/resources/application.yml | 6 +++---
6 files changed, 30 insertions(+), 8 deletions(-)
diff --git a/src/main/kotlin/com/flightfeather/uav/common/utils/TimeUtil.kt b/src/main/kotlin/com/flightfeather/uav/common/utils/TimeUtil.kt
index 246b159..c02eb83 100644
--- a/src/main/kotlin/com/flightfeather/uav/common/utils/TimeUtil.kt
+++ b/src/main/kotlin/com/flightfeather/uav/common/utils/TimeUtil.kt
@@ -1,5 +1,7 @@
package com.flightfeather.uav.common.utils
+import java.text.DateFormat
+import java.text.SimpleDateFormat
import java.util.*
/**
@@ -9,6 +11,7 @@
class TimeUtil {
companion object {
+
/**
* 鏄惁鏄浜屽ぉ鎴栨洿鏂扮殑鏃堕棿
*/
diff --git a/src/main/kotlin/com/flightfeather/uav/lightshare/service/RealTimeDataService.kt b/src/main/kotlin/com/flightfeather/uav/lightshare/service/RealTimeDataService.kt
index 880a3b9..d00d43c 100644
--- a/src/main/kotlin/com/flightfeather/uav/lightshare/service/RealTimeDataService.kt
+++ b/src/main/kotlin/com/flightfeather/uav/lightshare/service/RealTimeDataService.kt
@@ -5,5 +5,5 @@
interface RealTimeDataService {
- fun getSecondData(deviceCode: String?, page: Int?, perPage: Int?): BaseResponse<List<DataVo>>
+ fun getSecondData(deviceCode: String?, startTime: String?, endTime: String?, page: Int?, perPage: Int?): BaseResponse<List<DataVo>>
}
\ No newline at end of file
diff --git a/src/main/kotlin/com/flightfeather/uav/lightshare/service/impl/RealTimeDataServiceImpl.kt b/src/main/kotlin/com/flightfeather/uav/lightshare/service/impl/RealTimeDataServiceImpl.kt
index 182ac66..0872846 100644
--- a/src/main/kotlin/com/flightfeather/uav/lightshare/service/impl/RealTimeDataServiceImpl.kt
+++ b/src/main/kotlin/com/flightfeather/uav/lightshare/service/impl/RealTimeDataServiceImpl.kt
@@ -11,30 +11,37 @@
import com.github.pagehelper.PageHelper
import org.springframework.stereotype.Service
import tk.mybatis.mapper.entity.Example
+import java.text.DateFormat
import java.text.SimpleDateFormat
@Service
class RealTimeDataServiceImpl(val realTimeDataMapper: RealTimeDataMapper) : RealTimeDataService {
- override fun getSecondData(deviceCode: String?, page: Int?, perPage: Int?): BaseResponse<List<DataVo>> {
+ private var dateFormatter = SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
+
+ override fun getSecondData(deviceCode: String?, startTime: String?, endTime: String?, page: Int?, perPage: Int?): BaseResponse<List<DataVo>> {
val _perPage = perPage ?: 60
val _page = page ?: 1
+ val sTime = startTime?.let { dateFormatter.parse(it) }
+ val eTime = endTime?.let { dateFormatter.parse(it) }
val pageInfo = PageHelper.startPage<RealTimeData>(_page, _perPage)
val result = mutableListOf<DataVo>()
realTimeDataMapper.selectByExample(Example(RealTimeData::class.java).apply {
createCriteria().apply {
deviceCode?.let { andEqualTo("deviceCode", it) }
+ sTime?.let { andGreaterThanOrEqualTo("dataTime", it) }
+ eTime?.let { andLessThanOrEqualTo("dataTime", it) }
}
orderBy("dataTime").desc()
}).forEach {
result.add(DataVo(
- SimpleDateFormat.getDateTimeInstance().format(it.dataTime),
+ dateFormatter.format(it.dataTime),
it.deviceCode,
GsonUtils.parserJsonToArrayBeans(it.factors, AirData::class.java),
it.longitude.toDouble(), it.latitude.toDouble()
))
}
- result.reverse()
+// result.reverse()
return BaseResponse(true, head = DataHead(pageInfo.pageNum, pageInfo.pages), data = result)
}
}
\ No newline at end of file
diff --git a/src/main/kotlin/com/flightfeather/uav/lightshare/web/RealTimeDataController.kt b/src/main/kotlin/com/flightfeather/uav/lightshare/web/RealTimeDataController.kt
index f72e1e0..e491030 100644
--- a/src/main/kotlin/com/flightfeather/uav/lightshare/web/RealTimeDataController.kt
+++ b/src/main/kotlin/com/flightfeather/uav/lightshare/web/RealTimeDataController.kt
@@ -13,7 +13,9 @@
@GetMapping("/sec")
fun getSecondData(
@RequestParam(value = "deviceCode", required = false) deviceCode: String?,
+ @RequestParam(value = "startTime", required = false) startTime: String?,
+ @RequestParam(value = "endTime", required = false) endTime: String?,
@RequestParam(value = "page", required = false) page: Int?,
@RequestParam(value = "perPage", required = false) perPage: Int?
- ) = realTimeDataService.getSecondData(deviceCode,page, perPage)
+ ) = realTimeDataService.getSecondData(deviceCode, startTime, endTime, page, perPage)
}
\ No newline at end of file
diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml
index ece910b..27d2245 100644
--- a/src/main/resources/application.yml
+++ b/src/main/resources/application.yml
@@ -5,9 +5,9 @@
# username: uav
# password: obd2019
- url: jdbc:mysql://114.215.109.124:3306/dronemonitor?serverTimezone=Asia/Shanghai&prepStmtCacheSize=517&cachePrepStmts=true&autoReconnect=true&characterEncoding=utf-8&allowMultiQueries=true&useSSL=false
- username: root
- password: 123456
+ url: jdbc:mysql://localhost:3306/dronemonitor?serverTimezone=Asia/Shanghai&prepStmtCacheSize=517&cachePrepStmts=true&autoReconnect=true&characterEncoding=utf-8&allowMultiQueries=true&useSSL=false
+ username: dronemonitor
+ password: dronemonitor_hackxrnomxm
hikari:
maximum-pool-size: 500
minimum-idle: 20
diff --git a/src/test/kotlin/com/flightfeather/uav/UAVApplicationTests.kt b/src/test/kotlin/com/flightfeather/uav/UAVApplicationTests.kt
index d1be554..6bc811e 100644
--- a/src/test/kotlin/com/flightfeather/uav/UAVApplicationTests.kt
+++ b/src/test/kotlin/com/flightfeather/uav/UAVApplicationTests.kt
@@ -1,8 +1,10 @@
package com.flightfeather.uav
+import com.flightfeather.uav.lightshare.service.RealTimeDataService
import org.junit.Test
import org.junit.runner.RunWith
import org.slf4j.LoggerFactory
+import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.test.context.junit4.SpringRunner
@@ -10,6 +12,8 @@
@SpringBootTest
class UAVApplicationTests {
+ @Autowired
+ lateinit var realTimeDataService: RealTimeDataService
@Test
fun contextLoads() {
@@ -30,4 +34,10 @@
log.error("error")
}
+ @Test
+ fun foo2() {
+ val r = realTimeDataService.getSecondData(null, "2021-01-13 14:30:00", "2021-01-13 14:45:00", null, 10)
+ println(r)
+ }
+
}
--
Gitblit v1.9.3