资源整合

master
youahng 5 months ago committed by yh
parent 0592c2ed53
commit d74ca8b622
  1. 14
      src/main/java/com/teaching/backend/controller/Know/KnowController.java
  2. 2
      src/main/java/com/teaching/backend/controller/Knowtmp/KnowtmpController.java
  3. 1
      src/main/java/com/teaching/backend/controller/records/ResourceLearningRecordController.java
  4. 2
      src/main/java/com/teaching/backend/controller/resource/ResourceController.java
  5. 22
      src/main/java/com/teaching/backend/mapper/know/KnowRepository.java
  6. 2
      src/main/java/com/teaching/backend/mapper/resource/ResourcesRepository.java
  7. 10
      src/main/java/com/teaching/backend/model/entity/know/KnowChapter.java
  8. 8
      src/main/java/com/teaching/backend/model/entity/know/KnowCourse.java
  9. 10
      src/main/java/com/teaching/backend/service/Know/KnowService.java
  10. 110
      src/main/java/com/teaching/backend/service/impl/know/knowServiceImpl.java
  11. 14
      src/main/java/com/teaching/backend/service/impl/knowtmp/KnowtmpServiceImpl.java
  12. 4
      src/main/java/com/teaching/backend/service/impl/resource/ResourceServiceImpl.java
  13. 5
      src/main/java/com/teaching/backend/service/knowtmp/KnowtmpService.java
  14. 2
      src/main/java/com/teaching/backend/service/resource/ResourceService.java

@ -28,6 +28,20 @@ public class KnowController {
@Autowired @Autowired
private KnowService knowService; private KnowService knowService;
// 添加全部知识点
@PostMapping("/addAllKnow")
BaseResponse<String> addAllKnow(@RequestParam String courseId){
return knowService.addAllKnow(courseId);
}
// 添加知识点与资源的关系
@PostMapping("/addRelationship/Withresources")
BaseResponse<String> addRelationshipWithresources(@RequestParam Long id,@RequestParam Long resourceId){
return knowService.addRelationshipWithresources(id,resourceId);
}
//===================
// 添加知识点 // 添加知识点
@PostMapping("/addKnow") @PostMapping("/addKnow")
BaseResponse<String> addKnow(@RequestBody KnowRequest knowRequest){ BaseResponse<String> addKnow(@RequestBody KnowRequest knowRequest){

@ -50,7 +50,7 @@ public class KnowtmpController {
} }
//查询通过chapterId List //查询通过chapterId List
@GetMapping("/queryKnow") @GetMapping("/queryKnow")
BaseResponse<List<Knowtmp>> queryByChapterId(Long chapterId){ List<Knowtmp> queryByChapterId(Long chapterId){
return knowtmpService.queryByChapterId(chapterId); return knowtmpService.queryByChapterId(chapterId);
} }
} }

@ -25,6 +25,7 @@
//@RestController //@RestController
//@RequestMapping("/api/resourcelearningrecords") //@RequestMapping("/api/resourcelearningrecords")
//public class ResourceLearningRecordController { //public class ResourceLearningRecordController {
// @Resource // @Resource
// private ResourceLearningRecordServiceImpl resourceLearningRecordService; // private ResourceLearningRecordServiceImpl resourceLearningRecordService;
// @Resource // @Resource

