fix(测试跟踪): 功能用例创建版本后保存用例会创建多条最新用例
--bug=1018792 --user=陈建星 【测试跟踪】功能用例-用例有两个版本都不是项目的最新版本,在列表中都显示出来了 https://www.tapd.cn/55049933/s/1276187
This commit is contained in:
parent
31f09fb74f
commit
9b570eae45
|
@ -161,4 +161,6 @@ public interface ExtTestCaseMapper {
|
||||||
List<TestCaseNodeDTO> getWorkspaceCountNodes(@Param("request") QueryTestCaseRequest request);
|
List<TestCaseNodeDTO> getWorkspaceCountNodes(@Param("request") QueryTestCaseRequest request);
|
||||||
|
|
||||||
void updateNoModuleTrashNodeToDefault(@Param("projectId") String projectId, @Param("defaultNodeId") String defaultNodeId, @Param("defaultNodePath") String defaultNodePath);
|
void updateNoModuleTrashNodeToDefault(@Param("projectId") String projectId, @Param("defaultNodeId") String defaultNodeId, @Param("defaultNodePath") String defaultNodePath);
|
||||||
|
|
||||||
|
void clearLatestVersion(@Param("refId") String refId);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1381,4 +1381,9 @@
|
||||||
select id from test_case_node where project_id = #{projectId}
|
select id from test_case_node where project_id = #{projectId}
|
||||||
)
|
)
|
||||||
</update>
|
</update>
|
||||||
|
<update id="clearLatestVersion">
|
||||||
|
UPDATE test_case
|
||||||
|
SET latest = 0
|
||||||
|
where ref_id = #{refId}
|
||||||
|
</update>
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|
|
@ -379,12 +379,6 @@ public class TestCaseService {
|
||||||
public TestCaseWithBLOBs editTestCase(EditTestCaseRequest testCase) {
|
public TestCaseWithBLOBs editTestCase(EditTestCaseRequest testCase) {
|
||||||
checkTestCustomNum(testCase);
|
checkTestCustomNum(testCase);
|
||||||
testCase.setUpdateTime(System.currentTimeMillis());
|
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);
|
updateThirdPartyIssuesLink(testCase);
|
||||||
|
@ -395,12 +389,12 @@ public class TestCaseService {
|
||||||
if (StringUtils.isEmpty(testCase.getDemandId())) {
|
if (StringUtils.isEmpty(testCase.getDemandId())) {
|
||||||
testCase.setDemandId(StringUtils.EMPTY);
|
testCase.setDemandId(StringUtils.EMPTY);
|
||||||
}
|
}
|
||||||
createNewVersionOrNot(testCase, example);
|
createNewVersionOrNot(testCase);
|
||||||
|
|
||||||
if (StringUtils.isNotBlank(testCase.getCustomNum()) && StringUtils.isNotBlank(testCase.getId())) {
|
if (StringUtils.isNotBlank(testCase.getCustomNum()) && StringUtils.isNotBlank(testCase.getId())) {
|
||||||
TestCaseWithBLOBs caseWithBLOBs = testCaseMapper.selectByPrimaryKey(testCase.getId());
|
TestCaseWithBLOBs caseWithBLOBs = testCaseMapper.selectByPrimaryKey(testCase.getId());
|
||||||
if (caseWithBLOBs != null) {
|
if (caseWithBLOBs != null) {
|
||||||
example.clear();
|
TestCaseExample example = new TestCaseExample();
|
||||||
example.createCriteria().andRefIdEqualTo(caseWithBLOBs.getRefId());
|
example.createCriteria().andRefIdEqualTo(caseWithBLOBs.getRefId());
|
||||||
TestCaseWithBLOBs testCaseWithBLOBs = new TestCaseWithBLOBs();
|
TestCaseWithBLOBs testCaseWithBLOBs = new TestCaseWithBLOBs();
|
||||||
testCaseWithBLOBs.setCustomNum(testCase.getCustomNum());
|
testCaseWithBLOBs.setCustomNum(testCase.getCustomNum());
|
||||||
|
@ -442,9 +436,11 @@ public class TestCaseService {
|
||||||
* 根据前后端 versionId 判定是编辑旧数据还是创建新版本
|
* 根据前后端 versionId 判定是编辑旧数据还是创建新版本
|
||||||
*
|
*
|
||||||
* @param testCase
|
* @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) {
|
if (testCaseMapper.updateByExampleSelective(testCase, example) == 0) {
|
||||||
// 插入新版本的数据
|
// 插入新版本的数据
|
||||||
TestCaseWithBLOBs oldTestCase = testCaseMapper.selectByPrimaryKey(testCase.getId());
|
TestCaseWithBLOBs oldTestCase = testCaseMapper.selectByPrimaryKey(testCase.getId());
|
||||||
|
@ -458,8 +454,8 @@ public class TestCaseService {
|
||||||
testCase.setLatest(false);
|
testCase.setLatest(false);
|
||||||
DealWithOtherInfo(testCase, oldTestCase.getId());
|
DealWithOtherInfo(testCase, oldTestCase.getId());
|
||||||
testCaseMapper.insertSelective(testCase);
|
testCaseMapper.insertSelective(testCase);
|
||||||
checkAndSetLatestVersion(testCase.getRefId(), testCase.getVersionId(), testCase.getProjectId(), "add");
|
|
||||||
}
|
}
|
||||||
|
checkAndSetLatestVersion(testCase.getRefId());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1334,7 +1330,7 @@ public class TestCaseService {
|
||||||
sqlSession.flushStatements();
|
sqlSession.flushStatements();
|
||||||
|
|
||||||
insertCases.forEach(item -> {
|
insertCases.forEach(item -> {
|
||||||
checkAndSetLatestVersion(item.getRefId(), request.getVersionId(), request.getProjectId(), "add");
|
checkAndSetLatestVersion(item.getRefId());
|
||||||
});
|
});
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LogUtil.error(e);
|
LogUtil.error(e);
|
||||||
|
@ -2967,69 +2963,17 @@ public class TestCaseService {
|
||||||
//删除执行记录
|
//删除执行记录
|
||||||
functionCaseExecutionInfoService.deleteBySourceIdList(idList);
|
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) {
|
private void checkAndSetLatestVersion(String refId) {
|
||||||
if (StringUtils.isAnyBlank(refId, versionId, projectId))
|
extTestCaseMapper.clearLatestVersion(refId);
|
||||||
return;
|
extTestCaseMapper.addLatestVersion(refId);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deleteTestCasePublic(String versionId, String refId) {
|
public void deleteTestCasePublic(String versionId, String refId) {
|
||||||
|
|
|
@ -761,18 +761,19 @@ export default {
|
||||||
let param = this.buildParam();
|
let param = this.buildParam();
|
||||||
if (this.validate(param)) {
|
if (this.validate(param)) {
|
||||||
let option = this.getOption(param);
|
let option = this.getOption(param);
|
||||||
this.result = this.$request(option)
|
this.loading = true;
|
||||||
|
this.$request(option)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
response = response.data;
|
response = response.data;
|
||||||
// 保存用例后刷新附件
|
// 保存用例后刷新附件
|
||||||
this.currentTestCaseInfo.isCopy = false;
|
this.currentTestCaseInfo.isCopy = false;
|
||||||
this.$refs.otherInfo.getFileMetaData(response.data.id);
|
this.$refs.otherInfo.getFileMetaData(response.data.id);
|
||||||
|
this.loading = false;
|
||||||
this.$success(this.$t('commons.save_success'));
|
this.$success(this.$t('commons.save_success'));
|
||||||
this.path = "/test/case/edit";
|
this.path = "/test/case/edit";
|
||||||
// this.operationType = "edit"
|
this.operationType = "edit"
|
||||||
this.$emit("refreshTestCase",);
|
this.$emit("refreshTestCase",);
|
||||||
useStore().testCaseMap.set(this.form.id, 0);
|
useStore().testCaseMap.set(this.form.id, 0);
|
||||||
//this.tableType = 'edit';
|
|
||||||
this.$emit("refresh", response.data);
|
this.$emit("refresh", response.data);
|
||||||
if (this.form.id) {
|
if (this.form.id) {
|
||||||
this.$emit("caseEdit", param);
|
this.$emit("caseEdit", param);
|
||||||
|
@ -798,6 +799,8 @@ export default {
|
||||||
if (hasLicense()) {
|
if (hasLicense()) {
|
||||||
this.getVersionHistory();
|
this.getVersionHistory();
|
||||||
}
|
}
|
||||||
|
}).catch(() => {
|
||||||
|
this.loading = false;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -1084,10 +1087,11 @@ export default {
|
||||||
this.$refs.versionHistory.loading = false;
|
this.$refs.versionHistory.loading = false;
|
||||||
this.$refs.selectPropDialog.open();
|
this.$refs.selectPropDialog.open();
|
||||||
} else {
|
} else {
|
||||||
this.saveCase();
|
this.saveCase(() => {
|
||||||
if (this.$refs.versionHistory) {
|
if (this.$refs.versionHistory) {
|
||||||
this.$refs.versionHistory.loading = false;
|
this.$refs.versionHistory.loading = false;
|
||||||
}
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this.$refs.versionHistory.loading = false;
|
this.$refs.versionHistory.loading = false;
|
||||||
|
@ -1111,9 +1115,6 @@ export default {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
changeType(type) {
|
|
||||||
this.type = type;
|
|
||||||
},
|
|
||||||
hasOtherInfo() {
|
hasOtherInfo() {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
if (this.form.id) {
|
if (this.form.id) {
|
||||||
|
|
Loading…
Reference in New Issue