|
|
|
@ -1,27 +1,36 @@ |
|
|
|
|
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.ErrorCode; |
|
|
|
|
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.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.KnowChapter; |
|
|
|
|
import com.teaching.backend.model.entity.know.KnowCourse; |
|
|
|
|
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.vo.knowGraph.KnowVO; |
|
|
|
|
import com.teaching.backend.model.vo.knowGraph.KnowVO1; |
|
|
|
|
import com.teaching.backend.service.Know.KnowService; |
|
|
|
|
import com.teaching.backend.service.knowtmp.KnowtmpService; |
|
|
|
|
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.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
|
import java.util.*; |
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @Author:youhang |
|
|
|
@ -34,15 +43,108 @@ public class knowServiceImpl implements KnowService { |
|
|
|
|
@Autowired |
|
|
|
|
private KnowRepository knowRepository; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
private ChapterMapper chapterMapper; |
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
private KnowtmpService knowtmpService; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
CoursesMapper coursesMapper; |
|
|
|
|
|
|
|
|
|
@Resource |
|
|
|
|
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 |
|
|
|
|
public BaseResponse<String> addKnow(KnowRequest knowRequest) { |
|
|
|
|
Know know = new Know(); |
|
|
|
|
BeanUtils.copyProperties(knowRequest,know); |
|
|
|
|
int f = knowRepository.addKnow(know.getName(),know.getInfo()); |
|
|
|
|
if(f > 0){ |
|
|
|
|
Know know1 = knowRepository.addKnow(know.getName(),know.getInfo()); |
|
|
|
|
if(know1 != null){ |
|
|
|
|
return ResultUtils.success("添加知识点成功"); |
|
|
|
|
}else{ |
|
|
|
|
return ResultUtils.error(ErrorCode.OPERATION_ERROR,"添加知识点失败"); |
|
|
|
@ -85,8 +187,8 @@ public class knowServiceImpl implements KnowService { |
|
|
|
|
public BaseResponse<String> addCourse(KnowCourseCreateRequest knowCourseCreateRequest) { |
|
|
|
|
KnowCourse knowCourse = new KnowCourse(); |
|
|
|
|
BeanUtils.copyProperties(knowCourseCreateRequest,knowCourse); |
|
|
|
|
int f = knowRepository.addCourse(knowCourse.getCourseId(),knowCourse.getName(),knowCourse.getInfo()); |
|
|
|
|
if(f > 0){ |
|
|
|
|
int f = knowRepository.addCourse(knowCourse.getCourseId(),knowCourse.getName(),knowCourse.getInfo()); |
|
|
|
|
if(f >0){ |
|
|
|
|
return ResultUtils.success("添加知识点成功"); |
|
|
|
|
}else{ |
|
|
|
|
return ResultUtils.error(ErrorCode.OPERATION_ERROR,"添加知识点失败"); |
|
|
|
@ -130,11 +232,11 @@ public class knowServiceImpl implements KnowService { |
|
|
|
|
public BaseResponse<String> addChapter(KnowChapterCreateRequest knowChapterCreateRequest) { |
|
|
|
|
KnowChapter knowChapter = new KnowChapter(); |
|
|
|
|
BeanUtils.copyProperties(knowChapterCreateRequest,knowChapter); |
|
|
|
|
int f = knowRepository.addChapter(knowChapter.getChapterId(),knowChapter.getName(),knowChapter.getInfo()); |
|
|
|
|
if(f > 0){ |
|
|
|
|
return ResultUtils.success("添加知识点成功"); |
|
|
|
|
int f = knowRepository.addChapter(knowChapter.getChapterId(),knowChapter.getName(),knowChapter.getInfo()); |
|
|
|
|
if(f>0){ |
|
|
|
|
return ResultUtils.success("添加章节成功"); |
|
|
|
|
}else{ |
|
|
|
|
return ResultUtils.error(ErrorCode.OPERATION_ERROR,"添加知识点失败"); |
|
|
|
|
return ResultUtils.error(ErrorCode.OPERATION_ERROR,"添加章节失败"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|