From c599a316971851c9eee6028ee0b579aaa7611edd Mon Sep 17 00:00:00 2001 From: xudawei Date: Thu, 11 Jul 2024 19:40:07 +0800 Subject: [PATCH] =?UTF-8?q?[REQ-2599]=E6=9F=A5=E6=89=BE=E6=A0=B9=E6=8D=AEf?= =?UTF-8?q?ile=E4=B8=AD=E7=9A=84=E6=A1=B6=E6=9F=A5=E8=AF=A2=E5=8E=9F?= =?UTF-8?q?=E6=96=87=E4=BB=B6,=E8=80=8C=E9=9D=9EappCode?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../handler/ControllerExceptionHandler.java | 2 +- .../model/ServerFileCopyToDictRequest.java | 3 +- .../impl/FileCopyToDictServiceImpl.java | 28 +++++++++++++++---- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/oss-client/src/main/java/cn/axzo/oss/client/handler/ControllerExceptionHandler.java b/oss-client/src/main/java/cn/axzo/oss/client/handler/ControllerExceptionHandler.java index 9500aea..0855b06 100644 --- a/oss-client/src/main/java/cn/axzo/oss/client/handler/ControllerExceptionHandler.java +++ b/oss-client/src/main/java/cn/axzo/oss/client/handler/ControllerExceptionHandler.java @@ -75,7 +75,7 @@ public class ControllerExceptionHandler { @ExceptionHandler(value = MethodArgumentNotValidException.class) public CommonResponse handleArgumentValidException(MethodArgumentNotValidException e){ - log.warn("[oss] ControllerExceptionHandler.handleArgumentValidException Exception", e.getMessage()); + log.warn("[oss] ControllerExceptionHandler.handleArgumentValidException Exception", e); BindingResult bindingResult = e.getBindingResult(); StringBuilder errorMsg = new StringBuilder(); for (FieldError fieldError : bindingResult.getFieldErrors()) { diff --git a/oss-http-api/src/main/java/cn/axzo/oss/http/model/ServerFileCopyToDictRequest.java b/oss-http-api/src/main/java/cn/axzo/oss/http/model/ServerFileCopyToDictRequest.java index 6d0b802..1f025b0 100644 --- a/oss-http-api/src/main/java/cn/axzo/oss/http/model/ServerFileCopyToDictRequest.java +++ b/oss-http-api/src/main/java/cn/axzo/oss/http/model/ServerFileCopyToDictRequest.java @@ -18,12 +18,11 @@ public class ServerFileCopyToDictRequest { private String appCode; @NotBlank(message = "bizScene must not be null") private String bizScene; - @NotBlank(message = "fileName must not be null") @NotNull(message = "fileKey must not be null") private String fileKey; - @NotNull(message = "fileKey must not be null") + @NotNull(message = "targetDict must not be null") private String targetDict; private Integer channelCode; diff --git a/oss-service/src/main/java/cn/axzo/oss/service/impl/FileCopyToDictServiceImpl.java b/oss-service/src/main/java/cn/axzo/oss/service/impl/FileCopyToDictServiceImpl.java index 574f5ab..a1aeffa 100644 --- a/oss-service/src/main/java/cn/axzo/oss/service/impl/FileCopyToDictServiceImpl.java +++ b/oss-service/src/main/java/cn/axzo/oss/service/impl/FileCopyToDictServiceImpl.java @@ -7,18 +7,21 @@ import cn.axzo.oss.dal.entity.FileUploadConfig; import cn.axzo.oss.dal.repository.FileDao; import cn.axzo.oss.manager.api.FileManager; import cn.axzo.oss.manager.api.dto.request.ServerFileCopyToDictDto; +import cn.axzo.oss.manager.api.dto.request.SignUrlDownloadDto; import cn.axzo.oss.manager.api.dto.response.ManaGetObjectMetaResponse; import cn.axzo.oss.manager.api.dto.response.SignUrlDownloadResponse; import cn.axzo.oss.service.api.FileCopyToDictService; import cn.axzo.oss.service.api.FileService; import cn.hutool.core.lang.Pair; import com.alibaba.fastjson.JSON; +import com.google.common.collect.Lists; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.cloud.context.config.annotation.RefreshScope; import org.springframework.stereotype.Service; +import java.util.List; import java.util.Objects; /** @@ -57,19 +60,32 @@ public class FileCopyToDictServiceImpl implements FileCopyToDictService { String targetFileKey = Utility.generateFileKey(fileUploadConfig.getDirectory() + "_" + dto.getTargetDict(), dto.getFileKey(), byFileUuid.getFileFormat()); //3 获取下载文件url(支持:公有桶/私有桶) - SignUrlDownloadResponse downloadResponse = this.fileManager.fetchDownloadUrl(appChannelBucket.getBucketType(), fileUploadConfig.getBucketName(), sourceFileKey - , fileUploadConfig.getChannelCode(), SIGN_URL_DOWNLOAD_EXPIRE_SECOND, byFileUuid.getFileName(), null, false); +// SignUrlDownloadResponse downloadResponse = this.fileManager.fetchDownloadUrl(appChannelBucket.getBucketType(), fileUploadConfig.getBucketName(), sourceFileKey +// , fileUploadConfig.getChannelCode(), SIGN_URL_DOWNLOAD_EXPIRE_SECOND, byFileUuid.getFileName(), null, false); + String downloadSignUrl = this.fetchSignUrlByFileKey(dto.getFileKey(), null); + //4 获取文件元信息(此时主要文件大小) - ManaGetObjectMetaResponse objectMeta = fileService.getObjectMeta(appChannelBucket.getBucketName(), sourceFileKey, downloadResponse.getSignUrl(), appChannelBucket.getChannelCode()); + ManaGetObjectMetaResponse objectMeta = fileService.getObjectMeta(byFileUuid.getBucketName(), sourceFileKey, downloadSignUrl, byFileUuid.getChannelCode()); + //文件大小没有达到maxFileSize,则不用裁剪 if (Objects.nonNull(dto.getMaxFileSize()) && !Objects.equals(dto.getMaxFileSize(), 0) && !Objects.equals(objectMeta.getSize(), 0)&& objectMeta.getSize() > dto.getMaxFileSize()) { //5 重新获取下载文件url(支持:公有桶/私有桶) - downloadResponse = this.fileManager.fetchDownloadUrl(appChannelBucket.getBucketType(), fileUploadConfig.getBucketName(), sourceFileKey - , fileUploadConfig.getChannelCode(), SIGN_URL_DOWNLOAD_EXPIRE_SECOND, byFileUuid.getFileName(), dto.getStyle(), false); +// downloadResponse = this.fileManager.fetchDownloadUrl(appChannelBucket.getBucketType(), fileUploadConfig.getBucketName(), sourceFileKey +// , fileUploadConfig.getChannelCode(), SIGN_URL_DOWNLOAD_EXPIRE_SECOND, byFileUuid.getFileName(), dto.getStyle(), false); + downloadSignUrl = this.fetchSignUrlByFileKey(dto.getFileKey(), dto.getStyle()); } //6 上传至指定目录 - this.fileManager.uploadByUrl(fileUploadConfig.getBucketName(), targetFileKey, byFileUuid.getFileName(), downloadResponse.getSignUrl(), fileUploadConfig.getChannelCode()); + this.fileManager.uploadByUrl(fileUploadConfig.getBucketName(), targetFileKey, byFileUuid.getFileName(), downloadSignUrl, fileUploadConfig.getChannelCode()); + log.info("copyToDict-end,targetFileKey:{}", targetFileKey); return targetFileKey; } + + private String fetchSignUrlByFileKey(String fileKey, String style) { + SignUrlDownloadDto signUrlDownloadDto = new SignUrlDownloadDto(); + signUrlDownloadDto.setFileKeys(Lists.newArrayList(fileKey)); + signUrlDownloadDto.setStyle(style); + List responseList = this.fileService.signUrlDownload(signUrlDownloadDto); + return responseList.get(0).getSignUrl(); + } }