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