| | |
| | | import com.ard.oss.service.impl.OssServiceContext; |
| | | import com.ard.route.domain.route.ArdRouteInfo; |
| | | import com.ard.route.service.IArdRouteInfoService; |
| | | import com.baomidou.mybatisplus.core.conditions.Wrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | |
| | | import com.fasterxml.jackson.databind.ObjectMapper; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.codec.digest.DigestUtils; |
| | | import org.apache.ibatis.annotations.Param; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.integration.annotation.ServiceActivator; |
| | | import org.springframework.integration.mqtt.support.MqttHeaders; |
| | |
| | | /** |
| | | * 创建航线任务 |
| | | * |
| | | * @param param 任务参数 |
| | | * @param username 用户名 |
| | | * @param param 任务参数 |
| | | * @param username 用户名 |
| | | * @param beginTime 开始时间 |
| | | * @param endTime 结束时间 |
| | | * @return Optional<WaylineJobDTO> 返回创建的航线任务对象,若创建失败则返回Optional.empty() |
| | |
| | | .outOfControlAction(param.getOutOfControlAction()) |
| | | .rthAltitude(param.getRthAltitude()) |
| | | .mediaCount(0) |
| | | .parentId(param.getParentId()) |
| | | .loopSum(param.getLoopSum()) |
| | | .build(); |
| | | |
| | | return insertWaylineJob(jobEntity); |
| | |
| | | /** |
| | | * 发布飞行任务 |
| | | * |
| | | * @param param 任务参数 |
| | | * @param param 任务参数 |
| | | * @param loginUser 登录用户 |
| | | * @return ResponseResult 返回结果 |
| | | * @throws SQLException SQL异常 |
| | |
| | | if (waylineJobOpt.isEmpty()) { |
| | | return ResponseResult.error("创建机场任务失败!"); |
| | | } |
| | | // 循环任务 |
| | | if (param.getTaskType() == WaylineTaskTypeEnum.LOOP.getVal()) { |
| | | // 循环任务,不立即执行,由定时任务发布 |
| | | return ResponseResult.success(); |
| | | } |
| | | |
| | | WaylineJobDTO waylineJob = waylineJobOpt.get(); |
| | | |
| | | boolean isOnline = deviceService.checkDeviceOnline(waylineJob.getDockSn()); |
| | |
| | | |
| | | // get file url |
| | | // URL url = waylineFileService.getObjectUrl(waylineFile.get().getWaylineId()); |
| | | URL url= null; |
| | | String minioUrl = subStringMinioUrlName(ardRouteOpt.getUpPath()); |
| | | URL url = null; |
| | | String minioUrl = subStringMinioUrlName(ardRouteOpt.getPath()); |
| | | String md5 = ""; |
| | | try (InputStream inputStream = _ossService.getObject(kmzPath,minioUrl)) |
| | | { |
| | | try (InputStream inputStream = _ossService.getObject(kmzPath, minioUrl)) { |
| | | md5 = DigestUtils.md5Hex(inputStream); |
| | | url = new URL(ardRouteOpt.getUpPath()); |
| | | } |
| | | catch (Exception e) { |
| | | url = new URL(ardRouteOpt.getPath()); |
| | | } catch (Exception e) { |
| | | return ResponseResult.error("机场任务航线文件地址错误!" + e.getMessage()); |
| | | } |
| | | |
| | |
| | | .fingerprint(md5) |
| | | .build()) |
| | | .simulateMission(WaylineSimulateMissionDTO.builder() |
| | | .isEnable(param.getSimulateMission().getIsEnable()) |
| | | .latitude(param.getSimulateMission().getLatitude()) |
| | | .longitude(param.getSimulateMission().getLongitude()) |
| | | .isEnable(1) |
| | | .latitude(46.558831038) |
| | | .longitude(125.148072319) |
| | | .build()) |
| | | .build(); |
| | | |
| | | String topic = TopicConst.THING_MODEL_PRE + TopicConst.PRODUCT + |
| | | waylineJob.getDockSn() + TopicConst.SERVICES_SUF; |
| | | CommonTopicResponse<Object> response = CommonTopicResponse.builder() |
| | | .tid(UUID.randomUUID().toString()) |
| | | .bid(waylineJob.getJobId()) |
| | | .timestamp(System.currentTimeMillis()) |
| | | .data(flightTask) |
| | | .method(WaylineMethodEnum.FLIGHT_TASK_PREPARE.getMethod()) |
| | | .build(); |
| | | |
| | | ServiceReply serviceReply = messageSender.publishWithReply(topic, response); |
| | | if (ResponseResult.CODE_SUCCESS != serviceReply.getResult()) { |
| | | log.info("Prepare task ====> Error code: {}", serviceReply.getResult()); |
| | | this.updateJob(WaylineJobDTO.builder() |
| | | .jobId(waylineJob.getJobId()) |
| | | .executeTime(LocalDateTime.now()) |
| | | .status(WaylineJobStatusEnum.FAILED.getVal()) |
| | | .completedTime(LocalDateTime.now()) |
| | | .code(serviceReply.getResult()).build()); |
| | | return ResponseResult.error("Prepare task ====> Error code: " + serviceReply.getResult()); |
| | | } |
| | | |
| | | // 飞行命令先注释掉 |
| | | // Issue an immediate task execution command. |
| | | // if (WaylineTaskTypeEnum.IMMEDIATE.getVal() == waylineJob.getTaskType()) { |
| | | // if (!executeFlightTask(waylineJob.getJobId())) { |
| | | // return ResponseResult.error("Failed to execute job."); |
| | | // } |
| | | // } |
| | | // |
| | | // if (WaylineTaskTypeEnum.TIMED.getVal() == waylineJob.getTaskType()) { |
| | | // boolean isAdd = RedisOpsUtils.zAdd(RedisConst.WAYLINE_JOB_TIMED_EXECUTE, |
| | | // waylineJob.getDockSn() + RedisConst.DELIMITER + waylineJob.getJobId(), |
| | | // waylineJob.getBeginTime().atZone(ZoneId.systemDefault()).toInstant().toEpochMilli()); |
| | | // if (!isAdd) { |
| | | // return ResponseResult.error("Failed to create scheduled job."); |
| | | // } |
| | | // } |
| | | |
| | | return ResponseResult.success(); |
| | | } |
| | | |
| | | public ResponseResult publishFlightTaskPrepare(Optional<WaylineJobDTO> waylineJobOpt) throws SQLException{ |
| | | |
| | | if (waylineJobOpt.isEmpty()) { |
| | | return ResponseResult.error("创建机场任务失败!"); |
| | | } |
| | | WaylineJobDTO waylineJob = waylineJobOpt.get(); |
| | | boolean isOnline = deviceService.checkDeviceOnline(waylineJob.getDockSn()); |
| | | if (!isOnline) { |
| | | return ResponseResult.error("机场不在线!"); |
| | | } |
| | | // 换航线表 |
| | | ArdRouteInfo ardRouteOpt = _ardRouteInfoService.selectArdRouteInfoById(waylineJob.getFileId()); |
| | | if (ardRouteOpt == null) { |
| | | return ResponseResult.error("机场任务航线不存在!"); |
| | | } |
| | | // get file url |
| | | URL url = null; |
| | | String minioUrl = subStringMinioUrlName(ardRouteOpt.getPath()); |
| | | String md5 = ""; |
| | | try (InputStream inputStream = _ossService.getObject(kmzPath, minioUrl)) { |
| | | md5 = DigestUtils.md5Hex(inputStream); |
| | | url = new URL(ardRouteOpt.getPath()); |
| | | } catch (Exception e) { |
| | | return ResponseResult.error("机场任务航线文件地址错误!" + e.getMessage()); |
| | | } |
| | | |
| | | WaylineTaskCreateDTO flightTask = 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()) |
| | | // .fingerprint(waylineFile.get().getSign()) |
| | | .fingerprint(md5) |
| | | .build()) |
| | | .simulateMission(WaylineSimulateMissionDTO.builder() |
| | | .isEnable(1) |
| | | .latitude(46.558831038) |
| | | .longitude(125.148072319) |
| | | .build()) |
| | | .build(); |
| | | |
| | |
| | | * @param jobId 任务ID |
| | | * @return 如果任务执行成功返回true,否则返回false |
| | | * @throws IllegalArgumentException 如果任务不存在 |
| | | * @throws RuntimeException 如果设备处于离线状态 |
| | | * @throws RuntimeException 如果设备处于离线状态 |
| | | */ |
| | | @Override |
| | | public Boolean executeFlightTask(String jobId) { |
| | |
| | | |
| | | 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("These tasks have an incorrect status and cannot be canceled. " |
| | | + Arrays.toString(jobIds.toArray())); |
| | |
| | | * 发布取消任务 |
| | | * |
| | | * @param dockSn 设备序列号 |
| | | * @param jobIds 任务ID列表 |
| | | * @param jobIds 任务ID列表 |
| | | * @throws RuntimeException 如果设备离线或取消任务失败,则抛出运行时异常 |
| | | */ |
| | | @Override |
| | |
| | | .completedTime(LocalDateTime.now()) |
| | | .build()); |
| | | RedisOpsUtils.zRemove(RedisConst.WAYLINE_JOB_TIMED_EXECUTE, RedisConst.DELIMITER + dockSn + RedisConst.DELIMITER + jobId); |
| | | // 原流程是修改表中数据的status状态值,现在的精力是直接删除 |
| | | this.deleteTask(jobId); |
| | | } |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void deleteTask(String jobid) { |
| | | mapper.delete(new LambdaQueryWrapper<WaylineJobEntity>() |
| | | .eq(WaylineJobEntity::getJobId, jobid)); |
| | | } |
| | | |
| | | /** |
| | |
| | | @Override |
| | | public List<WaylineJobDTO> getJobsByConditions(Collection<String> jobIds, WaylineJobStatusEnum status) { |
| | | return mapper.selectList( |
| | | new LambdaQueryWrapper<WaylineJobEntity>() |
| | | .eq(Objects.nonNull(status), WaylineJobEntity::getStatus, status.getVal()) |
| | | .and(!CollectionUtils.isEmpty(jobIds), |
| | | wrapper -> jobIds.forEach(id -> wrapper.eq(WaylineJobEntity::getJobId, id).or()))) |
| | | new LambdaQueryWrapper<WaylineJobEntity>() |
| | | .eq(Objects.nonNull(status), WaylineJobEntity::getStatus, status.getVal()) |
| | | .and(!CollectionUtils.isEmpty(jobIds), |
| | | wrapper -> jobIds.forEach(id -> wrapper.eq(WaylineJobEntity::getJobId, id).or()))) |
| | | .stream() |
| | | .map(this::entity2Dto) |
| | | .collect(Collectors.toList()); |
| | |
| | | return new PaginationData<WaylineJobDTO>(records, new Pagination(pageData)); |
| | | } |
| | | |
| | | /** |
| | | * 根据条件筛选获取任务分页数据 |
| | | * |
| | | * @param page 页码,从1开始 |
| | | * @param pageSize 每页显示条数 |
| | | * @return PaginationData 包含工作线任务分页数据的对象 |
| | | */ |
| | | @Override |
| | | public PaginationData<WaylineJobDTO> getJobsList(long page, long pageSize, Integer status, |
| | | Long startTime, Long endTime, Integer taskType, String name, Boolean isComplete) { |
| | | Page<WaylineJobEntity> pageData = mapper.selectPage( |
| | | new Page<WaylineJobEntity>(page, pageSize), |
| | | new LambdaQueryWrapper<WaylineJobEntity>() |
| | | // 实际开始时间筛选,允许为空,为空则不进行筛选 |
| | | .ge(startTime != null, WaylineJobEntity::getExecuteTime, startTime) |
| | | .le(endTime != null, WaylineJobEntity::getExecuteTime, endTime) |
| | | // 任务类型筛选,允许为空,为空则不进行筛选 |
| | | .eq(taskType != null, WaylineJobEntity::getTaskType, taskType) |
| | | // 任务名称筛选,允许为空,为空则不进行筛选;....模糊查询 |
| | | .like(name != null, WaylineJobEntity::getName, "%"+name+"%") |
| | | // 根据是否完成筛选,允许为空,为空则不进行筛选 |
| | | .eq(isComplete != null && isComplete, WaylineJobEntity::getStatus, 3) |
| | | .ne(isComplete != null && !isComplete, WaylineJobEntity::getStatus, 3) |
| | | // 任务状态筛选,允许为空,为空则不进行筛选 |
| | | .eq(status != null, WaylineJobEntity::getStatus, status) |
| | | .orderByDesc(WaylineJobEntity::getId)); |
| | | List<WaylineJobDTO> records = pageData.getRecords() |
| | | .stream() |
| | | .map(this::entity2Dto) |
| | | .collect(Collectors.toList()); |
| | | |
| | | return new PaginationData<WaylineJobDTO>(records, new Pagination(pageData)); |
| | | } |
| | | |
| | | public List<WaylineJobEntity> selectList(Long taskType, Long executeTime, String parentId) { |
| | | return mapper.selectList(new LambdaQueryWrapper<WaylineJobEntity>() |
| | | .eq(taskType != null,WaylineJobEntity::getTaskType, taskType) |
| | | .ne(WaylineJobEntity::getStatus, WaylineJobStatusEnum.SUCCESS.getVal()) |
| | | .eq(executeTime != null,WaylineJobEntity::getBeginTime, executeTime) |
| | | .eq(parentId != null,WaylineJobEntity::getParentId,parentId) |
| | | .ne(WaylineJobEntity::getStatus, 3) |
| | | .orderByDesc(WaylineJobEntity::getId)); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 根据航班任务ID获取航班任务资源 |
| | | * |
| | | * @param receiver 接收到的消息对象 |
| | | * @param headers 消息头信息 |
| | | * |
| | | * @Override 覆盖父类方法 |
| | | * @ServiceActivator(inputChannel = ChannelName.INBOUND_REQUESTS_FLIGHT_TASK_RESOURCE_GET, outputChannel = ChannelName.OUTBOUND) |
| | | * 指定输入通道和输出通道 |
| | | * 指定输入通道和输出通道 |
| | | * @Transactional(isolation = Isolation.READ_UNCOMMITTED) |
| | | * 设置事务隔离级别为未提交读 |
| | | * 设置事务隔离级别为未提交读 |
| | | */ |
| | | @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() |
| | |
| | | // messageSender.publish(topic, builder.build()); |
| | | // return; |
| | | // } |
| | | // 修改航线文件名称,从ard_route_information航线表中取; |
| | | // 修改航线文件名称,从ard_route_info航线表中取; |
| | | // 换航线表 |
| | | ArdRouteInfo ardRouteOpt = _ardRouteInfoService.selectArdRouteInfoById(waylineJob.getFileId()); |
| | | if (ardRouteOpt == null) { |
| | |
| | | |
| | | // get file url |
| | | URL url = null; |
| | | String minioUrl = subStringMinioUrlName(ardRouteOpt.getUpPath()); |
| | | String minioUrl = subStringMinioUrlName(ardRouteOpt.getPath()); |
| | | String md5 = ""; |
| | | try (InputStream inputStream = _ossService.getObject(kmzPath,minioUrl)) |
| | | { |
| | | try (InputStream inputStream = _ossService.getObject(kmzPath, minioUrl)) { |
| | | md5 = DigestUtils.md5Hex(inputStream); |
| | | url = new URL(ardRouteOpt.getUpPath()); |
| | | url = new URL(ardRouteOpt.getPath()); |
| | | // } |
| | | // try { |
| | | // url = waylineFileService.getObjectUrl(waylineFile.get().getWaylineId()); |
| | |
| | | .rthAltitude(dto.getRthAltitude()) |
| | | .outOfControlAction(dto.getOutOfControlAction()) |
| | | .parentId(dto.getParentId()) |
| | | .loopSum(dto.getLoopSum()) |
| | | .build(); |
| | | } |
| | | |
| | |
| | | if (entity == null) { |
| | | return null; |
| | | } |
| | | // 修改航线文件名称,从ard_route_information航线表中取; |
| | | // 修改航线文件名称,从ard_route_info航线表中取; |
| | | WaylineJobDTO.WaylineJobDTOBuilder builder = WaylineJobDTO.builder() |
| | | .jobId(entity.getJobId()) |
| | | .jobName(entity.getName()) |
| | |
| | | .waylineType(entity.getWaylineType()) |
| | | .rthAltitude(entity.getRthAltitude()) |
| | | .outOfControlAction(entity.getOutOfControlAction()) |
| | | .mediaCount(entity.getMediaCount()); |
| | | .mediaCount(entity.getMediaCount()) |
| | | .loopSum(entity.getLoopSum()); |
| | | |
| | | |
| | | 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(); |
| | | } |
| | | |