修复code生成问题

This commit is contained in:
Xia Zekun
2024-03-26 17:20:16 +08:00
committed by fengchenchen
parent 79900811fc
commit f9c8316b1a
@@ -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<LawsLabelDatabase> 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<LawsLabelDatabase> childList) {
if (childList.isEmpty()) return 1;
List<Integer> 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;
}
}