fix(测试跟踪): 导入更新时排除回收站的用例&回收站恢复操作添加自定义ID校验
--bug=1029871 --user=宋昌昌 【测试跟踪】github#26516,测试跟踪-导入用例新建415条,然后把用例全部删除,再次导入用例到列表有415条用例。然后修改本地用例导入更新用例就有830条了数据重复 https://www.tapd.cn/55049933/s/1413550
This commit is contained in:
parent
1a27672244
commit
54fd4446bf
|
@ -14,6 +14,7 @@ import io.metersphere.commons.constants.*;
|
|||
import io.metersphere.commons.exception.MSException;
|
||||
import io.metersphere.commons.utils.*;
|
||||
import io.metersphere.constants.AttachmentType;
|
||||
import io.metersphere.constants.DataStatus;
|
||||
import io.metersphere.constants.TestCaseTestType;
|
||||
import io.metersphere.dto.*;
|
||||
import io.metersphere.excel.constants.TestCaseImportFiled;
|
||||
|
@ -87,6 +88,7 @@ import java.util.stream.Collectors;
|
|||
@Service
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public class TestCaseService {
|
||||
|
||||
@Resource
|
||||
TestCaseNodeMapper testCaseNodeMapper;
|
||||
|
||||
|
@ -698,6 +700,8 @@ public class TestCaseService {
|
|||
TestCaseExample example = new TestCaseExample();
|
||||
TestCaseExample.Criteria criteria = example.createCriteria();
|
||||
if (null != id) {
|
||||
// 只校验未删除的用例
|
||||
criteria.andStatusNotEqualTo(DataStatus.TRASH.getValue());
|
||||
criteria.andCustomNumEqualTo(id);
|
||||
criteria.andProjectIdEqualTo(projectId);
|
||||
List<TestCase> testCaseList = testCaseMapper.selectByExample(example); //查询是否有包含此ID的数据
|
||||
|
@ -2699,13 +2703,14 @@ public class TestCaseService {
|
|||
ServiceUtils.getSelectAllIds(request, request.getCondition(), (query) -> extTestCaseMapper.selectIds(query));
|
||||
List<String> ids = request.getIds();
|
||||
if (CollectionUtils.isNotEmpty(ids)) {
|
||||
extTestCaseMapper.checkOriginalStatusByIds(ids);
|
||||
|
||||
//检查原来模块是否还在
|
||||
TestCaseExample example = new TestCaseExample();
|
||||
// 关联版本之后,必须查询每一个数据的所有版本,依次还原
|
||||
example.createCriteria().andIdIn(ids);
|
||||
List<TestCase> reductionCaseList = testCaseMapper.selectByExample(example);
|
||||
// 如果项目开启了用例自定义ID, 恢复的用例自定义ID不能重复
|
||||
checkReductionCaseCustomIdExist(request.getProjectId(), reductionCaseList);
|
||||
extTestCaseMapper.checkOriginalStatusByIds(ids);
|
||||
// 检查原来模块是否还在
|
||||
// 关联版本之后,必须查询每一个数据的所有版本,依次还原
|
||||
List<String> refIds = reductionCaseList.stream().map(TestCase::getRefId).collect(Collectors.toList());
|
||||
example.clear();
|
||||
example.createCriteria().andRefIdIn(refIds);
|
||||
|
@ -3450,4 +3455,28 @@ public class TestCaseService {
|
|||
public TestCaseWithBLOBs getSimpleCase(String testCaseId) {
|
||||
return testCaseMapper.selectByPrimaryKey(testCaseId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验恢复的用例集合是否自定义ID已存在(当所属项目的自定义ID开启时)
|
||||
*
|
||||
* @param projectId 所属项目ID
|
||||
* @param cases 用例集合
|
||||
*/
|
||||
public void checkReductionCaseCustomIdExist(String projectId, List<TestCase> cases) {
|
||||
Project project = baseProjectService.getProjectById(projectId);
|
||||
if (project != null) {
|
||||
ProjectConfig config = baseProjectApplicationService.getSpecificTypeValue(project.getId(), ProjectApplicationType.CASE_CUSTOM_NUM.name());
|
||||
boolean customNum = config.getCaseCustomNum();
|
||||
if (customNum) {
|
||||
// 项目开启自定义ID
|
||||
List<String> customNums = cases.stream().map(TestCase::getCustomNum).toList();
|
||||
TestCaseExample example = new TestCaseExample();
|
||||
example.createCriteria().andStatusNotEqualTo(DataStatus.TRASH.getValue()).andCustomNumIn(customNums).andProjectIdEqualTo(projectId);
|
||||
List<TestCase> noTrashCases = testCaseMapper.selectByExample(example);
|
||||
if (!noTrashCases.isEmpty()) {
|
||||
MSException.throwException(Translator.get("reduction_error_of_custom_id_exist"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -176,6 +176,7 @@ Swagger_parse_error=Swagger parsing failed, please confirm file format is correc
|
|||
Swagger_parse_error_with_auth=Swagger parsing failed. Please check whether authentication information is correct or file format is correct!
|
||||
test_track.length_less_than=The title is too long, the length must be less than
|
||||
edit_trash_case_error=The case has been put in trash, please recover before edit!
|
||||
reduction_error_of_custom_id_exist=Recovery failed, the selected use case custom ID already exists!
|
||||
# check owner
|
||||
check_owner_project=The current user does not have permission to operate this project
|
||||
check_owner_test=The current user does not have permission to operate this test
|
||||
|
|
|
@ -148,6 +148,7 @@ swagger_parse_error=Swagger 解析失败,请确认文件格式是否正确!
|
|||
swagger_parse_error_with_auth=Swagger 解析失败,请确认认证信息是否正确或文件格式是否正确!
|
||||
test_track.length_less_than=标题过长,字数必须小于
|
||||
edit_trash_case_error=用例已进入回收站, 请恢复后再编辑!
|
||||
reduction_error_of_custom_id_exist=恢复失败, 勾选用例自定义ID已存在!
|
||||
# check owner
|
||||
check_owner_project=当前用户没有操作此项目的权限
|
||||
check_owner_test=当前用户没有操作此测试的权限
|
||||
|
|
|
@ -148,6 +148,7 @@ swagger_parse_error=Swagger 解析失敗,請確認文件格式是否正確!
|
|||
swagger_parse_error_with_auth=Swagger 解析失敗,請確認認證信息是否正確或文件格式是否正確!
|
||||
test_track.length_less_than=標題過長,字數必須小於
|
||||
edit_trash_case_error=用例已進入回收站, 請恢復後再編輯!
|
||||
reduction_error_of_custom_id_exist=恢復失敗, 勾選用例自定義ID已存在!
|
||||
# check owner
|
||||
check_owner_project=當前用戶沒有操作此項目的權限
|
||||
check_owner_test=當前用戶沒有操作此測試的權限
|
||||
|
|
Loading…
Reference in New Issue