| | |
| | | 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 |
| | |
| | | return cellList |
| | | } |
| | | |
| | | @Transactional |
| | | override fun splitGrid(groupId: Int, scale: Int): List<GridCell?> { |
| | | // 检查该网格属性是否合规 |
| | | val gridGroup = |
| | |
| | | } |
| | | |
| | | @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 |
| | |
| | | } |
| | | |
| | | @Transactional |
| | | override fun dataFusion(missionCode: String, groupId: Int): List<GridDataDetail?> { |
| | | override fun dataFusion(gridData: GridData): List<GridDataDetail?> { |
| | | val missionCode = gridData.missionCode ?: throw BizException("缺少任务编号") |
| | | val groupId = gridData.groupId ?: throw BizException("缺少网格组id") |
| | | |
| | | // 查询走航任务及对应走航监测数据 |
| | | val mission = missionRep.findOne(missionCode) ?: throw BizException("任务不存在") |
| | | val data = realTimeDataRep.fetchData(mission) |
| | | |
| | | // 查找是否已有走航融合记录 |
| | | val oldGridDataList = satelliteGridRep.fetchGridData(GridData().apply { |
| | | this.groupId = groupId |
| | | mixDataId = missionCode |
| | | this.missionCode = missionCode |
| | | this.type = SatelliteDataType.Monitor.value.toByte() |
| | | }) |
| | | |
| | | if (oldGridDataList.isEmpty()) { |
| | | // 创建融合数据索引对象 |
| | | val newGridData = GridData().apply { |
| | | val newGridData = gridData.apply { |
| | | this.groupId = groupId |
| | | dataTime = mission.startTime |
| | | type = SatelliteDataType.Monitor.value.toByte() |
| | | mixDataId = mission.missionCode |
| | | this.missionCode = mission.missionCode |
| | | provinceCode = mission.provinceCode |
| | | provinceName = mission.provinceName |
| | | cityCode = mission.cityCode |
| | | cityName = mission.cityName |
| | | districtCode = mission.districtCode |
| | | districtName = mission.districtName |
| | | // 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) |
| | | |
| | |
| | | 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) |
| | | // 将走航数据和卫星网格进行融合计算 |
| | |
| | | return gridDataDetailList |
| | | } |
| | | } |
| | | |
| | | override fun mixUnderwayGridData(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 gridGroup =satelliteGridRep.fetchGridGroup(groupId) |
| | | val gridCellList = satelliteGridRep.fetchGridCell(groupId) |
| | | val originCellIdList = gridDataDetailList.map { it.cellId } |
| | | // Fixme 2025.3.24: 此处根据现有的网格信息设计方式,使用临时的参数,后续将网格通过二维坐标形式表示,此处参数去除 |
| | | val option = GridGroupOption(gridGroup?.maxXaxis ?: 120, gridGroup?.maxYaxis ?: 90, 10, 10) |
| | | |
| | | val resMap = mutableMapOf<Int, MutableList<GridDataDetail>>() |
| | | |
| | | // 循环计算每个网格的周边扩散网格结果 |
| | | 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 |
| | | } |
| | | } |