| | |
| | | package com.flightfeather.uav.lightshare.service.impl |
| | | |
| | | 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.common.utils.GsonUtils |
| | |
| | | import com.flightfeather.uav.lightshare.service.RealTimeDataService |
| | | import com.flightfeather.uav.socket.bean.AirData |
| | | import com.github.pagehelper.PageHelper |
| | | import org.apache.poi.hssf.usermodel.HSSFWorkbook |
| | | import org.apache.poi.xssf.streaming.SXSSFWorkbook |
| | | import org.springframework.stereotype.Service |
| | | import org.springframework.web.multipart.MultipartFile |
| | | import tk.mybatis.mapper.entity.Example |
| | | import java.io.ByteArrayInputStream |
| | | import java.io.FileInputStream |
| | | import java.io.InputStream |
| | | import java.text.DateFormat |
| | | import java.text.SimpleDateFormat |
| | | import java.util.* |
| | | import javax.servlet.http.HttpServletResponse |
| | | |
| | | @Service |
| | |
| | | } |
| | | } |
| | | }).forEach { |
| | | if (it.longitude == null || it.latitude == null) { |
| | | return@forEach |
| | | } |
| | | result.add(DataVo( |
| | | dateFormatter.format(it.dataTime), |
| | | it.deviceCode, |
| | | GsonUtils.parserJsonToArrayBeans(it.factors, AirData::class.java), |
| | | it.longitude.toDouble(), it.latitude.toDouble() |
| | | it.longitude?.toDouble(), it.latitude?.toDouble() |
| | | )) |
| | | } |
| | | if (startTime == null && endTime == null) { |
| | |
| | | return BaseResponse(true, data = DataImportResult("")) |
| | | } |
| | | |
| | | override fun outToWorkbook(deviceCode: String, startTime: String, endTime: String): HSSFWorkbook { |
| | | override fun outToWorkbook(deviceCode: String, startTime: String, endTime: String): SXSSFWorkbook { |
| | | val sTime = dateFormatter.parse(startTime) |
| | | val eTime = dateFormatter.parse(endTime) |
| | | val r = realTimeDataMapper.selectByExample(Example(RealTimeData::class.java).apply { |
| | | createCriteria().andEqualTo("deviceCode", deviceCode) |
| | | .apply { |
| | | sTime?.let { andGreaterThanOrEqualTo("dataTime", it) } |
| | | eTime?.let { andLessThanOrEqualTo("dataTime", it) } |
| | | var page = 1 |
| | | var totalPage = 1 |
| | | val pageSize = 10000 |
| | | val workbook = SXSSFWorkbook() |
| | | var rowIndex = 0 |
| | | while (page <= totalPage) { |
| | | val pageInfo = PageHelper.startPage<RealTimeData>(page, pageSize) |
| | | val r = realTimeDataMapper.selectByExample(Example(RealTimeData::class.java).apply { |
| | | createCriteria().andEqualTo("deviceCode", deviceCode) |
| | | .apply { |
| | | sTime?.let { andGreaterThanOrEqualTo("dataTime", it) } |
| | | eTime?.let { andLessThanOrEqualTo("dataTime", it) } |
| | | } |
| | | }) |
| | | if (r.isNotEmpty()) { |
| | | val heads = if (page == 1) { |
| | | println("[${DateUtil.instance.dateToString(Date(), DateUtil.DateStyle.YYYY_MM_DD_HH_MM_SS)}] totalPage: ${pageInfo.pages}") |
| | | getTableTitle(r[0]) |
| | | } else { |
| | | emptyList() |
| | | } |
| | | }) |
| | | val workbook = HSSFWorkbook() |
| | | if (r.isNotEmpty()) { |
| | | val heads = getTableTitle(r[0]) |
| | | val contents = getTableContents(r) |
| | | |
| | | ExcelUtil.write(heads, contents, workbook) |
| | | val contents = getTableContents(r) |
| | | print("[${DateUtil.instance.dateToString(Date(), DateUtil.DateStyle.YYYY_MM_DD_HH_MM_SS)}] currentPage: ${pageInfo.pageNum}......") |
| | | rowIndex = ExcelUtil.write(heads, contents, workbook, row = rowIndex) |
| | | println("output done") |
| | | } |
| | | totalPage = pageInfo.pages |
| | | page++ |
| | | } |
| | | return workbook |
| | | } |