| | |
| | | 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 org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import com.ard.route.mapper.ArdRouteInformationMapper; |
| | | import com.ard.route.service.IArdRouteInformationService; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import static com.ard.route.util.ToolUtils.getFileNameWithoutExtension; |
| | | import javax.annotation.Resource; |
| | | |
| | | import static com.ard.route.util.ToolUtils.*; |
| | | |
| | | /** |
| | | * 航线(kmz)Service业务层处理 |
| | |
| | | @Autowired |
| | | private OssServiceContext ossService; |
| | | |
| | | @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; |
| | | } |
| | | |
| | | /** |
| | |
| | | * @return 结果 |
| | | */ |
| | | @Override |
| | | public int insertArdRouteInformation(ArdRouteInformation ardRouteInformation) { |
| | | public String insertArdRouteInformation(ArdRouteInformation ardRouteInformation) { |
| | | ardRouteInformation.setId(IdUtils.simpleUUID()); |
| | | ardRouteInformation.setCreateTime(DateUtils.getNowDate()); |
| | | return ardRouteInformationMapper.insertArdRouteInformation(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()); |
| | | 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; |
| | | } |
| | | |
| | | /** |
| | |
| | | // 删除航线(kmz)文件 |
| | | for (String id : ids) { |
| | | ArdRouteInformation information = ardRouteInformationMapper.selectArdRouteInformationById(id); |
| | | ossService.deleteObject("kmz", information.getUpPath()); |
| | | ossService.deleteObject("kmz", information.getMinioUpPath()); |
| | | } |
| | | return ardRouteInformationMapper.deleteArdRouteInformationByIds(ids); |
| | | } |
| | |
| | | ArdRouteInformation information = new ArdRouteInformation(); |
| | | information.setFileName(file.getOriginalFilename()); |
| | | information.setFileNameNew(getFileNameWithoutExtension(url)); |
| | | information.setMinioUpPath(extractFilePath(url)); |
| | | information.setUpPath(url); |
| | | information.setUpFileSize((double) file.getSize()); |
| | | insertArdRouteInformation(information); |
| | | insertRouteInformation(information); |
| | | return MinioUploadResult.builder() |
| | | .url(url) |
| | | .newFileName(FileUtils.getName(url)) |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 根据文件名称查询航线信息 |
| | | * |
| | | * @param name 文件名称 |
| | | * @return 结果 |
| | | */ |
| | | @Override |
| | | public ArdRouteInformation selectArdRouteInformationByName(String name) { |
| | | return ardRouteInformationMapper.selectArdRouteInformationByName(name); |
| | | } |
| | | |
| | | /** |
| | | * 修改航线分组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){ |
| | | ardRouteInformation.setId(IdUtils.simpleUUID()); |
| | | ardRouteInformation.setCreateTime(DateUtils.getNowDate()); |
| | | ardRouteInformationMapper.insertArdRouteInformation(ardRouteInformation); |
| | | } |
| | | |
| | | } |