知识点gf

master
you hang 3 months ago committed by youhang20021127
parent 0442325910
commit f63029e4d1
  1. 186
      src/main/java/com/teaching/backend/controller/Know/KnowController.java
  2. 19
      src/main/java/com/teaching/backend/controller/Knowtmp/KnowtmpController.java
  3. 45
      src/main/java/com/teaching/backend/controller/resource/ResourceController.java
  4. 78
      src/main/java/com/teaching/backend/controller/resource/ResourceGraphController.java
  5. 23
      src/main/java/com/teaching/backend/mapper/Knowtemp/KnowstrMapper.java
  6. 18
      src/main/java/com/teaching/backend/mapper/know/KnowRepository.java
  7. 19
      src/main/java/com/teaching/backend/mapper/resource/ResourcesRepository.java
  8. 1
      src/main/java/com/teaching/backend/model/dto/Knowtmp/KnowtempAdd.java
  9. 30
      src/main/java/com/teaching/backend/model/entity/know/KnowStr.java
  10. 29
      src/main/java/com/teaching/backend/model/entity/know/LinksVO.java
  11. 82
      src/main/java/com/teaching/backend/service/Know/KnowService.java
  12. 941
      src/main/java/com/teaching/backend/service/impl/know/knowServiceImpl.java
  13. 22
      src/main/java/com/teaching/backend/service/impl/knowtmp/KnowtmpServiceImpl.java
  14. 151
      src/main/java/com/teaching/backend/service/impl/resource/ResourceGraphServiceImpl.java
  15. 68
      src/main/java/com/teaching/backend/service/impl/resource/ResourceServiceImpl.java
  16. 5
      src/main/java/com/teaching/backend/service/knowtmp/KnowtmpService.java
  17. 39
      src/main/java/com/teaching/backend/service/resource/ResourceGraphService.java
  18. 17
      src/main/java/com/teaching/backend/service/resource/ResourceService.java

