From fb2e4e70b37aececaed2d0c68ae81d8cc1808b8e Mon Sep 17 00:00:00 2001 From: CaptainB Date: Thu, 20 Jan 2022 12:48:19 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E4=BF=AE=E6=94=B9=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mapper/ext/ExtApiDefinitionMapper.xml | 42 ++++++++++++------- .../base/mapper/ext/ExtApiScenarioMapper.xml | 19 ++++++--- .../base/mapper/ext/ExtLoadTestMapper.xml | 19 ++++++--- .../base/mapper/ext/ExtTestCaseMapper.xml | 38 +++++++++++------ .../mapper/ext/ExtTestPlanTestCaseMapper.xml | 19 ++++++--- .../mapper/ext/ExtTestReviewCaseMapper.xml | 19 ++++++--- 6 files changed, 106 insertions(+), 50 deletions(-) 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 ae16145f9c..7a7f9200e8 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 @@ -495,12 +495,19 @@ 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 - WHERE ref_id = api_definition.ref_id - GROUP BY ref_id - HAVING MAX(latest) = 0 - ORDER BY MAX(tmp.update_time) DESC + 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) ) @@ -758,14 +765,21 @@ 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 - WHERE ref_id = api_definition.ref_id - GROUP BY ref_id - HAVING MAX(latest) = 0 - ORDER BY MAX(tmp.update_time) DESC - LIMIT 1) + 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) ) 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 4b59c9f53e..2c45497fbc 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 @@ -335,12 +335,19 @@ 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 - WHERE ref_id = api_scenario.ref_id - GROUP BY ref_id - HAVING MAX(latest) = 0 - ORDER BY MAX(tmp.update_time) DESC + 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) ) 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 5f9a163b00..81ca5f6666 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 @@ -183,12 +183,19 @@ 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 - WHERE ref_id = load_test.ref_id - GROUP BY ref_id - HAVING MAX(latest) = 0 - ORDER BY MAX(tmp.update_time) DESC + 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) ) 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 68e8d81b0c..2465d59e21 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 @@ -144,12 +144,19 @@ 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 - WHERE ref_id = test_case.ref_id - GROUP BY ref_id - HAVING MAX(latest) = 0 - ORDER BY MAX(tmp.update_time) DESC + 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) ) @@ -637,12 +644,19 @@ 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 - WHERE ref_id = test_case.ref_id - GROUP BY ref_id - HAVING MAX(latest) = 0 - ORDER BY MAX(tmp.update_time) DESC + 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) ) 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 4951c54d6c..0c908b03aa 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 @@ -188,12 +188,19 @@ 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 - WHERE ref_id = test_case.ref_id - GROUP BY ref_id - HAVING MAX(latest) = 0 - ORDER BY MAX(tmp.update_time) DESC + 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) ) 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 3fe01dea79..94f73ac81f 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 @@ -184,12 +184,19 @@ 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 - WHERE ref_id = test_case.ref_id - GROUP BY ref_id - HAVING MAX(latest) = 0 - ORDER BY MAX(tmp.update_time) DESC + 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) )