| | |
| | | package com.flightfeather.uav.lightshare.service.impl |
| | | |
| | | import com.flightfeather.uav.common.scaleMap |
| | | import com.flightfeather.uav.common.utils.DateUtil |
| | | import com.flightfeather.uav.common.utils.ExcelUtil |
| | | import com.flightfeather.uav.common.utils.FileExchange |
| | |
| | | import com.flightfeather.uav.socket.eunm.UWDeviceType |
| | | import com.github.pagehelper.PageHelper |
| | | import org.apache.poi.xssf.streaming.SXSSFWorkbook |
| | | import org.springframework.beans.BeanUtils |
| | | import org.springframework.stereotype.Service |
| | | import org.springframework.web.multipart.MultipartFile |
| | | import tk.mybatis.mapper.entity.Example |
| | | import java.io.ByteArrayInputStream |
| | | import java.text.SimpleDateFormat |
| | | import java.time.LocalDateTime |
| | | import java.time.ZoneId |
| | | import java.time.format.DateTimeFormatter |
| | | import java.util.* |
| | | import javax.servlet.http.HttpServletResponse |
| | | import javax.swing.text.DateFormatter |
| | | import kotlin.math.sqrt |
| | | |
| | | @Service |
| | | class RealTimeDataServiceImpl( |
| | |
| | | private val realTimeDataVehicleMapper: RealTimeDataVehicleMapper, |
| | | private val realTimeDataUavMapper: RealTimeDataUavMapper, |
| | | private val realTimeDataGridMapper: RealTimeDataGridMapper, |
| | | private val realTimeDataGridOptMapper: RealTimeDataGridOptMapper, |
| | | private val realTimeDataGridMinMapper: RealTimeDataGridMinMapper |
| | | ) : RealTimeDataService { |
| | | |
| | |
| | | return BaseResponse(true, data = DataImportResult("")) |
| | | } |
| | | |
| | | override fun importJinanData(file: MultipartFile): BaseResponse<DataImportResult> { |
| | | TODO("Not yet implemented") |
| | | } |
| | | |
| | | override fun outToWorkbook(deviceCode: String, startTime: String, endTime: String): SXSSFWorkbook { |
| | | val sTime = dateFormatter.parse(startTime) |
| | | val eTime = dateFormatter.parse(endTime) |
| | |
| | | return contents |
| | | } |
| | | |
| | | private fun getOriginData(deviceCode: String?, startTime: String?, endTime: String?, page: Int?, perPage: Int?): BaseResponse<List<DataVo>> { |
| | | override 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) } |
| | |
| | | var count = 0 |
| | | |
| | | val minFormatter = SimpleDateFormat("yyyy-MM-dd HH:mm") |
| | | val averageUtil = AverageUtil<RealTimeDataGrid, RealTimeDataGridMin>({d -> |
| | | val averageUtil = AverageUtil<RealTimeDataGridOpt, RealTimeDataGridMin>({d -> |
| | | minFormatter.format(d.dataTime) |
| | | },{list -> |
| | | list.avg() |
| | |
| | | while (total == -1 || page <= total) { |
| | | println("------均值计算start------") |
| | | |
| | | val p = PageHelper.startPage<RealTimeDataGrid>(page, 50000) |
| | | val res = realTimeDataGridMapper.selectByExample(Example(RealTimeDataGrid::class.java).apply { |
| | | val p = PageHelper.startPage<RealTimeDataGridOpt>(page, 50000) |
| | | val res = realTimeDataGridOptMapper.selectByExample(Example(RealTimeDataGridOpt::class.java).apply { |
| | | createCriteria().andBetween("dataTime", "2021-06-01 00:00:00", "2021-11-05 00:00:00") |
| | | }) |
| | | |
| | |
| | | |
| | | return BaseResponse(count > 0, data = "插入数据: ${count}条") |
| | | } |
| | | |
| | | override fun dataCalibration(): BaseResponse<String> { |
| | | var page = 1 |
| | | var total = -1 |
| | | var count = 0 |
| | | val sT = "2021-06-19 00:00:00" |
| | | val eT = "2021-10-21 00:00:00" |
| | | |
| | | println("------数据优化start------") |
| | | while (total == -1 || page <= total) { |
| | | // 预处理后的网格化数据 |
| | | val p = PageHelper.startPage<RealTimeDataGrid>(page, 50000) |
| | | val dataList1 = realTimeDataGridMapper.selectByExample(Example(RealTimeDataGrid::class.java).apply { |
| | | createCriteria().andBetween("dataTime", sT, eT) |
| | | }) |
| | | // 原始数据(H2S) |
| | | val res = getOriginData("0d0000000001", sT, eT, page, 50000) |
| | | val dataList2 = res.data ?: emptyList() |
| | | |
| | | total = p.pages |
| | | |
| | | if (page == 1) { |
| | | println("总页数:$total") |
| | | } |
| | | println("当前页数:$page") |
| | | |
| | | for (i in dataList1.indices) { |
| | | if (i >= dataList2.size) break |
| | | val d1 = dataList1[i] |
| | | val d2 = dataList2[i] |
| | | // 判断小时,获取对应时段的优化系数 |
| | | val h = LocalDateTime.ofInstant(d1.dataTime?.toInstant(), ZoneId.systemDefault()).hour |
| | | val scaleList = scaleMap[h] ?: continue |
| | | d1.apply { |
| | | // 各预处理后的因子(除H2S)乘系数 |
| | | no2 = no2?.times(scaleList[0]) |
| | | co = co?.times(scaleList[1]) |
| | | so2 = so2?.times(scaleList[3]) |
| | | o3 = o3?.times(scaleList[4]) |
| | | voc = voc?.times(scaleList[7]) |
| | | |
| | | // 单独把原始的H2S乘以系数 |
| | | h2s = d2.values?.get(2)?.factorData?.toFloat()?.times(scaleList[2]) |
| | | h2s = h2s?.let { sqrt(it) * 2 } |
| | | } |
| | | |
| | | // 更新秒级值 |
| | | val opt = RealTimeDataGridOpt() |
| | | BeanUtils.copyProperties(d1, opt) |
| | | count += realTimeDataGridOptMapper.insert(opt) |
| | | } |
| | | page++ |
| | | } |
| | | |
| | | return BaseResponse(count > 0, data = "插入数据: ${count}条") |
| | | } |
| | | } |