1. 修改网格组数据导入接口返回值为bool 2. 修改网格组数据批量更新 使用Transactional注解
已修改7个文件
已删除1个文件
149 ■■■■■ 文件已修改
src/main/kotlin/com/flightfeather/uav/common/utils/FileExchange.kt 31 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/kotlin/com/flightfeather/uav/domain/mapper/GridDataDetailMapper.kt 4 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/kotlin/com/flightfeather/uav/domain/repository/SatelliteGridRep.kt 65 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/kotlin/com/flightfeather/uav/lightshare/bean/GridDataImportResult.kt 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/kotlin/com/flightfeather/uav/lightshare/service/SatelliteTelemetryService.kt 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/kotlin/com/flightfeather/uav/lightshare/service/impl/SatelliteTelemetryServiceImpl.kt 17 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/kotlin/com/flightfeather/uav/lightshare/web/SatelliteTelemetryController.kt 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapper/GridDataDetailMapper.xml 11 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/kotlin/com/flightfeather/uav/common/utils/FileExchange.kt
@@ -8,7 +8,6 @@
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.ss.usermodel.Cell
import org.apache.poi.ss.usermodel.CellType
import org.apache.poi.ss.util.CellAddress
import org.apache.poi.xssf.streaming.SXSSFWorkbook
@@ -166,23 +165,24 @@
                                this.pm25 = it.getCell(1)?.numericCellValue?.toFloat()
                            }
                            else -> {
                                throw BizException("单元格[${pm25CellPosStr}]不是数字类型")
                                throw BizException("单元格[${pm25CellPosStr}]不是数字类型或者文本类型")
                            }
                        }
                    }
                    result.add(data)
                })
        } catch (e: BizException) {
            throw e
        } catch (e: Exception) {
            e.printStackTrace()
            throw BizException("excel文件内容错误,数据转换失败!", e)
        }
        // åˆ¤æ–­ç½‘格单元格编号是否在正确的范围内
        val resultCellIdSet = result.asSequence().map { it.cellId ?: -1 }.toSet()
        val resultCellIdSet = result.map { it.cellId ?: -1 }.toSet()
        // ç”¨æˆ·å¯¼å…¥ä¸­ç¼ºå°‘的的单元格
        val shortCells = correctRangeGridCells - resultCellIdSet
        val lackCells = correctRangeGridCells - resultCellIdSet
        // excel ä¸­å¤šå‡ºçš„的单元格
        val outCells = resultCellIdSet - correctRangeGridCells
        if (shortCells.isNotEmpty()) {
            throw BizException("导入数据中缺少以下网格单元格:${shortCells.joinToString(",")}")
        if (lackCells.isNotEmpty()) {
            throw BizException("导入数据中缺少以下网格单元格:${lackCells.joinToString(",")}")
        }
        if (outCells.isNotEmpty()) {
            throw BizException("导入数据中有多余网格单元格:${outCells.joinToString(",")}")
@@ -265,17 +265,18 @@
                    }
                    result.add(data)
                })
        } catch (e: BizException) {
            throw e
        } catch (e: Exception) {
            e.printStackTrace()
            throw BizException("excel文件内容错误,数据转换失败!", e)
        }
        // åˆ¤æ–­ç½‘格单元格编号是否在正确的范围内
        val resultCellIdSet = result.asSequence().map { it.cellId ?: -1 }.toSet()
        val resultCellIdSet = result.map { it.cellId ?: -1 }.toSet()
        // ç”¨æˆ·å¯¼å…¥ä¸­ç¼ºå°‘的的单元格
        val shortCells = correctRangeGridCells - resultCellIdSet
        val lackCells = correctRangeGridCells - resultCellIdSet
        // excel ä¸­å¤šå‡ºçš„的单元格
        val outCells = resultCellIdSet - correctRangeGridCells
        if (shortCells.isNotEmpty()) {
            throw BizException("导入数据中缺少以下网格单元格:${shortCells.joinToString(",")}")
        if (lackCells.isNotEmpty()) {
            throw BizException("导入数据中缺少以下网格单元格:${lackCells.joinToString(",")}")
        }
        if (outCells.isNotEmpty()) {
            throw BizException("导入数据中有多余网格单元格:${outCells.joinToString(",")}")
@@ -619,4 +620,4 @@
        out.flush()
        out.close()
    }
}
}
src/main/kotlin/com/flightfeather/uav/domain/mapper/GridDataDetailMapper.kt
@@ -5,6 +5,4 @@
import org.apache.ibatis.annotations.Mapper
@Mapper
interface GridDataDetailMapper : MyMapper<GridDataDetail?> {
    fun updatePM25Batch(gridDataDetails: List<GridDataDetail>)
}
interface GridDataDetailMapper : MyMapper<GridDataDetail?>
src/main/kotlin/com/flightfeather/uav/domain/repository/SatelliteGridRep.kt
@@ -9,6 +9,7 @@
import com.flightfeather.uav.domain.mapper.GridGroupMapper
import com.flightfeather.uav.lightshare.bean.AreaVo
import org.springframework.stereotype.Repository
import org.springframework.transaction.annotation.Transactional
import tk.mybatis.mapper.entity.Example
import java.time.LocalDateTime
@@ -61,6 +62,14 @@
        })
    }
    /**
     * æ’入网格组PM2.5数据索引和详细数据。
     *
     * @param data ç½‘格组PM2.5数据索引。
     * @param gridDataDetails ç½‘格组PM2.5详细数据列表。
     * @author hc
     * @date 2024-12-29
     */
    fun insertGridDataAndDetail(data: GridData, gridDataDetails: List<GridDataDetail>) {
        gridDataMapper.insert(data)
        gridDataDetails.forEach {
@@ -70,12 +79,33 @@
        gridDataDetailMapper.insertList(gridDataDetails)
    }
    /**
     * æ›´æ–°ç½‘格组详细数据。
     *
     * @param gridDataDetails éœ€è¦æ›´æ–°çš„网格组详细数据列表。
     * @author hc
     * @date 2024-12-29
     */
    @Transactional(rollbackFor = [Exception::class])
    fun updatePM25Batch(gridDataDetails: List<GridDataDetail>) {
        gridDataDetailMapper.updatePM25Batch(gridDataDetails)
        gridDataDetails.forEach {
            gridDataDetailMapper.updateByExample(it, Example(GridDataDetail::class.java).apply {
                createCriteria().andEqualTo("dataId", it.dataId)
                    .andEqualTo("groupId", it.groupId)
                    .andEqualTo("cellId", it.cellId)
            })
        }
    }
    //    aod ç›¸å…³æ“ä½œ
    /**
     * æ ¹æ®ç»„ID和数据时间获取网格组aod数据索引。
     *
     * @param groupId ç½‘格组ID。
     * @param dataTime æ•°æ®æ—¶é—´ã€‚
     * @return ç½‘格组aod数据索引列表。
     * @author hc
     * @date 2024-12-29
     */
    fun fetchGridAod(groupId: Int, dataTime: LocalDateTime?): List<GridAod?> {
        return gridAodMapper.selectByExample(Example(GridAod::class.java).apply {
            createCriteria().andEqualTo("groupId", groupId)
@@ -83,6 +113,16 @@
        })
    }
    /**
     * èŽ·å–ç½‘æ ¼ç»„aod数据详情。
     *
     * @param aodId aod数据ID。
     * @param groupId ç½‘格组ID。
     * @param cellId å•元格ID。
     * @return ç½‘格组aod数据详情列表。
     * @author hc
     * @date 2024-12-29
     */
    fun fetchGridAodDetail(aodId: Int, groupId: Int?, cellId: Int?): List<GridAodDetail?> {
        return gridAodDetailMapper.selectByExample(Example(GridAodDetail::class.java).apply {
            createCriteria().andEqualTo("aodId", aodId)
@@ -92,6 +132,14 @@
        })
    }
    /**
     * æ’入网格组aod数据索引和详细数据。
     *
     * @param aod ç½‘格组aod数据索引。
     * @param gridAodDetails ç½‘格组aod详细数据列表。
     * @author hc
     * @date 2024-12-29
     */
    fun insertGridAodAndDetail(aod: GridAod, gridAodDetails: List<GridAodDetail>) {
        gridAodMapper.insert(aod)
        gridAodDetails.forEach {
@@ -101,6 +149,14 @@
        gridAodDetailMapper.insertList(gridAodDetails)
    }
    /**
     * æ›´æ–°ç½‘格组aod数据详情。
     *
     * @param gridDataDetails éœ€è¦æ›´æ–°çš„网格组aod详细数据列表。
     * @author hc
     * @date 2024-12-29
     */
    @Transactional(rollbackFor = [Exception::class])
    fun updateGridAodBatch(gridDataDetails: List<GridAodDetail>) {
        gridDataDetails.forEach {
            gridAodDetailMapper.updateByExample(it, Example(GridAodDetail::class.java).apply {
@@ -109,7 +165,6 @@
                    .andEqualTo("cellId", it.cellId)
            })
        }
    }
}
}
src/main/kotlin/com/flightfeather/uav/lightshare/bean/GridDataImportResult.kt
ÎļþÒÑɾ³ý
src/main/kotlin/com/flightfeather/uav/lightshare/service/SatelliteTelemetryService.kt
@@ -8,7 +8,6 @@
import com.flightfeather.uav.domain.entity.GridGroup
import com.flightfeather.uav.lightshare.bean.AreaVo
import com.flightfeather.uav.lightshare.bean.DataHead
import com.flightfeather.uav.lightshare.bean.GridDataImportResult
import org.springframework.web.multipart.MultipartFile
import java.time.LocalDateTime
import javax.servlet.http.HttpServletResponse
@@ -29,14 +28,14 @@
    fun fetchGridDataDetail(dataId: Int, groupId: Int?, cellId: Int?): List<GridDataDetail?>
    @Throws(BizException::class)
    fun importGridData(groupId: Int, dataTime: LocalDateTime?, update: Boolean, file: MultipartFile): GridDataImportResult?
    fun importGridData(groupId: Int, dataTime: LocalDateTime?, update: Boolean, file: MultipartFile): Boolean?
    fun downloadTemplate(response: HttpServletResponse): Boolean
    fun fetchGridAod(groupId: Int, dataTime: LocalDateTime?): List<GridAod?>
    @Throws(BizException::class)
    fun importGridAOD(groupId: Int, dataTime: LocalDateTime?, update: Boolean, file: MultipartFile): GridDataImportResult?
    fun importGridAOD(groupId: Int, dataTime: LocalDateTime?, update: Boolean, file: MultipartFile): Boolean?
    fun downloadAODTemplate(response: HttpServletResponse): Boolean
}
src/main/kotlin/com/flightfeather/uav/lightshare/service/impl/SatelliteTelemetryServiceImpl.kt
@@ -10,7 +10,6 @@
import com.flightfeather.uav.domain.repository.SatelliteGridRep
import com.flightfeather.uav.lightshare.bean.AreaVo
import com.flightfeather.uav.lightshare.bean.DataHead
import com.flightfeather.uav.lightshare.bean.GridDataImportResult
import com.flightfeather.uav.lightshare.service.SatelliteTelemetryService
import com.github.pagehelper.PageHelper
import org.springframework.stereotype.Service
@@ -53,7 +52,7 @@
        return satelliteGridRep.fetchGridDataDetail(dataId, groupId, cellId)
    }
    override fun importGridData(groupId: Int, dataTime: LocalDateTime?, update: Boolean, file: MultipartFile): GridDataImportResult? {
    override fun importGridData(groupId: Int, dataTime: LocalDateTime?, update: Boolean, file: MultipartFile): Boolean? {
        // å› ä¸ºæ˜¯å¯¼å…¥å«æ˜Ÿé¥æµ‹æ•°æ® type始终为0
        val type = 0
        // é¦–先判断文件类型,文件类型不是xlsx直接报错
@@ -65,7 +64,7 @@
        val gridData = satelliteGridRep.fetchGridData(groupId, dataTime, type)
        // å°†ç”¨æˆ·å¯¼å…¥çš„æ–‡ä»¶è½¬æ¢ä¸ºæ•°æ®
        // è½¬æ¢çš„过程需要网格单元格数据 ä»¥åˆ¤æ–­ç½‘格单元格是否在正确的范围内
        val gridCellsInDBSet = satelliteGridRep.fetchGridCell(groupId).asSequence().map { it?.id ?: -1 }.toSet()
        val gridCellsInDBSet = satelliteGridRep.fetchGridCell(groupId).map { it?.id ?: -1 }.toSet()
        val importData
                = fileExchange.exchangeGridData(ByteArrayInputStream(file.bytes), gridCellsInDBSet)
        if (update) {
@@ -78,7 +77,7 @@
                it.groupId = gridData[0]?.groupId
            }
            satelliteGridRep.updatePM25Batch(importData)
            return GridDataImportResult(true, "覆盖成功")
            return true
        }else {
            // ç”¨æˆ·éœ€è¦æ‰§è¡Œæ’å…¥
            if (gridData.isNotEmpty()) {
@@ -90,7 +89,7 @@
                ?.let { Date(it) }
            gridDataEntity.type = type.toByte()
            satelliteGridRep.insertGridDataAndDetail(gridDataEntity, importData)
            return GridDataImportResult(true, "导入成功")
            return true
        }
    }
@@ -120,7 +119,7 @@
        dataTime: LocalDateTime?,
        update: Boolean,
        file: MultipartFile
    ): GridDataImportResult? {
    ): Boolean? {
        // é¦–先判断文件类型,文件类型不是xlsx直接报错
        if (!file.contentType!!.startsWith("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")) {
            throw BizException("文件类型错误,请上传xlsx类型文件")
@@ -130,7 +129,7 @@
        val gridAod = satelliteGridRep.fetchGridAod(groupId, dataTime)
        // å°†ç”¨æˆ·å¯¼å…¥çš„æ–‡ä»¶è½¬æ¢ä¸ºæ•°æ®
        // è½¬æ¢çš„过程需要网格单元格数据 ä»¥åˆ¤æ–­ç½‘格单元格是否在正确的范围内
        val gridCellsInDBSet = satelliteGridRep.fetchGridCell(groupId).asSequence().map { it?.id ?: -1 }.toSet()
        val gridCellsInDBSet = satelliteGridRep.fetchGridCell(groupId).map { it?.id ?: -1 }.toSet()
        val importAod
                = fileExchange.exchangeGridAod(ByteArrayInputStream(file.bytes), gridCellsInDBSet)
        if (update) {
@@ -143,7 +142,7 @@
                it.groupId = gridAod[0]?.groupId
            }
            satelliteGridRep.updateGridAodBatch(importAod)
            return GridDataImportResult(true, "覆盖成功")
            return true
        }else {
            // ç”¨æˆ·éœ€è¦æ‰§è¡Œæ’å…¥
            if (gridAod.isNotEmpty()) {
@@ -154,7 +153,7 @@
            gridAodEntity.dataTime = dataTime?.atZone(ZoneId.systemDefault())?.toInstant()?.toEpochMilli()
                ?.let { Date(it) }
            satelliteGridRep.insertGridAodAndDetail(gridAodEntity, importAod)
            return GridDataImportResult(true, "导入成功")
            return true
        }
    }
src/main/kotlin/com/flightfeather/uav/lightshare/web/SatelliteTelemetryController.kt
@@ -61,7 +61,7 @@
        @ApiParam("网格组id") @RequestParam groupId: Int,
        @ApiParam("遥测数据时间")
        @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") dateTime: LocalDateTime,
        @ApiParam("覆盖旧数据 0: ä¸è¦†ç›– 1: è¦†ç›–") @RequestParam update: Boolean,
        @ApiParam("是否覆盖旧数据") @RequestParam update: Boolean,
        @RequestParam("excel") file: MultipartFile,
    ) = resPack {
        satelliteTelemetryService.importGridData(groupId, dateTime, update, file)
@@ -85,7 +85,7 @@
        @ApiParam("网格组id") @RequestParam groupId: Int,
        @ApiParam("遥测数据时间")
        @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") dateTime: LocalDateTime,
        @ApiParam("覆盖旧数据 0: ä¸è¦†ç›– 1: è¦†ç›–") @RequestParam update: Boolean,
        @ApiParam("是否覆盖旧数据") @RequestParam update: Boolean,
        @RequestParam("excel") file: MultipartFile,
    ) = resPack {
        satelliteTelemetryService.importGridAOD(groupId, dateTime, update, file)
src/main/resources/mapper/GridDataDetailMapper.xml
@@ -18,15 +18,4 @@
    -->
    id, data_id, group_id, cell_id, PM25, rank
  </sql>
  <!-- æ·»åŠ æ‰¹é‡æ›´æ–°PM25的函数 -->
  <update id="updatePM25Batch" parameterType="java.util.List">
    <foreach collection="list" item="item" separator=";">
      UPDATE grid_data_detail
      SET PM25 = #{item.pm25}
      WHERE data_id = #{item.dataId}
      AND group_id = #{item.groupId}
      AND cell_id = #{item.cellId}
    </foreach>
  </update>
</mapper>