知识图谱修改1 结合课程

master
youahng 4 months ago committed by yh
parent c9d9ffecb6
commit 847639f5a5
  1. 14
      src/main/java/com/teaching/backend/controller/KnowGraph/KnowController.java
  2. 5
      src/main/java/com/teaching/backend/mapper/KnowGraph/KnowRepository.java
  3. 38
      src/main/java/com/teaching/backend/model/dto/KnowGraph/KnowCourseCreateRequest.java
  4. 50
      src/main/java/com/teaching/backend/model/entity/KnowGraph/KnowCourse.java
  5. 7
      src/main/java/com/teaching/backend/model/vo/knowGraph/KnowVO.java
  6. 41
      src/main/java/com/teaching/backend/service/KnowGraph/KnowService.java

@ -7,12 +7,10 @@ package com.teaching.backend.controller.KnowGraph;
*/ */
import com.teaching.backend.common.BaseResponse; import com.teaching.backend.common.BaseResponse;
import com.teaching.backend.common.ResultUtils; import com.teaching.backend.common.ResultUtils;
import com.teaching.backend.model.dto.KnowGraph.BaseKnowReturn; import com.teaching.backend.model.dto.KnowGraph.*;
import com.teaching.backend.model.dto.KnowGraph.KnowRequest;
import com.teaching.backend.model.dto.KnowGraph.KnowUpdateRequest;
import com.teaching.backend.model.dto.KnowGraph.RelationshipKnowRequest;
import com.teaching.backend.model.entity.KnowGraph.Know; import com.teaching.backend.model.entity.KnowGraph.Know;
import com.teaching.backend.model.entity.KnowGraph.KnowCourse;
import com.teaching.backend.service.KnowGraph.KnowService; import com.teaching.backend.service.KnowGraph.KnowService;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@ -41,6 +39,12 @@ public class KnowController {
return knowService.createKnow(knowRequest); return knowService.createKnow(knowRequest);
} }
//添加知识点 - 课程
@PostMapping("/addKnowCourse")
public KnowCourse createCourseKnow(@RequestBody KnowCourseCreateRequest knowCourseCreateRequest) {
return knowService.createCourseKnow(knowCourseCreateRequest);
}
//修改知识点 //修改知识点
@PostMapping ("/update") @PostMapping ("/update")
public Know updateKnow(@RequestBody KnowUpdateRequest knowUpdateRequest) { public Know updateKnow(@RequestBody KnowUpdateRequest knowUpdateRequest) {
@ -67,7 +71,7 @@ public class KnowController {
} }
@GetMapping("/all") @GetMapping("/all")
public BaseResponse<BaseKnowReturn> getKnowAll(@RequestParam Long id) { public BaseResponse<BaseKnowReturn> getKnowAll(@RequestParam String id) {
BaseKnowReturn baseKnowReturn =knowService.getKnowAll(id); BaseKnowReturn baseKnowReturn =knowService.getKnowAll(id);
return ResultUtils.success(baseKnowReturn); return ResultUtils.success(baseKnowReturn);
} }

@ -7,7 +7,9 @@ package com.teaching.backend.mapper.KnowGraph;
*/ */
import com.teaching.backend.model.dto.KnowGraph.KnowCourseCreateRequest;
import com.teaching.backend.model.entity.KnowGraph.Know; import com.teaching.backend.model.entity.KnowGraph.Know;
import com.teaching.backend.model.entity.KnowGraph.KnowCourse;
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;
@ -26,6 +28,9 @@ public interface KnowRepository extends Neo4jRepository<Know, Long> {
List<Know> queryKnowAllKnowById(Long id); List<Know> queryKnowAllKnowById(Long id);
@Query("CREATE (n:Know {name: $name, courseId: $courseId,info:$info,resourceList:$resourceList}) return n")
KnowCourse createKnowCourse(String courseId, String name, String info, List<Integer>resourceList);
} }

@ -0,0 +1,38 @@
package com.teaching.backend.model.dto.KnowGraph;
import lombok.Data;
import org.springframework.data.neo4j.core.schema.Property;
import java.io.Serializable;
import java.util.List;
@Data
public class KnowCourseCreateRequest implements Serializable {
/**
* 知识点名称
*/
private String courseId;
/**
* 知识点名称
*/
private String name;
/**
* 信息
*/
private String info;
/**
* 知识点所关联的资源
*/
@Property
private List<Integer> resourceList;
}

@ -0,0 +1,50 @@
package com.teaching.backend.model.entity.KnowGraph;
import lombok.Data;
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;
import java.io.Serializable;
import java.util.List;
@Node
@Data
public class KnowCourse implements Serializable {
/**
* id
*/
@Id
@GeneratedValue
private Long id;
/**
* 知识点名称
*/
private String courseId;
/**
* 知识点名称
*/
@Property
private String name;
/**
* 信息
*/
@Property
private String info;
/**
* 知识点所关联的资源
*/
@Property
private List<Integer> resourceList;
}

