| | |
| | | package com.flightfeather.uav.common.utils |
| | | |
| | | import java.text.DateFormat |
| | | import java.text.SimpleDateFormat |
| | | import java.util.* |
| | | |
| | | /** |
| | |
| | | class TimeUtil { |
| | | |
| | | companion object { |
| | | |
| | | /** |
| | | * 是否是第二天或更新的时间 |
| | | */ |
| | |
| | | |
| | | 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>> |
| | | } |
| | |
| | | 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) |
| | | } |
| | | } |
| | |
| | | @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) |
| | | } |
| | |
| | | # 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 |
| | |
| | | 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 |
| | | |
| | |
| | | @SpringBootTest |
| | | class UAVApplicationTests { |
| | | |
| | | @Autowired |
| | | lateinit var realTimeDataService: RealTimeDataService |
| | | |
| | | @Test |
| | | fun contextLoads() { |
| | |
| | | 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) |
| | | } |
| | | |
| | | } |