fix(测试跟踪): 功能用例创建版本后保存用例会创建多条最新用例

--bug=1018792 --user=陈建星 【测试跟踪】功能用例-用例有两个版本都不是项目的最新版本,在列表中都显示出来了 https://www.tapd.cn/55049933/s/1276187
This commit is contained in:
chenjianxing 2022-10-25 13:57:17 +08:00 committed by jianxing
parent 31f09fb74f
commit 9b570eae45
4 changed files with 31 additions and 79 deletions

View File

@ -161,4 +161,6 @@ public interface ExtTestCaseMapper {
List<TestCaseNodeDTO> 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);
}

View File

@ -1381,4 +1381,9 @@
select id from test_case_node where project_id = #{projectId}
)
</update>
<update id="clearLatestVersion">
UPDATE test_case
SET latest = 0
where ref_id = #{refId}
</update>
</mapper>

View File

@ -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<String> 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<TestCase> differentVersionData = testCaseMapper.selectByExample(e);
if (differentVersionData.size() != 0) {
ProjectVersionExample pe = new ProjectVersionExample();
pe.createCriteria().andProjectIdEqualTo(projectId);
pe.setOrderByClause("create_time desc");
List<ProjectVersion> 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) {

View File

@ -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) {