From f9c8316b1ad639ad108b6d470a27f4c7c6ac505f Mon Sep 17 00:00:00 2001 From: Xia Zekun Date: Fri, 22 Mar 2024 16:59:21 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dcode=E7=94=9F=E6=88=90?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../laws/labeldatabase/rule/LabelTreeRule.java | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/laws-modules/src/main/java/com/jero/modules/laws/labeldatabase/rule/LabelTreeRule.java b/laws-modules/src/main/java/com/jero/modules/laws/labeldatabase/rule/LabelTreeRule.java index 5b98ff9d..195e9642 100644 --- a/laws-modules/src/main/java/com/jero/modules/laws/labeldatabase/rule/LabelTreeRule.java +++ b/laws-modules/src/main/java/com/jero/modules/laws/labeldatabase/rule/LabelTreeRule.java @@ -4,16 +4,12 @@ import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.jero.common.handler.IFillRuleHandler; import com.jero.common.util.SpringContextUtils; -import com.jero.common.util.YouBianCodeUtil; import com.jero.modules.laws.labeldatabase.entity.LawsLabelDatabase; import com.jero.modules.laws.labeldatabase.service.ILawsLabelDatabaseService; -import com.jero.modules.laws.standard.entity.LawsTreeNode; -import com.jero.modules.laws.standard.service.ILawsTreeNodeService; import io.netty.util.internal.StringUtil; -import org.jetbrains.annotations.Nullable; -import java.util.ArrayList; import java.util.List; +import java.util.stream.Collectors; /** * @author: Mzaxd @@ -46,15 +42,23 @@ public class LabelTreeRule implements IFillRuleHandler { LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>(); lambdaQueryWrapper.isNull(LawsLabelDatabase::getParentId); childList = lawsLabelDatabaseService.list(lambdaQueryWrapper); - result = "tag" + (childList.size() + 1); + result = "tag" + getNextNum("tag", childList); } else { //有父级 LawsLabelDatabase childLabel = new LawsLabelDatabase(); childLabel.setParentId(parentId); childList = lawsLabelDatabaseService.getList(childLabel); - result = parentCode+"-"+(childList.size() + 1); + result = parentCode + "-" + getNextNum(parentCode + "-", childList); } return result; } + Integer getNextNum(String removeCode, List childList) { + if (childList.isEmpty()) return 1; + List numList = childList.stream().map(item -> { + String numStr = item.getCode().replace(removeCode, ""); + return Integer.parseInt(numStr); + }).sorted().collect(Collectors.toList()); + return numList.get(numList.size() - 1) + 1; + } }