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);