fix: 脑图修改用例等级不生效

This commit is contained in:
chenjianxing 2021-07-21 12:08:58 +08:00 committed by jianxing
parent 09e9b5b79d
commit 5178c5b457
1 changed files with 38 additions and 0 deletions

View File

@ -1243,6 +1243,18 @@ public class TestCaseService {
public void minderEdit(TestCaseMinderEditRequest request) {
List<TestCaseWithBLOBs> data = request.getData();
if (CollectionUtils.isEmpty(data)) {
return;
}
TestCaseExample example = new TestCaseExample();
List<String> 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> testCaseWithBLOBs = testCaseMapper.selectByExampleWithBLOBs(example);
Map<String, TestCaseWithBLOBs> testCaseMap = testCaseWithBLOBs.stream().collect(Collectors.toMap(TestCaseWithBLOBs::getId, t -> t));
data.forEach(item -> {
if (StringUtils.isBlank(item.getNodeId()) || item.getNodeId().equals("root")) {
item.setNodeId("");
@ -1253,6 +1265,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);
}
});
@ -1264,6 +1280,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<TestCase> getTestCaseByProjectId(String projectId) {
TestCaseExample example = new TestCaseExample();
example.createCriteria().andProjectIdEqualTo(projectId);