From 9b570eae453813e5a4acd5df1453d47eeff46705 Mon Sep 17 00:00:00 2001 From: chenjianxing Date: Tue, 25 Oct 2022 13:57:17 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=B5=8B=E8=AF=95=E8=B7=9F=E8=B8=AA):=20?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=E7=94=A8=E4=BE=8B=E5=88=9B=E5=BB=BA=E7=89=88?= =?UTF-8?q?=E6=9C=AC=E5=90=8E=E4=BF=9D=E5=AD=98=E7=94=A8=E4=BE=8B=E4=BC=9A?= =?UTF-8?q?=E5=88=9B=E5=BB=BA=E5=A4=9A=E6=9D=A1=E6=9C=80=E6=96=B0=E7=94=A8?= =?UTF-8?q?=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1018792 --user=陈建星 【测试跟踪】功能用例-用例有两个版本都不是项目的最新版本,在列表中都显示出来了 https://www.tapd.cn/55049933/s/1276187 --- .../base/mapper/ext/ExtTestCaseMapper.java | 2 + .../base/mapper/ext/ExtTestCaseMapper.xml | 5 ++ .../metersphere/service/TestCaseService.java | 82 +++---------------- .../business/case/components/TestCaseEdit.vue | 21 ++--- 4 files changed, 31 insertions(+), 79 deletions(-) diff --git a/test-track/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestCaseMapper.java b/test-track/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestCaseMapper.java index 049632fadd..9824c33d26 100644 --- a/test-track/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestCaseMapper.java +++ b/test-track/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestCaseMapper.java @@ -161,4 +161,6 @@ public interface ExtTestCaseMapper { List getWorkspaceCountNodes(@Param("request") QueryTestCaseRequest request); void updateNoModuleTrashNodeToDefault(@Param("projectId") String projectId, @Param("defaultNodeId") String defaultNodeId, @Param("defaultNodePath") String defaultNodePath); + + void clearLatestVersion(@Param("refId") String refId); } diff --git a/test-track/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestCaseMapper.xml b/test-track/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestCaseMapper.xml index 2c74b35f9a..c95dab72f8 100644 --- a/test-track/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestCaseMapper.xml +++ b/test-track/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestCaseMapper.xml @@ -1381,4 +1381,9 @@ select id from test_case_node where project_id = #{projectId} ) + + UPDATE test_case + SET latest = 0 + where ref_id = #{refId} + diff --git a/test-track/backend/src/main/java/io/metersphere/service/TestCaseService.java b/test-track/backend/src/main/java/io/metersphere/service/TestCaseService.java index 13895bc0f9..86a950f4b6 100644 --- a/test-track/backend/src/main/java/io/metersphere/service/TestCaseService.java +++ b/test-track/backend/src/main/java/io/metersphere/service/TestCaseService.java @@ -379,12 +379,6 @@ public class TestCaseService { public TestCaseWithBLOBs editTestCase(EditTestCaseRequest testCase) { checkTestCustomNum(testCase); testCase.setUpdateTime(System.currentTimeMillis()); - // 更新数据 - TestCaseExample example = new TestCaseExample(); - example.createCriteria().andIdEqualTo(testCase.getId()); - if (StringUtils.isNotBlank(testCase.getVersionId())) { - example.getOredCriteria().get(0).andVersionIdEqualTo(testCase.getVersionId()); - } // 同步缺陷与需求的关联关系 updateThirdPartyIssuesLink(testCase); @@ -395,12 +389,12 @@ public class TestCaseService { if (StringUtils.isEmpty(testCase.getDemandId())) { testCase.setDemandId(StringUtils.EMPTY); } - createNewVersionOrNot(testCase, example); + createNewVersionOrNot(testCase); if (StringUtils.isNotBlank(testCase.getCustomNum()) && StringUtils.isNotBlank(testCase.getId())) { TestCaseWithBLOBs caseWithBLOBs = testCaseMapper.selectByPrimaryKey(testCase.getId()); if (caseWithBLOBs != null) { - example.clear(); + TestCaseExample example = new TestCaseExample(); example.createCriteria().andRefIdEqualTo(caseWithBLOBs.getRefId()); TestCaseWithBLOBs testCaseWithBLOBs = new TestCaseWithBLOBs(); testCaseWithBLOBs.setCustomNum(testCase.getCustomNum()); @@ -442,9 +436,11 @@ public class TestCaseService { * 根据前后端 versionId 判定是编辑旧数据还是创建新版本 * * @param testCase - * @param example */ - private void createNewVersionOrNot(EditTestCaseRequest testCase, TestCaseExample example) { + private void createNewVersionOrNot(EditTestCaseRequest testCase) { + TestCaseExample example = new TestCaseExample(); + example.createCriteria().andIdEqualTo(testCase.getId()) + .andVersionIdEqualTo(testCase.getVersionId()); if (testCaseMapper.updateByExampleSelective(testCase, example) == 0) { // 插入新版本的数据 TestCaseWithBLOBs oldTestCase = testCaseMapper.selectByPrimaryKey(testCase.getId()); @@ -458,8 +454,8 @@ public class TestCaseService { testCase.setLatest(false); DealWithOtherInfo(testCase, oldTestCase.getId()); testCaseMapper.insertSelective(testCase); - checkAndSetLatestVersion(testCase.getRefId(), testCase.getVersionId(), testCase.getProjectId(), "add"); } + checkAndSetLatestVersion(testCase.getRefId()); } /** @@ -1334,7 +1330,7 @@ public class TestCaseService { sqlSession.flushStatements(); insertCases.forEach(item -> { - checkAndSetLatestVersion(item.getRefId(), request.getVersionId(), request.getProjectId(), "add"); + checkAndSetLatestVersion(item.getRefId()); }); } catch (Exception e) { LogUtil.error(e); @@ -2967,69 +2963,17 @@ public class TestCaseService { //删除执行记录 functionCaseExecutionInfoService.deleteBySourceIdList(idList); //检查最新版本 - checkAndSetLatestVersion(refId, version, testCaseList.get(0).getProjectId(), "del"); + checkAndSetLatestVersion(refId); } } + /** * 检查设置最新版本 - * - * @param refId - * @param versionId */ - private void checkAndSetLatestVersion(String refId, String versionId, String projectId, String opt) { - if (StringUtils.isAnyBlank(refId, versionId, projectId)) - return; - if (StringUtils.equalsAnyIgnoreCase("add", opt)) { - String latestVersion = baseProjectVersionMapper.getDefaultVersion(projectId); - if (StringUtils.equals(versionId, latestVersion)) { - TestCaseExample e = new TestCaseExample(); - e.createCriteria().andRefIdEqualTo(refId).andVersionIdEqualTo(versionId); - List changeToLatestIds = testCaseMapper.selectByExample(e).stream().map(TestCase::getId).collect(Collectors.toList()); - //如果是最新版本 - TestCaseWithBLOBs t = new TestCaseWithBLOBs(); - t.setLatest(true); - testCaseMapper.updateByExampleSelective(t, e); - - if (CollectionUtils.isNotEmpty(changeToLatestIds)) { - e.clear(); - e.createCriteria().andRefIdEqualTo(refId).andIdNotIn(changeToLatestIds); - t.setLatest(false); - testCaseMapper.updateByExampleSelective(t, e); - } - } - } else if (StringUtils.equalsIgnoreCase("del", opt)) { - //删掉该版本数据 - TestCaseExample e = new TestCaseExample(); - e.createCriteria().andRefIdEqualTo(refId).andLatestEqualTo(true); - if (testCaseMapper.countByExample(e) == 0) { - //删掉最新版本的数据 - e.clear(); - e.createCriteria().andRefIdEqualTo(refId).andVersionIdNotEqualTo(versionId); - List differentVersionData = testCaseMapper.selectByExample(e); - if (differentVersionData.size() != 0) { - ProjectVersionExample pe = new ProjectVersionExample(); - pe.createCriteria().andProjectIdEqualTo(projectId); - pe.setOrderByClause("create_time desc"); - List versionList = projectVersionMapper.selectByExample(pe); - TestCase latestData = null; - for (ProjectVersion projectVersion : versionList) { - for (TestCase t : differentVersionData) - if (projectVersion.getId().equalsIgnoreCase(t.getVersionId())) { - latestData = t; - break; - } - if (latestData != null) - break; - } - if (latestData == null) - latestData = differentVersionData.get(0); - latestData.setLatest(true); - testCaseMapper.updateByPrimaryKey(latestData); - } - } - } - + private void checkAndSetLatestVersion(String refId) { + extTestCaseMapper.clearLatestVersion(refId); + extTestCaseMapper.addLatestVersion(refId); } public void deleteTestCasePublic(String versionId, String refId) { diff --git a/test-track/frontend/src/business/case/components/TestCaseEdit.vue b/test-track/frontend/src/business/case/components/TestCaseEdit.vue index aeddd23895..e181ba011a 100644 --- a/test-track/frontend/src/business/case/components/TestCaseEdit.vue +++ b/test-track/frontend/src/business/case/components/TestCaseEdit.vue @@ -761,18 +761,19 @@ export default { let param = this.buildParam(); if (this.validate(param)) { let option = this.getOption(param); - this.result = this.$request(option) + this.loading = true; + this.$request(option) .then((response) => { response = response.data; // 保存用例后刷新附件 this.currentTestCaseInfo.isCopy = false; this.$refs.otherInfo.getFileMetaData(response.data.id); + this.loading = false; this.$success(this.$t('commons.save_success')); this.path = "/test/case/edit"; - // this.operationType = "edit" + this.operationType = "edit" this.$emit("refreshTestCase",); useStore().testCaseMap.set(this.form.id, 0); - //this.tableType = 'edit'; this.$emit("refresh", response.data); if (this.form.id) { this.$emit("caseEdit", param); @@ -798,6 +799,8 @@ export default { if (hasLicense()) { this.getVersionHistory(); } + }).catch(() => { + this.loading = false; }); } }, @@ -1084,10 +1087,11 @@ export default { this.$refs.versionHistory.loading = false; this.$refs.selectPropDialog.open(); } else { - this.saveCase(); - if (this.$refs.versionHistory) { - this.$refs.versionHistory.loading = false; - } + this.saveCase(() => { + if (this.$refs.versionHistory) { + this.$refs.versionHistory.loading = false; + } + }); } } else { this.$refs.versionHistory.loading = false; @@ -1111,9 +1115,6 @@ export default { } }); }, - changeType(type) { - this.type = type; - }, hasOtherInfo() { return new Promise((resolve) => { if (this.form.id) {