From 8cf331411ea79c0d83e00657ed1374b29b09f4d7 Mon Sep 17 00:00:00 2001 From: feiyu02 <risaku@163.com> Date: 星期五, 28 三月 2025 17:46:30 +0800 Subject: [PATCH] 1. 新增走航卫星网格数据之间的融合功能 --- src/main/kotlin/com/flightfeather/uav/lightshare/service/impl/SatelliteDataCalculateServiceImpl.kt | 117 +++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 files changed, 106 insertions(+), 11 deletions(-) diff --git a/src/main/kotlin/com/flightfeather/uav/lightshare/service/impl/SatelliteDataCalculateServiceImpl.kt b/src/main/kotlin/com/flightfeather/uav/lightshare/service/impl/SatelliteDataCalculateServiceImpl.kt index a765aa6..ece5805 100644 --- a/src/main/kotlin/com/flightfeather/uav/lightshare/service/impl/SatelliteDataCalculateServiceImpl.kt +++ b/src/main/kotlin/com/flightfeather/uav/lightshare/service/impl/SatelliteDataCalculateServiceImpl.kt @@ -1,14 +1,14 @@ package com.flightfeather.uav.lightshare.service.impl +import com.flightfeather.uav.biz.satellite.GridGroupOption import com.flightfeather.uav.biz.satellite.SatelliteGridManage import com.flightfeather.uav.common.exception.BizException -import com.flightfeather.uav.domain.entity.GridCell -import com.flightfeather.uav.domain.entity.GridData -import com.flightfeather.uav.domain.entity.GridDataDetail -import com.flightfeather.uav.domain.entity.GridGroup +import com.flightfeather.uav.common.utils.TimeUtil +import com.flightfeather.uav.domain.entity.* import com.flightfeather.uav.domain.repository.MissionRep import com.flightfeather.uav.domain.repository.RealTimeDataRep import com.flightfeather.uav.domain.repository.SatelliteGridRep +import com.flightfeather.uav.lightshare.bean.GridDataDetailMixVo import com.flightfeather.uav.lightshare.eunm.GridType import com.flightfeather.uav.lightshare.eunm.SatelliteDataType import com.flightfeather.uav.lightshare.service.SatelliteDataCalculateService @@ -108,14 +108,15 @@ } @Transactional - override fun splitData(groupId: Int, dataId:Int): List<GridDataDetail?> { + override fun splitData(groupId: Int, dataId: Int): List<GridDataDetail?> { // 妫�鏌ユ槸鍚︽槸缁嗗垎缃戞牸绫诲瀷 - val gridGroup = satelliteGridRep.fetchGridGroup(groupId) ?: throw BizException("璇ョ綉鏍肩粍涓嶅瓨鍦紝鏃犳硶杩涜缁嗗垎缃戞牸鏁版嵁鏄犲皠") + val gridGroup = + satelliteGridRep.fetchGridGroup(groupId) ?: throw BizException("璇ョ綉鏍肩粍涓嶅瓨鍦紝鏃犳硶杩涜缁嗗垎缃戞牸鏁版嵁鏄犲皠") if (gridGroup.type != GridType.Sub.name.lowercase()) throw BizException("璇ョ綉鏍肩粍涓嶆槸缁嗗垎缃戞牸绫诲瀷瀛樺湪锛屾棤娉曡繘琛岀粏鍒嗙綉鏍兼暟鎹槧灏�") val subGridCellList = satelliteGridRep.fetchGridCell(groupId) val originGridData = satelliteGridRep.fetchGridData(dataId) - val originGridDataDetailList = satelliteGridRep.fetchGridDataDetail(dataId, null, null) + val originGridDataDetailList = satelliteGridRep.fetchGridDataDetail(dataId) val subGridData = GridData().apply { this.groupId = groupId @@ -138,9 +139,11 @@ val mission = missionRep.findOne(missionCode) ?: throw BizException("浠诲姟涓嶅瓨鍦�") val data = realTimeDataRep.fetchData(mission) + // 鏌ユ壘鏄惁宸叉湁璧拌埅铻嶅悎璁板綍 val oldGridDataList = satelliteGridRep.fetchGridData(GridData().apply { this.groupId = groupId mixDataId = missionCode + this.type = SatelliteDataType.Monitor.value.toByte() }) if (oldGridDataList.isEmpty()) { @@ -149,7 +152,23 @@ this.groupId = groupId dataTime = mission.startTime type = SatelliteDataType.Monitor.value.toByte() - mixDataId = mission.missionCode + this.missionCode = mission.missionCode + // Fixme 2025.3.27: 琛屾斂鍖哄垝鍦ㄨ蛋鑸换鍔℃坊鍔犲搴斿瓧娈靛悗杩涜璧嬪�� + provinceCode + provinceName + cityCode + cityName + districtCode + districtName = mission.districtName + // Fixme 2025.3.27: 鎵�灞炵洃娴嬬偣鍖哄煙鐩墠闇�瑕侀�氳繃鐢ㄦ埛閫夋嫨纭畾 + zone + pollutionDegreeIndex + pollutionDegree + + val period = TimeUtil.getDayTimeTag(mission.startTime, mission.endTime) + dayTimePeriod = period?.first + dayTimePeriodStart = period?.second + dayTimePeriodEnd = period?.third } satelliteGridRep.insertGridData(newGridData) @@ -163,8 +182,7 @@ return gridDataDetailList } else { val oldGridData = oldGridDataList.first() - val oldGridDataDetailList = satelliteGridRep.fetchGridDataDetail(oldGridData?.id, oldGridData?.groupId, - null) + val oldGridDataDetailList = satelliteGridRep.fetchGridDataDetail(oldGridData?.id, oldGridData?.groupId) // 鏌ヨ缃戞牸鍗曞厓鏍间俊鎭� val gridCellList = satelliteGridRep.fetchGridCell(groupId) // 灏嗚蛋鑸暟鎹拰鍗槦缃戞牸杩涜铻嶅悎璁$畻 @@ -181,8 +199,85 @@ } } - override fun buildHeatmap(groupId: Int, gridDataDetail: List<GridDataDetail>): List<GridDataDetail> { + override fun mixGridData(groupId: Int, dataIdList: List<Int>): List<GridDataDetailMixVo> { + // 鑾峰彇鎵�浣跨敤鐨勭綉鏍肩粍缃戞牸淇℃伅 val gridCellList = satelliteGridRep.fetchGridCell(groupId) + val gridDataDetailMap = mutableMapOf<Int?, MutableList<GridDataDetail>>() + + // 褰掗泦鎵�鏈夌浉鍚屽崟鍏冪綉鏍肩殑鏁版嵁 + dataIdList.forEach { id -> + satelliteGridRep.fetchGridDataDetail(id, groupId).forEach gdd@{ gdd -> + if (gdd == null) return@gdd + if (!gridDataDetailMap.containsKey(gdd.cellId)) { + gridDataDetailMap[gdd.cellId] = mutableListOf() + } + gridDataDetailMap[gdd.cellId]?.add(gdd) + } + } + + // 灏嗘墍鏈夌粨鏋滄牸寮忓寲锛屽悓鏃堕噸鍙犵綉鏍艰繘琛岀洃娴嬫暟鎹潎鍊艰绠� + val result = mutableListOf<GridDataDetailMixVo>() + gridDataDetailMap.forEach { (_, v) -> + val target = GridDataDetailMixVo() + if (v.size == 1) { + BeanUtils.copyProperties(v[0], target) + } else { + BeanUtils.copyProperties(v.avg(), target) + target.mixData = true + target.originDataList = v + } + target.apply { + this.dataId = v.first().dataId + this.groupId = v.first().groupId + this.cellId = v.first().cellId + } + result.add(target) + } + result.sortBy { it.pm25 } + result.forEachIndexed { index, d -> + d.rank = index + 1 + } + result.sortBy { it.cellId } + + return result + } + + override fun buildHeatmap( + groupId: Int, + gridDataDetailList: List<GridDataDetail>, + searchLength: Int, + ): List<GridDataDetail> { + val gridCellList = satelliteGridRep.fetchGridCell(groupId) + val originCellIdList = gridDataDetailList.map { it.cellId } + // Fixme 2025.3.24: 姝ゅ鏍规嵁鐜版湁鐨勭綉鏍间俊鎭璁℃柟寮忥紝浣跨敤涓存椂鐨勫弬鏁帮紝鍚庣画灏嗙綉鏍奸�氳繃浜岀淮鍧愭爣褰㈠紡琛ㄧず锛屾澶勫弬鏁板幓闄� + val option = GridGroupOption(120, 90, 10, 10) + + val resMap = mutableMapOf<Int, MutableList<GridDataDetail>>() + + // 寰幆璁$畻姣忎釜缃戞牸鐨勫懆杈规墿鏁g綉鏍肩粨鏋� + gridDataDetailList.forEach { gdd -> + SatelliteGridManage.heatMap(gdd, gridCellList, option, searchLength).forEach { r -> + if (!originCellIdList.contains(r.cellId)) { + if (!resMap.containsKey(r.cellId)) { + resMap[r.cellId] = mutableListOf() + } + resMap[r.cellId]?.add(r) + } + } + } + + // 灏嗘墍鏈夌粨鏋滄牸寮忓寲锛屽悓鏃堕噸鍙犵綉鏍艰繘琛岀洃娴嬫暟鎹潎鍊艰绠� + val result = mutableListOf<GridDataDetail>() + resMap.forEach { (_, v) -> + result.add(v.avg().apply { + this.dataId = v.first().dataId + this.groupId = v.first().groupId + this.cellId = v.first().cellId + }) + } + result.addAll(gridDataDetailList) + + return result } } \ No newline at end of file -- Gitblit v1.9.3