diff --git a/src/main/java/com/teaching/backend/controller/KnowGraph/KnowController.java b/src/main/java/com/teaching/backend/controller/KnowGraph/KnowController.java index 3d1625c..167e347 100644 --- a/src/main/java/com/teaching/backend/controller/KnowGraph/KnowController.java +++ b/src/main/java/com/teaching/backend/controller/KnowGraph/KnowController.java @@ -7,12 +7,10 @@ package com.teaching.backend.controller.KnowGraph; */ import com.teaching.backend.common.BaseResponse; import com.teaching.backend.common.ResultUtils; -import com.teaching.backend.model.dto.KnowGraph.BaseKnowReturn; -import com.teaching.backend.model.dto.KnowGraph.KnowRequest; -import com.teaching.backend.model.dto.KnowGraph.KnowUpdateRequest; -import com.teaching.backend.model.dto.KnowGraph.RelationshipKnowRequest; +import com.teaching.backend.model.dto.KnowGraph.*; import com.teaching.backend.model.entity.KnowGraph.Know; +import com.teaching.backend.model.entity.KnowGraph.KnowCourse; import com.teaching.backend.service.KnowGraph.KnowService; import org.springframework.web.bind.annotation.*; @@ -41,6 +39,12 @@ public class KnowController { return knowService.createKnow(knowRequest); } + //添加知识点 - 课程 + @PostMapping("/addKnowCourse") + public KnowCourse createCourseKnow(@RequestBody KnowCourseCreateRequest knowCourseCreateRequest) { + return knowService.createCourseKnow(knowCourseCreateRequest); + } + //修改知识点 @PostMapping ("/update") public Know updateKnow(@RequestBody KnowUpdateRequest knowUpdateRequest) { @@ -67,7 +71,7 @@ public class KnowController { } @GetMapping("/all") - public BaseResponse getKnowAll(@RequestParam Long id) { + public BaseResponse getKnowAll(@RequestParam String id) { BaseKnowReturn baseKnowReturn =knowService.getKnowAll(id); return ResultUtils.success(baseKnowReturn); } diff --git a/src/main/java/com/teaching/backend/mapper/KnowGraph/KnowRepository.java b/src/main/java/com/teaching/backend/mapper/KnowGraph/KnowRepository.java index ea96859..d26ff96 100644 --- a/src/main/java/com/teaching/backend/mapper/KnowGraph/KnowRepository.java +++ b/src/main/java/com/teaching/backend/mapper/KnowGraph/KnowRepository.java @@ -7,7 +7,9 @@ package com.teaching.backend.mapper.KnowGraph; */ +import com.teaching.backend.model.dto.KnowGraph.KnowCourseCreateRequest; import com.teaching.backend.model.entity.KnowGraph.Know; +import com.teaching.backend.model.entity.KnowGraph.KnowCourse; import org.springframework.data.neo4j.repository.Neo4jRepository; import org.springframework.data.neo4j.repository.query.Query; @@ -26,6 +28,9 @@ public interface KnowRepository extends Neo4jRepository { List queryKnowAllKnowById(Long id); + @Query("CREATE (n:Know {name: $name, courseId: $courseId,info:$info,resourceList:$resourceList}) return n") + KnowCourse createKnowCourse(String courseId, String name, String info, ListresourceList); + } diff --git a/src/main/java/com/teaching/backend/model/dto/KnowGraph/KnowCourseCreateRequest.java b/src/main/java/com/teaching/backend/model/dto/KnowGraph/KnowCourseCreateRequest.java new file mode 100644 index 0000000..6c71be0 --- /dev/null +++ b/src/main/java/com/teaching/backend/model/dto/KnowGraph/KnowCourseCreateRequest.java @@ -0,0 +1,38 @@ +package com.teaching.backend.model.dto.KnowGraph; + +import lombok.Data; +import org.springframework.data.neo4j.core.schema.Property; + +import java.io.Serializable; +import java.util.List; + +@Data +public class KnowCourseCreateRequest implements Serializable { + + /** + * 知识点名称 + */ + private String courseId; + + /** + * 知识点名称 + */ + private String name; + + /** + * 信息 + */ + + private String info; + + + + /** + * 知识点所关联的资源 + */ + @Property + private List resourceList; + + +} + diff --git a/src/main/java/com/teaching/backend/model/entity/KnowGraph/KnowCourse.java b/src/main/java/com/teaching/backend/model/entity/KnowGraph/KnowCourse.java new file mode 100644 index 0000000..587fb00 --- /dev/null +++ b/src/main/java/com/teaching/backend/model/entity/KnowGraph/KnowCourse.java @@ -0,0 +1,50 @@ +package com.teaching.backend.model.entity.KnowGraph; + +import lombok.Data; +import org.springframework.data.neo4j.core.schema.GeneratedValue; +import org.springframework.data.neo4j.core.schema.Id; +import org.springframework.data.neo4j.core.schema.Node; +import org.springframework.data.neo4j.core.schema.Property; + +import java.io.Serializable; +import java.util.List; + +@Node +@Data +public class KnowCourse implements Serializable { + + + /** + * id + */ + @Id + @GeneratedValue + private Long id; + + /** + * 知识点名称 + */ + private String courseId; + + + /** + * 知识点名称 + */ + @Property + private String name; + + /** + * 信息 + */ + @Property + private String info; + + + /** + * 知识点所关联的资源 + */ + @Property + private List resourceList; + +} + diff --git a/src/main/java/com/teaching/backend/model/vo/knowGraph/KnowVO.java b/src/main/java/com/teaching/backend/model/vo/knowGraph/KnowVO.java index 8ab5cc0..d6a60a2 100644 --- a/src/main/java/com/teaching/backend/model/vo/knowGraph/KnowVO.java +++ b/src/main/java/com/teaching/backend/model/vo/knowGraph/KnowVO.java @@ -24,13 +24,8 @@ public class KnowVO implements Serializable { /** * 信息 */ - private Long group; + private String color; - /** - * 知识点所关联的资源 - */ - private List resourceList; - } diff --git a/src/main/java/com/teaching/backend/service/KnowGraph/KnowService.java b/src/main/java/com/teaching/backend/service/KnowGraph/KnowService.java index 855fc65..03ae676 100644 --- a/src/main/java/com/teaching/backend/service/KnowGraph/KnowService.java +++ b/src/main/java/com/teaching/backend/service/KnowGraph/KnowService.java @@ -1,11 +1,9 @@ package com.teaching.backend.service.KnowGraph; import com.teaching.backend.mapper.KnowGraph.KnowRepository; -import com.teaching.backend.model.dto.KnowGraph.BaseKnowReturn; -import com.teaching.backend.model.dto.KnowGraph.KnowRequest; -import com.teaching.backend.model.dto.KnowGraph.KnowUpdateRequest; -import com.teaching.backend.model.dto.KnowGraph.RelationshipKnowRequest; +import com.teaching.backend.model.dto.KnowGraph.*; import com.teaching.backend.model.entity.KnowGraph.Know; +import com.teaching.backend.model.entity.KnowGraph.KnowCourse; import com.teaching.backend.model.entity.KnowGraph.Links; import com.teaching.backend.model.vo.knowGraph.KnowVO; import org.neo4j.driver.internal.InternalRelationship; @@ -46,6 +44,11 @@ public class KnowService { return knowRepository.save(know); } + public KnowCourse createCourseKnow(KnowCourseCreateRequest knowCourseCreateRequest ) { + return knowRepository.createKnowCourse(knowCourseCreateRequest.getCourseId(),knowCourseCreateRequest.getName(),knowCourseCreateRequest.getInfo(),knowCourseCreateRequest.getResourceList()); + + } + public void deleteKnow(Long id) { knowRepository.deleteById(id); @@ -67,9 +70,16 @@ public class KnowService { } - public BaseKnowReturn getKnowAll(Long id) { + public BaseKnowReturn getKnowAll(String id) { Collection> all = - neo4jClient.query( "match(n:Know)-[r*0..]->(p:Know) where ID(n) = "+id+" return n as `n`,r as `r`,p as `p`,length(r) as `d`").fetch().all(); + neo4jClient.query( "match(n:Know)-[r*0..]->(p:Know) where n.courseId = '"+id+"' return n as `n`,r as `r`,p as `p`,length(r) as `d`").fetch().all(); + + MapcolorChoose = new HashMap<>(); + String color[] = new String[10]; + String[] colorList = {"#91CC75", "#5470C6", "#FAC858", "#EE6666", "#73C0DE", "#EA7CCC", "#5577FF", "#5577FF", "#9DBFFF", "#78A7FF"}; + for (int i = 0; i < 10; i++) { + colorChoose.put((long) i,colorList[i]); + } Iterator> iterator = all.iterator(); Set knowList = new HashSet<>(); @@ -80,15 +90,17 @@ public class KnowService { int p = 0; while (iterator.hasNext()) { Map element = iterator.next(); - Long group = (Long) element.get("d"); knowVO = new KnowVO(); Node node1 = (Node) element.get("p"); + + Long group = (Long) element.get("d"); + knowVO.setColor(colorChoose.get(group)); + Long id1 = node1.id(); String name1 = node1.get("name").asString(); -// String info1 = node1.get("info").asString(); knowVO.setId(id1); knowVO.setLabel(name1); - knowVO.setGroup(group); + knowList.add(knowVO); node2 = (List) element.get("r"); @@ -112,6 +124,12 @@ public class KnowService { public BaseKnowReturn getKnowById(Long id) { Collection> all = neo4jClient.query( "match(n:Know)-[r*0..2]->(p:Know) where ID(n) = "+id+" return n as `n`,r as `r`,p as `p`,length(r) as `d`").fetch().all(); + MapcolorChoose = new HashMap<>(); + String color[] = new String[10]; + String[] colorList = {"#91CC75", "#5470C6", "#FAC858", "#EE6666", "#73C0DE", "#EA7CCC", "#5577FF", "#5577FF", "#9DBFFF", "#78A7FF"}; + for (int i = 0; i < 10; i++) { + colorChoose.put((long) i,colorList[i]); + } Iterator> iterator = all.iterator(); Set knowList = new HashSet<>(); @@ -123,15 +141,14 @@ public class KnowService { while (iterator.hasNext()) { Map element = iterator.next(); - Long group = (Long) element.get("d"); knowVO = new KnowVO(); Node node1 = (Node) element.get("p"); + Long group = (Long) element.get("d"); + knowVO.setColor(colorChoose.get(group)); Long id1 = node1.id(); String name1 = node1.get("name").asString(); -// String info1 = node1.get("info").asString(); knowVO.setId(id1); knowVO.setLabel(name1); - knowVO.setGroup(group); knowList.add(knowVO); node2 = (List) element.get("r");