mirror of
https://github.com/continew-org/continew-admin.git
synced 2025-09-11 06:57:12 +08:00
feat: 存储管理适配后端 API
This commit is contained in:
@@ -22,6 +22,7 @@ import lombok.Data;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
|
||||
import top.charles7c.continew.admin.common.enums.DisEnableStatusEnum;
|
||||
import top.charles7c.continew.admin.system.enums.StorageTypeEnum;
|
||||
import top.charles7c.continew.starter.extension.crud.base.BaseDO;
|
||||
|
||||
@@ -96,5 +97,5 @@ public class StorageDO extends BaseDO {
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
private Integer status;
|
||||
private DisEnableStatusEnum status;
|
||||
}
|
@@ -24,6 +24,9 @@ import lombok.Data;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
|
||||
import org.hibernate.validator.constraints.Length;
|
||||
|
||||
import top.charles7c.continew.admin.common.constant.RegexConstants;
|
||||
import top.charles7c.continew.admin.common.enums.DisEnableStatusEnum;
|
||||
import top.charles7c.continew.admin.system.enums.StorageTypeEnum;
|
||||
import top.charles7c.continew.starter.extension.crud.base.BaseReq;
|
||||
@@ -44,71 +47,79 @@ public class StorageReq extends BaseReq {
|
||||
/**
|
||||
* 名称
|
||||
*/
|
||||
@Schema(description = "名称")
|
||||
@Schema(description = "名称", example = "存储库1")
|
||||
@NotBlank(message = "名称不能为空")
|
||||
@Length(max = 100, message = "名称长度不能超过 {max} 个字符")
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 编码
|
||||
*/
|
||||
@Schema(description = "编码")
|
||||
@Schema(description = "编码", example = "local")
|
||||
@NotBlank(message = "编码不能为空")
|
||||
@Pattern(regexp = RegexConstants.GENERAL_CODE, message = "编码长度为 2 到 30 位,可以包含字母、数字,下划线,以字母开头")
|
||||
private String code;
|
||||
|
||||
/**
|
||||
* 类型
|
||||
*/
|
||||
@Schema(description = "类型")
|
||||
@Schema(description = "类型", type = "Integer", allowableValues = {"1", "2"}, example = "2")
|
||||
@NotNull(message = "类型非法")
|
||||
private StorageTypeEnum type;
|
||||
|
||||
/**
|
||||
* Access Key
|
||||
*/
|
||||
@Schema(description = "Access Key")
|
||||
@Schema(description = "Access Key", example = "")
|
||||
@Length(max = 255, message = "Access Key长度不能超过 {max} 个字符")
|
||||
private String accessKey;
|
||||
|
||||
/**
|
||||
* Secret Key
|
||||
*/
|
||||
@Schema(description = "Secret Key")
|
||||
@Schema(description = "Secret Key", example = "")
|
||||
@Length(max = 255, message = "Secret Key长度不能超过 {max} 个字符")
|
||||
private String secretKey;
|
||||
|
||||
/**
|
||||
* Endpoint
|
||||
*/
|
||||
@Schema(description = "Endpoint")
|
||||
@Schema(description = "Endpoint", example = "")
|
||||
@Length(max = 255, message = "Endpoint长度不能超过 {max} 个字符")
|
||||
private String endpoint;
|
||||
|
||||
/**
|
||||
* 桶名称
|
||||
*/
|
||||
@Schema(description = "桶名称")
|
||||
@Schema(description = "桶名称", example = "C:/continew-admin/data/file/")
|
||||
@Length(max = 255, message = "桶名称长度不能超过 {max} 个字符")
|
||||
private String bucketName;
|
||||
|
||||
/**
|
||||
* 自定义域名
|
||||
*/
|
||||
@Schema(description = "自定义域名")
|
||||
@Schema(description = "自定义域名", example = "http://localhost:8000/file")
|
||||
@Length(max = 255, message = "自定义域名长度不能超过 {max} 个字符")
|
||||
private String domain;
|
||||
|
||||
/**
|
||||
* 描述
|
||||
*/
|
||||
@Schema(description = "描述")
|
||||
@Schema(description = "描述", example = "存储库描述")
|
||||
@Length(max = 200, message = "描述长度不能超过 {max} 个字符")
|
||||
private String description;
|
||||
|
||||
/**
|
||||
* 是否为默认存储
|
||||
*/
|
||||
@Schema(description = "是否为默认存储")
|
||||
@Schema(description = "是否为默认存储", example = "true")
|
||||
@NotNull(message = "是否为默认存储不能为空")
|
||||
private Boolean isDefault;
|
||||
|
||||
/**
|
||||
* 排序
|
||||
*/
|
||||
@Schema(description = "排序")
|
||||
@Schema(description = "排序", example = "1")
|
||||
private Integer sort;
|
||||
|
||||
/**
|
||||
|
@@ -23,7 +23,6 @@ import lombok.Data;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
|
||||
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
|
||||
import top.charles7c.continew.admin.system.enums.FileTypeEnum;
|
||||
import top.charles7c.continew.starter.extension.crud.base.BaseDetailResp;
|
||||
@@ -46,48 +45,35 @@ public class FileResp extends BaseDetailResp {
|
||||
* 名称
|
||||
*/
|
||||
@Schema(description = "名称", example = "example")
|
||||
@ExcelProperty(value = "名称")
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 大小(字节)
|
||||
*/
|
||||
@Schema(description = "大小(字节)", example = "4096")
|
||||
@ExcelProperty(value = "大小(字节)")
|
||||
private Long size;
|
||||
|
||||
/**
|
||||
* URL
|
||||
*/
|
||||
@Schema(description = "URL", example = "https://examplebucket.oss-cn-hangzhou.aliyuncs.com/example/example.jpg")
|
||||
@ExcelProperty(value = "URL")
|
||||
private String url;
|
||||
|
||||
/**
|
||||
* 扩展名
|
||||
*/
|
||||
@Schema(description = "扩展名", example = "jpg")
|
||||
@ExcelProperty(value = "扩展名")
|
||||
private String extension;
|
||||
|
||||
/**
|
||||
* MIME类型
|
||||
*/
|
||||
@Schema(description = "MIME类型")
|
||||
@ExcelProperty(value = "MIME类型")
|
||||
private String mimeType;
|
||||
|
||||
/**
|
||||
* 类型
|
||||
*/
|
||||
@Schema(description = "类型", type = "Integer", allowableValues = {"1", "2", "3", "4", "5"}, example = "2")
|
||||
@ExcelProperty(value = "类型")
|
||||
private FileTypeEnum type;
|
||||
|
||||
/**
|
||||
* 存储库 ID
|
||||
*/
|
||||
@Schema(description = "存储库ID", example = "1")
|
||||
@ExcelProperty(value = "存储库ID")
|
||||
private Long storageId;
|
||||
}
|
@@ -25,6 +25,8 @@ import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
|
||||
import top.charles7c.continew.admin.common.config.easyexcel.ExcelBaseEnumConverter;
|
||||
import top.charles7c.continew.admin.common.enums.DisEnableStatusEnum;
|
||||
import top.charles7c.continew.admin.system.enums.StorageTypeEnum;
|
||||
import top.charles7c.continew.starter.extension.crud.base.BaseDetailResp;
|
||||
|
||||
@@ -45,83 +47,89 @@ public class StorageDetailResp extends BaseDetailResp {
|
||||
/**
|
||||
* 名称
|
||||
*/
|
||||
@Schema(description = "名称")
|
||||
@Schema(description = "名称", example = "存储库1")
|
||||
@ExcelProperty(value = "名称")
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 编码
|
||||
*/
|
||||
@Schema(description = "编码")
|
||||
@Schema(description = "编码", example = "local")
|
||||
@ExcelProperty(value = "编码")
|
||||
private String code;
|
||||
|
||||
/**
|
||||
* 类型
|
||||
*/
|
||||
@Schema(description = "类型")
|
||||
@Schema(description = "类型", type = "Integer", allowableValues = {"1", "2"}, example = "2")
|
||||
@ExcelProperty(value = "类型", converter = ExcelBaseEnumConverter.class)
|
||||
private StorageTypeEnum type;
|
||||
|
||||
/**
|
||||
* Access Key
|
||||
*/
|
||||
@Schema(description = "Access Key")
|
||||
@Schema(description = "Access Key", example = "")
|
||||
@ExcelProperty(value = "Access Key")
|
||||
private String accessKey;
|
||||
|
||||
/**
|
||||
* Secret Key
|
||||
*/
|
||||
@Schema(description = "Secret Key")
|
||||
@Schema(description = "Secret Key", example = "")
|
||||
@ExcelProperty(value = "Secret Key")
|
||||
private String secretKey;
|
||||
|
||||
/**
|
||||
* Endpoint
|
||||
*/
|
||||
@Schema(description = "Endpoint")
|
||||
@Schema(description = "Endpoint", example = "")
|
||||
@ExcelProperty(value = "Endpoint")
|
||||
private String endpoint;
|
||||
|
||||
/**
|
||||
* 桶名称
|
||||
*/
|
||||
@Schema(description = "桶名称")
|
||||
@Schema(description = "桶名称", example = "C:/continew-admin/data/file/")
|
||||
@ExcelProperty(value = "桶名称")
|
||||
private String bucketName;
|
||||
|
||||
/**
|
||||
* 自定义域名
|
||||
*/
|
||||
@Schema(description = "自定义域名")
|
||||
@Schema(description = "自定义域名", example = "http://localhost:8000/file")
|
||||
@ExcelProperty(value = "自定义域名")
|
||||
private String domain;
|
||||
|
||||
/**
|
||||
* 描述
|
||||
*/
|
||||
@Schema(description = "描述")
|
||||
@Schema(description = "描述", example = "存储库描述")
|
||||
@ExcelProperty(value = "描述")
|
||||
private String description;
|
||||
|
||||
/**
|
||||
* 是否为默认存储
|
||||
*/
|
||||
@Schema(description = "是否为默认存储")
|
||||
@Schema(description = "是否为默认存储", example = "true")
|
||||
@ExcelProperty(value = "是否为默认存储")
|
||||
private Boolean isDefault;
|
||||
|
||||
/**
|
||||
* 排序
|
||||
*/
|
||||
@Schema(description = "排序")
|
||||
@Schema(description = "排序", example = "1")
|
||||
@ExcelProperty(value = "排序")
|
||||
private Integer sort;
|
||||
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
@Schema(description = "状态")
|
||||
@ExcelProperty(value = "状态")
|
||||
private Integer status;
|
||||
@Schema(description = "状态(1:启用;2:禁用)", type = "Integer", allowableValues = {"1", "2"}, example = "1")
|
||||
@ExcelProperty(value = "状态", converter = ExcelBaseEnumConverter.class)
|
||||
private DisEnableStatusEnum status;
|
||||
|
||||
@Override
|
||||
public Boolean getDisabled() {
|
||||
return this.getIsDefault();
|
||||
}
|
||||
}
|
@@ -22,6 +22,9 @@ import lombok.Data;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
|
||||
import top.charles7c.continew.admin.common.enums.DisEnableStatusEnum;
|
||||
import top.charles7c.continew.admin.system.enums.StorageTypeEnum;
|
||||
import top.charles7c.continew.starter.extension.crud.base.BaseResp;
|
||||
|
||||
@@ -41,72 +44,78 @@ public class StorageResp extends BaseResp {
|
||||
/**
|
||||
* 名称
|
||||
*/
|
||||
@Schema(description = "名称")
|
||||
@Schema(description = "名称", example = "存储库1")
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 编码
|
||||
*/
|
||||
@Schema(description = "编码")
|
||||
@Schema(description = "编码", example = "local")
|
||||
private String code;
|
||||
|
||||
/**
|
||||
* 类型
|
||||
*/
|
||||
@Schema(description = "类型")
|
||||
@Schema(description = "类型", type = "Integer", allowableValues = {"1", "2"}, example = "2")
|
||||
private StorageTypeEnum type;
|
||||
|
||||
/**
|
||||
* Access Key
|
||||
*/
|
||||
@Schema(description = "Access Key")
|
||||
@Schema(description = "Access Key", example = "")
|
||||
private String accessKey;
|
||||
|
||||
/**
|
||||
* Secret Key
|
||||
*/
|
||||
@Schema(description = "Secret Key")
|
||||
@Schema(description = "Secret Key", example = "")
|
||||
@JsonIgnore
|
||||
private String secretKey;
|
||||
|
||||
/**
|
||||
* Endpoint
|
||||
*/
|
||||
@Schema(description = "Endpoint")
|
||||
@Schema(description = "Endpoint", example = "")
|
||||
private String endpoint;
|
||||
|
||||
/**
|
||||
* 桶名称
|
||||
*/
|
||||
@Schema(description = "桶名称")
|
||||
@Schema(description = "桶名称", example = "C:/continew-admin/data/file/")
|
||||
private String bucketName;
|
||||
|
||||
/**
|
||||
* 自定义域名
|
||||
*/
|
||||
@Schema(description = "自定义域名")
|
||||
@Schema(description = "自定义域名", example = "http://localhost:8000/file")
|
||||
private String domain;
|
||||
|
||||
/**
|
||||
* 描述
|
||||
*/
|
||||
@Schema(description = "描述")
|
||||
@Schema(description = "描述", example = "存储库描述")
|
||||
private String description;
|
||||
|
||||
/**
|
||||
* 是否为默认存储
|
||||
*/
|
||||
@Schema(description = "是否为默认存储")
|
||||
@Schema(description = "是否为默认存储", example = "true")
|
||||
private Boolean isDefault;
|
||||
|
||||
/**
|
||||
* 排序
|
||||
*/
|
||||
@Schema(description = "排序")
|
||||
@Schema(description = "排序", example = "1")
|
||||
private Integer sort;
|
||||
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
@Schema(description = "状态")
|
||||
private Integer status;
|
||||
@Schema(description = "状态(1:启用;2:禁用)", type = "Integer", allowableValues = {"1", "2"}, example = "1")
|
||||
private DisEnableStatusEnum status;
|
||||
|
||||
@Override
|
||||
public Boolean getDisabled() {
|
||||
return this.getIsDefault();
|
||||
}
|
||||
}
|
@@ -78,6 +78,7 @@ public class StorageServiceImpl
|
||||
|
||||
@Override
|
||||
public Long add(StorageReq req) {
|
||||
CheckUtils.throwIf(Boolean.TRUE.equals(req.getIsDefault()) && this.isDefaultExists(null), "请先取消原有默认存储库");
|
||||
String code = req.getCode();
|
||||
CheckUtils.throwIf(this.isCodeExists(code, null), "新增失败,[{}] 已存在", code);
|
||||
req.setStatus(DisEnableStatusEnum.ENABLE);
|
||||
@@ -87,14 +88,20 @@ public class StorageServiceImpl
|
||||
|
||||
@Override
|
||||
public void update(StorageReq req, Long id) {
|
||||
CheckUtils.throwIf(Boolean.TRUE.equals(req.getIsDefault()) && this.isDefaultExists(id), "请先取消原有默认存储库");
|
||||
String code = req.getCode();
|
||||
CheckUtils.throwIf(this.isCodeExists(code, id), "修改失败,[{}] 已存在", code);
|
||||
StorageDO oldStorage = super.getById(id);
|
||||
CheckUtils.throwIf(
|
||||
Boolean.TRUE.equals(oldStorage.getIsDefault()) && DisEnableStatusEnum.DISABLE.equals(req.getStatus()),
|
||||
"[{}] 是默认存储库,不允许禁用", oldStorage.getName());
|
||||
this.unload(BeanUtil.copyProperties(oldStorage, StorageReq.class));
|
||||
this.load(req);
|
||||
if (DisEnableStatusEnum.ENABLE.equals(oldStorage.getStatus())
|
||||
|| DisEnableStatusEnum.DISABLE.equals(req.getStatus())) {
|
||||
this.unload(BeanUtil.copyProperties(oldStorage, StorageReq.class));
|
||||
}
|
||||
if (DisEnableStatusEnum.ENABLE.equals(req.getStatus())) {
|
||||
this.load(req);
|
||||
}
|
||||
super.update(req, id);
|
||||
}
|
||||
|
||||
@@ -102,7 +109,10 @@ public class StorageServiceImpl
|
||||
public void delete(List<Long> ids) {
|
||||
CheckUtils.throwIf(fileService.countByStorageIds(ids) > 0, "所选存储库存在文件关联,请删除文件后重试");
|
||||
List<StorageDO> storageList = baseMapper.lambdaQuery().in(StorageDO::getId, ids).list();
|
||||
storageList.forEach(s -> this.unload(BeanUtil.copyProperties(s, StorageReq.class)));
|
||||
storageList.forEach(s -> {
|
||||
CheckUtils.throwIfEqual(Boolean.TRUE, s.getIsDefault(), "[{}] 是默认存储库,不允许禁用", s.getName());
|
||||
this.unload(BeanUtil.copyProperties(s, StorageReq.class));
|
||||
});
|
||||
super.delete(ids);
|
||||
}
|
||||
|
||||
@@ -161,6 +171,18 @@ public class StorageServiceImpl
|
||||
this.registerResource(MapUtil.of(URLUtil.url(req.getDomain()).getPath(), req.getBucketName()), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 默认存储库是否存在
|
||||
*
|
||||
* @param id
|
||||
* ID
|
||||
* @return 是否存在
|
||||
*/
|
||||
private boolean isDefaultExists(Long id) {
|
||||
return baseMapper.lambdaQuery().eq(StorageDO::getIsDefault, Boolean.TRUE).ne(null != id, StorageDO::getId, id)
|
||||
.exists();
|
||||
}
|
||||
|
||||
/**
|
||||
* 编码是否存在
|
||||
*
|
||||
|
Reference in New Issue
Block a user