rain
2024-06-14 8d9a2d656e4ae007590c622e5f7c228adacdca49
src/main/java/com/dji/sample/wayline/controller/WaylineFileController.java
@@ -3,11 +3,16 @@
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.common.util.MinioUrlUtils;
import com.dji.sample.log.aspect.SysLogAnnotation;
import com.dji.sample.wayline.model.dto.WaylineFileDTO;
import com.dji.sample.wayline.model.dto.WaylineFileUploadDTO;
import com.dji.sample.wayline.model.dto.WaylineListDTO;
import com.dji.sample.wayline.model.entity.WaylineFileEntity;
import com.dji.sample.wayline.model.param.WaylineQueryParam;
import com.dji.sample.wayline.service.IWaylineFileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
@@ -34,10 +39,10 @@
    private IWaylineFileService waylineFileService;
    /**
     * Query the basic data of the wayline file according to the query conditions.
     * The query condition field in pilot is fixed.
     * @param orderBy   Sorted fields. Spliced at the end of the sql statement.
     * @param favorited Whether the wayline file is favorited or not.
     * 根据查询条件查询航路线文件的基本数据。
     * pilot中的查询条件字段是固定的。
     * @param orderBy   排序的字段。在sql语句的末尾拼接。
     * @param favorited 路径线文件是否为收藏夹。
     * @param page
     * @param pageSize
     * @param templateType
@@ -45,6 +50,7 @@
     * @return
     */
    @GetMapping("/{workspace_id}/waylines")
    @SysLogAnnotation(operModul = "航线库", operType = "查询", operDesc = "根据查询条件查询航路线文件的基本数据")
    public ResponseResult<PaginationData<WaylineFileDTO>> getWaylinesPagination(@RequestParam(name = "order_by") String orderBy,
                                      @RequestParam(required = false) boolean favorited, @RequestParam Integer page,
                                      @RequestParam(name = "page_size", defaultValue = "10") Integer pageSize,
@@ -62,34 +68,50 @@
    }
    /**
     * Query the download address of the file according to the wayline file id,
     * and redirect to this address directly for download.
     * 根据wayline文件id查询文件的下载地址;
     * 和重定向到此地址直接下载。
     * @param workspaceId
     * @param waylineId
     * @param response
     */
    @GetMapping("/{workspace_id}/waylines/{wayline_id}/url")
    @SysLogAnnotation(operModul = "航线库", operType = "查询", operDesc = "根据wayline文件id查询文件的下载地址1")
    public void getFileUrl(@PathVariable(name = "workspace_id") String workspaceId,
                                @PathVariable(name = "wayline_id") String waylineId, HttpServletResponse response) {
        try {
            URL url = waylineFileService.getObjectUrl(workspaceId, waylineId);
            response.sendRedirect(url.toString());
            response.sendRedirect(MinioUrlUtils.getUrl(url));
        } catch (IOException | SQLException e) {
            e.printStackTrace();
        }
    }
    @GetMapping("/{workspace_id}/waylines/{wayline_id}/urlData")
    @SysLogAnnotation(operModul = "航线库", operType = "查询", operDesc = "根据wayline文件id查询文件的下载地址2")
    public ResponseResult getFileUrlData(@PathVariable(name = "workspace_id") String workspaceId,
                           @PathVariable(name = "wayline_id") String waylineId, HttpServletResponse response) {
        URL url = null;
        try {
            url = waylineFileService.getObjectUrl(workspaceId, waylineId);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
        return ResponseResult.success(MinioUrlUtils.getUrl(url));
    }
    /**
     * When the wayline file is uploaded to the storage server by pilot,
     * the basic information of the file is reported through this interface.
     * 当航路线文件被飞行员上传到存储服务器时,
     * 通过该接口报告文件的基本信息。
     * @param request
     * @param workspaceId
     * @param uploadFile
     * @return
     */
    @PostMapping("/{workspace_id}/upload-callback")
    @SysLogAnnotation(operModul = "航线库", operType = "新增", operDesc = "当航路线文件被飞行员上传到存储服务器时,通过该接口报告文件的基本信息")
    public ResponseResult uploadCallBack(HttpServletRequest request,
                                         @PathVariable(name = "workspace_id") String workspaceId,
                                         @RequestBody WaylineFileUploadDTO uploadFile) {
@@ -107,12 +129,13 @@
    }
    /**
     * Favorite the wayline file according to the wayline file id.
     * 根据路径线文件id收藏路径线文件。
     * @param workspaceId
     * @param ids   wayline file id
     * @return
     */
    @PostMapping("/{workspace_id}/favorites")
    @SysLogAnnotation(operModul = "航线库", operType = "修改", operDesc = "根据路径线文件id收藏路径线文件")
    public ResponseResult markFavorite(@PathVariable(name = "workspace_id") String workspaceId,
                             @RequestParam(name = "id") List<String> ids) {
        boolean isMark = waylineFileService.markFavorite(workspaceId, ids, true);
@@ -121,12 +144,13 @@
    }
    /**
     * Delete the favorites of this wayline file based on the wayline file id.
     * 根据航路线文件id删除此航路线文件的收藏夹。
     * @param workspaceId
     * @param ids wayline file id
     * @return
     */
    @DeleteMapping("/{workspace_id}/favorites")
    @SysLogAnnotation(operModul = "航线库", operType = "删除", operDesc = "根据航路线文件id删除此航路线文件的收藏夹")
    public ResponseResult unmarkFavorite(@PathVariable(name = "workspace_id") String workspaceId,
                             @RequestParam(name = "id") List<String> ids) {
        boolean isMark = waylineFileService.markFavorite(workspaceId, ids, false);
@@ -135,13 +159,14 @@
    }
    /**
     * Checking whether the name already exists according to the wayline name must ensure the uniqueness of the wayline name.
     * This interface will be called when uploading waylines and must be available.
     * 根据航路线名称检查名称是否已经存在,必须保证航路线名称的唯一性。
     * 此接口将在上传航路线时被调用,并且必须可用。
     * @param workspaceId
     * @param names
     * @return
     */
    @GetMapping("/{workspace_id}/waylines/duplicate-names")
    @SysLogAnnotation(operModul = "航线库", operType = "查询", operDesc = "根据航路线名称检查名称是否已经存在")
    public ResponseResult checkDuplicateNames(@PathVariable(name = "workspace_id") String workspaceId,
                                              @RequestParam(name = "name") List<String> names) {
        List<String> existNamesList = waylineFileService.getDuplicateNames(workspaceId, names);
@@ -150,32 +175,53 @@
    }
    /**
     * Delete the wayline file in the workspace according to the wayline id.
     * 根据航路线id删除工作区中的航路线文件。
     * @param workspaceId
     * @param waylineId
     * @return
     */
    @DeleteMapping("/{workspace_id}/waylines/{wayline_id}")
    @SysLogAnnotation(operModul = "航线库", operType = "删除", operDesc = "根据航路线id删除工作区中的航路线文件")
    public ResponseResult deleteWayline(@PathVariable(name = "workspace_id") String workspaceId,
                                        @PathVariable(name = "wayline_id") String waylineId) {
        boolean isDel = waylineFileService.deleteByWaylineId(workspaceId, waylineId);
        return isDel ? ResponseResult.success() : ResponseResult.error("Failed to delete wayline.");
        return isDel ? ResponseResult.success() : ResponseResult.error("航线删除失败");
    }
    /**
     * Import kmz wayline files.
     * 上传kmz航线文件
     * @param file
     * @return
     */
    @PostMapping("/{workspace_id}/waylines/file/upload")
    public ResponseResult importKmzFile(HttpServletRequest request, MultipartFile file) {
    @SysLogAnnotation(operModul = "航线库", operType = "上传", operDesc = "上传kmz航线文件")
    public ResponseResult importKmzFile(@PathVariable(name = "workspace_id") String workspaceId,
                                        HttpServletRequest request, MultipartFile file,
                                        @RequestParam(required = false) String patchesId) {
        if (Objects.isNull(file)) {
            return ResponseResult.error("No file received.");
            return ResponseResult.error("未上传文件");
        }
        CustomClaim customClaim = (CustomClaim)request.getAttribute(TOKEN_CLAIM);
        String workspaceId = customClaim.getWorkspaceId();
        String creator = customClaim.getUsername();
        waylineFileService.importKmzFile(file, workspaceId, creator);
        waylineFileService.importKmzFile(file, workspaceId, creator,patchesId);
        return ResponseResult.success();
    }
    @GetMapping("/{workspace_id}/waylines_list")
    @SysLogAnnotation(operModul = "航线库", operType = "查询", operDesc = "查询当前工作区航线库列表")
    public ResponseResult<List<WaylineListDTO>> waylineList(@PathVariable(name = "workspace_id") String workspaceId,String droneName) {
        return ResponseResult.success(waylineFileService.waylineList(workspaceId,droneName)) ;
    }
    @PutMapping("/{workspace_id}/wayline_update")
    public ResponseResult upWayline(@RequestParam String waylineId,@RequestParam String name){
        WaylineFileEntity entity=WaylineFileEntity
                .builder()
                .waylineId(waylineId)
                .name(name)
                .build();
        if(waylineFileService.updateWayline(entity)==0){
            return ResponseResult.error("更新失败");
        }else return ResponseResult.success();
    }
}