/*
|
* 【机场1】从 dock2 原类 com.ard.web.controller.sample.wayline.WaylineFileController 复制/独立适配(DJI Dock 1 / M30)。
|
* 与 dock2 原类同服务共存;本文件内的适配差异以「// 机场1:」内联注释标出。
|
*/
|
package com.ard.web.controller.sample.dock1.wayline;
|
|
import com.ard.common.constant.HttpStatus;
|
import com.ard.common.core.controller.BaseController;
|
import com.ard.common.core.domain.model.LoginUser;
|
import com.ard.common.core.page.TableDataInfo;
|
import com.ard.common.utils.SecurityUtils;
|
import com.ard.sample.common.model.PaginationData;
|
import com.ard.sample.common.model.ResponseResult;
|
import com.ard.sample.wayline.model.dto.WaylineFileDTO;
|
import com.ard.sample.wayline.model.dto.WaylineFileUploadDTO;
|
import com.ard.sample.wayline.model.param.WaylineQueryParam;
|
import com.ard.sample.dock1.wayline.service.IWaylineFileService;
|
import io.swagger.annotations.Api;
|
import io.swagger.annotations.ApiOperation;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.multipart.MultipartFile;
|
|
import javax.servlet.http.HttpServletResponse;
|
import java.io.IOException;
|
import java.net.URL;
|
import java.sql.SQLException;
|
import java.util.List;
|
import java.util.Objects;
|
import com.ard.web.controller.sample.wayline.WaylineFileController;
|
|
/**
|
* @author sean
|
* @version 0.3
|
* @date 2021/12/22
|
*/
|
@Api(tags="航线管理")
|
@RestController
|
@RequestMapping("/dock1/wayline")
|
public class Dock1WaylineFileController extends BaseController {
|
|
@Autowired
|
private IWaylineFileService waylineFileService;
|
|
/**
|
* Query the basic data of the wayline file according to the query conditions.
|
* The query condition field in pilot is fixed.
|
* @return
|
*/
|
@ApiOperation("查询航线列表")
|
@GetMapping("/list")
|
public TableDataInfo getWaylinesPagination(WaylineQueryParam param) {
|
|
PaginationData<WaylineFileDTO> data = waylineFileService.getWaylinesByParam(param);
|
|
TableDataInfo rspData = new TableDataInfo();
|
rspData.setCode(HttpStatus.SUCCESS);
|
rspData.setMsg("查询成功");
|
rspData.setRows(data.getList());
|
rspData.setTotal(data.getPagination().getTotal());
|
return rspData;
|
}
|
|
/**
|
* Query the download address of the file according to the wayline file id,
|
* and redirect to this address directly for download.
|
* @param waylineId
|
* @param response
|
*/
|
@ApiOperation("下载航线文件")
|
@GetMapping("/download")
|
public void getFileUrl(String waylineId, HttpServletResponse response) {
|
try {
|
URL url = waylineFileService.getObjectUrl(waylineId);
|
response.sendRedirect(url.toString());
|
|
} catch (IOException | SQLException e) {
|
e.printStackTrace();
|
}
|
}
|
|
/**
|
* When the wayline file is uploaded to the storage server by pilot,
|
* the basic information of the file is reported through this interface.
|
* @param uploadFile
|
* @return
|
*/
|
@ApiOperation("上传航线")
|
@PostMapping("/upload")
|
public ResponseResult uploadCallBack(@RequestBody WaylineFileUploadDTO uploadFile) {
|
|
LoginUser loginUser = SecurityUtils.getLoginUser();
|
WaylineFileDTO metadata = uploadFile.getMetadata();
|
metadata.setUsername(loginUser.getUsername());
|
metadata.setObjectKey(uploadFile.getObjectKey());
|
metadata.setName(uploadFile.getName());
|
|
int id = waylineFileService.saveWaylineFile(metadata);
|
|
return id <= 0 ? ResponseResult.error() : ResponseResult.success();
|
}
|
|
/**
|
* Favorite the wayline file according to the wayline file id.
|
* @param ids wayline file id
|
* @return
|
*/
|
@ApiOperation("收藏航线")
|
@PostMapping("/favorites")
|
public ResponseResult markFavorite(@RequestParam(name = "id") List<String> ids) {
|
boolean isMark = waylineFileService.markFavorite(ids, true);
|
|
return isMark ? ResponseResult.success() : ResponseResult.error();
|
}
|
|
/**
|
* Delete the favorites of this wayline file based on the wayline file id.
|
* @param ids wayline file id
|
* @return
|
*/
|
@ApiOperation("取消收藏航线")
|
@DeleteMapping("/favorites")
|
public ResponseResult unmarkFavorite(@RequestParam(name = "id") List<String> ids) {
|
boolean isMark = waylineFileService.markFavorite(ids, false);
|
|
return isMark ? ResponseResult.success() : ResponseResult.error();
|
}
|
|
/**
|
* 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 names
|
* @return
|
*/
|
@ApiOperation("检查航线名称是否重复")
|
@GetMapping("/checkDuplicateNames")
|
public ResponseResult checkDuplicateNames(@RequestParam(name = "name") List<String> names) {
|
List<String> existNamesList = waylineFileService.getDuplicateNames(names);
|
return ResponseResult.success(existNamesList);
|
}
|
|
/**
|
* Delete the wayline file in the workspace according to the wayline id.
|
* @param waylineId
|
* @return
|
*/
|
@ApiOperation("删除航线")
|
@DeleteMapping("/delete/{wayline_id}")
|
public ResponseResult deleteWayline(@PathVariable(name = "wayline_id") String waylineId) {
|
boolean isDel = waylineFileService.deleteByWaylineId(waylineId);
|
return isDel ? ResponseResult.success() : ResponseResult.error("Failed to delete wayline.");
|
}
|
|
/**
|
* Import kmz wayline files.
|
* @param file
|
* @return
|
*/
|
@ApiOperation("导入航线")
|
@PostMapping("/importKmzFile")
|
public ResponseResult importKmzFile(@RequestPart("file") MultipartFile file) {
|
if (Objects.isNull(file)) {
|
return ResponseResult.error("No file received.");
|
}
|
LoginUser loginUser = SecurityUtils.getLoginUser();
|
String creator = loginUser.getUsername();
|
waylineFileService.importKmzFile(file, creator);
|
return ResponseResult.success();
|
}
|
}
|