| | |
| | | package com.dji.sample.wayline.service.impl; |
| | | |
| | | import com.alibaba.druid.stat.TableStat; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | 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.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.dji.sample.common.error.CommonErrorEnum; |
| | | import com.dji.sample.common.model.CustomClaim; |
| | |
| | | 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.service.IControlService; |
| | | import com.dji.sample.control.service.IDrcService; |
| | | 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.manage.model.enums.DroneRcLostActionEnum; |
| | | import com.dji.sample.manage.model.enums.WaylineRcLostActionEnum; |
| | | import com.dji.sample.manage.model.receiver.OsdDockReceiver; |
| | | import com.dji.sample.manage.model.receiver.OsdSubDeviceReceiver; |
| | | import com.dji.sample.manage.service.IDeviceRedisService; |
| | |
| | | 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.wayline.dao.IWaylineJobMapper; |
| | | import com.dji.sample.wayline.model.dto.*; |
| | | import com.dji.sample.wayline.model.entity.WaylineJobEntity; |
| | | import com.dji.sample.wayline.model.enums.*; |
| | | import com.dji.sample.wayline.model.param.CreateJobParam; |
| | | import com.dji.sample.wayline.model.param.UpdateJobParam; |
| | | import com.dji.sample.wayline.model.param.WaylineJobQueryParam; |
| | | import com.dji.sample.wayline.model.param.*; |
| | | import com.dji.sample.wayline.service.IWaylineFileService; |
| | | import com.dji.sample.wayline.service.IWaylineJobService; |
| | | import com.dji.sample.wayline.service.IWaylineRedisService; |
| | |
| | | @Autowired |
| | | private IWaylineRedisService waylineRedisService; |
| | | |
| | | @Autowired |
| | | private IControlService controlService; |
| | | |
| | | private Optional<WaylineJobDTO> insertWaylineJob(WaylineJobEntity jobEntity) { |
| | | int id = mapper.insert(jobEntity); |
| | | if (id <= 0) { |
| | |
| | | |
| | | /** |
| | | * 对于即时任务,以服务器时间为准。 |
| | | * |
| | | * @param param |
| | | */ |
| | | private void fillImmediateTime(CreateJobParam param) { |
| | |
| | | |
| | | @Override |
| | | public ResponseResult publishFlightTask(CreateJobParam param, CustomClaim customClaim) throws SQLException { |
| | | |
| | | //当重复定时和连续执行时走这个逻辑 |
| | | if (param.getTaskType().getVal() == WaylineTaskTypeEnum.CONDITION.getVal()){ |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | //保存数据 |
| | | WaylineJobEntity waylineJobEntity = WaylineJobEntity.builder() |
| | | .jobId(UUID.randomUUID().toString()) |
| | | .name(param.getName()) |
| | | .dockSn(param.getDockSn()) |
| | | .fileId(param.getFileId()) |
| | | .username(customClaim.getUsername()) |
| | | .workspaceId(customClaim.getWorkspaceId()) |
| | | |
| | | |
| | | .beginTime(param.getTaskDays().get(0)*1000) |
| | | .endTime(param.getTaskDays().get(1)*1000) |
| | | .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()) |
| | | .build(); |
| | | |
| | | Boolean insert = mapper.insert(waylineJobEntity)>0; |
| | | |
| | | return ResponseResult.success(insert); |
| | | } |
| | | |
| | | fillImmediateTime(param); |
| | | |
| | | // param.getTaskDays().sort((a, b) -> (int) (a - b)); |
| | |
| | | return ResponseResult.success(); |
| | | } |
| | | |
| | | @Override |
| | | public ResponseResult publishFlightTaskCondition(CreateJobParam param, CustomClaim customClaim) throws SQLException { |
| | | //开始日期 |
| | | LocalDate startDate = LocalDate.ofInstant(Instant.ofEpochSecond(param.getTaskDays().get(0)), ZoneId.systemDefault()); |
| | | long start = 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()); |
| | | long end = LocalDateTime.of(endDate, LocalTime.ofInstant(Instant.ofEpochSecond(param.getExecuteStartTimeArr().get(param.getExecuteStartTimeArr().size() - 1).get(0)), ZoneId.systemDefault())) |
| | | .atZone(ZoneId.systemDefault()).toInstant().toEpochMilli(); |
| | | |
| | | //保存数据 |
| | | WaylineJobEntity waylineJobEntity = WaylineJobEntity.builder() |
| | | .jobId(UUID.randomUUID().toString()) |
| | | .name(param.getName()) |
| | | .dockSn(param.getDockSn()) |
| | | .fileId(param.getFileId()) |
| | | .username(customClaim.getUsername()) |
| | | .workspaceId(customClaim.getWorkspaceId()) |
| | | |
| | | .beginTime(start) |
| | | .endTime(end) |
| | | .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("任务创建失败"); |
| | | } |
| | | |
| | | WaylineJobDTO waylineJob = waylineJobOpt.get(); |
| | | |
| | | //存一条记录, |
| | | List<Long> timeArr = param.getExecuteStartTimeArr().get(0); |
| | | |
| | | LocalDate date = LocalDate.ofInstant(Instant.ofEpochSecond(timeArr.get(0)), ZoneId.systemDefault()); |
| | | LocalDateTime 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; |
| | | |
| | | if (WaylineTaskTypeEnum.IMMEDIATE != param.getTaskType() && endTime.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli() < System.currentTimeMillis()) { |
| | | return ResponseResult.error("任务已过期"); |
| | | } |
| | | //条件任务 |
| | | 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(beginTime.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli()) |
| | | .endTime(endTime.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli()) |
| | | .build()) |
| | | .build()); |
| | | } else { |
| | | waylineJob.setBeginTime(beginTime); |
| | | } |
| | | |
| | | ResponseResult response = this.publishOneFlightTask(waylineJob); |
| | | if (ResponseResult.CODE_SUCCESS != response.getCode()) { |
| | | return response; |
| | | } |
| | | |
| | | return ResponseResult.success(); |
| | | } |
| | | |
| | | private void addPreparedJob(WaylineJobDTO waylineJob, CreateJobParam param, Long beginTime, Long endTime) { |
| | | if (WaylineTaskTypeEnum.CONDITION == param.getTaskType()) { |
| | | waylineJob.setConditions( |
| | | WaylineTaskConditionDTO.builder() |
| | | .executableConditions(Objects.nonNull(param.getMinStorageCapacity()) ? |
| | | WaylineTaskExecutableConditionDTO.builder().storageCapacity(param.getMinStorageCapacity()).build() : null) |
| | | .executableConditions(Objects.nonNull(param.getMinStorageCapacity()) ? WaylineTaskExecutableConditionDTO.builder().storageCapacity(param.getMinStorageCapacity()).build() : null) |
| | | .readyConditions(WaylineTaskReadyConditionDTO.builder() |
| | | .batteryCapacity(param.getMinBatteryCapacity()) |
| | | .beginTime(beginTime) |
| | |
| | | |
| | | Set<String> waylineJobIds = waylineJobs.stream().map(WaylineJobDTO::getJobId).collect(Collectors.toSet()); |
| | | // Check if the task status is correct. |
| | | boolean isErr = !jobIds.removeAll(waylineJobIds) || !jobIds.isEmpty() ; |
| | | boolean isErr = !jobIds.removeAll(waylineJobIds) || !jobIds.isEmpty(); |
| | | if (isErr) { |
| | | throw new IllegalArgumentException("以下任务状态不正确,不能取消" + Arrays.toString(jobIds.toArray())); |
| | | } |
| | |
| | | |
| | | public List<WaylineJobDTO> getJobsByConditions(String workspaceId, Collection<String> jobIds, WaylineJobStatusEnum status) { |
| | | return mapper.selectList( |
| | | new LambdaQueryWrapper<WaylineJobEntity>() |
| | | .eq(WaylineJobEntity::getWorkspaceId, workspaceId) |
| | | .eq(Objects.nonNull(status), WaylineJobEntity::getStatus, status.getVal()) |
| | | .in(!CollectionUtils.isEmpty(jobIds), WaylineJobEntity::getJobId, jobIds)) |
| | | new LambdaQueryWrapper<WaylineJobEntity>() |
| | | .eq(WaylineJobEntity::getWorkspaceId, workspaceId) |
| | | .eq(Objects.nonNull(status), WaylineJobEntity::getStatus, status.getVal()) |
| | | .in(!CollectionUtils.isEmpty(jobIds), WaylineJobEntity::getJobId, jobIds)) |
| | | .stream() |
| | | .map(this::entity2Dto) |
| | | .collect(Collectors.toList()); |
| | |
| | | } |
| | | |
| | | @Override |
| | | public Boolean updateJob(WaylineJobDTO dto) { |
| | | public Boolean updateJob(WaylineJobDTO dto){ |
| | | |
| | | try { |
| | | if (dto.getStatus() == 3){ |
| | | this.checkNextJob(dto); |
| | | } |
| | | }catch (SQLException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | |
| | | |
| | | return mapper.update(this.dto2Entity(dto), |
| | | new LambdaUpdateWrapper<WaylineJobEntity>() |
| | | .eq(WaylineJobEntity::getJobId, dto.getJobId())) > 0; |
| | |
| | | |
| | | @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); |
| | | |
| | | |
| | | Page<WaylineJobEntity> pageData = mapper.getPage(new Page<WaylineJobEntity>(page, pageSize), waylineJobQueryParam, workspaceId); |
| | | |
| | | List<WaylineJobDTO> records = pageData.getRecords() |
| | | .stream() |
| | |
| | | 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; |
| | | } |
| | | |
| | | |
| | | @Override |
| | | @ServiceActivator(inputChannel = ChannelName.INBOUND_REQUESTS_FLIGHT_TASK_RESOURCE_GET, outputChannel = ChannelName.OUTBOUND) |
| | | @Transactional(isolation = Isolation.READ_UNCOMMITTED) |
| | | public void flightTaskResourceGet(CommonTopicReceiver receiver, MessageHeaders headers) { |
| | | Map<String, String> jobIdMap = objectMapper.convertValue(receiver.getData(), new TypeReference<Map<String, String>>() {}); |
| | | Map<String, String> jobIdMap = objectMapper.convertValue(receiver.getData(), new TypeReference<Map<String, String>>() { |
| | | }); |
| | | String jobId = jobIdMap.get(MapKeyConst.FLIGHT_ID); |
| | | |
| | | CommonTopicResponse.CommonTopicResponseBuilder<RequestsReply> builder = CommonTopicResponse.<RequestsReply>builder() |
| | |
| | | return WaylineJobStatusEnum.UNKNOWN; |
| | | } |
| | | |
| | | @Override |
| | | public WaylineJobEntity getLatestJob(String workspaceId, WaylineJobQueryParam waylineJobQueryParam) { |
| | | WaylineJobEntity waylineJobEntity = mapper.getLatest(workspaceId, waylineJobQueryParam); |
| | | return waylineJobEntity; |
| | | } |
| | | |
| | | @Override |
| | | public ResponseResult flyByArea(String sn, FlyAreaParam flyAreaParam) { |
| | | |
| | | List<List<PointPOJO>> areaList = flyAreaParam.getAreaList(); |
| | | PointPOJO dockPoint = flyAreaParam.getDockPoint(); |
| | | Double radius = flyAreaParam.getRadius(); |
| | | |
| | | List<PointPOJO> centerPointList = new ArrayList<>(); |
| | | |
| | | //根据区域获取中心点 |
| | | areaList.forEach(area -> { |
| | | PointPOJO centerPoint = GeoUtils.getCenterPoint(area); |
| | | centerPointList.add(centerPoint); |
| | | }); |
| | | |
| | | //巡逻目标集合 |
| | | List<PointPOJO> targetList = new ArrayList<>(); |
| | | //获取所有中心点之后, |
| | | centerPointList.forEach(centerPoint -> { |
| | | //判断各个中心点和机场点的距离 |
| | | double distance = GeoUtils.distance(dockPoint.getLon(), dockPoint.getLat(), centerPoint.getLon(), centerPoint.getLat()); |
| | | |
| | | //当距离小于半径时,添加到目标集合中 |
| | | if (distance <= radius) { |
| | | centerPoint.setDistance(distance); |
| | | targetList.add(centerPoint); |
| | | } |
| | | }); |
| | | |
| | | //按距离从近到远排序 |
| | | targetList.sort(Comparator.comparing(PointPOJO::getDistance)); |
| | | |
| | | //后续为无人机操作逻辑 |
| | | //先飞到空中 |
| | | TakeoffToPointParam takeoffToPointParam = new TakeoffToPointParam(); |
| | | |
| | | takeoffToPointParam.setTargetLatitude(dockPoint.getLat()); |
| | | takeoffToPointParam.setTargetLongitude(dockPoint.getLon()); |
| | | //设置飞行高度 |
| | | takeoffToPointParam.setTargetHeight(120.0); |
| | | //设置安全起飞高度 |
| | | takeoffToPointParam.setSecurityTakeoffHeight(100.0); |
| | | //设置返航高度 |
| | | takeoffToPointParam.setRthAltitude(100.0); |
| | | //设置失控操作 |
| | | takeoffToPointParam.setRcLostAction(DroneRcLostActionEnum.RETURN_HOME); |
| | | //设置起飞速度 |
| | | takeoffToPointParam.setMaxSpeed(10.0); |
| | | takeoffToPointParam.setExitWaylineWhenRcLost(WaylineRcLostActionEnum.EXECUTE_RC_LOST_ACTION); |
| | | |
| | | return ResponseResult.success(); |
| | | // //起飞 |
| | | // 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(); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public ResponseResult checkNextJob(WaylineJobDTO job) throws SQLException { |
| | | |
| | | WaylineJobEntity params = new WaylineJobEntity(); |
| | | params.setJobId(job.getJobId()); |
| | | |
| | | |
| | | WaylineJobEntity job1 = mapper.selectOne(Wrappers.query(params)); |
| | | |
| | | WaylineJobEntity currentJob = JSON.parseObject(JSON.toJSONString(job1), WaylineJobEntity.class); |
| | | |
| | | if (currentJob == null) { |
| | | return ResponseResult.error("该任务不存在"); |
| | | } |
| | | |
| | | //该任务没有多次时间 |
| | | if (currentJob.getExecuteStartTimeArr() == null) { |
| | | return ResponseResult.success(); |
| | | } |
| | | |
| | | List<List<Long>> executeStartTimeArr = currentJob.getExecuteStartTimeArr(); |
| | | int indexTime = -1; |
| | | |
| | | long currentTime = System.currentTimeMillis(); |
| | | for (int i = 0; i < executeStartTimeArr.size(); i++) { |
| | | Long startTime = executeStartTimeArr.get(i).get(0)*1000; |
| | | //如果当前时间小于开始时间 |
| | | if (currentTime < startTime) { |
| | | //当前索引就是下一次要执行的时间 |
| | | indexTime = i; |
| | | 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()); |
| | | LocalDateTime beginDate = LocalDateTime.of(date, LocalTime.ofInstant(Instant.ofEpochSecond(timeArr.get(0)), ZoneId.systemDefault())); |
| | | LocalDateTime endDate = timeArr.size() > 1 && Objects.nonNull(timeArr.get(1)) ? |
| | | LocalDateTime.of(date, LocalTime.ofInstant(Instant.ofEpochSecond(timeArr.get(1)), ZoneId.systemDefault())) |
| | | : beginDate; |
| | | |
| | | long beginTime = beginDate |
| | | .atZone(ZoneId.systemDefault()).toInstant().toEpochMilli(); |
| | | long endTime = endDate |
| | | .atZone(ZoneId.systemDefault()).toInstant().toEpochMilli(); |
| | | |
| | | |
| | | //添加一条新数据 |
| | | WaylineJobEntity waylineJobEntity = WaylineJobEntity.builder() |
| | | .jobId(UUID.randomUUID().toString()) |
| | | //大于1则拿前面的parentId,为1则拿第0个的id |
| | | .parentId(indexTime > 1 ? currentJob.getParentId().toString() : currentJob.getId().toString()) |
| | | .name(currentJob.getName()) |
| | | .dockSn(currentJob.getDockSn()) |
| | | .fileId(currentJob.getFileId()) |
| | | .username(currentJob.getUsername()) |
| | | .workspaceId(currentJob.getWorkspaceId()) |
| | | |
| | | .beginTime(beginTime) |
| | | .endTime(endTime) |
| | | .status(WaylineJobStatusEnum.PENDING.getVal()) |
| | | .taskType(currentJob.getTaskType()) |
| | | .waylineType(currentJob.getWaylineType()) |
| | | .outOfControlAction(currentJob.getOutOfControlAction()) |
| | | .batteryCapacity(currentJob.getBatteryCapacity()) |
| | | .rthAltitude(currentJob.getRthAltitude()) |
| | | .mediaCount(0) |
| | | .repFreVal(currentJob.getRepFreVal()) |
| | | .repFreType(currentJob.getRepFreType()) |
| | | .repRuleType(currentJob.getRepRuleType()) |
| | | .repRuleVal(currentJob.getRepRuleVal()) |
| | | .executeTimeArr(currentJob.getExecuteTimeArr()) |
| | | .executeStartTimeArr(currentJob.getExecuteStartTimeArr()) |
| | | .build(); |
| | | |
| | | Optional<WaylineJobDTO> waylineJobOpt = insertWaylineJob(waylineJobEntity); |
| | | |
| | | if (waylineJobOpt.isEmpty()) { |
| | | return ResponseResult.error("任务创建失败"); |
| | | } |
| | | |
| | | WaylineJobDTO waylineJob = waylineJobOpt.get(); |
| | | |
| | | LocalDateTime beginTimeNext = LocalDateTime.of(date, LocalTime.ofInstant(Instant.ofEpochSecond(timeArr.get(0)), ZoneId.systemDefault())); |
| | | |
| | | LocalDateTime endTimeNext = timeArr.size() > 1 && Objects.nonNull(timeArr.get(1)) ? |
| | | LocalDateTime.of(date, LocalTime.ofInstant(Instant.ofEpochSecond(timeArr.get(1)), ZoneId.systemDefault())) : beginTimeNext; |
| | | |
| | | |
| | | //条件任务 |
| | | if (currentJob.getTaskType() == 2) { |
| | | //如果是条件任务类型,需要在任务参数中添加条件。 |
| | | waylineJob.setConditions( |
| | | WaylineTaskConditionDTO.builder() |
| | | .executableConditions(null) |
| | | .readyConditions(WaylineTaskReadyConditionDTO.builder() |
| | | .batteryCapacity(currentJob.getBatteryCapacity()) |
| | | .beginTime(beginTime) |
| | | .endTime(endTime) |
| | | .build()) |
| | | .build()); |
| | | } else { |
| | | waylineJob.setBeginTime(beginDate); |
| | | } |
| | | |
| | | ResponseResult response = this.publishOneFlightTask(waylineJob); |
| | | if (ResponseResult.CODE_SUCCESS != response.getCode()) { |
| | | return response; |
| | | } |
| | | |
| | | return ResponseResult.success(); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | @Override |
| | | public WaylineJobCountDTO patrolStatistics(String workspaceId,String queryTime) { |
| | | WaylineJobCountDTO waylineJobCountDTO = new WaylineJobCountDTO(); |
| | | List<WaylineJobEntity> list = mapper.patrolStatistics(workspaceId,queryTime); |
| | | 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 h = totalTime / 3600; |
| | | long m = (totalTime % 3600) / 60; |
| | | buffer.append(h).append(" h "); |
| | | buffer.append(m).append(" min"); |
| | | waylineJobCountDTO.setTotalDuration(buffer.toString()); |
| | | } |
| | | 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()) |
| | | .update(); |
| | | } |
| | | |
| | | private void pauseJob(String workspaceId, String dockSn, String jobId, WaylineJobStatusEnum statusEnum) { |
| | | if (WaylineJobStatusEnum.PAUSED == statusEnum && jobId.equals(waylineRedisService.getPausedWaylineJobId(dockSn))) { |
| | | waylineRedisService.setPausedWaylineJob(dockSn, jobId); |
| | |
| | | .workspaceId(entity.getWorkspaceId()) |
| | | .status(WaylineJobStatusEnum.IN_PROGRESS.getVal() == entity.getStatus() && |
| | | entity.getJobId().equals(waylineRedisService.getPausedWaylineJobId(entity.getDockSn())) ? |
| | | WaylineJobStatusEnum.PAUSED.getVal() : entity.getStatus()) |
| | | WaylineJobStatusEnum.PAUSED.getVal() : entity.getStatus()) |
| | | .code(entity.getErrorCode()) |
| | | .beginTime(LocalDateTime.ofInstant(Instant.ofEpochMilli(entity.getBeginTime()), ZoneId.systemDefault())) |
| | | .endTime(Objects.nonNull(entity.getEndTime()) ? |
| | |
| | | .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())); |
| | |
| | | Object mediaFileCount = RedisOpsUtils.hashGet(countKey, entity.getJobId()); |
| | | if (Objects.nonNull(mediaFileCount)) { |
| | | builder.uploadedCount(((MediaFileCountDTO) mediaFileCount).getUploadedCount()) |
| | | .uploading(RedisOpsUtils.checkExist(key) && entity.getJobId().equals(((MediaFileCountDTO)RedisOpsUtils.get(key)).getJobId())); |
| | | .uploading(RedisOpsUtils.checkExist(key) && entity.getJobId().equals(((MediaFileCountDTO) RedisOpsUtils.get(key)).getJobId())); |
| | | return builder.build(); |
| | | } |
| | | |