From fbb478d19c8416d23ed5476f2f12856bbc9186f2 Mon Sep 17 00:00:00 2001 From: song-tianyang Date: Tue, 9 Jan 2024 10:11:50 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E7=B3=BB=E7=BB=9F=E8=AE=BE=E7=BD=AE):?= =?UTF-8?q?=20=E4=BF=AE=E6=94=B9=E6=96=87=E4=BB=B6=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E7=9A=84tag=E6=95=B0=E6=8D=AE=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../project/domain/FileMetadata.java | 3 +- .../project/domain/FileMetadataExample.java | 86 +++++++++++++------ .../project/mapper/FileMetadataMapper.xml | 72 ++++++++++++---- .../request/FileUpdateRequest.java | 10 +++ .../response/FileInformationResponse.java | 7 +- .../project/service/FileMetadataService.java | 7 +- .../main/resources/projectGeneratorConfig.xml | 9 +- .../FileManagementControllerTests.java | 6 +- 8 files changed, 144 insertions(+), 56 deletions(-) diff --git a/backend/framework/domain/src/main/java/io/metersphere/project/domain/FileMetadata.java b/backend/framework/domain/src/main/java/io/metersphere/project/domain/FileMetadata.java index 20db7dfe7e..2af004ac78 100644 --- a/backend/framework/domain/src/main/java/io/metersphere/project/domain/FileMetadata.java +++ b/backend/framework/domain/src/main/java/io/metersphere/project/domain/FileMetadata.java @@ -6,6 +6,7 @@ import jakarta.validation.constraints.*; import java.io.Serializable; import java.util.ArrayList; import java.util.Arrays; +import java.util.List; import lombok.Data; @Data @@ -50,7 +51,7 @@ public class FileMetadata implements Serializable { private String updateUser; @Schema(description = "标签") - private String tags; + private java.util.List tags; @Schema(description = "描述") private String description; diff --git a/backend/framework/domain/src/main/java/io/metersphere/project/domain/FileMetadataExample.java b/backend/framework/domain/src/main/java/io/metersphere/project/domain/FileMetadataExample.java index d0fd3b2b9e..5c1e2b7fcd 100644 --- a/backend/framework/domain/src/main/java/io/metersphere/project/domain/FileMetadataExample.java +++ b/backend/framework/domain/src/main/java/io/metersphere/project/domain/FileMetadataExample.java @@ -64,19 +64,50 @@ public class FileMetadataExample { } protected abstract static class GeneratedCriteria { + protected List tagsCriteria; + + protected List allCriteria; + protected List criteria; protected GeneratedCriteria() { super(); criteria = new ArrayList(); + tagsCriteria = new ArrayList(); + } + + public List getTagsCriteria() { + return tagsCriteria; + } + + protected void addTagsCriterion(String condition, Object value, String property) { + if (value == null) { + throw new RuntimeException("Value for " + property + " cannot be null"); + } + tagsCriteria.add(new Criterion(condition, value, "io.metersphere.handler.ListTypeHandler")); + allCriteria = null; + } + + protected void addTagsCriterion(String condition, List value1, List value2, String property) { + if (value1 == null || value2 == null) { + throw new RuntimeException("Between values for " + property + " cannot be null"); + } + tagsCriteria.add(new Criterion(condition, value1, value2, "io.metersphere.handler.ListTypeHandler")); + allCriteria = null; } public boolean isValid() { - return criteria.size() > 0; + return criteria.size() > 0 + || tagsCriteria.size() > 0; } public List getAllCriteria() { - return criteria; + if (allCriteria == null) { + allCriteria = new ArrayList(); + allCriteria.addAll(criteria); + allCriteria.addAll(tagsCriteria); + } + return allCriteria; } public List getCriteria() { @@ -88,6 +119,7 @@ public class FileMetadataExample { throw new RuntimeException("Value for condition cannot be null"); } criteria.add(new Criterion(condition)); + allCriteria = null; } protected void addCriterion(String condition, Object value, String property) { @@ -95,6 +127,7 @@ public class FileMetadataExample { throw new RuntimeException("Value for " + property + " cannot be null"); } criteria.add(new Criterion(condition, value)); + allCriteria = null; } protected void addCriterion(String condition, Object value1, Object value2, String property) { @@ -102,6 +135,7 @@ public class FileMetadataExample { throw new RuntimeException("Between values for " + property + " cannot be null"); } criteria.add(new Criterion(condition, value1, value2)); + allCriteria = null; } public Criteria andIdIsNull() { @@ -784,63 +818,63 @@ public class FileMetadataExample { return (Criteria) this; } - public Criteria andTagsEqualTo(String value) { - addCriterion("tags =", value, "tags"); + public Criteria andTagsEqualTo(List value) { + addTagsCriterion("tags =", value, "tags"); return (Criteria) this; } - public Criteria andTagsNotEqualTo(String value) { - addCriterion("tags <>", value, "tags"); + public Criteria andTagsNotEqualTo(List value) { + addTagsCriterion("tags <>", value, "tags"); return (Criteria) this; } - public Criteria andTagsGreaterThan(String value) { - addCriterion("tags >", value, "tags"); + public Criteria andTagsGreaterThan(List value) { + addTagsCriterion("tags >", value, "tags"); return (Criteria) this; } - public Criteria andTagsGreaterThanOrEqualTo(String value) { - addCriterion("tags >=", value, "tags"); + public Criteria andTagsGreaterThanOrEqualTo(List value) { + addTagsCriterion("tags >=", value, "tags"); return (Criteria) this; } - public Criteria andTagsLessThan(String value) { - addCriterion("tags <", value, "tags"); + public Criteria andTagsLessThan(List value) { + addTagsCriterion("tags <", value, "tags"); return (Criteria) this; } - public Criteria andTagsLessThanOrEqualTo(String value) { - addCriterion("tags <=", value, "tags"); + public Criteria andTagsLessThanOrEqualTo(List value) { + addTagsCriterion("tags <=", value, "tags"); return (Criteria) this; } - public Criteria andTagsLike(String value) { - addCriterion("tags like", value, "tags"); + public Criteria andTagsLike(List value) { + addTagsCriterion("tags like", value, "tags"); return (Criteria) this; } - public Criteria andTagsNotLike(String value) { - addCriterion("tags not like", value, "tags"); + public Criteria andTagsNotLike(List value) { + addTagsCriterion("tags not like", value, "tags"); return (Criteria) this; } - public Criteria andTagsIn(List values) { - addCriterion("tags in", values, "tags"); + public Criteria andTagsIn(List> values) { + addTagsCriterion("tags in", values, "tags"); return (Criteria) this; } - public Criteria andTagsNotIn(List values) { - addCriterion("tags not in", values, "tags"); + public Criteria andTagsNotIn(List> values) { + addTagsCriterion("tags not in", values, "tags"); return (Criteria) this; } - public Criteria andTagsBetween(String value1, String value2) { - addCriterion("tags between", value1, value2, "tags"); + public Criteria andTagsBetween(List value1, List value2) { + addTagsCriterion("tags between", value1, value2, "tags"); return (Criteria) this; } - public Criteria andTagsNotBetween(String value1, String value2) { - addCriterion("tags not between", value1, value2, "tags"); + public Criteria andTagsNotBetween(List value1, List value2) { + addTagsCriterion("tags not between", value1, value2, "tags"); return (Criteria) this; } diff --git a/backend/framework/domain/src/main/java/io/metersphere/project/mapper/FileMetadataMapper.xml b/backend/framework/domain/src/main/java/io/metersphere/project/mapper/FileMetadataMapper.xml index 2af30b5174..b03584deb1 100644 --- a/backend/framework/domain/src/main/java/io/metersphere/project/mapper/FileMetadataMapper.xml +++ b/backend/framework/domain/src/main/java/io/metersphere/project/mapper/FileMetadataMapper.xml @@ -12,7 +12,7 @@ - + @@ -45,6 +45,25 @@ + + + + and ${criterion.condition} + + + and ${criterion.condition} #{criterion.value,typeHandler=io.metersphere.handler.ListTypeHandler} + + + and ${criterion.condition} #{criterion.value,typeHandler=io.metersphere.handler.ListTypeHandler} and #{criterion.secondValue,typeHandler=io.metersphere.handler.ListTypeHandler} + + + and ${criterion.condition} + + #{listItem,typeHandler=io.metersphere.handler.ListTypeHandler} + + + + @@ -74,6 +93,25 @@ + + + + and ${criterion.condition} + + + and ${criterion.condition} #{criterion.value,typeHandler=io.metersphere.handler.ListTypeHandler} + + + and ${criterion.condition} #{criterion.value,typeHandler=io.metersphere.handler.ListTypeHandler} and #{criterion.secondValue,typeHandler=io.metersphere.handler.ListTypeHandler} + + + and ${criterion.condition} + + #{listItem,typeHandler=io.metersphere.handler.ListTypeHandler} + + + + @@ -117,16 +155,16 @@ 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 ) 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}, #{description,jdbcType=VARCHAR}, - #{moduleId,jdbcType=VARCHAR}, #{path,jdbcType=VARCHAR}, #{latest,jdbcType=BIT}, - #{enable,jdbcType=BIT}, #{refId,jdbcType=VARCHAR}, #{fileVersion,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} ) @@ -219,7 +257,7 @@ #{updateUser,jdbcType=VARCHAR}, - #{tags,jdbcType=VARCHAR}, + #{tags,jdbcType=VARCHAR,typeHandler=io.metersphere.handler.ListTypeHandler}, #{description,jdbcType=VARCHAR}, @@ -284,7 +322,7 @@ update_user = #{record.updateUser,jdbcType=VARCHAR}, - tags = #{record.tags,jdbcType=VARCHAR}, + tags = #{record.tags,jdbcType=VARCHAR,typeHandler=io.metersphere.handler.ListTypeHandler}, description = #{record.description,jdbcType=VARCHAR}, @@ -324,7 +362,7 @@ `storage` = #{record.storage,jdbcType=VARCHAR}, create_user = #{record.createUser,jdbcType=VARCHAR}, update_user = #{record.updateUser,jdbcType=VARCHAR}, - tags = #{record.tags,jdbcType=VARCHAR}, + tags = #{record.tags,jdbcType=VARCHAR,typeHandler=io.metersphere.handler.ListTypeHandler}, description = #{record.description,jdbcType=VARCHAR}, module_id = #{record.moduleId,jdbcType=VARCHAR}, `path` = #{record.path,jdbcType=VARCHAR}, @@ -367,7 +405,7 @@ update_user = #{updateUser,jdbcType=VARCHAR}, - tags = #{tags,jdbcType=VARCHAR}, + tags = #{tags,jdbcType=VARCHAR,typeHandler=io.metersphere.handler.ListTypeHandler}, description = #{description,jdbcType=VARCHAR}, @@ -404,7 +442,7 @@ `storage` = #{storage,jdbcType=VARCHAR}, create_user = #{createUser,jdbcType=VARCHAR}, update_user = #{updateUser,jdbcType=VARCHAR}, - tags = #{tags,jdbcType=VARCHAR}, + tags = #{tags,jdbcType=VARCHAR,typeHandler=io.metersphere.handler.ListTypeHandler}, description = #{description,jdbcType=VARCHAR}, module_id = #{moduleId,jdbcType=VARCHAR}, `path` = #{path,jdbcType=VARCHAR}, @@ -424,10 +462,10 @@ (#{item.id,jdbcType=VARCHAR}, #{item.name,jdbcType=VARCHAR}, #{item.type,jdbcType=VARCHAR}, #{item.size,jdbcType=BIGINT}, #{item.createTime,jdbcType=BIGINT}, #{item.updateTime,jdbcType=BIGINT}, #{item.projectId,jdbcType=VARCHAR}, #{item.storage,jdbcType=VARCHAR}, #{item.createUser,jdbcType=VARCHAR}, - #{item.updateUser,jdbcType=VARCHAR}, #{item.tags,jdbcType=VARCHAR}, #{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.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}) @@ -471,7 +509,7 @@ #{item.updateUser,jdbcType=VARCHAR} - #{item.tags,jdbcType=VARCHAR} + #{item.tags,jdbcType=VARCHAR,typeHandler=io.metersphere.handler.ListTypeHandler} #{item.description,jdbcType=VARCHAR} diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/dto/filemanagement/request/FileUpdateRequest.java b/backend/services/project-management/src/main/java/io/metersphere/project/dto/filemanagement/request/FileUpdateRequest.java index 6ab94480b8..a9e0fe1724 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/dto/filemanagement/request/FileUpdateRequest.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/dto/filemanagement/request/FileUpdateRequest.java @@ -4,7 +4,9 @@ import io.swagger.v3.oas.annotations.media.Schema; import jakarta.validation.constraints.NotBlank; import lombok.Data; +import java.util.ArrayList; import java.util.LinkedHashSet; +import java.util.List; @Data public class FileUpdateRequest { @@ -29,4 +31,12 @@ public class FileUpdateRequest { @Schema(description = "开启/关闭(目前用于jar文件)") private Boolean enable; + + public List getTags() { + if (tags == null) { + return null; + } else { + return new ArrayList<>(tags); + } + } } diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/dto/filemanagement/response/FileInformationResponse.java b/backend/services/project-management/src/main/java/io/metersphere/project/dto/filemanagement/response/FileInformationResponse.java index 526e23091b..a7b72708e0 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/dto/filemanagement/response/FileInformationResponse.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/dto/filemanagement/response/FileInformationResponse.java @@ -2,11 +2,10 @@ package io.metersphere.project.dto.filemanagement.response; import io.metersphere.project.domain.FileMetadata; import io.metersphere.project.domain.FileMetadataRepository; -import io.metersphere.sdk.util.JSON; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; import lombok.NoArgsConstructor; -import org.apache.commons.lang3.StringUtils; +import org.apache.commons.collections4.CollectionUtils; import java.util.ArrayList; import java.util.List; @@ -86,8 +85,8 @@ public class FileInformationResponse { this.description = fileMetadata.getDescription(); this.moduleId = fileMetadata.getModuleId(); this.size = fileMetadata.getSize(); - if (StringUtils.isNotBlank(fileMetadata.getTags())) { - tags = JSON.parseArray(fileMetadata.getTags(), String.class); + if (CollectionUtils.isNotEmpty(fileMetadata.getTags())) { + tags = fileMetadata.getTags(); } this.enable = fileMetadata.getEnable(); this.createTime = fileMetadata.getCreateTime(); diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/service/FileMetadataService.java b/backend/services/project-management/src/main/java/io/metersphere/project/service/FileMetadataService.java index a013b5cbb8..80c610ee69 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/service/FileMetadataService.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/service/FileMetadataService.java @@ -22,7 +22,10 @@ import io.metersphere.sdk.exception.MSException; import io.metersphere.sdk.file.FileRepository; import io.metersphere.sdk.file.FileRequest; import io.metersphere.sdk.file.MinioRepository; -import io.metersphere.sdk.util.*; +import io.metersphere.sdk.util.CommonBeanFactory; +import io.metersphere.sdk.util.GitRepositoryUtil; +import io.metersphere.sdk.util.TempFileUtils; +import io.metersphere.sdk.util.Translator; import io.metersphere.system.mapper.BaseUserMapper; import io.metersphere.system.uid.IDGenerator; import io.metersphere.system.utils.PageUtils; @@ -358,7 +361,7 @@ public class FileMetadataService { updateExample.setName(request.getName()); } if (request.getTags() != null) { - updateExample.setTags(JSON.toJSONString(request.getTags())); + updateExample.setTags(request.getTags()); } else { updateExample.setTags(null); } diff --git a/backend/services/project-management/src/main/resources/projectGeneratorConfig.xml b/backend/services/project-management/src/main/resources/projectGeneratorConfig.xml index 16ea919ce9..b0b6a2d8fd 100644 --- a/backend/services/project-management/src/main/resources/projectGeneratorConfig.xml +++ b/backend/services/project-management/src/main/resources/projectGeneratorConfig.xml @@ -72,9 +72,12 @@ - - -
+
+ +
+ + diff --git a/backend/services/project-management/src/test/java/io/metersphere/project/controller/filemanagement/FileManagementControllerTests.java b/backend/services/project-management/src/test/java/io/metersphere/project/controller/filemanagement/FileManagementControllerTests.java index d49f960555..49cfc203fd 100644 --- a/backend/services/project-management/src/test/java/io/metersphere/project/controller/filemanagement/FileManagementControllerTests.java +++ b/backend/services/project-management/src/test/java/io/metersphere/project/controller/filemanagement/FileManagementControllerTests.java @@ -2428,10 +2428,10 @@ public class FileManagementControllerTests extends BaseTest { } if (updateRequest.getTags() != null) { - Assertions.assertTrue(CollectionUtils.isEqualCollection(JSON.parseArray(fileMetadata.getTags(), String.class), updateRequest.getTags())); + Assertions.assertTrue(CollectionUtils.isEqualCollection(fileMetadata.getTags(), updateRequest.getTags())); } else { - List fileTags = fileMetadata.getTags() == null ? new ArrayList<>() : JSON.parseArray(fileMetadata.getTags(), String.class); - List oldTags = oldFileMetadata.getTags() == null ? new ArrayList<>() : JSON.parseArray(oldFileMetadata.getTags(), String.class); + List fileTags = fileMetadata.getTags() == null ? new ArrayList<>() : fileMetadata.getTags(); + List oldTags = oldFileMetadata.getTags() == null ? new ArrayList<>() : oldFileMetadata.getTags(); Assertions.assertTrue(CollectionUtils.isEqualCollection(fileTags, oldTags)); } }