| | |
| | | |
| | | import com.alibaba.fastjson.JSONObject |
| | | import com.flightfeather.uav.common.exception.BizException |
| | | import com.flightfeather.uav.domain.entity.GridDataDetail |
| | | import com.flightfeather.uav.domain.entity.RealTimeData |
| | | import com.flightfeather.uav.domain.entity.RealTimeDataVehicle |
| | | import com.flightfeather.uav.socket.bean.AirData |
| | |
| | | } |
| | | |
| | | /** |
| | | * 转换为PM2.5表格数据 |
| | | */ |
| | | fun exchangeGridData(file: InputStream): List<GridDataDetail> { |
| | | val headers = listOf( |
| | | "pointid", |
| | | "PM2.5" |
| | | ) |
| | | val result = mutableListOf<GridDataDetail>() |
| | | try { |
| | | ExcelUtil.readXLXS(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 BizException("文件格式错误, 表头[${head}]应该为[${cellText}]") |
| | | } |
| | | } else { |
| | | throw BizException("文件格式错误, 表头[${head}]缺失") |
| | | } |
| | | } |
| | | true |
| | | }, onRow = { |
| | | val data = GridDataDetail().apply { |
| | | try { |
| | | this.cellId = it.getCell(0)?.numericCellValue?.toInt() |
| | | } catch (e: Exception) { |
| | | throw BizException("单元格[${it.rowNum}${0}]不是数字类型") |
| | | } |
| | | try { |
| | | this.pm25 = it.getCell(1)?.numericCellValue?.toFloat() |
| | | } catch (e: Exception) { |
| | | throw BizException("单元格[${it.rowNum}${1}]不是数字类型") |
| | | } |
| | | } |
| | | result.add(data) |
| | | }) |
| | | } catch (e: BizException) { |
| | | throw e |
| | | } |
| | | return result |
| | | } |
| | | |
| | | /** |
| | | * 转换车载走航数据 |
| | | */ |
| | | fun exchangeVehicleData(deviceCode: String, file: InputStream): List<RealTimeDataVehicle> { |