guoshilong
2023-11-13 68f80a7451a126335153ec00bb6cb520a5ae1f8d
src/main/java/com/dji/sample/wayline/service/impl/WaylineJobServiceImpl.java
@@ -1,6 +1,7 @@
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;
@@ -283,108 +284,6 @@
            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();
    }
@@ -610,19 +509,7 @@
    @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()
@@ -630,6 +517,18 @@
                .collect(Collectors.toList());
        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;
    }
@@ -796,17 +695,7 @@
    @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;
    }
@@ -860,38 +749,40 @@
        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();
//        //起飞
//        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  {
@@ -900,7 +791,10 @@
        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("该任务不存在");
        }
@@ -915,7 +809,7 @@
        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) {
                //当前索引就是下一次要执行的时间
@@ -923,6 +817,11 @@
                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());
@@ -1002,6 +901,8 @@
        return ResponseResult.success();
    }
    @Override
@@ -1098,7 +999,8 @@
                .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()));