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