refactor(测试跟踪): 优化批量删除公共用例库

This commit is contained in:
wxg0103 2022-05-14 11:55:03 +08:00 committed by f2c-ci-robot[bot]
parent e3c2ff9e10
commit 79e8101171
1 changed files with 25 additions and 2 deletions

View File

@ -2204,17 +2204,40 @@ public class TestCaseService {
ServiceUtils.getSelectAllIds(request, request.getCondition(),
(query) -> extTestCaseMapper.selectPublicIds(query));
List<String> ids = request.getIds();
List<String> needDelete = new ArrayList<>();
List<String> noDelete = new ArrayList<>();
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
TestCaseMapper mapper = sqlSession.getMapper(TestCaseMapper.class);
if (CollectionUtils.isNotEmpty(ids)) {
for (String id : ids) {
TestCase testCase = testCaseMapper.selectByPrimaryKey(id);
if ((StringUtils.isNotEmpty(testCase.getMaintainer()) && testCase.getMaintainer().equals(SessionUtils.getUserId())) ||
(StringUtils.isNotEmpty(testCase.getCreateUser()) && testCase.getCreateUser().equals(SessionUtils.getUserId()))) {
this.deleteTestCasePublic(null, testCase.getRefId());
needDelete.add(testCase.getRefId());
} else {
MSException.throwException(Translator.get("check_owner_case"));
noDelete.add(testCase.getName());
}
}
}
try {
if (CollectionUtils.isNotEmpty(needDelete)) {
for (int i = 0; i < needDelete.size(); i++) {
TestCaseExample e = new TestCaseExample();
e.createCriteria().andRefIdEqualTo(needDelete.get(i));
TestCaseWithBLOBs t = new TestCaseWithBLOBs();
t.setCasePublic(false);
mapper.updateByExampleSelective(t, e);
if (i % 50 == 0)
sqlSession.flushStatements();
}
sqlSession.flushStatements();
}
} finally {
SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory);
}
if (CollectionUtils.isNotEmpty(noDelete)) {
MSException.throwException(Translator.get("check_owner_case"));
}
}
public String getCaseLogDetails(TestCaseMinderEditRequest request) {