1. 修改网格组数据导入接口返回值为bool 2. 修改网格组数据批量更新 使用Transactional注解
| | |
| | | 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 |
| | |
| | | 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(",")}") |
| | |
| | | } |
| | | 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(",")}") |
| | |
| | | import org.apache.ibatis.annotations.Mapper |
| | | |
| | | @Mapper |
| | | interface GridDataDetailMapper : MyMapper<GridDataDetail?> { |
| | | fun updatePM25Batch(gridDataDetails: List<GridDataDetail>) |
| | | } |
| | | interface GridDataDetailMapper : MyMapper<GridDataDetail?> |
| | |
| | | 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 |
| | | |
| | |
| | | }) |
| | | } |
| | | |
| | | /** |
| | | * æå
¥ç½æ ¼ç»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 { |
| | |
| | | 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) |
| | |
| | | }) |
| | | } |
| | | |
| | | /** |
| | | * è·åç½æ ¼ç»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) |
| | |
| | | }) |
| | | } |
| | | |
| | | /** |
| | | * æå
¥ç½æ ¼ç»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 { |
| | |
| | | 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 { |
| | |
| | | .andEqualTo("cellId", it.cellId) |
| | | }) |
| | | } |
| | | |
| | | } |
| | | |
| | | } |
| | |
| | | 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 |
| | |
| | | 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 |
| | | } |
| | |
| | | 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 |
| | |
| | | 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ç´æ¥æ¥é |
| | |
| | | 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) { |
| | |
| | | it.groupId = gridData[0]?.groupId |
| | | } |
| | | satelliteGridRep.updatePM25Batch(importData) |
| | | return GridDataImportResult(true, "è¦çæå") |
| | | return true |
| | | }else { |
| | | // ç¨æ·éè¦æ§è¡æå
¥ |
| | | if (gridData.isNotEmpty()) { |
| | |
| | | ?.let { Date(it) } |
| | | gridDataEntity.type = type.toByte() |
| | | satelliteGridRep.insertGridDataAndDetail(gridDataEntity, importData) |
| | | return GridDataImportResult(true, "导å
¥æå") |
| | | return true |
| | | } |
| | | } |
| | | |
| | |
| | | dataTime: LocalDateTime?, |
| | | update: Boolean, |
| | | file: MultipartFile |
| | | ): GridDataImportResult? { |
| | | ): Boolean? { |
| | | // é¦å
夿æä»¶ç±»åï¼æä»¶ç±»å䏿¯xlsxç´æ¥æ¥é |
| | | if (!file.contentType!!.startsWith("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")) { |
| | | throw BizException("æä»¶ç±»åé误ï¼è¯·ä¸ä¼ xlsxç±»åæä»¶") |
| | |
| | | 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) { |
| | |
| | | it.groupId = gridAod[0]?.groupId |
| | | } |
| | | satelliteGridRep.updateGridAodBatch(importAod) |
| | | return GridDataImportResult(true, "è¦çæå") |
| | | return true |
| | | }else { |
| | | // ç¨æ·éè¦æ§è¡æå
¥ |
| | | if (gridAod.isNotEmpty()) { |
| | |
| | | gridAodEntity.dataTime = dataTime?.atZone(ZoneId.systemDefault())?.toInstant()?.toEpochMilli() |
| | | ?.let { Date(it) } |
| | | satelliteGridRep.insertGridAodAndDetail(gridAodEntity, importAod) |
| | | return GridDataImportResult(true, "导å
¥æå") |
| | | return true |
| | | } |
| | | } |
| | | |
| | |
| | | @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) |
| | |
| | | @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) |
| | |
| | | --> |
| | | 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> |