diff --git a/pom.xml b/pom.xml index af309d8..6fdc2db 100644 --- a/pom.xml +++ b/pom.xml @@ -30,6 +30,12 @@ commons-io 1.4 + + org.springframework + spring-test + 5.1.5.RELEASE + + diff --git a/src/main/java/com/teaching/backend/common/ErrorCode.java b/src/main/java/com/teaching/backend/common/ErrorCode.java index 6685de7..4b2a66e 100644 --- a/src/main/java/com/teaching/backend/common/ErrorCode.java +++ b/src/main/java/com/teaching/backend/common/ErrorCode.java @@ -27,6 +27,8 @@ public enum ErrorCode { CONTENT_EXISTS(41000, "内容存在"), KNOWS_EXISTS(41001, "存在关联的知识点"), + ADD_RELATION_FAILED(41002, "添加关系失败"), + FORBIDDEN_ERROR(40300, "禁止访问"), @@ -44,7 +46,10 @@ public enum ErrorCode { UPLOAD_FAILED(40006, "上传失败"), DELETE_RELATIONSHIP_FAILED(40006, "添加关系失败"), + + KNOW_EXISIT(40007, "课程已存在"), SYSTEM_ERROR(50000, "系统内部异常"), + FILE_ERROR(50010, "附件无效"), UNKNOW_ERROR(50002, "系统内部异常"), OPERATION_ERROR(50001, "操作失败"); 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 b29720e..261bf7b 100644 --- a/src/main/java/com/teaching/backend/controller/KnowGraph/KnowController.java +++ b/src/main/java/com/teaching/backend/controller/KnowGraph/KnowController.java @@ -6,17 +6,16 @@ package com.teaching.backend.controller.KnowGraph; * @Description: */ import com.teaching.backend.common.BaseResponse; -import com.teaching.backend.common.ResultUtils; -import com.teaching.backend.model.dto.KnowGraph.*; -import com.teaching.backend.model.dto.chapter.ChapterDTO; -import com.teaching.backend.model.dto.courses.CoursesDTO; -import com.teaching.backend.model.entity.KnowGraph.Know; -import com.teaching.backend.model.entity.KnowGraph.KnowChapter; -import com.teaching.backend.model.entity.KnowGraph.KnowCourse; -import com.teaching.backend.model.entity.chapter.Chapter; -import com.teaching.backend.model.entity.courses.Courses; +import com.teaching.backend.common.ResultUtils; +import com.teaching.backend.model.dto.KnowGraph.BaseKnowReturn; +import com.teaching.backend.model.dto.Knowtemp.KnowtempAdd; +import com.teaching.backend.model.dto.Knowtemp.KnowtempUpdate; +import com.teaching.backend.model.entity.Knowtemp.Knowtemp; +import com.teaching.backend.model.vo.knowGraph.KnowVO; +import com.teaching.backend.model.vo.knowGraph.KnowVO1; import com.teaching.backend.service.KnowGraph.KnowService; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import java.util.List; @@ -27,86 +26,38 @@ import java.util.Set; @RequestMapping("/know") public class KnowController { + @Autowired private KnowService knowService; - public KnowController(KnowService knowService) { - this.knowService = knowService; - } - - //根据 id查询所关联的所有结点 - @PostMapping ("/query/{id}") - public List queryKnowAllKnowById(@PathVariable Long id) { - return knowService.queryKnowAllKnowById(id); - } - - //添加知识点 + //根据 章节id 创建知识点到mysql中 @PostMapping("/add") - public BaseResponse createKnow(@RequestBody KnowRequest knowRequest) { - return knowService.createKnow(knowRequest); - } - //修改知识点 - @PostMapping ("/update") - public BaseResponse updateKnow(@RequestBody KnowUpdateRequest knowUpdateRequest) { - return knowService.updateKnow(knowUpdateRequest); - } - //删除知识点 - @GetMapping ("delete/{id}") - public BaseResponse deleteKnow(@PathVariable Long id) { - return knowService.deleteKnow(id); - } - - //添加知识点 - 课程 - @PostMapping("/add/KnowCourse") - public BaseResponse createCourseKnow(@RequestBody Courses courses) { - return knowService.createCourseKnow(courses); - } - - //修改知识点 - 课程 - @PostMapping("/update/KnowCourse") - public BaseResponse updateCourseKnow(@RequestBody Courses courses) { - return knowService.createCourseKnow(courses); - } - - //删除知识点 - 课程 - @PostMapping("/delete/KnowCourse") - public BaseResponse deleteCourseKnow(@RequestParam String courseId) { - return knowService.deleteCourseKnow(courseId); + public BaseResponse add(@RequestBody KnowtempAdd knowtempAdd) { + return knowService.add(knowtempAdd); } - //添加知识点 - 章节 - @PostMapping("/addKnowChapter") - public BaseResponse createKnowChapter(@RequestBody Chapter chapter) { - return knowService.createKnowChapter(chapter); + @PostMapping("/update") + public BaseResponse update(@RequestBody KnowtempUpdate knowtempUpdate) { + return knowService.update(knowtempUpdate); } - - //修改知识点 - 章节 - @PostMapping("/update/KnowChapter") - public BaseResponse updateKnowChapter(@RequestBody Chapter chapter) { - return knowService.updateKnowChapter(chapter); + @PostMapping("/delete") + public BaseResponse delete(@RequestParam Long id) { + return knowService.delete(id); } - //删除知识点 - 章节 - @PostMapping("/delete/KnowChapter") - public BaseResponse deleteKnowChapter(@RequestParam Long chapterId) { - return knowService.deleteKnowChapter(chapterId); + @PostMapping("/query") + public BaseResponse query(@RequestParam Long id) { + return knowService.query(id); } - @GetMapping("/KnowBychapterId") - public Set queryByChapterId(@RequestParam Long chapterId) { - return knowService.queryByChapterId(chapterId); + //根据 课程id 从chapter表中获取List 章节 + @PostMapping("/addAll") + public BaseResponse addAll(@RequestParam String id) { + return knowService.saveKnowToNeo(id); } - - - //添加知识点与知识点的关系 related - @PostMapping ("/addKnowRelatedKnow") - public BaseResponse addKnowRelatedKnow(@RequestBody RelationshipKnowRequest relationshipKnowRequest) { - return knowService.addKnowRelatedKnow(relationshipKnowRequest); - } - - //添加知识点与知识点的关系 fatherandSon - @PostMapping ("/addKnowFatherAndSonKnow") - public BaseResponse addKnowFatherAndSonKnow(@RequestBody RelationshipKnowRequest relationshipKnowRequest) { - return knowService.addKnowFatherAndSonKnow(relationshipKnowRequest); + // 改变节点关系 + @PostMapping("/update/relationship") + public BaseResponse updateRelationship(@RequestParam Long id, @RequestParam List ids, @RequestParam String relationship) { + return knowService.updateRelationship(id,ids,relationship); } //获取该节点下所有的节点 @@ -115,13 +66,99 @@ public class KnowController { BaseKnowReturn baseKnowReturn =knowService.getKnowAll(id); return ResultUtils.success(baseKnowReturn); } - - //返回该节点以及二级节点 - @GetMapping("/KnowById") - public BaseResponse getKnowById(@RequestParam Long id) { - BaseKnowReturn baseKnowReturn =knowService.getKnowById(id); - return ResultUtils.success(baseKnowReturn); - } + @GetMapping("/getAllByCourseId") + public BaseResponse> getKnowByCourseId(String id) { + return knowService.getKnowByCourseId(id); + } +// //根据 id查询所关联的所有结点 +// @PostMapping ("/query/{id}") +// public List queryKnowAllKnowById(@PathVariable Long id) { +// return knowService.queryKnowAllKnowById(id); +// } +// +// //添加知识点 +// @PostMapping("/add") +// public BaseResponse createKnow(@RequestBody KnowRequest knowRequest) { +// return knowService.createKnow(knowRequest); +// } +// //修改知识点 +// @PostMapping ("/update") +// public BaseResponse updateKnow(@RequestBody KnowUpdateRequest knowUpdateRequest) { +// return knowService.updateKnow(knowUpdateRequest); +// } +// //删除知识点 +// @GetMapping ("delete/{id}") +// public BaseResponse deleteKnow(@PathVariable Long id) { +// return knowService.deleteKnow(id); +// } +// +// //添加知识点 - 课程 +// @PostMapping("/add/KnowCourse") +// public BaseResponse createCourseKnow(@RequestBody Courses courses) { +// return knowService.createCourseKnow(courses); +// } +// +// //修改知识点 - 课程 +// @PostMapping("/update/KnowCourse") +// public BaseResponse updateCourseKnow(@RequestBody Courses courses) { +// return knowService.createCourseKnow(courses); +// } +// +// //删除知识点 - 课程 +// @PostMapping("/delete/KnowCourse") +// public BaseResponse deleteCourseKnow(@RequestParam String courseId) { +// return knowService.deleteCourseKnow(courseId); +// } +// +// //添加知识点 - 章节 +// @PostMapping("/addKnowChapter") +// public BaseResponse createKnowChapter(@RequestBody Chapter chapter) { +// return knowService.createKnowChapter(chapter); +// } +// +// //修改知识点 - 章节 +// @PostMapping("/update/KnowChapter") +// public BaseResponse updateKnowChapter(@RequestBody Chapter chapter) { +// return knowService.updateKnowChapter(chapter); +// } +// //删除知识点 - 章节 +// @PostMapping("/delete/KnowChapter") +// public BaseResponse deleteKnowChapter(@RequestParam Long chapterId) { +// return knowService.deleteKnowChapter(chapterId); +// } +// +// @GetMapping("/KnowBychapterId") +// public Set queryByChapterId(@RequestParam Long chapterId) { +// return knowService.queryByChapterId(chapterId); +// } +// +// +// +// //添加知识点与知识点的关系 related +// @PostMapping ("/addKnowRelatedKnow") +// public BaseResponse addKnowRelatedKnow(@RequestBody RelationshipKnowRequest relationshipKnowRequest) { +// return knowService.addKnowRelatedKnow(relationshipKnowRequest); +// } +// +// //添加知识点与知识点的关系 fatherandSon +// @PostMapping ("/addKnowFatherAndSonKnow") +// public BaseResponse addKnowFatherAndSonKnow(@RequestBody RelationshipKnowRequest relationshipKnowRequest) { +// return knowService.addKnowFatherAndSonKnow(relationshipKnowRequest); +// } +// +// //获取该节点下所有的节点 +// @GetMapping("/all") +// public BaseResponse getKnowAll(@RequestParam String id) { +// BaseKnowReturn baseKnowReturn =knowService.getKnowAll(id); +// return ResultUtils.success(baseKnowReturn); +// } +// +// //返回该节点以及二级节点 +// @GetMapping("/KnowById") +// public BaseResponse getKnowById(@RequestParam Long id) { +// BaseKnowReturn baseKnowReturn =knowService.getKnowById(id); +// return ResultUtils.success(baseKnowReturn); +// } } diff --git a/src/main/java/com/teaching/backend/controller/KnowGraph/KnowGraphController.java b/src/main/java/com/teaching/backend/controller/KnowGraph/KnowGraphController.java new file mode 100644 index 0000000..dcbc2d8 --- /dev/null +++ b/src/main/java/com/teaching/backend/controller/KnowGraph/KnowGraphController.java @@ -0,0 +1,56 @@ +//package com.teaching.backend.controller.KnowGraph; +// +//import com.teaching.backend.common.BaseResponse; +//import com.teaching.backend.model.dto.Knowtemp.KnowtempAdd; +//import com.teaching.backend.model.dto.Knowtemp.KnowtempUpdate; +//import com.teaching.backend.model.entity.KnowGraph.Know; +//import com.teaching.backend.model.entity.Knowtemp.Knowtemp; +//import com.teaching.backend.model.entity.chapter.Chapter; +//import com.teaching.backend.service.KnowGraph.KnowGraphService; +//import io.swagger.models.auth.In; +//import org.springframework.beans.factory.annotation.Autowired; +//import org.springframework.web.bind.annotation.*; +// +//import java.util.List; +// +///** +// * @Author:youhang +// * @Date:2024-07-29-10:32 +// * @Description: +// */ +//@RestController +//@RequestMapping("/knowGraph") +//public class KnowGraphController { +// +// @Autowired +// private KnowGraphService knowGraphService; +// +// //add knowtemp +// @PostMapping("/add") +// public BaseResponse add(@RequestBody KnowtempAdd knowtempAdd) { +// return knowGraphService.add(knowtempAdd); +// } +// +// @PostMapping("/update") +// public BaseResponse update(@RequestBody KnowtempUpdate knowtempUpdate) { +// return knowGraphService.update(knowtempUpdate); +// } +// @PostMapping("/delete") +// public BaseResponse delete(@RequestParam Integer id) { +// return knowGraphService.delete(id); +// } +// @PostMapping("/query") +// public BaseResponse query(@RequestParam Integer id) { +// return knowGraphService.query(id); +// } +// +// +// //根据 课程id 从chapter表中获取List 章节 +// @PostMapping("/addAll") +// public BaseResponse addAll(@PathVariable String id) { +// return knowGraphService.saveKnowToNeo(id); +// } +// +// +// +//} diff --git a/src/main/java/com/teaching/backend/controller/KnowGraph/ResourcesController.java b/src/main/java/com/teaching/backend/controller/KnowGraph/ResourcesController.java index 9892f91..f8411eb 100644 --- a/src/main/java/com/teaching/backend/controller/KnowGraph/ResourcesController.java +++ b/src/main/java/com/teaching/backend/controller/KnowGraph/ResourcesController.java @@ -14,6 +14,7 @@ import com.teaching.backend.model.entity.KnowGraph.Know; import com.teaching.backend.model.entity.KnowGraph.Resources; import com.teaching.backend.service.KnowGraph.ResourcesService; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; @@ -27,10 +28,8 @@ import java.util.Set; @RequestMapping("/resources") public class ResourcesController { + @Autowired private ResourcesService resourcesService; - public ResourcesController(ResourcesService resourcesService) { - this.resourcesService = resourcesService; - } //添加知识点 @PostMapping("/upload") @@ -70,7 +69,7 @@ public class ResourcesController { resourcesService.deleteResources(id); } - //添加知识点与知识点的关系 related + //添加知识点与资源的关系 @PostMapping ("/addKnowResourcesResources") public void addKnowWithResource(@RequestBody RelationshipResourceRequest relationshipResourceRequest) { resourcesService.addKnowWithResources(relationshipResourceRequest); @@ -82,7 +81,7 @@ public class ResourcesController { } @GetMapping ("queryBesidesKnowToResources/{KnowId}") - public Set queryBesidesKnowToResources(@PathVariable Long KnowId) { + public List queryBesidesKnowToResources(@PathVariable Long KnowId) { return resourcesService.queryBesidesKnowToResources(KnowId); } diff --git a/src/main/java/com/teaching/backend/controller/resource/ResourceController.java b/src/main/java/com/teaching/backend/controller/resource/ResourceController.java index a9c9dec..16102ee 100644 --- a/src/main/java/com/teaching/backend/controller/resource/ResourceController.java +++ b/src/main/java/com/teaching/backend/controller/resource/ResourceController.java @@ -5,6 +5,7 @@ import com.teaching.backend.common.ResultUtils; import com.teaching.backend.service.KnowGraph.ResourcesService; import com.teaching.backend.service.resource.ResourceService; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; @@ -25,14 +26,13 @@ import java.io.*; @RequestMapping("/resource") public class ResourceController { - - private ResourceService resourceService; + @Autowired + private ResourcesService resourcesService; //添加知识点 @PostMapping("/upload") - public String uploadFile(@RequestParam("file")MultipartFile file) { - System.out.println(file.getOriginalFilename()); - return resourceService.upload(file); + public BaseResponse uploadFile(@RequestParam("file")MultipartFile file) { + return resourcesService.uploadFile(file); } 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 7483a9c..cbfbcf6 100644 --- a/src/main/java/com/teaching/backend/mapper/KnowGraph/KnowRepository.java +++ b/src/main/java/com/teaching/backend/mapper/KnowGraph/KnowRepository.java @@ -23,8 +23,6 @@ public interface KnowRepository extends Neo4jRepository { @Query("MATCH (p:Know) where ID(p) = $id RETURN count(p);") Boolean deleteKnow(Long id); - @Query("MATCH (p:Know), (c:Know) WHERE ID(p) = $id AND ID(c) IN $KnowIds CREATE (p)-[r:related]->(c),(c)-[:related]->(p) return count(r)") - int addKnowRelatedKnow(Long id, List KnowIds); @Query("MATCH (p:Know), (c:Know) WHERE ID(p) = $id AND ID(c) IN $KnowIds CREATE (p)-[r:FatherAndSon]->(c) return r") int addKnowFatherAndSonKnow(Long id, List KnowIds); @@ -33,8 +31,8 @@ public interface KnowRepository extends Neo4jRepository { List queryKnowAllKnowById(Long id); - @Query("CREATE (n:Know {name: $name, courseId: $courseId,info:$info}) return n") - KnowCourse createKnowCourse(String courseId, String name, String info); + @Query("CREATE (n:Know {name: $name, courseId: $courseId,info:$info}) return count(n)") + int createKnowCourse(String courseId, String name, String info); @Query("MATCH (p:Know {courseId:$courseId }) SET p.name = $name set p.info= $info RETURN p;") Boolean updateKnowCourse(String courseId, String name, String info); @@ -43,7 +41,7 @@ public interface KnowRepository extends Neo4jRepository { Boolean deleteKnowCourse(String courseId); @Query("CREATE (n:Know {name: $name, chapterId: $chapterId,info:$info}) return count(n)") - KnowChapter createKnowChapter(Long chapterId, String name, String info); + int createKnowChapter(Long chapterId, String name, String info); @Query("MATCH (p:Know {chapterId:$chapterId }) SET p.name = $name set p.info= $info RETURN p;") Boolean updateKnowChapter(Long chapterId, String name, String info); @@ -54,4 +52,27 @@ public interface KnowRepository extends Neo4jRepository { @Query("MATCH(n:Know)-[r:FatherAndSon*]->(nn:Know) where n.chapterId = $chapterId RETURN nn") Set queryByChapterId(Long chapterId); + + //在章节表里面添加章与课程的关系 + @Query("MATCH (p:Know), (c:Know) WHERE p.courseId = $courseId AND c.chapterId = $ChapterId CREATE (p)-[r:FatherAndSon]->(c) return count(r)") + int addChapterAndCourse(String courseId, Long ChapterId); + + //添加章与节的关系 + @Query("MATCH (p:Know), (c:Know) WHERE p.chapterId = $ChapterId1 AND c.chapterId = $ChapterId2 CREATE (p)-[r:FatherAndSon]->(c) return count(r)") + int addChapterAndCourse( Long ChapterId1, Long ChapterId2); + + //创造知识点并,添加节与知识点的关系 + @Query("MATCH (p:Know) WHERE p.chapterId = $ChapterId CREATE (c:Know{name:$name,info:$info}),(p)-[r:FatherAndSon]->(c) return count(r)") + int CreateKnowaddChapter( Long ChapterId, String name,String info); + + @Query("MATCH (p:Know), (c:Know) WHERE ID(p) = $id AND ID(c) IN $KnowIds CREATE (p)-[r:FatherAndSon]->(c),(c)-[:related]->(p) return count(r)") + int addKnowWithFaherAndSon(Long id, List KnowIds); + + @Query("MATCH (p:Know), (c:Know) WHERE ID(p) = $id AND ID(c) IN $KnowIds CREATE (p)-[r:related]->(c),(c)-[:related]->(p) return count(r)") + int addKnowWithRelated(Long id, List KnowIds); + + @Query("MATCH (p:Know), (c:Know) WHERE ID(p) = $id AND ID(c) IN $KnowIds CREATE (p)-[r:PreCondition]->(c),(c)-[:related]->(p) return count(r)") + int addKnowWithPreCondition(Long id, List KnowIds); + + } diff --git a/src/main/java/com/teaching/backend/mapper/KnowGraph/ResourcesRepository.java b/src/main/java/com/teaching/backend/mapper/KnowGraph/ResourcesRepository.java index 98de5e8..b4609af 100644 --- a/src/main/java/com/teaching/backend/mapper/KnowGraph/ResourcesRepository.java +++ b/src/main/java/com/teaching/backend/mapper/KnowGraph/ResourcesRepository.java @@ -21,11 +21,11 @@ public interface ResourcesRepository extends Neo4jRepository { @Query("MATCH(n:Resources) where n.resourcesId = $resourcesId RETURN n") - Resources queryResources(String resourcesId); + Resources queryResources(Long resourcesId); @Query("MATCH (p:Know), (c:Resources) WHERE ID(p) = $id AND ID(c) in $ResourcesIds CREATE (p)-[r:resources]->(c)") - void addResourceRelatedKnow(Long id, List ResourcesIds); + void addResourceResourcesKnow(Long id, List ResourcesIds); @Query("MATCH(n:Know)-[r:resources]->(nn:Resources) where ID(nn) = $id RETURN nn") @@ -34,9 +34,10 @@ public interface ResourcesRepository extends Neo4jRepository { @Query("MATCH p = (a:Know)-[rels*]-(b:Resources) WHERE ID(a) = $KnowId and ANY(rel IN rels WHERE TYPE(rel) = 'resources') RETURN b") Set queryCourseKnowToResources(Long KnowId); - @Query(" MATCH (p:Know)-[:FatherAndSon]->(n:Know)-[:resources]->(m:Resources) WHERE ID(p) = $KnowId RETURN m") + @Query("MATCH (p:Know)-[:FatherAndSon]->(n:Know)-[:resources]->(m:Resources) WHERE ID(p) = $KnowId RETURN m") Set queryBesidesKnowToResources(Long KnowId); - + @Query(" MATCH (p:Know)-[:resources]->(m:Resources) WHERE ID(p) = 272 RETURN m") + Set queryKnowToResources(Long KnowId); } diff --git a/src/main/java/com/teaching/backend/mapper/Knowtemp/KnowtempMapper.java b/src/main/java/com/teaching/backend/mapper/Knowtemp/KnowtempMapper.java new file mode 100644 index 0000000..38c1cab --- /dev/null +++ b/src/main/java/com/teaching/backend/mapper/Knowtemp/KnowtempMapper.java @@ -0,0 +1,15 @@ +package com.teaching.backend.mapper.Knowtemp; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.teaching.backend.model.entity.Knowtemp.Knowtemp; + +/** + * 课程点赞数据库操作 + */ +public interface KnowtempMapper extends BaseMapper { + +} + + + + diff --git a/src/main/java/com/teaching/backend/model/dto/KnowGraph/ResourceUpdateRequest.java b/src/main/java/com/teaching/backend/model/dto/KnowGraph/ResourceUpdateRequest.java index 7404cee..4775269 100644 --- a/src/main/java/com/teaching/backend/model/dto/KnowGraph/ResourceUpdateRequest.java +++ b/src/main/java/com/teaching/backend/model/dto/KnowGraph/ResourceUpdateRequest.java @@ -12,7 +12,7 @@ public class ResourceUpdateRequest { private Long id; - private String resourceId; + private String name; private Integer type; diff --git a/src/main/java/com/teaching/backend/model/dto/KnowGraph/ResourcesAddRequest.java b/src/main/java/com/teaching/backend/model/dto/KnowGraph/ResourcesAddRequest.java index 14bf6ec..32b408d 100644 --- a/src/main/java/com/teaching/backend/model/dto/KnowGraph/ResourcesAddRequest.java +++ b/src/main/java/com/teaching/backend/model/dto/KnowGraph/ResourcesAddRequest.java @@ -11,8 +11,6 @@ import org.springframework.data.neo4j.core.schema.Property; @Data public class ResourcesAddRequest { - private String resourcesId; - private String name; private Integer type; diff --git a/src/main/java/com/teaching/backend/model/dto/Knowtemp/KnowtempAdd.java b/src/main/java/com/teaching/backend/model/dto/Knowtemp/KnowtempAdd.java new file mode 100644 index 0000000..953db74 --- /dev/null +++ b/src/main/java/com/teaching/backend/model/dto/Knowtemp/KnowtempAdd.java @@ -0,0 +1,32 @@ +package com.teaching.backend.model.dto.Knowtemp; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import lombok.Data; + +import java.io.Serializable; + +/** + *

+ * + *

+ * + * @author author + * @since 2024-05-31 + */ +@Data +public class KnowtempAdd implements Serializable { + + private String name; + + private String info; + + private Long chapterid; + + private String courseid; + + private Integer ordernum; + + +} diff --git a/src/main/java/com/teaching/backend/model/dto/Knowtemp/KnowtempUpdate.java b/src/main/java/com/teaching/backend/model/dto/Knowtemp/KnowtempUpdate.java new file mode 100644 index 0000000..427aa4b --- /dev/null +++ b/src/main/java/com/teaching/backend/model/dto/Knowtemp/KnowtempUpdate.java @@ -0,0 +1,32 @@ +package com.teaching.backend.model.dto.Knowtemp; + +import io.swagger.models.auth.In; +import lombok.Data; + +import java.io.Serializable; + +/** + *

+ * + *

+ * + * @author author + * @since 2024-05-31 + */ +@Data +public class KnowtempUpdate implements Serializable { + + private Long id; + + private String name; + + private String info; + + private Long chapterid; + private String courseid; + + + private Integer ordernum; + + +} diff --git a/src/main/java/com/teaching/backend/model/entity/KnowGraph/Resources.java b/src/main/java/com/teaching/backend/model/entity/KnowGraph/Resources.java index 2f8ada6..bacbe59 100644 --- a/src/main/java/com/teaching/backend/model/entity/KnowGraph/Resources.java +++ b/src/main/java/com/teaching/backend/model/entity/KnowGraph/Resources.java @@ -18,8 +18,6 @@ public class Resources { @GeneratedValue private Long id; - @Property - private String resourcesId; @Property private String name; diff --git a/src/main/java/com/teaching/backend/model/entity/Knowtemp/Knowtemp.java b/src/main/java/com/teaching/backend/model/entity/Knowtemp/Knowtemp.java new file mode 100644 index 0000000..4538b48 --- /dev/null +++ b/src/main/java/com/teaching/backend/model/entity/Knowtemp/Knowtemp.java @@ -0,0 +1,42 @@ +package com.teaching.backend.model.entity.Knowtemp; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import io.swagger.models.auth.In; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.experimental.Accessors; + +import java.io.Serializable; + +/** + *

+ * + *

+ * + * @author author + * @since 2024-05-31 + */ +@Data +public class Knowtemp implements Serializable { + + @TableField(exist = false) + private static final long serialVersionUID = 1L; + + @TableId(type = IdType.AUTO) + private Long id; + + private String name; + + private String info; + + private Integer ordernum; + + private Long chapterid; + + private String courseid; + + +} diff --git a/src/main/java/com/teaching/backend/model/entity/chapter/Chapter.java b/src/main/java/com/teaching/backend/model/entity/chapter/Chapter.java index e70465a..e03dfdf 100644 --- a/src/main/java/com/teaching/backend/model/entity/chapter/Chapter.java +++ b/src/main/java/com/teaching/backend/model/entity/chapter/Chapter.java @@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; import com.teaching.backend.model.entity.KnowGraph.Know; +import com.teaching.backend.model.entity.Knowtemp.Knowtemp; import io.swagger.annotations.ApiModelProperty; import lombok.Data; import lombok.EqualsAndHashCode; @@ -59,7 +60,7 @@ public class Chapter implements Serializable { private String content; @ApiModelProperty(value = "父级节点") - private String pid; + private Long pid; @ApiModelProperty(value = "课程") @@ -89,7 +90,7 @@ public class Chapter implements Serializable { @ApiModelProperty(value = "知识点") @TableField(exist = false) - private List knowledgePoints; // 用于存储章节下的知识点 + private List knowledgePoints; // 用于存储章节下的知识点 } diff --git a/src/main/java/com/teaching/backend/model/vo/knowGraph/KnowVO1.java b/src/main/java/com/teaching/backend/model/vo/knowGraph/KnowVO1.java new file mode 100644 index 0000000..98f53cf --- /dev/null +++ b/src/main/java/com/teaching/backend/model/vo/knowGraph/KnowVO1.java @@ -0,0 +1,25 @@ +package com.teaching.backend.model.vo.knowGraph; + +import lombok.Data; + +import java.io.Serializable; + + +@Data +public class KnowVO1 implements Serializable { + + + /** + * id + */ + private Long id; + + + /** + * 知识点名称 + */ + private String label; + + +} + diff --git a/src/main/java/com/teaching/backend/service/KnowGraph/KnowGraphService.java b/src/main/java/com/teaching/backend/service/KnowGraph/KnowGraphService.java new file mode 100644 index 0000000..8797762 --- /dev/null +++ b/src/main/java/com/teaching/backend/service/KnowGraph/KnowGraphService.java @@ -0,0 +1,138 @@ +//package com.teaching.backend.service.KnowGraph; +// +//import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +//import com.teaching.backend.common.BaseResponse; +//import com.teaching.backend.common.ErrorCode; +//import com.teaching.backend.common.ResultUtils; +//import com.teaching.backend.mapper.KnowGraph.KnowRepository; +//import com.teaching.backend.mapper.Knowtemp.KnowtempMapper; +//import com.teaching.backend.mapper.chapter.ChapterMapper; +//import com.teaching.backend.mapper.courses.CoursesMapper; +//import com.teaching.backend.model.dto.Knowtemp.KnowtempAdd; +//import com.teaching.backend.model.dto.Knowtemp.KnowtempUpdate; +//import com.teaching.backend.model.entity.KnowGraph.Know; +//import com.teaching.backend.model.entity.Knowtemp.Knowtemp; +//import com.teaching.backend.model.entity.chapter.Chapter; +//import com.teaching.backend.model.entity.courses.Courses; +//import org.springframework.beans.factory.annotation.Autowired; +//import org.springframework.stereotype.Service; +// +//import java.time.LocalDateTime; +//import java.util.ArrayList; +//import java.util.List; +// +///** +// * @Author:youhang +// * @Date:2024-07-29-10:33 +// * @Description: +// */ +//@Service +//public class KnowGraphService { +// +// @Autowired +// private ChapterMapper chapterMapper; +// +// @Autowired +// private KnowtempMapper knowtempMapper; +// +// @Autowired +// private CoursesMapper coursesMapper; +// +// @Autowired +// private KnowRepository knowRepository; +// +// public BaseResponse add(KnowtempAdd knowtempAdd){ +// String name = knowtempAdd.getName(); +// String info = knowtempAdd.getInfo(); +// Integer chapterId = knowtempAdd.getChapterId(); +// +// Knowtemp knowtemp = new Knowtemp(); +// knowtemp.setName(name); +// knowtemp.setInfo(info); +// knowtemp.setChapterId(chapterId); +// int insert = knowtempMapper.insert(knowtemp); +// if(insert > 0){ +// return ResultUtils.success("添加成功"); +// } +// return ResultUtils.error(ErrorCode.OPERATION_ERROR); +// } +// +//// public BaseResponse update(KnowtempUpdate knowtempUpdate){ +//// Integer id = knowtempUpdate.getId(); +//// String name = knowtempUpdate.getName(); +//// String info = knowtempUpdate.getInfo(); +//// Integer chapterId = knowtempUpdate.getChapterId(); +//// Knowtemp knowtemp = new Knowtemp(); +//// knowtemp = knowtempMapper.selectById(id); +//// if(knowtemp == null){ +//// return ResultUtils.error(ErrorCode.NOT_FOUND_ERROR); +//// } +//// knowtemp.setName(name); +//// knowtemp.setInfo(info); +//// knowtemp.setChapterId(chapterId); +//// int insert = knowtempMapper.updateById(knowtemp); +//// if(insert > 0){ +//// return ResultUtils.success("修改成功"); +//// } +//// return ResultUtils.error(ErrorCode.OPERATION_ERROR); +//// } +//// +//// public BaseResponse delete(Integer id){ +//// Knowtemp knowtemp = new Knowtemp(); +//// knowtemp = knowtempMapper.selectById(id); +//// if(knowtemp == null){ +//// return ResultUtils.error(ErrorCode.NOT_FOUND_ERROR); +//// } +//// int insert = knowtempMapper.deleteById(id); +//// if(insert > 0){ +//// return ResultUtils.success("删除成功"); +//// } +//// return ResultUtils.error(ErrorCode.OPERATION_ERROR); +//// } +//// +//// public BaseResponse query(Integer id){ +//// Knowtemp knowtemp = new Knowtemp(); +//// knowtemp = knowtempMapper.selectById(id); +//// if(knowtemp != null){ +//// return ResultUtils.success(knowtemp); +//// } +//// return ResultUtils.error(ErrorCode.NOT_FOUND_ERROR); +//// } +// +// +//// public BaseResponse saveKnowToNeo(String id) { +//// Courses courses = coursesMapper.selectById(id); +//// int f = knowRepository.createKnowCourse(courses.getId(),courses.getName(),courses.getDescription()); +//// if(f <= 0)return ResultUtils.error(ErrorCode.OPERATION_ERROR); +//// +//// List chapterList = chapterMapper.selectSectionsByCourseId(id); +//// for (int i = 0; i < chapterList.size(); i++) { +//// Chapter chapter = chapterList.get(i); +//// f = knowRepository.createKnowChapter(chapter.getId(),chapter.getName(),chapter.getContent()); +//// if(f <= 0)return ResultUtils.error(ErrorCode.OPERATION_ERROR); +//// } +//// for (int i = 0; i < chapterList.size(); i++) { +//// Chapter chapter = chapterList.get(i); +//// if("".equals(chapter.getPid())){ +//// f = knowRepository.addCourseFatherAndSonKnow(chapter.getCourseId(),chapter.getId()); +//// if(f <= 0)return ResultUtils.error(ErrorCode.OPERATION_ERROR); +//// }else{ +//// f = knowRepository.addChapterFatherAndSonKnow(chapter.getPid(),chapter.getId()); +//// if(f <= 0)return ResultUtils.error(ErrorCode.OPERATION_ERROR); +//// } +//// +//// } +//// QueryWrapper queryWrapper = new QueryWrapper<>(); +//// queryWrapper.eq("courseid",id); +//// List list = knowtempMapper.selectList(queryWrapper); +//// for (int j = 0; j < list.size(); j++) { +//// Knowtemp knowtemp = list.get(j); +//// f = knowRepository.addFatherAndSonKnow(knowtemp.getChapterId(),knowtemp.getName(),knowtemp.getInfo()); +//// if(f <= 0)return ResultUtils.error(ErrorCode.OPERATION_ERROR); +//// } +//// +//// return ResultUtils.success("添加成功"); +//// } +// +// +//} 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 4f0f1a8..b74a779 100644 --- a/src/main/java/com/teaching/backend/service/KnowGraph/KnowService.java +++ b/src/main/java/com/teaching/backend/service/KnowGraph/KnowService.java @@ -1,24 +1,35 @@ package com.teaching.backend.service.KnowGraph; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.teaching.backend.common.BaseResponse; import com.teaching.backend.common.ErrorCode; import com.teaching.backend.common.ResultUtils; import com.teaching.backend.mapper.KnowGraph.KnowRepository; +import com.teaching.backend.mapper.Knowtemp.KnowtempMapper; +import com.teaching.backend.mapper.chapter.ChapterMapper; +import com.teaching.backend.mapper.courses.CoursesMapper; import com.teaching.backend.model.dto.KnowGraph.*; +import com.teaching.backend.model.dto.Knowtemp.KnowtempAdd; +import com.teaching.backend.model.dto.Knowtemp.KnowtempUpdate; import com.teaching.backend.model.dto.chapter.ChapterDTO; import com.teaching.backend.model.dto.courses.CoursesDTO; import com.teaching.backend.model.entity.KnowGraph.Know; import com.teaching.backend.model.entity.KnowGraph.KnowChapter; import com.teaching.backend.model.entity.KnowGraph.KnowCourse; import com.teaching.backend.model.entity.KnowGraph.Links; +import com.teaching.backend.model.entity.Knowtemp.Knowtemp; import com.teaching.backend.model.entity.chapter.Chapter; import com.teaching.backend.model.entity.courses.Courses; import com.teaching.backend.model.vo.knowGraph.KnowVO; +import com.teaching.backend.model.vo.knowGraph.KnowVO1; import org.neo4j.driver.internal.InternalRelationship; import org.neo4j.driver.types.Node; import org.springframework.beans.BeanUtils; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.neo4j.core.Neo4jClient; import org.springframework.stereotype.Service; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestParam; import javax.annotation.Resource; import java.time.LocalDateTime; @@ -31,109 +42,132 @@ import java.util.*; */ @Service public class KnowService { - + @Autowired private KnowRepository knowRepository; + @Autowired + private ChapterMapper chapterMapper; - @Resource - private Neo4jClient neo4jClient; - - public KnowService(KnowRepository knowRepository) { - this.knowRepository = knowRepository; - } - + @Autowired + private KnowtempMapper knowtempMapper; - public List queryKnowAllKnowById(Long id) { - return knowRepository.queryKnowAllKnowById(id); - } + @Autowired + private CoursesMapper coursesMapper; + @Resource + private Neo4jClient neo4jClient; - public BaseResponse createKnow(KnowRequest knowRequest ) { - String name = knowRequest.getName(); - String info = knowRequest.getInfo(); - if("".equals(name) || name.length()<=0){ - return ResultUtils.error(ErrorCode.PARAMS_EMPTY); + public BaseResponse add(KnowtempAdd knowtempAdd){ + String name = knowtempAdd.getName(); + String info = knowtempAdd.getInfo(); + Long chapterId = knowtempAdd.getChapterid(); + String courseid = knowtempAdd.getCourseid(); + Knowtemp knowtemp = new Knowtemp(); + knowtemp.setName(name); + knowtemp.setInfo(info); + knowtemp.setChapterid(chapterId); + knowtemp.setCourseid(courseid); + int insert = knowtempMapper.insert(knowtemp); + if(insert > 0){ + return ResultUtils.success("添加成功"); } - Know know = new Know(); - BeanUtils.copyProperties(knowRequest,know); - return ResultUtils.success(knowRepository.save(know)) ; + return ResultUtils.error(ErrorCode.OPERATION_ERROR); } - - public BaseResponse updateKnow(KnowUpdateRequest knowUpdateRequest ) { - Know know = new Know(); - try { - know = knowRepository.findById(knowUpdateRequest.getId()).orElseThrow(() -> new RuntimeException("知识点 not found")); - }catch (RuntimeException e){ + public BaseResponse update(KnowtempUpdate knowtempUpdate){ + Long id = knowtempUpdate.getId(); + String name = knowtempUpdate.getName(); + String info = knowtempUpdate.getInfo(); + Long chapterId = knowtempUpdate.getChapterid(); + String courseid = knowtempUpdate.getCourseid(); + Knowtemp knowtemp = new Knowtemp(); + knowtemp = knowtempMapper.selectById(id); + if(knowtemp == null){ return ResultUtils.error(ErrorCode.NOT_FOUND_ERROR); } - String name = knowUpdateRequest.getName(); - String info = knowUpdateRequest.getInfo(); - if("".equals(name) || name.length()<=0){ - return ResultUtils.error(ErrorCode.PARAMS_EMPTY); + knowtemp.setName(name); + knowtemp.setInfo(info); + knowtemp.setChapterid(chapterId); + knowtemp.setCourseid(courseid); + int insert = knowtempMapper.updateById(knowtemp); + if(insert > 0){ + return ResultUtils.success("修改成功"); } - BeanUtils.copyProperties(knowUpdateRequest,know); - return ResultUtils.success(knowRepository.save(know)); + return ResultUtils.error(ErrorCode.OPERATION_ERROR); } - public BaseResponse deleteKnow(Long id) { - Boolean f = knowRepository.deleteKnow(id); - if(f)return ResultUtils.success("删除成功"); - return ResultUtils.error(ErrorCode.DELETE_FAILED); - } - - - public BaseResponse createCourseKnow( Courses courses) { - String courseId = courses.getId(); - String name = courses.getName(); - String description = courses.getDescription(); - return ResultUtils.success(knowRepository.createKnowCourse(courseId,name,description)); + public BaseResponse delete(Long id){ + Knowtemp knowtemp = new Knowtemp(); + knowtemp = knowtempMapper.selectById(id); + if(knowtemp == null){ + return ResultUtils.error(ErrorCode.NOT_FOUND_ERROR); + } + int insert = knowtempMapper.deleteById(id); + if(insert > 0){ + return ResultUtils.success("删除成功"); + } + return ResultUtils.error(ErrorCode.OPERATION_ERROR); } - public BaseResponse deleteCourseKnow( String courseId) { - boolean f = knowRepository.deleteKnowCourse(courseId); - if(f)return ResultUtils.success("删除成功"); - return ResultUtils.error(ErrorCode.DELETE_FAILED); + public BaseResponse query(Long id){ + Knowtemp knowtemp = new Knowtemp(); + knowtemp = knowtempMapper.selectById(id); + if(knowtemp != null){ + return ResultUtils.success(knowtemp); + } + return ResultUtils.error(ErrorCode.NOT_FOUND_ERROR); } - public Boolean updateCourseKnow( Courses courses) { - String id = courses.getId(); - String name = courses.getName(); - String description = courses.getDescription(); - return knowRepository.updateKnowCourse(id,name,description); + public BaseResponse saveKnowToNeo(String id) { + Courses courses = coursesMapper.selectById(id); + int f = knowRepository.createKnowCourse(courses.getId(),courses.getName(),courses.getDescription()); + if(f <= 0)return ResultUtils.error(ErrorCode.OPERATION_ERROR); - } + List chapterList = chapterMapper.selectSectionsByCourseId(id); + for (int i = 0; i < chapterList.size(); i++) { + Chapter chapter = chapterList.get(i); + f = knowRepository.createKnowChapter(chapter.getId(),chapter.getName(),chapter.getContent()); + if(f <= 0)return ResultUtils.error(ErrorCode.OPERATION_ERROR); + } + for (int i = 0; i < chapterList.size(); i++) { + Chapter chapter = chapterList.get(i); + if(chapter.getPid()== 0){ + f = knowRepository.addChapterAndCourse(chapter.getCourseId(),chapter.getId()); + if(f <= 0)return ResultUtils.error(ErrorCode.OPERATION_ERROR); + }else{ + f = knowRepository.addChapterAndCourse(chapter.getPid(),chapter.getId()); + if(f <= 0)return ResultUtils.error(ErrorCode.OPERATION_ERROR); + } - public BaseResponse createKnowChapter(Chapter chapter) { - return ResultUtils.success(knowRepository.createKnowChapter(chapter.getId(), chapter.getName(), chapter.getContent())); + } + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("courseid",id); + List list = knowtempMapper.selectList(queryWrapper); + for (int j = 0; j < list.size(); j++) { + Knowtemp knowtemp = list.get(j); + f = knowRepository.CreateKnowaddChapter(knowtemp.getChapterid(),knowtemp.getName(),knowtemp.getInfo()); + if(f <= 0)return ResultUtils.error(ErrorCode.OPERATION_ERROR); + } + return ResultUtils.success("添加成功"); } - public BaseResponse updateKnowChapter(Chapter chapter) { - return ResultUtils.success(knowRepository.createKnowChapter(chapter.getId(), chapter.getName(), chapter.getContent())); - } - public BaseResponse deleteKnowChapter(Long chapterId) { - boolean f = knowRepository.deleteKnowChapter(chapterId); - if(f)return ResultUtils.success("删除成功"); - return ResultUtils.error(ErrorCode.DELETE_FAILED); - } - public Set queryByChapterId(Long chapterId){ - Set knows = knowRepository.queryByChapterId(chapterId); - return knows; - } - - - public BaseResponse addKnowRelatedKnow(RelationshipKnowRequest relationshipKnowRequest) { - int num = knowRepository.addKnowRelatedKnow(relationshipKnowRequest.getId(),relationshipKnowRequest.getKnowIds()); - if(num == relationshipKnowRequest.getKnowIds().size())return ResultUtils.success("添加关系成功,共添加了"+num+" 条关系"); - return ResultUtils.error(ErrorCode.DELETE_RELATIONSHIP_FAILED); - } - public BaseResponse addKnowFatherAndSonKnow( RelationshipKnowRequest relationshipKnowRequest) { - int num = knowRepository.addKnowFatherAndSonKnow(relationshipKnowRequest.getId(),relationshipKnowRequest.getKnowIds()); - if(num == relationshipKnowRequest.getKnowIds().size())return ResultUtils.success("添加关系成功,共添加了"+num+" 条关系"); - return ResultUtils.error(ErrorCode.DELETE_RELATIONSHIP_FAILED); + public BaseResponse updateRelationship(Long id,List ids,String relationship){ + //必须先学id1的知识点才能学习id2的知识点 + int f = -1; + if("PreCondition".equals(relationship)){ + f = knowRepository.addKnowWithPreCondition(id,ids); + if(f<=0)return ResultUtils.error(ErrorCode.ADD_RELATION_FAILED); + } else if ("FatherAndSon".equals(relationship)) { + f = knowRepository.addKnowWithFaherAndSon(id,ids); + if(f<=0)return ResultUtils.error(ErrorCode.ADD_RELATION_FAILED); + }else{ + f = knowRepository.addKnowWithRelated(id,ids); + if(f<=0)return ResultUtils.error(ErrorCode.ADD_RELATION_FAILED); + } + return ResultUtils.success("添加成功"); } - public BaseKnowReturn getKnowAll(String id) { + public BaseKnowReturn getKnowAll(String id) { Collection> 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(); @@ -180,57 +214,218 @@ public class KnowService { } BaseKnowReturn baseKnowReturn = new BaseKnowReturn(knowList,linksList); - System.out.println(baseKnowReturn); return baseKnowReturn; } - 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]); - } + public BaseResponse> getKnowByCourseId(String id) { + Collection> all = + neo4jClient.query( "match(n:Know)-[r*0..]->(p:Know) where n.courseId = '"+id+"' return p as `p`").fetch().all(); Iterator> iterator = all.iterator(); - Set knowList = new HashSet<>(); - SetlinksList = new HashSet<>(); - KnowVO knowVO; - List node2 = new ArrayList<>(); - Links links; - int p = 0; + Set knowList = new HashSet<>(); + KnowVO1 knowVO; while (iterator.hasNext()) { Map element = iterator.next(); - - knowVO = new KnowVO(); + knowVO = new KnowVO1(); 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(); knowVO.setId(id1); knowVO.setLabel(name1); knowList.add(knowVO); - - node2 = (List) element.get("r"); - for (int i = 0; i < node2.size(); i++) { - InternalRelationship e = (InternalRelationship) node2.get(i); - links = new Links(); - links.setId(e.id()); - links.setSource(e.startNodeId()); - links.setTarget(e.endNodeId()); - links.setLabel(e.type()); - linksList.add(links); - } - - } - BaseKnowReturn baseKnowReturn = new BaseKnowReturn(knowList,linksList); - System.out.println(baseKnowReturn); - return baseKnowReturn; + return ResultUtils.success(knowList); } +// public List queryKnowAllKnowById(Long id) { +// return knowRepository.queryKnowAllKnowById(id); +// } +// +// +// public BaseResponse createKnow(KnowRequest knowRequest ) { +// String name = knowRequest.getName(); +// String info = knowRequest.getInfo(); +// if("".equals(name) || name.length()<=0){ +// return ResultUtils.error(ErrorCode.PARAMS_EMPTY); +// } +// Know know = new Know(); +// BeanUtils.copyProperties(knowRequest,know); +// return ResultUtils.success(knowRepository.save(know)) ; +// } +// +// public BaseResponse updateKnow(KnowUpdateRequest knowUpdateRequest ) { +// Know know = new Know(); +// try { +// know = knowRepository.findById(knowUpdateRequest.getId()).orElseThrow(() -> new RuntimeException("知识点 not found")); +// }catch (RuntimeException e){ +// return ResultUtils.error(ErrorCode.NOT_FOUND_ERROR); +// } +// String name = knowUpdateRequest.getName(); +// String info = knowUpdateRequest.getInfo(); +// if("".equals(name) || name.length()<=0){ +// return ResultUtils.error(ErrorCode.PARAMS_EMPTY); +// } +// BeanUtils.copyProperties(knowUpdateRequest,know); +// return ResultUtils.success(knowRepository.save(know)); +// } +// public BaseResponse deleteKnow(Long id) { +// Boolean f = knowRepository.deleteKnow(id); +// if(f)return ResultUtils.success("删除成功"); +// return ResultUtils.error(ErrorCode.DELETE_FAILED); +// } +// +// +// +// public BaseResponse createCourseKnow( Courses courses) { +// String courseId = courses.getId(); +// String name = courses.getName(); +// String description = courses.getDescription(); +// return ResultUtils.success(knowRepository.createKnowCourse(courseId,name,description)); +// } +// +// public BaseResponse deleteCourseKnow( String courseId) { +// boolean f = knowRepository.deleteKnowCourse(courseId); +// if(f)return ResultUtils.success("删除成功"); +// return ResultUtils.error(ErrorCode.DELETE_FAILED); +// } +// +// public Boolean updateCourseKnow( Courses courses) { +// String id = courses.getId(); +// String name = courses.getName(); +// String description = courses.getDescription(); +// return knowRepository.updateKnowCourse(id,name,description); +// +// } +// +// public BaseResponse createKnowChapter(Chapter chapter) { +// return ResultUtils.success(knowRepository.createKnowChapter(chapter.getId(), chapter.getName(), chapter.getContent())); +// +// } +// public BaseResponse updateKnowChapter(Chapter chapter) { +// return ResultUtils.success(knowRepository.createKnowChapter(chapter.getId(), chapter.getName(), chapter.getContent())); +// } +// public BaseResponse deleteKnowChapter(Long chapterId) { +// boolean f = knowRepository.deleteKnowChapter(chapterId); +// if(f)return ResultUtils.success("删除成功"); +// return ResultUtils.error(ErrorCode.DELETE_FAILED); +// } +// public Set queryByChapterId(Long chapterId){ +// Set knows = knowRepository.queryByChapterId(chapterId); +// return knows; +// } +// +// +// +// public BaseResponse addKnowRelatedKnow(RelationshipKnowRequest relationshipKnowRequest) { +// int num = knowRepository.addKnowRelatedKnow(relationshipKnowRequest.getId(),relationshipKnowRequest.getKnowIds()); +// if(num == relationshipKnowRequest.getKnowIds().size())return ResultUtils.success("添加关系成功,共添加了"+num+" 条关系"); +// return ResultUtils.error(ErrorCode.DELETE_RELATIONSHIP_FAILED); +// } +// public BaseResponse addKnowFatherAndSonKnow( RelationshipKnowRequest relationshipKnowRequest) { +// int num = knowRepository.addKnowFatherAndSonKnow(relationshipKnowRequest.getId(),relationshipKnowRequest.getKnowIds()); +// if(num == relationshipKnowRequest.getKnowIds().size())return ResultUtils.success("添加关系成功,共添加了"+num+" 条关系"); +// return ResultUtils.error(ErrorCode.DELETE_RELATIONSHIP_FAILED); +// } +// +// +// public BaseKnowReturn getKnowAll(String id) { +// Collection> 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<>(); +// SetlinksList = new HashSet<>(); +// KnowVO knowVO; +// List node2 = new ArrayList<>(); +// Links links; +// int p = 0; +// while (iterator.hasNext()) { +// Map element = iterator.next(); +// 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(); +// knowVO.setId(id1); +// knowVO.setLabel(name1); +// +// knowList.add(knowVO); +// +// node2 = (List) element.get("r"); +// for (int i = 0; i < node2.size(); i++) { +// InternalRelationship e = (InternalRelationship) node2.get(i); +// links = new Links(); +// links.setId(e.id()); +// links.setSource(e.startNodeId()); +// links.setTarget(e.endNodeId()); +// links.setLabel(e.type()); +// linksList.add(links); +// } +// +// +// } +// BaseKnowReturn baseKnowReturn = new BaseKnowReturn(knowList,linksList); +// System.out.println(baseKnowReturn); +// return baseKnowReturn; +// } +// +// 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<>(); +// SetlinksList = new HashSet<>(); +// KnowVO knowVO; +// List node2 = new ArrayList<>(); +// Links links; +// int p = 0; +// while (iterator.hasNext()) { +// Map element = iterator.next(); +// +// 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(); +// knowVO.setId(id1); +// knowVO.setLabel(name1); +// knowList.add(knowVO); +// +// node2 = (List) element.get("r"); +// for (int i = 0; i < node2.size(); i++) { +// InternalRelationship e = (InternalRelationship) node2.get(i); +// links = new Links(); +// links.setId(e.id()); +// links.setSource(e.startNodeId()); +// links.setTarget(e.endNodeId()); +// links.setLabel(e.type()); +// linksList.add(links); +// } +// +// +// } +// BaseKnowReturn baseKnowReturn = new BaseKnowReturn(knowList,linksList); +// System.out.println(baseKnowReturn); +// return baseKnowReturn; +// } + } diff --git a/src/main/java/com/teaching/backend/service/KnowGraph/ResourcesService.java b/src/main/java/com/teaching/backend/service/KnowGraph/ResourcesService.java index 4a9498f..ffe73b4 100644 --- a/src/main/java/com/teaching/backend/service/KnowGraph/ResourcesService.java +++ b/src/main/java/com/teaching/backend/service/KnowGraph/ResourcesService.java @@ -9,12 +9,17 @@ import com.teaching.backend.common.ResultUtils; import com.teaching.backend.mapper.KnowGraph.ResourcesRepository; import com.teaching.backend.model.dto.KnowGraph.*; import com.teaching.backend.model.entity.KnowGraph.Resources; +import com.teaching.backend.utils.FileUtils; import org.springframework.beans.BeanUtils; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.neo4j.core.Neo4jClient; import org.springframework.stereotype.Service; import org.springframework.web.multipart.MultipartFile; +import org.springframework.web.multipart.commons.CommonsMultipartFile; + import javax.annotation.Resource; import java.io.File; +import java.io.FileInputStream; import java.io.IOException; import java.nio.charset.StandardCharsets; import java.util.*; @@ -27,14 +32,12 @@ import java.util.*; @Service public class ResourcesService { private static final String GLOBAL_CODE_DIR_NAME = "tempFile"; + + @Autowired private ResourcesRepository resourcesRepository; @Resource private Neo4jClient neo4jClient; - public ResourcesService(ResourcesRepository resourcesRepository) { - this.resourcesRepository = resourcesRepository; - } - public List queryKnowAllResources(Long id) { return resourcesRepository.queryResourceAllId(id); @@ -42,12 +45,6 @@ public class ResourcesService { public Resources createResource(ResourcesAddRequest resourceAddRequest ) { - String resourcesId = resourceAddRequest.getResourcesId(); - try { - Resources resourcesOld = resourcesRepository.queryResources(resourcesId); - }catch (RuntimeException e){ - System.out.println("not found"); - } String name = resourceAddRequest.getName(); Integer type = resourceAddRequest.getType(); String path = resourceAddRequest.getPath(); @@ -70,15 +67,24 @@ public class ResourcesService { public void addKnowWithResources( RelationshipResourceRequest relationshipResourceRequest) { - resourcesRepository.addResourceRelatedKnow(relationshipResourceRequest.getId(),relationshipResourceRequest.getResourceIds()); + resourcesRepository.addResourceResourcesKnow(relationshipResourceRequest.getId(),relationshipResourceRequest.getResourceIds()); } public Set queryCourseKnowToResources(Long KnowId){ return resourcesRepository.queryCourseKnowToResources(KnowId); } - public Set queryBesidesKnowToResources(Long KnowId){ - return resourcesRepository.queryBesidesKnowToResources(KnowId); + public List queryBesidesKnowToResources(Long KnowId){ + ListmultipartFileList = new ArrayList<>(); + SetresourcesSet = resourcesRepository.queryBesidesKnowToResources(KnowId); + resourcesSet = resourcesRepository.queryKnowToResources(KnowId); + Iteratoriterator = resourcesSet.iterator(); + while (iterator.hasNext()){ + Resources resources = iterator.next(); + MultipartFile multipartFile = FileUtils.fileUrlConvertToMultipartFile(resources.getPath()); + multipartFileList.add(multipartFile); + } + return multipartFileList; } public BaseResponse uploadFile(MultipartFile file) { diff --git a/src/main/java/com/teaching/backend/service/impl/chapter/ChapterServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/chapter/ChapterServiceImpl.java index 7e64960..fb81fdc 100644 --- a/src/main/java/com/teaching/backend/service/impl/chapter/ChapterServiceImpl.java +++ b/src/main/java/com/teaching/backend/service/impl/chapter/ChapterServiceImpl.java @@ -3,12 +3,15 @@ package com.teaching.backend.service.impl.chapter; import cn.hutool.core.bean.BeanUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.teaching.backend.common.ErrorCode; import com.teaching.backend.exception.BusinessException; +import com.teaching.backend.mapper.Knowtemp.KnowtempMapper; import com.teaching.backend.mapper.chapter.ChapterMapper; import com.teaching.backend.model.dto.chapter.ChapterDTO; import com.teaching.backend.model.entity.KnowGraph.Know; +import com.teaching.backend.model.entity.Knowtemp.Knowtemp; import com.teaching.backend.model.entity.chapter.Chapter; import com.teaching.backend.model.vo.chapter.ChapterVo; import com.teaching.backend.service.KnowGraph.KnowService; @@ -31,6 +34,9 @@ import java.util.stream.Collectors; public class ChapterServiceImpl extends ServiceImpl implements IChapterService { @Autowired private ChapterMapper chapterMapper; + + @Autowired + private KnowtempMapper knowtempMapper; // private int count=0; List list=new ArrayList<>(); @@ -42,7 +48,7 @@ public class ChapterServiceImpl extends ServiceImpl impl String finalNumShow; String courseid = chapter.getCourseId(); - String pid = chapter.getPid(); + Long pid = chapter.getPid(); LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); Long countChapter ; // pid为0时,说明为章 @@ -173,7 +179,7 @@ public class ChapterServiceImpl extends ServiceImpl impl chapterMap.put(String.valueOf(chapter.getId()),chapter); } for (Chapter chapter:chapters){ - String parentId=chapter.getPid(); + Long parentId=chapter.getPid(); if (!parentId.equals("0")){ Chapter parentChapter=chapterMap.get(parentId); @@ -203,9 +209,10 @@ public class ChapterServiceImpl extends ServiceImpl impl .collect(Collectors.toList()); chapter.setChildren(sortedChildren); - + QueryWrapperqueryWrapper = new QueryWrapper<>(); for (Chapter child : sortedChildren) { - Set knows = knowService.queryByChapterId(child.getId()); + queryWrapper.eq("chapterId",child.getId()); + List knows = knowtempMapper.selectList(queryWrapper); child.setKnowledgePoints(new ArrayList<>(knows)); loadKnowledgePointsRecursively(child); @@ -220,11 +227,11 @@ public class ChapterServiceImpl extends ServiceImpl impl } catch (Exception e) { throw new RuntimeException("复制数据出错", e); } - String pid = chapter.getPid(); + Long pid = chapter.getPid(); - if (pid == null || pid.isEmpty()) { + if (pid == null ) { - chapter.setPid("0"); + chapter.setPid(0L); LambdaQueryWrapper maxSortWrapper = new LambdaQueryWrapper<>(); maxSortWrapper.eq(Chapter::getPid, "0").orderByDesc(Chapter::getOrderNum).last("limit 1"); @@ -287,8 +294,9 @@ public class ChapterServiceImpl extends ServiceImpl impl if (count>0){ throw new BusinessException(ErrorCode.OPERATION_ERROR,"存在子章节,无法删除"); } - - Set knows = knowService.queryByChapterId(id); + QueryWrapperqueryWrapper1 = new QueryWrapper<>(); + queryWrapper1.eq("chapterId",id); + List knows = knowtempMapper.selectList(queryWrapper1); if (!knows.isEmpty()) { throw new BusinessException(ErrorCode.OPERATION_ERROR, "子章节下存在知识点,无法删除"); diff --git a/src/main/java/com/teaching/backend/service/impl/courses/CoursesServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/courses/CoursesServiceImpl.java index f815edd..4130315 100644 --- a/src/main/java/com/teaching/backend/service/impl/courses/CoursesServiceImpl.java +++ b/src/main/java/com/teaching/backend/service/impl/courses/CoursesServiceImpl.java @@ -142,8 +142,6 @@ public class CoursesServiceImpl extends ServiceImpl impl courseObjectivesMapper.updateById(courseTotalObjectives); } } - //将课程同步到图数据库中 - addNeoKnowByCourse.addCourse(courses); return "添加成功"; } else { throw new BusinessException(ErrorCode.OPERATION_ERROR, "这个课程已经存在了!请联系系统相关人员为您导入课程数据!"); diff --git a/src/main/java/com/teaching/backend/utils/FileUtils.java b/src/main/java/com/teaching/backend/utils/FileUtils.java new file mode 100644 index 0000000..4adb507 --- /dev/null +++ b/src/main/java/com/teaching/backend/utils/FileUtils.java @@ -0,0 +1,54 @@ +package com.teaching.backend.utils; + +import com.teaching.backend.common.ErrorCode; +import com.teaching.backend.exception.BusinessException; +import org.springframework.mock.web.MockMultipartFile; +import org.springframework.web.multipart.MultipartFile; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.net.HttpURLConnection; +import java.net.URL; +import java.net.URLConnection; + +//文件转换工具 +public class FileUtils { + + /** + * 将网络文件转换为文件流 + * @param imageUrl + * @return + */ + public static MultipartFile fileUrlConvertToMultipartFile(String imageUrl) { + try { + // 将在线图片地址转换为URL对象 + URL url = new URL(imageUrl); + // 打开URL连接 + URLConnection connection = url.openConnection(); + // 转换为HttpURLConnection对象 + HttpURLConnection httpURLConnection = (HttpURLConnection) connection; + // 获取输入流 + InputStream inputStream = httpURLConnection.getInputStream(); + // 读取输入流中的数据,并保存到字节数组中 + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + byte[] buffer = new byte[1024]; + int bytesRead; + while ((bytesRead = inputStream.read(buffer)) != -1) { + byteArrayOutputStream.write(buffer, 0, bytesRead); + } + // 将字节数组转换为字节数组 + byte[] bytes = byteArrayOutputStream.toByteArray(); + // 创建ByteArrayInputStream对象,将字节数组传递给它 + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes); + // 创建MultipartFile对象,将ByteArrayInputStream对象作为构造函数的参数 + MultipartFile multipartFile = new MockMultipartFile("file", "filename.jpg", "image/jpg", byteArrayInputStream); + return multipartFile; + }catch (IOException ex){ + ex.printStackTrace(); + throw new BusinessException(ErrorCode.FILE_ERROR); + } + } +} + diff --git a/src/main/java/com/teaching/backend/utils/knowGraph/AddNeoKnowByCourse.java b/src/main/java/com/teaching/backend/utils/knowGraph/AddNeoKnowByCourse.java index 77a7074..89a779c 100644 --- a/src/main/java/com/teaching/backend/utils/knowGraph/AddNeoKnowByCourse.java +++ b/src/main/java/com/teaching/backend/utils/knowGraph/AddNeoKnowByCourse.java @@ -11,6 +11,7 @@ import com.teaching.backend.service.KnowGraph.KnowService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestParam; /** * @Author:youhang @@ -23,12 +24,12 @@ public class AddNeoKnowByCourse { @Autowired private KnowService knowService; - public BaseResponse addCourse(Courses courses){ - return knowService.createCourseKnow(courses); - } +// public BaseResponse addCourse(String courseId , String name, String description){ +// return knowService.createCourseKnow( courseId , name, description); +// } - public BaseResponse addChapter(Chapter chapter){ - return knowService.createKnowChapter(chapter); - } +// public BaseResponse addChapter(Chapter chapter){ +// return knowService.createKnowChapter(chapter); +// } }