Merge branch 'feature/REQ-3540' into 'master'

Feature/req 3540

See merge request universal/infrastructure/backend/oss!161
This commit is contained in:
徐大伟 2025-04-28 09:13:27 +00:00
commit caad1ac9bd
10 changed files with 248 additions and 4 deletions

View File

@ -5,6 +5,7 @@ import cn.axzo.core.utils.converter.BeanConverter;
import cn.axzo.framework.auth.domain.ContextInfo;
import cn.axzo.oss.client.convert.ServerFileConvert;
import cn.axzo.oss.common.utils.BeanConvertUtil;
import cn.axzo.oss.dal.entity.File;
import cn.axzo.oss.http.api.ServerFileServiceApi;
import cn.axzo.oss.http.model.ApiSignUrlDownloadRequest;
import cn.axzo.oss.http.model.ApiSignUrlDownloadResponse;
@ -32,6 +33,8 @@ import cn.axzo.oss.http.model.copyobject.ServerFileBatchCopyObjectRequest;
import cn.axzo.oss.http.model.copyobject.ServerFileBatchCopyObjectResponse;
import cn.axzo.oss.http.model.copyobject.ServerFileBatchDeleteObjectRequest;
import cn.axzo.oss.http.model.copyobject.ServerFileBatchDeleteObjectResponse;
import cn.axzo.oss.http.model.file.FetchFileInfoRequest;
import cn.axzo.oss.http.model.file.FetchFileInfoResponse;
import cn.axzo.oss.http.model.file.FileRenameRequest;
import cn.axzo.oss.http.model.file.FileRenameResponse;
import cn.axzo.oss.http.model.file.UpdateFileInfoRequest;
@ -59,6 +62,8 @@ import cn.hutool.json.JSONUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
@ -310,4 +315,16 @@ public class ServerFileController implements ServerFileServiceApi {
AssertUtil.isFalse(CollectionUtils.isEmpty(deleteObjectFileDtos), "参数为空");
return DeleteObjectsFileDto.builder().deleteFiles(deleteObjectFileDtos).build();
}
/**
* 获取文件信息
*/
@Override
public CommonResponse<FetchFileInfoResponse> fetchFileInfo(@Valid @RequestBody FetchFileInfoRequest request) {
File file = fileService.fetchFileInfo(request.getFileKey());
if (Objects.isNull(file) || Objects.isNull(file.getId())) {
return CommonResponse.success();
}
return CommonResponse.success(BeanUtil.copyProperties(file, FetchFileInfoResponse.class));
}
}

View File

@ -23,6 +23,12 @@ public abstract class CommonConstants {
*/
public static final String APP_PRO_BUCKET_NAME = "axzo-pro";
/**
* 文件存储B
* 字节Byte简称 B
*/
public static final String DEFAULT_FILE_STORAGE_UNIT = "B";
/**
* 是否删除
*/

View File

@ -26,6 +26,8 @@ import cn.axzo.oss.http.model.copyobject.ServerFileBatchCopyObjectRequest;
import cn.axzo.oss.http.model.copyobject.ServerFileBatchCopyObjectResponse;
import cn.axzo.oss.http.model.copyobject.ServerFileBatchDeleteObjectRequest;
import cn.axzo.oss.http.model.copyobject.ServerFileBatchDeleteObjectResponse;
import cn.axzo.oss.http.model.file.FetchFileInfoRequest;
import cn.axzo.oss.http.model.file.FetchFileInfoResponse;
import cn.axzo.oss.http.model.file.FileRenameRequest;
import cn.axzo.oss.http.model.file.FileRenameResponse;
import cn.axzo.oss.http.model.file.UpdateFileInfoRequest;
@ -167,5 +169,11 @@ public interface ServerFileServiceApi {
@RequestMapping(value = "/api/server/deleteObject", method = RequestMethod.POST)
CommonResponse<ServerFileBatchDeleteObjectResponse> batchDeleteObject(@Valid @RequestBody ServerFileBatchDeleteObjectRequest request);
/**
* 获取文件信息
*/
@RequestMapping(value = "/api/server/fetchFileInfo", method = RequestMethod.POST)
CommonResponse<FetchFileInfoResponse> fetchFileInfo(@Valid @RequestBody FetchFileInfoRequest request);
}

View File

@ -70,4 +70,27 @@ public class ApiSignUrlUploadRequest {
* 文件key
*/
private String fileKey;
/**
* 存储单位
*/
private String storageUnit;
/**
* 文件大小-单位B
* 字节Byte简称 B
*/
private Integer fileSize;
/**
* 创建人
*/
private String createBy;
/**
* 更新人
*/
private String updateBy;
}

View File

@ -0,0 +1,28 @@
package cn.axzo.oss.http.model.file;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* 获取文件请求
*
* @author xudawei
* @date 2025-03-12
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class FetchFileInfoRequest {
/**
* 文件Id
*/
private Long fileId;
/**
* 文件fileKey
*/
private String fileKey;
}

View File

@ -0,0 +1,115 @@
package cn.axzo.oss.http.model.file;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.Date;
/**
* 获取文件返回
*
* @author xudawei
* @date 2025-03-12
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class FetchFileInfoResponse {
private Long id;
/**
* APP渠道桶编码
*/
private String appChannelBucketNo;
/**
* 应用编码
*/
private String appCode;
/**
* 渠道代码
*/
private String channelCode;
/**
* 桶名称
*/
private String bucketName;
/**
* 上传目录
*/
private String directory;
/**
* 文件UUID
*/
private String fileUuid;
/**
* 文件md5
*/
private String fileMd5;
/**
* 文件地址
*/
private String fileUrl;
/**
* 文件URLmd5
*/
private String urlMd5;
/**
* 文件上传状态:(0:处理中,1:上传成功,2:上传失败,3:已删除)
*/
private Integer status;
/**
* 文件类型
*/
private String fileFormat;
/**
* 原文件名称
*/
private String fileName;
/**
* 存储大小限制单位KB/MB
*/
private String storageUnit;
/**
* 存储大小
*/
private Integer storageSize;
/**
* 创建时间
*/
private Date createAt;
/**
* 更新时间
*/
private Date updateAt;
/**
* 创建人
*/
private String createBy;
/**
* 更新人
*/
private String updateBy;
}

