From be376a4847c94ed2df4d1e7271e4787887a1c3ec Mon Sep 17 00:00:00 2001 From: wxg0103 <727495428@qq.com> Date: Thu, 21 Sep 2023 13:52:00 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E7=B3=BB=E7=BB=9F=E8=AE=BE=E7=BD=AE):?= =?UTF-8?q?=20=E9=A1=B9=E7=9B=AE=E5=A2=9E=E5=8A=A0=E8=B5=84=E6=BA=90?= =?UTF-8?q?=E6=B1=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/ProjectTestResourcePool.java | 99 +++++ .../ProjectTestResourcePoolExample.java | 340 ++++++++++++++++++ .../mapper/ProjectTestResourcePoolMapper.java | 28 ++ .../mapper/ProjectTestResourcePoolMapper.xml | 173 +++++++++ .../ddl/V3.0.0_4__project_management.sql | 10 + .../metersphere/sdk/constants/ModuleType.java | 8 + .../sdk/dto/ProjectBaseRequest.java | 6 + .../metersphere/sdk/dto/ProjectExtendDTO.java | 16 - .../resources/i18n/project_en_US.properties | 2 + .../resources/i18n/project_zh_CN.properties | 1 + .../resources/i18n/project_zh_TW.properties | 2 + .../project/controller/ProjectController.java | 52 +-- .../project/service/ProjectLogService.java | 68 +--- .../project/service/ProjectService.java | 112 +++--- .../main/resources/projectGeneratorConfig.xml | 1 + .../controller/ProjectControllerTests.java | 116 ++---- .../src/test/resources/dml/init_project.sql | 14 +- .../OrganizationProjectController.java | 17 +- .../SystemOrganizationController.java | 2 +- .../controller/SystemProjectController.java | 24 +- .../system}/dto/AddProjectRequest.java | 8 +- .../metersphere/system}/dto/ProjectDTO.java | 5 +- .../system/dto/ProjectResourcePoolDTO.java | 22 ++ .../system}/dto/UpdateProjectRequest.java | 7 +- .../system/mapper/ExtSystemProjectMapper.java | 5 +- .../system/mapper/ExtSystemProjectMapper.xml | 18 +- .../system/service/CommonProjectService.java | 141 ++++++-- .../OrganizationProjectLogService.java | 4 +- .../service/OrganizationProjectService.java | 14 +- .../service/SystemProjectLogService.java | 4 +- .../system/service/SystemProjectService.java | 21 +- .../service/TestResourcePoolService.java | 17 +- .../OrganizationProjectControllerTests.java | 85 ++++- .../SystemOrganizationControllerTests.java | 2 +- .../SystemProjectControllerTests.java | 81 ++++- .../test/resources/dml/init_org_project.sql | 13 +- .../src/test/resources/dml/init_project.sql | 70 +++- 37 files changed, 1240 insertions(+), 368 deletions(-) create mode 100644 backend/framework/domain/src/main/java/io/metersphere/project/domain/ProjectTestResourcePool.java create mode 100644 backend/framework/domain/src/main/java/io/metersphere/project/domain/ProjectTestResourcePoolExample.java create mode 100644 backend/framework/domain/src/main/java/io/metersphere/project/mapper/ProjectTestResourcePoolMapper.java create mode 100644 backend/framework/domain/src/main/java/io/metersphere/project/mapper/ProjectTestResourcePoolMapper.xml create mode 100644 backend/framework/sdk/src/main/java/io/metersphere/sdk/constants/ModuleType.java delete mode 100644 backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/ProjectExtendDTO.java rename backend/{framework/sdk/src/main/java/io/metersphere/sdk => services/system-setting/src/main/java/io/metersphere/system}/dto/AddProjectRequest.java (70%) rename backend/{framework/sdk/src/main/java/io/metersphere/sdk => services/system-setting/src/main/java/io/metersphere/system}/dto/ProjectDTO.java (82%) create mode 100644 backend/services/system-setting/src/main/java/io/metersphere/system/dto/ProjectResourcePoolDTO.java rename backend/{framework/sdk/src/main/java/io/metersphere/sdk => services/system-setting/src/main/java/io/metersphere/system}/dto/UpdateProjectRequest.java (77%) diff --git a/backend/framework/domain/src/main/java/io/metersphere/project/domain/ProjectTestResourcePool.java b/backend/framework/domain/src/main/java/io/metersphere/project/domain/ProjectTestResourcePool.java new file mode 100644 index 0000000000..e1626e3836 --- /dev/null +++ b/backend/framework/domain/src/main/java/io/metersphere/project/domain/ProjectTestResourcePool.java @@ -0,0 +1,99 @@ +package io.metersphere.project.domain; + +import io.metersphere.validation.groups.Created; +import io.metersphere.validation.groups.Updated; +import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.Size; +import lombok.Data; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Arrays; + +@Data +public class ProjectTestResourcePool implements Serializable { + @Schema(description = "项目ID", requiredMode = Schema.RequiredMode.REQUIRED) + @NotBlank(message = "{project_test_resource_pool.project_id.not_blank}", groups = {Created.class}) + @Size(min = 1, max = 50, message = "{project_test_resource_pool.project_id.length_range}", groups = {Created.class, Updated.class}) + private String projectId; + + @Schema(description = "资源池ID", requiredMode = Schema.RequiredMode.REQUIRED) + @NotBlank(message = "{project_test_resource_pool.test_resource_pool_id.not_blank}", groups = {Created.class}) + @Size(min = 1, max = 50, message = "{project_test_resource_pool.test_resource_pool_id.length_range}", groups = {Created.class, Updated.class}) + private String testResourcePoolId; + + private static final long serialVersionUID = 1L; + + public enum Column { + projectId("project_id", "projectId", "VARCHAR", false), + testResourcePoolId("test_resource_pool_id", "testResourcePoolId", "VARCHAR", false); + + private static final String BEGINNING_DELIMITER = "`"; + + private static final String ENDING_DELIMITER = "`"; + + private final String column; + + private final boolean isColumnNameDelimited; + + private final String javaProperty; + + private final String jdbcType; + + public String value() { + return this.column; + } + + public String getValue() { + return this.column; + } + + public String getJavaProperty() { + return this.javaProperty; + } + + public String getJdbcType() { + return this.jdbcType; + } + + Column(String column, String javaProperty, String jdbcType, boolean isColumnNameDelimited) { + this.column = column; + this.javaProperty = javaProperty; + this.jdbcType = jdbcType; + this.isColumnNameDelimited = isColumnNameDelimited; + } + + public String desc() { + return this.getEscapedColumnName() + " DESC"; + } + + public String asc() { + return this.getEscapedColumnName() + " ASC"; + } + + public static Column[] excludes(Column ... excludes) { + ArrayList columns = new ArrayList<>(Arrays.asList(Column.values())); + if (excludes != null && excludes.length > 0) { + columns.removeAll(new ArrayList<>(Arrays.asList(excludes))); + } + return columns.toArray(new Column[]{}); + } + + public static Column[] all() { + return Column.values(); + } + + public String getEscapedColumnName() { + if (this.isColumnNameDelimited) { + return new StringBuilder().append(BEGINNING_DELIMITER).append(this.column).append(ENDING_DELIMITER).toString(); + } else { + return this.column; + } + } + + public String getAliasedEscapedColumnName() { + return this.getEscapedColumnName(); + } + } +} \ No newline at end of file diff --git a/backend/framework/domain/src/main/java/io/metersphere/project/domain/ProjectTestResourcePoolExample.java b/backend/framework/domain/src/main/java/io/metersphere/project/domain/ProjectTestResourcePoolExample.java new file mode 100644 index 0000000000..3661d0ad3c --- /dev/null +++ b/backend/framework/domain/src/main/java/io/metersphere/project/domain/ProjectTestResourcePoolExample.java @@ -0,0 +1,340 @@ +package io.metersphere.project.domain; + +import java.util.ArrayList; +import java.util.List; + +public class ProjectTestResourcePoolExample { + protected String orderByClause; + + protected boolean distinct; + + protected List oredCriteria; + + public ProjectTestResourcePoolExample() { + oredCriteria = new ArrayList(); + } + + public void setOrderByClause(String orderByClause) { + this.orderByClause = orderByClause; + } + + public String getOrderByClause() { + return orderByClause; + } + + public void setDistinct(boolean distinct) { + this.distinct = distinct; + } + + public boolean isDistinct() { + return distinct; + } + + public List getOredCriteria() { + return oredCriteria; + } + + public void or(Criteria criteria) { + oredCriteria.add(criteria); + } + + public Criteria or() { + Criteria criteria = createCriteriaInternal(); + oredCriteria.add(criteria); + return criteria; + } + + public Criteria createCriteria() { + Criteria criteria = createCriteriaInternal(); + if (oredCriteria.size() == 0) { + oredCriteria.add(criteria); + } + return criteria; + } + + protected Criteria createCriteriaInternal() { + Criteria criteria = new Criteria(); + return criteria; + } + + public void clear() { + oredCriteria.clear(); + orderByClause = null; + distinct = false; + } + + protected abstract static class GeneratedCriteria { + protected List criteria; + + protected GeneratedCriteria() { + super(); + criteria = new ArrayList(); + } + + public boolean isValid() { + return criteria.size() > 0; + } + + public List getAllCriteria() { + return criteria; + } + + public List getCriteria() { + return criteria; + } + + protected void addCriterion(String condition) { + if (condition == null) { + throw new RuntimeException("Value for condition cannot be null"); + } + criteria.add(new Criterion(condition)); + } + + protected void addCriterion(String condition, Object value, String property) { + if (value == null) { + throw new RuntimeException("Value for " + property + " cannot be null"); + } + criteria.add(new Criterion(condition, value)); + } + + protected void addCriterion(String condition, Object value1, Object value2, String property) { + if (value1 == null || value2 == null) { + throw new RuntimeException("Between values for " + property + " cannot be null"); + } + criteria.add(new Criterion(condition, value1, value2)); + } + + public Criteria andProjectIdIsNull() { + addCriterion("project_id is null"); + return (Criteria) this; + } + + public Criteria andProjectIdIsNotNull() { + addCriterion("project_id is not null"); + return (Criteria) this; + } + + public Criteria andProjectIdEqualTo(String value) { + addCriterion("project_id =", value, "projectId"); + return (Criteria) this; + } + + public Criteria andProjectIdNotEqualTo(String value) { + addCriterion("project_id <>", value, "projectId"); + return (Criteria) this; + } + + public Criteria andProjectIdGreaterThan(String value) { + addCriterion("project_id >", value, "projectId"); + return (Criteria) this; + } + + public Criteria andProjectIdGreaterThanOrEqualTo(String value) { + addCriterion("project_id >=", value, "projectId"); + return (Criteria) this; + } + + public Criteria andProjectIdLessThan(String value) { + addCriterion("project_id <", value, "projectId"); + return (Criteria) this; + } + + public Criteria andProjectIdLessThanOrEqualTo(String value) { + addCriterion("project_id <=", value, "projectId"); + return (Criteria) this; + } + + public Criteria andProjectIdLike(String value) { + addCriterion("project_id like", value, "projectId"); + return (Criteria) this; + } + + public Criteria andProjectIdNotLike(String value) { + addCriterion("project_id not like", value, "projectId"); + return (Criteria) this; + } + + public Criteria andProjectIdIn(List values) { + addCriterion("project_id in", values, "projectId"); + return (Criteria) this; + } + + public Criteria andProjectIdNotIn(List values) { + addCriterion("project_id not in", values, "projectId"); + return (Criteria) this; + } + + public Criteria andProjectIdBetween(String value1, String value2) { + addCriterion("project_id between", value1, value2, "projectId"); + return (Criteria) this; + } + + public Criteria andProjectIdNotBetween(String value1, String value2) { + addCriterion("project_id not between", value1, value2, "projectId"); + return (Criteria) this; + } + + public Criteria andTestResourcePoolIdIsNull() { + addCriterion("test_resource_pool_id is null"); + return (Criteria) this; + } + + public Criteria andTestResourcePoolIdIsNotNull() { + addCriterion("test_resource_pool_id is not null"); + return (Criteria) this; + } + + public Criteria andTestResourcePoolIdEqualTo(String value) { + addCriterion("test_resource_pool_id =", value, "testResourcePoolId"); + return (Criteria) this; + } + + public Criteria andTestResourcePoolIdNotEqualTo(String value) { + addCriterion("test_resource_pool_id <>", value, "testResourcePoolId"); + return (Criteria) this; + } + + public Criteria andTestResourcePoolIdGreaterThan(String value) { + addCriterion("test_resource_pool_id >", value, "testResourcePoolId"); + return (Criteria) this; + } + + public Criteria andTestResourcePoolIdGreaterThanOrEqualTo(String value) { + addCriterion("test_resource_pool_id >=", value, "testResourcePoolId"); + return (Criteria) this; + } + + public Criteria andTestResourcePoolIdLessThan(String value) { + addCriterion("test_resource_pool_id <", value, "testResourcePoolId"); + return (Criteria) this; + } + + public Criteria andTestResourcePoolIdLessThanOrEqualTo(String value) { + addCriterion("test_resource_pool_id <=", value, "testResourcePoolId"); + return (Criteria) this; + } + + public Criteria andTestResourcePoolIdLike(String value) { + addCriterion("test_resource_pool_id like", value, "testResourcePoolId"); + return (Criteria) this; + } + + public Criteria andTestResourcePoolIdNotLike(String value) { + addCriterion("test_resource_pool_id not like", value, "testResourcePoolId"); + return (Criteria) this; + } + + public Criteria andTestResourcePoolIdIn(List values) { + addCriterion("test_resource_pool_id in", values, "testResourcePoolId"); + return (Criteria) this; + } + + public Criteria andTestResourcePoolIdNotIn(List values) { + addCriterion("test_resource_pool_id not in", values, "testResourcePoolId"); + return (Criteria) this; + } + + public Criteria andTestResourcePoolIdBetween(String value1, String value2) { + addCriterion("test_resource_pool_id between", value1, value2, "testResourcePoolId"); + return (Criteria) this; + } + + public Criteria andTestResourcePoolIdNotBetween(String value1, String value2) { + addCriterion("test_resource_pool_id not between", value1, value2, "testResourcePoolId"); + return (Criteria) this; + } + } + + public static class Criteria extends GeneratedCriteria { + + protected Criteria() { + super(); + } + } + + public static class Criterion { + private String condition; + + private Object value; + + private Object secondValue; + + private boolean noValue; + + private boolean singleValue; + + private boolean betweenValue; + + private boolean listValue; + + private String typeHandler; + + public String getCondition() { + return condition; + } + + public Object getValue() { + return value; + } + + public Object getSecondValue() { + return secondValue; + } + + public boolean isNoValue() { + return noValue; + } + + public boolean isSingleValue() { + return singleValue; + } + + public boolean isBetweenValue() { + return betweenValue; + } + + public boolean isListValue() { + return listValue; + } + + public String getTypeHandler() { + return typeHandler; + } + + protected Criterion(String condition) { + super(); + this.condition = condition; + this.typeHandler = null; + this.noValue = true; + } + + protected Criterion(String condition, Object value, String typeHandler) { + super(); + this.condition = condition; + this.value = value; + this.typeHandler = typeHandler; + if (value instanceof List) { + this.listValue = true; + } else { + this.singleValue = true; + } + } + + protected Criterion(String condition, Object value) { + this(condition, value, null); + } + + protected Criterion(String condition, Object value, Object secondValue, String typeHandler) { + super(); + this.condition = condition; + this.value = value; + this.secondValue = secondValue; + this.typeHandler = typeHandler; + this.betweenValue = true; + } + + protected Criterion(String condition, Object value, Object secondValue) { + this(condition, value, secondValue, null); + } + } +} \ No newline at end of file diff --git a/backend/framework/domain/src/main/java/io/metersphere/project/mapper/ProjectTestResourcePoolMapper.java b/backend/framework/domain/src/main/java/io/metersphere/project/mapper/ProjectTestResourcePoolMapper.java new file mode 100644 index 0000000000..eab52f5b2f --- /dev/null +++ b/backend/framework/domain/src/main/java/io/metersphere/project/mapper/ProjectTestResourcePoolMapper.java @@ -0,0 +1,28 @@ +package io.metersphere.project.mapper; + +import io.metersphere.project.domain.ProjectTestResourcePool; +import io.metersphere.project.domain.ProjectTestResourcePoolExample; +import java.util.List; +import org.apache.ibatis.annotations.Param; + +public interface ProjectTestResourcePoolMapper { + long countByExample(ProjectTestResourcePoolExample example); + + int deleteByExample(ProjectTestResourcePoolExample example); + + int deleteByPrimaryKey(@Param("projectId") String projectId, @Param("testResourcePoolId") String testResourcePoolId); + + int insert(ProjectTestResourcePool record); + + int insertSelective(ProjectTestResourcePool record); + + List selectByExample(ProjectTestResourcePoolExample example); + + int updateByExampleSelective(@Param("record") ProjectTestResourcePool record, @Param("example") ProjectTestResourcePoolExample example); + + int updateByExample(@Param("record") ProjectTestResourcePool record, @Param("example") ProjectTestResourcePoolExample example); + + int batchInsert(@Param("list") List list); + + int batchInsertSelective(@Param("list") List list, @Param("selective") ProjectTestResourcePool.Column ... selective); +} \ No newline at end of file diff --git a/backend/framework/domain/src/main/java/io/metersphere/project/mapper/ProjectTestResourcePoolMapper.xml b/backend/framework/domain/src/main/java/io/metersphere/project/mapper/ProjectTestResourcePoolMapper.xml new file mode 100644 index 0000000000..46676c7a46 --- /dev/null +++ b/backend/framework/domain/src/main/java/io/metersphere/project/mapper/ProjectTestResourcePoolMapper.xml @@ -0,0 +1,173 @@ + + + + + + + + + + + + + + + + and ${criterion.condition} + + + and ${criterion.condition} #{criterion.value} + + + and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} + + + and ${criterion.condition} + + #{listItem} + + + + + + + + + + + + + + + + + + and ${criterion.condition} + + + and ${criterion.condition} #{criterion.value} + + + and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} + + + and ${criterion.condition} + + #{listItem} + + + + + + + + + + + project_id, test_resource_pool_id + + + + delete from project_test_resource_pool + where project_id = #{projectId,jdbcType=VARCHAR} + and test_resource_pool_id = #{testResourcePoolId,jdbcType=VARCHAR} + + + delete from project_test_resource_pool + + + + + + insert into project_test_resource_pool (project_id, test_resource_pool_id) + values (#{projectId,jdbcType=VARCHAR}, #{testResourcePoolId,jdbcType=VARCHAR}) + + + insert into project_test_resource_pool + + + project_id, + + + test_resource_pool_id, + + + + + #{projectId,jdbcType=VARCHAR}, + + + #{testResourcePoolId,jdbcType=VARCHAR}, + + + + + + update project_test_resource_pool + + + project_id = #{record.projectId,jdbcType=VARCHAR}, + + + test_resource_pool_id = #{record.testResourcePoolId,jdbcType=VARCHAR}, + + + + + + + + update project_test_resource_pool + set project_id = #{record.projectId,jdbcType=VARCHAR}, + test_resource_pool_id = #{record.testResourcePoolId,jdbcType=VARCHAR} + + + + + + insert into project_test_resource_pool + (project_id, test_resource_pool_id) + values + + (#{item.projectId,jdbcType=VARCHAR}, #{item.testResourcePoolId,jdbcType=VARCHAR}) + + + + insert into project_test_resource_pool ( + + ${column.escapedColumnName} + + ) + values + + ( + + + #{item.projectId,jdbcType=VARCHAR} + + + #{item.testResourcePoolId,jdbcType=VARCHAR} + + + ) + + + \ No newline at end of file diff --git a/backend/framework/domain/src/main/resources/migration/3.0.0/ddl/V3.0.0_4__project_management.sql b/backend/framework/domain/src/main/resources/migration/3.0.0/ddl/V3.0.0_4__project_management.sql index 0e3d7702b9..77a900bdd0 100644 --- a/backend/framework/domain/src/main/resources/migration/3.0.0/ddl/V3.0.0_4__project_management.sql +++ b/backend/framework/domain/src/main/resources/migration/3.0.0/ddl/V3.0.0_4__project_management.sql @@ -318,5 +318,15 @@ CREATE INDEX idx_platform ON project_robot(platform); CREATE INDEX idx_webhook ON project_robot(webhook); +CREATE TABLE IF NOT EXISTS project_test_resource_pool( + `project_id` VARCHAR(50) NOT NULL COMMENT '项目ID' , + `test_resource_pool_id` VARCHAR(50) NOT NULL COMMENT '资源池ID' , + PRIMARY KEY (project_id,test_resource_pool_id) +) ENGINE = InnoDB + DEFAULT CHARSET = utf8mb4 + COLLATE = utf8mb4_general_ci + COMMENT = '项目与资源池关系表'; + + -- set innodb lock wait timeout to default SET SESSION innodb_lock_wait_timeout = DEFAULT; \ No newline at end of file diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/constants/ModuleType.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/constants/ModuleType.java new file mode 100644 index 0000000000..ac55e89e44 --- /dev/null +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/constants/ModuleType.java @@ -0,0 +1,8 @@ +package io.metersphere.sdk.constants; + +public class ModuleType { + public static final String API_TEST = "api_test"; + public static final String UI_TEST = "ui_test"; + public static final String LOAD_TEST = "load_test"; + +} diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/ProjectBaseRequest.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/ProjectBaseRequest.java index 80b89e722f..9ced522254 100644 --- a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/ProjectBaseRequest.java +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/ProjectBaseRequest.java @@ -32,4 +32,10 @@ public class ProjectBaseRequest { @Schema(description = "模块设置") private List moduleIds; + + @Schema(description = "成员数", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + private List userIds; + + @Schema(description = "资源池", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + private List resourcePoolIds; } diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/ProjectExtendDTO.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/ProjectExtendDTO.java deleted file mode 100644 index 691ab94633..0000000000 --- a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/ProjectExtendDTO.java +++ /dev/null @@ -1,16 +0,0 @@ -package io.metersphere.sdk.dto; - -import io.metersphere.project.domain.Project; -import lombok.Data; -import lombok.EqualsAndHashCode; - -import java.io.Serializable; -import java.util.List; - -@Data -@EqualsAndHashCode(callSuper = false) -public class ProjectExtendDTO extends ProjectDTO implements Serializable { - private List moduleIds; - - private static final long serialVersionUID = 1L; -} diff --git a/backend/framework/sdk/src/main/resources/i18n/project_en_US.properties b/backend/framework/sdk/src/main/resources/i18n/project_en_US.properties index 570c3e2c4d..7f6ff1bfbe 100644 --- a/backend/framework/sdk/src/main/resources/i18n/project_en_US.properties +++ b/backend/framework/sdk/src/main/resources/i18n/project_en_US.properties @@ -148,6 +148,8 @@ environment_datasource.dbUrl.not_blank=Db Url is required environment_name_is_null=Environment name is required environment_config_is_null=Environment config is required +resource_pool_not_exist=Resource pool does not exist + #file management file_module.not.exist=File module does not exist upload.file.error=Upload file error diff --git a/backend/framework/sdk/src/main/resources/i18n/project_zh_CN.properties b/backend/framework/sdk/src/main/resources/i18n/project_zh_CN.properties index b6a97d09bf..63958e7d28 100644 --- a/backend/framework/sdk/src/main/resources/i18n/project_zh_CN.properties +++ b/backend/framework/sdk/src/main/resources/i18n/project_zh_CN.properties @@ -147,6 +147,7 @@ environment_datasource.driverId.not_blank=驱动ID不能为空 environment_datasource.dbUrl.not_blank=数据库连接不能为空 environment_name_is_null=环境名称不能为空 environment_config_is_null=环境配置不能为空 +resource_pool_not_exist=资源池不存在 #file management file_module.not.exist=文件模块不存在 diff --git a/backend/framework/sdk/src/main/resources/i18n/project_zh_TW.properties b/backend/framework/sdk/src/main/resources/i18n/project_zh_TW.properties index 900d9f5d7f..5abb5a3d0f 100644 --- a/backend/framework/sdk/src/main/resources/i18n/project_zh_TW.properties +++ b/backend/framework/sdk/src/main/resources/i18n/project_zh_TW.properties @@ -147,6 +147,8 @@ environment_datasource.driverId.not_blank=驅動ID不能為空 environment_datasource.dbUrl.not_blank=數據庫地址不能為空 environment_name_is_null=環境名稱不能為空 environment_config_is_null=環境配置不能為空 + +resource_pool_not_exist=資源池不存在 #file management file_module.not.exist=文件模塊不存在 upload.file.error=上傳文件失敗 diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/controller/ProjectController.java b/backend/services/project-management/src/main/java/io/metersphere/project/controller/ProjectController.java index 76f1eec932..ca31192bd5 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/controller/ProjectController.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/controller/ProjectController.java @@ -5,16 +5,15 @@ import io.metersphere.project.request.ProjectSwitchRequest; import io.metersphere.project.service.ProjectLogService; import io.metersphere.project.service.ProjectService; import io.metersphere.sdk.constants.PermissionConstants; -import io.metersphere.sdk.dto.ProjectExtendDTO; -import io.metersphere.sdk.dto.UpdateProjectRequest; +import io.metersphere.system.dto.ProjectDTO; +import io.metersphere.system.dto.UpdateProjectRequest; import io.metersphere.sdk.dto.UserDTO; -import io.metersphere.system.utils.SessionUtils; +import io.metersphere.system.domain.TestResourcePool; import io.metersphere.system.log.annotation.Log; import io.metersphere.system.log.constants.OperationLogType; +import io.metersphere.system.utils.SessionUtils; import io.metersphere.validation.groups.Updated; import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.Parameter; -import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.annotation.Resource; import org.apache.shiro.authz.annotation.RequiresPermissions; @@ -33,7 +32,7 @@ public class ProjectController { @GetMapping("/get/{id}") @Operation(summary = "项目管理-基本信息") @RequiresPermissions(PermissionConstants.PROJECT_BASE_INFO_READ) - public ProjectExtendDTO getProject(@PathVariable String id) { + public ProjectDTO getProject(@PathVariable String id) { return projectService.getProjectById(id); } @@ -55,44 +54,15 @@ public class ProjectController { @Operation(summary = "项目管理-更新项目") @RequiresPermissions(PermissionConstants.PROJECT_BASE_INFO_READ_UPDATE) @Log(type = OperationLogType.UPDATE, expression = "#msClass.updateLog(#request)", msClass = ProjectLogService.class) - public ProjectExtendDTO updateProject(@RequestBody @Validated({Updated.class}) UpdateProjectRequest request) { + public ProjectDTO updateProject(@RequestBody @Validated({Updated.class}) UpdateProjectRequest request) { return projectService.update(request, SessionUtils.getUserId()); } - @GetMapping("/delete/{id}") - @RequiresPermissions(PermissionConstants.PROJECT_BASE_INFO_READ_DELETE) - @Operation(summary = "项目管理-删除") - @Parameter(name = "id", description = "项目", schema = @Schema(requiredMode = Schema.RequiredMode.REQUIRED)) - @Log(type = OperationLogType.DELETE, expression = "#msClass.deleteLog(#id)", msClass = ProjectLogService.class) - public int deleteProject(@PathVariable String id) { - return projectService.delete(id, SessionUtils.getUserId()); - } - - @GetMapping("/revoke/{id}") - @RequiresPermissions(PermissionConstants.PROJECT_BASE_INFO_READ_RECOVER) - @Operation(summary = "项目管理-撤销删除") - @Log(type = OperationLogType.UPDATE, expression = "#msClass.recoverLog(#id)", msClass = ProjectLogService.class) - @Parameter(name = "id", description = "项目", schema = @Schema(requiredMode = Schema.RequiredMode.REQUIRED)) - public int revokeProject(@PathVariable String id) { - return projectService.revoke(id, SessionUtils.getUserId()); - } - - @GetMapping("/enable/{id}") - @Operation(summary = "项目管理-启用") - @Parameter(name = "id", description = "项目ID", schema = @Schema(requiredMode = Schema.RequiredMode.REQUIRED)) - @Log(type = OperationLogType.UPDATE, expression = "#msClass.updateLog(#id)", msClass = ProjectLogService.class) - @RequiresPermissions(PermissionConstants.PROJECT_BASE_INFO_READ_UPDATE) - public void enable(@PathVariable String id) { - projectService.enable(id, SessionUtils.getUserId()); - } - - @GetMapping("/disable/{id}") - @Operation(summary = "项目管理-禁用") - @Parameter(name = "id", description = "项目ID", schema = @Schema(requiredMode = Schema.RequiredMode.REQUIRED)) - @RequiresPermissions(PermissionConstants.PROJECT_BASE_INFO_READ_UPDATE) - @Log(type = OperationLogType.UPDATE, expression = "#msClass.updateLog(#id)", msClass = ProjectLogService.class) - public void disable(@PathVariable String id) { - projectService.disable(id, SessionUtils.getUserId()); + @GetMapping("/pool-options/{type}/{projectId}") + @Operation(summary = "项目管理-获取项目下的资源池") + @RequiresPermissions(PermissionConstants.PROJECT_BASE_INFO_READ) + public List getPoolOptions(@PathVariable String type ,@PathVariable String projectId) { + return projectService.getPoolOptions(projectId, type); } } diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/service/ProjectLogService.java b/backend/services/project-management/src/main/java/io/metersphere/project/service/ProjectLogService.java index 35cd688847..4ff1c95423 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/service/ProjectLogService.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/service/ProjectLogService.java @@ -2,9 +2,8 @@ package io.metersphere.project.service; import io.metersphere.project.domain.Project; import io.metersphere.project.mapper.ProjectMapper; -import io.metersphere.sdk.constants.HttpMethodConstants; import io.metersphere.sdk.dto.LogDTO; -import io.metersphere.sdk.dto.UpdateProjectRequest; +import io.metersphere.system.dto.UpdateProjectRequest; import io.metersphere.sdk.util.JSON; import io.metersphere.system.log.constants.OperationLogModule; import io.metersphere.system.log.constants.OperationLogType; @@ -40,69 +39,4 @@ public class ProjectLogService { } return null; } - - public LogDTO updateLog(String id) { - Project project = projectMapper.selectByPrimaryKey(id); - if (project != null) { - LogDTO dto = new LogDTO( - project.getId(), - project.getOrganizationId(), - project.getId(), - project.getCreateUser(), - OperationLogType.UPDATE.name(), - OperationLogModule.PROJECT_MANAGEMENT, - project.getName()); - dto.setMethod(HttpMethodConstants.GET.name()); - - dto.setOriginalValue(JSON.toJSONBytes(project)); - return dto; - } - return null; - } - - /** - * 删除接口日志 - * - * @param id - * @return - */ - public LogDTO deleteLog(String id) { - Project project = projectMapper.selectByPrimaryKey(id); - if (project != null) { - LogDTO dto = new LogDTO( - project.getId(), - project.getOrganizationId(), - id, - project.getCreateUser(), - OperationLogType.DELETE.name(), - OperationLogModule.PROJECT_MANAGEMENT, - project.getName()); - - dto.setOriginalValue(JSON.toJSONBytes(project)); - return dto; - } - return null; - } - - /** - * 恢复项目 - * @param id 接口请求参数 - * @return 日志详情 - */ - public LogDTO recoverLog(String id) { - Project project = projectMapper.selectByPrimaryKey(id); - if (project != null) { - LogDTO dto = new LogDTO( - project.getId(), - project.getOrganizationId(), - id, - null, - OperationLogType.RECOVER.name(), - OperationLogModule.PROJECT_MANAGEMENT, - project.getName()); - dto.setOriginalValue(JSON.toJSONBytes(project)); - return dto; - } - return null; - } } diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/service/ProjectService.java b/backend/services/project-management/src/main/java/io/metersphere/project/service/ProjectService.java index adbe0f854c..896625b73c 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/service/ProjectService.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/service/ProjectService.java @@ -2,34 +2,37 @@ package io.metersphere.project.service; import io.metersphere.project.domain.Project; import io.metersphere.project.domain.ProjectExample; +import io.metersphere.project.domain.ProjectTestResourcePool; +import io.metersphere.project.domain.ProjectTestResourcePoolExample; import io.metersphere.project.mapper.ExtProjectMapper; import io.metersphere.project.mapper.ProjectMapper; +import io.metersphere.project.mapper.ProjectTestResourcePoolMapper; import io.metersphere.project.request.ProjectSwitchRequest; import io.metersphere.sdk.constants.InternalUserRole; -import io.metersphere.sdk.dto.ProjectExtendDTO; +import io.metersphere.sdk.constants.ModuleType; import io.metersphere.sdk.dto.SessionUser; -import io.metersphere.sdk.dto.UpdateProjectRequest; import io.metersphere.sdk.dto.UserDTO; import io.metersphere.sdk.exception.MSException; -import io.metersphere.system.domain.Organization; -import io.metersphere.system.service.BaseUserService; import io.metersphere.sdk.util.BeanUtils; import io.metersphere.sdk.util.JSON; -import io.metersphere.system.utils.SessionUtils; import io.metersphere.sdk.util.Translator; -import io.metersphere.system.domain.User; -import io.metersphere.system.domain.UserRoleRelation; -import io.metersphere.system.domain.UserRoleRelationExample; +import io.metersphere.system.domain.*; +import io.metersphere.system.dto.ProjectDTO; +import io.metersphere.system.dto.UpdateProjectRequest; import io.metersphere.system.mapper.OrganizationMapper; +import io.metersphere.system.mapper.TestResourcePoolMapper; +import io.metersphere.system.mapper.TestResourcePoolOrganizationMapper; import io.metersphere.system.mapper.UserRoleRelationMapper; +import io.metersphere.system.service.BaseUserService; import io.metersphere.system.service.CommonProjectService; +import io.metersphere.system.utils.SessionUtils; import jakarta.annotation.Resource; import org.apache.commons.collections.CollectionUtils; -import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.ArrayList; import java.util.List; @Service @@ -47,6 +50,12 @@ public class ProjectService { private OrganizationMapper organizationMapper; @Resource private CommonProjectService commonProjectService; + @Resource + private TestResourcePoolMapper testResourcePoolMapper; + @Resource + private ProjectTestResourcePoolMapper projectTestResourcePoolMapper; + @Resource + private TestResourcePoolOrganizationMapper testResourcePoolOrganizationMapper; public List getUserProject(String organizationId, String userId) { @@ -83,25 +92,13 @@ public class ProjectService { return sessionUser; } - public ProjectExtendDTO getProjectById(String id) { - Project project = projectMapper.selectByPrimaryKey(id); - ProjectExtendDTO projectExtendDTO = new ProjectExtendDTO(); - if (ObjectUtils.isNotEmpty(project)) { - BeanUtils.copyBean(projectExtendDTO, project); - Organization organization = organizationMapper.selectByPrimaryKey(project.getOrganizationId()); - projectExtendDTO.setOrganizationName(organization.getName()); - if (StringUtils.isNotEmpty(project.getModuleSetting())) { - projectExtendDTO.setModuleIds(JSON.parseArray(project.getModuleSetting(), String.class)); - } - } else { - return null; - } - return projectExtendDTO; + public ProjectDTO getProjectById(String id) { + return commonProjectService.get(id); } - public ProjectExtendDTO update(UpdateProjectRequest updateProjectDto, String updateUser) { + public ProjectDTO update(UpdateProjectRequest updateProjectDto, String updateUser) { Project project = new Project(); - ProjectExtendDTO projectExtendDTO = new ProjectExtendDTO(); + ProjectDTO projectDTO = new ProjectDTO(); project.setId(updateProjectDto.getId()); project.setName(updateProjectDto.getName()); project.setDescription(updateProjectDto.getDescription()); @@ -113,16 +110,16 @@ public class ProjectService { project.setUpdateTime(System.currentTimeMillis()); checkProjectExistByName(project); checkProjectNotExist(project.getId()); - projectExtendDTO.setOrganizationName(organizationMapper.selectByPrimaryKey(updateProjectDto.getOrganizationId()).getName()); - BeanUtils.copyBean(projectExtendDTO, project); + projectDTO.setOrganizationName(organizationMapper.selectByPrimaryKey(updateProjectDto.getOrganizationId()).getName()); + BeanUtils.copyBean(projectDTO, project); //判断是否有模块设置 if (CollectionUtils.isNotEmpty(updateProjectDto.getModuleIds())) { project.setModuleSetting(JSON.toJSONString(updateProjectDto.getModuleIds())); - projectExtendDTO.setModuleIds(updateProjectDto.getModuleIds()); + projectDTO.setModuleIds(updateProjectDto.getModuleIds()); } projectMapper.updateByPrimaryKeySelective(project); - return projectExtendDTO; + return projectDTO; } private void checkProjectExistByName(Project project) { @@ -139,19 +136,52 @@ public class ProjectService { } } - public int delete(String id, String deleteUser) { - return commonProjectService.delete(id,deleteUser); + private List getPoolIds(String projectId) { + List poolIds = new ArrayList<>(); + ProjectTestResourcePoolExample example = new ProjectTestResourcePoolExample(); + example.createCriteria().andProjectIdEqualTo(projectId); + List projectPools = projectTestResourcePoolMapper.selectByExample(example); + if (CollectionUtils.isNotEmpty(projectPools)) { + return projectPools.stream().map(ProjectTestResourcePool::getTestResourcePoolId).toList(); + } + //判断项目所属组织是否关联了资源池 + Project project = projectMapper.selectByPrimaryKey(projectId); + TestResourcePoolOrganizationExample orgExample = new TestResourcePoolOrganizationExample(); + orgExample.createCriteria().andOrgIdEqualTo(project.getOrganizationId()); + List orgPools = testResourcePoolOrganizationMapper.selectByExample(orgExample); + if (CollectionUtils.isNotEmpty(orgPools)) { + poolIds.addAll(orgPools.stream().map(TestResourcePoolOrganization::getTestResourcePoolId).toList()); + } + //获取应用全部组织的资源池 + TestResourcePoolExample poolExample = new TestResourcePoolExample(); + poolExample.createCriteria().andAllOrgEqualTo(true).andEnableEqualTo(true).andDeletedEqualTo(false); + List testResourcePools = testResourcePoolMapper.selectByExample(poolExample); + poolIds.addAll(testResourcePools.stream().map(TestResourcePool::getId).toList()); + poolIds = poolIds.stream().distinct().filter(StringUtils::isNotBlank).toList(); + return poolIds; } - public int revoke(String id, String updateUser) { - return commonProjectService.revoke(id, updateUser); - } - - public void enable(String id, String updateUser) { - commonProjectService.enable(id, updateUser); - } - - public void disable(String id, String updateUser) { - commonProjectService.disable(id, updateUser); + public List getPoolOptions(String projectId, String type) { + //判断项目是否关联了资源池 + checkProjectNotExist(projectId); + List poolIds = getPoolIds(projectId); + TestResourcePoolExample example = new TestResourcePoolExample(); + TestResourcePoolExample.Criteria criteria = example.createCriteria(); + criteria.andIdIn(poolIds).andEnableEqualTo(true).andDeletedEqualTo(false); + return switch (type) { + case ModuleType.API_TEST-> { + criteria.andApiTestEqualTo(true); + yield testResourcePoolMapper.selectByExample(example); + } + case ModuleType.UI_TEST -> { + criteria.andUiTestEqualTo(true); + yield testResourcePoolMapper.selectByExample(example); + } + case ModuleType.LOAD_TEST -> { + criteria.andLoadTestEqualTo(true); + yield testResourcePoolMapper.selectByExample(example); + } + default -> new ArrayList<>(); + }; } } diff --git a/backend/services/project-management/src/main/resources/projectGeneratorConfig.xml b/backend/services/project-management/src/main/resources/projectGeneratorConfig.xml index f39f9f1302..73b3469280 100644 --- a/backend/services/project-management/src/main/resources/projectGeneratorConfig.xml +++ b/backend/services/project-management/src/main/resources/projectGeneratorConfig.xml @@ -85,6 +85,7 @@
+