From a0ae2cb2fe95630bb13795b94dd5f2cfadea7a97 Mon Sep 17 00:00:00 2001
From: guoshilong <123456>
Date: Sat, 07 Oct 2023 14:28:47 +0800
Subject: [PATCH] 高德地图api接口请求
---
src/main/java/com/dji/sample/wayline/service/impl/WaylineFileServiceImpl.java | 39 +++++++++++++++++++--------------------
1 files changed, 19 insertions(+), 20 deletions(-)
diff --git a/src/main/java/com/dji/sample/wayline/service/impl/WaylineFileServiceImpl.java b/src/main/java/com/dji/sample/wayline/service/impl/WaylineFileServiceImpl.java
index 7502950..8267a90 100644
--- a/src/main/java/com/dji/sample/wayline/service/impl/WaylineFileServiceImpl.java
+++ b/src/main/java/com/dji/sample/wayline/service/impl/WaylineFileServiceImpl.java
@@ -12,6 +12,7 @@
import com.dji.sample.wayline.model.dto.KmzFileProperties;
import com.dji.sample.wayline.model.dto.WaylineFileDTO;
import com.dji.sample.wayline.model.entity.WaylineFileEntity;
+import com.dji.sample.wayline.model.enums.WaylineTemplateTypeEnum;
import com.dji.sample.wayline.model.param.WaylineQueryParam;
import com.dji.sample.wayline.service.IWaylineFileService;
import org.dom4j.Document;
@@ -53,9 +54,6 @@
@Autowired
private OssServiceContext ossService;
- @Autowired
- private OssConfiguration configuration;
-
@Override
public PaginationData<WaylineFileDTO> getWaylinesByParam(String workspaceId, WaylineQueryParam param) {
// Paging Query
@@ -95,9 +93,9 @@
public URL getObjectUrl(String workspaceId, String waylineId) throws SQLException {
Optional<WaylineFileDTO> waylineOpt = this.getWaylineByWaylineId(workspaceId, waylineId);
if (waylineOpt.isEmpty()) {
- throw new SQLException(waylineId + " does not exist.");
+ throw new SQLException(waylineId + " 不存在");
}
- return ossService.getObjectUrl(configuration.getBucket(), waylineOpt.get().getObjectKey());
+ return ossService.getObjectUrl(OssConfiguration.bucket, waylineOpt.get().getObjectKey());
}
@Override
@@ -107,10 +105,10 @@
file.setWorkspaceId(workspaceId);
if (!StringUtils.hasText(file.getSign())) {
- try (InputStream object = ossService.getObject(configuration.getBucket(), metadata.getObjectKey())) {
+ try (InputStream object = ossService.getObject(OssConfiguration.bucket, metadata.getObjectKey())) {
if (object.available() == 0) {
- throw new RuntimeException("The file " + metadata.getObjectKey() +
- " does not exist in the bucket[" + configuration.getBucket() + "].");
+ throw new RuntimeException("文件" + metadata.getObjectKey() +
+ " 在空间中不存在[" + OssConfiguration.bucket + "].");
}
file.setSign(DigestUtils.md5DigestAsHex(object));
} catch (IOException e) {
@@ -159,14 +157,14 @@
if (!isDel) {
return false;
}
- return ossService.deleteObject(configuration.getBucket(), wayline.getObjectKey());
+ return ossService.deleteObject(OssConfiguration.bucket, wayline.getObjectKey());
}
@Override
public void importKmzFile(MultipartFile file, String workspaceId, String creator) {
Optional<WaylineFileDTO> waylineFileOpt = validKmzFile(file);
if (waylineFileOpt.isEmpty()) {
- throw new RuntimeException("The file format is incorrect.");
+ throw new RuntimeException("文件格式错误");
}
try {
@@ -174,7 +172,7 @@
waylineFile.setWaylineId(workspaceId);
waylineFile.setUsername(creator);
- ossService.putObject(configuration.getBucket(), waylineFile.getObjectKey(), file.getInputStream());
+ ossService.putObject(OssConfiguration.bucket, waylineFile.getObjectKey(), file.getInputStream());
this.saveWaylineFile(workspaceId, waylineFile);
} catch (IOException e) {
e.printStackTrace();
@@ -184,13 +182,13 @@
private Optional<WaylineFileDTO> validKmzFile(MultipartFile file) {
String filename = file.getOriginalFilename();
if (Objects.nonNull(filename) && !filename.endsWith(WAYLINE_FILE_SUFFIX)) {
- throw new RuntimeException("The file format is incorrect.");
+ throw new RuntimeException("文件格式错误");
}
try (ZipInputStream unzipFile = new ZipInputStream(file.getInputStream(), StandardCharsets.UTF_8)) {
ZipEntry nextEntry = unzipFile.getNextEntry();
while (Objects.nonNull(nextEntry)) {
- boolean isWaylines = (KmzFileProperties.FILE_DIR_FIRST + File.separator + KmzFileProperties.FILE_DIR_SECOND_WAYLINES).equals(nextEntry.getName());
+ boolean isWaylines = (KmzFileProperties.FILE_DIR_FIRST + "/" + KmzFileProperties.FILE_DIR_SECOND_TEMPLATE).equals(nextEntry.getName());
if (!isWaylines) {
nextEntry = unzipFile.getNextEntry();
continue;
@@ -198,34 +196,35 @@
SAXReader reader = new SAXReader();
Document document = reader.read(unzipFile);
if (!StandardCharsets.UTF_8.name().equals(document.getXMLEncoding())) {
- throw new RuntimeException("The file encoding format is incorrect.");
+ throw new RuntimeException("文件编码格式错误");
}
Node droneNode = document.selectSingleNode("//" + KmzFileProperties.TAG_WPML_PREFIX + KmzFileProperties.TAG_DRONE_INFO);
Node payloadNode = document.selectSingleNode("//" + KmzFileProperties.TAG_WPML_PREFIX + KmzFileProperties.TAG_PAYLOAD_INFO);
if (Objects.isNull(droneNode) || Objects.isNull(payloadNode)) {
- throw new RuntimeException("The file format is incorrect.");
+ throw new RuntimeException("文件格式错误");
}
String type = droneNode.valueOf(KmzFileProperties.TAG_WPML_PREFIX + KmzFileProperties.TAG_DRONE_ENUM_VALUE);
String subType = droneNode.valueOf(KmzFileProperties.TAG_WPML_PREFIX + KmzFileProperties.TAG_DRONE_SUB_ENUM_VALUE);
String payloadType = payloadNode.valueOf(KmzFileProperties.TAG_WPML_PREFIX + KmzFileProperties.TAG_PAYLOAD_ENUM_VALUE);
String payloadSubType = payloadNode.valueOf(KmzFileProperties.TAG_WPML_PREFIX + KmzFileProperties.TAG_PAYLOAD_SUB_ENUM_VALUE);
- String templateId = document.valueOf("//" + KmzFileProperties.TAG_WPML_PREFIX + KmzFileProperties.TAG_TEMPLATE_ID);
+ String templateType = document.valueOf("//" + KmzFileProperties.TAG_WPML_PREFIX + KmzFileProperties.TAG_TEMPLATE_TYPE);
if (!StringUtils.hasText(type) || !StringUtils.hasText(subType) ||
!StringUtils.hasText(payloadSubType) || !StringUtils.hasText(payloadType) ||
- !StringUtils.hasText(templateId)) {
- throw new RuntimeException("The file format is incorrect.");
+ !StringUtils.hasText(templateType)) {
+ throw new RuntimeException("文件格式错误");
}
return Optional.of(WaylineFileDTO.builder()
.droneModelKey(String.format("%s-%s-%s", DeviceDomainEnum.SUB_DEVICE.getVal(), type, subType))
.payloadModelKeys(List.of(String.format("%s-%s-%s",DeviceDomainEnum.PAYLOAD.getVal(), payloadType, payloadSubType)))
- .objectKey(configuration.getObjectDirPrefix() + File.separator + filename)
+// .objectKey(OssConfiguration.objectDirPrefix + File.separator + filename)
+ .objectKey(OssConfiguration.objectDirPrefix + "/" + filename)
.name(filename.substring(0, filename.lastIndexOf(WAYLINE_FILE_SUFFIX)))
.sign(DigestUtils.md5DigestAsHex(file.getInputStream()))
- .templateTypes(List.of(Integer.parseInt(templateId)))
+ .templateTypes(List.of(WaylineTemplateTypeEnum.find(templateType).map(WaylineTemplateTypeEnum::getVal).orElse(-1)))
.build());
}
--
Gitblit v1.9.3