diff --git a/src/main/java/com/biutag/supervision/service/RiskScoreRuleService.java b/src/main/java/com/biutag/supervision/service/RiskScoreRuleService.java index c37dbf0..402dd59 100644 --- a/src/main/java/com/biutag/supervision/service/RiskScoreRuleService.java +++ b/src/main/java/com/biutag/supervision/service/RiskScoreRuleService.java @@ -17,6 +17,8 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.function.Function; +import java.util.stream.Collectors; @RequiredArgsConstructor @Service @@ -31,33 +33,78 @@ public class RiskScoreRuleService extends ServiceImpl riskClasses = riskScoreRuleMapper.selectListAll(); List treeList = riskClasses.stream().filter(item -> item.getPid() != 0).toList(); List models = modelService.list(); - List list = new ArrayList<>(); - list.addAll(rootsList.stream().map(item -> { - RiskTree node = new RiskTree(); - node.setId(item.getId()); - node.setRiskName(item.getName()); - node.setSize(item.getSize()); - node.setType("modelClass"); - List children = models.stream().filter( - model -> { - for (RiskClassModel riskClassModel : treeList) { - boolean b = item.getId().equals(riskClassModel.getPid()) && riskClassModel.getId().equals(model.getRiskScoreRuleId()); - System.out.println("测试1当前item:【id:" + item.getId() + ",pid:" + item.getPid() - + "】,当前model:【id:" + model.getId() + ",risk_id:" + model.getRiskScoreRuleId() - + "】,当前riskClassModel:【id:" + riskClassModel.getId() + ",pid:" + riskClassModel.getPid() - + ",name:" + riskClassModel.getName() + ",size:" + riskClassModel.getSize()); - return b; - } - System.out.println("测试2当前item:【id:" + item.getId() + ",pid:" + item.getPid() - + "】,当前model:【id:" + model.getId() + ",risk_id:" + model.getRiskScoreRuleId() - + "】"); - return false; + + // id, root item根目录 + Map map = rootsList.stream().collect(Collectors.toMap(RiskClassModel::getId, Function.identity(), (newVal, oldVal) -> newVal)); + + // pid, treeList 子目录 + Map> treeMap = treeList.stream().collect(Collectors.groupingBy(RiskClassModel::getPid)); + +// Map> modelMap = models.stream().collect(Collectors.groupingBy(Model::getRiskScoreRuleId)); + + + // pid,子目录 + Map> rootChildren = new HashMap<>(); + for (Map.Entry> entry : treeMap.entrySet()) { + List trees = entry.getValue(); + List children = new ArrayList<>(); + for (RiskClassModel tree : trees) { + for (Model model : models) { + if (tree.getId().equals(model.getRiskScoreRuleId())) { + RiskTree node = new RiskTree(); + node.setId(model.getId()); + node.setRiskName(model.getModelName()); +// node.setSize(tree.getSize()); + node.setType("modelClass"); + children.add(node); } - ).map(RiskTree::of).toList(); - node.setChildren(children); - return node; - }).toList()); - return list; + } + } + rootChildren.put(entry.getKey(), children); + } + + List result = new ArrayList<>(); + for (Map.Entry map1 : map.entrySet()) { + Integer key = map1.getKey(); + RiskClassModel value = map1.getValue(); + if (rootChildren.containsKey(key)) { + RiskTree node = new RiskTree(); + node.setId(value.getId()); + node.setRiskName(value.getName()); + node.setSize(value.getSize()); + node.setType("modelClass"); + node.setChildren(rootChildren.get(key)); + result.add(node); + } + } + return result; +// List list = new ArrayList<>(); +// list.addAll(rootsList.stream().map(item -> { +// RiskTree node = new RiskTree(); +// node.setId(item.getId()); +// node.setRiskName(item.getName()); +// node.setSize(item.getSize()); +// node.setType("modelClass"); +// List children = models.stream().filter( +// model -> { +// for (RiskClassModel riskClassModel : treeList) { +// boolean b = item.getId().equals(riskClassModel.getPid()) && riskClassModel.getId().equals(model.getRiskScoreRuleId()); +// System.out.println("测试1当前item:【id:" + item.getId() + ",pid:" + item.getPid() +// + "】,当前model:【id:" + model.getId() + ",risk_id:" + model.getRiskScoreRuleId() +// + "】,当前riskClassModel:【id:" + riskClassModel.getId() + ",pid:" + riskClassModel.getPid() +// + ",name:" + riskClassModel.getName() + ",size:" + riskClassModel.getSize()); +// return b; +// } +// System.out.println("测试2当前item:【id:" + item.getId() + ",pid:" + item.getPid() +// + "】,当前model:【id:" + model.getId() + ",risk_id:" + model.getRiskScoreRuleId() +// + "】"); +// return false; +// } +// ).map(RiskTree::of).toList(); +// node.setChildren(children); +// return node; +// }).toList()); +// return list; } public List oldBuildTree() {