@ -32,7 +32,7 @@ public class ResourceController {
//添加知识点 //添加知识点
@PostMapping("/upload") @PostMapping("/upload")
@ResponseBody @ResponseBody
public BaseResponse<ResourceUploadDto> uploadFile(@RequestPart("file") MultipartFile file) { public BaseResponse<Resources> uploadFile(@RequestPart("file") MultipartFile file) {
return resourceService.upload(file); return resourceService.upload(file);
} }

@ -14,12 +14,15 @@ import com.teaching.backend.model.entity.resource.Resources;
import org.springframework.data.neo4j.repository.Neo4jRepository; import org.springframework.data.neo4j.repository.Neo4jRepository;
import org.springframework.data.neo4j.repository.query.Query; import org.springframework.data.neo4j.repository.query.Query;
import java.util.List;
import java.util.Set; import java.util.Set;
public interface KnowRepository extends Neo4jRepository<Know, Long> { public interface KnowRepository extends Neo4jRepository<Know, Long> {
@Query("CREATE (n:Know {name: $name,info:$info}) return count(n)") //======================
int addKnow(String name,String info);
@Query("CREATE (n:Know {name: $name,info:$info}) return n;")
Know addKnow(String name,String info);
@Query("MATCH ID(p:Know) = $id SET p.name = $name set p.info= $info RETURN count(p);") @Query("MATCH ID(p:Know) = $id SET p.name = $name set p.info= $info RETURN count(p);")
@ -63,4 +66,19 @@ public interface KnowRepository extends Neo4jRepository<Know, Long> {
@Query("MATCH (p:Know)-[:FatherAndSon]->(n:Know)-[:resources]->(m:Resources) WHERE ID(p) = $id RETURN m") @Query("MATCH (p:Know)-[:FatherAndSon]->(n:Know)-[:resources]->(m:Resources) WHERE ID(p) = $id RETURN m")
Set<Resources> queryBesidesKnowToResources(Long id); Set<Resources> queryBesidesKnowToResources(Long id);
//建立关系 课程 - 章节
@Query("MATCH (p:Know {courseId: $courseId}), (c:Know {chapterId: $chapterId}) CREATE (p)-[r:FatherAndSon]->(c) return count(r);")
int addFatherAndSonWithCourse(String courseId,Long chapterId);
//建立关系 章节与章节
@Query("MATCH (p:Know {chapterId: $chapterId1}), (c:Know {chapterId: $chapterId2}) CREATE (c)-[r:FatherAndSon]->(p) return count(r);")
int addFatherAndSonWithChapter(Long chapterId1,Long chapterId2);
//建立关系 章节与知识点
@Query("MATCH (p:Know), (j:Know) WHERE p.chapterId= $chapterId AND ID(j) = $id CREATE (p)-[r:FatherAndSon]->(j) return count(r);")
int addFatherAndSonWithKnow(Long id,Long chapterId);
@Query("MATCH (p:Know), (c:Resources) WHERE ID(p) = $id AND ID(c) = $ResourcesId CREATE (p)-[r:resources]->(c) return count(r)")
int addResourceResourcesKnow(Long id, Long ResourcesId);
} }

@ -38,7 +38,7 @@ public interface ResourcesRepository extends Neo4jRepository<Resources, Long> {
Set<Resources> queryResourcesByCourseId(String courseId); Set<Resources> queryResourcesByCourseId(String courseId);
//查询章节下资源 //查询章节下资源
@Query("MATCH p = (a:Know)-[rels*]-(b:Resources) WHERE a.chapterId = chapterId and ANY(rel IN rels WHERE TYPE(rel) = 'resources') RETURN b") @Query("MATCH p = (a:Know)-[rels*]-(b:Resources) WHERE a.chapterId = $chapterId and ANY(rel IN rels WHERE TYPE(rel) = 'resources') RETURN b")
Set<Resources> queryResourcesByChapterId(Long chapterId); Set<Resources> queryResourcesByChapterId(Long chapterId);
//查询二级节点下资源 //查询二级节点下资源

@ -8,7 +8,7 @@ import org.springframework.data.neo4j.core.schema.Property;
import java.io.Serializable; import java.io.Serializable;
@Node
@Data @Data
public class KnowChapter implements Serializable { public class KnowChapter implements Serializable {
@ -16,26 +16,26 @@ public class KnowChapter implements Serializable {
/** /**
* id * id
*/ */
@Id
@GeneratedValue
private Long id; private Long id;
/** /**
* 章节id * 章节id
*/ */
private Long chapterId; private Long chapterId;
/** /**
* 知识点名称 * 知识点名称
*/ */
@Property
private String name; private String name;
/** /**
* 信息 * 信息
*/ */
@Property
private String info; private String info;

@ -8,7 +8,6 @@ import org.springframework.data.neo4j.core.schema.Property;
import java.io.Serializable; import java.io.Serializable;
@Node
@Data @Data
public class KnowCourse implements Serializable { public class KnowCourse implements Serializable {
@ -16,26 +15,25 @@ public class KnowCourse implements Serializable {
/** /**
* id * id
*/ */
@Id
@GeneratedValue
private Long id; private Long id;
/** /**
* 课程id * 课程id
*/ */
private String courseId; private String courseId;
/** /**
* 知识点名称 * 知识点名称
*/ */
@Property
private String name; private String name;
/** /**
* 信息 * 信息
*/ */
@Property
private String info; private String info;

@ -7,6 +7,7 @@ import com.teaching.backend.model.entity.know.KnowChapter;
import com.teaching.backend.model.entity.know.KnowCourse; import com.teaching.backend.model.entity.know.KnowCourse;
import com.teaching.backend.model.entity.resource.Resources; import com.teaching.backend.model.entity.resource.Resources;
import com.teaching.backend.model.vo.knowGraph.KnowVO1; import com.teaching.backend.model.vo.knowGraph.KnowVO1;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.Set; import java.util.Set;
@ -17,6 +18,15 @@ import java.util.Set;
*/ */
public interface KnowService { public interface KnowService {
//通过courseId 添加所有节点
BaseResponse<String> addAllKnow(String courseId);
BaseResponse<String> addRelationshipWithresources(Long id, Long resourceId);
//=====================
// 添加知识点 // 添加知识点
BaseResponse<String> addKnow(KnowRequest knowRequest); BaseResponse<String> addKnow(KnowRequest knowRequest);

@ -1,27 +1,36 @@
package com.teaching.backend.service.impl.know; package com.teaching.backend.service.impl.know;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.teaching.backend.common.BaseResponse; import com.teaching.backend.common.BaseResponse;
import com.teaching.backend.common.ErrorCode; import com.teaching.backend.common.ErrorCode;
import com.teaching.backend.common.ResultUtils; import com.teaching.backend.common.ResultUtils;
import com.teaching.backend.mapper.chapter.ChapterMapper;
import com.teaching.backend.mapper.courses.CoursesMapper;
import com.teaching.backend.mapper.know.KnowRepository; import com.teaching.backend.mapper.know.KnowRepository;
import com.teaching.backend.model.dto.Know.*; import com.teaching.backend.model.dto.Know.*;
import com.teaching.backend.model.entity.chapter.Chapter;
import com.teaching.backend.model.entity.courses.Courses;
import com.teaching.backend.model.entity.know.Know; import com.teaching.backend.model.entity.know.Know;
import com.teaching.backend.model.entity.know.KnowChapter; import com.teaching.backend.model.entity.know.KnowChapter;
import com.teaching.backend.model.entity.know.KnowCourse; import com.teaching.backend.model.entity.know.KnowCourse;
import com.teaching.backend.model.entity.know.Links; import com.teaching.backend.model.entity.know.Links;
import com.teaching.backend.model.entity.knowtmp.Knowtmp;
import com.teaching.backend.model.entity.resource.Resources; import com.teaching.backend.model.entity.resource.Resources;
import com.teaching.backend.model.vo.knowGraph.KnowVO; import com.teaching.backend.model.vo.knowGraph.KnowVO;
import com.teaching.backend.model.vo.knowGraph.KnowVO1; import com.teaching.backend.model.vo.knowGraph.KnowVO1;
import com.teaching.backend.service.Know.KnowService; import com.teaching.backend.service.Know.KnowService;
import com.teaching.backend.service.knowtmp.KnowtmpService;
import org.neo4j.driver.internal.InternalRelationship; import org.neo4j.driver.internal.InternalRelationship;
import org.neo4j.driver.types.Node; import org.neo4j.driver.types.Node;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.neo4j.core.Neo4jClient; import org.springframework.data.neo4j.core.Neo4jClient;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.*; import java.util.*;
import java.util.stream.Collectors;
/** /**
* @Author:youhang * @Author:youhang
@ -34,15 +43,108 @@ public class knowServiceImpl implements KnowService {
@Autowired @Autowired
private KnowRepository knowRepository; private KnowRepository knowRepository;
@Autowired
private ChapterMapper chapterMapper;
@Autowired
private KnowtmpService knowtmpService;
@Autowired
CoursesMapper coursesMapper;
@Resource @Resource
private Neo4jClient neo4jClient; private Neo4jClient neo4jClient;
public BaseResponse<String> addRelationshipWithresources(Long id, Long resourceId){
int f = knowRepository.addResourceResourcesKnow(id,resourceId);
if(f <= 0){
throw new RuntimeException("添加关系失败");
}
return ResultUtils.success("添加关系成功");
}
@Override
public BaseResponse<String> addAllKnow(String courseId) {
try {
addAllKnowTransation(courseId) ;
}catch (Exception e){
e.printStackTrace();
return ResultUtils.error(ErrorCode.OPERATION_ERROR,e.getMessage());
}
//6.返回成功信息,关闭事务
return ResultUtils.success("添加成功");
}
@Transactional
// todo 事务没有正确使用
public void addAllKnowTransation(String courseId) throws Exception{
// 2.从课程表查出课程节点 并添加到 neo
Courses courses = coursesMapper.selectById(courseId);
int f = knowRepository.addCourse(courseId,courses.getName(),courses.getDescription());
if(f <= 0){
throw new RuntimeException("添加课程失败");
}
// 3 从章节表查出章节节点 并添加到 neo
List<Chapter> chapterList = chapterMapper.selectSectionsByCourseId(courseId);
for (int i = 0; i < chapterList.size(); i++) {
Chapter chapter = chapterList.get(i);
f =knowRepository.addChapter(chapter.getId(),chapter.getName(),chapter.getContent());
if(f <= 0){
throw new RuntimeException("添加章节失败");
}
}
List<Long> idList = chapterList.stream()
.map(menu -> menu.getId())
.collect(Collectors.toList());
//获取chapterId 查询知识点 返回知识点集合
List<Knowtmp> knowlist = knowtmpService.queryByChapterIdList(idList);
for (int i = 0; i < idList.size(); i++) {
List<Knowtmp> knowlist1 = knowtmpService.queryByChapterId(idList.get(i));
for (int j = 0; j < knowlist1.size(); j++) {
Know know = knowRepository.addKnow(knowlist1.get(j).getName(),knowlist1.get(j).getInfo());
if(know == null){
throw new RuntimeException("添加知识点失败");
}
f = knowRepository.addFatherAndSonWithKnow(know.getId(),idList.get(i));
if(f <= 0){
throw new RuntimeException("添加知识点-章节失败");
}
}
}
for (int i = 0; i < chapterList.size(); i++) {
Chapter chapter = chapterList.get(i);
if(chapter.getPid()== 0){
f = knowRepository.addFatherAndSonWithCourse(chapter.getCourseId(),chapter.getId());
if(f <= 0) throw new RuntimeException("添加课程-章节关系失败");
}else{
f = knowRepository.addFatherAndSonWithChapter(chapter.getId(),chapter.getPid());
if(f <= 0) throw new RuntimeException("添加章节-章节关系失败");
}
}
// for (int j = 0; j < knowlist.size(); j++) {
// Knowtmp knowtmp = knowlist.get(j);
// f = knowRepository.addFatherAndSonWithKnow(knowtmp.getId(),knowtmp.getChapterid());
// if(f <= 0) throw new RuntimeException("添加章节-知识点关系失败");
// }
}
@Override @Override
public BaseResponse<String> addKnow(KnowRequest knowRequest) { public BaseResponse<String> addKnow(KnowRequest knowRequest) {
Know know = new Know(); Know know = new Know();
BeanUtils.copyProperties(knowRequest,know); BeanUtils.copyProperties(knowRequest,know);
int f = knowRepository.addKnow(know.getName(),know.getInfo()); Know know1 = knowRepository.addKnow(know.getName(),know.getInfo());
if(f > 0){ if(know1 != null){
return ResultUtils.success("添加知识点成功"); return ResultUtils.success("添加知识点成功");
}else{ }else{
return ResultUtils.error(ErrorCode.OPERATION_ERROR,"添加知识点失败"); return ResultUtils.error(ErrorCode.OPERATION_ERROR,"添加知识点失败");
@ -132,9 +234,9 @@ public class knowServiceImpl implements KnowService {
BeanUtils.copyProperties(knowChapterCreateRequest,knowChapter); BeanUtils.copyProperties(knowChapterCreateRequest,knowChapter);
int f = knowRepository.addChapter(knowChapter.getChapterId(),knowChapter.getName(),knowChapter.getInfo()); int f = knowRepository.addChapter(knowChapter.getChapterId(),knowChapter.getName(),knowChapter.getInfo());
if(f>0){ if(f>0){
return ResultUtils.success("添加知识点成功"); return ResultUtils.success("添加章节成功");
}else{ }else{
return ResultUtils.error(ErrorCode.OPERATION_ERROR,"添加知识点失败"); return ResultUtils.error(ErrorCode.OPERATION_ERROR,"添加章节失败");
} }
} }

@ -69,11 +69,19 @@ public class KnowtmpServiceImpl implements KnowtmpService {
} }
@Override @Override
public BaseResponse<List<Knowtmp>> queryByChapterId(Long chapterId) { public List<Knowtmp> queryByChapterId(Long chapterId) {
Knowtmp knowtmp = new Knowtmp(); Knowtmp knowtmp = new Knowtmp();
final QueryWrapper<Knowtmp> knowtmpQueryWrapper = new QueryWrapper<>(); QueryWrapper<Knowtmp> knowtmpQueryWrapper = new QueryWrapper<>();
knowtmpQueryWrapper.eq("chapterId",chapterId); knowtmpQueryWrapper.eq("chapterId",chapterId);
List<Knowtmp> knowtmps = knowtmpMapper.selectList(knowtmpQueryWrapper); List<Knowtmp> knowtmps = knowtmpMapper.selectList(knowtmpQueryWrapper);
return ResultUtils.success(knowtmps); return knowtmps;
}
@Override
public List<Knowtmp> queryByChapterIdList(List<Long> chapterIdList) {
QueryWrapper<Knowtmp> knowtmpQueryWrapper = new QueryWrapper<>();
knowtmpQueryWrapper.in("chapterId",chapterIdList);
List<Knowtmp> knowtmps = knowtmpMapper.selectList(knowtmpQueryWrapper);
return knowtmps;
} }
} }

@ -67,7 +67,7 @@ public class ResourceServiceImpl implements ResourceService {
private Neo4jClient neo4jClient; private Neo4jClient neo4jClient;
@Override @Override
public BaseResponse<ResourceUploadDto> upload(MultipartFile file) { public BaseResponse<Resources> upload(MultipartFile file) {
ResourceUploadDto resourceUploadDto = minioUtils.upload(file); ResourceUploadDto resourceUploadDto = minioUtils.upload(file);
if (resourceUploadDto == null) { if (resourceUploadDto == null) {
return ResultUtils.error(ErrorCode.OPERATION_ERROR, "上传失败"); return ResultUtils.error(ErrorCode.OPERATION_ERROR, "上传失败");
@ -83,7 +83,7 @@ public class ResourceServiceImpl implements ResourceService {
resource.setUrl(url); resource.setUrl(url);
resourcesRepository.save(resource); resourcesRepository.save(resource);
return ResultUtils.success(resourceUploadDto); return ResultUtils.success(resource);
} }
@Override @Override

@ -26,6 +26,9 @@ public interface KnowtmpService {
BaseResponse<Knowtmp> query(Long id); BaseResponse<Knowtmp> query(Long id);
//查询通过chapterId List //查询通过chapterId List
BaseResponse<List<Knowtmp>> queryByChapterId(Long chapterId); List<Knowtmp> queryByChapterId(Long chapterId);
//查询通过chapterId List
List<Knowtmp> queryByChapterIdList(List<Long> chapterIdList);
} }

@ -20,7 +20,7 @@ import java.util.Set;
public interface ResourceService { public interface ResourceService {
BaseResponse<ResourceUploadDto> upload(MultipartFile file) ; BaseResponse<Resources> upload(MultipartFile file) ;
BaseResponse<String> delete(String filename) ; BaseResponse<String> delete(String filename) ;

Loading…
Cancel
Save