diff --git a/backend/framework/domain/src/main/java/io/metersphere/api/domain/ApiScenarioEnvironment.java b/backend/framework/domain/src/main/java/io/metersphere/api/domain/ApiScenarioEnvironment.java deleted file mode 100644 index 29e5cd91ab..0000000000 --- a/backend/framework/domain/src/main/java/io/metersphere/api/domain/ApiScenarioEnvironment.java +++ /dev/null @@ -1,98 +0,0 @@ -package io.metersphere.api.domain; - -import io.metersphere.validation.groups.*; -import io.swagger.v3.oas.annotations.media.Schema; -import jakarta.validation.constraints.*; -import java.io.Serializable; -import java.util.ArrayList; -import java.util.Arrays; -import lombok.Data; - -@Data -public class ApiScenarioEnvironment implements Serializable { - @Schema(description = "场景fk", requiredMode = Schema.RequiredMode.REQUIRED) - @NotBlank(message = "{api_scenario_environment.api_scenario_id.not_blank}", groups = {Created.class}) - @Size(min = 1, max = 50, message = "{api_scenario_environment.api_scenario_id.length_range}", groups = {Created.class, Updated.class}) - private String apiScenarioId; - - @Schema(description = "环境fk") - private String environmentId; - - @Schema(description = "环境组fk") - private String environmentGroupId; - - private static final long serialVersionUID = 1L; - - public enum Column { - apiScenarioId("api_scenario_id", "apiScenarioId", "VARCHAR", false), - environmentId("environment_id", "environmentId", "VARCHAR", false), - environmentGroupId("environment_group_id", "environmentGroupId", "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/api/domain/ApiScenarioEnvironmentExample.java b/backend/framework/domain/src/main/java/io/metersphere/api/domain/ApiScenarioEnvironmentExample.java deleted file mode 100644 index c028cb54cd..0000000000 --- a/backend/framework/domain/src/main/java/io/metersphere/api/domain/ApiScenarioEnvironmentExample.java +++ /dev/null @@ -1,410 +0,0 @@ -package io.metersphere.api.domain; - -import java.util.ArrayList; -import java.util.List; - -public class ApiScenarioEnvironmentExample { - protected String orderByClause; - - protected boolean distinct; - - protected List oredCriteria; - - public ApiScenarioEnvironmentExample() { - 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 andApiScenarioIdIsNull() { - addCriterion("api_scenario_id is null"); - return (Criteria) this; - } - - public Criteria andApiScenarioIdIsNotNull() { - addCriterion("api_scenario_id is not null"); - return (Criteria) this; - } - - public Criteria andApiScenarioIdEqualTo(String value) { - addCriterion("api_scenario_id =", value, "apiScenarioId"); - return (Criteria) this; - } - - public Criteria andApiScenarioIdNotEqualTo(String value) { - addCriterion("api_scenario_id <>", value, "apiScenarioId"); - return (Criteria) this; - } - - public Criteria andApiScenarioIdGreaterThan(String value) { - addCriterion("api_scenario_id >", value, "apiScenarioId"); - return (Criteria) this; - } - - public Criteria andApiScenarioIdGreaterThanOrEqualTo(String value) { - addCriterion("api_scenario_id >=", value, "apiScenarioId"); - return (Criteria) this; - } - - public Criteria andApiScenarioIdLessThan(String value) { - addCriterion("api_scenario_id <", value, "apiScenarioId"); - return (Criteria) this; - } - - public Criteria andApiScenarioIdLessThanOrEqualTo(String value) { - addCriterion("api_scenario_id <=", value, "apiScenarioId"); - return (Criteria) this; - } - - public Criteria andApiScenarioIdLike(String value) { - addCriterion("api_scenario_id like", value, "apiScenarioId"); - return (Criteria) this; - } - - public Criteria andApiScenarioIdNotLike(String value) { - addCriterion("api_scenario_id not like", value, "apiScenarioId"); - return (Criteria) this; - } - - public Criteria andApiScenarioIdIn(List values) { - addCriterion("api_scenario_id in", values, "apiScenarioId"); - return (Criteria) this; - } - - public Criteria andApiScenarioIdNotIn(List values) { - addCriterion("api_scenario_id not in", values, "apiScenarioId"); - return (Criteria) this; - } - - public Criteria andApiScenarioIdBetween(String value1, String value2) { - addCriterion("api_scenario_id between", value1, value2, "apiScenarioId"); - return (Criteria) this; - } - - public Criteria andApiScenarioIdNotBetween(String value1, String value2) { - addCriterion("api_scenario_id not between", value1, value2, "apiScenarioId"); - return (Criteria) this; - } - - public Criteria andEnvironmentIdIsNull() { - addCriterion("environment_id is null"); - return (Criteria) this; - } - - public Criteria andEnvironmentIdIsNotNull() { - addCriterion("environment_id is not null"); - return (Criteria) this; - } - - public Criteria andEnvironmentIdEqualTo(String value) { - addCriterion("environment_id =", value, "environmentId"); - return (Criteria) this; - } - - public Criteria andEnvironmentIdNotEqualTo(String value) { - addCriterion("environment_id <>", value, "environmentId"); - return (Criteria) this; - } - - public Criteria andEnvironmentIdGreaterThan(String value) { - addCriterion("environment_id >", value, "environmentId"); - return (Criteria) this; - } - - public Criteria andEnvironmentIdGreaterThanOrEqualTo(String value) { - addCriterion("environment_id >=", value, "environmentId"); - return (Criteria) this; - } - - public Criteria andEnvironmentIdLessThan(String value) { - addCriterion("environment_id <", value, "environmentId"); - return (Criteria) this; - } - - public Criteria andEnvironmentIdLessThanOrEqualTo(String value) { - addCriterion("environment_id <=", value, "environmentId"); - return (Criteria) this; - } - - public Criteria andEnvironmentIdLike(String value) { - addCriterion("environment_id like", value, "environmentId"); - return (Criteria) this; - } - - public Criteria andEnvironmentIdNotLike(String value) { - addCriterion("environment_id not like", value, "environmentId"); - return (Criteria) this; - } - - public Criteria andEnvironmentIdIn(List values) { - addCriterion("environment_id in", values, "environmentId"); - return (Criteria) this; - } - - public Criteria andEnvironmentIdNotIn(List values) { - addCriterion("environment_id not in", values, "environmentId"); - return (Criteria) this; - } - - public Criteria andEnvironmentIdBetween(String value1, String value2) { - addCriterion("environment_id between", value1, value2, "environmentId"); - return (Criteria) this; - } - - public Criteria andEnvironmentIdNotBetween(String value1, String value2) { - addCriterion("environment_id not between", value1, value2, "environmentId"); - return (Criteria) this; - } - - public Criteria andEnvironmentGroupIdIsNull() { - addCriterion("environment_group_id is null"); - return (Criteria) this; - } - - public Criteria andEnvironmentGroupIdIsNotNull() { - addCriterion("environment_group_id is not null"); - return (Criteria) this; - } - - public Criteria andEnvironmentGroupIdEqualTo(String value) { - addCriterion("environment_group_id =", value, "environmentGroupId"); - return (Criteria) this; - } - - public Criteria andEnvironmentGroupIdNotEqualTo(String value) { - addCriterion("environment_group_id <>", value, "environmentGroupId"); - return (Criteria) this; - } - - public Criteria andEnvironmentGroupIdGreaterThan(String value) { - addCriterion("environment_group_id >", value, "environmentGroupId"); - return (Criteria) this; - } - - public Criteria andEnvironmentGroupIdGreaterThanOrEqualTo(String value) { - addCriterion("environment_group_id >=", value, "environmentGroupId"); - return (Criteria) this; - } - - public Criteria andEnvironmentGroupIdLessThan(String value) { - addCriterion("environment_group_id <", value, "environmentGroupId"); - return (Criteria) this; - } - - public Criteria andEnvironmentGroupIdLessThanOrEqualTo(String value) { - addCriterion("environment_group_id <=", value, "environmentGroupId"); - return (Criteria) this; - } - - public Criteria andEnvironmentGroupIdLike(String value) { - addCriterion("environment_group_id like", value, "environmentGroupId"); - return (Criteria) this; - } - - public Criteria andEnvironmentGroupIdNotLike(String value) { - addCriterion("environment_group_id not like", value, "environmentGroupId"); - return (Criteria) this; - } - - public Criteria andEnvironmentGroupIdIn(List values) { - addCriterion("environment_group_id in", values, "environmentGroupId"); - return (Criteria) this; - } - - public Criteria andEnvironmentGroupIdNotIn(List values) { - addCriterion("environment_group_id not in", values, "environmentGroupId"); - return (Criteria) this; - } - - public Criteria andEnvironmentGroupIdBetween(String value1, String value2) { - addCriterion("environment_group_id between", value1, value2, "environmentGroupId"); - return (Criteria) this; - } - - public Criteria andEnvironmentGroupIdNotBetween(String value1, String value2) { - addCriterion("environment_group_id not between", value1, value2, "environmentGroupId"); - 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/api/mapper/ApiScenarioEnvironmentMapper.java b/backend/framework/domain/src/main/java/io/metersphere/api/mapper/ApiScenarioEnvironmentMapper.java deleted file mode 100644 index 78c2238ed6..0000000000 --- a/backend/framework/domain/src/main/java/io/metersphere/api/mapper/ApiScenarioEnvironmentMapper.java +++ /dev/null @@ -1,34 +0,0 @@ -package io.metersphere.api.mapper; - -import io.metersphere.api.domain.ApiScenarioEnvironment; -import io.metersphere.api.domain.ApiScenarioEnvironmentExample; -import java.util.List; -import org.apache.ibatis.annotations.Param; - -public interface ApiScenarioEnvironmentMapper { - long countByExample(ApiScenarioEnvironmentExample example); - - int deleteByExample(ApiScenarioEnvironmentExample example); - - int deleteByPrimaryKey(String apiScenarioId); - - int insert(ApiScenarioEnvironment record); - - int insertSelective(ApiScenarioEnvironment record); - - List selectByExample(ApiScenarioEnvironmentExample example); - - ApiScenarioEnvironment selectByPrimaryKey(String apiScenarioId); - - int updateByExampleSelective(@Param("record") ApiScenarioEnvironment record, @Param("example") ApiScenarioEnvironmentExample example); - - int updateByExample(@Param("record") ApiScenarioEnvironment record, @Param("example") ApiScenarioEnvironmentExample example); - - int updateByPrimaryKeySelective(ApiScenarioEnvironment record); - - int updateByPrimaryKey(ApiScenarioEnvironment record); - - int batchInsert(@Param("list") List list); - - int batchInsertSelective(@Param("list") List list, @Param("selective") ApiScenarioEnvironment.Column ... selective); -} \ No newline at end of file diff --git a/backend/framework/domain/src/main/java/io/metersphere/api/mapper/ApiScenarioEnvironmentMapper.xml b/backend/framework/domain/src/main/java/io/metersphere/api/mapper/ApiScenarioEnvironmentMapper.xml deleted file mode 100644 index 020e39eff7..0000000000 --- a/backend/framework/domain/src/main/java/io/metersphere/api/mapper/ApiScenarioEnvironmentMapper.xml +++ /dev/null @@ -1,213 +0,0 @@ - - - - - - - - - - - - - - - - - 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} - - - - - - - - - - - api_scenario_id, environment_id, environment_group_id - - - - - delete from api_scenario_environment - where api_scenario_id = #{apiScenarioId,jdbcType=VARCHAR} - - - delete from api_scenario_environment - - - - - - insert into api_scenario_environment (api_scenario_id, environment_id, environment_group_id - ) - values (#{apiScenarioId,jdbcType=VARCHAR}, #{environmentId,jdbcType=VARCHAR}, #{environmentGroupId,jdbcType=VARCHAR} - ) - - - insert into api_scenario_environment - - - api_scenario_id, - - - environment_id, - - - environment_group_id, - - - - - #{apiScenarioId,jdbcType=VARCHAR}, - - - #{environmentId,jdbcType=VARCHAR}, - - - #{environmentGroupId,jdbcType=VARCHAR}, - - - - - - update api_scenario_environment - - - api_scenario_id = #{record.apiScenarioId,jdbcType=VARCHAR}, - - - environment_id = #{record.environmentId,jdbcType=VARCHAR}, - - - environment_group_id = #{record.environmentGroupId,jdbcType=VARCHAR}, - - - - - - - - update api_scenario_environment - set api_scenario_id = #{record.apiScenarioId,jdbcType=VARCHAR}, - environment_id = #{record.environmentId,jdbcType=VARCHAR}, - environment_group_id = #{record.environmentGroupId,jdbcType=VARCHAR} - - - - - - update api_scenario_environment - - - environment_id = #{environmentId,jdbcType=VARCHAR}, - - - environment_group_id = #{environmentGroupId,jdbcType=VARCHAR}, - - - where api_scenario_id = #{apiScenarioId,jdbcType=VARCHAR} - - - update api_scenario_environment - set environment_id = #{environmentId,jdbcType=VARCHAR}, - environment_group_id = #{environmentGroupId,jdbcType=VARCHAR} - where api_scenario_id = #{apiScenarioId,jdbcType=VARCHAR} - - - insert into api_scenario_environment - (api_scenario_id, environment_id, environment_group_id) - values - - (#{item.apiScenarioId,jdbcType=VARCHAR}, #{item.environmentId,jdbcType=VARCHAR}, - #{item.environmentGroupId,jdbcType=VARCHAR}) - - - - insert into api_scenario_environment ( - - ${column.escapedColumnName} - - ) - values - - ( - - - #{item.apiScenarioId,jdbcType=VARCHAR} - - - #{item.environmentId,jdbcType=VARCHAR} - - - #{item.environmentGroupId,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_5__api_test.sql b/backend/framework/domain/src/main/resources/migration/3.0.0/ddl/V3.0.0_5__api_test.sql index cd1dc9e71b..33c121568f 100644 --- a/backend/framework/domain/src/main/resources/migration/3.0.0/ddl/V3.0.0_5__api_test.sql +++ b/backend/framework/domain/src/main/resources/migration/3.0.0/ddl/V3.0.0_5__api_test.sql @@ -178,7 +178,7 @@ CREATE TABLE IF NOT EXISTS api_report_detail( COLLATE = utf8mb4_general_ci COMMENT = 'API/CASE执行结果详情'; CREATE INDEX idx_report ON api_report_detail(report_id); -CREATE INDEX idx_resource_id ON api_report_detail(resource_id); +CREATE INDEX idx_step_id ON api_report_detail(step_id); CREATE TABLE api_report_log( `id` VARCHAR(50) NOT NULL COMMENT '主键' , @@ -562,19 +562,6 @@ CREATE TABLE IF NOT EXISTS api_test_case_blob( DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '接口用例详情'; -CREATE TABLE IF NOT EXISTS api_scenario_environment( - `api_scenario_id` VARCHAR(50) NOT NULL COMMENT '场景fk' , - `environment_id` VARCHAR(50) COMMENT '环境fk' , - `environment_group_id` VARCHAR(50) COMMENT '环境组fk' , - PRIMARY KEY (api_scenario_id) -) ENGINE = InnoDB - DEFAULT CHARSET = utf8mb4 - COLLATE = utf8mb4_general_ci COMMENT = '场景环境'; - -CREATE INDEX idx_api_scenario_id ON api_scenario_environment(api_scenario_id); -CREATE INDEX idx_environment_id ON api_scenario_environment(environment_id); - - CREATE TABLE IF NOT EXISTS api_file_resource( `resource_id` VARCHAR(50) NOT NULL COMMENT '资源ID(接口用例等)' , `file_id` VARCHAR(50) NOT NULL COMMENT '文件ID' , diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiScenarioMapper.xml b/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiScenarioMapper.xml index 5fefaaa3d9..1ae2f53f0c 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiScenarioMapper.xml +++ b/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiScenarioMapper.xml @@ -13,7 +13,7 @@ select api_scenario.id, api_scenario.`name`,api_scenario.priority, api_scenario.step_total,api_scenario.request_pass_rate,api_scenario.last_report_status, - api_scenario.request_execution_rate, + api_scenario.environment_id, api_scenario.last_report_id,api_scenario.grouped, api_scenario.`status`, api_scenario.num, api_scenario.tags, api_scenario.pos, api_scenario.project_id, api_scenario.module_id, api_scenario.latest, api_scenario.version_id, diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiTestCaseService.java b/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiTestCaseService.java index b251642031..ef2fcea439 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiTestCaseService.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiTestCaseService.java @@ -370,6 +370,7 @@ public class ApiTestCaseService { } return ids; } else { + request.getSelectIds().removeAll(request.getExcludeIds()); return request.getSelectIds(); } } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/service/scenario/ApiScenarioService.java b/backend/services/api-test/src/main/java/io/metersphere/api/service/scenario/ApiScenarioService.java index 9a65b74573..3aba1d302b 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/service/scenario/ApiScenarioService.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/service/scenario/ApiScenarioService.java @@ -5,7 +5,10 @@ import io.metersphere.api.domain.*; import io.metersphere.api.dto.scenario.ApiScenarioBatchEditRequest; import io.metersphere.api.dto.scenario.ApiScenarioDTO; import io.metersphere.api.dto.scenario.ApiScenarioPageRequest; -import io.metersphere.api.mapper.*; +import io.metersphere.api.mapper.ApiScenarioFollowerMapper; +import io.metersphere.api.mapper.ApiScenarioMapper; +import io.metersphere.api.mapper.ApiScenarioModuleMapper; +import io.metersphere.api.mapper.ExtApiScenarioMapper; import io.metersphere.sdk.domain.Environment; import io.metersphere.sdk.domain.EnvironmentExample; import io.metersphere.sdk.domain.EnvironmentGroup; @@ -50,8 +53,6 @@ public class ApiScenarioService { @Resource private UserLoginService userLoginService; @Resource - private ApiScenarioEnvironmentMapper apiScenarioEnvironmentMapper; - @Resource private ApiScenarioModuleMapper apiScenarioModuleMapper; @Resource private EnvironmentMapper environmentMapper; @@ -82,21 +83,13 @@ public class ApiScenarioService { private void processApiScenario(List scenarioLists) { Set userIds = extractUserIds(scenarioLists); Map userMap = userLoginService.getUserNameMap(new ArrayList<>(userIds)); - //取出所有的apiId - List scenarioIds = scenarioLists.stream().map(ApiScenarioDTO::getId).distinct().toList(); - ApiScenarioEnvironmentExample scenarioEnvironmentExample = new ApiScenarioEnvironmentExample(); - scenarioEnvironmentExample.createCriteria().andApiScenarioIdIn(scenarioIds); - List apiScenarioEnvironments = apiScenarioEnvironmentMapper.selectByExample(scenarioEnvironmentExample); - //生成map key为id value为ApiScenarioEnvironment - Map environmentMap = apiScenarioEnvironments.stream().collect(Collectors.toMap(ApiScenarioEnvironment::getApiScenarioId, item -> item)); - List envIds = apiScenarioEnvironments.stream().map(ApiScenarioEnvironment::getEnvironmentId).toList(); + List envIds = scenarioLists.stream().map(ApiScenarioDTO::getEnvironmentId).toList(); EnvironmentExample environmentExample = new EnvironmentExample(); environmentExample.createCriteria().andIdIn(envIds); List environments = environmentMapper.selectByExample(environmentExample); Map envMap = environments.stream().collect(Collectors.toMap(Environment::getId, Environment::getName)); - List envGroupIds = apiScenarioEnvironments.stream().map(ApiScenarioEnvironment::getEnvironmentGroupId).toList(); EnvironmentGroupExample groupExample = new EnvironmentGroupExample(); - groupExample.createCriteria().andIdIn(envGroupIds); + groupExample.createCriteria().andIdIn(envIds); List environmentGroups = environmentGroupMapper.selectByExample(groupExample); Map groupMap = environmentGroups.stream().collect(Collectors.toMap(EnvironmentGroup::getId, EnvironmentGroup::getName)); //取模块id为新的set @@ -111,14 +104,10 @@ public class ApiScenarioService { item.setDeleteUserName(userMap.get(item.getDeleteUser())); item.setUpdateUserName(userMap.get(item.getUpdateUser())); item.setModulePath(StringUtils.isNotBlank(moduleMap.get(item.getModuleId())) ? moduleMap.get(item.getModuleId()) : Translator.get("api_unplanned_scenario")); - if (!item.getGrouped() && environmentMap.containsKey(item.getId()) && - StringUtils.isNotBlank(environmentMap.get(item.getId()).getEnvironmentId()) && - envMap.containsKey(environmentMap.get(item.getId()).getEnvironmentId())) { - item.setEnvironmentName(environmentMap.get(item.getId()).getEnvironmentId()); - } else if (item.getGrouped() && environmentMap.containsKey(item.getId()) && - StringUtils.isNotBlank(environmentMap.get(item.getId()).getEnvironmentGroupId()) && - groupMap.containsKey(environmentMap.get(item.getId()).getEnvironmentGroupId())) { - item.setEnvironmentName(groupMap.get(item.getId())); + if (!item.getGrouped() && envMap.containsKey(item.getEnvironmentId())) { + item.setEnvironmentName(envMap.get(item.getEnvironmentId())); + } else if (item.getGrouped() && groupMap.containsKey(item.getId())) { + item.setEnvironmentName(groupMap.get(item.getEnvironmentId())); } }); } @@ -150,7 +139,7 @@ public class ApiScenarioService { case PRIORITY -> batchUpdatePriority(example, updateScenario, request.getPriority()); case STATUS -> batchUpdateStatus(example, updateScenario, request.getStatus()); case TAGS -> batchUpdateTags(example, updateScenario, request, ids, sqlSession, mapper); - case ENVIRONMENT -> batchUpdateEnvironment(example, updateScenario, request, ids); + case ENVIRONMENT -> batchUpdateEnvironment(example, updateScenario, request); default -> throw new MSException(Translator.get("batch_edit_type_error")); } List scenarioInfoByIds = extApiScenarioMapper.getInfoByIds(ids, false); @@ -158,8 +147,7 @@ public class ApiScenarioService { } private void batchUpdateEnvironment(ApiScenarioExample example, ApiScenario updateScenario, - ApiScenarioBatchEditRequest request, - List ids) { + ApiScenarioBatchEditRequest request) { if (BooleanUtils.isFalse(request.isGrouped())) { if (StringUtils.isBlank(request.getEnvId())) { throw new MSException(Translator.get("environment_id_is_null")); @@ -169,11 +157,7 @@ public class ApiScenarioService { throw new MSException(Translator.get("environment_is_not_exist")); } updateScenario.setGrouped(false); - ApiScenarioEnvironment apiScenarioEnvironment = new ApiScenarioEnvironment(); - apiScenarioEnvironment.setEnvironmentId(request.getEnvId()); - ApiScenarioEnvironmentExample environmentExample = new ApiScenarioEnvironmentExample(); - environmentExample.createCriteria().andApiScenarioIdIn(ids); - apiScenarioEnvironmentMapper.updateByExampleSelective(apiScenarioEnvironment, environmentExample); + updateScenario.setEnvironmentId(request.getEnvId()); } else { if (StringUtils.isBlank(request.getGroupId())) { throw new MSException(Translator.get("environment_group_id_is_null")); @@ -183,11 +167,7 @@ public class ApiScenarioService { throw new MSException(Translator.get("environment_group_is_not_exist")); } updateScenario.setGrouped(true); - ApiScenarioEnvironment apiScenarioEnvironment = new ApiScenarioEnvironment(); - apiScenarioEnvironment.setEnvironmentGroupId(request.getGroupId()); - ApiScenarioEnvironmentExample environmentExample = new ApiScenarioEnvironmentExample(); - environmentExample.createCriteria().andApiScenarioIdIn(ids); - apiScenarioEnvironmentMapper.updateByExampleSelective(apiScenarioEnvironment, environmentExample); + updateScenario.setEnvironmentId(request.getGroupId()); } apiScenarioMapper.updateByExampleSelective(updateScenario, example); diff --git a/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiScenarioControllerTests.java b/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiScenarioControllerTests.java index a58e8428b6..47bf966fe2 100644 --- a/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiScenarioControllerTests.java +++ b/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiScenarioControllerTests.java @@ -4,7 +4,10 @@ import io.metersphere.api.domain.*; import io.metersphere.api.dto.scenario.ApiScenarioBatchEditRequest; import io.metersphere.api.dto.scenario.ApiScenarioDTO; import io.metersphere.api.dto.scenario.ApiScenarioPageRequest; -import io.metersphere.api.mapper.*; +import io.metersphere.api.mapper.ApiScenarioFollowerMapper; +import io.metersphere.api.mapper.ApiScenarioMapper; +import io.metersphere.api.mapper.ApiScenarioModuleMapper; +import io.metersphere.api.mapper.ExtApiScenarioMapper; import io.metersphere.sdk.constants.ApplicationNumScope; import io.metersphere.sdk.constants.PermissionConstants; import io.metersphere.sdk.constants.SessionConstants; @@ -57,8 +60,6 @@ public class ApiScenarioControllerTests extends BaseTest { @Resource private ExtApiScenarioMapper extApiScenarioMapper; @Resource - private ApiScenarioEnvironmentMapper apiScenarioEnvironmentMapper; - @Resource private EnvironmentMapper environmentMapper; @Resource private ApiScenarioFollowerMapper apiScenarioFollowerMapper; @@ -132,18 +133,15 @@ public class ApiScenarioControllerTests extends BaseTest { apiScenario.setUpdateTime(System.currentTimeMillis()); apiScenario.setCreateUser("admin"); apiScenario.setUpdateUser("admin"); - ApiScenarioEnvironment apiScenarioEnvironment = new ApiScenarioEnvironment(); - apiScenarioEnvironment.setApiScenarioId(apiScenario.getId()); if (i % 2 == 0) { apiScenario.setTags(new ArrayList<>(List.of("tag1", "tag2"))); apiScenario.setGrouped(true); - apiScenarioEnvironment.setEnvironmentGroupId("scenario-environment-group-id"); + apiScenario.setEnvironmentId("scenario-environment-group-id"); } else { apiScenario.setGrouped(false); - apiScenarioEnvironment.setEnvironmentId(environments.get(0).getId()); + apiScenario.setEnvironmentId(environments.get(0).getId()); } apiScenarioMapper.insertSelective(apiScenario); - apiScenarioEnvironmentMapper.insertSelective(apiScenarioEnvironment); } } @@ -176,9 +174,6 @@ public class ApiScenarioControllerTests extends BaseTest { apiScenario.setCreateUser("admin"); apiScenario.setUpdateUser("admin"); apiScenarioMapper.insertSelective(apiScenario); - ApiScenarioEnvironment apiScenarioEnvironment = new ApiScenarioEnvironment(); - apiScenarioEnvironment.setApiScenarioId(apiScenario.getId()); - apiScenarioEnvironmentMapper.insertSelective(apiScenarioEnvironment); } } @@ -362,13 +357,9 @@ public class ApiScenarioControllerTests extends BaseTest { List environments = environmentMapper.selectByExample(environmentExample); request.setEnvId(environments.get(0).getId()); responsePost(BATCH_EDIT, request); - //取所有的ids - List scenarioIds = apiScenarios.stream().map(ApiScenario::getId).toList(); //判断数据的环境是不是environments.get(0).getId() - ApiScenarioEnvironmentExample apiScenarioEnvironmentExample = new ApiScenarioEnvironmentExample(); - apiScenarioEnvironmentExample.createCriteria().andApiScenarioIdIn(scenarioIds); - List apiScenarioEnvironments = apiScenarioEnvironmentMapper.selectByExample(apiScenarioEnvironmentExample); - apiScenarioEnvironments.forEach(apiTestCase -> Assertions.assertEquals(apiTestCase.getEnvironmentId(), environments.get(0).getId())); + apiScenarios = apiScenarioMapper.selectByExample(example); + apiScenarios.forEach(apiTestCase -> Assertions.assertEquals(apiTestCase.getEnvironmentId(), environments.get(0).getId())); //环境数据为空 request.setEnvId(null); @@ -380,10 +371,12 @@ public class ApiScenarioControllerTests extends BaseTest { request.setGrouped(true); request.setGroupId("scenario-environment-group-id"); responsePost(BATCH_EDIT, request); - apiScenarioEnvironments = apiScenarioEnvironmentMapper.selectByExample(apiScenarioEnvironmentExample); - apiScenarioEnvironments.forEach(apiTestCase -> Assertions.assertEquals(apiTestCase.getEnvironmentGroupId(), "scenario-environment-group-id")); apiScenarios = apiScenarioMapper.selectByExample(example); - apiScenarios.forEach(apiTestCase -> Assertions.assertEquals(apiTestCase.getGrouped(), true)); + apiScenarios.forEach(apiTestCase -> { + Assertions.assertEquals(apiTestCase.getGrouped(), true); + Assertions.assertEquals(apiTestCase.getEnvironmentId(), "scenario-environment-group-id"); + }); + //环境组数据为空 request.setGroupId(null);