refactor(功能用例): 功能用例脑图模块更新同名检查

This commit is contained in:
guoyuqi 2024-06-13 17:21:55 +08:00 committed by Craftsman
parent 7d47d08c09
commit b523963553
1 changed files with 13 additions and 6 deletions

View File

@ -564,7 +564,7 @@ public class FunctionalCaseMinderService {
List<FunctionalCaseModule> modules = new ArrayList<>(); List<FunctionalCaseModule> modules = new ArrayList<>();
Map<String, List<FunctionalCaseModule>> parentModuleMap = getParentModuleMap(addList); Map<String, List<FunctionalCaseModule>> parentModuleMap = getParentModuleMap(addList);
for (FunctionalCaseModuleEditRequest functionalCaseModuleEditRequest : addList) { for (FunctionalCaseModuleEditRequest functionalCaseModuleEditRequest : addList) {
checkModules(functionalCaseModuleEditRequest, parentModuleMap); checkModules(functionalCaseModuleEditRequest, parentModuleMap, OperationLogType.ADD.toString());
FunctionalCaseModule functionalCaseModule = buildModule(request, userId, functionalCaseModuleEditRequest, moduleMapper); FunctionalCaseModule functionalCaseModule = buildModule(request, userId, functionalCaseModuleEditRequest, moduleMapper);
modules.add(functionalCaseModule); modules.add(functionalCaseModule);
newModuleMap.put(functionalCaseModuleEditRequest.getId(), functionalCaseModule.getId()); newModuleMap.put(functionalCaseModuleEditRequest.getId(), functionalCaseModule.getId());
@ -588,7 +588,7 @@ public class FunctionalCaseMinderService {
List<FunctionalCaseModule> modules = new ArrayList<>(); List<FunctionalCaseModule> modules = new ArrayList<>();
Map<String, List<FunctionalCaseModule>> parentModuleMap = getParentModuleMap(updateList); Map<String, List<FunctionalCaseModule>> parentModuleMap = getParentModuleMap(updateList);
for (FunctionalCaseModuleEditRequest functionalCaseModuleEditRequest : updateList) { for (FunctionalCaseModuleEditRequest functionalCaseModuleEditRequest : updateList) {
checkModules(functionalCaseModuleEditRequest, parentModuleMap); checkModules(functionalCaseModuleEditRequest, parentModuleMap, OperationLogType.UPDATE.toString());
FunctionalCaseModule updateModule = updateModule(userId, functionalCaseModuleEditRequest, moduleMapper); FunctionalCaseModule updateModule = updateModule(userId, functionalCaseModuleEditRequest, moduleMapper);
modules.add(updateModule); modules.add(updateModule);
reSetModuleMap(functionalCaseModuleEditRequest, parentModuleMap, updateModule); reSetModuleMap(functionalCaseModuleEditRequest, parentModuleMap, updateModule);
@ -630,14 +630,21 @@ public class FunctionalCaseMinderService {
} }
} }
private static void checkModules(FunctionalCaseModuleEditRequest functionalCaseModuleEditRequest, Map<String, List<FunctionalCaseModule>> parentModuleMap) { private static void checkModules(FunctionalCaseModuleEditRequest functionalCaseModuleEditRequest, Map<String, List<FunctionalCaseModule>> parentModuleMap, String type) {
List<FunctionalCaseModule> functionalCaseModules = parentModuleMap.get(functionalCaseModuleEditRequest.getParentId()); List<FunctionalCaseModule> functionalCaseModules = parentModuleMap.get(functionalCaseModuleEditRequest.getParentId());
if (CollectionUtils.isEmpty(functionalCaseModules)) { if (CollectionUtils.isEmpty(functionalCaseModules)) {
return; return;
} }
List<FunctionalCaseModule> sameNameList = functionalCaseModules.stream().filter(t -> StringUtils.equalsIgnoreCase(t.getName(), functionalCaseModuleEditRequest.getName())).toList(); if (StringUtils.equalsIgnoreCase(type, OperationLogType.ADD.toString())) {
if (CollectionUtils.isNotEmpty(sameNameList)) { List<FunctionalCaseModule> sameNameList = functionalCaseModules.stream().filter(t -> StringUtils.equalsIgnoreCase(t.getName(), functionalCaseModuleEditRequest.getName())).toList();
throw new MSException(Translator.get("node.name.repeat")); if (CollectionUtils.isNotEmpty(sameNameList)) {
throw new MSException(Translator.get("node.name.repeat"));
}
} else {
List<FunctionalCaseModule> sameNameList = functionalCaseModules.stream().filter(t -> StringUtils.equalsIgnoreCase(t.getName(), functionalCaseModuleEditRequest.getName()) && !StringUtils.equalsIgnoreCase(t.getId(), functionalCaseModuleEditRequest.getId())).toList();
if (CollectionUtils.isNotEmpty(sameNameList)) {
throw new MSException(Translator.get("node.name.repeat"));
}
} }
} }