| | |
| | | package com.ard.route.service.impl; |
| | | |
| | | import java.io.IOException; |
| | | import java.util.List; |
| | | |
| | | import com.ard.common.exception.ControlException; |
| | | import com.ard.common.utils.DateUtils; |
| | | import com.ard.common.utils.file.FileUtils; |
| | | import com.ard.common.utils.uuid.IdUtils; |
| | | import com.ard.data.noflyzone.domain.ArdNoFlyZone; |
| | | import com.ard.data.noflyzone.domain.Vertex; |
| | | import com.ard.data.noflyzone.service.IArdNoFlyZoneService; |
| | | import com.ard.data.noflyzone.utils.NoFlyZoneUtils; |
| | | import com.ard.oss.model.MinioUploadResult; |
| | | import com.ard.oss.service.impl.OssServiceContext; |
| | | import com.ard.route.domain.UavRouteReq; |
| | | import com.ard.route.domain.route.ArdRouteInformation; |
| | | import com.ard.route.domain.vo.KmzResultVo; |
| | | import com.ard.route.service.UavRouteService; |
| | |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | import static com.ard.route.util.ToolUtils.extractFilePath; |
| | | import static com.ard.route.util.ToolUtils.getFileNameWithoutExtension; |
| | | import static com.ard.route.util.ToolUtils.*; |
| | | |
| | | /** |
| | | * 航线(kmz)Service业务层处理 |
| | |
| | | @Autowired |
| | | private UavRouteService routeService; |
| | | |
| | | @Resource |
| | | private IArdNoFlyZoneService ardNoFlyZoneService; |
| | | |
| | | /** |
| | | * 查询航线(kmz) |
| | | * |
| | |
| | | */ |
| | | @Override |
| | | public ArdRouteInformation selectArdRouteInformationById(String id) { |
| | | return ardRouteInformationMapper.selectArdRouteInformationById(id); |
| | | ArdRouteInformation ardRouteInformation = ardRouteInformationMapper.selectArdRouteInformationById(id); |
| | | try { |
| | | ardRouteInformation.setUavRouteReq((UavRouteReq) deserialize(ardRouteInformation.getRouteData())); |
| | | } catch (IOException | ClassNotFoundException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | return ardRouteInformation; |
| | | } |
| | | |
| | | /** |
| | |
| | | if (ardRouteInformation.getFolderId() == null){ |
| | | ardRouteInformation.setFolderId("0"); |
| | | } |
| | | // 航线数据 |
| | | byte[] routeData; |
| | | try { |
| | | routeData = serialize(ardRouteInformation.getUavRouteReq()); |
| | | } catch (IOException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | ardRouteInformation.setRouteData(routeData); |
| | | KmzResultVo kmzResult = routeService.buildKmz(ardRouteInformation.getUavRouteReq(), ardRouteInformation.getFileName()); |
| | | // 将KmzResult中的信息设置到ardRouteInformation中 |
| | | ardRouteInformation.setFileNameNew(kmzResult.getFileNameNew()); |
| | | ardRouteInformation.setMinioUpPath(kmzResult.getMinioUpPath()); |
| | | ardRouteInformation.setUpPath(kmzResult.getUpPath()); |
| | | ardRouteInformation.setUpFileSize(kmzResult.getUpFileSize()); |
| | | ardRouteInformationMapper.insertArdRouteInformation(ardRouteInformation); |
| | | ardRouteInformationMapper.insertArdRouteInformation(assembly(ardRouteInformation,kmzResult)); |
| | | return kmzResult.getUpPath(); |
| | | } |
| | | |
| | |
| | | @Override |
| | | public int updateArdRouteInformation(ArdRouteInformation ardRouteInformation) { |
| | | ardRouteInformation.setUpdateTime(DateUtils.getNowDate()); |
| | | return ardRouteInformationMapper.updateArdRouteInformation(ardRouteInformation); |
| | | KmzResultVo kmzResult = new KmzResultVo(); |
| | | // 获取源文件名字 |
| | | ArdRouteInformation route = ardRouteInformationMapper.selectArdRouteInformationById(ardRouteInformation.getId()); |
| | | if (route.getFileName().equals(ardRouteInformation.getFileName())) { |
| | | kmzResult = routeService.updateKmz(ardRouteInformation.getUavRouteReq(), ardRouteInformation.getFileName()); |
| | | }else { |
| | | kmzResult = routeService.updateKmzNew(ardRouteInformation.getUavRouteReq(), route.getFileName(),ardRouteInformation.getFileName()); |
| | | } |
| | | if ("更新航线kmz文件失败".equals(kmzResult.getData())) { |
| | | return 0; |
| | | } |
| | | return ardRouteInformationMapper.updateArdRouteInformation(assembly(ardRouteInformation,kmzResult)); |
| | | } |
| | | |
| | | //组装数据 |
| | | private ArdRouteInformation assembly(ArdRouteInformation information,KmzResultVo kmzResult){ |
| | | information.setFileNameNew(kmzResult.getFileNameNew()); |
| | | information.setMinioUpPath(kmzResult.getMinioUpPath()); |
| | | information.setUpPath(kmzResult.getUpPath()); |
| | | information.setUpFileSize(kmzResult.getUpFileSize()); |
| | | return information; |
| | | } |
| | | |
| | | /** |
| | |
| | | } |
| | | |
| | | /** |
| | | * 修改航线分组ID |
| | | * |
| | | * @param id ID |
| | | * @param folderId 分组ID |
| | | * @return 结果 |
| | | */ |
| | | @Override |
| | | public int updateRouteInformationFolderId(String id, String folderId) { |
| | | return ardRouteInformationMapper.updateRouteInformationFolderId(id, folderId); |
| | | } |
| | | |
| | | /** |
| | | * 判断行点是否在禁飞区 |
| | | * |
| | | * @param longitude 经度 |
| | | * @param latitude 纬度 |
| | | * @return 结果 |
| | | */ |
| | | @Override |
| | | public Boolean selectRouteInformationNoFly(Double longitude, Double latitude) { |
| | | if (longitude == null || latitude == null) { |
| | | throw new ControlException("方法参数中未找到有效经纬度字段,无法判断禁飞区!"); |
| | | } |
| | | List<ArdNoFlyZone> ardNoFlyZones = ardNoFlyZoneService.selectArdNoFlyZoneList(new ArdNoFlyZone()); |
| | | if (!ardNoFlyZones.isEmpty()) { |
| | | Vertex vertex = new Vertex(longitude, latitude); |
| | | boolean inNoFlyZones = NoFlyZoneUtils.isInNoFlyZones(vertex, ardNoFlyZones); |
| | | if (inNoFlyZones) { |
| | | throw new ControlException("目标点在禁飞区内,无法执行操作!"); |
| | | } |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | /** |
| | | * 数据新增航线信息 |
| | | */ |
| | | private void insertRouteInformation(ArdRouteInformation ardRouteInformation){ |