diff --git a/backend/src/main/java/io/metersphere/track/service/TestCaseService.java b/backend/src/main/java/io/metersphere/track/service/TestCaseService.java index e0c466aa2c..f4f7c11cc5 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestCaseService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestCaseService.java @@ -2204,17 +2204,40 @@ public class TestCaseService { ServiceUtils.getSelectAllIds(request, request.getCondition(), (query) -> extTestCaseMapper.selectPublicIds(query)); List ids = request.getIds(); + List needDelete = new ArrayList<>(); + List 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) {