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 5cfb2ca2e4..a8fb3a0bd9 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 @@ -141,4 +141,8 @@ public interface ExtTestCaseMapper { int countByWorkSpaceId(String workSpaceId); long trashCount(@Param("projectId") String projectId); + + List selectRefIdsForVersionChange(@Param("versionId") String versionId, @Param("projectId") String projectId); + + int addLatestVersion(@Param("refId") String refId); } 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 4f56278573..bf5b9ea751 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 @@ -980,4 +980,50 @@ AND ${versionTable}.latest = 1 + + + + + UPDATE test_case + INNER JOIN (( + SELECT tmp.id + FROM test_case tmp + JOIN project_version + ON tmp.project_id = project_version.project_id AND + tmp.version_id = project_version.id AND project_version.latest = TRUE + WHERE ref_id = #{refId,jdbcType=VARCHAR} + LIMIT 1 + ) + UNION + ( + SELECT tmp.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 + project_version.latest = TRUE + WHERE tmp.ref_id = tmp2.ref_id) + WHERE tmp.ref_id = #{refId,jdbcType=VARCHAR} + ORDER BY tmp.update_time DESC + LIMIT 1)) AS t + ON test_case.id = t.id + SET test_case.latest = TRUE +