| | |
| | | package com.flightfeather.uav.common.utils |
| | | |
| | | import com.alibaba.fastjson.JSONObject |
| | | import com.flightfeather.uav.common.exception.ResponseErrorException |
| | | import com.flightfeather.uav.domain.entity.RealTimeData |
| | | import com.flightfeather.uav.socket.bean.AirData |
| | | import org.apache.poi.hssf.usermodel.HSSFWorkbook |
| | |
| | | import java.util.* |
| | | |
| | | /** |
| | | * 无人船采集数据格式转换 |
| | | * 采集数据格式转换 |
| | | */ |
| | | class FileExchange { |
| | | |
| | |
| | | private val format = SimpleDateFormat("yyyy-MM-dd HH:mm:ss") |
| | | } |
| | | |
| | | fun exchangeJinanData(file: File) { |
| | | val headers = listOf( |
| | | "longitude", |
| | | "latitude", |
| | | "data_time", |
| | | "NO2", |
| | | "CO", |
| | | "H2S", |
| | | "SO2", |
| | | "O3", |
| | | "PM25", |
| | | "PM10", |
| | | "temperature", |
| | | "humidity", |
| | | "VOC", |
| | | "NOI", |
| | | "velocity", |
| | | "wind_speed", |
| | | "wind_direction" |
| | | ) |
| | | try { |
| | | ExcelUtil.read(file, headerCheck = { |
| | | val cellIterator = it.cellIterator() |
| | | val headIterator = headers.iterator() |
| | | while (headIterator.hasNext()) { |
| | | val head = headIterator.next() |
| | | if (cellIterator.hasNext()) { |
| | | val cellText = cellIterator.next().stringCellValue |
| | | if (!cellText.equals(head)) { |
| | | throw ResponseErrorException("文件格式错误, 表头[${head}]应该为[${cellText}]") |
| | | } |
| | | } else { |
| | | throw ResponseErrorException("文件格式错误, 表头[${head}]缺失") |
| | | } |
| | | } |
| | | true |
| | | }, onRow = { |
| | | it.cellIterator().forEach { |
| | | it.numericCellValue |
| | | } |
| | | }) |
| | | } catch (e: Exception) { |
| | | throw ResponseErrorException("excel文件内容错误,数据转换失败!", e) |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 转换无人船的水质监测数据 |
| | | */ |
| | | fun exchangeBoatData(deviceCode: String, file: InputStream): List<RealTimeData> { |
| | | val workbook = HSSFWorkbook(file) |
| | | val sheet = workbook.getSheetAt(0) |
| | |
| | | val filePath = "e:/$fileName" |
| | | val out = FileOutputStream(File(filePath)) |
| | | |
| | | val heads = listOf("id", "device_code", "latitude", "longitude", "altitude", "height", "factors", "data_time", "create_time") |
| | | val heads = listOf("id", |
| | | "device_code", |
| | | "latitude", |
| | | "longitude", |
| | | "altitude", |
| | | "height", |
| | | "factors", |
| | | "data_time", |
| | | "create_time") |
| | | val contents = mutableListOf<Array<Any>>() |
| | | |
| | | for (i in 1..sheet.lastRowNum) { |