名称重复验证bugfix

This commit is contained in:
yangsong 2023-10-10 10:52:24 +08:00
parent 353dd2fd1b
commit 9c7d91aced

View File

@ -168,7 +168,9 @@ public class SaasFeatureApplyDetailServiceImpl implements SaasFeatureApplyDetail
.eq(SaasFeatureApplyDetail::getIsDelete, TableIsDeleteEnum.NORMAL.value)
.inSql(SaasFeatureApplyDetail::getApplyId, "select a.id from saas_feature_apply a where a.is_delete = 0 and a.is_abort = 0")
.list().stream().collect(Collectors.groupingBy(SaasFeatureApplyDetail::getParentBusinessNo));
existDetails.forEach((k, v) -> parentBusinessCodeMap.merge(k, v, (l1, l2) -> {
Map<String, List<SaasFeatureApplyDetail>> existedParentBusinessCodeMap = new HashMap<>();
existDetails.forEach((k, v) -> existedParentBusinessCodeMap.merge(k, v, (l1, l2) -> {
l1.addAll(l2);
return l1;
}));
@ -177,15 +179,20 @@ public class SaasFeatureApplyDetailServiceImpl implements SaasFeatureApplyDetail
.collect(Collectors.groupingBy(SaasFeature::getParentBusinessNo, Collectors.mapping(e -> SaasFeatureApplyDetail.builder()
.featureName(e.getFeatureName())
.build(), Collectors.toList())));
existFeatures.forEach((k, v) -> parentBusinessCodeMap.merge(k, v, (l1, l2) -> {
existFeatures.forEach((k, v) -> existedParentBusinessCodeMap.merge(k, v, (l1, l2) -> {
l1.addAll(l2);
return l1;
}));
parentBusinessCodeMap.forEach((k, v) -> {
Map<String, List<SaasFeatureApplyDetail>> mapChildren = v.stream().collect(Collectors.groupingBy(SaasFeatureApplyDetail::getFeatureName));
Set<String> errorFeatureNames = mapChildren.entrySet().stream().filter(kv -> kv.getValue().size() > 1).map(Map.Entry::getKey).collect(Collectors.toSet());
if (CollectionUtils.isNotEmpty(errorFeatureNames)) {
throw new ServiceException(String.format("同一节点下权限点名称不能重复【%s】", String.join(",", errorFeatureNames)));
List<SaasFeatureApplyDetail> exists = existedParentBusinessCodeMap.get(k);
if (CollectionUtils.isEmpty(v) || CollectionUtils.isEmpty(exists)) {
return;
}
Set<String> submitFeatureNames = v.stream().map(SaasFeatureApplyDetail::getFeatureName).filter(StringUtils::isNotBlank).collect(Collectors.toSet());
Set<String> existFeatureNames = exists.stream().map(SaasFeatureApplyDetail::getFeatureName).filter(StringUtils::isNotBlank).collect(Collectors.toSet());
submitFeatureNames.retainAll(existFeatureNames);
if (CollectionUtils.isNotEmpty(submitFeatureNames)) {
throw new ServiceException(String.format("同一节点下权限点名称不能重复【%s】", String.join(",", submitFeatureNames)));
}
});
}
@ -208,7 +215,9 @@ public class SaasFeatureApplyDetailServiceImpl implements SaasFeatureApplyDetail
.eq(SaasFeatureApplyDetail::getIsDelete, TableIsDeleteEnum.NORMAL.value)
.inSql(SaasFeatureApplyDetail::getApplyId, "select a.id from saas_feature_apply a where a.is_delete = 0 and a.is_abort = 0")
.list().stream().collect(Collectors.groupingBy(SaasFeatureApplyDetail::getTerminal));
existDetails.forEach((k, v) -> parentTerminalMap.merge(k, v, (l1, l2) -> {
Map<String, List<SaasFeatureApplyDetail>> existedParentTerminalMap = new HashMap<>();
existDetails.forEach((k, v) -> existedParentTerminalMap.merge(k, v, (l1, l2) -> {
l1.addAll(l2);
return l1;
}));
@ -218,15 +227,20 @@ public class SaasFeatureApplyDetailServiceImpl implements SaasFeatureApplyDetail
.collect(Collectors.groupingBy(SaasFeature::getTerminal, Collectors.mapping(e -> SaasFeatureApplyDetail.builder()
.featureName(e.getFeatureName())
.build(), Collectors.toList())));
existFeatures.forEach((k, v) -> parentTerminalMap.merge(k, v, (l1, l2) -> {
existFeatures.forEach((k, v) -> existedParentTerminalMap.merge(k, v, (l1, l2) -> {
l1.addAll(l2);
return l1;
}));
parentTerminalMap.forEach((k, v) -> {
Map<String, List<SaasFeatureApplyDetail>> mapChildren = v.stream().collect(Collectors.groupingBy(SaasFeatureApplyDetail::getFeatureName));
Set<String> errorFeatureNames = mapChildren.entrySet().stream().filter(kv -> kv.getValue().size() > 1).map(Map.Entry::getKey).collect(Collectors.toSet());
if (CollectionUtils.isNotEmpty(errorFeatureNames)) {
throw new ServiceException(String.format("同一节点下权限点名称不能重复【%s】", String.join(",", errorFeatureNames)));
List<SaasFeatureApplyDetail> exists = existedParentTerminalMap.get(k);
if (CollectionUtils.isEmpty(v) || CollectionUtils.isEmpty(exists)) {
return;
}
Set<String> submitFeatureNames = v.stream().map(SaasFeatureApplyDetail::getFeatureName).filter(StringUtils::isNotBlank).collect(Collectors.toSet());
Set<String> existFeatureNames = exists.stream().map(SaasFeatureApplyDetail::getFeatureName).filter(StringUtils::isNotBlank).collect(Collectors.toSet());
submitFeatureNames.retainAll(existFeatureNames);
if (CollectionUtils.isNotEmpty(submitFeatureNames)) {
throw new ServiceException(String.format("同一节点下权限点名称不能重复【%s】", String.join(",", submitFeatureNames)));
}
});
}