From bc16d0f0fc46ca6cb7d9bfb8496ad8f20ffba677 Mon Sep 17 00:00:00 2001
From: rain <167982779@qq.com>
Date: Mon, 06 May 2024 14:53:52 +0800
Subject: [PATCH] 修改DB库相关问题
---
src/main/java/com/dji/sample/media/service/impl/MediaServiceImpl.java | 52 ++++++++++++++++++++++++++++++++++++++++++++++------
1 files changed, 46 insertions(+), 6 deletions(-)
diff --git a/src/main/java/com/dji/sample/media/service/impl/MediaServiceImpl.java b/src/main/java/com/dji/sample/media/service/impl/MediaServiceImpl.java
index 5a75fa0..87a9bc2 100644
--- a/src/main/java/com/dji/sample/media/service/impl/MediaServiceImpl.java
+++ b/src/main/java/com/dji/sample/media/service/impl/MediaServiceImpl.java
@@ -1,5 +1,9 @@
package com.dji.sample.media.service.impl;
+import com.aliyuncs.utils.StringUtils;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.dji.sample.common.model.Pagination;
+import com.dji.sample.common.model.PaginationData;
import com.dji.sample.common.model.ResponseResult;
import com.dji.sample.component.mqtt.model.ChannelName;
import com.dji.sample.component.mqtt.model.CommonTopicReceiver;
@@ -13,10 +17,9 @@
import com.dji.sample.manage.model.enums.UserTypeEnum;
import com.dji.sample.manage.service.IDeviceRedisService;
import com.dji.sample.manage.service.IDeviceService;
-import com.dji.sample.media.model.FileUploadCallback;
-import com.dji.sample.media.model.FileUploadDTO;
-import com.dji.sample.media.model.MediaFileCountDTO;
-import com.dji.sample.media.model.MediaFileDTO;
+import com.dji.sample.media.dao.IFileMapper;
+import com.dji.sample.media.model.*;
+import com.dji.sample.media.model.param.SearchMediaParam;
import com.dji.sample.media.service.IFileService;
import com.dji.sample.media.service.IMediaService;
import com.dji.sample.wayline.model.dto.WaylineJobDTO;
@@ -24,9 +27,11 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
import org.springframework.integration.annotation.ServiceActivator;
import org.springframework.messaging.MessageHeaders;
import org.springframework.stereotype.Service;
+import org.springframework.web.bind.annotation.RequestParam;
import java.util.List;
import java.util.Map;
@@ -64,6 +69,13 @@
@Autowired
private IDeviceRedisService deviceRedisService;
+ @Autowired
+ private IFileMapper mapper;
+
+ @Value("${oss.out-net-file-address}")
+ private String fileAddress;
+ @Value("${oss.bucket}")
+ private String bucket;
@Override
public Boolean fastUpload(String workspaceId, String fingerprint) {
return fileService.checkExist(workspaceId, fingerprint);
@@ -92,8 +104,22 @@
}
+ @Override
+ public PaginationData<MediaJobDTO> mediaPage(String workspaceId, SearchMediaParam param) {
+ param.setFileAddress(fileAddress+"/"+bucket);
+ Page<MediaJobDTO> waylineJobDTOPage = mapper.mediaPage(new Page<MediaJobDTO>(param.getPage(), param.getPageSize()), workspaceId, param);
+ return new PaginationData<MediaJobDTO>(waylineJobDTOPage.getRecords(), new Pagination(waylineJobDTOPage));
+ }
+
+ @Override
+ public PaginationData<MediaJobDTO> mediaDetail( String jobId,Long page, Long pageSize) {
+ Page<MediaJobDTO> waylineJobDTOPage = mapper.mediaDetail(new Page<MediaJobDTO>(page, pageSize), jobId,fileAddress+"/"+bucket);
+ return new PaginationData<MediaJobDTO>(waylineJobDTOPage.getRecords(), new Pagination(waylineJobDTOPage));
+ }
+
/**
* Handle media files messages reported by dock.
+ * 处理由dock报告的媒体文件消息。
* @param receiver
* @return
*/
@@ -102,7 +128,7 @@
FileUploadCallback callback = objectMapper.convertValue(receiver.getData(), FileUploadCallback.class);
if (callback.getResult() != ResponseResult.CODE_SUCCESS) {
- log.error("Media file upload failed!");
+ log.error("媒体文件上传失败;Media file upload failed!");
return null;
}
@@ -123,7 +149,16 @@
if (jobOpt.isPresent()) {
boolean isSave = parseMediaFile(callback, jobOpt.get());
if (!isSave) {
- log.error("Failed to save the file to the database, please check the data manually.");
+ log.error("保存文件到数据库失败,请手动检查数据;Failed to save the file to the database, please check the data manually.");
+ return null;
+ }
+ } else if (!StringUtils.isEmpty(jobId)) { //一键起飞操作需要
+ WaylineJobDTO waylineJobDTO = new WaylineJobDTO();
+ waylineJobDTO.setWorkspaceId(device.getWorkspaceId());
+ waylineJobDTO.setDockSn(device.getDeviceSn());
+ boolean isSave = parseMediaFile(callback, waylineJobDTO);
+ if (!isSave) {
+ log.error("保存文件到数据库失败,请手动检查数据;Failed to save the file to the database, please check the data manually.");
return null;
}
}
@@ -134,12 +169,14 @@
/**
* update the uploaded count and notify web side
+ * 更新上传的计数并通知web端
* @param mediaFileCount
* @param receiver
* @param jobId
*/
private void notifyUploadedCount(MediaFileCountDTO mediaFileCount, CommonTopicReceiver receiver, String jobId, DeviceDTO dock) {
// Do not notify when files that do not belong to the route are uploaded.
+ //上传不属于该路线的文件时不进行通知。
if (Objects.isNull(mediaFileCount)) {
return;
}
@@ -149,10 +186,12 @@
String key = RedisConst.MEDIA_FILE_PREFIX + receiver.getGateway();
// After all the files of the job are uploaded, delete the media file key.
+ //待作业的所有文件上传完成后,删除媒体文件密钥。
if (mediaFileCount.getUploadedCount() >= mediaFileCount.getMediaCount()) {
RedisOpsUtils.hashDel(key, new String[]{jobId});
// After uploading, delete the key with the highest priority.
+ //上传完成后,删除优先级最高的密钥。
String highestKey = RedisConst.MEDIA_HIGHEST_PRIORITY_PREFIX + receiver.getGateway();
if (RedisOpsUtils.checkExist(highestKey) &&
jobId.equals(((MediaFileCountDTO) RedisOpsUtils.get(highestKey)).getJobId())) {
@@ -166,6 +205,7 @@
RedisOpsUtils.hashSet(key, jobId, mediaFileCount);
}
+ //通过websocket把数据发送给web
sendMessageService.sendBatch(dock.getWorkspaceId(), UserTypeEnum.WEB.getVal(),
BizCodeEnum.FILE_UPLOAD_CALLBACK.getCode(), mediaFileCount);
}
--
Gitblit v1.9.3