Commit b26913c0 by gdj

航飞任务图片上传,移动文件到org目录下。

parent 6936432e
...@@ -12,6 +12,7 @@ import com.dji.sample.media.model.MediaFileDTO; ...@@ -12,6 +12,7 @@ import com.dji.sample.media.model.MediaFileDTO;
import com.dji.sample.media.service.IFileService; import com.dji.sample.media.service.IFileService;
import com.dji.sample.media.service.IMediaRedisService; import com.dji.sample.media.service.IMediaRedisService;
import com.dji.sample.media.service.IMediaService; import com.dji.sample.media.service.IMediaService;
import com.dji.sample.wayline.model.dto.WaylineJobDTO;
import com.dji.sample.wayline.service.IWaylineJobService; import com.dji.sample.wayline.service.IWaylineJobService;
import com.dji.sdk.cloudapi.media.*; import com.dji.sdk.cloudapi.media.*;
import com.dji.sdk.cloudapi.media.api.AbstractMediaService; import com.dji.sdk.cloudapi.media.api.AbstractMediaService;
...@@ -19,12 +20,19 @@ import com.dji.sdk.mqtt.MqttReply; ...@@ -19,12 +20,19 @@ import com.dji.sdk.mqtt.MqttReply;
import com.dji.sdk.mqtt.events.TopicEventsRequest; import com.dji.sdk.mqtt.events.TopicEventsRequest;
import com.dji.sdk.mqtt.events.TopicEventsResponse; import com.dji.sdk.mqtt.events.TopicEventsResponse;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.messaging.MessageHeaders; import org.springframework.messaging.MessageHeaders;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.Optional; import java.util.Optional;
...@@ -60,6 +68,9 @@ public class MediaServiceImpl extends AbstractMediaService implements IMediaServ ...@@ -60,6 +68,9 @@ public class MediaServiceImpl extends AbstractMediaService implements IMediaServ
@Autowired @Autowired
private IMediaRedisService mediaRedisService; private IMediaRedisService mediaRedisService;
@Value("${my.file.base-path}")
private String basePath;
@Override @Override
public Boolean fastUpload(String workspaceId, String fingerprint) { public Boolean fastUpload(String workspaceId, String fingerprint) {
return fileService.checkExist(workspaceId, fingerprint); return fileService.checkExist(workspaceId, fingerprint);
...@@ -150,19 +161,63 @@ public class MediaServiceImpl extends AbstractMediaService implements IMediaServ ...@@ -150,19 +161,63 @@ public class MediaServiceImpl extends AbstractMediaService implements IMediaServ
} }
private Boolean parseMediaFile(FileUploadCallback callback, DeviceDTO device) { private Boolean parseMediaFile(FileUploadCallback callback, DeviceDTO device) {
// moveFile path wayline/workspaceId/jobId/fileName -> wayline/worksapceId/orgId/jobId/fileName
// file.path name objectKey
// 查询 任务的orgId
String orgId = "";
WaylineJobDTO jobDTO = null;
Optional<WaylineJobDTO> jobOpt = waylineJobService.getJobByJobId(device.getWorkspaceId(), callback.getFile().getExt().getFlightId());
if (jobOpt.isPresent()) {
jobDTO = jobOpt.get();
orgId = jobDTO.getOrgId();
}
MediaUploadCallbackRequest file = convert2callbackRequest(callback.getFile()); MediaUploadCallbackRequest file = convert2callbackRequest(callback.getFile());
// Set the drone sn that shoots the media // Set the drone sn that shoots the media
file.getExt().setSn(device.getChildDeviceSn()); file.getExt().setSn(device.getChildDeviceSn());
// set path // set path
String objectKey = file.getObjectKey(); String objectKey = file.getObjectKey();
file.setPath(objectKey.substring(Optional.of(objectKey.indexOf(OssConfiguration.objectDirPrefix)) String path = objectKey.substring(Optional.of(objectKey.indexOf(OssConfiguration.objectDirPrefix))
.filter(index -> index > 0).map(index -> index++).orElse(0), .filter(index -> index > 0).map(index -> index++).orElse(0), objectKey.lastIndexOf("/"));
objectKey.lastIndexOf("/")) + "/" + device.getWorkspaceId()); if (StringUtils.hasText(orgId)) {
String orgFilePath = path;
// 增加 org路径
path = path.replace(OssConfiguration.objectDirPrefix + "/" + device.getWorkspaceId(), OssConfiguration.objectDirPrefix + "/" + device.getWorkspaceId() + "/" + orgId);
// jobId改成 jobName
if (jobDTO != null) {
path = path.replace(callback.getFile().getExt().getFlightId(), jobDTO.getJobName());
}
String moveFilePath = path;
// DJI_20250801115516_0033_V.jpeg
// wayline/e3dea0f5-37f2-4d79-ae58-490af3228069/test-8-1-11-52-2025-08-01-11-52-49-9c08/DJI_202508011152_001_test-8-1-11-52-2025-08-01-11-52-49-9c08/DJI_20250801115516_0033_V.jpeg
file.setPath(path);
file.setObjectKey(moveFilePath);
moveFile(orgFilePath, moveFilePath, callback.getFile().getName());
} else {
file.setPath(path);
}
return fileService.saveFile(device.getWorkspaceId(), file) > 0; return fileService.saveFile(device.getWorkspaceId(), file) > 0;
} }
@SneakyThrows
public void moveFile(String sourceFilePath, String targetFilePath, String fileName) {
File directory = new File(basePath);
if (!directory.exists()) {
boolean created = directory.mkdirs();
}
Path source = Paths.get(basePath, OssConfiguration.bucket, sourceFilePath, fileName);
Path targetDir = Paths.get(basePath, OssConfiguration.bucket, targetFilePath);
if (!Files.exists(targetDir)) {
Files.createDirectories(targetDir);
}
Path target = targetDir.resolve(fileName);
Files.move(source, target, StandardCopyOption.REPLACE_EXISTING);
}
private void notifyUploadedCount(MediaFileCountDTO mediaFileCount, TopicEventsRequest<FileUploadCallback> request, String jobId, DeviceDTO dock) { private void notifyUploadedCount(MediaFileCountDTO mediaFileCount, TopicEventsRequest<FileUploadCallback> request, String jobId, DeviceDTO dock) {
// Do not notify when files that do not belong to the route are uploaded. // Do not notify when files that do not belong to the route are uploaded.
if (Objects.isNull(mediaFileCount)) { if (Objects.isNull(mediaFileCount)) {
......
server: server:
port: 6789 port: 6789
my:
file:
base-path: /app/filePath
spring: spring:
main: main:
allow-bean-definition-overriding: true allow-bean-definition-overriding: true
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment