feiyu02
2024-02-02 83455446544f89b0663a3f520744331ad8259289
src/main/kotlin/com/flightfeather/uav/common/utils/FileExchange.kt
@@ -3,6 +3,7 @@
import com.alibaba.fastjson.JSONObject
import com.flightfeather.uav.common.exception.ResponseErrorException
import com.flightfeather.uav.domain.entity.RealTimeData
import com.flightfeather.uav.domain.entity.RealTimeDataVehicle
import com.flightfeather.uav.socket.bean.AirData
import org.apache.poi.hssf.usermodel.HSSFWorkbook
import org.apache.poi.xssf.streaming.SXSSFWorkbook
@@ -28,11 +29,11 @@
        private val format = SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
    }
    fun exchangeJinanData(file: File) {
    fun exchangeJinanData(deviceCode: String, file: InputStream): List<RealTimeDataVehicle> {
        val headers = listOf(
            "data_time",
            "longitude",
            "latitude",
            "data_time",
            "NO2",
            "CO",
            "H2S",
@@ -48,6 +49,7 @@
            "wind_speed",
            "wind_direction"
        )
        val result = mutableListOf<RealTimeDataVehicle>()
        try {
            ExcelUtil.read(file, headerCheck = {
                val cellIterator = it.cellIterator()
@@ -65,13 +67,33 @@
                }
                true
            }, onRow = {
                it.cellIterator().forEach {
                    it.numericCellValue
                val data = RealTimeDataVehicle().apply {
                    this.deviceCode = deviceCode
                    dataTime = it.getCell(0).dateCellValue
                    longitude = it.getCell(1).numericCellValue.toBigDecimal()
                    latitude = it.getCell(2).numericCellValue.toBigDecimal()
                    no2 = it.getCell(3).numericCellValue.toFloat()
                    co = it.getCell(4).numericCellValue.toFloat()
                    h2s = it.getCell(5).numericCellValue.toFloat()
                    so2 = it.getCell(6).numericCellValue.toFloat()
                    o3 = it.getCell(7).numericCellValue.toFloat()
                    pm25 = it.getCell(8).numericCellValue.toFloat()
                    pm10 = it.getCell(9).numericCellValue.toFloat()
                    temperature = it.getCell(10).numericCellValue.toFloat()
                    humidity = it.getCell(11).numericCellValue.toFloat()
                    voc = it.getCell(12).numericCellValue.toFloat()
                    noi = it.getCell(13).numericCellValue.toFloat()
                    velocity = it.getCell(14).numericCellValue.toFloat()
                    windSpeed = it.getCell(15).numericCellValue.toFloat()
                    windDirection = it.getCell(16).numericCellValue.toFloat()
                }
                result.add(data)
            })
        } catch (e: Exception) {
            e.printStackTrace()
            throw ResponseErrorException("excel文件内容错误,数据转换失败!", e)
        }
        return result
    }
    /**