@ -24,13 +24,8 @@ public class KnowVO implements Serializable {
/** /**
* 信息 * 信息
*/ */
private Long group; private String color;
/**
* 知识点所关联的资源
*/
private List<Integer> resourceList;
} }

@ -1,11 +1,9 @@
package com.teaching.backend.service.KnowGraph; package com.teaching.backend.service.KnowGraph;
import com.teaching.backend.mapper.KnowGraph.KnowRepository; import com.teaching.backend.mapper.KnowGraph.KnowRepository;
import com.teaching.backend.model.dto.KnowGraph.BaseKnowReturn; import com.teaching.backend.model.dto.KnowGraph.*;
import com.teaching.backend.model.dto.KnowGraph.KnowRequest;
import com.teaching.backend.model.dto.KnowGraph.KnowUpdateRequest;
import com.teaching.backend.model.dto.KnowGraph.RelationshipKnowRequest;
import com.teaching.backend.model.entity.KnowGraph.Know; import com.teaching.backend.model.entity.KnowGraph.Know;
import com.teaching.backend.model.entity.KnowGraph.KnowCourse;
import com.teaching.backend.model.entity.KnowGraph.Links; import com.teaching.backend.model.entity.KnowGraph.Links;
import com.teaching.backend.model.vo.knowGraph.KnowVO; import com.teaching.backend.model.vo.knowGraph.KnowVO;
import org.neo4j.driver.internal.InternalRelationship; import org.neo4j.driver.internal.InternalRelationship;
@ -46,6 +44,11 @@ public class KnowService {
return knowRepository.save(know); return knowRepository.save(know);
} }
public KnowCourse createCourseKnow(KnowCourseCreateRequest knowCourseCreateRequest ) {
return knowRepository.createKnowCourse(knowCourseCreateRequest.getCourseId(),knowCourseCreateRequest.getName(),knowCourseCreateRequest.getInfo(),knowCourseCreateRequest.getResourceList());
}
public void deleteKnow(Long id) { public void deleteKnow(Long id) {
knowRepository.deleteById(id); knowRepository.deleteById(id);
@ -67,9 +70,16 @@ public class KnowService {
} }
public BaseKnowReturn getKnowAll(Long id) { public BaseKnowReturn getKnowAll(String id) {
Collection<Map<String, Object>> all = Collection<Map<String, Object>> all =
neo4jClient.query( "match(n:Know)-[r*0..]->(p:Know) where ID(n) = "+id+" return n as `n`,r as `r`,p as `p`,length(r) as `d`").fetch().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(); Iterator<Map<String, Object>> iterator = all.iterator();
Set<KnowVO> knowList = new HashSet<>(); Set<KnowVO> knowList = new HashSet<>();
@ -80,15 +90,17 @@ public class KnowService {
int p = 0; int p = 0;
while (iterator.hasNext()) { while (iterator.hasNext()) {
Map<String, Object> element = iterator.next(); Map<String, Object> element = iterator.next();
Long group = (Long) element.get("d");
knowVO = new KnowVO(); knowVO = new KnowVO();
Node node1 = (Node) element.get("p"); Node node1 = (Node) element.get("p");
Long group = (Long) element.get("d");
knowVO.setColor(colorChoose.get(group));
Long id1 = node1.id(); Long id1 = node1.id();
String name1 = node1.get("name").asString(); String name1 = node1.get("name").asString();
// String info1 = node1.get("info").asString();
knowVO.setId(id1); knowVO.setId(id1);
knowVO.setLabel(name1); knowVO.setLabel(name1);
knowVO.setGroup(group);
knowList.add(knowVO); knowList.add(knowVO);
node2 = (List) element.get("r"); node2 = (List) element.get("r");
@ -112,6 +124,12 @@ public class KnowService {
public BaseKnowReturn getKnowById(Long id) { public BaseKnowReturn getKnowById(Long id) {
Collection<Map<String, Object>> all = 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(); 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(); Iterator<Map<String, Object>> iterator = all.iterator();
Set<KnowVO> knowList = new HashSet<>(); Set<KnowVO> knowList = new HashSet<>();
@ -123,15 +141,14 @@ public class KnowService {
while (iterator.hasNext()) { while (iterator.hasNext()) {
Map<String, Object> element = iterator.next(); Map<String, Object> element = iterator.next();
Long group = (Long) element.get("d");
knowVO = new KnowVO(); knowVO = new KnowVO();
Node node1 = (Node) element.get("p"); Node node1 = (Node) element.get("p");
Long group = (Long) element.get("d");
knowVO.setColor(colorChoose.get(group));
Long id1 = node1.id(); Long id1 = node1.id();
String name1 = node1.get("name").asString(); String name1 = node1.get("name").asString();
// String info1 = node1.get("info").asString();
knowVO.setId(id1); knowVO.setId(id1);
knowVO.setLabel(name1); knowVO.setLabel(name1);
knowVO.setGroup(group);
knowList.add(knowVO); knowList.add(knowVO);
node2 = (List) element.get("r"); node2 = (List) element.get("r");

Loading…
Cancel
Save