From 79e8101171b1ff27892f7f5d244a10427935820d Mon Sep 17 00:00:00 2001 From: wxg0103 <727495428@qq.com> Date: Sat, 14 May 2022 11:55:03 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E6=B5=8B=E8=AF=95=E8=B7=9F=E8=B8=AA):?= =?UTF-8?q?=20=E4=BC=98=E5=8C=96=E6=89=B9=E9=87=8F=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E5=85=AC=E5=85=B1=E7=94=A8=E4=BE=8B=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../track/service/TestCaseService.java | 27 +++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) 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) {