From 1fa0e57df26dcbf9f7c936806b5f4f0744e1d543 Mon Sep 17 00:00:00 2001 From: riku <risaku@163.com> Date: 星期一, 15 十一月 2021 17:42:01 +0800 Subject: [PATCH] 1. 网格化数据查询添加秒级值和分钟值的选择 --- src/main/kotlin/com/flightfeather/uav/lightshare/service/impl/RealTimeDataServiceImpl.kt | 140 +++++++++++++++++++++++++++++++++++++++++----- 1 files changed, 123 insertions(+), 17 deletions(-) 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 cce2f37..48aff07 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 @@ -4,11 +4,9 @@ import com.flightfeather.uav.common.utils.ExcelUtil import com.flightfeather.uav.common.utils.FileExchange import com.flightfeather.uav.common.utils.GsonUtils +import com.flightfeather.uav.dataprocess.AverageUtil import com.flightfeather.uav.domain.entity.* -import com.flightfeather.uav.domain.mapper.RealTimeDataGridMapper -import com.flightfeather.uav.domain.mapper.RealTimeDataMapper -import com.flightfeather.uav.domain.mapper.RealTimeDataUavMapper -import com.flightfeather.uav.domain.mapper.RealTimeDataVehicleMapper +import com.flightfeather.uav.domain.mapper.* import com.flightfeather.uav.lightshare.bean.* import com.flightfeather.uav.lightshare.service.RealTimeDataService import com.flightfeather.uav.model.epw.EPWDataPrep @@ -22,8 +20,11 @@ import tk.mybatis.mapper.entity.Example import java.io.ByteArrayInputStream import java.text.SimpleDateFormat +import java.time.LocalDateTime +import java.time.format.DateTimeFormatter import java.util.* import javax.servlet.http.HttpServletResponse +import javax.swing.text.DateFormatter @Service class RealTimeDataServiceImpl( @@ -31,38 +32,64 @@ private val airDataRepository: AirDataRepository, private val realTimeDataVehicleMapper: RealTimeDataVehicleMapper, private val realTimeDataUavMapper: RealTimeDataUavMapper, - private val realTimeDataGridMapper: RealTimeDataGridMapper + private val realTimeDataGridMapper: RealTimeDataGridMapper, + private val realTimeDataGridMinMapper: RealTimeDataGridMinMapper ) : RealTimeDataService { private var dateFormatter = SimpleDateFormat("yyyy-MM-dd HH:mm:ss") + private var dateFormatter2 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm") private val fileExchange = FileExchange() - override fun getSecondData(deviceCode: String?, startTime: String?, endTime: String?, page: Int?, perPage: Int?): BaseResponse<List<DataVo>> { + override fun getSecondData(deviceCode: String?, startTime: String?, endTime: String?, type: Int?, 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) +// var pageInfo = PageHelper.startPage<BaseRealTimeData>(_page, _perPage) + var pageNum = 1 + var pages = 0 val result = mutableListOf<DataVo>() when (UWDeviceType.getType(deviceCode)) { UWDeviceType.VEHICLE -> { + val pageInfo = PageHelper.startPage<RealTimeDataVehicle>(_page, _perPage) realTimeDataVehicleMapper.selectByExample(Example(RealTimeDataVehicle::class.java).apply { getSecondDataExample(this, deviceCode, sTime, eTime) }).forEach { result.add(it.toDataVo()) } + pageNum = pageInfo.pageNum + pages = pageInfo.pages } UWDeviceType.UAV -> { + val pageInfo = PageHelper.startPage<RealTimeDataUav>(_page, _perPage) realTimeDataUavMapper.selectByExample(Example(RealTimeDataUav::class.java).apply { getSecondDataExample(this, deviceCode, sTime, eTime) }).forEach { result.add(it.toDataVo()) } + pageNum = pageInfo.pageNum + pages = pageInfo.pages } UWDeviceType.GRID -> { - realTimeDataGridMapper.selectByExample(Example(RealTimeDataGrid::class.java).apply { - getSecondDataExample(this, deviceCode, sTime, eTime) - }).forEach { result.add(it.toDataVo()) } + // 缃戞牸鍖栫洃娴嬬绾у�� + if (type == null || type == 0) { + val pageInfo = PageHelper.startPage<RealTimeDataGrid>(_page, _perPage) + realTimeDataGridMapper.selectByExample(Example(RealTimeDataGrid::class.java).apply { + getSecondDataExample(this, deviceCode, sTime, eTime) + }).forEach { result.add(it.toDataVo()) } + pageNum = pageInfo.pageNum + pages = pageInfo.pages + } + // 缃戞牸鍖栫洃娴嬪垎閽熷�� + else if (type == 1) { + val pageInfo = PageHelper.startPage<RealTimeDataGridMin>(_page, _perPage) + realTimeDataGridMinMapper.selectByExample(Example(RealTimeDataGridMin::class.java).apply { + getSecondDataExample(this, deviceCode, sTime, eTime) + }).forEach { result.add(it.toDataVo()) } + pageNum = pageInfo.pageNum + pages = pageInfo.pages + } } else -> { // 浠庡師濮嬫暟鎹〃涓幏鍙栨暟鎹� + val pageInfo = PageHelper.startPage<RealTimeData>(_page, _perPage) realTimeDataMapper.selectByExample(Example(RealTimeData::class.java).apply { getSecondDataExample(this, deviceCode, sTime, eTime) }).forEach { @@ -71,13 +98,15 @@ } result.add(it.toDataVo()) } + pageNum = pageInfo.pageNum + pages = pageInfo.pages } } if (startTime == null && endTime == null) { result.reverse() } - return BaseResponse(true, head = DataHead(pageInfo.pageNum, pageInfo.pages), data = result) + return BaseResponse(true, head = DataHead(pageNum, pages), data = result) } private fun getSecondDataExample(example: Example, deviceCode: String?, sTime: Date?, eTime: Date?) { @@ -198,17 +227,94 @@ return contents } + private fun getOriginData(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) } +// var pageInfo = PageHelper.startPage<BaseRealTimeData>(_page, _perPage) + var pageNum = 1 + var pages = 0 + val result = mutableListOf<DataVo>() + + // 浠庡師濮嬫暟鎹〃涓幏鍙栨暟鎹� + val pageInfo = PageHelper.startPage<RealTimeData>(_page, _perPage) + realTimeDataMapper.selectByExample(Example(RealTimeData::class.java).apply { + getSecondDataExample(this, deviceCode, sTime, eTime) + }).forEach { + if (it.longitude == null || it.latitude == null) { + return@forEach + } + result.add(it.toDataVo()) + } + pageNum = pageInfo.pageNum + pages = pageInfo.pages + + if (startTime == null && endTime == null) { + result.reverse() + } + return BaseResponse(true, head = DataHead(pageNum, pages), data = result) + } + override fun dataPreprocessing(): BaseResponse<String> { val epwDataPrep = EPWDataPrep() - val res = getSecondData("0b0000000002", "2021-10-23 19:00:00", "2021-10-23 20:00:00", 1, 5000) - val dataList = res.data ?: emptyList() + var page = 1 + var total = -1 var count = 0 - dataList.forEach { - val result = epwDataPrep.mDataPrep2(listOf(it)) + + while (total == -1 || page <= total) { + println("------鏁版嵁棰勫鐞唖tart------") + val res = getOriginData("0d0000000001", "2021-07-05 19:47:01", "2021-11-05 00:00:00", page, 50000) + res.head?.let { + total = it.totalPage + } + if (page == 1) { + println("鎬婚〉鏁帮細$total") + } + println("褰撳墠椤垫暟锛�$page") + val dataList = res.data ?: emptyList() + val result = epwDataPrep.mDataPrep2(dataList) count += airDataRepository.savePrepData2(result) - println("[${it.deviceCode}]: [${it.time}]") - Thread.sleep(4000) + page++ } + + return BaseResponse(count > 0, data = "鎻掑叆鏁版嵁: ${count}鏉�") + } + + override fun averageData(): BaseResponse<String> { + var page = 1 + var total = -1 + var count = 0 + + val minFormatter = SimpleDateFormat("yyyy-MM-dd HH:mm") + val averageUtil = AverageUtil<RealTimeDataGrid, RealTimeDataGridMin>({d -> + minFormatter.format(d.dataTime) + },{list -> + list.avg() + }) + + while (total == -1 || page <= total) { + println("------鍧囧�艰绠梥tart------") + + val p = PageHelper.startPage<RealTimeDataGrid>(page, 50000) + val res = realTimeDataGridMapper.selectByExample(Example(RealTimeDataGrid::class.java).apply { + createCriteria().andBetween("dataTime", "2021-06-01 00:00:00", "2021-11-05 00:00:00") + }) + + total = p.pages + + if (page == 1) { + println("鎬婚〉鏁帮細$total") + } + println("褰撳墠椤垫暟锛�$page") + averageUtil.avg(res).forEach { + realTimeDataGridMinMapper.insert(it) + count++ + } + + page++ + } + return BaseResponse(count > 0, data = "鎻掑叆鏁版嵁: ${count}鏉�") } } \ No newline at end of file -- Gitblit v1.9.3