| | |
| | | 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.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.wayline.service.IWaylineJobBreakPointService; |
| | | import com.dji.sample.wayline.service.IWaylineJobService; |
| | | import com.dji.sample.wayline.service.IWaylineRedisService; |
| | | import com.dji.sample.wayline.util.ErrorCodeUtil; |
| | | import com.fasterxml.jackson.core.type.TypeReference; |
| | | import com.fasterxml.jackson.databind.ObjectMapper; |
| | | import lombok.extern.slf4j.Slf4j; |
| | |
| | | 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.*; |
| | | import java.util.*; |
| | | import java.util.concurrent.ConcurrentHashMap; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import static com.dji.sample.component.mqtt.model.TopicConst.*; |
| | | import static com.dji.sample.component.mqtt.model.TopicConst._REPLY_SUF; |
| | | |
| | | /** |
| | | * @author sean |
| | |
| | | if (Objects.isNull(param)) { |
| | | return Optional.empty(); |
| | | } |
| | | if (param.getJobId()!=null){ |
| | | WaylineJobEntity jobEntity = WaylineJobEntity.builder() |
| | | .name(param.getName()) |
| | | .dockSn(param.getDockSn()) |
| | | .fileId(param.getFileId()) |
| | | .username(username) |
| | | .workspaceId(workspaceId) |
| | | .jobId(param.getJobId()) |
| | | .beginTime(beginTime) |
| | | .endTime(endTime) |
| | | .status(WaylineJobStatusEnum.PENDING.getVal()) |
| | | .taskType(param.getTaskType().getVal()) |
| | | .waylineType(param.getWaylineType().getVal()) |
| | | .outOfControlAction(param.getOutOfControlAction()) |
| | | .rthAltitude(param.getRthAltitude()) |
| | | .rthMode(param.getRthMode()) |
| | | .mediaCount(0) |
| | | .build(); |
| | | if (StringUtils.hasText(param.getJobId())) { |
| | | jobEntity.setJobId(param.getJobId()); |
| | | } |
| | | return insertWaylineJob(jobEntity); |
| | | } |
| | | // Immediate tasks, allocating time on the backend. |
| | | WaylineJobEntity jobEntity = WaylineJobEntity.builder() |
| | | .name(param.getName()) |
| | |
| | | .waylineType(param.getWaylineType().getVal()) |
| | | .outOfControlAction(param.getOutOfControlAction()) |
| | | .rthAltitude(param.getRthAltitude()) |
| | | .rthMode(param.getRthMode()) |
| | | .mediaCount(0) |
| | | .build(); |
| | | if (StringUtils.hasText(param.getJobId())){ |
| | | if (StringUtils.hasText(param.getJobId())) { |
| | | jobEntity.setJobId(param.getJobId()); |
| | | } |
| | | return insertWaylineJob(jobEntity); |
| | |
| | | jobEntity.setParentId(parentId); |
| | | |
| | | return this.insertWaylineJob(jobEntity); |
| | | } |
| | | @Override |
| | | public String getWaylineId(String jobId){ |
| | | WaylineJobEntity waylineJob=mapper.selectOne(new LambdaQueryWrapper<WaylineJobEntity>().select(WaylineJobEntity::getFileId).eq(WaylineJobEntity::getJobId,jobId)); |
| | | return waylineJob.getFileId(); |
| | | } |
| | | |
| | | /** |
| | |
| | | .taskType(waylineJob.getTaskType()) |
| | | .waylineType(waylineJob.getWaylineType()) |
| | | .rthAltitude(waylineJob.getRthAltitude()) |
| | | .rthMode(waylineJob.getRthMode()) |
| | | .outOfControlAction(waylineJob.getOutOfControlAction()) |
| | | .file(WaylineTaskFileDTO.builder() |
| | | .url(MinioUrlUtils.getUrl(url)) |
| | |
| | | } |
| | | |
| | | @Override |
| | | public Optional<WaylineJobDTO> getJobByJobId(String workspaceId, String jobId,Boolean isBreakPoint) { |
| | | public Optional<WaylineJobDTO> getJobByJobId(String workspaceId, String jobId, Boolean isBreakPoint) { |
| | | WaylineJobEntity jobEntity = mapper.selectOne( |
| | | new LambdaQueryWrapper<WaylineJobEntity>() |
| | | .eq(WaylineJobEntity::getWorkspaceId, workspaceId) |
| | |
| | | |
| | | @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); |
| | | Page<WaylineJobEntity> pageData = mapper.getPageNew(new Page<WaylineJobEntity>(page, pageSize), waylineJobQueryParam, workspaceId, order); |
| | | |
| | | List<WaylineJobDTO> records = pageData.getRecords() |
| | | .stream() |
| | |
| | | |
| | | // 是否需要断点续飞 |
| | | records.forEach(wjd -> wjd.setBreakPoint(waylineJobBreakPointService.count( |
| | | new LambdaQueryWrapper<WaylineJobBreakPointEntity>().eq(WaylineJobBreakPointEntity::getJobId,wjd.getJobId())) > 0)); |
| | | new LambdaQueryWrapper<WaylineJobBreakPointEntity>().eq(WaylineJobBreakPointEntity::getJobId, wjd.getJobId())) > 0)); |
| | | |
| | | |
| | | return new PaginationData<WaylineJobDTO>(records, new Pagination(pageData)); |
| | |
| | | messageSender.publish(topic, builder.build()); |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 机场的获取离线地图协议请求回复 |
| | | * @param receiver |
| | | */ |
| | | @ServiceActivator(inputChannel = ChannelName.INBOUND_REQUESTS_OFFLINE_MAP_GET, outputChannel = ChannelName.OUTBOUND) |
| | | public void offlineMapGet(CommonTopicReceiver receiver) { |
| | | log.info("接收到机场的获取离线地图协议消息,编号:{}",receiver.getGateway()); |
| | | // 查询在线设备,不存在就不发送了 |
| | | Optional<DeviceDTO> deviceOpt = deviceRedisService.getDeviceOnline(receiver.getGateway()); |
| | | if (deviceOpt.isEmpty()) { |
| | | return; |
| | | } |
| | | // 组装数据 |
| | | CommonTopicResponse<Object> builder = CommonTopicResponse.builder() |
| | | .tid(receiver.getTid()) |
| | | .bid(receiver.getBid()) |
| | | .method(RequestsMethodEnum.OFFLINE_MAP_GET.getMethod()) |
| | | .timestamp(System.currentTimeMillis()) |
| | | .build(); |
| | | // 组装 data 数据 |
| | | Map<String, Integer> result = new ConcurrentHashMap<>(1); |
| | | result.put("result", 0); |
| | | builder.setData(result); |
| | | log.info("回复机场的获取离线地图协议消息:{},{}",BASIC_PRE + PRODUCT +receiver.getGateway() + REQUESTS_SUF + _REPLY_SUF, builder ); |
| | | // 回复消息 |
| | | messageSender.publish( |
| | | new StringBuilder() |
| | | .append(THING_MODEL_PRE) |
| | | .append(PRODUCT) |
| | | .append(receiver.getGateway()) |
| | | .append(REQUESTS_SUF) |
| | | .append(_REPLY_SUF) |
| | | .toString(), |
| | | builder); |
| | | } |
| | | |
| | | /** |
| | | * 自定义飞行区文件获取协议请求回复 |
| | | * @param receiver |
| | | */ |
| | | @ServiceActivator(inputChannel = ChannelName.INBOUND_REQUESTS_FLIGHT_AREAS_GET, outputChannel = ChannelName.OUTBOUND) |
| | | public void flightAreasGet(CommonTopicReceiver receiver) { |
| | | log.info("接收到自定义飞行区文件获取消息,编号:{}",receiver.getGateway()); |
| | | // 查询在线设备,不存在就不发送了 |
| | | Optional<DeviceDTO> deviceOpt = deviceRedisService.getDeviceOnline(receiver.getGateway()); |
| | | if (deviceOpt.isEmpty()) { |
| | | return; |
| | | } |
| | | // 组装数据 |
| | | CommonTopicResponse<Object> builder = CommonTopicResponse.builder() |
| | | .tid(receiver.getTid()) |
| | | .bid(receiver.getBid()) |
| | | .method(RequestsMethodEnum.FLIGHT_AREAS_GET.getMethod()) |
| | | .timestamp(System.currentTimeMillis()) |
| | | .build(); |
| | | // 组装 data 数据 |
| | | Map<String, Integer> result = new ConcurrentHashMap<>(1); |
| | | result.put("result", 0); |
| | | builder.setData(result); |
| | | log.info("回复自定义飞行区文件获取消息:{},{}",BASIC_PRE + PRODUCT +receiver.getGateway() + REQUESTS_SUF + _REPLY_SUF, builder ); |
| | | // 回复消息 |
| | | messageSender.publish( |
| | | new StringBuilder() |
| | | .append(THING_MODEL_PRE) |
| | | .append(PRODUCT) |
| | | .append(receiver.getGateway()) |
| | | .append(REQUESTS_SUF) |
| | | .append(_REPLY_SUF) |
| | | .toString(), |
| | | builder); |
| | | } |
| | | |
| | | @Override |
| | | public List<String> selectJobIdByName(String name) { |
| | | List<WaylineJobEntity> waylineJobs = mapper.selectList(new LambdaQueryWrapper<WaylineJobEntity>() |
| | | .select(WaylineJobEntity::getJobId) |
| | | .like(WaylineJobEntity::getName, name)); |
| | | return waylineJobs.stream() |
| | | .map(WaylineJobEntity::getJobId) |
| | | .collect(Collectors.toList()); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public void uploadMediaHighestPriority(String workspaceId, String jobId) { |
| | |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public List<String> getJobNamesByPartialName(String partialJobName) { |
| | | LambdaQueryWrapper<WaylineJobEntity> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.like(WaylineJobEntity::getName, partialJobName); |
| | | return mapper.selectList(queryWrapper).stream() |
| | | .map(WaylineJobEntity::getName) |
| | | .collect(Collectors.toList()); |
| | | } |
| | | |
| | | public WaylineJobStatusEnum getWaylineState(String dockSn) { |
| | | Optional<DeviceDTO> dockOpt = deviceRedisService.getDeviceOnline(dockSn); |
| | | if (dockOpt.isEmpty() || !StringUtils.hasText(dockOpt.get().getChildDeviceSn())) { |
| | |
| | | } |
| | | return WaylineJobStatusEnum.UNKNOWN; |
| | | } |
| | | |
| | | @Override |
| | | public String getName(String jobId) { |
| | | WaylineJobEntity entity = mapper.selectOne( |
| | | new LambdaQueryWrapper<WaylineJobEntity>() |
| | | .select(WaylineJobEntity::getName) |
| | | .eq(WaylineJobEntity::getJobId, jobId) |
| | | ); |
| | | return entity != null ? entity.getName() : null; |
| | | } |
| | | |
| | | @Override |
| | | public List<String> getJobIds(String jobNames) { |
| | | List<String> names = getJobNamesByPartialName(jobNames); |
| | | |
| | | // 如果 names 列表为空,直接返回空的 jobIdStringList |
| | | if (names.isEmpty()) { |
| | | return new ArrayList<>(); |
| | | } |
| | | |
| | | // 使用 LambdaQueryWrapper 进行查询 |
| | | List<Object> jobIdList = mapper.selectObjs( |
| | | new LambdaQueryWrapper<WaylineJobEntity>() |
| | | .select(WaylineJobEntity::getJobId) |
| | | .in(WaylineJobEntity::getName, names) // 使用 IN 子句 |
| | | ); |
| | | |
| | | // 将 Object 类型的 jobId 转换为 String 类型,并放入 List<String> 中 |
| | | List<String> jobIdStringList = new ArrayList<>(); |
| | | for (Object jobIdObj : jobIdList) { |
| | | jobIdStringList.add(String.valueOf(jobIdObj)); |
| | | } |
| | | return jobIdStringList; |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public WaylineJobEntity getLatestJob(String workspaceId, WaylineJobQueryParam waylineJobQueryParam) { |
| | |
| | | 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); |
| | | jsonObject.put("targetList", targetList); |
| | | jsonObject.put("payloadIndex", flyAreaParam.getPayloadIndex()); |
| | | jsonObject.put("curIndex", 0); |
| | | RedisOpsUtils.set("tuban:" + sn, jsonObject); |
| | | } |
| | | break; |
| | | } |
| | |
| | | |
| | | |
| | | @Override |
| | | public WaylineJobCountDTO patrolStatistics(String workspaceId, String queryTime,String deviceSn) { |
| | | public WaylineJobCountDTO patrolStatistics(String workspaceId, String queryTime, String deviceSn) { |
| | | WaylineJobCountDTO waylineJobCountDTO = new WaylineJobCountDTO(); |
| | | List<DroneFlightLogEntity> list = flightLogMapper.patrolStatistics(workspaceId,queryTime,deviceSn); |
| | | List<DroneFlightLogEntity> list = flightLogMapper.patrolStatistics(workspaceId, queryTime, deviceSn); |
| | | if (!CollectionUtils.isEmpty(list)) { |
| | | waylineJobCountDTO.setTotalNumber(list.size()); |
| | | long totalTime = list.stream().filter(task -> task.getEndTime()!= null && task.getStartTime()!= null).mapToLong(s -> s.getEndTime() - s.getStartTime()).sum() / 1000; |
| | | 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; |
| | | waylineJobCountDTO.setTotalDuration( String.format("%02d h %02d min", h, m)); |
| | | 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; |
| | | if (totalFlightDistance != null) { |
| | | sum += totalFlightDistance; |
| | | } |
| | | } |
| | | waylineJobCountDTO.setTotalDistance((int) sum); |
| | |
| | | |
| | | WaylineJobDTO.WaylineJobDTOBuilder builder = WaylineJobDTO.builder() |
| | | .jobId(entity.getJobId()) |
| | | .reason(ErrorCodeUtil.codeToReason(entity.getErrorCode())) |
| | | .jobName(entity.getName()) |
| | | .fileId(entity.getFileId()) |
| | | .fileName(waylineFileService.getWaylineByWaylineId(entity.getWorkspaceId(), entity.getFileId()) |
| | |
| | | .taskType(WaylineTaskTypeEnum.find(entity.getTaskType())) |
| | | .waylineType(WaylineTemplateTypeEnum.find(entity.getWaylineType())) |
| | | .rthAltitude(entity.getRthAltitude()) |
| | | .rthMode(entity.getRthMode()) |
| | | .outOfControlAction(entity.getOutOfControlAction()) |
| | | .mediaCount(entity.getMediaCount()) |
| | | .hasChildren(entity.getHasChildren()); |