From 175bd760717be35d6caff9da9e7eb29e3a395b51 Mon Sep 17 00:00:00 2001 From: chenjianxing Date: Wed, 21 Jul 2021 12:08:58 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=84=91=E5=9B=BE=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E7=94=A8=E4=BE=8B=E7=AD=89=E7=BA=A7=E4=B8=8D=E7=94=9F=E6=95=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../track/service/TestCaseService.java | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) 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 69c02c0e30..1d7726b6f5 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestCaseService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestCaseService.java @@ -1205,6 +1205,18 @@ public class TestCaseService { public void minderEdit(TestCaseMinderEditRequest request) { List data = request.getData(); + if (CollectionUtils.isEmpty(data)) { + return; + } + + TestCaseExample example = new TestCaseExample(); + List editIds = data.stream() + .filter(t -> StringUtils.isNotBlank(t.getId()) && t.getId().length() > 20) + .map(TestCaseWithBLOBs::getId).collect(Collectors.toList()); + example.createCriteria().andIdIn(editIds); + List testCaseWithBLOBs = testCaseMapper.selectByExampleWithBLOBs(example); + Map testCaseMap = testCaseWithBLOBs.stream().collect(Collectors.toMap(TestCaseWithBLOBs::getId, t -> t)); + data.forEach(item -> { if (StringUtils.isBlank(item.getNodeId()) || item.getNodeId().equals("root")) { item.setNodeId(""); @@ -1215,6 +1227,10 @@ public class TestCaseService { item.setMaintainer(SessionUtils.getUserId()); addTestCase(item); } else { + TestCaseWithBLOBs dbCase = testCaseMap.get(item.getId()); + if (editCustomFieldsPriority(dbCase, item.getPriority())) { + item.setCustomFields(dbCase.getCustomFields()); + }; editTestCase(item); } }); @@ -1226,6 +1242,28 @@ public class TestCaseService { } } + /** + * 脑图编辑之后修改用例等级,同时修改自定义字段的用例等级 + * @param dbCase + * @param priority + * @return + */ + private boolean editCustomFieldsPriority(TestCaseWithBLOBs dbCase, String priority) { + String customFields = dbCase.getCustomFields(); + if (StringUtils.isNotBlank(customFields)) { + JSONArray fields = JSONObject.parseArray(customFields); + for (int i = 0; i < fields.size(); i++) { + JSONObject field = fields.getJSONObject(i); + if (field.getString("name").equals("用例等级")) { + field.put("value", priority); + dbCase.setCustomFields(JSONObject.toJSONString(fields)); + return true; + } + } + } + return false; + } + public List getTestCaseByProjectId(String projectId) { TestCaseExample example = new TestCaseExample(); example.createCriteria().andProjectIdEqualTo(projectId);