riku
2021-02-03 df881fabbfbde09b9ec53b53e500d43ac314d736
1. 调整获取数据的排序为按时间升序
已修改6个文件
38 ■■■■ 文件已修改
src/main/kotlin/com/flightfeather/uav/common/utils/TimeUtil.kt 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/kotlin/com/flightfeather/uav/lightshare/service/RealTimeDataService.kt 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/kotlin/com/flightfeather/uav/lightshare/service/impl/RealTimeDataServiceImpl.kt 13 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/kotlin/com/flightfeather/uav/lightshare/web/RealTimeDataController.kt 4 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/application.yml 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/test/kotlin/com/flightfeather/uav/UAVApplicationTests.kt 10 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
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 {
        /**
         * 是否是第二天或更新的时间
         */
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>>
}
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)
    }
}
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)
}
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
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)
    }
}