youahng 6 months ago committed by yh
parent b21b0fdad1
commit a6959fabdc
  1. 6
      pom.xml
  2. 5
      src/main/java/com/teaching/backend/common/ErrorCode.java
  3. 207
      src/main/java/com/teaching/backend/controller/KnowGraph/KnowController.java
  4. 56
      src/main/java/com/teaching/backend/controller/KnowGraph/KnowGraphController.java
  5. 9
      src/main/java/com/teaching/backend/controller/KnowGraph/ResourcesController.java
  6. 10
      src/main/java/com/teaching/backend/controller/resource/ResourceController.java
  7. 31
      src/main/java/com/teaching/backend/mapper/KnowGraph/KnowRepository.java
  8. 9
      src/main/java/com/teaching/backend/mapper/KnowGraph/ResourcesRepository.java
  9. 15
      src/main/java/com/teaching/backend/mapper/Knowtemp/KnowtempMapper.java
  10. 2
      src/main/java/com/teaching/backend/model/dto/KnowGraph/ResourceUpdateRequest.java
  11. 2
      src/main/java/com/teaching/backend/model/dto/KnowGraph/ResourcesAddRequest.java
  12. 32
      src/main/java/com/teaching/backend/model/dto/Knowtemp/KnowtempAdd.java
  13. 32
      src/main/java/com/teaching/backend/model/dto/Knowtemp/KnowtempUpdate.java
  14. 2
      src/main/java/com/teaching/backend/model/entity/KnowGraph/Resources.java
  15. 42
      src/main/java/com/teaching/backend/model/entity/Knowtemp/Knowtemp.java
  16. 5
      src/main/java/com/teaching/backend/model/entity/chapter/Chapter.java
  17. 25
      src/main/java/com/teaching/backend/model/vo/knowGraph/KnowVO1.java
  18. 138
      src/main/java/com/teaching/backend/service/KnowGraph/KnowGraphService.java
  19. 425
      src/main/java/com/teaching/backend/service/KnowGraph/KnowService.java
  20. 32
      src/main/java/com/teaching/backend/service/KnowGraph/ResourcesService.java
  21. 26
      src/main/java/com/teaching/backend/service/impl/chapter/ChapterServiceImpl.java
  22. 2
      src/main/java/com/teaching/backend/service/impl/courses/CoursesServiceImpl.java
  23. 54
      src/main/java/com/teaching/backend/utils/FileUtils.java
  24. 13
      src/main/java/com/teaching/backend/utils/knowGraph/AddNeoKnowByCourse.java

@ -30,6 +30,12 @@
<artifactId>commons-io</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>5.1.5.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-fileupload/commons-fileupload -->
<dependency>

@ -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, "操作失败");

