diff --git a/continew-admin-system/src/main/java/top/charles7c/continew/admin/system/model/entity/StorageDO.java b/continew-admin-system/src/main/java/top/charles7c/continew/admin/system/model/entity/StorageDO.java index bbe16eb8..3dc7b1e0 100644 --- a/continew-admin-system/src/main/java/top/charles7c/continew/admin/system/model/entity/StorageDO.java +++ b/continew-admin-system/src/main/java/top/charles7c/continew/admin/system/model/entity/StorageDO.java @@ -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; } \ No newline at end of file diff --git a/continew-admin-system/src/main/java/top/charles7c/continew/admin/system/model/req/StorageReq.java b/continew-admin-system/src/main/java/top/charles7c/continew/admin/system/model/req/StorageReq.java index 644a4c6e..aaedc5b8 100644 --- a/continew-admin-system/src/main/java/top/charles7c/continew/admin/system/model/req/StorageReq.java +++ b/continew-admin-system/src/main/java/top/charles7c/continew/admin/system/model/req/StorageReq.java @@ -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; /** diff --git a/continew-admin-system/src/main/java/top/charles7c/continew/admin/system/model/resp/FileResp.java b/continew-admin-system/src/main/java/top/charles7c/continew/admin/system/model/resp/FileResp.java index 51344031..d903e25f 100644 --- a/continew-admin-system/src/main/java/top/charles7c/continew/admin/system/model/resp/FileResp.java +++ b/continew-admin-system/src/main/java/top/charles7c/continew/admin/system/model/resp/FileResp.java @@ -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; } \ No newline at end of file diff --git a/continew-admin-system/src/main/java/top/charles7c/continew/admin/system/model/resp/StorageDetailResp.java b/continew-admin-system/src/main/java/top/charles7c/continew/admin/system/model/resp/StorageDetailResp.java index 143634a5..3146d25d 100644 --- a/continew-admin-system/src/main/java/top/charles7c/continew/admin/system/model/resp/StorageDetailResp.java +++ b/continew-admin-system/src/main/java/top/charles7c/continew/admin/system/model/resp/StorageDetailResp.java @@ -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(); + } } \ No newline at end of file diff --git a/continew-admin-system/src/main/java/top/charles7c/continew/admin/system/model/resp/StorageResp.java b/continew-admin-system/src/main/java/top/charles7c/continew/admin/system/model/resp/StorageResp.java index 50ee4120..6d568a1d 100644 --- a/continew-admin-system/src/main/java/top/charles7c/continew/admin/system/model/resp/StorageResp.java +++ b/continew-admin-system/src/main/java/top/charles7c/continew/admin/system/model/resp/StorageResp.java @@ -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(); + } } \ No newline at end of file diff --git a/continew-admin-system/src/main/java/top/charles7c/continew/admin/system/service/impl/StorageServiceImpl.java b/continew-admin-system/src/main/java/top/charles7c/continew/admin/system/service/impl/StorageServiceImpl.java index 27e61ce1..2fdf6dc1 100644 --- a/continew-admin-system/src/main/java/top/charles7c/continew/admin/system/service/impl/StorageServiceImpl.java +++ b/continew-admin-system/src/main/java/top/charles7c/continew/admin/system/service/impl/StorageServiceImpl.java @@ -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 ids) { CheckUtils.throwIf(fileService.countByStorageIds(ids) > 0, "所选存储库存在文件关联,请删除文件后重试"); List 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(); + } + /** * 编码是否存在 * diff --git a/continew-admin-ui/src/api/system/file.ts b/continew-admin-ui/src/api/system/file.ts index 50d5e306..e9f24a5f 100644 --- a/continew-admin-ui/src/api/system/file.ts +++ b/continew-admin-ui/src/api/system/file.ts @@ -9,7 +9,6 @@ export interface FileItem { size: number; url: string; extension: string; - mimeType?: string; type?: string; storageId?: string; createUser?: string; diff --git a/continew-admin-ui/src/api/system/storage.ts b/continew-admin-ui/src/api/system/storage.ts new file mode 100644 index 00000000..3601ad7f --- /dev/null +++ b/continew-admin-ui/src/api/system/storage.ts @@ -0,0 +1,64 @@ +import axios from 'axios'; +import qs from 'query-string'; + +const BASE_URL = '/system/storage'; + +export interface DataRecord { + id?: number; + name?: string; + code?: string; + type?: number; + accessKey?: string; + secretKey?: string; + endpoint?: string; + bucketName?: string; + domain?: string; + description?: string; + isDefault?: boolean; + sort?: number; + status?: number; + createUser?: string; + createTime?: string; + updateUser?: string; + updateTime?: string; + createUserString?: string; + updateUserString?: string; +} + +export interface ListParam { + name?: string; + status?: string; + page?: number; + size?: number; + sort?: Array; +} + +export interface PageRes { + total: number; + list: T; +} + +export function list(params: ListParam) { + return axios.get>(`${BASE_URL}`, { + params, + paramsSerializer: (obj) => { + return qs.stringify(obj); + }, + }); +} + +export function get(id: number) { + return axios.get(`${BASE_URL}/${id}`); +} + +export function add(req: DataRecord) { + return axios.post(BASE_URL, req); +} + +export function update(req: DataRecord, id: number) { + return axios.put(`${BASE_URL}/${id}`, req); +} + +export function del(ids: number | Array) { + return axios.delete(`${BASE_URL}/${ids}`); +} diff --git a/continew-admin-ui/src/views/system/file/locale/zh-CN.ts b/continew-admin-ui/src/views/system/file/locale/zh-CN.ts index 2c8c9233..e43b850d 100644 --- a/continew-admin-ui/src/views/system/file/locale/zh-CN.ts +++ b/continew-admin-ui/src/views/system/file/locale/zh-CN.ts @@ -1,3 +1,3 @@ export default { - 'menu.system.file.list': '文件管理(尚在开发)', + 'menu.system.file.list': '文件管理', }; diff --git a/continew-admin-ui/src/views/system/file/main/FileMain/FileRightMenu.vue b/continew-admin-ui/src/views/system/file/main/FileMain/FileRightMenu.vue index 02da423f..a57a6956 100644 --- a/continew-admin-ui/src/views/system/file/main/FileMain/FileRightMenu.vue +++ b/continew-admin-ui/src/views/system/file/main/FileMain/FileRightMenu.vue @@ -1,18 +1,18 @@