| | |
| | | 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.domain.repository.SatelliteGridRep |
| | | import com.flightfeather.uav.lightshare.eunm.GridType |
| | | import com.flightfeather.uav.lightshare.eunm.SatelliteDataType |
| | | import com.flightfeather.uav.lightshare.service.SatelliteDataCalculateService |
| | | import org.springframework.beans.BeanUtils |
| | | import org.springframework.stereotype.Service |
| | | import org.springframework.transaction.annotation.Transactional |
| | | import java.util.Date |
| | | import kotlin.math.round |
| | | |
| | | /** |
| | | * |
| | | * 卫星网格坐标及监测数据二次计算 |
| | | * @date 2025/1/15 |
| | | * @author feiyu02 |
| | | */ |
| | |
| | | return cellList |
| | | } |
| | | |
| | | override fun splitGrid(groupId: Int): List<GridCell?> { |
| | | TODO("Not yet implemented") |
| | | override fun splitGrid(groupId: Int, scale: Int): List<GridCell?> { |
| | | // 检查该网格属性是否合规 |
| | | val gridGroup = |
| | | satelliteGridRep.fetchGridGroup(groupId) ?: throw BizException("该网格组不存在,无法进行网格细分") |
| | | if (gridGroup.length == null) throw BizException("该网格组没有设定网格边长,无法进行网格细分") |
| | | |
| | | // 检查该网格下该种类的细分网格是否存在,若不存在,则新建 |
| | | val searchGridGroup = GridGroup().apply { |
| | | type = GridType.Sub.name.lowercase() |
| | | fatherGroupId = gridGroup.id |
| | | length = round(gridGroup.length / scale) |
| | | } |
| | | val subGridGroupList = satelliteGridRep.fetchGridGroup(searchGridGroup) |
| | | // 若细分网格记录超过1个,说明业务逻辑存在问题,相同边长的细分网格应该只有1个 |
| | | if (subGridGroupList.size > 1) { |
| | | throw BizException("该网格组下${searchGridGroup.length}米边长的网格记录超过1个,无法再进行网格细分,并且请检查生成逻辑是否问题") |
| | | } |
| | | // 若细分网格记录有且只有1个,则无需再次细分,直接返回已有结果 |
| | | else if (subGridGroupList.size == 1) { |
| | | val g = subGridGroupList.first() |
| | | ?: throw BizException("该网格组下的细分网格记录已损坏,无法使用,请检查数据库记录") |
| | | return satelliteGridRep.fetchGridCell(g.id) |
| | | } |
| | | // 当没有记录时,执行生成逻辑 |
| | | |
| | | // 生成新的细分网格组记录 |
| | | val newGridGroup = GridGroup() |
| | | BeanUtils.copyProperties(gridGroup, newGridGroup) |
| | | newGridGroup.apply { |
| | | id = null |
| | | name += "${searchGridGroup.length.toInt()}米细分" |
| | | createTime = Date() |
| | | length = searchGridGroup.length |
| | | type = GridType.Sub.name.lowercase() |
| | | fatherGroupId = groupId |
| | | } |
| | | satelliteGridRep.insertGridGroup(newGridGroup) |
| | | |
| | | // 获取具体网格信息 |
| | | val cellList = satelliteGridRep.fetchGridCell(groupId) |
| | | // 按照给定的拆分系数进行拆分 |
| | | val subCellList = SatelliteGridManage.splitGrid(cellList, scale, newGridGroup.id) |
| | | satelliteGridRep.insertGridCell(subCellList) |
| | | |
| | | return subCellList |
| | | } |
| | | |
| | | @Transactional |
| | | override fun splitData(groupId: Int, dataId:Int): List<GridDataDetail?> { |
| | | // 检查是否是细分网格类型 |
| | | 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 subGridData = GridData().apply { |
| | | this.groupId = groupId |
| | | dataTime = originGridData?.dataTime |
| | | type = SatelliteDataType.Sub.value.toByte() |
| | | } |
| | | satelliteGridRep.insertGridData(subGridData) |
| | | |
| | | val subGridDataDetailList = |
| | | SatelliteGridManage.splitData(subGridCellList, subGridData, originGridDataDetailList) |
| | | |
| | | satelliteGridRep.insertGridDataDetail(subGridDataDetailList) |
| | | |
| | | return subGridDataDetailList |
| | | } |
| | | } |