mirror of
https://github.com/continew-org/continew-admin.git
synced 2025-09-21 18:57:12 +08:00
refactor(system): 优化文件相关类的属性顺序和注释,增强代码可读性
- 优化文件相关类的属性顺序和注释,增强代码可读性 - 优化 File、Message 相关代码的包结构
This commit is contained in:
@@ -65,17 +65,8 @@ public class FileRecorderImpl implements FileRecorder {
|
||||
: originalFilename);
|
||||
file.setUrl(fileInfo.getUrl());
|
||||
file.setSize(fileInfo.getSize());
|
||||
file.setExtension(fileInfo.getExt());
|
||||
file.setType(FileTypeEnum.getByExtension(file.getExtension()));
|
||||
file.setThumbnailUrl(fileInfo.getThUrl());
|
||||
file.setThumbnailSize(fileInfo.getThSize());
|
||||
StorageDO storage = (StorageDO) fileInfo.getAttr().get(ClassUtil.getClassName(StorageDO.class, false));
|
||||
file.setStorageId(storage.getId());
|
||||
file.setCreateTime(DateUtil.toLocalDateTime(fileInfo.getCreateTime()));
|
||||
file.setUpdateUser(UserContextHolder.getUserId());
|
||||
file.setUpdateTime(file.getCreateTime());
|
||||
String absPath = fileInfo.getPath();
|
||||
if (absPath.endsWith("/")) {
|
||||
if (absPath.endsWith(StringConstants.SLASH)) {
|
||||
String tempAbsPath = absPath.substring(0, absPath.length() - 1);
|
||||
String[] pathArr = tempAbsPath.split(StringConstants.SLASH);
|
||||
if (pathArr.length > 1) {
|
||||
@@ -84,11 +75,20 @@ public class FileRecorderImpl implements FileRecorder {
|
||||
file.setParentPath(StringConstants.SLASH);
|
||||
}
|
||||
}
|
||||
file.setMd5(fileInfo.getHashInfo().getMd5());
|
||||
file.setAbsPath(fileInfo.getPath());
|
||||
file.setMetadata(JSONUtil.toJsonStr(fileInfo.getMetadata()));
|
||||
file.setThumbnailMetadata(JSONUtil.toJsonStr(fileInfo.getThMetadata()));
|
||||
file.setExtension(fileInfo.getExt());
|
||||
file.setType(FileTypeEnum.getByExtension(file.getExtension()));
|
||||
file.setContentType(fileInfo.getContentType());
|
||||
file.setMd5(fileInfo.getHashInfo().getMd5());
|
||||
file.setMetadata(JSONUtil.toJsonStr(fileInfo.getMetadata()));
|
||||
file.setThumbnailUrl(fileInfo.getThUrl());
|
||||
file.setThumbnailSize(fileInfo.getThSize());
|
||||
file.setThumbnailMetadata(JSONUtil.toJsonStr(fileInfo.getThMetadata()));
|
||||
StorageDO storage = (StorageDO)fileInfo.getAttr().get(ClassUtil.getClassName(StorageDO.class, false));
|
||||
file.setStorageId(storage.getId());
|
||||
file.setCreateTime(DateUtil.toLocalDateTime(fileInfo.getCreateTime()));
|
||||
file.setUpdateUser(UserContextHolder.getUserId());
|
||||
file.setUpdateTime(file.getCreateTime());
|
||||
fileMapper.insert(file);
|
||||
return true;
|
||||
}
|
||||
|
@@ -64,8 +64,7 @@ public enum FileTypeEnum implements BaseEnum<Integer> {
|
||||
/**
|
||||
* 音频
|
||||
*/
|
||||
AUDIO(5, "音频", List.of("mp3", "flac", "wav", "ogg", "midi", "m4a", "aac", "amr", "ac3", "aiff")),
|
||||
;
|
||||
AUDIO(5, "音频", List.of("mp3", "flac", "wav", "ogg", "midi", "m4a", "aac", "amr", "ac3", "aiff")),;
|
||||
|
||||
private final Integer value;
|
||||
private final String description;
|
||||
|
@@ -18,7 +18,7 @@ package top.continew.admin.system.mapper;
|
||||
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
import top.continew.admin.system.model.entity.FileDO;
|
||||
import top.continew.admin.system.model.resp.FileStatisticsResp;
|
||||
import top.continew.admin.system.model.resp.file.FileStatisticsResp;
|
||||
import top.continew.starter.data.mp.base.BaseMapper;
|
||||
|
||||
import java.util.List;
|
||||
|
@@ -21,7 +21,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Constants;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import top.continew.admin.system.model.entity.MessageDO;
|
||||
import top.continew.admin.system.model.resp.MessageResp;
|
||||
import top.continew.admin.system.model.resp.message.MessageResp;
|
||||
import top.continew.starter.data.mp.base.BaseMapper;
|
||||
|
||||
/**
|
||||
|
@@ -70,31 +70,31 @@ public class FileDO extends BaseDO {
|
||||
*/
|
||||
private String absPath;
|
||||
|
||||
/**
|
||||
* 文件元数据
|
||||
*/
|
||||
private String metadata;
|
||||
|
||||
/**
|
||||
* 文件类型
|
||||
*/
|
||||
private String contentType;
|
||||
|
||||
/**
|
||||
* 文件md5值
|
||||
*/
|
||||
private String md5;
|
||||
|
||||
/**
|
||||
* 扩展名
|
||||
*/
|
||||
private String extension;
|
||||
|
||||
/**
|
||||
* 内容类型
|
||||
*/
|
||||
private String contentType;
|
||||
|
||||
/**
|
||||
* 类型
|
||||
*/
|
||||
private FileTypeEnum type;
|
||||
|
||||
/**
|
||||
* MD5 值
|
||||
*/
|
||||
private String md5;
|
||||
|
||||
/**
|
||||
* 元数据
|
||||
*/
|
||||
private String metadata;
|
||||
|
||||
/**
|
||||
* 缩略图大小(字节)
|
||||
*/
|
||||
@@ -106,7 +106,7 @@ public class FileDO extends BaseDO {
|
||||
private String thumbnailUrl;
|
||||
|
||||
/**
|
||||
* 文件元数据
|
||||
* 缩略图元数据
|
||||
*/
|
||||
private String thumbnailMetadata;
|
||||
|
||||
|
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package top.continew.admin.system.model.resp;
|
||||
package top.continew.admin.system.model.resp.file;
|
||||
|
||||
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
@@ -68,36 +68,36 @@ public class FileResp extends BaseDetailResp {
|
||||
@Schema(description = "绝对路径", example = "/2025/2/25")
|
||||
private String absPath;
|
||||
|
||||
/**
|
||||
* 文件元数据
|
||||
*/
|
||||
@Schema(description = "文件元数据", example = "{width:1024,height:1024}")
|
||||
private String metadata;
|
||||
|
||||
/**
|
||||
* 文件md5值
|
||||
*/
|
||||
@Schema(description = "文件md5值", example = "abcdefghijklmnopqrstuvwxyz0123456789")
|
||||
private String md5;
|
||||
|
||||
/**
|
||||
* 文件类型
|
||||
*/
|
||||
@Schema(description = "文件md5值", example = "abcdefghijklmnopqrstuvwxyz0123456789")
|
||||
private String contentType;
|
||||
|
||||
/**
|
||||
* 扩展名
|
||||
*/
|
||||
@Schema(description = "扩展名", example = "jpg")
|
||||
private String extension;
|
||||
|
||||
/**
|
||||
* 内容类型
|
||||
*/
|
||||
@Schema(description = "内容类型", example = "image/jpeg")
|
||||
private String contentType;
|
||||
|
||||
/**
|
||||
* 类型
|
||||
*/
|
||||
@Schema(description = "类型", example = "2")
|
||||
private FileTypeEnum type;
|
||||
|
||||
/**
|
||||
* MD5 值
|
||||
*/
|
||||
@Schema(description = "MD5值", example = "193572f83684128a0d0f993e97100f8a")
|
||||
private String md5;
|
||||
|
||||
/**
|
||||
* 元数据
|
||||
*/
|
||||
@Schema(description = "元数据", example = "{width:1024,height:1024}")
|
||||
private String metadata;
|
||||
|
||||
/**
|
||||
* 缩略图大小(字节)
|
||||
*/
|
||||
@@ -111,7 +111,7 @@ public class FileResp extends BaseDetailResp {
|
||||
private String thumbnailUrl;
|
||||
|
||||
/**
|
||||
* 缩略图文件元数据
|
||||
* 缩略图元数据
|
||||
*/
|
||||
@Schema(description = "缩略图文件元数据", example = "{width:100,height:100}")
|
||||
private String thumbnailMetadata;
|
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package top.continew.admin.system.model.resp;
|
||||
package top.continew.admin.system.model.resp.file;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package top.continew.admin.system.model.resp;
|
||||
package top.continew.admin.system.model.resp.file;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Builder;
|
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package top.continew.admin.system.model.resp;
|
||||
package top.continew.admin.system.model.resp.message;
|
||||
|
||||
import cn.crane4j.annotation.Assemble;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package top.continew.admin.system.model.resp;
|
||||
package top.continew.admin.system.model.resp.message;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package top.continew.admin.system.model.resp;
|
||||
package top.continew.admin.system.model.resp.message;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
@@ -21,8 +21,8 @@ import org.springframework.web.multipart.MultipartFile;
|
||||
import top.continew.admin.system.model.entity.FileDO;
|
||||
import top.continew.admin.system.model.query.FileQuery;
|
||||
import top.continew.admin.system.model.req.FileReq;
|
||||
import top.continew.admin.system.model.resp.FileResp;
|
||||
import top.continew.admin.system.model.resp.FileStatisticsResp;
|
||||
import top.continew.admin.system.model.resp.file.FileResp;
|
||||
import top.continew.admin.system.model.resp.file.FileStatisticsResp;
|
||||
import top.continew.starter.data.mp.service.IService;
|
||||
import top.continew.starter.extension.crud.service.BaseService;
|
||||
|
||||
|
@@ -18,7 +18,7 @@ package top.continew.admin.system.service;
|
||||
|
||||
import top.continew.admin.system.model.query.MessageQuery;
|
||||
import top.continew.admin.system.model.req.MessageReq;
|
||||
import top.continew.admin.system.model.resp.MessageResp;
|
||||
import top.continew.admin.system.model.resp.message.MessageResp;
|
||||
import top.continew.starter.extension.crud.model.query.PageQuery;
|
||||
import top.continew.starter.extension.crud.model.resp.PageResp;
|
||||
|
||||
|
@@ -16,7 +16,7 @@
|
||||
|
||||
package top.continew.admin.system.service;
|
||||
|
||||
import top.continew.admin.system.model.resp.MessageUnreadResp;
|
||||
import top.continew.admin.system.model.resp.message.MessageUnreadResp;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@@ -36,8 +36,8 @@ import top.continew.admin.system.model.entity.FileDO;
|
||||
import top.continew.admin.system.model.entity.StorageDO;
|
||||
import top.continew.admin.system.model.query.FileQuery;
|
||||
import top.continew.admin.system.model.req.FileReq;
|
||||
import top.continew.admin.system.model.resp.FileResp;
|
||||
import top.continew.admin.system.model.resp.FileStatisticsResp;
|
||||
import top.continew.admin.system.model.resp.file.FileResp;
|
||||
import top.continew.admin.system.model.resp.file.FileStatisticsResp;
|
||||
import top.continew.admin.system.service.FileService;
|
||||
import top.continew.admin.system.service.StorageService;
|
||||
import top.continew.starter.core.constant.StringConstants;
|
||||
|
@@ -29,7 +29,7 @@ import top.continew.admin.system.mapper.MessageMapper;
|
||||
import top.continew.admin.system.model.entity.MessageDO;
|
||||
import top.continew.admin.system.model.query.MessageQuery;
|
||||
import top.continew.admin.system.model.req.MessageReq;
|
||||
import top.continew.admin.system.model.resp.MessageResp;
|
||||
import top.continew.admin.system.model.resp.message.MessageResp;
|
||||
import top.continew.admin.system.service.MessageService;
|
||||
import top.continew.admin.system.service.MessageUserService;
|
||||
import top.continew.starter.core.validation.CheckUtils;
|
||||
|
@@ -22,8 +22,8 @@ import org.springframework.stereotype.Service;
|
||||
import top.continew.admin.system.enums.MessageTypeEnum;
|
||||
import top.continew.admin.system.mapper.MessageUserMapper;
|
||||
import top.continew.admin.system.model.entity.MessageUserDO;
|
||||
import top.continew.admin.system.model.resp.MessageTypeUnreadResp;
|
||||
import top.continew.admin.system.model.resp.MessageUnreadResp;
|
||||
import top.continew.admin.system.model.resp.message.MessageTypeUnreadResp;
|
||||
import top.continew.admin.system.model.resp.message.MessageUnreadResp;
|
||||
import top.continew.admin.system.service.MessageUserService;
|
||||
import top.continew.starter.core.validation.CheckUtils;
|
||||
|
||||
|
@@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||
<mapper namespace="top.continew.admin.system.mapper.MessageMapper">
|
||||
<select id="selectPageByUserId" resultType="top.continew.admin.system.model.resp.MessageResp">
|
||||
<select id="selectPageByUserId" resultType="top.continew.admin.system.model.resp.message.MessageResp">
|
||||
SELECT
|
||||
t1.*,
|
||||
t2.user_id,
|
||||
|
@@ -33,7 +33,7 @@ import org.springframework.web.multipart.MultipartFile;
|
||||
import top.continew.admin.common.constant.CacheConstants;
|
||||
import top.continew.admin.system.enums.OptionCategoryEnum;
|
||||
import top.continew.admin.system.model.query.*;
|
||||
import top.continew.admin.system.model.resp.FileUploadResp;
|
||||
import top.continew.admin.system.model.resp.file.FileUploadResp;
|
||||
import top.continew.admin.system.service.*;
|
||||
import top.continew.starter.core.validation.ValidationUtils;
|
||||
import top.continew.starter.extension.crud.model.query.SortQuery;
|
||||
|
@@ -25,8 +25,8 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
import top.continew.admin.common.controller.BaseController;
|
||||
import top.continew.admin.system.model.query.FileQuery;
|
||||
import top.continew.admin.system.model.req.FileReq;
|
||||
import top.continew.admin.system.model.resp.FileResp;
|
||||
import top.continew.admin.system.model.resp.FileStatisticsResp;
|
||||
import top.continew.admin.system.model.resp.file.FileResp;
|
||||
import top.continew.admin.system.model.resp.file.FileStatisticsResp;
|
||||
import top.continew.admin.system.service.FileService;
|
||||
import top.continew.starter.extension.crud.annotation.CrudRequestMapping;
|
||||
import top.continew.starter.extension.crud.enums.Api;
|
||||
|
@@ -25,8 +25,8 @@ import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import top.continew.admin.common.context.UserContextHolder;
|
||||
import top.continew.admin.system.model.query.MessageQuery;
|
||||
import top.continew.admin.system.model.resp.MessageResp;
|
||||
import top.continew.admin.system.model.resp.MessageUnreadResp;
|
||||
import top.continew.admin.system.model.resp.message.MessageResp;
|
||||
import top.continew.admin.system.model.resp.message.MessageUnreadResp;
|
||||
import top.continew.admin.system.service.MessageService;
|
||||
import top.continew.admin.system.service.MessageUserService;
|
||||
import top.continew.starter.extension.crud.model.query.PageQuery;
|
||||
|
@@ -281,16 +281,16 @@ CREATE TABLE IF NOT EXISTS `sys_file` (
|
||||
`name` varchar(255) NOT NULL COMMENT '名称',
|
||||
`size` bigint(20) NOT NULL COMMENT '大小(字节)',
|
||||
`url` varchar(512) NOT NULL COMMENT 'URL',
|
||||
`parent_path` varchar(512) NOT NULL COMMENT '上级目录',
|
||||
`parent_path` varchar(512) DEFAULT '/' COMMENT '上级目录',
|
||||
`abs_path` varchar(1024) NOT NULL COMMENT '绝对路径',
|
||||
`extension` varchar(100) DEFAULT NULL COMMENT '扩展名',
|
||||
`metadata` TEXT NOT NULL COMMENT '元数据',
|
||||
`content_type` varchar(64) NOT NULL COMMENT '文件类型',
|
||||
`md5` varchar(128) NOT NULL COMMENT '文件md5值',
|
||||
`content_type` varchar(64) NOT NULL COMMENT '内容类型',
|
||||
`type` tinyint(1) UNSIGNED NOT NULL DEFAULT 1 COMMENT '类型(0: 目录;1:其他;2:图片;3:文档;4:视频;5:音频)',
|
||||
`md5` varchar(128) NOT NULL COMMENT 'MD5值',
|
||||
`metadata` text DEFAULT NULL COMMENT '元数据',
|
||||
`thumbnail_size` bigint(20) DEFAULT NULL COMMENT '缩略图大小(字节)',
|
||||
`thumbnail_url` varchar(512) DEFAULT NULL COMMENT '缩略图URL',
|
||||
`thumbnail_metadata` TEXT COMMENT '元数据',
|
||||
`type` tinyint(1) UNSIGNED NOT NULL DEFAULT 1 COMMENT '类型(0: 目录;1:其他;2:图片;3:文档;4:视频;5:音频)',
|
||||
`thumbnail_metadata` text DEFAULT NULL COMMENT '缩略图元数据',
|
||||
`storage_id` bigint(20) NOT NULL COMMENT '存储ID',
|
||||
`create_user` bigint(20) NOT NULL COMMENT '创建人',
|
||||
`create_time` datetime NOT NULL COMMENT '创建时间',
|
||||
@@ -298,8 +298,8 @@ CREATE TABLE IF NOT EXISTS `sys_file` (
|
||||
`update_time` datetime NOT NULL COMMENT '修改时间',
|
||||
PRIMARY KEY (`id`),
|
||||
INDEX `idx_url`(`url`),
|
||||
INDEX `idx_md5`(`md5`),
|
||||
INDEX `idx_type`(`type`),
|
||||
INDEX `idx_sys_file_md5`(`md5`),
|
||||
INDEX `idx_create_user`(`create_user`),
|
||||
INDEX `idx_update_user`(`update_user`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='文件表';
|
||||
|
@@ -467,16 +467,16 @@ CREATE TABLE IF NOT EXISTS "sys_file" (
|
||||
"name" varchar(255) NOT NULL,
|
||||
"size" int8 NOT NULL,
|
||||
"url" varchar(512) NOT NULL,
|
||||
"parent_path" varchar(512) NOT NULL default '/',
|
||||
"parent_path" varchar(512) NOT NULL DEFAULT '/',
|
||||
"abs_path" varchar(512) NOT NULL,
|
||||
"extension" varchar(100) DEFAULT NULL,
|
||||
"metadata" varchar(10000) NOT NULL DEFAULT '',
|
||||
"content_type" varchar(64) NOT NULL,
|
||||
"md5" varchar(128) NOT NULL DEFAULT '',
|
||||
"type" int2 NOT NULL DEFAULT 1,
|
||||
"md5" varchar(128) NOT NULL,
|
||||
"metadata" text DEFAULT NULL,
|
||||
"thumbnail_size" int8 DEFAULT NULL,
|
||||
"thumbnail_url" varchar(512) DEFAULT NULL,
|
||||
"thumbnail_metadata" varchar(10000) DEFAULT NULL,
|
||||
"type" int2 NOT NULL DEFAULT 1,
|
||||
"thumbnail_metadata" text DEFAULT NULL,
|
||||
"storage_id" int8 NOT NULL,
|
||||
"create_user" int8 NOT NULL,
|
||||
"create_time" timestamp NOT NULL,
|
||||
@@ -486,9 +486,9 @@ CREATE TABLE IF NOT EXISTS "sys_file" (
|
||||
);
|
||||
CREATE INDEX "idx_file_url" ON "sys_file" ("url");
|
||||
CREATE INDEX "idx_file_type" ON "sys_file" ("type");
|
||||
CREATE INDEX "idx_file_md5" ON "sys_file" ("md5");
|
||||
CREATE INDEX "idx_file_create_user" ON "sys_file" ("create_user");
|
||||
CREATE INDEX "idx_file_update_user" ON "sys_file" ("update_user");
|
||||
CREATE INDEX "idx_sys_file_md5" ON "sys_file" ("md5");
|
||||
COMMENT ON COLUMN "sys_file"."id" IS 'ID';
|
||||
COMMENT ON COLUMN "sys_file"."name" IS '名称';
|
||||
COMMENT ON COLUMN "sys_file"."size" IS '大小(字节)';
|
||||
@@ -496,12 +496,13 @@ COMMENT ON COLUMN "sys_file"."url" IS 'URL';
|
||||
COMMENT ON COLUMN "sys_file"."parent_path" IS '上级目录';
|
||||
COMMENT ON COLUMN "sys_file"."abs_path" IS '绝对路径';
|
||||
COMMENT ON COLUMN "sys_file"."extension" IS '扩展名';
|
||||
COMMENT ON COLUMN "sys_file"."content_type" IS '内容类型';
|
||||
COMMENT ON COLUMN "sys_file"."type" IS '类型(0: 目录;1:其他;2:图片;3:文档;4:视频;5:音频)';
|
||||
COMMENT ON COLUMN "sys_file"."md5" IS 'MD5值';
|
||||
COMMENT ON COLUMN "sys_file"."metadata" IS '元数据';
|
||||
COMMENT ON COLUMN "sys_file"."thumbnail_size" IS '缩略图大小(字节)';
|
||||
COMMENT ON COLUMN "sys_file"."thumbnail_url" IS '缩略图URL';
|
||||
COMMENT ON COLUMN "sys_file"."type" IS '类型(0: 目录;1:其他;2:图片;3:文档;4:视频;5:音频)';
|
||||
COMMENT ON COLUMN "sys_file"."metadata" IS '元数据';
|
||||
COMMENT ON COLUMN "sys_file"."content_type" IS '文件类型';
|
||||
COMMENT ON COLUMN "sys_file"."md5" IS '文件md5值';
|
||||
COMMENT ON COLUMN "sys_file"."thumbnail_metadata" IS '缩略图元数据';
|
||||
COMMENT ON COLUMN "sys_file"."storage_id" IS '存储ID';
|
||||
COMMENT ON COLUMN "sys_file"."create_user" IS '创建人';
|
||||
COMMENT ON COLUMN "sys_file"."create_time" IS '创建时间';
|
||||
|
Reference in New Issue
Block a user