feat(项目管理): 文件管理增加原始文件名

文件管理增加原始文件名
This commit is contained in:
song-tianyang 2024-02-22 14:27:34 +08:00 committed by 刘瑞斌
parent 2c86f9d06a
commit ed47fba038
7 changed files with 112 additions and 11 deletions

View File

@ -77,6 +77,9 @@ public class FileMetadata implements Serializable {
@Schema(description = "文件版本号")
private String fileVersion;
@Schema(description = "原始名(含后缀)")
private String originalName;
private static final long serialVersionUID = 1L;
public enum Column {
@ -97,7 +100,8 @@ public class FileMetadata implements Serializable {
latest("latest", "latest", "BIT", false),
enable("enable", "enable", "BIT", true),
refId("ref_id", "refId", "VARCHAR", false),
fileVersion("file_version", "fileVersion", "VARCHAR", false);
fileVersion("file_version", "fileVersion", "VARCHAR", false),
originalName("original_name", "originalName", "VARCHAR", false);
private static final String BEGINNING_DELIMITER = "`";

View File

@ -1347,6 +1347,76 @@ public class FileMetadataExample {
addCriterion("file_version not between", value1, value2, "fileVersion");
return (Criteria) this;
}
public Criteria andOriginalNameIsNull() {
addCriterion("original_name is null");
return (Criteria) this;
}
public Criteria andOriginalNameIsNotNull() {
addCriterion("original_name is not null");
return (Criteria) this;
}
public Criteria andOriginalNameEqualTo(String value) {
addCriterion("original_name =", value, "originalName");
return (Criteria) this;
}
public Criteria andOriginalNameNotEqualTo(String value) {
addCriterion("original_name <>", value, "originalName");
return (Criteria) this;
}
public Criteria andOriginalNameGreaterThan(String value) {
addCriterion("original_name >", value, "originalName");
return (Criteria) this;
}
public Criteria andOriginalNameGreaterThanOrEqualTo(String value) {
addCriterion("original_name >=", value, "originalName");
return (Criteria) this;
}
public Criteria andOriginalNameLessThan(String value) {
addCriterion("original_name <", value, "originalName");
return (Criteria) this;
}
public Criteria andOriginalNameLessThanOrEqualTo(String value) {
addCriterion("original_name <=", value, "originalName");
return (Criteria) this;
}
public Criteria andOriginalNameLike(String value) {
addCriterion("original_name like", value, "originalName");
return (Criteria) this;
}
public Criteria andOriginalNameNotLike(String value) {
addCriterion("original_name not like", value, "originalName");
return (Criteria) this;
}
public Criteria andOriginalNameIn(List<String> values) {
addCriterion("original_name in", values, "originalName");
return (Criteria) this;
}
public Criteria andOriginalNameNotIn(List<String> values) {
addCriterion("original_name not in", values, "originalName");
return (Criteria) this;
}
public Criteria andOriginalNameBetween(String value1, String value2) {
addCriterion("original_name between", value1, value2, "originalName");
return (Criteria) this;
}
public Criteria andOriginalNameNotBetween(String value1, String value2) {
addCriterion("original_name not between", value1, value2, "originalName");
return (Criteria) this;
}
}
public static class Criteria extends GeneratedCriteria {

View File

@ -20,6 +20,7 @@
<result column="enable" jdbcType="BIT" property="enable" />
<result column="ref_id" jdbcType="VARCHAR" property="refId" />
<result column="file_version" jdbcType="VARCHAR" property="fileVersion" />
<result column="original_name" jdbcType="VARCHAR" property="originalName" />
</resultMap>
<sql id="Example_Where_Clause">
<where>
@ -119,7 +120,8 @@
</sql>
<sql id="Base_Column_List">
id, `name`, `type`, `size`, create_time, update_time, project_id, `storage`, create_user,
update_user, tags, description, module_id, `path`, latest, `enable`, ref_id, file_version
update_user, tags, description, module_id, `path`, latest, `enable`, ref_id, file_version,
original_name
</sql>
<select id="selectByExample" parameterType="io.metersphere.project.domain.FileMetadataExample" resultMap="BaseResultMap">
select
@ -157,15 +159,15 @@
project_id, `storage`, create_user,
update_user, tags,
description, module_id, `path`,
latest, `enable`, ref_id, file_version
)
latest, `enable`, ref_id, file_version,
original_name)
values (#{id,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{type,jdbcType=VARCHAR},
#{size,jdbcType=BIGINT}, #{createTime,jdbcType=BIGINT}, #{updateTime,jdbcType=BIGINT},
#{projectId,jdbcType=VARCHAR}, #{storage,jdbcType=VARCHAR}, #{createUser,jdbcType=VARCHAR},
#{updateUser,jdbcType=VARCHAR}, #{tags,jdbcType=VARCHAR,typeHandler=io.metersphere.handler.ListTypeHandler},
#{description,jdbcType=VARCHAR}, #{moduleId,jdbcType=VARCHAR}, #{path,jdbcType=VARCHAR},
#{latest,jdbcType=BIT}, #{enable,jdbcType=BIT}, #{refId,jdbcType=VARCHAR}, #{fileVersion,jdbcType=VARCHAR}
)
#{latest,jdbcType=BIT}, #{enable,jdbcType=BIT}, #{refId,jdbcType=VARCHAR}, #{fileVersion,jdbcType=VARCHAR},
#{originalName,jdbcType=VARCHAR})
</insert>
<insert id="insertSelective" parameterType="io.metersphere.project.domain.FileMetadata">
insert into file_metadata
@ -224,6 +226,9 @@
<if test="fileVersion != null">
file_version,
</if>
<if test="originalName != null">
original_name,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">
@ -280,6 +285,9 @@
<if test="fileVersion != null">
#{fileVersion,jdbcType=VARCHAR},
</if>
<if test="originalName != null">
#{originalName,jdbcType=VARCHAR},
</if>
</trim>
</insert>
<select id="countByExample" parameterType="io.metersphere.project.domain.FileMetadataExample" resultType="java.lang.Long">
@ -345,6 +353,9 @@
<if test="record.fileVersion != null">
file_version = #{record.fileVersion,jdbcType=VARCHAR},
</if>
<if test="record.originalName != null">
original_name = #{record.originalName,jdbcType=VARCHAR},
</if>
</set>
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
@ -369,7 +380,8 @@
latest = #{record.latest,jdbcType=BIT},
`enable` = #{record.enable,jdbcType=BIT},
ref_id = #{record.refId,jdbcType=VARCHAR},
file_version = #{record.fileVersion,jdbcType=VARCHAR}
file_version = #{record.fileVersion,jdbcType=VARCHAR},
original_name = #{record.originalName,jdbcType=VARCHAR}
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
@ -428,6 +440,9 @@
<if test="fileVersion != null">
file_version = #{fileVersion,jdbcType=VARCHAR},
</if>
<if test="originalName != null">
original_name = #{originalName,jdbcType=VARCHAR},
</if>
</set>
where id = #{id,jdbcType=VARCHAR}
</update>
@ -449,14 +464,15 @@
latest = #{latest,jdbcType=BIT},
`enable` = #{enable,jdbcType=BIT},
ref_id = #{refId,jdbcType=VARCHAR},
file_version = #{fileVersion,jdbcType=VARCHAR}
file_version = #{fileVersion,jdbcType=VARCHAR},
original_name = #{originalName,jdbcType=VARCHAR}
where id = #{id,jdbcType=VARCHAR}
</update>
<insert id="batchInsert" parameterType="map">
insert into file_metadata
(id, `name`, `type`, `size`, create_time, update_time, project_id, `storage`, create_user,
update_user, tags, description, module_id, `path`, latest, `enable`, ref_id, file_version
)
update_user, tags, description, module_id, `path`, latest, `enable`, ref_id, file_version,
original_name)
values
<foreach collection="list" item="item" separator=",">
(#{item.id,jdbcType=VARCHAR}, #{item.name,jdbcType=VARCHAR}, #{item.type,jdbcType=VARCHAR},
@ -465,7 +481,7 @@
#{item.updateUser,jdbcType=VARCHAR}, #{item.tags,jdbcType=VARCHAR,typeHandler=io.metersphere.handler.ListTypeHandler},
#{item.description,jdbcType=VARCHAR}, #{item.moduleId,jdbcType=VARCHAR}, #{item.path,jdbcType=VARCHAR},
#{item.latest,jdbcType=BIT}, #{item.enable,jdbcType=BIT}, #{item.refId,jdbcType=VARCHAR},
#{item.fileVersion,jdbcType=VARCHAR})
#{item.fileVersion,jdbcType=VARCHAR}, #{item.originalName,jdbcType=VARCHAR})
</foreach>
</insert>
<insert id="batchInsertSelective" parameterType="map">
@ -532,6 +548,9 @@
<if test="'file_version'.toString() == column.value">
#{item.fileVersion,jdbcType=VARCHAR}
</if>
<if test="'original_name'.toString() == column.value">
#{item.originalName,jdbcType=VARCHAR}
</if>
</foreach>
)
</foreach>

