diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsHTTPSamplerProxy.java b/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsHTTPSamplerProxy.java index 42a3d68135..413a41e135 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsHTTPSamplerProxy.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsHTTPSamplerProxy.java @@ -253,9 +253,10 @@ public class MsHTTPSamplerProxy extends MsTestElement { if (CollectionUtils.isNotEmpty(hashTree)) { for (MsTestElement el : hashTree) { - if(this.getEnvironmentId() == null){ + if(this.getEnvironmentId() == null || el.getEnvironmentId() == null){ el.setEnvironmentId(useEnvironment); } + el.toHashTree(httpSamplerTree, el.getHashTree(), config); } } diff --git a/backend/src/main/java/io/metersphere/base/domain/TestPlanReportResource.java b/backend/src/main/java/io/metersphere/base/domain/TestPlanReportResource.java new file mode 100644 index 0000000000..d9aced46bd --- /dev/null +++ b/backend/src/main/java/io/metersphere/base/domain/TestPlanReportResource.java @@ -0,0 +1,19 @@ +package io.metersphere.base.domain; + +import java.io.Serializable; +import lombok.Data; + +@Data +public class TestPlanReportResource implements Serializable { + private String id; + + private String testPlanReportId; + + private String resourceId; + + private String resourceType; + + private String executeResult; + + private static final long serialVersionUID = 1L; +} \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/base/domain/TestPlanReportResourceExample.java b/backend/src/main/java/io/metersphere/base/domain/TestPlanReportResourceExample.java new file mode 100644 index 0000000000..93e2afd28d --- /dev/null +++ b/backend/src/main/java/io/metersphere/base/domain/TestPlanReportResourceExample.java @@ -0,0 +1,550 @@ +package io.metersphere.base.domain; + +import java.util.ArrayList; +import java.util.List; + +public class TestPlanReportResourceExample { + protected String orderByClause; + + protected boolean distinct; + + protected List oredCriteria; + + public TestPlanReportResourceExample() { + 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 andIdIsNull() { + addCriterion("id is null"); + return (Criteria) this; + } + + public Criteria andIdIsNotNull() { + addCriterion("id is not null"); + return (Criteria) this; + } + + public Criteria andIdEqualTo(String value) { + addCriterion("id =", value, "id"); + return (Criteria) this; + } + + public Criteria andIdNotEqualTo(String value) { + addCriterion("id <>", value, "id"); + return (Criteria) this; + } + + public Criteria andIdGreaterThan(String value) { + addCriterion("id >", value, "id"); + return (Criteria) this; + } + + public Criteria andIdGreaterThanOrEqualTo(String value) { + addCriterion("id >=", value, "id"); + return (Criteria) this; + } + + public Criteria andIdLessThan(String value) { + addCriterion("id <", value, "id"); + return (Criteria) this; + } + + public Criteria andIdLessThanOrEqualTo(String value) { + addCriterion("id <=", value, "id"); + return (Criteria) this; + } + + public Criteria andIdLike(String value) { + addCriterion("id like", value, "id"); + return (Criteria) this; + } + + public Criteria andIdNotLike(String value) { + addCriterion("id not like", value, "id"); + return (Criteria) this; + } + + public Criteria andIdIn(List values) { + addCriterion("id in", values, "id"); + return (Criteria) this; + } + + public Criteria andIdNotIn(List values) { + addCriterion("id not in", values, "id"); + return (Criteria) this; + } + + public Criteria andIdBetween(String value1, String value2) { + addCriterion("id between", value1, value2, "id"); + return (Criteria) this; + } + + public Criteria andIdNotBetween(String value1, String value2) { + addCriterion("id not between", value1, value2, "id"); + return (Criteria) this; + } + + public Criteria andTestPlanReportIdIsNull() { + addCriterion("test_plan_report_id is null"); + return (Criteria) this; + } + + public Criteria andTestPlanReportIdIsNotNull() { + addCriterion("test_plan_report_id is not null"); + return (Criteria) this; + } + + public Criteria andTestPlanReportIdEqualTo(String value) { + addCriterion("test_plan_report_id =", value, "testPlanReportId"); + return (Criteria) this; + } + + public Criteria andTestPlanReportIdNotEqualTo(String value) { + addCriterion("test_plan_report_id <>", value, "testPlanReportId"); + return (Criteria) this; + } + + public Criteria andTestPlanReportIdGreaterThan(String value) { + addCriterion("test_plan_report_id >", value, "testPlanReportId"); + return (Criteria) this; + } + + public Criteria andTestPlanReportIdGreaterThanOrEqualTo(String value) { + addCriterion("test_plan_report_id >=", value, "testPlanReportId"); + return (Criteria) this; + } + + public Criteria andTestPlanReportIdLessThan(String value) { + addCriterion("test_plan_report_id <", value, "testPlanReportId"); + return (Criteria) this; + } + + public Criteria andTestPlanReportIdLessThanOrEqualTo(String value) { + addCriterion("test_plan_report_id <=", value, "testPlanReportId"); + return (Criteria) this; + } + + public Criteria andTestPlanReportIdLike(String value) { + addCriterion("test_plan_report_id like", value, "testPlanReportId"); + return (Criteria) this; + } + + public Criteria andTestPlanReportIdNotLike(String value) { + addCriterion("test_plan_report_id not like", value, "testPlanReportId"); + return (Criteria) this; + } + + public Criteria andTestPlanReportIdIn(List values) { + addCriterion("test_plan_report_id in", values, "testPlanReportId"); + return (Criteria) this; + } + + public Criteria andTestPlanReportIdNotIn(List values) { + addCriterion("test_plan_report_id not in", values, "testPlanReportId"); + return (Criteria) this; + } + + public Criteria andTestPlanReportIdBetween(String value1, String value2) { + addCriterion("test_plan_report_id between", value1, value2, "testPlanReportId"); + return (Criteria) this; + } + + public Criteria andTestPlanReportIdNotBetween(String value1, String value2) { + addCriterion("test_plan_report_id not between", value1, value2, "testPlanReportId"); + return (Criteria) this; + } + + public Criteria andResourceIdIsNull() { + addCriterion("resource_id is null"); + return (Criteria) this; + } + + public Criteria andResourceIdIsNotNull() { + addCriterion("resource_id is not null"); + return (Criteria) this; + } + + public Criteria andResourceIdEqualTo(String value) { + addCriterion("resource_id =", value, "resourceId"); + return (Criteria) this; + } + + public Criteria andResourceIdNotEqualTo(String value) { + addCriterion("resource_id <>", value, "resourceId"); + return (Criteria) this; + } + + public Criteria andResourceIdGreaterThan(String value) { + addCriterion("resource_id >", value, "resourceId"); + return (Criteria) this; + } + + public Criteria andResourceIdGreaterThanOrEqualTo(String value) { + addCriterion("resource_id >=", value, "resourceId"); + return (Criteria) this; + } + + public Criteria andResourceIdLessThan(String value) { + addCriterion("resource_id <", value, "resourceId"); + return (Criteria) this; + } + + public Criteria andResourceIdLessThanOrEqualTo(String value) { + addCriterion("resource_id <=", value, "resourceId"); + return (Criteria) this; + } + + public Criteria andResourceIdLike(String value) { + addCriterion("resource_id like", value, "resourceId"); + return (Criteria) this; + } + + public Criteria andResourceIdNotLike(String value) { + addCriterion("resource_id not like", value, "resourceId"); + return (Criteria) this; + } + + public Criteria andResourceIdIn(List values) { + addCriterion("resource_id in", values, "resourceId"); + return (Criteria) this; + } + + public Criteria andResourceIdNotIn(List values) { + addCriterion("resource_id not in", values, "resourceId"); + return (Criteria) this; + } + + public Criteria andResourceIdBetween(String value1, String value2) { + addCriterion("resource_id between", value1, value2, "resourceId"); + return (Criteria) this; + } + + public Criteria andResourceIdNotBetween(String value1, String value2) { + addCriterion("resource_id not between", value1, value2, "resourceId"); + return (Criteria) this; + } + + public Criteria andResourceTypeIsNull() { + addCriterion("resource_type is null"); + return (Criteria) this; + } + + public Criteria andResourceTypeIsNotNull() { + addCriterion("resource_type is not null"); + return (Criteria) this; + } + + public Criteria andResourceTypeEqualTo(String value) { + addCriterion("resource_type =", value, "resourceType"); + return (Criteria) this; + } + + public Criteria andResourceTypeNotEqualTo(String value) { + addCriterion("resource_type <>", value, "resourceType"); + return (Criteria) this; + } + + public Criteria andResourceTypeGreaterThan(String value) { + addCriterion("resource_type >", value, "resourceType"); + return (Criteria) this; + } + + public Criteria andResourceTypeGreaterThanOrEqualTo(String value) { + addCriterion("resource_type >=", value, "resourceType"); + return (Criteria) this; + } + + public Criteria andResourceTypeLessThan(String value) { + addCriterion("resource_type <", value, "resourceType"); + return (Criteria) this; + } + + public Criteria andResourceTypeLessThanOrEqualTo(String value) { + addCriterion("resource_type <=", value, "resourceType"); + return (Criteria) this; + } + + public Criteria andResourceTypeLike(String value) { + addCriterion("resource_type like", value, "resourceType"); + return (Criteria) this; + } + + public Criteria andResourceTypeNotLike(String value) { + addCriterion("resource_type not like", value, "resourceType"); + return (Criteria) this; + } + + public Criteria andResourceTypeIn(List values) { + addCriterion("resource_type in", values, "resourceType"); + return (Criteria) this; + } + + public Criteria andResourceTypeNotIn(List values) { + addCriterion("resource_type not in", values, "resourceType"); + return (Criteria) this; + } + + public Criteria andResourceTypeBetween(String value1, String value2) { + addCriterion("resource_type between", value1, value2, "resourceType"); + return (Criteria) this; + } + + public Criteria andResourceTypeNotBetween(String value1, String value2) { + addCriterion("resource_type not between", value1, value2, "resourceType"); + return (Criteria) this; + } + + public Criteria andExecuteResultIsNull() { + addCriterion("execute_result is null"); + return (Criteria) this; + } + + public Criteria andExecuteResultIsNotNull() { + addCriterion("execute_result is not null"); + return (Criteria) this; + } + + public Criteria andExecuteResultEqualTo(String value) { + addCriterion("execute_result =", value, "executeResult"); + return (Criteria) this; + } + + public Criteria andExecuteResultNotEqualTo(String value) { + addCriterion("execute_result <>", value, "executeResult"); + return (Criteria) this; + } + + public Criteria andExecuteResultGreaterThan(String value) { + addCriterion("execute_result >", value, "executeResult"); + return (Criteria) this; + } + + public Criteria andExecuteResultGreaterThanOrEqualTo(String value) { + addCriterion("execute_result >=", value, "executeResult"); + return (Criteria) this; + } + + public Criteria andExecuteResultLessThan(String value) { + addCriterion("execute_result <", value, "executeResult"); + return (Criteria) this; + } + + public Criteria andExecuteResultLessThanOrEqualTo(String value) { + addCriterion("execute_result <=", value, "executeResult"); + return (Criteria) this; + } + + public Criteria andExecuteResultLike(String value) { + addCriterion("execute_result like", value, "executeResult"); + return (Criteria) this; + } + + public Criteria andExecuteResultNotLike(String value) { + addCriterion("execute_result not like", value, "executeResult"); + return (Criteria) this; + } + + public Criteria andExecuteResultIn(List values) { + addCriterion("execute_result in", values, "executeResult"); + return (Criteria) this; + } + + public Criteria andExecuteResultNotIn(List values) { + addCriterion("execute_result not in", values, "executeResult"); + return (Criteria) this; + } + + public Criteria andExecuteResultBetween(String value1, String value2) { + addCriterion("execute_result between", value1, value2, "executeResult"); + return (Criteria) this; + } + + public Criteria andExecuteResultNotBetween(String value1, String value2) { + addCriterion("execute_result not between", value1, value2, "executeResult"); + 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/src/main/java/io/metersphere/base/domain/TestPlanTestCase.java b/backend/src/main/java/io/metersphere/base/domain/TestPlanTestCase.java index 3f57aeab86..63a834c7d7 100644 --- a/backend/src/main/java/io/metersphere/base/domain/TestPlanTestCase.java +++ b/backend/src/main/java/io/metersphere/base/domain/TestPlanTestCase.java @@ -11,8 +11,6 @@ public class TestPlanTestCase implements Serializable { private String caseId; - private String reportId; - private String executor; private String status; @@ -23,9 +21,11 @@ public class TestPlanTestCase implements Serializable { private Long updateTime; + private String reportId; + private String createUser; private Integer issuesCount; private static final long serialVersionUID = 1L; -} +} \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/base/domain/TestPlanTestCaseExample.java b/backend/src/main/java/io/metersphere/base/domain/TestPlanTestCaseExample.java index 55f91058ff..3498cecb28 100644 --- a/backend/src/main/java/io/metersphere/base/domain/TestPlanTestCaseExample.java +++ b/backend/src/main/java/io/metersphere/base/domain/TestPlanTestCaseExample.java @@ -314,76 +314,6 @@ public class TestPlanTestCaseExample { return (Criteria) this; } - public Criteria andReportIdIsNull() { - addCriterion("report_id is null"); - return (Criteria) this; - } - - public Criteria andReportIdIsNotNull() { - addCriterion("report_id is not null"); - return (Criteria) this; - } - - public Criteria andReportIdEqualTo(String value) { - addCriterion("report_id =", value, "reportId"); - return (Criteria) this; - } - - public Criteria andReportIdNotEqualTo(String value) { - addCriterion("report_id <>", value, "reportId"); - return (Criteria) this; - } - - public Criteria andReportIdGreaterThan(String value) { - addCriterion("report_id >", value, "reportId"); - return (Criteria) this; - } - - public Criteria andReportIdGreaterThanOrEqualTo(String value) { - addCriterion("report_id >=", value, "reportId"); - return (Criteria) this; - } - - public Criteria andReportIdLessThan(String value) { - addCriterion("report_id <", value, "reportId"); - return (Criteria) this; - } - - public Criteria andReportIdLessThanOrEqualTo(String value) { - addCriterion("report_id <=", value, "reportId"); - return (Criteria) this; - } - - public Criteria andReportIdLike(String value) { - addCriterion("report_id like", value, "reportId"); - return (Criteria) this; - } - - public Criteria andReportIdNotLike(String value) { - addCriterion("report_id not like", value, "reportId"); - return (Criteria) this; - } - - public Criteria andReportIdIn(List values) { - addCriterion("report_id in", values, "reportId"); - return (Criteria) this; - } - - public Criteria andReportIdNotIn(List values) { - addCriterion("report_id not in", values, "reportId"); - return (Criteria) this; - } - - public Criteria andReportIdBetween(String value1, String value2) { - addCriterion("report_id between", value1, value2, "reportId"); - return (Criteria) this; - } - - public Criteria andReportIdNotBetween(String value1, String value2) { - addCriterion("report_id not between", value1, value2, "reportId"); - return (Criteria) this; - } - public Criteria andExecutorIsNull() { addCriterion("executor is null"); return (Criteria) this; @@ -714,6 +644,76 @@ public class TestPlanTestCaseExample { return (Criteria) this; } + public Criteria andReportIdIsNull() { + addCriterion("report_id is null"); + return (Criteria) this; + } + + public Criteria andReportIdIsNotNull() { + addCriterion("report_id is not null"); + return (Criteria) this; + } + + public Criteria andReportIdEqualTo(String value) { + addCriterion("report_id =", value, "reportId"); + return (Criteria) this; + } + + public Criteria andReportIdNotEqualTo(String value) { + addCriterion("report_id <>", value, "reportId"); + return (Criteria) this; + } + + public Criteria andReportIdGreaterThan(String value) { + addCriterion("report_id >", value, "reportId"); + return (Criteria) this; + } + + public Criteria andReportIdGreaterThanOrEqualTo(String value) { + addCriterion("report_id >=", value, "reportId"); + return (Criteria) this; + } + + public Criteria andReportIdLessThan(String value) { + addCriterion("report_id <", value, "reportId"); + return (Criteria) this; + } + + public Criteria andReportIdLessThanOrEqualTo(String value) { + addCriterion("report_id <=", value, "reportId"); + return (Criteria) this; + } + + public Criteria andReportIdLike(String value) { + addCriterion("report_id like", value, "reportId"); + return (Criteria) this; + } + + public Criteria andReportIdNotLike(String value) { + addCriterion("report_id not like", value, "reportId"); + return (Criteria) this; + } + + public Criteria andReportIdIn(List values) { + addCriterion("report_id in", values, "reportId"); + return (Criteria) this; + } + + public Criteria andReportIdNotIn(List values) { + addCriterion("report_id not in", values, "reportId"); + return (Criteria) this; + } + + public Criteria andReportIdBetween(String value1, String value2) { + addCriterion("report_id between", value1, value2, "reportId"); + return (Criteria) this; + } + + public Criteria andReportIdNotBetween(String value1, String value2) { + addCriterion("report_id not between", value1, value2, "reportId"); + return (Criteria) this; + } + public Criteria andCreateUserIsNull() { addCriterion("create_user is null"); return (Criteria) this; @@ -937,4 +937,4 @@ public class TestPlanTestCaseExample { this(condition, value, secondValue, null); } } -} +} \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/base/mapper/TestPlanReportResourceMapper.java b/backend/src/main/java/io/metersphere/base/mapper/TestPlanReportResourceMapper.java new file mode 100644 index 0000000000..1e9580641a --- /dev/null +++ b/backend/src/main/java/io/metersphere/base/mapper/TestPlanReportResourceMapper.java @@ -0,0 +1,30 @@ +package io.metersphere.base.mapper; + +import io.metersphere.base.domain.TestPlanReportResource; +import io.metersphere.base.domain.TestPlanReportResourceExample; +import java.util.List; +import org.apache.ibatis.annotations.Param; + +public interface TestPlanReportResourceMapper { + long countByExample(TestPlanReportResourceExample example); + + int deleteByExample(TestPlanReportResourceExample example); + + int deleteByPrimaryKey(String id); + + int insert(TestPlanReportResource record); + + int insertSelective(TestPlanReportResource record); + + List selectByExample(TestPlanReportResourceExample example); + + TestPlanReportResource selectByPrimaryKey(String id); + + int updateByExampleSelective(@Param("record") TestPlanReportResource record, @Param("example") TestPlanReportResourceExample example); + + int updateByExample(@Param("record") TestPlanReportResource record, @Param("example") TestPlanReportResourceExample example); + + int updateByPrimaryKeySelective(TestPlanReportResource record); + + int updateByPrimaryKey(TestPlanReportResource record); +} \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/base/mapper/TestPlanReportResourceMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/TestPlanReportResourceMapper.xml new file mode 100644 index 0000000000..a6fb88a90b --- /dev/null +++ b/backend/src/main/java/io/metersphere/base/mapper/TestPlanReportResourceMapper.xml @@ -0,0 +1,211 @@ + + + + + + + + + + + + + + + + + + + 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} + + + + + + + + + + + id, test_plan_report_id, resource_id, resource_type, execute_result + + + + + delete from test_plan_report_resource + where id = #{id,jdbcType=VARCHAR} + + + delete from test_plan_report_resource + + + + + + insert into test_plan_report_resource (id, test_plan_report_id, resource_id, + resource_type, execute_result) + values (#{id,jdbcType=VARCHAR}, #{testPlanReportId,jdbcType=VARCHAR}, #{resourceId,jdbcType=VARCHAR}, + #{resourceType,jdbcType=VARCHAR}, #{executeResult,jdbcType=VARCHAR}) + + + insert into test_plan_report_resource + + + id, + + + test_plan_report_id, + + + resource_id, + + + resource_type, + + + execute_result, + + + + + #{id,jdbcType=VARCHAR}, + + + #{testPlanReportId,jdbcType=VARCHAR}, + + + #{resourceId,jdbcType=VARCHAR}, + + + #{resourceType,jdbcType=VARCHAR}, + + + #{executeResult,jdbcType=VARCHAR}, + + + + + + update test_plan_report_resource + + + id = #{record.id,jdbcType=VARCHAR}, + + + test_plan_report_id = #{record.testPlanReportId,jdbcType=VARCHAR}, + + + resource_id = #{record.resourceId,jdbcType=VARCHAR}, + + + resource_type = #{record.resourceType,jdbcType=VARCHAR}, + + + execute_result = #{record.executeResult,jdbcType=VARCHAR}, + + + + + + + + update test_plan_report_resource + set id = #{record.id,jdbcType=VARCHAR}, + test_plan_report_id = #{record.testPlanReportId,jdbcType=VARCHAR}, + resource_id = #{record.resourceId,jdbcType=VARCHAR}, + resource_type = #{record.resourceType,jdbcType=VARCHAR}, + execute_result = #{record.executeResult,jdbcType=VARCHAR} + + + + + + update test_plan_report_resource + + + test_plan_report_id = #{testPlanReportId,jdbcType=VARCHAR}, + + + resource_id = #{resourceId,jdbcType=VARCHAR}, + + + resource_type = #{resourceType,jdbcType=VARCHAR}, + + + execute_result = #{executeResult,jdbcType=VARCHAR}, + + + where id = #{id,jdbcType=VARCHAR} + + + update test_plan_report_resource + set test_plan_report_id = #{testPlanReportId,jdbcType=VARCHAR}, + resource_id = #{resourceId,jdbcType=VARCHAR}, + resource_type = #{resourceType,jdbcType=VARCHAR}, + execute_result = #{executeResult,jdbcType=VARCHAR} + where id = #{id,jdbcType=VARCHAR} + + \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/base/mapper/TestPlanTestCaseMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/TestPlanTestCaseMapper.xml index 3ea3f5ad28..aa5ed2d353 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/TestPlanTestCaseMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/TestPlanTestCaseMapper.xml @@ -5,12 +5,12 @@ - + @@ -78,7 +78,7 @@ - id, plan_id, case_id, report_id, executor, `status`, remark, create_time, update_time, + id, plan_id, case_id, executor, `status`, remark, create_time, update_time, report_id, create_user, issues_count @@ -115,7 +115,7 @@ + select resource_id,resource_type,execute_result from test_plan_report_resource + where test_plan_report_id = #{0} + + + diff --git a/backend/src/main/java/io/metersphere/commons/constants/TestPlanResourceType.java b/backend/src/main/java/io/metersphere/commons/constants/TestPlanResourceType.java new file mode 100644 index 0000000000..620d354193 --- /dev/null +++ b/backend/src/main/java/io/metersphere/commons/constants/TestPlanResourceType.java @@ -0,0 +1,5 @@ +package io.metersphere.commons.constants; + +public enum TestPlanResourceType { + API_CASE,SCENARIO_CASE,PERFORMANCE_CASE +} diff --git a/backend/src/main/java/io/metersphere/track/request/report/TestPlanReportSaveRequest.java b/backend/src/main/java/io/metersphere/track/request/report/TestPlanReportSaveRequest.java index 54c60f37ef..e322c34d67 100644 --- a/backend/src/main/java/io/metersphere/track/request/report/TestPlanReportSaveRequest.java +++ b/backend/src/main/java/io/metersphere/track/request/report/TestPlanReportSaveRequest.java @@ -3,6 +3,8 @@ package io.metersphere.track.request.report; import lombok.Getter; import lombok.Setter; +import java.util.Map; + /** * @author song.tianyang * @Date 2021/1/8 4:36 下午 @@ -21,9 +23,12 @@ public class TestPlanReportSaveRequest { private boolean scenarioIsExecuting; private boolean performanceIsExecuting; - private String apiCaseIdListJSON; - private String scenarioIdListJSON; - private String performanceIdListJSON; +// private String apiCaseIdListJSON; +// private String scenarioIdListJSON; +// private String performanceIdListJSON; + Map apiCaseIdMap; + Map scenarioIdMap; + Map performanceIdMap; public TestPlanReportSaveRequest(String reportID, String planId, String userId, String triggerMode) { this.reportID = reportID; @@ -34,7 +39,8 @@ public class TestPlanReportSaveRequest { this.countResources = true; } - public TestPlanReportSaveRequest(String reportID, String planId, String userId, String triggerMode, boolean apiCaseIsExecuting, boolean scenarioIsExecuting, boolean performanceIsExecuting, String apiCaseIdListJSON, String scenarioIdListJSON, String performanceIdListJSON) { + public TestPlanReportSaveRequest(String reportID, String planId, String userId, String triggerMode, boolean apiCaseIsExecuting, boolean scenarioIsExecuting, boolean performanceIsExecuting, + Map apiCaseIdMap, Map scenarioIdMap, Map performanceIdMap) { this.reportID = reportID; this.planId = planId; this.userId = userId; @@ -46,8 +52,8 @@ public class TestPlanReportSaveRequest { this.scenarioIsExecuting = scenarioIsExecuting; this.performanceIsExecuting = performanceIsExecuting; - this.apiCaseIdListJSON = apiCaseIdListJSON; - this.scenarioIdListJSON = scenarioIdListJSON; - this.performanceIdListJSON = performanceIdListJSON; + this.apiCaseIdMap = apiCaseIdMap; + this.scenarioIdMap = scenarioIdMap; + this.performanceIdMap = performanceIdMap; } } diff --git a/backend/src/main/java/io/metersphere/track/service/TestPlanReportResourceService.java b/backend/src/main/java/io/metersphere/track/service/TestPlanReportResourceService.java new file mode 100644 index 0000000000..6ef86bb27f --- /dev/null +++ b/backend/src/main/java/io/metersphere/track/service/TestPlanReportResourceService.java @@ -0,0 +1,73 @@ +package io.metersphere.track.service; + +import io.metersphere.base.domain.TestPlanReportResource; +import io.metersphere.base.domain.TestPlanReportResourceExample; +import io.metersphere.base.mapper.TestPlanReportResourceMapper; +import io.metersphere.base.mapper.ext.ExtTestPlanReportResourceMapper; +import org.apache.commons.collections.CollectionUtils; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * @author song.tianyang + * @Date 2021/8/2 1:57 下午 + */ +@Service +public class TestPlanReportResourceService { + @Resource + private TestPlanReportResourceMapper testPlanReportResourceMapper; + @Resource + private ExtTestPlanReportResourceMapper extTestPlanReportResourceMapper; + + public int updateExecuteResultByReportIdAndResourceIds(String executeResult, String planReportId, List ids) { + if(CollectionUtils.isEmpty(ids)){ + return 0; + }else { + TestPlanReportResourceExample example = new TestPlanReportResourceExample(); + example.createCriteria().andTestPlanReportIdEqualTo(planReportId).andResourceIdIn(ids); + + TestPlanReportResource updateModel = new TestPlanReportResource(); + updateModel.setExecuteResult(executeResult); + return testPlanReportResourceMapper.updateByExampleSelective(updateModel,example); + } + } + + public long countByReportIdAndResourceTypeAndExecuteResultNotEquals(String planReportId, String resourceType, String executeResult) { + TestPlanReportResourceExample example = new TestPlanReportResourceExample(); + example.createCriteria().andTestPlanReportIdEqualTo(planReportId).andResourceTypeEqualTo(resourceType).andExecuteResultNotEqualTo(executeResult); + return this.testPlanReportResourceMapper.countByExample(example); + } + + public long countByReportIdAndResourceTypeAndExecuteResultEquals(String planReportId, String resourceType, String executeResult) { + TestPlanReportResourceExample example = new TestPlanReportResourceExample(); + example.createCriteria().andTestPlanReportIdEqualTo(planReportId).andResourceTypeEqualTo(resourceType).andExecuteResultEqualTo(executeResult); + return this.testPlanReportResourceMapper.countByExample(example); + } + + public Map> selectExecuteResultByTestPlanReportId(String testPlanReportId) { + Map> resourceTypeMap = new HashMap<>(); + List testPlanReportResourceList = extTestPlanReportResourceMapper.selectResourceIdAndResourceTypeAndExecuteResultByTestPlanReportId(testPlanReportId); + for (TestPlanReportResource model : testPlanReportResourceList) { + String resourceType = model.getResourceType(); + String resourceId = model.getResourceId(); + String executeResult = model.getExecuteResult(); + + if(resourceTypeMap.containsKey(resourceType)){ + resourceTypeMap.get(resourceType).put(resourceId,executeResult); + }else { + Map map = new HashMap<>(); + map.put(resourceId,executeResult); + resourceTypeMap.put(resourceType,map); + } + } + return resourceTypeMap; + } + + public void deleteByExample(TestPlanReportResourceExample resourceExample) { + testPlanReportResourceMapper.deleteByExample(resourceExample); + } +} diff --git a/backend/src/main/java/io/metersphere/track/service/TestPlanReportService.java b/backend/src/main/java/io/metersphere/track/service/TestPlanReportService.java index a7c1414b4c..652b931ffd 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestPlanReportService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestPlanReportService.java @@ -72,6 +72,8 @@ public class TestPlanReportService { ExtTestPlanMapper extTestPlanMapper; @Resource ExtTestPlanApiCaseMapper extTestPlanApiCaseMapper; + @Resource + TestPlanReportResourceService testPlanReportResourceService; // @Resource // TestPlanLoadCaseService testPlanLoadCaseService; // @Resource @@ -90,7 +92,25 @@ public class TestPlanReportService { if (StringUtils.isNotBlank(projectId)) { request.setProjectId(projectId); } - return extTestPlanReportMapper.list(request); + List list = extTestPlanReportMapper.list(request); +// this.checkReport(list); + return list; + } +// private void checkReport(List list) { +// if(CollectionUtils.isNotEmpty(list)){ +// for (TestPlanReportDTO dto : list){ +// if(StringUtils.equalsIgnoreCase(dto.getStatus(),TestPlanApiExecuteStatus.RUNNING.name())){ +// TestPlanReport model = this.updateTestPlanReportById(dto.getId()); +// if(model != null && model.getStatus() != null){ +// dto.setStatus(model.getStatus()); +// } +// } +// } +// } +// } + + private TestPlanReport updateTestPlanReportById(String id) { + return this.updateExecuteApis(id,null,null,null); } public TestPlanScheduleReportInfoDTO genTestPlanReportBySchedule(String projectID, String planId, String userId, String triggerMode) { @@ -122,30 +142,21 @@ public class TestPlanReportService { String planReportId = UUID.randomUUID().toString(); - List> apiCaseInfoList = new ArrayList<>(); + Map apiCaseInfoMap = new HashMap<>(); for (String id : apiTestCaseIdMap.keySet()) { - Map map = new HashMap<>(); - map.put("id", id); - map.put("status", TestPlanApiExecuteStatus.PREPARE.name()); - apiCaseInfoList.add(map); + apiCaseInfoMap.put(id,TestPlanApiExecuteStatus.PREPARE.name()); } - List> scenarioInfoList = new ArrayList<>(); + Map scenarioInfoMap = new HashMap<>(); for (String id : planScenarioIdMap.keySet()) { - Map map = new HashMap<>(); - map.put("id", id); - map.put("status", TestPlanApiExecuteStatus.PREPARE.name()); - scenarioInfoList.add(map); + scenarioInfoMap.put(id,TestPlanApiExecuteStatus.PREPARE.name()); } - List> performanceInfoList = new ArrayList<>(); + Map performanceInfoMap = new HashMap<>(); for (String id : performanceIdMap.values()) { - Map map = new HashMap<>(); - map.put("id", id); - map.put("status", TestPlanApiExecuteStatus.PREPARE.name()); - performanceInfoList.add(map); + performanceInfoMap.put(id,TestPlanApiExecuteStatus.PREPARE.name()); } TestPlanReportSaveRequest saveRequest = new TestPlanReportSaveRequest(planReportId, planId, userId, triggerMode, apiTestCaseIdMap.size() > 0, planScenarioIdMap.size() > 0, performanceIdMap.size() > 0, - JSONArray.toJSONString(apiCaseInfoList), JSONArray.toJSONString(scenarioInfoList), JSONArray.toJSONString(performanceInfoList)); + apiCaseInfoMap, scenarioInfoMap, performanceInfoMap); TestPlanReport report = this.genTestPlanReport(saveRequest); TestPlanScheduleReportInfoDTO returnDTO = new TestPlanScheduleReportInfoDTO(); @@ -187,6 +198,10 @@ public class TestPlanReportService { testPlanReportData.setId(UUID.randomUUID().toString()); testPlanReportData.setTestPlanReportId(testPlanReportID); + Map apiCaseInfoMap = new HashMap<>(); + Map scenarioInfoMap = new HashMap<>(); + Map performanceInfoMap = new HashMap<>(); + if (saveRequest.isCountResources()) { TestPlanApiCaseExample apiExample = new TestPlanApiCaseExample(); apiExample.createCriteria().andTestPlanIdEqualTo(saveRequest.getPlanId()); @@ -207,38 +222,70 @@ public class TestPlanReportService { .stream().map(TestPlanLoadCaseDTO::getLoadCaseId).collect(Collectors.toList()); testPlanReport.setIsPerformanceExecuting(!performanceIdList.isEmpty()); - List> apiCaseInfoList = new ArrayList<>(); for (String id : apiCaseIdList) { - Map map = new HashMap<>(); - map.put("id", id); - map.put("status", TestPlanApiExecuteStatus.PREPARE.name()); - apiCaseInfoList.add(map); + apiCaseInfoMap.put(id,TestPlanApiExecuteStatus.PREPARE.name()); } - List> scenarioInfoList = new ArrayList<>(); for (String id : scenarioIdList) { - Map map = new HashMap<>(); - map.put("id", id); - map.put("status", TestPlanApiExecuteStatus.PREPARE.name()); - scenarioInfoList.add(map); + scenarioInfoMap.put(id,TestPlanApiExecuteStatus.PREPARE.name()); } - List> performanceInfoList = new ArrayList<>(); for (String id : performanceIdList) { - Map map = new HashMap<>(); - map.put("id", id); - map.put("status", TestPlanApiExecuteStatus.PREPARE.name()); - performanceInfoList.add(map); + performanceInfoMap.put(id,TestPlanApiExecuteStatus.PREPARE.name()); } - testPlanReportData.setApiCaseInfo(JSONArray.toJSONString(apiCaseInfoList)); - testPlanReportData.setScenarioInfo(JSONArray.toJSONString(scenarioInfoList)); - testPlanReportData.setPerformanceInfo(JSONArray.toJSONString(performanceInfoList)); } else { testPlanReport.setIsApiCaseExecuting(saveRequest.isApiCaseIsExecuting()); testPlanReport.setIsScenarioExecuting(saveRequest.isScenarioIsExecuting()); testPlanReport.setIsPerformanceExecuting(saveRequest.isPerformanceIsExecuting()); - testPlanReportData.setApiCaseInfo(saveRequest.getApiCaseIdListJSON()); - testPlanReportData.setScenarioInfo(saveRequest.getScenarioIdListJSON()); - testPlanReportData.setPerformanceInfo(saveRequest.getPerformanceIdListJSON()); + apiCaseInfoMap = saveRequest.getApiCaseIdMap(); + scenarioInfoMap = saveRequest.getScenarioIdMap(); + performanceInfoMap = saveRequest.getPerformanceIdMap(); + } + + List resourceList = new ArrayList<>(); + if(MapUtils.isNotEmpty(apiCaseInfoMap)){ + for (Map.Entry entry : apiCaseInfoMap.entrySet()){ + String id = entry.getKey(); + String status = entry.getValue(); + String type = TestPlanResourceType.API_CASE.name(); + + TestPlanReportResource apiCaseResource = new TestPlanReportResource(); + apiCaseResource.setResourceId(id); + apiCaseResource.setTestPlanReportId(testPlanReportID); + apiCaseResource.setResourceType(type); + apiCaseResource.setExecuteResult(status); + apiCaseResource.setId(UUID.randomUUID().toString()); + resourceList.add(apiCaseResource); + } + } + if(MapUtils.isNotEmpty(scenarioInfoMap)){ + for (Map.Entry entry : scenarioInfoMap.entrySet()){ + String id = entry.getKey(); + String status = entry.getValue(); + String type = TestPlanResourceType.SCENARIO_CASE.name(); + + TestPlanReportResource scenarioResource = new TestPlanReportResource(); + scenarioResource.setResourceId(id); + scenarioResource.setTestPlanReportId(testPlanReportID); + scenarioResource.setResourceType(type); + scenarioResource.setExecuteResult(status); + scenarioResource.setId(UUID.randomUUID().toString()); + resourceList.add(scenarioResource); + } + } + if(MapUtils.isNotEmpty(performanceInfoMap)){ + for (Map.Entry entry : performanceInfoMap.entrySet()){ + String id = entry.getKey(); + String status = entry.getValue(); + String type = TestPlanResourceType.PERFORMANCE_CASE.name(); + + TestPlanReportResource performanceResource = new TestPlanReportResource(); + performanceResource.setResourceId(id); + performanceResource.setTestPlanReportId(testPlanReportID); + performanceResource.setResourceType(type); + performanceResource.setExecuteResult(status); + performanceResource.setId(UUID.randomUUID().toString()); + resourceList.add(performanceResource); + } } testPlanReport.setPrincipal(testPlan.getPrincipal()); @@ -251,8 +298,12 @@ public class TestPlanReportService { SqlSession sqlSession = sqlSessionFactory.openSession(false); TestPlanReportMapper insertReportMapper = sqlSession.getMapper(TestPlanReportMapper.class); TestPlanReportDataMapper insertReportDataMapper = sqlSession.getMapper(TestPlanReportDataMapper.class); + TestPlanReportResourceMapper insertResourceMapper = sqlSession.getMapper(TestPlanReportResourceMapper.class); insertReportMapper.insert(testPlanReport); insertReportDataMapper.insert(testPlanReportData); + for (TestPlanReportResource resource : resourceList) { + insertResourceMapper.insert(resource); + } sqlSession.commit(); sqlSession.flushStatements(); @@ -266,6 +317,9 @@ public class TestPlanReportService { TestPlanReportDTO returnDTO = new TestPlanReportDTO(); TestPlanReport report = testPlanReportMapper.selectByPrimaryKey(reportId); if (report != null) { + if(StringUtils.equalsIgnoreCase(report.getStatus(),TestPlanApiExecuteStatus.RUNNING.name())){ + report = this.updateExecuteApis(reportId,null,null,null); + } TestPlanReportDataExample example = new TestPlanReportDataExample(); example.createCriteria().andTestPlanReportIdEqualTo(reportId); List reportDataList = testPlanReportDataMapper.selectByExampleWithBLOBs(example); @@ -317,15 +371,15 @@ public class TestPlanReportService { } } - public TestCaseReportMetricDTO countReportData(TestPlanDTO testPlan, TestPlanReportDataWithBLOBs testPlanReportData) { + public TestCaseReportMetricDTO countReportData(TestPlanDTO testPlan, Map> executeResult) { TestCaseReportMetricDTO returnDTO = new TestCaseReportMetricDTO(); ReportResultComponent reportResultComponent = new ReportResultComponent(testPlan); reportResultComponent.afterBuild(returnDTO); TestCaseReportAdvanceStatusResultDTO statusDTO = new TestCaseReportAdvanceStatusResultDTO(); - String apiCaseExecuteMapJson = testPlanReportData.getApiCaseInfo(); - String scenarioExecuteMapJson = testPlanReportData.getScenarioInfo(); - String loadExecuteMapJson = testPlanReportData.getPerformanceInfo(); + Map apiCaseExecuteMap = executeResult.get(TestPlanResourceType.API_CASE.name()); + Map scenarioExecuteMap = executeResult.get(TestPlanResourceType.SCENARIO_CASE.name()); + Map performanceCaseExecuteMap = executeResult.get(TestPlanResourceType.PERFORMANCE_CASE.name()); List apiResult = new ArrayList<>(); List scenarioResult = new ArrayList<>(); @@ -335,55 +389,26 @@ public class TestPlanReportService { List faliureScenarioCaseIdList = new ArrayList<>(); List faliureLoadCaseIdList = new ArrayList<>(); - JSONArray apiCaseExecuteArr = new JSONArray(); - JSONArray scenarioExecuteArr = new JSONArray(); - JSONArray loadExecuteArr = new JSONArray(); - if (StringUtils.isNotEmpty(apiCaseExecuteMapJson)) { - try { - apiCaseExecuteArr = JSONArray.parseArray(apiCaseExecuteMapJson); - } catch (Exception e) { - } - } - - if (StringUtils.isNotEmpty(scenarioExecuteMapJson)) { - try { - scenarioExecuteArr = JSONArray.parseArray(scenarioExecuteMapJson); - } catch (Exception e) { - } - } - - if (StringUtils.isNotEmpty(loadExecuteMapJson)) { - try { - loadExecuteArr = JSONArray.parseArray(loadExecuteMapJson); - } catch (Exception e) { - } - } - - for (int i = 0; i < apiCaseExecuteArr.size(); i++) { - JSONObject jsonObj = apiCaseExecuteArr.getJSONObject(i); - + if(MapUtils.isNotEmpty(apiCaseExecuteMap)){ Map countMap = new HashMap<>(); - if (jsonObj.containsKey("status")) { - String status = jsonObj.getString("status"); - if (StringUtils.equalsAnyIgnoreCase(status, TestPlanApiExecuteStatus.SUCCESS.name())) { + for (Map.Entry executeEntry: apiCaseExecuteMap.entrySet()){ + String caseResult = executeEntry.getValue(); + String id = executeEntry.getKey(); + if (StringUtils.equalsAnyIgnoreCase(caseResult, TestPlanApiExecuteStatus.SUCCESS.name())) { if (countMap.containsKey("Pass")) { countMap.put("Pass", countMap.get("Pass") + 1); } else { countMap.put("Pass", 1); } - } else if (StringUtils.equalsAnyIgnoreCase(status, TestPlanApiExecuteStatus.FAILD.name())) { - if (jsonObj.containsKey("id")) { - faliureApiCaseIdList.add(jsonObj.getString("id")); - } + } else if (StringUtils.equalsAnyIgnoreCase(caseResult, TestPlanApiExecuteStatus.FAILD.name())) { + faliureApiCaseIdList.add(id); if (countMap.containsKey("Failure")) { countMap.put("Failure", countMap.get("Failure") + 1); } else { countMap.put("Failure", 1); } - } else if (StringUtils.equalsAnyIgnoreCase(status, TestPlanApiExecuteStatus.PREPARE.name())) { - if (jsonObj.containsKey("id")) { - faliureApiCaseIdList.add(jsonObj.getString("id")); - } + } else if (StringUtils.equalsAnyIgnoreCase(caseResult, TestPlanApiExecuteStatus.PREPARE.name())) { + faliureApiCaseIdList.add(id); if (countMap.containsKey("Skip")) { countMap.put("Skip", countMap.get("Skip") + 1); } else { @@ -407,30 +432,26 @@ public class TestPlanReportService { } } - for (int i = 0; i < scenarioExecuteArr.size(); i++) { - JSONObject jsonObj = scenarioExecuteArr.getJSONObject(i); + if(MapUtils.isNotEmpty(scenarioExecuteMap)){ Map countMap = new HashMap<>(); - if (jsonObj.containsKey("status")) { - String status = jsonObj.getString("status"); - if (StringUtils.equalsAnyIgnoreCase(status, TestPlanApiExecuteStatus.SUCCESS.name())) { + for (Map.Entry executeEntry: scenarioExecuteMap.entrySet()){ + String caseResult = executeEntry.getValue(); + String id = executeEntry.getKey(); + if (StringUtils.equalsAnyIgnoreCase(caseResult, TestPlanApiExecuteStatus.SUCCESS.name())) { if (countMap.containsKey("Pass")) { countMap.put("Pass", countMap.get("Pass") + 1); } else { countMap.put("Pass", 1); } - } else if (StringUtils.equalsAnyIgnoreCase(status, TestPlanApiExecuteStatus.FAILD.name())) { - if (jsonObj.containsKey("id")) { - faliureScenarioCaseIdList.add(jsonObj.getString("id")); - } + } else if (StringUtils.equalsAnyIgnoreCase(caseResult, TestPlanApiExecuteStatus.FAILD.name())) { + faliureApiCaseIdList.add(id); if (countMap.containsKey("Failure")) { countMap.put("Failure", countMap.get("Failure") + 1); } else { countMap.put("Failure", 1); } - } else if (StringUtils.equalsAnyIgnoreCase(status, TestPlanApiExecuteStatus.PREPARE.name())) { - if (jsonObj.containsKey("id")) { - faliureScenarioCaseIdList.add(jsonObj.getString("id")); - } + } else if (StringUtils.equalsAnyIgnoreCase(caseResult, TestPlanApiExecuteStatus.PREPARE.name())) { + faliureApiCaseIdList.add(id); if (countMap.containsKey("Skip")) { countMap.put("Skip", countMap.get("Skip") + 1); } else { @@ -444,7 +465,6 @@ public class TestPlanReportService { } } } - for (Map.Entry entry : countMap.entrySet()) { String status = entry.getKey(); Integer value = entry.getValue(); @@ -455,30 +475,26 @@ public class TestPlanReportService { } } - for (int i = 0; i < loadExecuteArr.size(); i++) { - JSONObject jsonObj = loadExecuteArr.getJSONObject(i); + if(MapUtils.isNotEmpty(performanceCaseExecuteMap)){ Map countMap = new HashMap<>(); - if (jsonObj.containsKey("status")) { - String status = jsonObj.getString("status"); - if (StringUtils.equalsAnyIgnoreCase(status, TestPlanApiExecuteStatus.SUCCESS.name())) { + for (Map.Entry executeEntry: performanceCaseExecuteMap.entrySet()){ + String caseResult = executeEntry.getValue(); + String id = executeEntry.getKey(); + if (StringUtils.equalsAnyIgnoreCase(caseResult, TestPlanApiExecuteStatus.SUCCESS.name())) { if (countMap.containsKey("Pass")) { countMap.put("Pass", countMap.get("Pass") + 1); } else { countMap.put("Pass", 1); } - } else if (StringUtils.equalsAnyIgnoreCase(status, TestPlanApiExecuteStatus.FAILD.name())) { - if (jsonObj.containsKey("id")) { - faliureLoadCaseIdList.add(jsonObj.getString("id")); - } + } else if (StringUtils.equalsAnyIgnoreCase(caseResult, TestPlanApiExecuteStatus.FAILD.name())) { + faliureApiCaseIdList.add(id); if (countMap.containsKey("Failure")) { countMap.put("Failure", countMap.get("Failure") + 1); } else { countMap.put("Failure", 1); } - } else if (StringUtils.equalsAnyIgnoreCase(status, TestPlanApiExecuteStatus.PREPARE.name())) { - if (jsonObj.containsKey("id")) { - faliureLoadCaseIdList.add(jsonObj.getString("id")); - } + } else if (StringUtils.equalsAnyIgnoreCase(caseResult, TestPlanApiExecuteStatus.PREPARE.name())) { + faliureApiCaseIdList.add(id); if (countMap.containsKey("Skip")) { countMap.put("Skip", countMap.get("Skip") + 1); } else { @@ -492,7 +508,6 @@ public class TestPlanReportService { } } } - for (Map.Entry entry : countMap.entrySet()) { String status = entry.getKey(); Integer value = entry.getValue(); @@ -502,6 +517,113 @@ public class TestPlanReportService { loadResult.add(dto); } } +// for (int i = 0; i < apiCaseExecuteArr.size(); i++) { +// JSONObject jsonObj = apiCaseExecuteArr.getJSONObject(i); +// +// Map countMap = new HashMap<>(); +// if (jsonObj.containsKey("status")) { +// String status = jsonObj.getString("status"); +// +// } +// +// } +// +// for (int i = 0; i < scenarioExecuteArr.size(); i++) { +// JSONObject jsonObj = scenarioExecuteArr.getJSONObject(i); +// Map countMap = new HashMap<>(); +// if (jsonObj.containsKey("status")) { +// String status = jsonObj.getString("status"); +// if (StringUtils.equalsAnyIgnoreCase(status, TestPlanApiExecuteStatus.SUCCESS.name())) { +// if (countMap.containsKey("Pass")) { +// countMap.put("Pass", countMap.get("Pass") + 1); +// } else { +// countMap.put("Pass", 1); +// } +// } else if (StringUtils.equalsAnyIgnoreCase(status, TestPlanApiExecuteStatus.FAILD.name())) { +// if (jsonObj.containsKey("id")) { +// faliureScenarioCaseIdList.add(jsonObj.getString("id")); +// } +// if (countMap.containsKey("Failure")) { +// countMap.put("Failure", countMap.get("Failure") + 1); +// } else { +// countMap.put("Failure", 1); +// } +// } else if (StringUtils.equalsAnyIgnoreCase(status, TestPlanApiExecuteStatus.PREPARE.name())) { +// if (jsonObj.containsKey("id")) { +// faliureScenarioCaseIdList.add(jsonObj.getString("id")); +// } +// if (countMap.containsKey("Skip")) { +// countMap.put("Skip", countMap.get("Skip") + 1); +// } else { +// countMap.put("Skip", 1); +// } +// } else { +// if (countMap.containsKey("Underway")) { +// countMap.put("Underway", countMap.get("Underway") + 1); +// } else { +// countMap.put("Underway", 1); +// } +// } +// } +// +// for (Map.Entry entry : countMap.entrySet()) { +// String status = entry.getKey(); +// Integer value = entry.getValue(); +// TestCaseReportStatusResultDTO dto = new TestCaseReportStatusResultDTO(); +// dto.setStatus(status); +// dto.setCount(value); +// scenarioResult.add(dto); +// } +// } +// +// for (int i = 0; i < loadExecuteArr.size(); i++) { +// JSONObject jsonObj = loadExecuteArr.getJSONObject(i); +// Map countMap = new HashMap<>(); +// if (jsonObj.containsKey("status")) { +// String status = jsonObj.getString("status"); +// if (StringUtils.equalsAnyIgnoreCase(status, TestPlanApiExecuteStatus.SUCCESS.name())) { +// if (countMap.containsKey("Pass")) { +// countMap.put("Pass", countMap.get("Pass") + 1); +// } else { +// countMap.put("Pass", 1); +// } +// } else if (StringUtils.equalsAnyIgnoreCase(status, TestPlanApiExecuteStatus.FAILD.name())) { +// if (jsonObj.containsKey("id")) { +// faliureLoadCaseIdList.add(jsonObj.getString("id")); +// } +// if (countMap.containsKey("Failure")) { +// countMap.put("Failure", countMap.get("Failure") + 1); +// } else { +// countMap.put("Failure", 1); +// } +// } else if (StringUtils.equalsAnyIgnoreCase(status, TestPlanApiExecuteStatus.PREPARE.name())) { +// if (jsonObj.containsKey("id")) { +// faliureLoadCaseIdList.add(jsonObj.getString("id")); +// } +// if (countMap.containsKey("Skip")) { +// countMap.put("Skip", countMap.get("Skip") + 1); +// } else { +// countMap.put("Skip", 1); +// } +// } else { +// if (countMap.containsKey("Underway")) { +// countMap.put("Underway", countMap.get("Underway") + 1); +// } else { +// countMap.put("Underway", 1); +// } +// } +// } +// +// for (Map.Entry entry : countMap.entrySet()) { +// String status = entry.getKey(); +// Integer value = entry.getValue(); +// TestCaseReportStatusResultDTO dto = new TestCaseReportStatusResultDTO(); +// dto.setStatus(status); +// dto.setCount(value); +// loadResult.add(dto); +// } +// } + statusDTO.setApiResult(apiResult); statusDTO.setScenarioResult(scenarioResult); statusDTO.setLoadResult(loadResult); @@ -547,14 +669,17 @@ public class TestPlanReportService { return returnDTO; } - public void updateReport(TestPlanReportDataWithBLOBs testPlanReportData, boolean apiCaseIsOk, boolean scenarioIsOk, boolean performanceIsOk) { + public TestPlanReport updateReport(TestPlanReportDataWithBLOBs testPlanReportData, boolean apiCaseIsOk, boolean scenarioIsOk, boolean performanceIsOk,boolean updateTime) { TestPlanReport testPlanReport = testPlanReportMapper.selectByPrimaryKey(testPlanReportData.getTestPlanReportId()); if (testPlanReport == null) { - return; + return null; + } + + if(updateTime){ + testPlanReport.setEndTime(System.currentTimeMillis()); + testPlanReport.setUpdateTime(System.currentTimeMillis()); } - testPlanReport.setEndTime(System.currentTimeMillis()); - testPlanReport.setUpdateTime(System.currentTimeMillis()); if (apiCaseIsOk) { testPlanReport.setIsApiCaseExecuting(false); } @@ -581,8 +706,11 @@ public class TestPlanReportService { testPlanService.buildScenarioCaseReport(testPlanReport.getTestPlanId(), components); testPlanService.buildLoadCaseReport(testPlanReport.getTestPlanId(), components); + Map> testPlanExecuteResult = testPlanReportResourceService.selectExecuteResultByTestPlanReportId(testPlanReportData.getTestPlanReportId()); - TestCaseReportMetricDTO testCaseReportMetricDTO = this.countReportData(testPlan, testPlanReportData); + testPlanLog.info("ReportId["+testPlanReportData.getTestPlanReportId()+"] COUNT OVER. COUNT RESULT :"+JSONObject.toJSONString(testPlanExecuteResult)); + + TestCaseReportMetricDTO testCaseReportMetricDTO = this.countReportData(testPlan, testPlanExecuteResult); //统计执行的场景ID testPlanReportData.setExecuteResult(JSONObject.toJSONString(testCaseReportMetricDTO.getExecuteResult())); @@ -593,7 +721,8 @@ public class TestPlanReportService { String testPlanStatus = this.getTestPlanReportStatus(testPlanReport, testPlanReportData); testPlanReport.setStatus(testPlanStatus); - this.update(testPlanReport); + testPlanReport = this.update(testPlanReport); + return testPlanReport; } public void checkTestPlanStatus(String planReportId) { @@ -792,7 +921,7 @@ public class TestPlanReportService { return status; } - public void update(TestPlanReport report) { + public TestPlanReport update(TestPlanReport report) { if (!report.getIsApiCaseExecuting() && !report.getIsPerformanceExecuting() && !report.getIsScenarioExecuting()) { try { //更新TestPlan状态为完成 @@ -812,6 +941,7 @@ public class TestPlanReportService { } testPlanReportMapper.updateByPrimaryKey(report); + return report; } public void sendMessage(TestPlanReport testPlanReport) { @@ -961,6 +1091,9 @@ public class TestPlanReportService { TestPlanReportDataExample example = new TestPlanReportDataExample(); example.createCriteria().andTestPlanReportIdEqualTo(testPlanReportId); testPlanReportDataMapper.deleteByExample(example); + TestPlanReportResourceExample resourceExample = new TestPlanReportResourceExample(); + resourceExample.createCriteria().andTestPlanReportIdEqualTo(testPlanReportId); + testPlanReportResourceService.deleteByExample(resourceExample); } } @@ -969,13 +1102,20 @@ public class TestPlanReportService { if (request.isSelectAllDate()) { deleteReportIds = this.getAllApiIdsByFontedSelect(request.getFilters(), request.getName(), request.getProjectId(), request.getUnSelectIds()); } - TestPlanReportExample deleteReportExample = new TestPlanReportExample(); - deleteReportExample.createCriteria().andIdIn(deleteReportIds); - testPlanReportMapper.deleteByExample(deleteReportExample); + if(CollectionUtils.isNotEmpty(deleteReportIds)){ + TestPlanReportExample deleteReportExample = new TestPlanReportExample(); + deleteReportExample.createCriteria().andIdIn(deleteReportIds); + testPlanReportMapper.deleteByExample(deleteReportExample); - TestPlanReportDataExample example = new TestPlanReportDataExample(); - example.createCriteria().andTestPlanReportIdIn(deleteReportIds); - testPlanReportDataMapper.deleteByExample(example); + + TestPlanReportDataExample example = new TestPlanReportDataExample(); + example.createCriteria().andTestPlanReportIdIn(deleteReportIds); + testPlanReportDataMapper.deleteByExample(example); + + TestPlanReportResourceExample resourceExample = new TestPlanReportResourceExample(); + resourceExample.createCriteria().andTestPlanReportIdIn(deleteReportIds); + testPlanReportResourceService.deleteByExample(resourceExample); + } } private List getAllApiIdsByFontedSelect(Map> filters, String name, String projectId, List unSelectIds) { @@ -1005,8 +1145,9 @@ public class TestPlanReportService { return null; } - public synchronized void updateExecuteApis(String planReportId, Map executeApiCaseIdMap, Map executeScenarioCaseIdMap, Map executePerformanceIdMap) { + public synchronized TestPlanReport updateExecuteApis(String planReportId, Map executeApiCaseIdMap, Map executeScenarioCaseIdMap, Map executePerformanceIdMap) { TestPlanReportDataExample example = new TestPlanReportDataExample(); + List resourceIdList = new ArrayList<>(); if(executeApiCaseIdMap == null){ executeApiCaseIdMap = new HashMap<>(); } @@ -1016,104 +1157,78 @@ public class TestPlanReportService { if(executePerformanceIdMap == null){ executePerformanceIdMap = new HashMap<>(); } + boolean updateTime = MapUtils.isNotEmpty(executeApiCaseIdMap)||MapUtils.isNotEmpty(executeScenarioCaseIdMap)||MapUtils.isNotEmpty(executePerformanceIdMap); + testPlanLog.info("ReportId["+planReportId+"] Executed. api :"+JSONObject.toJSONString(executeApiCaseIdMap)+"; scenario:"+JSONObject.toJSONString(executeScenarioCaseIdMap)+"; performance:"+JSONObject.toJSONString(executePerformanceIdMap)); example.createCriteria().andTestPlanReportIdEqualTo(planReportId); List reportDataList = testPlanReportDataMapper.selectByExampleWithBLOBs(example); + TestPlanReport report = null; if (!reportDataList.isEmpty()) { + Map> batchUpdateMap = new HashMap<>(); + for (Map.Entry entry:executeApiCaseIdMap.entrySet()){ + String id = entry.getKey(); + String result = entry.getValue(); + if(batchUpdateMap.containsKey(result)){ + batchUpdateMap.get(result).add(id); + }else { + List idList = new ArrayList<>(); + idList.add(id); + batchUpdateMap.put(result,idList); + } + } + for (Map.Entry entry:executeScenarioCaseIdMap.entrySet()){ + String id = entry.getKey(); + String result = entry.getValue(); + if(batchUpdateMap.containsKey(result)){ + batchUpdateMap.get(result).add(id); + }else { + List idList = new ArrayList<>(); + idList.add(id); + batchUpdateMap.put(result,idList); + } + } + for (Map.Entry entry:executePerformanceIdMap.entrySet()){ + String id = entry.getKey(); + String result = entry.getValue(); + if(batchUpdateMap.containsKey(result)){ + batchUpdateMap.get(result).add(id); + }else { + List idList = new ArrayList<>(); + idList.add(id); + batchUpdateMap.put(result,idList); + } + } + + for(Map.Entry> entry : batchUpdateMap.entrySet()){ + String status = entry.getKey(); + List ids = entry.getValue(); + if(CollectionUtils.isEmpty(ids)){ + continue; + } + int updateCount = this.testPlanReportResourceService.updateExecuteResultByReportIdAndResourceIds(status,planReportId,ids); + testPlanLog.info("ReportId["+planReportId+"] Update Execute Result. Update datas count is :["+updateCount+"]; Update Status:["+status+"],Update ids :["+JSONArray.toJSONString(ids)+"] "); + } + boolean apiCaseExecuteOk = testPlanReportResourceService.countByReportIdAndResourceTypeAndExecuteResultEquals(planReportId,TestPlanResourceType.API_CASE.name(),TestPlanApiExecuteStatus.RUNNING.name()) == 0; + boolean scenarioExecuteOk = testPlanReportResourceService.countByReportIdAndResourceTypeAndExecuteResultEquals(planReportId,TestPlanResourceType.SCENARIO_CASE.name(),TestPlanApiExecuteStatus.RUNNING.name()) == 0; + boolean performanceExecuteOk = testPlanReportResourceService.countByReportIdAndResourceTypeAndExecuteResultEquals(planReportId,TestPlanResourceType.PERFORMANCE_CASE.name(),TestPlanApiExecuteStatus.RUNNING.name()) == 0;; + + testPlanLog.info("ReportId["+planReportId+"] count over. Testplan Execute Result: Api is over ->"+apiCaseExecuteOk+"; scenario is over ->"+scenarioExecuteOk+"; performance is over ->"+performanceExecuteOk); + TestPlanReportDataWithBLOBs reportData = reportDataList.get(0); - boolean apiCaseExecuteOk = true; - try { - JSONArray executeArr = JSONArray.parseArray(reportData.getApiCaseInfo()); - JSONArray newArr = new JSONArray(); - for (int i = 0; i < executeArr.size(); i++) { - JSONObject caseInfo = executeArr.getJSONObject(i); - if (caseInfo.containsKey("id") && caseInfo.containsKey("status")) { - if (MapUtils.isNotEmpty(executeApiCaseIdMap)) { - String id = caseInfo.getString("id"); - String status = caseInfo.getString("status"); - String updateStatus = executeApiCaseIdMap.get(id); - if (StringUtils.isNotEmpty(updateStatus) - && !StringUtils.equalsAnyIgnoreCase(status, TestPlanApiExecuteStatus.SUCCESS.name(), TestPlanApiExecuteStatus.FAILD.name())) { - caseInfo.put("status", updateStatus); - } - } - if (StringUtils.equals(TestPlanApiExecuteStatus.RUNNING.name(), caseInfo.getString("status"))) { - apiCaseExecuteOk = false; - } - newArr.add(caseInfo); - } - } - reportData.setApiCaseInfo(newArr.toJSONString()); - } catch (Exception e) { - } - - boolean scenarioExecuteOk = true; - - try { - JSONArray executeArr = JSONArray.parseArray(reportData.getScenarioInfo()); - JSONArray newArr = new JSONArray(); - for (int i = 0; i < executeArr.size(); i++) { - JSONObject caseInfo = executeArr.getJSONObject(i); - if (caseInfo.containsKey("id") && caseInfo.containsKey("status")) { - if (MapUtils.isNotEmpty(executeScenarioCaseIdMap)) { - String id = caseInfo.getString("id"); - String status = caseInfo.getString("status"); - String updateStatus = executeScenarioCaseIdMap.get(id); - if (StringUtils.isNotEmpty(updateStatus) - && !StringUtils.equalsAnyIgnoreCase(status, TestPlanApiExecuteStatus.SUCCESS.name(), TestPlanApiExecuteStatus.FAILD.name())) { - caseInfo.put("status", updateStatus); - } - } - if (StringUtils.equals(TestPlanApiExecuteStatus.RUNNING.name(), caseInfo.getString("status"))) { - scenarioExecuteOk = false; - } - newArr.add(caseInfo); - } - } - reportData.setScenarioInfo(newArr.toJSONString()); - } catch (Exception e) { - } - boolean performanceExecuteOk = true; - - try { - JSONArray executeArr = JSONArray.parseArray(reportData.getPerformanceInfo()); - JSONArray newArr = new JSONArray(); - for (int i = 0; i < executeArr.size(); i++) { - JSONObject caseInfo = executeArr.getJSONObject(i); - if (caseInfo.containsKey("id") && caseInfo.containsKey("status")) { - if (MapUtils.isNotEmpty(executePerformanceIdMap)) { - String id = caseInfo.getString("id"); - String status = caseInfo.getString("status"); - String updateStatus = executePerformanceIdMap.get(id); - if (StringUtils.isNotEmpty(updateStatus) - && !StringUtils.equalsAnyIgnoreCase(status, TestPlanApiExecuteStatus.SUCCESS.name(), TestPlanApiExecuteStatus.FAILD.name())) { - caseInfo.put("status", updateStatus); - } - } - - if (StringUtils.equals(TestPlanApiExecuteStatus.RUNNING.name(), caseInfo.getString("status"))) { - performanceExecuteOk = false; - } - newArr.add(caseInfo); - } - } - reportData.setPerformanceInfo(newArr.toJSONString()); - } catch (Exception e) { - } - testPlanLog.info("ReportId["+planReportId+"] count over. Execute result: Api ->"+reportData.getApiCaseInfo()+"; scenario->"+reportData.getScenarioInfo()+"; performance->"+reportData.getPerformanceInfo()); - - SqlSession sqlSession = sqlSessionFactory.openSession(false); - TestPlanReportDataMapper updateReportDataMapper = sqlSession.getMapper(TestPlanReportDataMapper.class); - updateReportDataMapper.updateByPrimaryKeySelective(reportData); - sqlSession.commit(); - sqlSession.flushStatements(); +// SqlSession sqlSession = sqlSessionFactory.openSession(false); +// TestPlanReportDataMapper updateReportDataMapper = sqlSession.getMapper(TestPlanReportDataMapper.class); +// updateReportDataMapper.updateByPrimaryKeySelective(reportData); +// sqlSession.commit(); +// sqlSession.flushStatements(); - this.updateReport(reportData, apiCaseExecuteOk, scenarioExecuteOk, performanceExecuteOk); + report = this.updateReport(reportData, apiCaseExecuteOk, scenarioExecuteOk, performanceExecuteOk,updateTime); }else { testPlanLog.info("ReportId["+planReportId+"] CANNOT FIND REPORT! Execited result. api :"+JSONObject.toJSONString(executeApiCaseIdMap)+"; scenario:"+JSONObject.toJSONString(executeScenarioCaseIdMap)+"; performance:"+JSONObject.toJSONString(executePerformanceIdMap)); } + + return report; } } diff --git a/backend/src/main/resources/db/migration/V92__v1.11.2_release.sql b/backend/src/main/resources/db/migration/V92__v1.11.2_release.sql index 9ac2eb76b5..1b8aab9e5a 100644 --- a/backend/src/main/resources/db/migration/V92__v1.11.2_release.sql +++ b/backend/src/main/resources/db/migration/V92__v1.11.2_release.sql @@ -43,3 +43,18 @@ CREATE TABLE IF NOT EXISTS `api_load_test` ( -- 添加版本号 ALTER TABLE api_test_case ADD version INT(10) DEFAULT 0 NULL COMMENT '版本号'; + +-- 测试计划资源表 +CREATE TABLE IF NOT EXISTS test_plan_report_resource ( + `id` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL, + `test_plan_report_id` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL, + `resource_id` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL, + `resource_type` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL, + `execute_result` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL, + PRIMARY KEY (`id`) USING BTREE, + INDEX `test_plan_report_id`(`test_plan_report_id`) USING BTREE, + INDEX `resource_id`(`resource_id`) USING BTREE, + INDEX `resource_type`(`resource_type`) USING BTREE, + INDEX `report_resource_id`(`test_plan_report_id`,`resource_id`) USING BTREE, + INDEX `report_resource_type_id`(`test_plan_report_id`,`resource_id`,`resource_type`) USING BTREE +) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic; diff --git a/backend/src/main/resources/generatorConfig.xml b/backend/src/main/resources/generatorConfig.xml index 7d40769c53..72de9d40b4 100644 --- a/backend/src/main/resources/generatorConfig.xml +++ b/backend/src/main/resources/generatorConfig.xml @@ -84,7 +84,7 @@ -
+