View File

@ -72,4 +72,24 @@ public class SignUrlUploadDto {
* 文件key
*/
private String fileKey;
/**
* 存储单位
*/
private String storageUnit;
/**
* 文件大小-单位KB
*/
private Integer fileSize;
/**
* 创建人
*/
private String createBy;
/**
* 更新人
*/
private String updateBy;
}

View File

@ -2,6 +2,7 @@ package cn.axzo.oss.service.api;
import cn.axzo.framework.auth.domain.ContextInfo;
import cn.axzo.oss.dal.entity.AppChannelBucket;
import cn.axzo.oss.dal.entity.File;
import cn.axzo.oss.dal.entity.FileUploadConfig;
import cn.axzo.oss.manager.api.dto.request.AppInfoDto;
import cn.axzo.oss.manager.api.dto.request.DeleteFileDto;
@ -139,4 +140,9 @@ public interface FileService {
* 删除文件信息
*/
void deleteObject(DeleteObjectsFileDto dto);
/**
* 获取文件基础信息
*/
File fetchFileInfo(String fileKey);
}

View File

@ -1512,4 +1512,11 @@ public class FileServiceImpl implements FileService {
File file = byFileUuids.get(0);
return Pair.of(deleteObjectFileDtos, file);
}
/**
* 获取文件基础信息
*/
public File fetchFileInfo(String fileKey) {
return this.fileDao.getByFileUuid(fileKey);
}
}

View File

@ -1,5 +1,6 @@
package cn.axzo.oss.service.metafile.impl;
import cn.axzo.oss.common.constans.CommonConstants;
import cn.axzo.oss.common.enums.FileStatusEnum;
import cn.axzo.oss.common.utils.UrlUtil;
import cn.axzo.oss.common.utils.Utility;
@ -52,7 +53,7 @@ public class HandleFileService extends WithFileService{
, Objects.isNull(dto.getHasFileName()) ? true: dto.getHasFileName() );
//2 保存File对象
this.saveOssFile(fileUploadConfig, dto.getFileName(), fileFormat, uuid,
signUrlUpload.getDownloadSignUrl(), Utility.getMd5(signUrlUpload.getDownloadSignUrl()), expiration);
signUrlUpload.getDownloadSignUrl(), Utility.getMd5(signUrlUpload.getDownloadSignUrl()), expiration, dto);
return SignUrlUploadResponse.builder()
.signUrl(UrlUtil.httpToHttps(signUrlUpload.getSignUrl()))
.fileKey(uuid)
@ -71,7 +72,7 @@ public class HandleFileService extends WithFileService{
private File saveOssFile(FileUploadConfig fileUploadConfig, String fileName, String fileConform, String uuid,
String fileUrl, String fileMd5, Long expiration) {
String fileUrl, String fileMd5, Long expiration,SignUrlUploadDto dto) {
File byFileUuid = this.fileDao.getByFileUuid(uuid);
if (Objects.isNull(byFileUuid) || Objects.isNull(byFileUuid.getId())) {
File ossFile = new File();
@ -81,8 +82,8 @@ public class HandleFileService extends WithFileService{
ossFile.setBucketName(fileUploadConfig.getBucketName());
ossFile.setDirectory(fileUploadConfig.getDirectory());
ossFile.setStatus(FileStatusEnum.STATUS_UPLOAD_FAIL.getCode());
ossFile.setStorageUnit(fileUploadConfig.getStorageUnit());
ossFile.setStorageSize(fileUploadConfig.getStorageSize());
ossFile.setStorageUnit(StringUtils.isNotBlank(dto.getStorageUnit()) ? dto.getStorageUnit() : CommonConstants.DEFAULT_FILE_STORAGE_UNIT);
ossFile.setStorageSize(Objects.nonNull(dto.getFileSize()) ? dto.getFileSize() : 0);
ossFile.setFileFormat(fileConform);
ossFile.setFileUuid(uuid);
ossFile.setFileUrl(fileUrl);
@ -90,8 +91,21 @@ public class HandleFileService extends WithFileService{
ossFile.setStatus(FileStatusEnum.STATUS_UPLOAD_SUCCESS.getCode());
ossFile.setFileName(fileName);
ossFile.setFileMd5(fileMd5);
ossFile.setCreateBy(dto.getCreateBy());
ossFile.setUpdateBy(dto.getUpdateBy());
fileDao.save(ossFile);
return ossFile;
} else {
//1入参updateBy不为空且db#file#updateBy不为空且他们不相等
//2入参updateBy不为空且db#file#updateBy为空
// 以上2个条件满足一个则更新db中的updateBy
if ((StringUtils.isNotBlank(dto.getUpdateBy())
&& StringUtils.isNotBlank(byFileUuid.getUpdateBy())
&& !Objects.equals(dto.getUpdateBy(), byFileUuid.getUpdateBy()))
|| (StringUtils.isNotBlank(dto.getUpdateBy()) &&StringUtils.isBlank(byFileUuid.getUpdateBy()))) {
byFileUuid.setUpdateBy(dto.getUpdateBy());
fileDao.saveOrUpdate(byFileUuid);
}
}
return byFileUuid;
}