From 9d4ca2e7bdfc0d634b0cc27c7fbe23740f4bb398 Mon Sep 17 00:00:00 2001 From: hcong <1050828145@qq.com> Date: 星期五, 27 十二月 2024 15:43:30 +0800 Subject: [PATCH] 1. 新增aod数据索引,aod详细数据实体类,mapper,service 2. 新增卫星遥测数据网格数据pm2.5、aod数据导入,模板下载 3. FileExchange.kt 新增转换pm2.5和aod数据方法 --- src/main/kotlin/com/flightfeather/uav/common/utils/ExcelUtil.kt | 35 +++++++++++++++++++++++++++-------- 1 files changed, 27 insertions(+), 8 deletions(-) diff --git a/src/main/kotlin/com/flightfeather/uav/common/utils/ExcelUtil.kt b/src/main/kotlin/com/flightfeather/uav/common/utils/ExcelUtil.kt index 6d598ef..c73f36b 100644 --- a/src/main/kotlin/com/flightfeather/uav/common/utils/ExcelUtil.kt +++ b/src/main/kotlin/com/flightfeather/uav/common/utils/ExcelUtil.kt @@ -1,14 +1,13 @@ package com.flightfeather.uav.common.utils -import com.flightfeather.uav.common.exception.ResponseErrorException +import com.flightfeather.uav.common.exception.BizException +import org.apache.poi.hssf.usermodel.HSSFRow import org.apache.poi.hssf.usermodel.HSSFWorkbook import org.apache.poi.ss.usermodel.Row import org.apache.poi.ss.util.CellRangeAddress import org.apache.poi.xssf.streaming.SXSSFWorkbook import org.apache.poi.xssf.usermodel.XSSFRow import org.apache.poi.xssf.usermodel.XSSFWorkbook -import org.jetbrains.kotlin.incremental.isJavaFile -import java.io.ByteArrayInputStream import java.io.File import java.io.FileInputStream import java.io.InputStream @@ -37,15 +36,18 @@ * @param headerCheck 鏂囦欢棣栬妫�鏌ュ洖璋� * @param onRow 鍗曡鍐呭鍥炶皟锛屼粠绗簩琛屽紑濮� */ - fun read(file: File, headerCheck: (header: XSSFRow) -> Boolean, onRow: (row: Row) -> Unit): Boolean { - if (!file.exists() || !file.isFile) throw ResponseErrorException("it's not a normal file!") + fun readXLXS(file: File, headerCheck: (header: XSSFRow) -> Boolean, onRow: (row: Row) -> Unit): Boolean { + if (!file.exists() || !file.isFile) throw BizException("it's not a normal file!") if (!file.extension.equals("xls", ignoreCase = true) || !file.extension.equals("xlsx", ignoreCase = true)) { - throw ResponseErrorException("file's extension name should be xls or xlsx!") + throw BizException("file's extension name should be xls or xlsx!") } - return read(FileInputStream(file), headerCheck, onRow) + return readXLXS(FileInputStream(file), headerCheck, onRow) } - fun read(input: InputStream, headerCheck: (header: XSSFRow) -> Boolean, onRow: (row: Row) -> Unit): Boolean { + /** + * 鍖呮嫭 .xlsx 鏂囦欢 + */ + fun readXLXS(input: InputStream, headerCheck: (header: XSSFRow) -> Boolean, onRow: (row: Row) -> Unit): Boolean { val workbook = XSSFWorkbook(input) val sheet1 = workbook.getSheetAt(0) val header = sheet1.getRow(sheet1.topRow.toInt()) @@ -60,6 +62,23 @@ } /** + * 鍖呮嫭 .xls .csv 鏂囦欢 + */ + fun readXLS(input: InputStream, headerCheck: (header: HSSFRow) -> Boolean, onRow: (row: Row) -> Unit): Boolean { + val workbook = HSSFWorkbook(input) + val sheet1 = workbook.getSheetAt(0) + val header = sheet1.getRow(sheet1.topRow.toInt()) + return if (headerCheck(header)) { + // 鑾峰彇杩唬鍣ㄥ苟鍘婚櫎绗竴琛屾爣棰� + val iterator = sheet1.rowIterator().also { it.next() } + iterator.forEach { onRow(it) } + true + } else { + false + } + } + + /** * 鑷姩澶勭悊琛屽悎骞舵暟鎹� */ fun write2(heads: List<String>, contents: List<Array<Any>>, workbook: SXSSFWorkbook, sheetName: String) { -- Gitblit v1.9.3