From 7a6a5266784379f2afbb24cf456de162ee21bb5a Mon Sep 17 00:00:00 2001 From: shiziyuan9527 Date: Tue, 25 Jan 2022 14:19:19 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E5=8A=9F=E8=83=BD=E7=94=A8=E4=BE=8B):=20?= =?UTF-8?q?=E5=88=9B=E5=BB=BA=E5=85=B6=E4=BB=96=E7=89=88=E6=9C=AC=E7=94=A8?= =?UTF-8?q?=E4=BE=8B=EF=BC=8C=E6=8F=90=E7=A4=BAID=E5=B7=B2=E5=AD=98?= =?UTF-8?q?=E5=9C=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../track/service/TestCaseService.java | 21 +++++++++++++++++-- 1 file changed, 19 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 82d601f277..2956df6aea 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestCaseService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestCaseService.java @@ -251,11 +251,16 @@ public class TestCaseService { } private void checkCustomNumExist(TestCaseWithBLOBs testCase) { + String id = testCase.getId(); + TestCaseWithBLOBs testCaseWithBLOBs = testCaseMapper.selectByPrimaryKey(id); TestCaseExample example = new TestCaseExample(); - example.createCriteria() - .andCustomNumEqualTo(testCase.getCustomNum()) + TestCaseExample.Criteria criteria = example.createCriteria(); + criteria.andCustomNumEqualTo(testCase.getCustomNum()) .andProjectIdEqualTo(testCase.getProjectId()) .andIdNotEqualTo(testCase.getId()); + if (testCaseWithBLOBs != null && StringUtils.isNotBlank(testCaseWithBLOBs.getRefId())) { + criteria.andRefIdNotEqualTo(testCaseWithBLOBs.getRefId()); + } List list = testCaseMapper.selectByExample(example); if (CollectionUtils.isNotEmpty(list)) { MSException.throwException(Translator.get("custom_num_is_exist")); @@ -282,6 +287,18 @@ public class TestCaseService { example.getOredCriteria().get(0).andVersionIdEqualTo(testCase.getVersionId()); } createNewVersionOrNot(testCase, example); + + if (StringUtils.isNotBlank(testCase.getCustomNum()) && StringUtils.isNotBlank(testCase.getId())) { + TestCaseWithBLOBs caseWithBLOBs = testCaseMapper.selectByPrimaryKey(testCase.getId()); + if (caseWithBLOBs != null) { + example.clear(); + example.createCriteria().andRefIdEqualTo(caseWithBLOBs.getRefId()); + TestCaseWithBLOBs testCaseWithBLOBs = new TestCaseWithBLOBs(); + testCaseWithBLOBs.setCustomNum(testCase.getCustomNum()); + testCaseMapper.updateByExampleSelective(testCaseWithBLOBs, example); + } + } + testCase.setLatest(null); testCaseMapper.updateByPrimaryKeySelective(testCase); return testCaseMapper.selectByPrimaryKey(testCase.getId());