From 7adb8aeeee1154a6040a1cffd09bf3fc0878352a Mon Sep 17 00:00:00 2001 From: zhangdahai112 Date: Sat, 22 Jan 2022 17:02:31 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E7=89=88=E6=9C=AC=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/metersphere/base/domain/TestCase.java | 2 + .../base/domain/TestCaseExample.java | 60 +++++++ .../base/mapper/TestCaseMapper.xml | 31 +++- .../base/mapper/TestCaseTestMapper.xml | 91 +++------- .../mapper/ext/ExtApiDefinitionMapper.xml | 120 +++---------- .../base/mapper/ext/ExtApiScenarioMapper.xml | 48 ++--- .../base/mapper/ext/ExtApiTestCaseMapper.xml | 38 ++-- .../base/mapper/ext/ExtLoadTestMapper.xml | 48 ++--- .../base/mapper/ext/ExtShareInfoMapper.xml | 29 ++- .../base/mapper/ext/ExtTestCaseMapper.java | 14 +- .../base/mapper/ext/ExtTestCaseMapper.xml | 165 +++++++----------- .../mapper/ext/ExtTestPlanApiCaseMapper.xml | 41 ++--- .../mapper/ext/ExtTestPlanLoadCaseMapper.xml | 41 ++--- .../mapper/ext/ExtTestPlanTestCaseMapper.xml | 48 ++--- .../mapper/ext/ExtTestReviewCaseMapper.xml | 48 ++--- .../commons/constants/VersionConstants.java | 8 + .../track/service/TestCaseService.java | 30 +++- .../db/migration/V106__v1.17_release.sql | 54 +++++- .../track/case/components/TestCaseEdit.vue | 1 - 19 files changed, 414 insertions(+), 503 deletions(-) create mode 100644 backend/src/main/java/io/metersphere/commons/constants/VersionConstants.java diff --git a/backend/src/main/java/io/metersphere/base/domain/TestCase.java b/backend/src/main/java/io/metersphere/base/domain/TestCase.java index aa691e289c..f1593db258 100644 --- a/backend/src/main/java/io/metersphere/base/domain/TestCase.java +++ b/backend/src/main/java/io/metersphere/base/domain/TestCase.java @@ -65,5 +65,7 @@ public class TestCase implements Serializable { private String refId; + private Byte latest; + private static final long serialVersionUID = 1L; } \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/base/domain/TestCaseExample.java b/backend/src/main/java/io/metersphere/base/domain/TestCaseExample.java index 0aae3d1ae8..307f638ca1 100644 --- a/backend/src/main/java/io/metersphere/base/domain/TestCaseExample.java +++ b/backend/src/main/java/io/metersphere/base/domain/TestCaseExample.java @@ -2133,6 +2133,66 @@ public class TestCaseExample { addCriterion("ref_id not between", value1, value2, "refId"); return (Criteria) this; } + + public Criteria andLatestIsNull() { + addCriterion("latest is null"); + return (Criteria) this; + } + + public Criteria andLatestIsNotNull() { + addCriterion("latest is not null"); + return (Criteria) this; + } + + public Criteria andLatestEqualTo(Byte value) { + addCriterion("latest =", value, "latest"); + return (Criteria) this; + } + + public Criteria andLatestNotEqualTo(Byte value) { + addCriterion("latest <>", value, "latest"); + return (Criteria) this; + } + + public Criteria andLatestGreaterThan(Byte value) { + addCriterion("latest >", value, "latest"); + return (Criteria) this; + } + + public Criteria andLatestGreaterThanOrEqualTo(Byte value) { + addCriterion("latest >=", value, "latest"); + return (Criteria) this; + } + + public Criteria andLatestLessThan(Byte value) { + addCriterion("latest <", value, "latest"); + return (Criteria) this; + } + + public Criteria andLatestLessThanOrEqualTo(Byte value) { + addCriterion("latest <=", value, "latest"); + return (Criteria) this; + } + + public Criteria andLatestIn(List values) { + addCriterion("latest in", values, "latest"); + return (Criteria) this; + } + + public Criteria andLatestNotIn(List values) { + addCriterion("latest not in", values, "latest"); + return (Criteria) this; + } + + public Criteria andLatestBetween(Byte value1, Byte value2) { + addCriterion("latest between", value1, value2, "latest"); + return (Criteria) this; + } + + public Criteria andLatestNotBetween(Byte value1, Byte value2) { + addCriterion("latest not between", value1, value2, "latest"); + return (Criteria) this; + } } public static class Criteria extends GeneratedCriteria { diff --git a/backend/src/main/java/io/metersphere/base/mapper/TestCaseMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/TestCaseMapper.xml index 97acd1aa50..6330fb3573 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/TestCaseMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/TestCaseMapper.xml @@ -32,6 +32,7 @@ + @@ -103,7 +104,7 @@ id, node_id, test_id, node_path, project_id, `name`, `type`, maintainer, priority, `method`, create_time, update_time, sort, num, other_test_name, review_status, tags, demand_id, demand_name, `status`, step_model, custom_num, create_user, original_status, - delete_time, delete_user_id, `order`, case_public, version_id, ref_id + delete_time, delete_user_id, `order`, case_public, version_id, ref_id, latest prerequisite, remark, steps, step_description, expected_result, custom_fields @@ -167,8 +168,8 @@ custom_num, create_user, original_status, delete_time, delete_user_id, `order`, case_public, version_id, ref_id, - prerequisite, remark, steps, - step_description, expected_result, + latest, prerequisite, remark, + steps, step_description, expected_result, custom_fields) values (#{id,jdbcType=VARCHAR}, #{nodeId,jdbcType=VARCHAR}, #{testId,jdbcType=VARCHAR}, #{nodePath,jdbcType=VARCHAR}, #{projectId,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, @@ -180,8 +181,8 @@ #{customNum,jdbcType=VARCHAR}, #{createUser,jdbcType=VARCHAR}, #{originalStatus,jdbcType=VARCHAR}, #{deleteTime,jdbcType=BIGINT}, #{deleteUserId,jdbcType=VARCHAR}, #{order,jdbcType=BIGINT}, #{casePublic,jdbcType=BIT}, #{versionId,jdbcType=VARCHAR}, #{refId,jdbcType=VARCHAR}, - #{prerequisite,jdbcType=LONGVARCHAR}, #{remark,jdbcType=LONGVARCHAR}, #{steps,jdbcType=LONGVARCHAR}, - #{stepDescription,jdbcType=LONGVARCHAR}, #{expectedResult,jdbcType=LONGVARCHAR}, + #{latest,jdbcType=TINYINT}, #{prerequisite,jdbcType=LONGVARCHAR}, #{remark,jdbcType=LONGVARCHAR}, + #{steps,jdbcType=LONGVARCHAR}, #{stepDescription,jdbcType=LONGVARCHAR}, #{expectedResult,jdbcType=LONGVARCHAR}, #{customFields,jdbcType=LONGVARCHAR}) @@ -277,6 +278,9 @@ ref_id, + + latest, + prerequisite, @@ -387,6 +391,9 @@ #{refId,jdbcType=VARCHAR}, + + #{latest,jdbcType=TINYINT}, + #{prerequisite,jdbcType=LONGVARCHAR}, @@ -506,6 +513,9 @@ ref_id = #{record.refId,jdbcType=VARCHAR}, + + latest = #{record.latest,jdbcType=TINYINT}, + prerequisite = #{record.prerequisite,jdbcType=LONGVARCHAR}, @@ -561,6 +571,7 @@ case_public = #{record.casePublic,jdbcType=BIT}, version_id = #{record.versionId,jdbcType=VARCHAR}, ref_id = #{record.refId,jdbcType=VARCHAR}, + latest = #{record.latest,jdbcType=TINYINT}, prerequisite = #{record.prerequisite,jdbcType=LONGVARCHAR}, remark = #{record.remark,jdbcType=LONGVARCHAR}, steps = #{record.steps,jdbcType=LONGVARCHAR}, @@ -602,7 +613,8 @@ `order` = #{record.order,jdbcType=BIGINT}, case_public = #{record.casePublic,jdbcType=BIT}, version_id = #{record.versionId,jdbcType=VARCHAR}, - ref_id = #{record.refId,jdbcType=VARCHAR} + ref_id = #{record.refId,jdbcType=VARCHAR}, + latest = #{record.latest,jdbcType=TINYINT} @@ -697,6 +709,9 @@ ref_id = #{refId,jdbcType=VARCHAR}, + + latest = #{latest,jdbcType=TINYINT}, + prerequisite = #{prerequisite,jdbcType=LONGVARCHAR}, @@ -749,6 +764,7 @@ case_public = #{casePublic,jdbcType=BIT}, version_id = #{versionId,jdbcType=VARCHAR}, ref_id = #{refId,jdbcType=VARCHAR}, + latest = #{latest,jdbcType=TINYINT}, prerequisite = #{prerequisite,jdbcType=LONGVARCHAR}, remark = #{remark,jdbcType=LONGVARCHAR}, steps = #{steps,jdbcType=LONGVARCHAR}, @@ -787,7 +803,8 @@ `order` = #{order,jdbcType=BIGINT}, case_public = #{casePublic,jdbcType=BIT}, version_id = #{versionId,jdbcType=VARCHAR}, - ref_id = #{refId,jdbcType=VARCHAR} + ref_id = #{refId,jdbcType=VARCHAR}, + latest = #{latest,jdbcType=TINYINT} where id = #{id,jdbcType=VARCHAR} \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/base/mapper/TestCaseTestMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/TestCaseTestMapper.xml index 417ed040f4..811b502fcc 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/TestCaseTestMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/TestCaseTestMapper.xml @@ -180,28 +180,9 @@ - - and ad.version_id = #{request.versionId} - - - and ad.ref_id = #{request.refId} - - - AND ( - ad.version_id = (SELECT project_version.id - FROM api_definition tmp - JOIN project_version - ON tmp.project_id = project_version.project_id AND tmp.version_id = project_version.id AND latest = TRUE - WHERE ref_id = ad.ref_id - LIMIT 1) - OR - ad.version_id = (SELECT tmp.version_id - FROM api_definition tmp - WHERE ref_id = ad.ref_id - ORDER BY tmp.update_time DESC - LIMIT 1) - ) - + + + @@ -439,30 +420,9 @@ #{nodeId} - - and atc.version_id = #{request.versionId} - - - and atc.ref_id = #{request.refId} - - - AND ( - atc.version_id = (SELECT project_version.id - FROM api_scenario tmp - JOIN project_version - ON tmp.project_id = project_version.project_id AND tmp.version_id = project_version.id AND latest = TRUE - WHERE ref_id = atc.ref_id - LIMIT 1) - OR - atc.version_id = (SELECT tmp.version_id - FROM api_scenario tmp - WHERE ref_id = atc.ref_id - GROUP BY ref_id - HAVING max(latest) = 0 - ORDER BY tmp.update_time DESC - LIMIT 1) - ) - + + + @@ -513,30 +473,9 @@ and (atc.name like CONCAT('%', #{request.name},'%') or atc.num like CONCAT('%', #{request.name},'%')) - - and atc.version_id = #{request.versionId} - - - and atc.ref_id = #{request.refId} - - - AND ( - atc.version_id = (SELECT project_version.id - FROM load_test tmp - JOIN project_version - ON tmp.project_id = project_version.project_id AND tmp.version_id = project_version.id AND latest = TRUE - WHERE ref_id = atc.ref_id - LIMIT 1) - OR - atc.version_id = (SELECT tmp.version_id - FROM load_test tmp - WHERE ref_id = atc.ref_id - GROUP BY ref_id - HAVING max(latest) = 0 - ORDER BY tmp.update_time DESC - LIMIT 1) - ) - + + + @@ -594,4 +533,16 @@ + + + + and ${versionTable}.version_id = #{request.versionId} + + + and ${versionTable}.ref_id = #{request.refId} + + + AND ${versionTable}.latest = 1 + + diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiDefinitionMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiDefinitionMapper.xml index d4af33d689..c92be9d19a 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiDefinitionMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiDefinitionMapper.xml @@ -475,39 +475,9 @@ ) ) - - and api_definition.version_id = #{request.versionId} - - - and api_definition.ref_id = #{request.refId} - - - AND ( - version_id = (SELECT project_version.id - FROM api_definition tmp - JOIN project_version - ON tmp.project_id = project_version.project_id AND tmp.version_id = project_version.id AND latest = TRUE - WHERE ref_id = api_definition.ref_id - LIMIT 1) - OR - version_id = (SELECT project_version.id - FROM api_definition tmp - JOIN project_version - ON tmp.project_id = project_version.project_id AND - tmp.version_id = project_version.id AND NOT EXISTS(SELECT ref_id - FROM api_definition tmp2 - JOIN project_version - ON tmp2.project_id = - project_version.project_id AND - version_id = - project_version.id AND - latest = TRUE - WHERE tmp.ref_id = tmp2.ref_id) - WHERE tmp.ref_id = api_definition.ref_id - ORDER BY tmp.update_time DESC - LIMIT 1) - ) - + + + order by @@ -743,39 +713,9 @@ and api_definition.id in (SELECT api_definition_id FROM api_test_case) - - AND ref_id = #{request.refId} - - - AND version_id = #{request.versionId} - - - AND ( - version_id = (SELECT project_version.id - FROM api_definition tmp - JOIN project_version - ON tmp.project_id = project_version.project_id AND tmp.version_id = project_version.id AND latest = TRUE - WHERE ref_id = api_definition.ref_id - LIMIT 1) - OR - version_id = (SELECT project_version.id - FROM api_definition tmp - JOIN project_version - ON tmp.project_id = project_version.project_id AND - tmp.version_id = project_version.id AND NOT EXISTS(SELECT ref_id - FROM api_definition tmp2 - JOIN project_version - ON tmp2.project_id = - project_version.project_id AND - version_id = - project_version.id AND - latest = TRUE - WHERE tmp.ref_id = tmp2.ref_id) - WHERE tmp.ref_id = api_definition.ref_id - ORDER BY tmp.update_time DESC - LIMIT 1) - ) - + + + @@ -843,39 +783,9 @@ and api_definition.id in (SELECT api_definition_id FROM api_test_case) - - AND ref_id = #{request.refId} - - - AND version_id = #{request.versionId} - - - AND ( - version_id = (SELECT project_version.id - FROM api_definition tmp - JOIN project_version - ON tmp.project_id = project_version.project_id AND tmp.version_id = project_version.id AND latest = TRUE - WHERE ref_id = api_definition.ref_id - LIMIT 1) - OR - version_id = (SELECT project_version.id - FROM api_definition tmp - JOIN project_version - ON tmp.project_id = project_version.project_id AND - tmp.version_id = project_version.id AND NOT EXISTS(SELECT ref_id - FROM api_definition tmp2 - JOIN project_version - ON tmp2.project_id = - project_version.project_id AND - version_id = - project_version.id AND - latest = TRUE - WHERE tmp.ref_id = tmp2.ref_id) - WHERE tmp.ref_id = api_definition.ref_id - ORDER BY tmp.update_time DESC - LIMIT 1) - ) - + + + @@ -950,4 +860,16 @@ + + + + and ${versionTable}.version_id = #{request.versionId} + + + and ${versionTable}.ref_id = #{request.refId} + + + AND ${versionTable}.latest = 1 + + diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioMapper.xml index 2c45497fbc..a62e093287 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioMapper.xml @@ -318,39 +318,9 @@ where pc.test_plan_id = #{request.planId} ) - - AND ref_id = #{request.refId} - - - AND version_id = #{request.versionId} - - - AND ( - version_id = (SELECT project_version.id - FROM api_scenario tmp - JOIN project_version - ON tmp.project_id = project_version.project_id AND tmp.version_id = project_version.id AND latest = TRUE - WHERE ref_id = api_scenario.ref_id - LIMIT 1) - OR - version_id = (SELECT project_version.id - FROM api_scenario tmp - JOIN project_version - ON tmp.project_id = project_version.project_id AND - tmp.version_id = project_version.id AND NOT EXISTS(SELECT ref_id - FROM api_scenario tmp2 - JOIN project_version - ON tmp2.project_id = - project_version.project_id AND - version_id = - project_version.id AND - latest = TRUE - WHERE tmp.ref_id = tmp2.ref_id) - WHERE tmp.ref_id = api_scenario.ref_id - ORDER BY tmp.update_time DESC - LIMIT 1) - ) - + + + @@ -674,4 +644,16 @@ LEFT JOIN project on api_scenario.project_id = project.id WHERE api_scenario.id = #{id} + + + + and ${versionTable}.version_id = #{request.versionId} + + + and ${versionTable}.ref_id = #{request.refId} + + + AND ${versionTable}.latest = 1 + + diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiTestCaseMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiTestCaseMapper.xml index cf07dc32fa..00bacd5bbd 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiTestCaseMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiTestCaseMapper.xml @@ -419,29 +419,9 @@ and (t1.update_time >= #{request.updateTime} or t2.status = 'error') - - AND t1.version_id = #{request.versionId} - - - AND ( - t1.version_id = (SELECT project_version.id - FROM api_definition tmp - JOIN project_version - ON tmp.project_id = project_version.project_id AND tmp.version_id = project_version.id AND latest = TRUE - WHERE ref_id = a.ref_id - LIMIT 1) - OR - t1.version_id = (SELECT project_version.id - FROM api_definition tmp - JOIN project_version ON tmp.project_id = project_version.project_id AND - tmp.version_id = project_version.id - WHERE ref_id = a.ref_id - GROUP BY ref_id - HAVING MAX(latest) = 0 - ORDER BY MAX(project_version.create_time) DESC - LIMIT 1) - ) - + + + GROUP BY t1.id, t1.project_id, t1.name, @@ -787,4 +767,16 @@ #{v} + + + + and ${versionTable}.version_id = #{request.versionId} + + + and ${versionTable}.ref_id = #{request.refId} + + + AND ${versionTable}.latest = 1 + + diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtLoadTestMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtLoadTestMapper.xml index 81ca5f6666..f35d25b9a2 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtLoadTestMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtLoadTestMapper.xml @@ -166,39 +166,9 @@ - - AND ref_id = #{request.refId} - - - AND version_id = #{request.versionId} - - - AND ( - version_id = (SELECT project_version.id - FROM load_test tmp - JOIN project_version - ON tmp.project_id = project_version.project_id AND tmp.version_id = project_version.id AND latest = TRUE - WHERE ref_id = load_test.ref_id - LIMIT 1) - OR - version_id = (SELECT project_version.id - FROM load_test tmp - JOIN project_version - ON tmp.project_id = project_version.project_id AND - tmp.version_id = project_version.id AND NOT EXISTS(SELECT ref_id - FROM load_test tmp2 - JOIN project_version - ON tmp2.project_id = - project_version.project_id AND - version_id = - project_version.id AND - latest = TRUE - WHERE tmp.ref_id = tmp2.ref_id) - WHERE tmp.ref_id = load_test.ref_id - ORDER BY tmp.update_time DESC - LIMIT 1) - ) - + + + ORDER BY @@ -305,4 +275,16 @@ order by `order` desc limit 1; + + + + and ${versionTable}.version_id = #{request.versionId} + + + and ${versionTable}.ref_id = #{request.refId} + + + AND ${versionTable}.latest = 1 + + diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtShareInfoMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtShareInfoMapper.xml index 9015089111..d09b1a1f85 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtShareInfoMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtShareInfoMapper.xml @@ -30,21 +30,9 @@ #{apiId} - - AND api.ref_id = #{request.refId} - - - AND api.version_id = #{request.versionId} - - - AND api.version_id = (SELECT project_version.id - FROM api_definition tmp - JOIN project_version - ON tmp.project_id = project_version.project_id AND tmp.version_id = project_version.id - WHERE ref_id = api.ref_id - ORDER BY project_version.create_time DESC - LIMIT 1) - + + + ORDER BY api.create_time DESC @@ -67,4 +55,15 @@ + + + and ${versionTable}.version_id = #{request.versionId} + + + and ${versionTable}.ref_id = #{request.refId} + + + AND ${versionTable}.latest = 1 + + diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestCaseMapper.java b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestCaseMapper.java index 7b8bcc9aae..3f94a020b1 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestCaseMapper.java +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestCaseMapper.java @@ -83,7 +83,7 @@ public interface ExtTestCaseMapper { List countRelevance(@Param("projectId") String projectId); - long countRelevanceCreatedThisWeek(@Param("projectId") String projectId,@Param("firstDayTimestamp") long firstDayTimestamp, @Param("lastDayTimestamp") long lastDayTimestamp); + long countRelevanceCreatedThisWeek(@Param("projectId") String projectId, @Param("firstDayTimestamp") long firstDayTimestamp, @Param("lastDayTimestamp") long lastDayTimestamp); int countCoverage(@Param("projectId") String projectId); @@ -92,13 +92,15 @@ public interface ExtTestCaseMapper { List countRelevanceMaintainer(@Param("projectId") String projectId); int getTestPlanBug(@Param("planId") String planId); + int getTestPlanCase(@Param("planId") String planId); + int getTestPlanPassCase(@Param("planId") String planId); List listForMinder(@Param("request") QueryTestCaseRequest request); - List getTestCaseByIds(@Param("ids")List ids); + List getTestCaseByIds(@Param("ids") List ids); void updateTestCaseCustomNumByProjectId(@Param("projectId") String projectId); @@ -124,7 +126,7 @@ public interface ExtTestCaseMapper { List getIdsOrderByUpdateTime(@Param("projectId") String projectId); - Long getLastOrder(@Param("projectId")String projectId, @Param("baseOrder") Long baseOrder); + Long getLastOrder(@Param("projectId") String projectId, @Param("baseOrder") Long baseOrder); Long getPreOrder(@Param("projectId") String projectId, @Param("baseOrder") Long baseOrder); @@ -139,4 +141,10 @@ public interface ExtTestCaseMapper { int countByWorkSpaceId(String workSpaceId); long trashCount(@Param("projectId") String projectId); + + int addLatestVersion(@Param("refId") String refId); + + int clearLatestVersion(@Param("refId") String refId); + + int setLatestVersion(@Param("refId") String refId, @Param("versionId") String versionId); } diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestCaseMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestCaseMapper.xml index 73e03d25cd..6d29b0913b 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestCaseMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestCaseMapper.xml @@ -126,39 +126,9 @@ #{nodeId} - - and test_case.version_id = #{request.versionId} - - - and test_case.ref_id = #{request.refId} - - - AND ( - version_id = (SELECT project_version.id - FROM test_case tmp - JOIN project_version - ON tmp.project_id = project_version.project_id AND tmp.version_id = project_version.id AND latest = TRUE - WHERE ref_id = test_case.ref_id - LIMIT 1) - OR - version_id = (SELECT project_version.id - FROM test_case tmp - JOIN project_version - ON tmp.project_id = project_version.project_id AND - tmp.version_id = project_version.id AND NOT EXISTS(SELECT ref_id - FROM test_case tmp2 - JOIN project_version - ON tmp2.project_id = - project_version.project_id AND - version_id = - project_version.id AND - latest = TRUE - WHERE tmp.ref_id = tmp2.ref_id) - WHERE tmp.ref_id = test_case.ref_id - ORDER BY tmp.update_time DESC - LIMIT 1) - ) - + + + @@ -642,39 +612,9 @@ and test_case.id in (select distinct test_case_test.test_case_id from test_case_test) - - and test_case.version_id = #{request.versionId} - - - and test_case.ref_id = #{request.refId} - - - AND ( - version_id = (SELECT project_version.id - FROM test_case tmp - JOIN project_version - ON tmp.project_id = project_version.project_id AND tmp.version_id = project_version.id AND latest = TRUE - WHERE ref_id = test_case.ref_id - LIMIT 1) - OR - version_id = (SELECT project_version.id - FROM test_case tmp - JOIN project_version - ON tmp.project_id = project_version.project_id AND - tmp.version_id = project_version.id AND NOT EXISTS(SELECT ref_id - FROM test_case tmp2 - JOIN project_version - ON tmp2.project_id = - project_version.project_id AND - version_id = - project_version.id AND - latest = TRUE - WHERE tmp.ref_id = tmp2.ref_id) - WHERE tmp.ref_id = test_case.ref_id - ORDER BY tmp.update_time DESC - LIMIT 1) - ) - + + + @@ -733,39 +673,9 @@ and test_case.id in (select distinct test_case_test.test_case_id from test_case_test) - - and test_case.version_id = #{request.versionId} - - - and test_case.ref_id = #{request.refId} - - - AND ( - version_id = (SELECT project_version.id - FROM test_case tmp - JOIN project_version - ON tmp.project_id = project_version.project_id AND tmp.version_id = project_version.id AND latest = TRUE - WHERE ref_id = test_case.ref_id - LIMIT 1) - OR - version_id = (SELECT project_version.id - FROM test_case tmp - JOIN project_version - ON tmp.project_id = project_version.project_id AND - tmp.version_id = project_version.id AND NOT EXISTS(SELECT ref_id - FROM test_case tmp2 - JOIN project_version - ON tmp2.project_id = - project_version.project_id AND - version_id = - project_version.id AND - latest = TRUE - WHERE tmp.ref_id = tmp2.ref_id) - WHERE tmp.ref_id = test_case.ref_id - ORDER BY tmp.update_time DESC - LIMIT 1) - ) - + + + @@ -1057,4 +967,61 @@ AND STATUS = 'Trash' + + + and ${versionTable}.version_id = #{request.versionId} + + + and ${versionTable}.ref_id = #{request.refId} + + + AND ${versionTable}.latest = 1 + + + + + UPDATE test_case + INNER JOIN ( + SELECT + test_case.* + FROM + test_case + LEFT JOIN project_version ON test_case.version_id = project_version.id + + + ref_id = #{refId} + + + GROUP BY + ref_id + HAVING + max(test_case.latest) = 0 + ORDER BY + project_version.create_time desc + LIMIT 1 + ) t + ON test_case.id = t.id + SET test_case.latest = 1 + + + + UPDATE test_case + SET latest = 0 + + + and ref_id = #{refId} + + + + + + UPDATE test_case + SET latest = 1 + + + ref_id = #{refId} + + + AND version_id = #{versionId} + diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanApiCaseMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanApiCaseMapper.xml index 380c3dbf25..0570ce2e6e 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanApiCaseMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanApiCaseMapper.xml @@ -139,32 +139,9 @@ - - and a.version_id = #{request.versionId} - - - and a.ref_id = #{request.refId} - - - AND ( - a.version_id = (SELECT project_version.id - FROM api_definition tmp - JOIN project_version - ON tmp.project_id = project_version.project_id AND tmp.version_id = project_version.id AND latest = TRUE - WHERE ref_id = a.ref_id - LIMIT 1) - OR - a.version_id = (SELECT project_version.id - FROM api_definition tmp - JOIN project_version ON tmp.project_id = project_version.project_id AND - tmp.version_id = project_version.id - WHERE ref_id = a.ref_id - GROUP BY ref_id - HAVING MAX(latest) = 0 - ORDER BY MAX(project_version.create_time) DESC - LIMIT 1) - ) - + + + order by @@ -371,4 +348,16 @@ order by `order` desc limit 1; + + + + and ${versionTable}.version_id = #{request.versionId} + + + and ${versionTable}.ref_id = #{request.refId} + + + AND ${versionTable}.latest = 1 + + diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanLoadCaseMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanLoadCaseMapper.xml index 0202b831ab..721232e2f6 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanLoadCaseMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanLoadCaseMapper.xml @@ -193,32 +193,9 @@ - - and lt.version_id = #{request.versionId} - - - and lt.ref_id = #{request.refId} - - - AND ( - lt.version_id = (SELECT project_version.id - FROM load_test tmp - JOIN project_version - ON tmp.project_id = project_version.project_id AND tmp.version_id = project_version.id AND latest = TRUE - WHERE ref_id = lt.ref_id - LIMIT 1) - OR - lt.version_id = (SELECT project_version.id - FROM load_test tmp - JOIN project_version ON tmp.project_id = project_version.project_id AND - tmp.version_id = project_version.id - WHERE ref_id = lt.ref_id - GROUP BY ref_id - HAVING MAX(latest) = 0 - ORDER BY MAX(project_version.create_time) DESC - LIMIT 1) - ) - + + + order by @@ -371,4 +348,16 @@ set status = null where id = #{0} + + + + and ${versionTable}.version_id = #{request.versionId} + + + and ${versionTable}.ref_id = #{request.refId} + + + AND ${versionTable}.latest = 1 + + diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanTestCaseMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanTestCaseMapper.xml index 4b072d8756..bdd5d8e2c3 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanTestCaseMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanTestCaseMapper.xml @@ -171,39 +171,9 @@ and test_case.method = #{request.method} - - and test_case.version_id = #{request.versionId} - - - and test_case.ref_id = #{request.refId} - - - AND ( - version_id = (SELECT project_version.id - FROM test_case tmp - JOIN project_version - ON tmp.project_id = project_version.project_id AND tmp.version_id = project_version.id AND latest = TRUE - WHERE ref_id = test_case.ref_id - LIMIT 1) - OR - version_id = (SELECT project_version.id - FROM test_case tmp - JOIN project_version - ON tmp.project_id = project_version.project_id AND - tmp.version_id = project_version.id AND NOT EXISTS(SELECT ref_id - FROM test_case tmp2 - JOIN project_version - ON tmp2.project_id = - project_version.project_id AND - version_id = - project_version.id AND - latest = TRUE - WHERE tmp.ref_id = tmp2.ref_id) - WHERE tmp.ref_id = test_case.ref_id - ORDER BY tmp.update_time DESC - LIMIT 1) - ) - + + + and (test_case.status != 'Trash' or test_case.status is null) @@ -585,4 +555,16 @@ order by `order` desc limit 1; + + + + and ${versionTable}.version_id = #{request.versionId} + + + and ${versionTable}.ref_id = #{request.refId} + + + AND ${versionTable}.latest = 1 + + diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestReviewCaseMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestReviewCaseMapper.xml index 94f73ac81f..ba02543e99 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestReviewCaseMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestReviewCaseMapper.xml @@ -167,39 +167,9 @@ and test_case.method = #{request.method} - - and test_case.version_id = #{request.versionId} - - - and test_case.ref_id = #{request.refId} - - - AND ( - version_id = (SELECT project_version.id - FROM test_case tmp - JOIN project_version - ON tmp.project_id = project_version.project_id AND tmp.version_id = project_version.id AND latest = TRUE - WHERE ref_id = test_case.ref_id - LIMIT 1) - OR - version_id = (SELECT project_version.id - FROM test_case tmp - JOIN project_version - ON tmp.project_id = project_version.project_id AND - tmp.version_id = project_version.id AND NOT EXISTS(SELECT ref_id - FROM test_case tmp2 - JOIN project_version - ON tmp2.project_id = - project_version.project_id AND - version_id = - project_version.id AND - latest = TRUE - WHERE tmp.ref_id = tmp2.ref_id) - WHERE tmp.ref_id = test_case.ref_id - ORDER BY tmp.update_time DESC - LIMIT 1) - ) - + + + @@ -492,4 +462,16 @@ order by `order` desc limit 1; + + + + and ${versionTable}.version_id = #{request.versionId} + + + and ${versionTable}.ref_id = #{request.refId} + + + AND ${versionTable}.latest = 1 + + diff --git a/backend/src/main/java/io/metersphere/commons/constants/VersionConstants.java b/backend/src/main/java/io/metersphere/commons/constants/VersionConstants.java new file mode 100644 index 0000000000..873fad38f9 --- /dev/null +++ b/backend/src/main/java/io/metersphere/commons/constants/VersionConstants.java @@ -0,0 +1,8 @@ +package io.metersphere.commons.constants; + +public class VersionConstants { + //最新版本 + public static Byte LATEST = 1; + //非最新版本 可以不用设置数据库 default = 0 + public static Byte NOT_LATEST = 0; +} diff --git a/backend/src/main/java/io/metersphere/track/service/TestCaseService.java b/backend/src/main/java/io/metersphere/track/service/TestCaseService.java index 5c30658a5d..63e6f3c424 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestCaseService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestCaseService.java @@ -22,6 +22,7 @@ import io.metersphere.base.mapper.ext.ExtTestCaseMapper; import io.metersphere.commons.constants.TestCaseConstants; import io.metersphere.commons.constants.TestCaseReviewStatus; import io.metersphere.commons.constants.UserGroupType; +import io.metersphere.commons.constants.VersionConstants; import io.metersphere.commons.exception.MSException; import io.metersphere.commons.user.SessionUser; import io.metersphere.commons.utils.*; @@ -206,7 +207,8 @@ public class TestCaseService { //从版本选择直接创建 request.setRefId(request.getId()); } - + //完全新增一条记录直接就是最新 + request.setLatest(VersionConstants.LATEST); testCaseMapper.insert(request); saveFollows(request.getId(), request.getFollows()); return request; @@ -306,9 +308,11 @@ public class TestCaseService { testCase.setCreateUser(SessionUtils.getUserId()); testCase.setOrder(oldTestCase.getOrder()); testCase.setRefId(oldTestCase.getRefId()); + testCase.setLatest(null); DealWithOtherInfo(testCase, oldTestCase.getId()); testCaseMapper.insertSelective(testCase); } + checkAndSetLatestVersion(testCase.getRefId(), testCase.getVersionId(), testCase.getProjectId()); } /** @@ -2490,6 +2494,30 @@ public class TestCaseService { if (CollectionUtils.isNotEmpty(testCaseList)) { testCaseMapper.deleteByExample(e); } + //检查最新版本 + checkAndSetLatestVersion(refId, version, testCaseList.get(0).getProjectId()); + } + + /** + * 检查设置最新版本 + * + * @param refId + * @param versionId + */ + private void checkAndSetLatestVersion(String refId, String versionId, String projectId) { + TestCaseExample e = new TestCaseExample(); + e.createCriteria().andRefIdEqualTo(refId).andLatestEqualTo(VersionConstants.LATEST); + //如果因为删除导致没有了最新的版本,则按照版本创建顺序选择一个版本为最新版本 + if (testCaseMapper.countByExample(e) == 0) { + extTestCaseMapper.addLatestVersion(refId); + } else { + //已经存在了最新版本 但是要判断这个所谓的最新版本是否是版本管理里面最新版本 + String latestVersion = extProjectVersionMapper.getDefaultVersion(projectId); + if (StringUtils.equals(versionId, latestVersion)) { + extTestCaseMapper.clearLatestVersion(refId); + extTestCaseMapper.setLatestVersion(refId, versionId); + } + } } public void deleteTestCasePublic(String versionId, String refId) { diff --git a/backend/src/main/resources/db/migration/V106__v1.17_release.sql b/backend/src/main/resources/db/migration/V106__v1.17_release.sql index 5c178ce138..711d6c952c 100644 --- a/backend/src/main/resources/db/migration/V106__v1.17_release.sql +++ b/backend/src/main/resources/db/migration/V106__v1.17_release.sql @@ -195,4 +195,56 @@ ALTER TABLE `test_plan_report_content` ADD COLUMN `error_report_cases` LONGTEXT ALTER TABLE `test_plan_report_content` ADD COLUMN `error_report_scenarios` LONGTEXT COMMENT '误报状态场景用例'; -- 缺陷相关配置 -ALTER TABLE project ADD issue_config TEXT NULL; +ALTER TABLE project + ADD issue_config TEXT NULL; + +-- 增加 latest 字段优化最新版本查询 + +ALTER TABLE test_case + ADD latest tinyint DEFAULT 0 COMMENT '是否为最新版本 0:否,1:是'; +ALTER TABLE api_definition + ADD latest tinyint DEFAULT 0 COMMENT '是否为最新版本 0:否,1:是'; +ALTER TABLE api_scenario + ADD latest tinyint DEFAULT 0 COMMENT '是否为最新版本 0:否,1:是'; +ALTER TABLE load_test + ADD latest tinyint DEFAULT 0 COMMENT '是否为最新版本 0:否,1:是'; + +-- 设置最新版本的数据 + +UPDATE test_case +SET latest = 1 +WHERE version_id = ( + SELECT id + FROM project_version + WHERE project_version.project_id = test_case.project_id + AND project_version.latest = 1 +); + +UPDATE api_definition +SET latest = 1 +WHERE version_id = ( + SELECT id + FROM project_version + WHERE project_version.project_id = api_definition.project_id + AND project_version.latest = 1 +); + +UPDATE api_scenario +SET latest = 1 +WHERE version_id = ( + SELECT id + FROM project_version + WHERE project_version.project_id = api_scenario.project_id + AND project_version.latest = 1 +); + +UPDATE load_test +SET latest = 1 +WHERE version_id = ( + SELECT id + FROM project_version + WHERE project_version.project_id = load_test.project_id + AND project_version.latest = 1 +); + + diff --git a/frontend/src/business/components/track/case/components/TestCaseEdit.vue b/frontend/src/business/components/track/case/components/TestCaseEdit.vue index 5d468b1ee3..514a6af703 100644 --- a/frontend/src/business/components/track/case/components/TestCaseEdit.vue +++ b/frontend/src/business/components/track/case/components/TestCaseEdit.vue @@ -23,7 +23,6 @@ ref="versionHistory" :version-data="versionData" :current-id="currentTestCaseInfo.id" - :is-test-case-version="true" @confirmOtherInfo="confirmOtherInfo" :current-project-id="currentProjectId" @compare="compare" @checkout="checkout" @create="create" @del="del"/>