findTeacherStudentByLesson();
}
diff --git a/spring-boot-demo-neo4j/src/main/java/com/xkcoding/neo4j/service/NeoService.java b/spring-boot-demo-neo4j/src/main/java/com/xkcoding/neo4j/service/NeoService.java
index 057b800..b0a04f3 100644
--- a/spring-boot-demo-neo4j/src/main/java/com/xkcoding/neo4j/service/NeoService.java
+++ b/spring-boot-demo-neo4j/src/main/java/com/xkcoding/neo4j/service/NeoService.java
@@ -3,11 +3,13 @@ package com.xkcoding.neo4j.service;
import cn.hutool.core.util.StrUtil;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
+import com.google.common.collect.Sets;
import com.xkcoding.neo4j.model.Class;
import com.xkcoding.neo4j.model.Lesson;
import com.xkcoding.neo4j.model.Student;
import com.xkcoding.neo4j.model.Teacher;
import com.xkcoding.neo4j.payload.ClassmateInfoGroupByLesson;
+import com.xkcoding.neo4j.payload.TeacherStudent;
import com.xkcoding.neo4j.repository.ClassRepository;
import com.xkcoding.neo4j.repository.LessonRepository;
import com.xkcoding.neo4j.repository.StudentRepository;
@@ -21,7 +23,7 @@ import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import java.util.Map;
-import java.util.stream.Collectors;
+import java.util.Set;
/**
*
@@ -163,4 +165,23 @@ public class NeoService {
return result;
}
+
+ /**
+ * 查询所有师生关系,包括班主任/学生,任课老师/学生
+ *
+ * @return 师生关系
+ */
+ public Map> findTeacherStudent() {
+ List teacherStudentByClass = studentRepo.findTeacherStudentByClass();
+ List teacherStudentByLesson = studentRepo.findTeacherStudentByLesson();
+ Map> result = Maps.newHashMap();
+
+ teacherStudentByClass.forEach(teacherStudent -> result.put(teacherStudent.getTeacherName(), Sets.newHashSet(teacherStudent
+ .getStudents())));
+
+ teacherStudentByLesson.forEach(teacherStudent -> result.put(teacherStudent.getTeacherName(), Sets.newHashSet(teacherStudent
+ .getStudents())));
+
+ return result;
+ }
}
diff --git a/spring-boot-demo-neo4j/src/test/java/com/xkcoding/neo4j/Neo4jTest.java b/spring-boot-demo-neo4j/src/test/java/com/xkcoding/neo4j/Neo4jTest.java
index da2af0d..9f4fed2 100644
--- a/spring-boot-demo-neo4j/src/test/java/com/xkcoding/neo4j/Neo4jTest.java
+++ b/spring-boot-demo-neo4j/src/test/java/com/xkcoding/neo4j/Neo4jTest.java
@@ -10,6 +10,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import java.util.stream.Collectors;
/**
@@ -79,4 +80,15 @@ public class Neo4jTest extends SpringBootDemoNeo4jApplicationTests {
.map(Student::getName)
.collect(Collectors.toList()))));
}
+
+ /**
+ * 查询所有师生关系,包括班主任/学生,任课老师/学生
+ */
+ @Test
+ public void testFindTeacherStudent() {
+ Map> teacherStudent = neoService.findTeacherStudent();
+ teacherStudent.forEach((k, v) -> log.info("【{}】教的学生有 {}", k, JSONUtil.toJsonStr(v.stream()
+ .map(Student::getName)
+ .collect(Collectors.toList()))));
+ }
}