| | |
| | | package com.dji.sample.wayline.controller; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.dji.sample.common.model.CustomClaim; |
| | | import com.dji.sample.common.model.PaginationData; |
| | | import com.dji.sample.common.model.ResponseResult; |
| | | import com.dji.sample.log.aspect.SysLogAnnotation; |
| | | import com.dji.sample.wayline.dao.IWaylineJobMapper; |
| | | import com.dji.sample.wayline.model.dto.WaylineJobCountDTO; |
| | | import com.dji.sample.wayline.model.dto.WaylineJobDTO; |
| | | import com.dji.sample.wayline.model.param.CreateJobParam; |
| | | import com.dji.sample.wayline.model.entity.WaylineJobEntity; |
| | | import com.dji.sample.wayline.model.param.*; |
| | | import com.dji.sample.wayline.service.IWaylineJobService; |
| | | import com.dji.sample.wayline.service.impl.WaylineJobServiceImpl; |
| | | import com.dji.sample.wayline.util.ErrorCodeUtil; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | |
| | | import javax.validation.Valid; |
| | | import java.sql.SQLException; |
| | | import java.util.List; |
| | | import java.util.Optional; |
| | | import java.util.Set; |
| | | |
| | | import static com.dji.sample.component.AuthInterceptor.TOKEN_CLAIM; |
| | | |
| | |
| | | private IWaylineJobService waylineJobService; |
| | | |
| | | /** |
| | | * Create a wayline task for the Dock. |
| | | * 创建航路任务。 |
| | | * |
| | | * @param request |
| | | * @param param |
| | | * @param workspaceId |
| | |
| | | * @throws SQLException |
| | | */ |
| | | @PostMapping("/{workspace_id}/flight-tasks") |
| | | @SysLogAnnotation(operModul = "计划库", operType = "新增", operDesc = "创建计划") |
| | | public ResponseResult createJob(HttpServletRequest request, @Valid @RequestBody CreateJobParam param, |
| | | @PathVariable(name = "workspace_id") String workspaceId) throws SQLException { |
| | | CustomClaim customClaim = (CustomClaim)request.getAttribute(TOKEN_CLAIM); |
| | | CustomClaim customClaim = (CustomClaim) request.getAttribute(TOKEN_CLAIM); |
| | | customClaim.setWorkspaceId(workspaceId); |
| | | |
| | | return waylineJobService.publishFlightTask(param, customClaim); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Paginate through all jobs in this workspace. |
| | | * 创建航路任务(重复定时和连续执行) |
| | | * |
| | | * @param request |
| | | * @param param |
| | | * @param workspaceId |
| | | * @return |
| | | * @throws SQLException |
| | | */ |
| | | @PostMapping("/{workspace_id}/flight-tasks-condition") |
| | | @SysLogAnnotation(operModul = "计划库", operType = "新增", operDesc = "创建航路任务(重复定时和连续执行)") |
| | | public ResponseResult createJobCondition(HttpServletRequest request, @Valid @RequestBody CreateJobParam param, |
| | | @PathVariable(name = "workspace_id") String workspaceId) throws SQLException { |
| | | CustomClaim customClaim = (CustomClaim) request.getAttribute(TOKEN_CLAIM); |
| | | customClaim.setWorkspaceId(workspaceId); |
| | | |
| | | return waylineJobService.publishFlightTaskCondition(param, customClaim); |
| | | } |
| | | |
| | | /** |
| | | * 断点任务 |
| | | * |
| | | * @return |
| | | */ |
| | | @PostMapping("/{workspace_id}/breakpoint-tasks") |
| | | @SysLogAnnotation(operModul = "计划库", operType = "断点续飞", operDesc = "创建航路任务(重复定时和连续执行)") |
| | | public ResponseResult breakPointJob(HttpServletRequest request, @Valid @RequestBody BreakPointJobParam param, |
| | | @PathVariable(name = "workspace_id") String workspaceId) throws SQLException { |
| | | Optional<WaylineJobDTO> waylineJobDTO = waylineJobService.getJobByJobId(workspaceId, param.getJobId(), param.isBreakPoint()); |
| | | return waylineJobService.publishOneFlightTask(waylineJobDTO.get()); |
| | | } |
| | | |
| | | /** |
| | | * 分页查询 |
| | | * |
| | | * @param page |
| | | * @param pageSize |
| | | * @param workspaceId |
| | | * @return |
| | | */ |
| | | @GetMapping("/{workspace_id}/jobs") |
| | | @SysLogAnnotation(operModul = "计划库", operType = "查询", operDesc = "分页查询") |
| | | public ResponseResult<PaginationData<WaylineJobDTO>> getJobs(@RequestParam(defaultValue = "1") Long page, |
| | | @RequestParam(name = "page_size", defaultValue = "10") Long pageSize, |
| | | @PathVariable(name = "workspace_id") String workspaceId) { |
| | | PaginationData<WaylineJobDTO> data = waylineJobService.getJobsByWorkspaceId(workspaceId, page, pageSize); |
| | | @RequestParam(name = "page_size", defaultValue = "10") Long pageSize, |
| | | @PathVariable(name = "workspace_id") String workspaceId, WaylineJobQueryParam waylineJobQueryParam) { |
| | | PaginationData<WaylineJobDTO> data = waylineJobService.getJobsByWorkspaceId(workspaceId, page, pageSize, waylineJobQueryParam); |
| | | return ResponseResult.success(data); |
| | | } |
| | | |
| | | @GetMapping("/{workspace_id}/jobs-dp") |
| | | @SysLogAnnotation(operModul = "计划库", operType = "查询", operDesc = "分页查询") |
| | | public ResponseResult<PaginationData<WaylineJobDTO>> getJobsByState(@RequestParam(defaultValue = "1") Long page, |
| | | @RequestParam(name = "page_size", defaultValue = "10") Long pageSize, |
| | | @PathVariable(name = "workspace_id") String workspaceId, |
| | | @RequestParam(name = "order", defaultValue = "") String order, |
| | | WaylineJobQueryParam waylineJobQueryParam) { |
| | | PaginationData<WaylineJobDTO> data = waylineJobService.getJobsByWorkspaceIdNew(workspaceId, page, pageSize, waylineJobQueryParam, order); |
| | | return ResponseResult.success(data); |
| | | } |
| | | |
| | | /** |
| | | * Send the command to cancel the jobs. |
| | | * 子查询 |
| | | * |
| | | * @param workspaceId |
| | | * @return |
| | | */ |
| | | @GetMapping("/{workspace_id}/getChildrenJobs") |
| | | @SysLogAnnotation(operModul = "计划库", operType = "查询", operDesc = "分页查询") |
| | | public ResponseResult<List<WaylineJobDTO>> getChildrenJobs( |
| | | @PathVariable(name = "workspace_id") String workspaceId, WaylineJobQueryParam waylineJobQueryParam) { |
| | | List<WaylineJobDTO> data = waylineJobService.getChildrenJobs(workspaceId, waylineJobQueryParam); |
| | | return ResponseResult.success(data); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 查询最新的记录 |
| | | * |
| | | * @return |
| | | */ |
| | | @GetMapping("/{workspace_id}/latestJob") |
| | | public ResponseResult<WaylineJobEntity> getLatestJobs(@PathVariable(name = "workspace_id") String workspaceId, WaylineJobQueryParam waylineJobQueryParam) { |
| | | |
| | | WaylineJobEntity waylineJobEntity = waylineJobService.getLatestJob(workspaceId, waylineJobQueryParam); |
| | | |
| | | return ResponseResult.success(waylineJobEntity); |
| | | } |
| | | |
| | | @GetMapping("/code") |
| | | public ResponseResult errotCode(@RequestParam Integer code) { |
| | | return ResponseResult.success(ErrorCodeUtil.codeToReason(code)); |
| | | } |
| | | |
| | | /** |
| | | * 发送命令取消作业。 |
| | | * |
| | | * @param jobIds |
| | | * @param workspaceId |
| | | * @return |
| | | * @throws SQLException |
| | | */ |
| | | @DeleteMapping("/{workspace_id}/jobs") |
| | | public ResponseResult publishCancelJob(@RequestParam(name = "job_id") List<String> jobIds, |
| | | @PathVariable(name = "workspace_id") String workspaceId) throws SQLException { |
| | | @SysLogAnnotation(operModul = "计划库", operType = "删除", operDesc = "发送命令取消作业") |
| | | public ResponseResult publishCancelJob(@RequestParam(name = "job_id") Set<String> jobIds, |
| | | @PathVariable(name = "workspace_id") String workspaceId) throws SQLException { |
| | | waylineJobService.cancelFlightTask(workspaceId, jobIds); |
| | | return ResponseResult.success(); |
| | | } |
| | | |
| | | /** |
| | | * Set the media files for this job to upload immediately. |
| | | * 将此作业的媒体文件设置为立即上传。 |
| | | * |
| | | * @param workspaceId |
| | | * @param jobId |
| | | * @return |
| | | */ |
| | | @PostMapping("/{workspace_id}/jobs/{job_id}/media-highest") |
| | | @SysLogAnnotation(operModul = "计划库", operType = "修改", operDesc = "将此作业的媒体文件设置为立即上传") |
| | | public ResponseResult uploadMediaHighestPriority(@PathVariable(name = "workspace_id") String workspaceId, |
| | | @PathVariable(name = "job_id") String jobId) { |
| | | @PathVariable(name = "job_id") String jobId) { |
| | | waylineJobService.uploadMediaHighestPriority(workspaceId, jobId); |
| | | return ResponseResult.success(); |
| | | } |
| | | |
| | | @PutMapping("/{workspace_id}/jobs/{job_id}") |
| | | @SysLogAnnotation(operModul = "计划库", operType = "修改", operDesc = "修改") |
| | | public ResponseResult updateJobStatus(@PathVariable(name = "workspace_id") String workspaceId, |
| | | @PathVariable(name = "job_id") String jobId, |
| | | @Valid @RequestBody UpdateJobParam param) { |
| | | waylineJobService.updateJobStatus(workspaceId, jobId, param); |
| | | return ResponseResult.success(); |
| | | } |
| | | |
| | | /** |
| | | * 统计飞行次数 |
| | | */ |
| | | @PostMapping("/{workspace_id}/patrol_statistics") |
| | | public ResponseResult<WaylineJobCountDTO> patrolStatistics(@PathVariable(name = "workspace_id") String workspaceId, String queryTime, String deviceSn) { |
| | | |
| | | WaylineJobCountDTO waylineJobCountDTO = waylineJobService.patrolStatistics(workspaceId, queryTime, deviceSn); |
| | | |
| | | return ResponseResult.success(waylineJobCountDTO); |
| | | } |
| | | @GetMapping("/idToName") |
| | | public ResponseResult findName(@RequestParam String jobid) { |
| | | return ResponseResult.success(waylineJobService.getName(jobid)); |
| | | } |
| | | |
| | | /** |
| | | * 收藏媒体库 |
| | | */ |
| | | @PostMapping("/update_job_collect") |
| | | public ResponseResult updateJobCollect(HttpServletRequest request, @RequestBody WaylineJobEntity waylineJob) { |
| | | CustomClaim claims = (CustomClaim) request.getAttribute(TOKEN_CLAIM); |
| | | waylineJob.setUserId(claims.getId()); |
| | | waylineJobService.updateJobCollect(waylineJob); |
| | | |
| | | return ResponseResult.success(); |
| | | } |
| | | |
| | | /** |
| | | * 根据区域飞行 |
| | | * |
| | | * @return |
| | | */ |
| | | @PostMapping("/{sn}/jobs/{device_sn}/flyByArea") |
| | | @SysLogAnnotation(operModul = "根据区域飞行", operType = "根据区域飞行", operDesc = "根据区域飞行") |
| | | public ResponseResult flyByArea(@PathVariable(name = "sn") String sn, @RequestBody FlyAreaParam flyAreaParam, @PathVariable(name = "device_sn") String deviceSn) throws Exception { |
| | | return waylineJobService.flyByArea(sn, flyAreaParam, deviceSn); |
| | | } |
| | | } |