瀏覽代碼

知识点列表搜索

ywx
雍文秀 3 週之前
父節點
當前提交
3c1e1df12e
共有 1 個檔案被更改,包括 35 行新增3 行删除
  1. 35
    3
      sstudy/src/main/java/com/xhkjedu/sstudy/service/subjectbook/PointService.java

+ 35
- 3
sstudy/src/main/java/com/xhkjedu/sstudy/service/subjectbook/PointService.java 查看文件

@@ -9,8 +9,8 @@ import org.springframework.beans.factory.annotation.Autowired;
9 9
 import org.springframework.stereotype.Service;
10 10
 import org.springframework.transaction.annotation.Transactional;
11 11
 
12
-import java.util.ArrayList;
13
-import java.util.List;
12
+import java.util.*;
13
+import java.util.stream.Collectors;
14 14
 
15 15
 /**
16 16
  * @ClassName PointService
@@ -88,6 +88,21 @@ public class PointService {
88 88
     //获取科目下知识点数
89 89
     public List<TPoint> listPoints(TPoint point){
90 90
         List<TPoint> lst = pointMapper.listPoints(point);
91
+        String pointname = point.getPointname();
92
+        if (N_Utils.isNotEmpty(pointname)) {
93
+            List<TPoint> filterLst = lst.stream().filter(p -> p.getPointname().contains(pointname)).collect(Collectors.toList());
94
+            if (N_Utils.isListEmpty(filterLst)) {
95
+                return filterLst;
96
+            }
97
+            List<TPoint> parentPoints = new ArrayList<>();
98
+            for (TPoint p : filterLst) {
99
+                //查找所有父级知识点
100
+                parentPoints.addAll(getParentPoints(p, lst));
101
+            }
102
+            parentPoints.addAll(filterLst);
103
+            parentPoints = parentPoints.stream().distinct().collect(Collectors.toList());
104
+            lst = parentPoints;
105
+        }
91 106
 
92 107
         List<TPoint> points = new ArrayList<>();
93 108
         for (TPoint p:lst){
@@ -102,7 +117,24 @@ public class PointService {
102 117
         return points;
103 118
     }
104 119
 
105
-    //获取子知识点
120
+    //获取父级知识点
121
+    private List<TPoint> getParentPoints(TPoint p, List<TPoint> lst) {
122
+        List<TPoint> parentPoints = new ArrayList<>();
123
+        for (TPoint tPoint : lst) {
124
+            String pointpid = p.getPointpid();
125
+            if (N_Utils.isEmpty(pointpid)) continue;
126
+            if (tPoint.getPointid().equals(pointpid)) {
127
+                parentPoints.add(tPoint);
128
+                List<TPoint> parentPoints1 = getParentPoints(tPoint, lst);
129
+                parentPoints.addAll(parentPoints1);
130
+            }
131
+        }
132
+        return parentPoints;
133
+    }
134
+
135
+
136
+
137
+//获取子知识点
106 138
     private List<TPoint> listChildePoint(TPoint point,List<TPoint> points){
107 139
         List<TPoint> rtnPoints = new ArrayList<>();
108 140
         for(TPoint p : points){

Loading…
取消
儲存