| | |
| | | package com.dji.sample.wayline.service.impl; |
| | | |
| | | import com.alibaba.druid.stat.TableStat; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; |
| | |
| | | import com.dji.sample.common.model.Pagination; |
| | | import com.dji.sample.common.model.PaginationData; |
| | | import com.dji.sample.common.model.ResponseResult; |
| | | import com.dji.sample.common.util.MinioUrlUtils; |
| | | import com.dji.sample.common.util.SpringBeanUtils; |
| | | import com.dji.sample.component.mqtt.model.*; |
| | | import com.dji.sample.component.mqtt.service.IMessageSenderService; |
| | | import com.dji.sample.component.redis.RedisConst; |
| | | import com.dji.sample.component.redis.RedisOpsUtils; |
| | | import com.dji.sample.control.model.dto.PointDTO; |
| | | import com.dji.sample.control.model.param.DrcModeParam; |
| | | import com.dji.sample.control.model.param.FlyToPointParam; |
| | | import com.dji.sample.control.model.param.TakeoffToPointParam; |
| | | import com.dji.sample.control.model.enums.CameraModeEnum; |
| | | import com.dji.sample.control.model.enums.DroneAuthorityEnum; |
| | | import com.dji.sample.control.model.enums.PayloadCommandsEnum; |
| | | import com.dji.sample.control.model.param.*; |
| | | import com.dji.sample.control.service.IControlService; |
| | | import com.dji.sample.control.service.IDrcService; |
| | | import com.dji.sample.geo.entity.GeoJson; |
| | | import com.dji.sample.log.dao.IDroneFlightLogMapper; |
| | | import com.dji.sample.log.model.entity.DroneFlightLogEntity; |
| | | import com.dji.sample.manage.model.dto.DeviceDTO; |
| | | import com.dji.sample.manage.model.enums.DeviceModeCodeEnum; |
| | | import com.dji.sample.manage.model.enums.DockModeCodeEnum; |
| | |
| | | import com.dji.sample.media.model.MediaFileCountDTO; |
| | | import com.dji.sample.media.model.MediaMethodEnum; |
| | | import com.dji.sample.media.service.IFileService; |
| | | import com.dji.sample.utils.GeoUtils; |
| | | import com.dji.sample.geo.utils.GeoUtils; |
| | | import com.dji.sample.wayline.dao.IWaylineJobMapper; |
| | | import com.dji.sample.wayline.model.dto.*; |
| | | import com.dji.sample.wayline.model.entity.WaylineJobBreakPointEntity; |
| | | import com.dji.sample.wayline.model.entity.WaylineJobEntity; |
| | | import com.dji.sample.wayline.model.enums.*; |
| | | import com.dji.sample.wayline.model.param.*; |
| | | import com.dji.sample.wayline.service.IWaylineFileService; |
| | | import com.dji.sample.wayline.service.IWaylineJobBreakPointService; |
| | | import com.dji.sample.wayline.service.IWaylineJobService; |
| | | import com.dji.sample.wayline.service.IWaylineRedisService; |
| | | import com.fasterxml.jackson.core.type.TypeReference; |
| | |
| | | import org.springframework.util.CollectionUtils; |
| | | import org.springframework.util.StringUtils; |
| | | |
| | | import java.io.File; |
| | | import java.net.URL; |
| | | import java.sql.SQLException; |
| | | import java.time.*; |
| | |
| | | @Autowired |
| | | private IControlService controlService; |
| | | |
| | | @Autowired |
| | | private IDroneFlightLogMapper flightLogMapper; |
| | | |
| | | @Autowired |
| | | private IWaylineJobBreakPointService waylineJobBreakPointService; |
| | | |
| | | private Optional<WaylineJobDTO> insertWaylineJob(WaylineJobEntity jobEntity) { |
| | | int id = mapper.insert(jobEntity); |
| | | if (id <= 0) { |
| | |
| | | .rthAltitude(param.getRthAltitude()) |
| | | .mediaCount(0) |
| | | .build(); |
| | | |
| | | if (StringUtils.hasText(param.getJobId())){ |
| | | jobEntity.setJobId(param.getJobId()); |
| | | } |
| | | return insertWaylineJob(jobEntity); |
| | | } |
| | | |
| | |
| | | return response; |
| | | } |
| | | |
| | | |
| | | //新增多条数据 |
| | | //开始日期 |
| | | // String parentId = ""; |
| | | // for (int i = 0; i < param.getExecuteStartTimeArr().size(); i++) { |
| | | // List<Long> timeArr = param.getExecuteStartTimeArr().get(i); |
| | | // |
| | | // long beginTimeLong = 0L; |
| | | // long endTimeLong = 0L; |
| | | // LocalDateTime beginTime = null; |
| | | // if (i == 0) { |
| | | // //父,开始-结束为整个区间 |
| | | // //开始日期 |
| | | // LocalDate startDate = LocalDate.ofInstant(Instant.ofEpochSecond(param.getTaskDays().get(0)), ZoneId.systemDefault()); |
| | | // beginTimeLong = LocalDateTime.of(startDate, LocalTime.ofInstant(Instant.ofEpochSecond(param.getExecuteStartTimeArr().get(0).get(0)), ZoneId.systemDefault())) |
| | | // .atZone(ZoneId.systemDefault()).toInstant().toEpochMilli(); |
| | | // |
| | | // //结束日期 |
| | | // LocalDate endDate = LocalDate.ofInstant(Instant.ofEpochSecond(param.getTaskDays().get(1)), ZoneId.systemDefault()); |
| | | // endTimeLong = LocalDateTime.of(endDate, LocalTime.ofInstant(Instant.ofEpochSecond(param.getExecuteStartTimeArr().get(param.getExecuteStartTimeArr().size() - 1).get(0)), ZoneId.systemDefault())) |
| | | // .atZone(ZoneId.systemDefault()).toInstant().toEpochMilli(); |
| | | // } else { |
| | | // //子,开始-结束为当前区间 |
| | | // //开始日期 |
| | | // LocalDate date = LocalDate.ofInstant(Instant.ofEpochSecond(timeArr.get(0)), ZoneId.systemDefault()); |
| | | // //任务执行开始时间 |
| | | // beginTime = LocalDateTime.of(date, LocalTime.ofInstant(Instant.ofEpochSecond(timeArr.get(0)), ZoneId.systemDefault())); |
| | | // //任务结束时间 |
| | | // LocalDateTime endTime = timeArr.size() > 1 && Objects.nonNull(timeArr.get(1)) ? |
| | | // LocalDateTime.of(date, LocalTime.ofInstant(Instant.ofEpochSecond(timeArr.get(1)), ZoneId.systemDefault())) : beginTime; |
| | | // |
| | | // beginTimeLong = beginTime.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli(); |
| | | // endTimeLong = endTime.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli(); |
| | | // } |
| | | // |
| | | // |
| | | // //保存数据 |
| | | // WaylineJobEntity waylineJobEntity = WaylineJobEntity.builder() |
| | | // .parentId(parentId.equals("") ? null : parentId) |
| | | // .jobId(UUID.randomUUID().toString()) |
| | | // .name(param.getName()) |
| | | // .dockSn(param.getDockSn()) |
| | | // .fileId(param.getFileId()) |
| | | // .username(customClaim.getUsername()) |
| | | // .workspaceId(customClaim.getWorkspaceId()) |
| | | // |
| | | // .beginTime(beginTimeLong) |
| | | // .endTime(endTimeLong) |
| | | // .status(WaylineJobStatusEnum.PENDING.getVal()) |
| | | // .taskType(param.getTaskType().getVal()) |
| | | // .waylineType(param.getWaylineType().getVal()) |
| | | // .outOfControlAction(param.getOutOfControlAction()) |
| | | // .batteryCapacity(param.getMinBatteryCapacity()) |
| | | // .rthAltitude(param.getRthAltitude()) |
| | | // .mediaCount(0) |
| | | // .repFreVal(param.getRepFreVal()) |
| | | // .repFreType(param.getRepFreType()) |
| | | // .repRuleType(param.getRepRuleType()) |
| | | // .repRuleVal(param.getRepRuleVal()) |
| | | // .executeTimeArr(param.getTaskPeriods()) |
| | | // .executeStartTimeArr(param.getExecuteStartTimeArr()) |
| | | // .build(); |
| | | // |
| | | // Optional<WaylineJobDTO> waylineJobOpt = insertWaylineJob(waylineJobEntity); |
| | | // |
| | | // if (waylineJobOpt.isEmpty()) { |
| | | // throw new SQLException("任务创建失败"); |
| | | // } |
| | | // |
| | | // |
| | | // if (i == 0) { |
| | | // //把第一个当作父 |
| | | // parentId = waylineJobEntity.getId().toString(); |
| | | // } |
| | | // WaylineJobDTO waylineJob = waylineJobOpt.get(); |
| | | // |
| | | // //条件任务 |
| | | // if (param.getTaskType() == WaylineTaskTypeEnum.CONDITION) { |
| | | // //如果是条件任务类型,需要在任务参数中添加条件。 |
| | | // waylineJob.setConditions( |
| | | // WaylineTaskConditionDTO.builder() |
| | | // .executableConditions(Objects.nonNull(param.getMinStorageCapacity()) ? WaylineTaskExecutableConditionDTO.builder().storageCapacity(param.getMinStorageCapacity()).build() : null) |
| | | // .readyConditions(WaylineTaskReadyConditionDTO.builder() |
| | | // .batteryCapacity(param.getMinBatteryCapacity()) |
| | | // .beginTime(beginTimeLong) |
| | | // .endTime(endTimeLong) |
| | | // .build()) |
| | | // .build()); |
| | | // } else { |
| | | // waylineJob.setBeginTime(beginTime); |
| | | // } |
| | | // |
| | | // if (waylineJobOpt.isEmpty()) { |
| | | // throw new SQLException("任务创建失败"); |
| | | // } |
| | | // |
| | | // ResponseResult response = this.publishOneFlightTask(waylineJob); |
| | | // if (ResponseResult.CODE_SUCCESS != response.getCode()) { |
| | | // return response; |
| | | // } |
| | | // } |
| | | |
| | | return ResponseResult.success(); |
| | | } |
| | | |
| | |
| | | if (WaylineTaskTypeEnum.IMMEDIATE == waylineJob.getTaskType()) { |
| | | boolean isExecuted = executeFlightTask(waylineJob.getWorkspaceId(), waylineJob.getJobId()); |
| | | if (!isExecuted) { |
| | | return ResponseResult.error("执行任务失败"); |
| | | return ResponseResult.error("当前状态不支持飞行,请检查是否已有正在执行的飞行任务!"); |
| | | } |
| | | } |
| | | |
| | |
| | | |
| | | private Boolean prepareFlightTask(WaylineJobDTO waylineJob) throws SQLException { |
| | | |
| | | boolean isOnline = deviceRedisService.checkDeviceOnline(waylineJob.getDockSn()); |
| | | /*boolean isOnline = deviceRedisService.checkDeviceOnline(waylineJob.getDockSn()); |
| | | if (!isOnline) { |
| | | throw new RuntimeException("设备离线。"); |
| | | } |
| | | }*/ |
| | | |
| | | // get wayline file |
| | | Optional<WaylineFileDTO> waylineFile = waylineFileService.getWaylineByWaylineId(waylineJob.getWorkspaceId(), waylineJob.getFileId()); |
| | |
| | | // get file url |
| | | //获取航线文件地址 |
| | | URL url = waylineFileService.getObjectUrl(waylineJob.getWorkspaceId(), waylineFile.get().getWaylineId()); |
| | | |
| | | WaylineTaskCreateDTO flightTask = WaylineTaskCreateDTO.builder() |
| | | .flightId(waylineJob.getJobId()) |
| | | WaylineTaskCreateDTO.WaylineTaskCreateDTOBuilder flightTaskBuilder = WaylineTaskCreateDTO.builder().flightId(waylineJob.getJobId()) |
| | | .executeTime(waylineJob.getBeginTime().atZone(ZoneId.systemDefault()).toInstant().toEpochMilli()) |
| | | .taskType(waylineJob.getTaskType()) |
| | | .waylineType(waylineJob.getWaylineType()) |
| | | .rthAltitude(waylineJob.getRthAltitude()) |
| | | .outOfControlAction(waylineJob.getOutOfControlAction()) |
| | | .file(WaylineTaskFileDTO.builder() |
| | | .url(url.toString()) |
| | | .url(MinioUrlUtils.getUrl(url)) |
| | | .fingerprint(waylineFile.get().getSign()) |
| | | .build()) |
| | | .build(); |
| | | .build()); |
| | | WaylineJobBreakPointEntity entity = waylineJob.getWaylineJobBreakPointEntity(); |
| | | if (null != entity) { |
| | | flightTaskBuilder.breakPoint(BreakPointJobDTO.builder() |
| | | .index(entity.getBpIndex()) |
| | | .state(entity.getState()) |
| | | .progress(entity.getProgress()) |
| | | .waylineId(entity.getWaylineId()) |
| | | .build()); |
| | | } |
| | | |
| | | WaylineTaskCreateDTO flightTask = flightTaskBuilder.build(); |
| | | |
| | | //当任务类型为条件时 |
| | | if (WaylineTaskTypeEnum.CONDITION == waylineJob.getTaskType()) { |
| | |
| | | .status(WaylineJobStatusEnum.FAILED.getVal()) |
| | | .completedTime(LocalDateTime.now()) |
| | | .code(serviceReply.getResult()).build()); |
| | | // The conditional task fails and enters the blocking status. |
| | | // 条件任务失败,进入阻塞状态。 |
| | | if (WaylineTaskTypeEnum.CONDITION == job.getTaskType() |
| | | && WaylineErrorCodeEnum.find(serviceReply.getResult()).isBlock()) { |
| | | waylineRedisService.setBlockedWaylineJob(job.getDockSn(), jobId); |
| | |
| | | } |
| | | |
| | | @Override |
| | | public Boolean updateJob(WaylineJobDTO dto){ |
| | | public Optional<WaylineJobDTO> getJobByJobId(String workspaceId, String jobId,Boolean isBreakPoint) { |
| | | WaylineJobEntity jobEntity = mapper.selectOne( |
| | | new LambdaQueryWrapper<WaylineJobEntity>() |
| | | .eq(WaylineJobEntity::getWorkspaceId, workspaceId) |
| | | .eq(WaylineJobEntity::getJobId, jobId)); |
| | | WaylineJobDTO waylineJobDTO = entity2Dto(jobEntity); |
| | | if (isBreakPoint) { |
| | | QueryWrapper queryWrapper = new QueryWrapper(); |
| | | queryWrapper.eq("job_id", jobId); |
| | | WaylineJobBreakPointEntity waylineJobBreakPointEntity = waylineJobBreakPointService.getOne(queryWrapper); |
| | | waylineJobDTO.setWaylineJobBreakPointEntity(waylineJobBreakPointEntity); |
| | | } |
| | | |
| | | //设置当前时间为执行时间 |
| | | waylineJobDTO.setBeginTime(LocalDateTime.now()); |
| | | return Optional.ofNullable(waylineJobDTO); |
| | | } |
| | | |
| | | @Override |
| | | public Boolean updateJob(WaylineJobDTO dto) { |
| | | |
| | | try { |
| | | if (dto.getStatus() == 3){ |
| | | if (dto.getStatus() == 3) { |
| | | this.checkNextJob(dto); |
| | | } |
| | | }catch (SQLException e) { |
| | | } catch (SQLException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | |
| | |
| | | |
| | | @Override |
| | | public PaginationData<WaylineJobDTO> getJobsByWorkspaceId(String workspaceId, long page, long pageSize, WaylineJobQueryParam waylineJobQueryParam) { |
| | | // Page<WaylineJobEntity> pageData = mapper.selectPage( |
| | | // new Page<WaylineJobEntity>(page, pageSize), |
| | | // new LambdaQueryWrapper<WaylineJobEntity>() |
| | | // .eq(WaylineJobEntity::getWorkspaceId, workspaceId) |
| | | // .eq(waylineJobDTO.getTaskType() !=null, WaylineJobEntity::getTaskType, waylineJobDTO.getTaskType()) |
| | | // .eq(waylineJobDTO.getStatus()!=null, WaylineJobEntity::getStatus, waylineJobDTO.getStatus()) |
| | | // .like(StringUtils.hasText(waylineJobDTO.getJobName()),WaylineJobEntity::getName,waylineJobDTO.getJobName()) |
| | | // |
| | | // |
| | | // .orderByDesc(WaylineJobEntity::getId)); |
| | | |
| | | Page<WaylineJobEntity> pageData = mapper.getPage(new Page<WaylineJobEntity>(page, pageSize), waylineJobQueryParam, workspaceId); |
| | | |
| | | |
| | | List<WaylineJobDTO> records = pageData.getRecords() |
| | | .stream() |
| | |
| | | .collect(Collectors.toList()); |
| | | |
| | | return new PaginationData<WaylineJobDTO>(records, new Pagination(pageData)); |
| | | } |
| | | |
| | | @Override |
| | | public PaginationData<WaylineJobDTO> getJobsByWorkspaceIdNew(String workspaceId, long page, long pageSize, WaylineJobQueryParam waylineJobQueryParam, String order) { |
| | | Page<WaylineJobEntity> pageData = mapper.getPageNew(new Page<WaylineJobEntity>(page, pageSize), waylineJobQueryParam, workspaceId,order); |
| | | |
| | | List<WaylineJobDTO> records = pageData.getRecords() |
| | | .stream() |
| | | .map(this::entity2Dto) |
| | | .collect(Collectors.toList()); |
| | | |
| | | // 是否需要断点续飞 |
| | | records.forEach(wjd -> wjd.setBreakPoint(waylineJobBreakPointService.count( |
| | | new LambdaQueryWrapper<WaylineJobBreakPointEntity>().eq(WaylineJobBreakPointEntity::getJobId,wjd.getJobId())) > 0)); |
| | | |
| | | |
| | | return new PaginationData<WaylineJobDTO>(records, new Pagination(pageData)); |
| | | } |
| | | |
| | | @Override |
| | | public List<WaylineJobDTO> getChildrenJobs(String workspaceId, WaylineJobQueryParam waylineJobQueryParam) { |
| | | |
| | | List<WaylineJobEntity> list = mapper.getJobs(workspaceId, waylineJobQueryParam); |
| | | List<WaylineJobDTO> records = list |
| | | .stream() |
| | | .map(this::entity2Dto) |
| | | .collect(Collectors.toList()); |
| | | |
| | | return records; |
| | | } |
| | | |
| | | |
| | |
| | | url = waylineFileService.getObjectUrl(waylineJob.getWorkspaceId(), waylineFile.get().getWaylineId()); |
| | | builder.data(RequestsReply.success(WaylineTaskCreateDTO.builder() |
| | | .file(WaylineTaskFileDTO.builder() |
| | | .url(url.toString()) |
| | | .url(MinioUrlUtils.getUrl(url)) |
| | | .fingerprint(waylineFile.get().getSign()) |
| | | .build()) |
| | | .build())); |
| | |
| | | |
| | | @Override |
| | | public WaylineJobEntity getLatestJob(String workspaceId, WaylineJobQueryParam waylineJobQueryParam) { |
| | | // List<WaylineJobEntity> waylineJobEntities = mapper.selectList(new LambdaQueryWrapper<>(WaylineJobEntity.class) |
| | | // .eq(WaylineJobEntity::getWorkspaceId, workspaceId) |
| | | // .eq(WaylineJobEntity::getDockSn, waylineJobQueryParam.getDockSn()) |
| | | // //获取状态为待执行 |
| | | // .eq(WaylineJobEntity::getStatus,1) |
| | | // .orderByDesc(WaylineJobEntity::getBeginTime) |
| | | // ); |
| | | |
| | | WaylineJobEntity waylineJobEntity = mapper.getLatest(workspaceId, waylineJobQueryParam); |
| | | |
| | | |
| | | return waylineJobEntity; |
| | | } |
| | | |
| | | @Override |
| | | public ResponseResult flyByArea(String sn, FlyAreaParam flyAreaParam) { |
| | | public ResponseResult flyByArea(String sn, FlyAreaParam flyAreaParam, String deviceSn) throws Exception { |
| | | |
| | | List<List<PointPOJO>> areaList = flyAreaParam.getAreaList(); |
| | | //获取所有中心点 |
| | | // List<PointPOJO> targetList = GeoUtils.caculatePointList(flyAreaParam); |
| | | PointPOJO dockPoint = flyAreaParam.getDockPoint(); |
| | | Double radius = flyAreaParam.getRadius(); |
| | | GeoJson geoJson = GeoUtils.readJsonFile(flyAreaParam.getJsonPath()); |
| | | List<PointPOJO> targetList = GeoUtils.caculatePointList(geoJson, dockPoint, flyAreaParam.getRadius()); |
| | | |
| | | List<PointPOJO> centerPointList = new ArrayList<>(); |
| | | //一键起飞 |
| | | TakeoffToPointParam takeoffToPointParam = buildTakeoffToPointParam(dockPoint); |
| | | |
| | | //根据区域获取中心点 |
| | | areaList.forEach(area -> { |
| | | PointPOJO centerPoint = GeoUtils.getCenterPoint(area); |
| | | centerPointList.add(centerPoint); |
| | | }); |
| | | ResponseResult takeoffToPointRes = controlService.takeoffToPoint(sn, takeoffToPointParam); |
| | | |
| | | //巡逻目标集合 |
| | | List<PointPOJO> targetList = new ArrayList<>(); |
| | | //获取所有中心点之后, |
| | | centerPointList.forEach(centerPoint -> { |
| | | //判断各个中心点和机场点的距离 |
| | | double distance = GeoUtils.distance(dockPoint.getLon(), dockPoint.getLat(), centerPoint.getLon(), centerPoint.getLat()); |
| | | //设置飞向第一个点 |
| | | while (takeoffToPointRes.getCode() == ResponseResult.CODE_SUCCESS) { |
| | | //获取无人机状态 |
| | | DeviceModeCodeEnum deviceMode = deviceService.getDeviceMode(deviceSn); |
| | | |
| | | //当距离小于半径时,添加到目标集合中 |
| | | if (distance <= radius) { |
| | | centerPoint.setDistance(distance); |
| | | targetList.add(centerPoint); |
| | | //当无人机状态为手动飞行 |
| | | if (deviceMode == DeviceModeCodeEnum.MANUAL) { |
| | | //飞向目标点 |
| | | FlyToPointParam flyToPointParam = new FlyToPointParam(); |
| | | flyToPointParam.setMaxSpeed(14); |
| | | List<PointDTO> pointDTOS = new ArrayList<>(); |
| | | |
| | | PointDTO pointDTO = new PointDTO(); |
| | | pointDTO.setHeight(120.0); |
| | | pointDTO.setLongitude(targetList.get(0).getLon()); |
| | | pointDTO.setLatitude(targetList.get(0).getLat()); |
| | | pointDTOS.add(pointDTO); |
| | | flyToPointParam.setPoints(pointDTOS); |
| | | |
| | | |
| | | ResponseResult flyToRes = controlService.flyToPoint(sn, flyToPointParam); |
| | | |
| | | if (flyToRes.getCode() == ResponseResult.CODE_SUCCESS) { |
| | | //第一个点指令飞行成功后,把数组存到redis中 |
| | | JSONObject jsonObject = new JSONObject(); |
| | | jsonObject.put("targetList",targetList); |
| | | jsonObject.put("payloadIndex",flyAreaParam.getPayloadIndex()); |
| | | jsonObject.put("curIndex",0); |
| | | RedisOpsUtils.set("tuban:"+sn,jsonObject); |
| | | } |
| | | break; |
| | | } |
| | | }); |
| | | } |
| | | |
| | | //按距离从近到远排序 |
| | | targetList.sort(Comparator.comparing(PointPOJO::getDistance)); |
| | | return ResponseResult.success(targetList); |
| | | } |
| | | |
| | | //后续为无人机操作逻辑 |
| | | //先飞到空中 |
| | | public TakeoffToPointParam buildTakeoffToPointParam(PointPOJO dockPoint) { |
| | | TakeoffToPointParam takeoffToPointParam = new TakeoffToPointParam(); |
| | | |
| | | takeoffToPointParam.setTargetLatitude(dockPoint.getLat()); |
| | |
| | | takeoffToPointParam.setMaxSpeed(10.0); |
| | | takeoffToPointParam.setExitWaylineWhenRcLost(WaylineRcLostActionEnum.EXECUTE_RC_LOST_ACTION); |
| | | |
| | | //起飞 |
| | | ResponseResult responseResult = controlService.takeoffToPoint(sn, takeoffToPointParam); |
| | | |
| | | if (responseResult.getCode() != ResponseResult.CODE_SUCCESS) { |
| | | return responseResult; |
| | | } |
| | | //向目标点飞行 |
| | | |
| | | FlyToPointParam flyToPointParam = new FlyToPointParam(); |
| | | flyToPointParam.setMaxSpeed(14); |
| | | List<PointDTO> pointDTOS = new ArrayList<>(); |
| | | targetList.forEach(pointPOJO -> { |
| | | PointDTO pointDTO = new PointDTO(); |
| | | pointDTO.setHeight(150.0); |
| | | pointDTO.setLongitude(pointPOJO.getLon()); |
| | | pointDTO.setLatitude(pointPOJO.getLat()); |
| | | |
| | | pointDTOS.add(pointDTO); |
| | | }); |
| | | flyToPointParam.setPoints(pointDTOS); |
| | | ResponseResult responseResult1 = controlService.flyToPoint(sn, flyToPointParam); |
| | | |
| | | if (responseResult1.getCode() != ResponseResult.CODE_SUCCESS) { |
| | | return responseResult1; |
| | | } |
| | | |
| | | //返航 |
| | | //return_home |
| | | |
| | | |
| | | return ResponseResult.success(); |
| | | return takeoffToPointParam; |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public ResponseResult checkNextJob(WaylineJobDTO job) throws SQLException { |
| | | public ResponseResult checkNextJob(WaylineJobDTO job) throws SQLException { |
| | | |
| | | WaylineJobEntity params = new WaylineJobEntity(); |
| | | params.setJobId(job.getJobId()); |
| | | |
| | | |
| | | WaylineJobEntity currentJob = mapper.selectOne(Wrappers.query(params)); |
| | | WaylineJobEntity job1 = mapper.selectOne(Wrappers.query(params)); |
| | | |
| | | WaylineJobEntity currentJob = JSON.parseObject(JSON.toJSONString(job1), WaylineJobEntity.class); |
| | | |
| | | if (currentJob == null) { |
| | | return ResponseResult.error("该任务不存在"); |
| | | } |
| | |
| | | |
| | | long currentTime = System.currentTimeMillis(); |
| | | for (int i = 0; i < executeStartTimeArr.size(); i++) { |
| | | Long startTime = Long.valueOf(executeStartTimeArr.get(i).get(0)); |
| | | Long startTime = executeStartTimeArr.get(i).get(0) * 1000; |
| | | //如果当前时间小于开始时间 |
| | | if (currentTime < startTime) { |
| | | //当前索引就是下一次要执行的时间 |
| | |
| | | break; |
| | | } |
| | | } |
| | | |
| | | if (indexTime == -1) { |
| | | return ResponseResult.success(); |
| | | } |
| | | |
| | | |
| | | List<Long> timeArr = currentJob.getExecuteStartTimeArr().get(indexTime); |
| | | LocalDate date = LocalDate.ofInstant(Instant.ofEpochSecond(timeArr.get(0)), ZoneId.systemDefault()); |
| | |
| | | |
| | | |
| | | @Override |
| | | public WaylineJobCountDTO patrolStatistics(String workspaceId) { |
| | | public WaylineJobCountDTO patrolStatistics(String workspaceId, String queryTime,String deviceSn) { |
| | | WaylineJobCountDTO waylineJobCountDTO = new WaylineJobCountDTO(); |
| | | List<WaylineJobEntity> list = new LambdaQueryChainWrapper<>(mapper).eq(WaylineJobEntity::getStatus, 3).list(); |
| | | if (!CollectionUtils.isEmpty(list)){ |
| | | List<DroneFlightLogEntity> list = flightLogMapper.patrolStatistics(workspaceId,queryTime,deviceSn); |
| | | if (!CollectionUtils.isEmpty(list)) { |
| | | waylineJobCountDTO.setTotalNumber(list.size()); |
| | | long totalTime = list.stream().mapToLong(s -> s.getEndTime() - s.getBeginTime()).sum() / 1000; |
| | | StringBuffer buffer = new StringBuffer(); |
| | | long totalTime = list.stream().filter(task -> task.getEndTime()!= null && task.getStartTime()!= null).mapToLong(s -> s.getEndTime() - s.getStartTime()).sum() / 1000; |
| | | long h = totalTime / 3600; |
| | | long m = (totalTime % 3600) / 60; |
| | | buffer.append(h).append(" h "); |
| | | buffer.append(m).append(" min"); |
| | | waylineJobCountDTO.setTotalDuration(buffer.toString()); |
| | | waylineJobCountDTO.setTotalDuration( String.format("%02d h %02d min", h, m)); |
| | | List<String> deviceSns = list.stream().map(DroneFlightLogEntity::getDeviceSn).distinct().collect(Collectors.toList()); |
| | | double sum = 0.0; |
| | | for (String sn : deviceSns) { |
| | | Double totalFlightDistance = new LambdaQueryChainWrapper<>(flightLogMapper) |
| | | .eq(DroneFlightLogEntity::getDeviceSn, sn).orderByDesc(DroneFlightLogEntity::getEndTime).last("limit 1").one().getTotalFlightDistance(); |
| | | if (totalFlightDistance!= null){ |
| | | sum+=totalFlightDistance; |
| | | } |
| | | } |
| | | waylineJobCountDTO.setTotalDistance((int) sum); |
| | | } |
| | | return waylineJobCountDTO; |
| | | } |
| | |
| | | @Override |
| | | public void updateJobCollect(WaylineJobEntity waylineJob) { |
| | | new LambdaUpdateChainWrapper<>(mapper) |
| | | .eq(WaylineJobEntity::getJobId,waylineJob.getJobId()) |
| | | .set(WaylineJobEntity::getCollectStatus,waylineJob.getCollectStatus()) |
| | | .set(WaylineJobEntity::getUserId,waylineJob.getUserId()) |
| | | .eq(WaylineJobEntity::getJobId, waylineJob.getJobId()) |
| | | .set(WaylineJobEntity::getCollectStatus, waylineJob.getCollectStatus()) |
| | | .set(WaylineJobEntity::getUserId, waylineJob.getUserId()) |
| | | .update(); |
| | | } |
| | | |
| | |
| | | .waylineType(WaylineTemplateTypeEnum.find(entity.getWaylineType())) |
| | | .rthAltitude(entity.getRthAltitude()) |
| | | .outOfControlAction(entity.getOutOfControlAction()) |
| | | .mediaCount(entity.getMediaCount()); |
| | | .mediaCount(entity.getMediaCount()) |
| | | .hasChildren(entity.getHasChildren()); |
| | | |
| | | if (Objects.nonNull(entity.getEndTime())) { |
| | | builder.endTime(LocalDateTime.ofInstant(Instant.ofEpochMilli(entity.getEndTime()), ZoneId.systemDefault())); |