View File

@ -95,6 +95,7 @@ CREATE TABLE IF NOT EXISTS file_metadata
(
`id` VARCHAR(50) NOT NULL COMMENT '文件ID',
`name` VARCHAR(255) NOT NULL COMMENT '文件名',
`original_name` VARCHAR(255) COMMENT '原始名(含后缀)' ,
`type` VARCHAR(64) COMMENT '文件类型',
`size` BIGINT NOT NULL COMMENT '文件大小',
`create_time` BIGINT NOT NULL COMMENT '创建时间',

View File

@ -19,6 +19,9 @@ public class FileInformationResponse {
@Schema(description = "文件名称")
private String name;
@Schema(description = "原始文件名")
private String originalName;
@Schema(description = "文件类型")
private String fileType;
@ -83,6 +86,7 @@ public class FileInformationResponse {
this.name = fileMetadata.getName();
this.fileType = fileMetadata.getType();
this.description = fileMetadata.getDescription();
this.originalName = fileMetadata.getOriginalName();
this.moduleId = fileMetadata.getModuleId();
this.size = fileMetadata.getSize();
if (CollectionUtils.isNotEmpty(fileMetadata.getTags())) {

View File

@ -5,6 +5,7 @@
<resultMap id="BaseResultMap" type="io.metersphere.project.domain.FileMetadata">
<id column="id" jdbcType="VARCHAR" property="id"/>
<result column="name" jdbcType="VARCHAR" property="name"/>
<result column="original_name" jdbcType="VARCHAR" property="originalName"/>
<result column="type" jdbcType="VARCHAR" property="type"/>
<result column="size" jdbcType="BIGINT" property="size"/>
<result column="create_time" jdbcType="BIGINT" property="createTime"/>

View File

@ -140,10 +140,12 @@ public class FileMetadataService {
private void parseAndSetFileNameType(String filePath, @NotNull FileMetadata fileMetadata) {
String fileName = TempFileUtils.getFileNameByPath(filePath);
if (FileMetadataUtils.isUnknownFile(fileName)) {
fileMetadata.setOriginalName(fileName);
fileMetadata.setName(fileName);
fileMetadata.setType(StringUtils.EMPTY);
} else {
//采用这种判断方式可以避免将隐藏文件的后缀名作为文件类型
fileMetadata.setOriginalName(fileName);
fileMetadata.setName(StringUtils.substring(fileName, 0, fileName.lastIndexOf(".")));
fileMetadata.setType(StringUtils.substring(fileName, fileName.lastIndexOf(".") + 1));
}