| | |
| | | import com.ard.data.noflyzone.domain.Vertex; |
| | | import com.ard.data.noflyzone.service.IArdNoFlyZoneService; |
| | | import com.ard.data.noflyzone.utils.NoFlyZoneUtils; |
| | | import com.ard.framework.web.service.TokenService; |
| | | import com.ard.oss.model.MinioUploadResult; |
| | | import com.ard.oss.service.impl.OssServiceContext; |
| | | import com.ard.route.domain.djuav.ActionGroupReq; |
| | |
| | | import com.ard.route.domain.djuav.UavRouteReq; |
| | | import com.ard.route.domain.dto.ArdNoflyDto; |
| | | import com.ard.route.domain.route.ArdRouteInfo; |
| | | import com.ard.route.domain.sixhe.ArdRouteChange; |
| | | import com.ard.route.domain.vo.KmzResultVo; |
| | | import com.ard.route.mapper.ArdRouteInfoMapper; |
| | | import com.ard.route.service.IArdRouteInfoService; |
| | | import com.ard.route.service.UavRouteService; |
| | | import com.ard.work.domain.cache.UavWaylineCache; |
| | | import com.ard.work.domain.dto.state.PointData; |
| | | import com.ard.work.domain.dto.wayline.*; |
| | | import com.ard.work.service.ITyService; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | import static com.ard.route.enums.kml.DroneEnumValueEnums.M350_RTK; |
| | | import static com.ard.route.util.InitializationUtils.divided_23; |
| | | import static com.ard.route.util.ToolUtils.*; |
| | | import static com.ard.route.util.UavRouteReqUtils.fileConversionEntity; |
| | | |
| | | /** |
| | | * 航线(kmz)Service业务层处理 |
| | |
| | | @Service |
| | | public class ArdRouteInfoServiceImpl implements IArdRouteInfoService { |
| | | |
| | | private static final Logger log = LoggerFactory.getLogger(TokenService.class); |
| | | |
| | | @Autowired |
| | | private ArdRouteInfoMapper ardRouteInfoMapper; |
| | | |
| | | @Autowired |
| | | private OssServiceContext ossService; |
| | | |
| | | |
| | | @Autowired |
| | | private UavRouteService routeService; |
| | |
| | | } catch (IOException | ClassNotFoundException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | |
| | | // 主逻辑优化 |
| | | double altitudeOffset = getDoublePoint(ardRouteInfo.getUavRouteReq().getTakeOffRefPoint(), "alt"); |
| | | boolean isM350RTK = M350_RTK.getValue().equals(ardRouteInfo.getUavRouteReq().getDroneType()); |
| | | |
| | | for (RoutePointReq routePointReq : ardRouteInfo.getUavRouteReq().getRoutePointList()) { |
| | | // 调整航点高度 |
| | | adjustRoutePointHeight(routePointReq, altitudeOffset); |
| | | // 如果是M350_RTK无人机,处理变焦动作 |
| | | // if (isM350RTK && routePointReq.getActionGroupList() != null) { |
| | | // for (ActionGroupReq actionGroupReq : routePointReq.getActionGroupList()) { |
| | | // if (actionGroupReq != null && actionGroupReq.getActions() != null) { |
| | | // processZoomActions(actionGroupReq); |
| | | // } |
| | | // } |
| | | // } |
| | | } |
| | | return ardRouteInfo; |
| | | } |
| | | |
| | | // 提取航点高度调整逻辑到方法中 |
| | | private void adjustRoutePointHeight(RoutePointReq routePointReq, double altitudeOffset) { |
| | | routePointReq.setHeight(routePointReq.getHeight() + altitudeOffset); |
| | | } |
| | | |
| | | // 提取变焦值处理逻辑到方法中 |
| | | private void processZoomActions(ActionGroupReq actionGroupReq) { |
| | | for (PointActionReq action : actionGroupReq.getActions()) { |
| | | if (action != null && action.getZoom() != null) { |
| | | action.setZoom(divided_23(action.getZoom())); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | |
| | | if (ardRouteInfo.getGroupId() == null){ |
| | | ardRouteInfo.setGroupId("0"); |
| | | } |
| | | // 航线数据 |
| | | byte[] routeData; |
| | | try { |
| | | routeData = serialize(ardRouteInfo.getUavRouteReq()); |
| | | } catch (IOException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | UavRouteReq uavRouteReq = new UavRouteReq(); |
| | | BeanUtils.copyProperties(ardRouteInfo.getUavRouteReq(), uavRouteReq); |
| | | ardRouteInfo.getUavRouteReq().setDroneType(subStringDroneType(ardRouteInfo.getAircraft())); |
| | | ardRouteInfo.setRouteData(routeData); |
| | | KmzResultVo kmzResult = routeService.buildKmz(ardRouteInfo.getUavRouteReq(), ardRouteInfo.getName()); |
| | | KmzResultVo kmzResult = routeService.buildKmz(uavRouteReq,ardRouteInfo.getName()); |
| | | if (M350_RTK.getValue().equals(uavRouteReq.getDroneType())) { |
| | | // 变焦数值加工 |
| | | for (RoutePointReq routePointReq : ardRouteInfo.getUavRouteReq().getRoutePointList()) { |
| | | for (ActionGroupReq actionGroupReq : routePointReq.getActionGroupList()) { |
| | | for (PointActionReq action : actionGroupReq.getActions()) { |
| | | action.setZoom(divided_23(action.getZoom())); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | ardRouteInfo.setPath(kmzResult.getPath()); |
| | | ardRouteInfo.setReadOnly("0"); |
| | | ardRouteInfoMapper.insertArdRouteInfo(ardRouteInfo); |
| | | ardRouteInfoMapper.insertArdRouteInfo(dataProcessing(ardRouteInfo)); |
| | | return kmzResult.getPath(); |
| | | } |
| | | |
| | |
| | | KmzResultVo kmzResult; |
| | | // 获取源文件名字 |
| | | ArdRouteInfo route = ardRouteInfoMapper.selectArdRouteInfoById(ardRouteInfo.getId()); |
| | | if (route.getName().equals(ardRouteInfo.getName())) { |
| | | kmzResult = routeService.updateKmz(ardRouteInfo.getUavRouteReq(), ardRouteInfo.getName()); |
| | | }else { |
| | | kmzResult = routeService.updateKmzNew(ardRouteInfo.getUavRouteReq(), route.getName(), ardRouteInfo.getName()); |
| | | } |
| | | // 先删除航线 |
| | | delOssService(route); |
| | | // 再生成航线 |
| | | kmzResult = routeService.buildKmz(ardRouteInfo.getUavRouteReq(), ardRouteInfo.getName()); |
| | | if ("更新航线kmz文件失败".equals(kmzResult.getData())) { |
| | | return 0; |
| | | } |
| | | ardRouteInfo.setPath(kmzResult.getPath()); |
| | | } |
| | | return ardRouteInfoMapper.updateArdRouteInfo(ardRouteInfo); |
| | | return ardRouteInfoMapper.updateArdRouteInfo(dataProcessing(ardRouteInfo)); |
| | | } |
| | | |
| | | // 新增信息加工 |
| | | private ArdRouteInfo dataProcessing(ArdRouteInfo ardRouteInfo) { |
| | | // 航线数据 |
| | | byte[] routeData = null; |
| | | try { |
| | | if (ardRouteInfo.getUavRouteReq() != null){ |
| | | routeData = serialize(ardRouteInfo.getUavRouteReq()); |
| | | } |
| | | } catch (IOException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | ardRouteInfo.setRouteData(routeData); |
| | | ardRouteInfo.setPointCount(getPointCount(ardRouteInfo)); |
| | | return ardRouteInfo; |
| | | } |
| | | |
| | | // 获取行点总数 |
| | | private Integer getPointCount(ArdRouteInfo ardRouteInfo) { |
| | | if (ardRouteInfo.getUavRouteReq() != null){ |
| | | if (ardRouteInfo.getUavRouteReq().getRoutePointList() != null) { |
| | | return ardRouteInfo.getUavRouteReq().getRoutePointList().size(); |
| | | } |
| | | } |
| | | return 0; |
| | | } |
| | | |
| | | /** |
| | |
| | | // 删除航线(kmz)文件 |
| | | for (String id : ids) { |
| | | ArdRouteInfo information = ardRouteInfoMapper.selectArdRouteInfoById(id); |
| | | ossService.deleteObject("kmz", subStringMinioUrlName(information.getPath())); |
| | | delOssService(information); |
| | | } |
| | | return ardRouteInfoMapper.deleteArdRouteInfoByIds(ids); |
| | | } |
| | | |
| | | // 删除minio文件 |
| | | private void delOssService(ArdRouteInfo information){ |
| | | if (information.getPath() != null){ |
| | | ossService.deleteObject("kmz", subStringMinioUrlName(information.getPath())); |
| | | } |
| | | } |
| | | |
| | | /** |
| | |
| | | @Override |
| | | public MinioUploadResult uploadArdRouteInfo(MultipartFile file) { |
| | | try { |
| | | // 增加航线实体类信息 |
| | | UavRouteReq uavRouteReq = fileConversionEntity(file); |
| | | ArdRouteInfo ardRouteInfo = new ArdRouteInfo(); |
| | | if (uavRouteReq != null){ |
| | | ardRouteInfo.setUavRouteReq(uavRouteReq); |
| | | ardRouteInfo.setType(templateTypeData(uavRouteReq)); |
| | | ardRouteInfo.setAircraft(droneTypeData(uavRouteReq)); |
| | | } |
| | | |
| | | // 判断禁飞区 |
| | | try { |
| | | arrayWithinNoFlyZone(ardRouteInfo.getUavRouteReq().getRoutePointList()); |
| | | } catch (ControlException e) { |
| | | // 返回包含禁飞区错误信息的特定结果 |
| | | return MinioUploadResult.builder() |
| | | .originalFilename("禁飞区错误.航线航点在禁飞区!") |
| | | .build(); |
| | | } |
| | | |
| | | String url = ossService.upload("kmz",file); |
| | | ArdRouteInfo information = new ArdRouteInfo(); |
| | | information.setName(file.getOriginalFilename()); |
| | | information.setPath(url); |
| | | information.setGroupId("0"); // 默认分组 |
| | | information.setReadOnly("1"); // 默认只读 |
| | | insertRouteInfomation(information); |
| | | ardRouteInfo.setName(file.getOriginalFilename()); |
| | | ardRouteInfo.setPath(url); |
| | | ardRouteInfo.setGroupId("0"); // 默认分组 |
| | | ardRouteInfo.setReadOnly("1"); // 默认只读 |
| | | insertRouteInfomation(ardRouteInfo); |
| | | return MinioUploadResult.builder() |
| | | .url(url) |
| | | .newFileName(FileUtils.getName(url)) |
| | | .originalFilename(file.getOriginalFilename()) |
| | | .build(); |
| | | }catch (Exception e){ |
| | | log.error("上传航线文件失败", e); |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 根据文件名称查询航线信息 |
| | | * 判断一组数组,是否包含禁飞区 |
| | | */ |
| | | private void arrayWithinNoFlyZone(List<RoutePointReq> routePointList) { |
| | | if (routePointList == null || routePointList.isEmpty()) { |
| | | return; |
| | | } |
| | | // 检查第一个航点 |
| | | ArdNoflyDto firstDto = new ArdNoflyDto(); |
| | | firstDto.setTarget(new Vertex( |
| | | routePointList.get(0).getLongitude(), |
| | | routePointList.get(0).getLatitude())); |
| | | verifyNoFlyZone(firstDto); |
| | | |
| | | // 检查后续航点及与前一个航点的线段 |
| | | for (int i = 1; i < routePointList.size(); i++) { |
| | | ArdNoflyDto dto = new ArdNoflyDto(); |
| | | dto.setCurrent(new Vertex( |
| | | routePointList.get(i - 1).getLongitude(), |
| | | routePointList.get(i - 1).getLatitude())); |
| | | dto.setTarget(new Vertex( |
| | | routePointList.get(i).getLongitude(), |
| | | routePointList.get(i).getLatitude())); |
| | | verifyNoFlyZone(dto); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 根据名称查询航线信息 |
| | | * |
| | | * @param name 文件名称 |
| | | * @return 结果 |
| | |
| | | throw new RuntimeException(e); |
| | | } |
| | | // 1.2通过minio获取航线信息 |
| | | |
| | | // 2.将航线信息转换成对应实体类 |
| | | WayLineUploadDTO wayLineUploadDTO = buildWayLineUploadDTO(route); |
| | | wayLineUploadDTO.setBoxSn(boxSn); |
| | | // 3.调用接口 |
| | | // 3.缓存航线信息 |
| | | WaylineInfo WaylineInfo = new WaylineInfo(); |
| | | WaylineInfo.setBoxSn(boxSn); |
| | | WaylineInfo.setWaylineId(route.getId()); |
| | | UavWaylineCache.put(WaylineInfo); |
| | | // 4.调用接口 |
| | | tyService.wayLineUpload(wayLineUploadDTO); |
| | | return true; |
| | | } |
| | |
| | | String exitOnRcLostAction = ardRouteInfo.getUavRouteReq().getExitOnRcLostAction(); //0 |
| | | |
| | | PlanLineData planLineData = new PlanLineData(); |
| | | |
| | | |
| | | |
| | | if (finishAction != null){ |
| | | planLineData.setLoseAction(0); |
| | | } |
| | | if (autoFlightSpeed != null){ |
| | | planLineData.setAutoSpeed(8); |
| | | } |
| | | if (globalTransitionalSpeed != null){ |
| | | planLineData.setMaxSpeed(15); |
| | | } |
| | | planLineData.setMaxSpeed(15); |
| | | // if (globalTransitionalSpeed != null){ |
| | | // planLineData.setMaxSpeed(15); |
| | | // } |
| | | if (exitOnRcLostAction != null){ |
| | | planLineData.setFinishedAction(1); |
| | | } |
| | |
| | | if (height != null){ |
| | | pointData.setHeight(height.floatValue()); |
| | | } |
| | | Double longitude = routePointReq.getLatitude(); |
| | | Double longitude = routePointReq.getLongitude(); |
| | | if (longitude != null){ |
| | | pointData.setLng(longitude.floatValue()); |
| | | } |
| | | Double latitude = routePointReq.getLongitude(); |
| | | Double latitude = routePointReq.getLatitude(); |
| | | if (latitude != null){ |
| | | pointData.setLat(latitude.floatValue()); |
| | | } |
| | |
| | | private void insertRouteInfomation(ArdRouteInfo ardRouteInfo){ |
| | | ardRouteInfo.setId(IdUtils.simpleUUID()); |
| | | ardRouteInfo.setCreateTime(DateUtils.getNowDate()); |
| | | ardRouteInfoMapper.insertArdRouteInfo(ardRouteInfo); |
| | | ardRouteInfo.setUpdateTime(DateUtils.getNowDate()); |
| | | ardRouteInfoMapper.insertArdRouteInfo(dataProcessing(ardRouteInfo)); |
| | | } |
| | | |
| | | /** |