@ -6,183 +6,111 @@ package com.teaching.backend.controller.Know;
* @Description:
*/
import com.teaching.backend.common.BaseResponse;
import com.teaching.backend.mapper.know.KnowRepository;
import com.teaching.backend.model.dto.Know.*;
import com.teaching.backend.model.entity.know.Know;
import com.teaching.backend.model.entity.know.KnowChapter;
import com.teaching.backend.model.entity.know.KnowCourse;
import com.teaching.backend.model.entity.resource.Resources;
import com.teaching.backend.model.vo.knowGraph.KnowVO1;
import com.teaching.backend.model.entity.know.*;
import com.teaching.backend.model.entity.knowtmp.Knowtmp;
import com.teaching.backend.model.vo.knowGraph.KnowVO;
import com.teaching.backend.service.Know.KnowService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.neo4j.core.Neo4jClient;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import javax.annotation.Resource;
import java.util.Collection;
import java.util.Map;
import java.util.Set;
@RestController
@RequestMapping("/api/knowNeo")
@Api(tags= "图-知识点管理")
public class KnowController {
@Autowired
private KnowService knowService;
@Autowired
private KnowRepository knowRepository;
@Resource
private Neo4jClient neo4jClient;
//返回2层知识点
@GetMapping("/twoLevelKnows")
BaseResponse<BaseKnowReturn> getTwoLevelKnows(@RequestParam Long id){
return knowService.getTwoLevelKnows(id);
}
//返回3层知识点
@GetMapping("/threeLevelKnows")
BaseResponse<BaseKnowReturn> getThreeLevelKnows(@RequestParam Long id){
return knowService.getThreeLevelKnows(id);
}
//返回4层知识点
@GetMapping("/fourLevelKnows")
BaseResponse<BaseKnowReturn> getFourLevelKnows(@RequestParam Long id){
return knowService.getFourLevelKnows(id);
}
//通过courseId 显示图的JSON
@GetMapping("/test")
void test(){
String t = "related";
String str = "MATCH (p:Know), (j:Know) WHERE ID(p)= "+407+" AND ID(j)= "+389+" CREATE (p)-[r: "+t+" ]->(j) return count(r);";
Collection<Map<String, Object>> res = neo4jClient.query(str).fetch().all();
System.out.println(res);
}
//通过courseId 显示图的JSON
//通过courseId 查询所有结点,存储成JSON
@ApiOperation(value = "通过courseId 查询所有结点,存储成JSON")
@GetMapping("/showGraphJson")
BaseResponse<String> showGraphJson(@RequestParam String courseId){
return knowService.showGraphJson(courseId);
}
// 添加全部知识点
@PostMapping("/addAllKnow")
BaseResponse<String> addAllKnow(@RequestParam String courseId){
return knowService.addAllKnow(courseId);
//通过courseId 查询 JSON 生成图
@ApiOperation(value = "通过courseId 查询 JSON 生成图")
@GetMapping("/generateGraph")
BaseResponse<String> generateGraph(@RequestParam String courseId){
return knowService.generateGraph(courseId);
}
// 添加知识点与资源的关系
@PostMapping("/addRelationship/Withresources")
BaseResponse<String> addRelationshipWithresources(@RequestParam Long id,@RequestParam Long resourceId){
return knowService.addRelationshipWithresources(id,resourceId);
}
//===================
// // 添加知识点
// @PostMapping("/addKnow")
// BaseResponse<String> addKnow(@RequestBody KnowRequest knowRequest){
// return knowService.addKnow(knowRequest);
// }
// 修改知识点
@PostMapping("/updateKnow")
BaseResponse<String> updateKnow(@RequestBody KnowUpdateRequest knowUpdateRequest){
return knowService.updateKnow(knowUpdateRequest);
}
// 删除知识点
@GetMapping("/deleteKnow")
BaseResponse<String> deleteKnow(@RequestParam Long id){
return knowService.deleteKnow(id);
//生成知识点学习路径 默认从第一个知识点到第最后个知识点
@ApiOperation(value = "生成知识点学习路径")
@GetMapping("/knowLearnPath")
BaseResponse<BaseKnowReturn> knowLearnPath(@RequestParam String corseId){
return knowService.knowLearnPath(corseId);
}
//查询知识点通过id
@GetMapping("/queryKnow")
BaseResponse<Know> queryKnow(@RequestParam Long id){
return knowService.queryKnow(id);
//返回depth层知识点
@ApiOperation(value = "返回depth层知识点")
@GetMapping("/getNodeByDepth")
BaseResponse<BaseKnowReturn> getNodeByDepth(@RequestParam Long id,@RequestParam Long depth){
return knowService.getNodeByDepth(id,depth);
}
//======================================
// 添加课程
@PostMapping("/addCourse")
BaseResponse<String> addCourse(@RequestBody KnowCourseCreateRequest knowCourseCreateRequest){
return knowService.addCourse(knowCourseCreateRequest);
//返回课程下指定关系的知识图谱
@ApiOperation(value = "返回课程下指定关系的知识图谱")
@GetMapping("/getRelsNodesByCourseId")
BaseResponse<BaseKnowReturn> getRelsNodesByCourseId(@RequestParam String courseId,@RequestParam List<String>types){
return knowService.getRelsNodesByCourseId(courseId,types);
}
// 修改课程
@PostMapping("/updateCourse")
BaseResponse<String> updateCourse(@RequestBody KnowCourseCreateRequest knowCourseCreateRequest){
return knowService.updateCourse(knowCourseCreateRequest);
//返回知识点的前后知识点
@ApiOperation(value = "返回知识点的前后知识点")
@GetMapping("/getFontedAndBackKnows")
BaseResponse<List<KnowVO>> getFontedAndBackKnows(@RequestParam Long id){
return knowService.getFontedAndBackKnows(id);
}
// 删除课程
@PostMapping("/deleteCourse")
BaseResponse<String> deleteCourse(@RequestParam String courseId){
return knowService.deleteCourse(courseId);
}
//查询课程通过courseid
@GetMapping ("/queryCourse")
BaseResponse<KnowCourse> queryCourse(@RequestParam String courseId){
return knowService.queryCourse(courseId);
}
//=========================
// 添加章节
@PostMapping("/addChapter")
BaseResponse<String> addChapter(@RequestBody KnowChapterCreateRequest knowChapterCreateRequest){
return knowService.addChapter(knowChapterCreateRequest);
//返回知识点下指定关系的知识图谱
@ApiOperation(value = "返回知识点下指定关系的知识图谱")
@GetMapping("/getRelsNodesById")
BaseResponse<BaseKnowReturn> getRelsNodesById(@RequestParam Long id,@RequestParam List<String>types){
return knowService.getRelsNodesById(id,types);
}
// 修改章节
@PostMapping("/updateChapter")
BaseResponse<String> updateChapter(@RequestBody KnowChapterCreateRequest knowChapterCreateRequest){
return knowService.updateChapter(knowChapterCreateRequest);
//重置 知识点下 知识图谱
@ApiOperation(value = "重置-知识点下-知识图谱")
@GetMapping("/getKnowGraphById")
BaseResponse<BaseKnowReturn> getKnowGraphById(@RequestParam Long id){
return knowService.getKnowGraphById(id);
}
// 删除章节
@GetMapping("/deleteChapter")
BaseResponse<String> deleteChapter(@RequestParam Long chapterId){
return knowService.deleteChapter(chapterId);
}
//查询章节通过chapterId
@PostMapping("/queryChapter")
BaseResponse<KnowChapter> queryChapter(@RequestParam Long chapterId){
return knowService.queryChapter(chapterId);
}
//=====================
//通过courseId 删除所有节点
@ApiOperation(value = "通过courseId 删除所有节点")
@GetMapping("/deleteAllByCourseId")
BaseResponse<String> deleteAllByCourseId(@RequestParam String courseId){
return knowService.deleteAllByCourseId(courseId);
}
//获取课程下的所有知识点
@ApiOperation(value = "获取课程下的所有知识点")
@GetMapping("/getAllKnowByCourseId")
BaseResponse<BaseKnowReturn> getAllKnowByCourseId(@RequestParam String id){
return knowService.getAllKnowByCourseId(id);
}
//获取二级知识图谱
@GetMapping("/getsecondKnowsById")
BaseResponse<BaseKnowReturn> getsecondKnowsById(@RequestParam Long id){
return knowService.getsecondKnowsById(id);
//批量修改节点关系
@ApiOperation(value = "批量修改节点关系")
@PostMapping("/updateLinks")
BaseResponse<String> updateLinks(@RequestBody List<LinksVO> linksList){
return knowService.updateLinks(linksList);
}
}

@ -6,6 +6,9 @@ import com.teaching.backend.model.dto.Knowtmp.KnowtempAdd;
import com.teaching.backend.model.dto.Knowtmp.KnowtempUpdate;
import com.teaching.backend.model.entity.knowtmp.Knowtmp;
import com.teaching.backend.service.knowtmp.KnowtmpService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@ -18,21 +21,25 @@ import java.util.List;
*/
@RestController
@RequestMapping("/knowtmp")
@Api(tags="Mysql-知识点管理")
public class KnowtmpController {
@Autowired
private KnowtmpService knowtmpService;
//返回课程下所有知识点
@ApiOperation(value = "返回课程下所有知识点")
@GetMapping("/getAllKnows")
BaseResponse<Long> getAllKnows(@RequestParam String courseId){
return knowtmpService.getAllKnows(courseId);
}
// 添加知识点
@ApiOperation(value = "添加知识点")
@PostMapping("/addKnow")
BaseResponse<String> add(@RequestBody KnowtempAdd knowtempAdd){
return knowtmpService.add(knowtempAdd);
@ -40,26 +47,30 @@ public class KnowtmpController {
//修改知识点
@ApiOperation(value = "修改知识点")
@PostMapping("/updateKnow")
BaseResponse<String> update(@RequestBody KnowtempUpdate knowtempUpdate){
return knowtmpService.update(knowtempUpdate);
}
//删除知识点
@ApiOperation(value = "删除知识点")
@GetMapping("/deleteKnow")
BaseResponse<String> delete(Long id){
return knowtmpService.delete(id);
}
//查询通过chapterId List
@ApiOperation(value = "查询通过chapterId List")
@GetMapping("/query")
BaseResponse<Knowtmp> query(Long id){
return knowtmpService.query(id);
}
//查询通过chapterId List
@ApiOperation(value = "查询通过chapterId List")
@GetMapping("/queryKnow")
List<Knowtmp> queryByChapterId(Long chapterId){
BaseResponse<List<Knowtmp>> queryByChapterId(Long chapterId){
return knowtmpService.queryByChapterId(chapterId);
}
}

@ -11,6 +11,9 @@ import com.teaching.backend.common.BaseResponse;
import com.teaching.backend.model.dto.resource.ResourceUploadDto;
import com.teaching.backend.model.entity.resource.Resources;
import com.teaching.backend.service.resource.ResourceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.InputStreamResource;
import org.springframework.http.ResponseEntity;
@ -23,6 +26,7 @@ import java.util.Set;
@RestController
@RequestMapping("/api/resource")
@Api(tags= "资源管理")
public class ResourceController {
@Autowired
@ -32,6 +36,7 @@ public class ResourceController {
//添加知识点
@PostMapping("/upload")
@ResponseBody
@ApiOperation(value = "添加资源")
public BaseResponse<Resources> uploadFile(@RequestPart("file") MultipartFile file) {
return resourceService.upload(file);
}
@ -39,51 +44,15 @@ public class ResourceController {
//删除资源
@GetMapping ("delete")
@ResponseBody
@ApiOperation(value = "删除资源")
public BaseResponse<String> deleteResource(@RequestParam("filename") String filename) {
return resourceService.delete(filename);
}
@GetMapping("/read")
@ApiOperation(value = "查询资源")
public ResponseEntity<InputStreamResource> readFile(@RequestParam String filename) {
return resourceService.readFile(filename);
}
@GetMapping("/addRelationship/BetweenCourseAndResources")
public BaseResponse<String> addResourcesAndKnowByCourseId(@RequestParam String courseId, @RequestParam List<Long> resourcesIds){
return resourceService.addResourcesAndKnowByCourseId(courseId,resourcesIds);
}
@GetMapping("/addRelationship/BetweenChapterAndResources")
public BaseResponse<String> addResourcesAndKnowByChapterId(@RequestParam Long chapterId,@RequestParam List<Long> resourcesIds){
return resourceService.addResourcesAndKnowByChapterId(chapterId,resourcesIds);
}
@GetMapping("/addRelationship/BetweenKnowAndResources")
public BaseResponse<String> addResourcesAndKnowById(@RequestParam Long id, @RequestParam List<Long> resourcesIds){
return resourceService.addResourcesAndKnowById(id,resourcesIds);
}
//查询课程下资源
@GetMapping("/queryByCourseId")
BaseResponse<Set<Resources>> queryResourcesByCourseId(@RequestParam String courseId){
return resourceService.queryResourcesByCourseId(courseId);
}
//查询章节下资源
@GetMapping("/queryByChapterId")
BaseResponse<Set<Resources>> queryResourcesByChapterId(@RequestParam Long chapterId){
return resourceService.queryResourcesByChapterId(chapterId);
}
//查询二级节点下资源
@GetMapping("/queryBesidesKnow")
BaseResponse<Set<Resources>> queryBesidesKnowToResources(@RequestParam Long KnowId){
return resourceService.queryBesidesKnowToResources(KnowId);
}
//查询知识点下资源
@GetMapping("/queryResourcesByKnowId")
BaseResponse<Set<Resources>> queryResourcesByKnowId(@RequestParam Long KnowId){
return resourceService.queryResourcesByKnowId(KnowId);
}
}

@ -0,0 +1,78 @@
package com.teaching.backend.controller.resource;
/**
* @Author:youhang
* @Date:2024-06-09-9:55
* @Description:
*/
import com.teaching.backend.common.BaseResponse;
import com.teaching.backend.model.entity.resource.Resources;
import com.teaching.backend.service.resource.ResourceGraphService;
import com.teaching.backend.service.resource.ResourceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.InputStreamResource;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.util.List;
import java.util.Set;
@RestController
@RequestMapping("/api/resource/graph")
@Api(tags= "资源与图管理")
public class ResourceGraphController {
@Autowired
private ResourceGraphService resourceGraphService;
@GetMapping("/addRelationship/BetweenKnowAndResources")
@ApiOperation(value = "添加知识点资源关系")
public BaseResponse<String> addResourcesByIdAndResourcesIds(@RequestParam Long id,@RequestParam List<Long> resourcesIds){
return resourceGraphService.addResourcesByIdAndResourcesIds(id,resourcesIds);
}
@GetMapping("/deleteRelationship/BetweenKnowAndResources")
@ApiOperation(value = "删除知识点资源关系")
public BaseResponse<String> deleteResourcesAndKnowById(@RequestParam Long id, @RequestParam List<Long> resourcesIds){
return resourceGraphService.deleteResourcesAndKnowById(id,resourcesIds);
}
//查询课程下资源
@GetMapping("/queryByCourseId")
@ApiOperation(value = "查询课程下资源")
BaseResponse<Set<Resources>> queryResourcesByCourseId(@RequestParam String courseId){
return resourceGraphService.queryResourcesByCourseId(courseId);
}
//查询章节下资源
@GetMapping("/queryByChapterId")
@ApiOperation(value = "查询章节下资源")
BaseResponse<Set<Resources>> queryResourcesByChapterId(@RequestParam Long chapterId){
return resourceGraphService.queryResourcesByChapterId(chapterId);
}
//查询二级节点下资源
@ApiOperation(value = "查询二级节点下资源")
@GetMapping("/queryBesidesKnow")
BaseResponse<Set<Resources>> queryBesidesKnowToResources(@RequestParam Long knowId){
return resourceGraphService.queryBesidesKnowToResources(knowId);
}
//查询知识点下资源
@GetMapping("/queryResourcesByKnowId")
@ApiOperation(value = "查询知识点下资源")
BaseResponse<Set<Resources>> queryResourcesByKnowId(@RequestParam Long knowId){
return resourceGraphService.queryResourcesByKnowId(knowId);
}
}

@ -0,0 +1,23 @@
package com.teaching.backend.mapper.Knowtemp;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.teaching.backend.model.entity.know.KnowStr;
import com.teaching.backend.model.entity.knowtmp.Knowtmp;
import io.lettuce.core.dynamic.annotation.Param;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import java.util.List;
/**
*
*/
@Mapper
public interface KnowstrMapper extends BaseMapper<KnowStr> {
}

@ -23,6 +23,14 @@ import java.util.Set;
public interface KnowRepository extends Neo4jRepository<Know, Long> {
@Query("MATCH (n:Know) WHERE n.courseId = $courseId OPTIONAL MATCH p=(n)-[*0..]-() DETACH DELETE p return count(p);")
Long deleteAllByCourseId(String courseId);
@Query("MATCH (n:Know) WHERE ID(n)= ${id} DETACH DELETE n;")
Long deleteNode(Long id);
//=============
@Query("MATCH (p:Know)-[:FatherAndSon]->(n:Know) WHERE p.chapterId = $chapterId RETURN p.id ORDER BY ordernum;")
@ -42,8 +50,14 @@ public interface KnowRepository extends Neo4jRepository<Know, Long> {
@Query("MATCH ID(p:Know) = $id delete p RETURN count(p);")
int deleteKnow(Long id);
@Query("MATCH ID(p:Know) = $id RETURN p;")
Know queryKnow(Long id);
@Query("MATCH (p:Know) where ID(p) = $id RETURN count(p);")
int queryNode(Long id);
@Query("MATCH (p:Know) where ID(p) = $id RETURN p;")
Know queryNodeT(Long id);
@Query("MATCH (p:Know) where p.knowId = $knowId RETURN p;")
Know queryKnowByKnowId(Long knowId);
//=============================

@ -16,6 +16,20 @@ import java.util.Set;
public interface ResourcesRepository extends Neo4jRepository<Resources, Long> {
//查询资源
@Query("MATCH (b:Resources) WHERE ID(b) in $resourceIds RETURN b")
Set<Resources> queryResourcesByIds(List<Long> resourceIds);
//查询资源 - 知识点
@Query("MATCH (p:Know)-[r:resources]->(c:Resources) WHERE ID(p) = $id AND ID(c) = $resourcesId return count(r)")
int queryExisitRel(Long id, Long resourcesId);
//添加知识点与资源关系
@Query("MATCH (p:Know), (c:Resources) WHERE ID(p) = $id AND ID(c) = $resourcesId CREATE (p)-[r:resources]->(c) return count(r)")
int addResourcesAndKnowById(Long id, Long resourcesId);
//删除资源节点
@Query("MATCH(n:Resources) where n.name = $name DETACH DELETE n RETURN COUNT(n) >0;")
Boolean deleteByobjectName(String name);
@ -29,6 +43,11 @@ public interface ResourcesRepository extends Neo4jRepository<Resources, Long> {
@Query("MATCH (p:Know), (c:Resources) WHERE p.chapterId = $chapterId AND ID(c) in $resourcesIds CREATE (p)-[r:resources]->(c) return count(r)")
int addResourcesAndKnowByChapterId(Long chapterId, List<Long> resourcesIds);
//删除知识点与资源关系
@Query("MATCH (p:Know)-[r:resources]->(c:Resources) WHERE ID(p) = $id AND ID(c) = $resourcesId delete r return count(r)")
int deleteResourcesAndKnowById(Long id, Long resourcesId);
//添加知识点与资源关系
@Query("MATCH (p:Know), (c:Resources) WHERE ID(p) = $id AND ID(c) in $resourcesIds CREATE (p)-[r:resources]->(c) return count(r)")
int addResourcesAndKnowById(Long id, List<Long> resourcesIds);

@ -21,7 +21,6 @@ public class KnowtempAdd implements Serializable {
private Long chapterid;
private Integer ordernum;
private double hour;

@ -0,0 +1,30 @@
package com.teaching.backend.model.entity.know;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import javax.xml.soap.Text;
import java.io.Serializable;
/**
* @Author:youhang
* @Date:2024-08-23-17:29
* @Description:
*/
@Data
@TableName("know_str")
public class KnowStr implements Serializable {
private static final long serialVersionUID = 1L;
@TableId(value = "id", type = IdType.AUTO)
private Long id;
private String courseId;
private String coursestr;
private String chapterstr;
private String knowstr;
private String edgestr;
}

@ -0,0 +1,29 @@
package com.teaching.backend.model.entity.know;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.checkerframework.checker.units.qual.A;
import org.springframework.data.neo4j.core.schema.GeneratedValue;
import org.springframework.data.neo4j.core.schema.Id;
import org.springframework.data.neo4j.core.schema.Node;
import org.springframework.data.neo4j.core.schema.Property;
/**
* @Author:youhang
* @Date:2024-07-21-16:32
* @Description:
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class LinksVO {
private Long source;
private Long target;
private String label;
}

@ -2,13 +2,14 @@ package com.teaching.backend.service.Know;
import com.teaching.backend.common.BaseResponse;
import com.teaching.backend.model.dto.Know.*;
import com.teaching.backend.model.entity.know.Know;
import com.teaching.backend.model.entity.know.KnowChapter;
import com.teaching.backend.model.entity.know.KnowCourse;
import com.teaching.backend.model.entity.know.*;
import com.teaching.backend.model.entity.knowtmp.Knowtmp;
import com.teaching.backend.model.entity.resource.Resources;
import com.teaching.backend.model.vo.knowGraph.KnowVO;
import com.teaching.backend.model.vo.knowGraph.KnowVO1;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.List;
import java.util.Set;
/**
@ -17,78 +18,33 @@ import java.util.Set;
* @Description:
*/
public interface KnowService {
public BaseResponse<BaseKnowReturn> getNodeByDepth(long id,Long depth);
BaseResponse<BaseKnowReturn> getTwoLevelKnows(Long id);
BaseResponse<BaseKnowReturn> getThreeLevelKnows(Long id);
BaseResponse<BaseKnowReturn> getFourLevelKnows(Long id);
BaseResponse<BaseKnowReturn> knowLearnPath(String corseId);
//通过courseId 显示图的JSON
BaseResponse<String> showGraphJson(String courseId);
//通过courseId 添加所有节点
BaseResponse<String> addAllKnow(String courseId);
BaseResponse<String> addRelationshipWithresources(Long id, Long resourceId);
//=====================
// // 添加知识点
// BaseResponse<String> addKnow(KnowRequest knowRequest);
// 修改知识点
BaseResponse<String> updateKnow(KnowUpdateRequest knowUpdateRequest);
// 删除知识点
BaseResponse<String> deleteKnow(Long id);
//查询知识点通过id
BaseResponse<Know> queryKnow(Long id);
//======================================
BaseResponse<String> updateLinks(List<LinksVO> linksList);
BaseResponse<String> deleteAllByCourseId(String courseId1);
BaseResponse<String> generateGraph(String courseId1);
// 添加课程
BaseResponse<String> addCourse(KnowCourseCreateRequest knowCourseCreateRequest);
// 修改课程
BaseResponse<String> updateCourse(KnowCourseCreateRequest knowCourseCreateRequest);
// 删除课程
BaseResponse<String> deleteCourse(String courseId);
//查询课程通过courseid
BaseResponse<KnowCourse> queryCourse(String courseId);
//=========================
// 添加章节
BaseResponse<String> addChapter(KnowChapterCreateRequest knowChapterCreateRequest);
// 修改章节
BaseResponse<String> updateChapter(KnowChapterCreateRequest knowChapterCreateRequest);
// 删除章节
BaseResponse<String> deleteChapter(Long chapterId);
//查询章节通过chapterId
BaseResponse<KnowChapter> queryChapter(Long chapterId);
//通过courseId 显示图的JSON
BaseResponse<String> showGraphJson(String courseId);
//=====================
//获取课程下的所有知识点
BaseResponse<BaseKnowReturn> getAllKnowByCourseId(String id);
//获取课程下的所有知识点
BaseResponse<BaseKnowReturn> getsecondKnowsById(Long id);
//返回课程下指定关系的知识图谱
BaseResponse<BaseKnowReturn> getRelsNodesByCourseId(String courseId,List<String>types);
//获取课程下的所有资源
BaseResponse<Set<KnowVO1>> getAllResourcesByCourseId(String id);
//返回课程下指定关系的知识图谱
BaseResponse<BaseKnowReturn> getRelsNodesById(Long id,List<String>types);
//返回课程下指定关系的知识图谱
BaseResponse<BaseKnowReturn> getKnowGraphById(Long id);
//查询
BaseResponse<List<KnowVO>> getFontedAndBackKnows(Long id);
}

@ -34,6 +34,8 @@ public class KnowtmpServiceImpl implements KnowtmpService {
@Autowired
private KnowtmpMapper knowtmpMapper;
@Override
public BaseResponse<Long> getAllKnows(String courseId) {
// 3 从章节表查出章节节点 并添加到 neo
@ -61,6 +63,10 @@ public class KnowtmpServiceImpl implements KnowtmpService {
public BaseResponse<String> update(KnowtempUpdate knowtempUpdate) {
Knowtmp knowtmp = new Knowtmp();
BeanUtils.copyProperties(knowtempUpdate,knowtmp);
Knowtmp knowtmpOld = knowtmpMapper.selectById(knowtmp.getId());
if(knowtmpOld == null){
return ResultUtils.error(ErrorCode.OPERATION_ERROR,"数据不存在");
}
int f = knowtmpMapper.updateById(knowtmp);
if(f > 0){
return ResultUtils.success("修改成功");
@ -71,7 +77,11 @@ public class KnowtmpServiceImpl implements KnowtmpService {
@Override
public BaseResponse<String> delete(Long id) {
// todo 查询 id
Knowtmp knowtmpOld = knowtmpMapper.selectById(id);
if(knowtmpOld == null){
return ResultUtils.error(ErrorCode.OPERATION_ERROR,"数据不存在");
}
int f = knowtmpMapper.deleteById(id);
if(f > 0){
return ResultUtils.success("删除成功");
@ -83,13 +93,19 @@ public class KnowtmpServiceImpl implements KnowtmpService {
@Override
public BaseResponse<Knowtmp> query(Long id) {
Knowtmp knowtmp = knowtmpMapper.selectById(id);
if(knowtmp == null){
return ResultUtils.error(ErrorCode.OPERATION_ERROR,"数据不存在");
}
return ResultUtils.success(knowtmp);
}
@Override
public List<Knowtmp> queryByChapterId(Long chapterId) {
public BaseResponse<List<Knowtmp>> queryByChapterId(Long chapterId) {
List<Knowtmp> knowtmps = knowtmpMapper.queryIdByChapterId(chapterId);
return knowtmps;
if(knowtmps == null){
return ResultUtils.error(ErrorCode.OPERATION_ERROR,"数据不存在");
}
return ResultUtils.success(knowtmps);
}
@Override

@ -0,0 +1,151 @@
package com.teaching.backend.service.impl.resource;
import com.teaching.backend.common.BaseResponse;
import com.teaching.backend.common.ErrorCode;
import com.teaching.backend.common.ResultUtils;
import com.teaching.backend.mapper.know.KnowRepository;
import com.teaching.backend.mapper.resource.ResourcesRepository;
import com.teaching.backend.model.dto.resource.ResourceUploadDto;
import com.teaching.backend.model.entity.know.KnowChapter;
import com.teaching.backend.model.entity.know.KnowCourse;
import com.teaching.backend.model.entity.resource.Resources;
import com.teaching.backend.service.resource.ResourceGraphService;
import com.teaching.backend.service.resource.ResourceService;
import com.teaching.backend.utils.MinioUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.InputStreamResource;
import org.springframework.data.neo4j.core.Neo4jClient;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import java.util.List;
import java.util.Set;
/**
* @Author:youhang
* @Date:2024-07-26-13:58
* @Description:
*/
@Service
public class ResourceGraphServiceImpl implements ResourceGraphService {
@Autowired
private ResourcesRepository resourcesRepository;
@Autowired
private KnowRepository knowRepository;
@Override
public BaseResponse<String> addResourcesByIdAndResourcesIds(Long id, List<Long> resourcesIds) {
// 查询知识点是否存在 ,资源是否存在
int f = knowRepository.queryNode(id);
if(f <= 0){
return ResultUtils.error(ErrorCode.PARAMS_ERROR,"知识点不存在");
}
Set<Resources>resourcesSet = resourcesRepository.queryResourcesByIds(resourcesIds);
if(resourcesSet.size() < resourcesIds.size()){
return ResultUtils.error(ErrorCode.PARAMS_ERROR,"资源不存在");
}
//查询关系是否存在
for (int i = 0; i < resourcesIds.size(); i++) {
int count = resourcesRepository.queryExisitRel(id,resourcesIds.get(i));
if(count <= 0){
//添加关系 addResourcesAndKnowById
f = resourcesRepository.addResourcesAndKnowById(id,resourcesIds.get(i));
if(f<= 0){
return ResultUtils.error(ErrorCode.PARAMS_ERROR,"创建关系失败");
}
}
}
return ResultUtils.success("添加关系成功");
}
@Override
public BaseResponse<String> deleteResourcesAndKnowById(Long id, List<Long> resourcesIds) {
// 查询知识点是否存在 ,资源是否存在
int f = knowRepository.queryNode(id);
if(f <= 0){
return ResultUtils.error(ErrorCode.PARAMS_ERROR,"知识点不存在");
}
Set<Resources>resourcesSet = resourcesRepository.queryResourcesByIds(resourcesIds);
if(resourcesSet.size() < resourcesIds.size()){
return ResultUtils.error(ErrorCode.PARAMS_ERROR,"资源不存在");
}
//查询关系是否存在
for (int i = 0; i < resourcesIds.size(); i++) {
int count = resourcesRepository.queryExisitRel(id,resourcesIds.get(i));
if(count <= 0){
//添加关系 addResourcesAndKnowById
f = resourcesRepository.deleteResourcesAndKnowById(id,resourcesIds.get(i));
if(f<= 0){
return ResultUtils.error(ErrorCode.PARAMS_ERROR,"删除关系失败");
}
}
}
return ResultUtils.success("删除关系成功");
}
@Override
//查询课程下资源
public BaseResponse<Set<Resources>> queryResourcesByCourseId(String courseId){
// 判空,查询
KnowCourse knowCourse = knowRepository.queryCourse(courseId);
if(knowCourse == null){
return ResultUtils.error(ErrorCode.NOT_FOUND_ERROR,"课程不存在");
}
Set<Resources> resourcesSet = resourcesRepository.queryResourcesByCourseId(courseId);
return ResultUtils.success(resourcesSet);
}
@Override
//查询章节下资源
public BaseResponse<Set<Resources>> queryResourcesByChapterId(Long chapterId){
// 判空,查询
KnowChapter knowChapter = knowRepository.queryChapter(chapterId);
if(knowChapter == null){
return ResultUtils.error(ErrorCode.NOT_FOUND_ERROR,"章节不存在");
}
Set<Resources>resourcesSet ;
resourcesSet = resourcesRepository.queryResourcesByChapterId(chapterId);
return ResultUtils.success(resourcesSet);
}
@Override
//查询二级节点下资源
public BaseResponse<Set<Resources>> queryBesidesKnowToResources(Long knowId){
// 判空,查询
int i = knowRepository.queryNode(knowId);
if(i <= 0){
return ResultUtils.error(ErrorCode.NOT_FOUND_ERROR,"知识点不存在");
}
Set<Resources> resourcesSet = resourcesRepository.queryBesidesKnowToResources(knowId);
return ResultUtils.success(resourcesSet);
}
@Override
public BaseResponse<Set<Resources>> queryResourcesByKnowId(Long knowId) {
// 判空,查询
int i = knowRepository.queryNode(knowId);
if(i <= 0){
return ResultUtils.error(ErrorCode.NOT_FOUND_ERROR,"知识点不存在");
}
Set<Resources> resourcesSet = resourcesRepository.queryResourcesByKnowId(knowId);
return ResultUtils.success(resourcesSet);
}
}

@ -8,9 +8,12 @@ import com.teaching.backend.common.ErrorCode;
import com.teaching.backend.common.ResultUtils;
import com.teaching.backend.constant.ViewContentTypeEnum;
import com.teaching.backend.mapper.know.KnowRepository;
import com.teaching.backend.mapper.resource.ResourcesRepository;
import com.teaching.backend.model.dto.resource.BucketPolicyConfigDto;
import com.teaching.backend.model.dto.resource.ResourceUploadDto;
import com.teaching.backend.model.entity.know.KnowChapter;
import com.teaching.backend.model.entity.know.KnowCourse;
import com.teaching.backend.model.entity.resource.Resources;
import com.teaching.backend.service.resource.ResourceService;
import com.teaching.backend.utils.MinioUtils;
@ -47,6 +50,10 @@ public class ResourceServiceImpl implements ResourceService {
@Autowired
private ResourcesRepository resourcesRepository;
@Autowired
private KnowRepository knowRepository;
private static final Logger LOGGER = LoggerFactory.getLogger(ResourceService.class);
@Autowired
@ -108,69 +115,8 @@ public class ResourceServiceImpl implements ResourceService {
public ResponseEntity<InputStreamResource> readFile(String filename) {
return minioUtils.readFile(filename);
}
@Override
public BaseResponse<String> addResourcesAndKnowByCourseId(String courseId, List<Long> resourcesIds){
// todo 查询课程是否存在 ,资源是否存在
int count = resourcesRepository.addResourcesAndKnowByCourseId(courseId,resourcesIds);
if(count == resourcesIds.size()){
return ResultUtils.success("添加关系成功");
}else{
return ResultUtils.error(ErrorCode.OPERATION_ERROR,"添加失败");
}
}
@Override
public BaseResponse<String> addResourcesAndKnowByChapterId(Long chapterId, List<Long> resourcesIds){
// todo 查询章节是否存在 ,资源是否存在
int count = resourcesRepository.addResourcesAndKnowByChapterId(chapterId,resourcesIds);
if(count == resourcesIds.size()){
return ResultUtils.success("添加关系成功");
}else{
return ResultUtils.error(ErrorCode.OPERATION_ERROR,"添加失败");
}
}
@Override
public BaseResponse<String> addResourcesAndKnowById(Long id, List<Long> resourcesIds){
// todo 查询知识点是否存在 ,资源是否存在
int count = resourcesRepository.addResourcesAndKnowById(id,resourcesIds);
if(count == resourcesIds.size()){
return ResultUtils.success("添加关系成功");
}else{
return ResultUtils.error(ErrorCode.OPERATION_ERROR,"添加失败");
}
}
@Override
//查询课程下资源
public BaseResponse<Set<Resources>> queryResourcesByCourseId(String courseId){
// todo 判空,查询
Set<Resources>resourcesSet;
resourcesSet = resourcesRepository.queryResourcesByCourseId(courseId);
return ResultUtils.success(resourcesSet);
}
@Override
//查询章节下资源
public BaseResponse<Set<Resources>> queryResourcesByChapterId(Long chapterId){
// todo 判空,查询
Set<Resources>resourcesSet ;
resourcesSet = resourcesRepository.queryResourcesByChapterId(chapterId);
return ResultUtils.success(resourcesSet);
}
@Override
//查询二级节点下资源
public BaseResponse<Set<Resources>> queryBesidesKnowToResources(Long KnowId){
// todo 判空,查询
Set<Resources>resourcesSet ;
resourcesSet = resourcesRepository.queryBesidesKnowToResources(KnowId);
return ResultUtils.success(resourcesSet);
}
@Override
public BaseResponse<Set<Resources>> queryResourcesByKnowId(Long KnowId) {
// todo 判空,查询
Set<Resources>resourcesSet ;
resourcesSet = resourcesRepository.queryResourcesByKnowId(KnowId);
return ResultUtils.success(resourcesSet);
}
}

@ -13,6 +13,9 @@ import java.util.List;
* @Description:
*/
public interface KnowtmpService {
//查询
BaseResponse<Long> getAllKnows(String courseId);
@ -30,7 +33,7 @@ public interface KnowtmpService {
BaseResponse<Knowtmp> query(Long id);
//查询通过chapterId List
List<Knowtmp> queryByChapterId(Long chapterId);
BaseResponse<List<Knowtmp>> queryByChapterId(Long chapterId);
//查询通过chapterId List
List<Knowtmp> queryByChapterIdList(List<Long> chapterIdList);

@ -0,0 +1,39 @@
package com.teaching.backend.service.resource;
import com.teaching.backend.common.BaseResponse;
import com.teaching.backend.model.entity.resource.Resources;
import org.springframework.core.io.InputStreamResource;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;
import java.util.List;
import java.util.Set;
/**
* @Author:youhang
* @Date:2024-07-26-13:55
* @Description:
*/
public interface ResourceGraphService {
public BaseResponse<String> deleteResourcesAndKnowById(@RequestParam Long id, @RequestParam List<Long> resourcesIds);
BaseResponse<String> addResourcesByIdAndResourcesIds(Long id, List<Long> resourcesIds);
//查询课程下资源
BaseResponse<Set<Resources>> queryResourcesByCourseId(String courseId);
//查询章节下资源
BaseResponse<Set<Resources>> queryResourcesByChapterId(Long chapterId);
//查询二级节点下资源
BaseResponse<Set<Resources>> queryBesidesKnowToResources(Long knowId);
BaseResponse<Set<Resources>> queryResourcesByKnowId(Long knowId);
}

@ -7,6 +7,7 @@ import com.teaching.backend.model.entity.resource.Resources;
import org.springframework.core.io.InputStreamResource;
import org.springframework.data.neo4j.repository.query.Query;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;
import java.util.List;
@ -25,22 +26,6 @@ public interface ResourceService {
BaseResponse<String> delete(String filename) ;
ResponseEntity<InputStreamResource> readFile(String filename);
BaseResponse<String> addResourcesAndKnowByCourseId(String courseId, List<Long> resourcesIds);
BaseResponse<String> addResourcesAndKnowByChapterId(Long chapterId, List<Long> resourcesIds);
BaseResponse<String> addResourcesAndKnowById(Long id, List<Long> resourcesIds);
//查询课程下资源
BaseResponse<Set<Resources>> queryResourcesByCourseId(String courseId);
//查询章节下资源
BaseResponse<Set<Resources>> queryResourcesByChapterId(Long chapterId);
//查询二级节点下资源
BaseResponse<Set<Resources>> queryBesidesKnowToResources(Long KnowId);
BaseResponse<Set<Resources>> queryResourcesByKnowId(Long KnowId);
}

Loading…
Cancel
Save