refactor: 完善部分校验、注释,优化部分后端代码格式

This commit is contained in:
2023-12-30 23:01:14 +08:00
parent 89e4326290
commit 06887604fd
10 changed files with 45 additions and 38 deletions

View File

@@ -68,24 +68,24 @@ public class StorageReq extends BaseReq {
private StorageTypeEnum type;
/**
* Access Key
* 访问密钥
*/
@Schema(description = "Access Key", example = "")
@Length(max = 255, message = "Access Key长度不能超过 {max} 个字符")
@Schema(description = "访问密钥", example = "")
@Length(max = 255, message = "访问密钥长度不能超过 {max} 个字符")
private String accessKey;
/**
* Secret Key
* 私有密钥
*/
@Schema(description = "Secret Key", example = "")
@Length(max = 255, message = "Secret Key长度不能超过 {max} 个字符")
@Schema(description = "私有密钥", example = "")
@Length(max = 255, message = "私有密钥长度不能超过 {max} 个字符")
private String secretKey;
/**
* Endpoint
* 终端节点
*/
@Schema(description = "Endpoint", example = "")
@Length(max = 255, message = "Endpoint长度不能超过 {max} 个字符")
@Schema(description = "终端节点", example = "")
@Length(max = 255, message = "终端节点长度不能超过 {max} 个字符")
private String endpoint;
/**

View File

@@ -68,7 +68,8 @@ public class FileResp extends BaseDetailResp {
/**
* 类型
*/
@Schema(description = "类型", type = "Integer", allowableValues = {"1", "2", "3", "4", "5"}, example = "2")
@Schema(description = "类型1其他2图片3文档4视频5音频", type = "Integer", allowableValues = {"1", "2", "3", "4", "5"},
example = "2")
private FileTypeEnum type;
/**

View File

@@ -61,29 +61,29 @@ public class StorageDetailResp extends BaseDetailResp {
/**
* 类型
*/
@Schema(description = "类型", type = "Integer", allowableValues = {"1", "2"}, example = "2")
@Schema(description = "类型1兼容S3协议存储2本地存储", type = "Integer", allowableValues = {"1", "2"}, example = "2")
@ExcelProperty(value = "类型", converter = ExcelBaseEnumConverter.class)
private StorageTypeEnum type;
/**
* Access Key
* 访问密钥
*/
@Schema(description = "Access Key", example = "")
@ExcelProperty(value = "Access Key")
@Schema(description = "访问密钥", example = "")
@ExcelProperty(value = "访问密钥")
private String accessKey;
/**
* Secret Key
* 私有密钥
*/
@Schema(description = "Secret Key", example = "")
@ExcelProperty(value = "Secret Key")
@Schema(description = "私有密钥", example = "")
@ExcelProperty(value = "私有密钥")
private String secretKey;
/**
* Endpoint
* 终端节点
*/
@Schema(description = "Endpoint", example = "")
@ExcelProperty(value = "Endpoint")
@Schema(description = "终端节点", example = "")
@ExcelProperty(value = "终端节点")
private String endpoint;
/**

View File

@@ -56,26 +56,26 @@ public class StorageResp extends BaseResp {
/**
* 类型
*/
@Schema(description = "类型", type = "Integer", allowableValues = {"1", "2"}, example = "2")
@Schema(description = "类型1兼容S3协议存储2本地存储", type = "Integer", allowableValues = {"1", "2"}, example = "2")
private StorageTypeEnum type;
/**
* Access Key
* 访问密钥
*/
@Schema(description = "Access Key", example = "")
@Schema(description = "访问密钥", example = "")
private String accessKey;
/**
* Secret Key
* 私有密钥
*/
@Schema(description = "Secret Key", example = "")
@Schema(description = "私有密钥", example = "")
@JsonIgnore
private String secretKey;
/**
* Endpoint
* 终端节点
*/
@Schema(description = "Endpoint", example = "")
@Schema(description = "终端节点", example = "")
private String endpoint;
/**

View File

@@ -57,9 +57,9 @@ import top.charles7c.continew.starter.extension.crud.base.BaseServiceImpl;
public class DeptServiceImpl extends BaseServiceImpl<DeptMapper, DeptDO, DeptResp, DeptDetailResp, DeptQuery, DeptReq>
implements DeptService {
private final RoleDeptService roleDeptService;
@Resource
private UserService userService;
private final RoleDeptService roleDeptService;
@Override
public Long add(DeptReq req) {

View File

@@ -42,7 +42,6 @@ import top.charles7c.continew.admin.system.model.resp.FileResp;
import top.charles7c.continew.admin.system.model.resp.StorageDetailResp;
import top.charles7c.continew.admin.system.service.FileService;
import top.charles7c.continew.admin.system.service.StorageService;
import top.charles7c.continew.starter.core.constant.StringConstants;
import top.charles7c.continew.starter.core.util.URLUtils;
import top.charles7c.continew.starter.core.util.validate.CheckUtils;
import top.charles7c.continew.starter.extension.crud.base.BaseServiceImpl;
@@ -107,7 +106,7 @@ public class FileServiceImpl extends BaseServiceImpl<FileMapper, FileDO, FileRes
// 处理本地存储文件 URL
FileInfo fileInfo = uploadPretreatment.upload();
fileInfo.setUrl(StorageTypeEnum.LOCAL.equals(storage.getType())
? URLUtil.normalize(storage.getDomain() + StringConstants.SLASH + fileInfo.getUrl()) : fileInfo.getUrl());
? URLUtil.normalize(storage.getDomain() + fileInfo.getUrl()) : fileInfo.getUrl());
return fileInfo;
}
@@ -120,7 +119,7 @@ public class FileServiceImpl extends BaseServiceImpl<FileMapper, FileDO, FileRes
protected void fill(Object baseObj) {
if (baseObj instanceof FileResp fileResp && !URLUtils.isHttpUrl(fileResp.getUrl())) {
StorageDetailResp storage = storageService.get(fileResp.getStorageId());
fileResp.setUrl(URLUtil.normalize(storage.getDomain() + StringConstants.SLASH + fileResp.getUrl()));
fileResp.setUrl(URLUtil.normalize(storage.getDomain() + fileResp.getUrl()));
}
super.fill(baseObj);
}

View File

@@ -55,6 +55,7 @@ import top.charles7c.continew.admin.system.model.resp.StorageResp;
import top.charles7c.continew.admin.system.service.FileService;
import top.charles7c.continew.admin.system.service.StorageService;
import top.charles7c.continew.starter.core.constant.StringConstants;
import top.charles7c.continew.starter.core.util.URLUtils;
import top.charles7c.continew.starter.core.util.validate.CheckUtils;
import top.charles7c.continew.starter.core.util.validate.ValidationUtils;
import top.charles7c.continew.starter.extension.crud.base.BaseServiceImpl;
@@ -130,10 +131,16 @@ public class StorageServiceImpl
public void load(StorageReq req) {
CopyOnWriteArrayList<FileStorage> fileStorageList = fileStorageService.getFileStorageList();
String bucketName = req.getBucketName();
String domain = req.getDomain();
StorageTypeEnum type = req.getType();
switch (type) {
case LOCAL -> {
ValidationUtils.throwIfBlank(bucketName, "存储路径不能为空");
ValidationUtils.throwIfBlank(domain, "自定义域名不能为空");
ValidationUtils.throwIf(!URLUtils.isHttpUrl(domain), "自定义域名格式错误");
req.setDomain(StrUtil.appendIfMissing(domain, StringConstants.SLASH));
req.setBucketName(StrUtil.appendIfMissing(
bucketName.replace(StringConstants.BACKSLASH, StringConstants.SLASH), StringConstants.SLASH));
FileStorageProperties.LocalPlusConfig config = new FileStorageProperties.LocalPlusConfig();
config.setPlatform(req.getCode());
config.setStoragePath(bucketName);
@@ -145,9 +152,9 @@ public class StorageServiceImpl
String accessKey = req.getAccessKey();
String secretKey = req.getSecretKey();
String endpoint = req.getEndpoint();
ValidationUtils.throwIfBlank(accessKey, "Access Key不能为空");
ValidationUtils.throwIfBlank(secretKey, "Secret Key不能为空");
ValidationUtils.throwIfBlank(endpoint, "Endpoint不能为空");
ValidationUtils.throwIfBlank(accessKey, "访问密钥不能为空");
ValidationUtils.throwIfBlank(secretKey, "私有密钥不能为空");
ValidationUtils.throwIfBlank(endpoint, "终端节点不能为空");
ValidationUtils.throwIfBlank(bucketName, "桶名称不能为空");
FileStorageProperties.AmazonS3Config config = new FileStorageProperties.AmazonS3Config();
config.setPlatform(req.getCode());
@@ -155,7 +162,7 @@ public class StorageServiceImpl
config.setSecretKey(secretKey);
config.setEndPoint(endpoint);
config.setBucketName(bucketName);
config.setDomain(req.getDomain());
config.setDomain(domain);
fileStorageList.addAll(
FileStorageServiceBuilder.buildAmazonS3FileStorage(Collections.singletonList(config), null));
}