@ -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<Know> queryKnowAllKnowById(@PathVariable Long id) {
return knowService.queryKnowAllKnowById(id);
}
//添加知识点
//根据 章节id 创建知识点到mysql中
@PostMapping("/add")
public BaseResponse<Know> createKnow(@RequestBody KnowRequest knowRequest) {
return knowService.createKnow(knowRequest);
}
//修改知识点
@PostMapping ("/update")
public BaseResponse<Know> updateKnow(@RequestBody KnowUpdateRequest knowUpdateRequest) {
return knowService.updateKnow(knowUpdateRequest);
}
//删除知识点
@GetMapping ("delete/{id}")
public BaseResponse<String> deleteKnow(@PathVariable Long id) {
return knowService.deleteKnow(id);
}
//添加知识点 - 课程
@PostMapping("/add/KnowCourse")
public BaseResponse<KnowCourse> createCourseKnow(@RequestBody Courses courses) {
return knowService.createCourseKnow(courses);
}
//修改知识点 - 课程
@PostMapping("/update/KnowCourse")
public BaseResponse<KnowCourse> updateCourseKnow(@RequestBody Courses courses) {
return knowService.createCourseKnow(courses);
}
//删除知识点 - 课程
@PostMapping("/delete/KnowCourse")
public BaseResponse<String> deleteCourseKnow(@RequestParam String courseId) {
return knowService.deleteCourseKnow(courseId);
public BaseResponse<String> add(@RequestBody KnowtempAdd knowtempAdd) {
return knowService.add(knowtempAdd);
}
//添加知识点 - 章节
@PostMapping("/addKnowChapter")
public BaseResponse<KnowChapter> createKnowChapter(@RequestBody Chapter chapter) {
return knowService.createKnowChapter(chapter);
@PostMapping("/update")
public BaseResponse<String> update(@RequestBody KnowtempUpdate knowtempUpdate) {
return knowService.update(knowtempUpdate);
}
//修改知识点 - 章节
@PostMapping("/update/KnowChapter")
public BaseResponse<KnowChapter> updateKnowChapter(@RequestBody Chapter chapter) {
return knowService.updateKnowChapter(chapter);
@PostMapping("/delete")
public BaseResponse<String> delete(@RequestParam Long id) {
return knowService.delete(id);
}
//删除知识点 - 章节
@PostMapping("/delete/KnowChapter")
public BaseResponse<String> deleteKnowChapter(@RequestParam Long chapterId) {
return knowService.deleteKnowChapter(chapterId);
@PostMapping("/query")
public BaseResponse<Knowtemp> query(@RequestParam Long id) {
return knowService.query(id);
}
@GetMapping("/KnowBychapterId")
public Set<Know> queryByChapterId(@RequestParam Long chapterId) {
return knowService.queryByChapterId(chapterId);
//根据 课程id 从chapter表中获取List 章节
@PostMapping("/addAll")
public BaseResponse<String> addAll(@RequestParam String id) {
return knowService.saveKnowToNeo(id);
}
//添加知识点与知识点的关系 related
@PostMapping ("/addKnowRelatedKnow")
public BaseResponse<String> addKnowRelatedKnow(@RequestBody RelationshipKnowRequest relationshipKnowRequest) {
return knowService.addKnowRelatedKnow(relationshipKnowRequest);
}
//添加知识点与知识点的关系 fatherandSon
@PostMapping ("/addKnowFatherAndSonKnow")
public BaseResponse<String> addKnowFatherAndSonKnow(@RequestBody RelationshipKnowRequest relationshipKnowRequest) {
return knowService.addKnowFatherAndSonKnow(relationshipKnowRequest);
// 改变节点关系
@PostMapping("/update/relationship")
public BaseResponse<String> updateRelationship(@RequestParam Long id, @RequestParam List<Long> 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<BaseKnowReturn> getKnowById(@RequestParam Long id) {
BaseKnowReturn baseKnowReturn =knowService.getKnowById(id);
return ResultUtils.success(baseKnowReturn);
}
@GetMapping("/getAllByCourseId")
public BaseResponse<Set<KnowVO1>> getKnowByCourseId(String id) {
return knowService.getKnowByCourseId(id);
}
// //根据 id查询所关联的所有结点
// @PostMapping ("/query/{id}")
// public List<Know> queryKnowAllKnowById(@PathVariable Long id) {
// return knowService.queryKnowAllKnowById(id);
// }
//
// //添加知识点
// @PostMapping("/add")
// public BaseResponse<Know> createKnow(@RequestBody KnowRequest knowRequest) {
// return knowService.createKnow(knowRequest);
// }
// //修改知识点
// @PostMapping ("/update")
// public BaseResponse<Know> updateKnow(@RequestBody KnowUpdateRequest knowUpdateRequest) {
// return knowService.updateKnow(knowUpdateRequest);
// }
// //删除知识点
// @GetMapping ("delete/{id}")
// public BaseResponse<String> deleteKnow(@PathVariable Long id) {
// return knowService.deleteKnow(id);
// }
//
// //添加知识点 - 课程
// @PostMapping("/add/KnowCourse")
// public BaseResponse<KnowCourse> createCourseKnow(@RequestBody Courses courses) {
// return knowService.createCourseKnow(courses);
// }
//
// //修改知识点 - 课程
// @PostMapping("/update/KnowCourse")
// public BaseResponse<KnowCourse> updateCourseKnow(@RequestBody Courses courses) {
// return knowService.createCourseKnow(courses);
// }
//
// //删除知识点 - 课程
// @PostMapping("/delete/KnowCourse")
// public BaseResponse<String> deleteCourseKnow(@RequestParam String courseId) {
// return knowService.deleteCourseKnow(courseId);
// }
//
// //添加知识点 - 章节
// @PostMapping("/addKnowChapter")
// public BaseResponse<KnowChapter> createKnowChapter(@RequestBody Chapter chapter) {
// return knowService.createKnowChapter(chapter);
// }
//
// //修改知识点 - 章节
// @PostMapping("/update/KnowChapter")
// public BaseResponse<KnowChapter> updateKnowChapter(@RequestBody Chapter chapter) {
// return knowService.updateKnowChapter(chapter);
// }
// //删除知识点 - 章节
// @PostMapping("/delete/KnowChapter")
// public BaseResponse<String> deleteKnowChapter(@RequestParam Long chapterId) {
// return knowService.deleteKnowChapter(chapterId);
// }
//
// @GetMapping("/KnowBychapterId")
// public Set<Know> queryByChapterId(@RequestParam Long chapterId) {
// return knowService.queryByChapterId(chapterId);
// }
//
//
//
// //添加知识点与知识点的关系 related
// @PostMapping ("/addKnowRelatedKnow")
// public BaseResponse<String> addKnowRelatedKnow(@RequestBody RelationshipKnowRequest relationshipKnowRequest) {
// return knowService.addKnowRelatedKnow(relationshipKnowRequest);
// }
//
// //添加知识点与知识点的关系 fatherandSon
// @PostMapping ("/addKnowFatherAndSonKnow")
// public BaseResponse<String> addKnowFatherAndSonKnow(@RequestBody RelationshipKnowRequest relationshipKnowRequest) {
// return knowService.addKnowFatherAndSonKnow(relationshipKnowRequest);
// }
//
// //获取该节点下所有的节点
// @GetMapping("/all")
// public BaseResponse<BaseKnowReturn> getKnowAll(@RequestParam String id) {
// BaseKnowReturn baseKnowReturn =knowService.getKnowAll(id);
// return ResultUtils.success(baseKnowReturn);
// }
//
// //返回该节点以及二级节点
// @GetMapping("/KnowById")
// public BaseResponse<BaseKnowReturn> getKnowById(@RequestParam Long id) {
// BaseKnowReturn baseKnowReturn =knowService.getKnowById(id);
// return ResultUtils.success(baseKnowReturn);
// }
}

@ -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<String> add(@RequestBody KnowtempAdd knowtempAdd) {
// return knowGraphService.add(knowtempAdd);
// }
//
// @PostMapping("/update")
// public BaseResponse<String> update(@RequestBody KnowtempUpdate knowtempUpdate) {
// return knowGraphService.update(knowtempUpdate);
// }
// @PostMapping("/delete")
// public BaseResponse<String> delete(@RequestParam Integer id) {
// return knowGraphService.delete(id);
// }
// @PostMapping("/query")
// public BaseResponse<Knowtemp> query(@RequestParam Integer id) {
// return knowGraphService.query(id);
// }
//
//
// //根据 课程id 从chapter表中获取List 章节
// @PostMapping("/addAll")
// public BaseResponse<String> addAll(@PathVariable String id) {
// return knowGraphService.saveKnowToNeo(id);
// }
//
//
//
//}

@ -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<Resources> queryBesidesKnowToResources(@PathVariable Long KnowId) {
public List<MultipartFile> queryBesidesKnowToResources(@PathVariable Long KnowId) {
return resourcesService.queryBesidesKnowToResources(KnowId);
}

@ -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<String> uploadFile(@RequestParam("file")MultipartFile file) {
return resourcesService.uploadFile(file);
}

@ -23,8 +23,6 @@ public interface KnowRepository extends Neo4jRepository<Know, Long> {
@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<Long> 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<Long> KnowIds);
@ -33,8 +31,8 @@ public interface KnowRepository extends Neo4jRepository<Know, Long> {
List<Know> 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<Know, Long> {
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<Know, Long> {
@Query("MATCH(n:Know)-[r:FatherAndSon*]->(nn:Know) where n.chapterId = $chapterId RETURN nn")
Set<Know> 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<Long> 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<Long> 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<Long> KnowIds);
}

@ -21,11 +21,11 @@ public interface ResourcesRepository extends Neo4jRepository<Resources, Long> {
@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<Long> ResourcesIds);
void addResourceResourcesKnow(Long id, List<Long> ResourcesIds);
@Query("MATCH(n:Know)-[r:resources]->(nn:Resources) where ID(nn) = $id RETURN nn")
@ -34,9 +34,10 @@ public interface ResourcesRepository extends Neo4jRepository<Resources, Long> {
@Query("MATCH p = (a:Know)-[rels*]-(b:Resources) WHERE ID(a) = $KnowId and ANY(rel IN rels WHERE TYPE(rel) = 'resources') RETURN b")
Set<Resources> 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<Resources> queryBesidesKnowToResources(Long KnowId);
@Query(" MATCH (p:Know)-[:resources]->(m:Resources) WHERE ID(p) = 272 RETURN m")
Set<Resources> queryKnowToResources(Long KnowId);
}

@ -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<Knowtemp> {
}

@ -12,7 +12,7 @@ public class ResourceUpdateRequest {
private Long id;
private String resourceId;
private String name;
private Integer type;

@ -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;

@ -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;
/**
* <p>
*
* </p>
*
* @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;
}

@ -0,0 +1,32 @@
package com.teaching.backend.model.dto.Knowtemp;
import io.swagger.models.auth.In;
import lombok.Data;
import java.io.Serializable;
/**
* <p>
*
* </p>
*
* @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;
}

@ -18,8 +18,6 @@ public class Resources {
@GeneratedValue
private Long id;
@Property
private String resourcesId;
@Property
private String name;

@ -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;
/**
* <p>
*
* </p>
*
* @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;
}

@ -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<Know> knowledgePoints; // 用于存储章节下的知识点
private List<Knowtemp> knowledgePoints; // 用于存储章节下的知识点
}

@ -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;
}

@ -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<String> 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<String> 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<String> 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<Knowtemp> 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<String> 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<Chapter> 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<Knowtemp> 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("添加成功");
//// }
//
//
//}

@ -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<Know> queryKnowAllKnowById(Long id) {
return knowRepository.queryKnowAllKnowById(id);
}
@Autowired
private CoursesMapper coursesMapper;
@Resource
private Neo4jClient neo4jClient;
public BaseResponse<Know> 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<String> 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<Know> updateKnow(KnowUpdateRequest knowUpdateRequest ) {
Know know = new Know();
try {
know = knowRepository.findById(knowUpdateRequest.getId()).orElseThrow(() -> new RuntimeException("知识点 not found"));
}catch (RuntimeException e){
public BaseResponse<String> 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<String> deleteKnow(Long id) {
Boolean f = knowRepository.deleteKnow(id);
if(f)return ResultUtils.success("删除成功");
return ResultUtils.error(ErrorCode.DELETE_FAILED);
}
public BaseResponse<KnowCourse> 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<String> 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<String> deleteCourseKnow( String courseId) {
boolean f = knowRepository.deleteKnowCourse(courseId);
if(f)return ResultUtils.success("删除成功");
return ResultUtils.error(ErrorCode.DELETE_FAILED);
public BaseResponse<Knowtemp> 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<String> 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<Chapter> 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<KnowChapter> createKnowChapter(Chapter chapter) {
return ResultUtils.success(knowRepository.createKnowChapter(chapter.getId(), chapter.getName(), chapter.getContent()));
}
QueryWrapper<Knowtemp> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("courseid",id);
List<Knowtemp> 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<KnowChapter> updateKnowChapter(Chapter chapter) {
return ResultUtils.success(knowRepository.createKnowChapter(chapter.getId(), chapter.getName(), chapter.getContent()));
}
public BaseResponse<String> deleteKnowChapter(Long chapterId) {
boolean f = knowRepository.deleteKnowChapter(chapterId);
if(f)return ResultUtils.success("删除成功");
return ResultUtils.error(ErrorCode.DELETE_FAILED);
}
public Set<Know> queryByChapterId(Long chapterId){
Set<Know> knows = knowRepository.queryByChapterId(chapterId);
return knows;
}
public BaseResponse<String> 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<String> 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<String> updateRelationship(Long id,List<Long> 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<Map<String, Object>> 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<Map<String, Object>> 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();
Map<Long,String>colorChoose = 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<Set<KnowVO1>> getKnowByCourseId(String id) {
Collection<Map<String, Object>> all =
neo4jClient.query( "match(n:Know)-[r*0..]->(p:Know) where n.courseId = '"+id+"' return p as `p`").fetch().all();
Iterator<Map<String, Object>> iterator = all.iterator();
Set<KnowVO> knowList = new HashSet<>();
Set<Links>linksList = new HashSet<>();
KnowVO knowVO;
List node2 = new ArrayList<>();
Links links;
int p = 0;
Set<KnowVO1> knowList = new HashSet<>();
KnowVO1 knowVO;
while (iterator.hasNext()) {
Map<String, Object> 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<Know> queryKnowAllKnowById(Long id) {
// return knowRepository.queryKnowAllKnowById(id);
// }
//
//
// public BaseResponse<Know> 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<Know> 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<String> deleteKnow(Long id) {
// Boolean f = knowRepository.deleteKnow(id);
// if(f)return ResultUtils.success("删除成功");
// return ResultUtils.error(ErrorCode.DELETE_FAILED);
// }
//
//
//
// public BaseResponse<KnowCourse> 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<String> 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<KnowChapter> createKnowChapter(Chapter chapter) {
// return ResultUtils.success(knowRepository.createKnowChapter(chapter.getId(), chapter.getName(), chapter.getContent()));
//
// }
// public BaseResponse<KnowChapter> updateKnowChapter(Chapter chapter) {
// return ResultUtils.success(knowRepository.createKnowChapter(chapter.getId(), chapter.getName(), chapter.getContent()));
// }
// public BaseResponse<String> deleteKnowChapter(Long chapterId) {
// boolean f = knowRepository.deleteKnowChapter(chapterId);
// if(f)return ResultUtils.success("删除成功");
// return ResultUtils.error(ErrorCode.DELETE_FAILED);
// }
// public Set<Know> queryByChapterId(Long chapterId){
// Set<Know> knows = knowRepository.queryByChapterId(chapterId);
// return knows;
// }
//
//
//
// public BaseResponse<String> 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<String> 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<Map<String, Object>> 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();
//
// Map<Long,String>colorChoose = 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<Map<String, Object>> iterator = all.iterator();
// Set<KnowVO> knowList = new HashSet<>();
// Set<Links>linksList = new HashSet<>();
// KnowVO knowVO;
// List node2 = new ArrayList<>();
// Links links;
// int p = 0;
// while (iterator.hasNext()) {
// Map<String, Object> 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<Map<String, Object>> 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();
// Map<Long,String>colorChoose = 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<Map<String, Object>> iterator = all.iterator();
// Set<KnowVO> knowList = new HashSet<>();
// Set<Links>linksList = new HashSet<>();
// KnowVO knowVO;
// List node2 = new ArrayList<>();
// Links links;
// int p = 0;
// while (iterator.hasNext()) {
// Map<String, Object> 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;
// }
}

@ -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<Resources> 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<Resources> queryCourseKnowToResources(Long KnowId){
return resourcesRepository.queryCourseKnowToResources(KnowId);
}
public Set<Resources> queryBesidesKnowToResources(Long KnowId){
return resourcesRepository.queryBesidesKnowToResources(KnowId);
public List<MultipartFile> queryBesidesKnowToResources(Long KnowId){
List<MultipartFile>multipartFileList = new ArrayList<>();
Set<Resources>resourcesSet = resourcesRepository.queryBesidesKnowToResources(KnowId);
resourcesSet = resourcesRepository.queryKnowToResources(KnowId);
Iterator<Resources>iterator = resourcesSet.iterator();
while (iterator.hasNext()){
Resources resources = iterator.next();
MultipartFile multipartFile = FileUtils.fileUrlConvertToMultipartFile(resources.getPath());
multipartFileList.add(multipartFile);
}
return multipartFileList;
}
public BaseResponse<String> uploadFile(MultipartFile file) {

@ -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<ChapterMapper, Chapter> implements IChapterService {
@Autowired
private ChapterMapper chapterMapper;
@Autowired
private KnowtempMapper knowtempMapper;
// private int count=0;
List<Chapter> list=new ArrayList<>();
@ -42,7 +48,7 @@ public class ChapterServiceImpl extends ServiceImpl<ChapterMapper, Chapter> impl
String finalNumShow;
String courseid = chapter.getCourseId();
String pid = chapter.getPid();
Long pid = chapter.getPid();
LambdaQueryWrapper<Chapter> wrapper = new LambdaQueryWrapper<>();
Long countChapter ;
// pid为0时,说明为章
@ -173,7 +179,7 @@ public class ChapterServiceImpl extends ServiceImpl<ChapterMapper, Chapter> 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<ChapterMapper, Chapter> impl
.collect(Collectors.toList());
chapter.setChildren(sortedChildren);
QueryWrapper<Knowtemp>queryWrapper = new QueryWrapper<>();
for (Chapter child : sortedChildren) {
Set<Know> knows = knowService.queryByChapterId(child.getId());
queryWrapper.eq("chapterId",child.getId());
List<Knowtemp> knows = knowtempMapper.selectList(queryWrapper);
child.setKnowledgePoints(new ArrayList<>(knows));
loadKnowledgePointsRecursively(child);
@ -220,11 +227,11 @@ public class ChapterServiceImpl extends ServiceImpl<ChapterMapper, Chapter> 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<Chapter> maxSortWrapper = new LambdaQueryWrapper<>();
maxSortWrapper.eq(Chapter::getPid, "0").orderByDesc(Chapter::getOrderNum).last("limit 1");
@ -287,8 +294,9 @@ public class ChapterServiceImpl extends ServiceImpl<ChapterMapper, Chapter> impl
if (count>0){
throw new BusinessException(ErrorCode.OPERATION_ERROR,"存在子章节,无法删除");
}
Set<Know> knows = knowService.queryByChapterId(id);
QueryWrapper<Knowtemp>queryWrapper1 = new QueryWrapper<>();
queryWrapper1.eq("chapterId",id);
List<Knowtemp> knows = knowtempMapper.selectList(queryWrapper1);
if (!knows.isEmpty()) {
throw new BusinessException(ErrorCode.OPERATION_ERROR, "子章节下存在知识点,无法删除");

@ -142,8 +142,6 @@ public class CoursesServiceImpl extends ServiceImpl<CoursesMapper, Courses> impl
courseObjectivesMapper.updateById(courseTotalObjectives);
}
}
//将课程同步到图数据库中
addNeoKnowByCourse.addCourse(courses);
return "添加成功";
} else {
throw new BusinessException(ErrorCode.OPERATION_ERROR, "这个课程已经存在了!请联系系统相关人员为您导入课程数据!");

@ -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);
}
}
}

@ -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<KnowCourse> addCourse(Courses courses){
return knowService.createCourseKnow(courses);
}
// public BaseResponse<KnowCourse> addCourse(String courseId , String name, String description){
// return knowService.createCourseKnow( courseId , name, description);
// }
public BaseResponse<KnowChapter> addChapter(Chapter chapter){
return knowService.createKnowChapter(chapter);
}
// public BaseResponse<KnowChapter> addChapter(Chapter chapter){
// return knowService.createKnowChapter(chapter);
// }
}

Loading…
Cancel
Save