知识点xiugai

master
you hang 3 months ago committed by youhang20021127
parent fac39973ea
commit 76a984b533
  1. 10
      src/main/java/com/teaching/backend/controller/Know/KnowController.java
  2. 21
      src/main/java/com/teaching/backend/controller/Know/KnowPathVO.java
  3. 8
      src/main/java/com/teaching/backend/controller/resource/ResourceGraphController.java
  4. 6
      src/main/java/com/teaching/backend/mapper/know/KnowRepository.java
  5. 24
      src/main/java/com/teaching/backend/mapper/resource/ResourcesRepository.java
  6. 4
      src/main/java/com/teaching/backend/service/Know/KnowService.java
  7. 161
      src/main/java/com/teaching/backend/service/impl/know/knowServiceImpl.java
  8. 41
      src/main/java/com/teaching/backend/service/impl/resource/ResourceGraphServiceImpl.java
  9. 4
      src/main/java/com/teaching/backend/service/resource/ResourceGraphService.java

@ -47,7 +47,7 @@ public class KnowController {
//生成知识点学习路径 默认从第一个知识点到第最后个知识点 //生成知识点学习路径 默认从第一个知识点到第最后个知识点
@ApiOperation(value = "生成知识点学习路径") @ApiOperation(value = "生成知识点学习路径")
@GetMapping("/knowLearnPath") @GetMapping("/knowLearnPath")
BaseResponse<BaseKnowReturn> knowLearnPath(@RequestParam String corseId){ BaseResponse<List<KnowPathVO>> knowLearnPath(@RequestParam String corseId){
return knowService.knowLearnPath(corseId); return knowService.knowLearnPath(corseId);
} }
@ -58,6 +58,13 @@ public class KnowController {
return knowService.getNodeByDepth(id,depth); return knowService.getNodeByDepth(id,depth);
} }
//通过courseId 返回depth层知识点
@ApiOperation(value = "通过courseId-返回depth层知识点")
@GetMapping("/getDepthNodeByCourseId")
BaseResponse<BaseKnowReturn> getDepthNodeByCourseId(@RequestParam String courseId,@RequestParam Long depth){
return knowService.getDepthNodeByCourseId(courseId,depth);
}
//返回课程下指定关系的知识图谱 //返回课程下指定关系的知识图谱
@ApiOperation(value = "返回课程下指定关系的知识图谱") @ApiOperation(value = "返回课程下指定关系的知识图谱")
@ -65,6 +72,7 @@ public class KnowController {
BaseResponse<BaseKnowReturn> getRelsNodesByCourseId(@RequestParam String courseId,@RequestParam List<String>types){ BaseResponse<BaseKnowReturn> getRelsNodesByCourseId(@RequestParam String courseId,@RequestParam List<String>types){
return knowService.getRelsNodesByCourseId(courseId,types); return knowService.getRelsNodesByCourseId(courseId,types);
} }
//返回知识点的前后知识点 //返回知识点的前后知识点
@ApiOperation(value = "返回知识点的前后知识点") @ApiOperation(value = "返回知识点的前后知识点")
@GetMapping("/getFontedAndBackKnows") @GetMapping("/getFontedAndBackKnows")

@ -0,0 +1,21 @@
package com.teaching.backend.controller.Know;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
/**
* @Author:youhang
* @Date:2024-08-29-11:23
* @Description:
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class KnowPathVO {
private List<String>nodeList;
private Double weight;
}

@ -35,14 +35,14 @@ public class ResourceGraphController {
@GetMapping("/addRelationship/BetweenKnowAndResources") @GetMapping("/addRelationship/BetweenKnowAndResources")
@ApiOperation(value = "添加知识点资源关系") @ApiOperation(value = "添加知识点资源关系")
public BaseResponse<String> addResourcesByIdAndResourcesIds(@RequestParam Long id,@RequestParam List<Long> resourcesIds){ public BaseResponse<String> addResourcesByIdAndResourcesId(@RequestParam Long id,@RequestParam Long resourcesId){
return resourceGraphService.addResourcesByIdAndResourcesIds(id,resourcesIds); return resourceGraphService.addResourcesByIdAndResourcesId(id,resourcesId);
} }
@GetMapping("/deleteRelationship/BetweenKnowAndResources") @GetMapping("/deleteRelationship/BetweenKnowAndResources")
@ApiOperation(value = "删除知识点资源关系") @ApiOperation(value = "删除知识点资源关系")
public BaseResponse<String> deleteResourcesAndKnowById(@RequestParam Long id, @RequestParam List<Long> resourcesIds){ public BaseResponse<String> deleteResourcesAndKnowById(@RequestParam Long id, @RequestParam Long resourcesId){
return resourceGraphService.deleteResourcesAndKnowById(id,resourcesIds); return resourceGraphService.deleteResourcesAndKnowById(id,resourcesId);
} }
//查询课程下资源 //查询课程下资源

@ -23,7 +23,7 @@ import java.util.Set;
public interface KnowRepository extends Neo4jRepository<Know, Long> { 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);") @Query("MATCH (n:Know) WHERE n.courseId = $courseId OPTIONAL MATCH p=(n)-[*0..]->() DETACH DELETE p return count(p);")
Long deleteAllByCourseId(String courseId); Long deleteAllByCourseId(String courseId);
@ -61,10 +61,10 @@ public interface KnowRepository extends Neo4jRepository<Know, Long> {
//============================= //=============================
@Query("CREATE (n:Know {name: $name, courseId: $courseId,info:$info,hour:$hour}) return ID(n) as id") @Query("CREATE (n:Know {courseId: $courseId,name: $name,info:$info,hour:$hour}) return ID(n) as id")
Long addCourse(String courseId, String name, String info, double hour); Long addCourse(String courseId, String name, String info, double hour);
@Query("MATCH (p:Know {courseId:$courseId }) SET p.name = $name set p.info= $info RETURN count(p);") @Query("MATCH (p:Know {courseId:$courseId}) SET p.name = $name set p.info= $info RETURN count(p);")
int updateCourse(String courseId, String name, String info); int updateCourse(String courseId, String name, String info);
@Query("MATCH (p:Know {courseId:$courseId }) delete p RETURN count(p);") @Query("MATCH (p:Know {courseId:$courseId }) delete p RETURN count(p);")

@ -17,15 +17,15 @@ import java.util.Set;
public interface ResourcesRepository extends Neo4jRepository<Resources, Long> { public interface ResourcesRepository extends Neo4jRepository<Resources, Long> {
//查询资源 //查询资源
@Query("MATCH (b:Resources) WHERE ID(b) in $resourceIds RETURN b") @Query("MATCH (b:Resources) WHERE ID(b) = $resourceIds RETURN b")
Set<Resources> queryResourcesByIds(List<Long> resourceIds); Resources queryResourcesByIds(Long resourceIds);
//查询资源 - 知识点 //查询资源 - 知识点
@Query("MATCH (p:Know)-[r:resources]->(c:Resources) WHERE ID(p) = $id AND ID(c) = $resourcesId return count(r)") @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); 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)") @Query("MATCH (p:Know), (c:Resources) WHERE ID(p) = $id AND ID(c) = $resourcesId CREATE (c)-[r:resources]->(p) return count(r)")
int addResourcesAndKnowById(Long id, Long resourcesId); int addResourcesAndKnowById(Long id, Long resourcesId);
@ -35,37 +35,37 @@ public interface ResourcesRepository extends Neo4jRepository<Resources, Long> {
Boolean deleteByobjectName(String name); Boolean deleteByobjectName(String name);
//添加课程与资源关系 //添加课程与资源关系
@Query("MATCH (p:Know), (c:Resources) WHERE p.courseId = $courseId AND ID(c) in $resourcesIds CREATE (p)-[r:resources]->(c) return count(r)") @Query("MATCH (p:Know), (c:Resources) WHERE p.courseId = $courseId AND ID(c) in $resourcesIds CREATE (c)-[r:resources]->(p) return count(r)")
int addResourcesAndKnowByCourseId(String courseId, List<Long> resourcesIds); int addResourcesAndKnowByCourseId(String courseId, List<Long> resourcesIds);
//添加章节与资源关系 //添加章节与资源关系
@Query("MATCH (p:Know), (c:Resources) WHERE p.chapterId = $chapterId AND ID(c) in $resourcesIds CREATE (p)-[r:resources]->(c) return count(r)") @Query("MATCH (p:Know), (c:Resources) WHERE p.chapterId = $chapterId AND ID(c) in $resourcesIds CREATE (c)-[r:resources]->(p) return count(r)")
int addResourcesAndKnowByChapterId(Long chapterId, List<Long> resourcesIds); 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)") @Query("MATCH (c:Resources)-[r:resources]->(p:Know) WHERE ID(c) = $resourcesId AND ID(p) = $id delete r return count(r)")
int deleteResourcesAndKnowById(Long id, Long resourcesId); 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)") @Query("MATCH (p:Know), (c:Resources) WHERE ID(p) = $id AND ID(c) in $resourcesIds CREATE (c)-[r:resources]->(p) return count(r)")
int addResourcesAndKnowById(Long id, List<Long> resourcesIds); int addResourcesAndKnowById(Long id, List<Long> resourcesIds);
//查询课程下资源 //查询课程下资源
@Query("MATCH p = (a:Know)-[rels*]-(b:Resources) WHERE a.courseId = $courseId and ANY(rel IN rels WHERE TYPE(rel) = 'resources') RETURN b") @Query("MATCH (a:Know)-[*]->(c:Know)<-[r:resources]-(b:Resources) WHERE a.courseId = $courseId RETURN b")
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 (a:Know)-[*]->(c:Know)<-[r:resources]-(b:Resources) WHERE a.chapterId = $chapterId RETURN b")
Set<Resources> queryResourcesByChapterId(Long chapterId); Set<Resources> queryResourcesByChapterId(Long chapterId);
//查询二级节点下资源 //查询二级节点下资源
@Query("MATCh (p:Know)-[*0..1]->(n:Know)-[:resources]->(m:Resources) WHERE ID(p) = $KnowId RETURN m") @Query("MATCh (p:Know)-[*0..1]->(n:Know)<-[:resources]-(m:Resources) WHERE ID(p) = $KnowId RETURN m")
Set<Resources> queryBesidesKnowToResources(Long KnowId); Set<Resources> queryBesidesKnowToResources(Long KnowId);
// //
@Query("MATCH (p)-[r:resources]->(c) WHERE ID(p) = $KnowId RETURN c") @Query("MATCH (p)<-[r:resources]-(c) WHERE ID(p) = $KnowId RETURN c")
Set<Resources> queryResourcesByKnowId(Long KnowId); Set<Resources> queryResourcesByKnowId(Long KnowId);

@ -1,6 +1,7 @@
package com.teaching.backend.service.Know; package com.teaching.backend.service.Know;
import com.teaching.backend.common.BaseResponse; import com.teaching.backend.common.BaseResponse;
import com.teaching.backend.controller.Know.KnowPathVO;
import com.teaching.backend.model.dto.Know.*; import com.teaching.backend.model.dto.Know.*;
import com.teaching.backend.model.entity.know.*; import com.teaching.backend.model.entity.know.*;
import com.teaching.backend.model.entity.knowtmp.Knowtmp; import com.teaching.backend.model.entity.knowtmp.Knowtmp;
@ -18,9 +19,10 @@ import java.util.Set;
* @Description: * @Description:
*/ */
public interface KnowService { public interface KnowService {
public BaseResponse<BaseKnowReturn> getDepthNodeByCourseId(String CourseId,Long depth);
public BaseResponse<BaseKnowReturn> getNodeByDepth(long id,Long depth); public BaseResponse<BaseKnowReturn> getNodeByDepth(long id,Long depth);
BaseResponse<BaseKnowReturn> knowLearnPath(String corseId); BaseResponse<List<KnowPathVO>> knowLearnPath(String corseId);
BaseResponse<String> updateLinks(List<LinksVO> linksList); BaseResponse<String> updateLinks(List<LinksVO> linksList);
BaseResponse<String> deleteAllByCourseId(String courseId1); BaseResponse<String> deleteAllByCourseId(String courseId1);

@ -4,21 +4,10 @@ import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject; import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil; import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonObject;
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.controller.Know.Edge; import com.teaching.backend.controller.Know.KnowPathVO;
import com.teaching.backend.controller.Know.KnowJson;
import com.teaching.backend.controller.Know.KnowJsonListVO;
import com.teaching.backend.mapper.Knowtemp.KnowstrMapper; import com.teaching.backend.mapper.Knowtemp.KnowstrMapper;
import com.teaching.backend.mapper.Knowtemp.KnowtmpMapper; import com.teaching.backend.mapper.Knowtemp.KnowtmpMapper;
import com.teaching.backend.mapper.chapter.ChapterMapper; import com.teaching.backend.mapper.chapter.ChapterMapper;
@ -29,24 +18,17 @@ import com.teaching.backend.model.entity.chapter.Chapter;
import com.teaching.backend.model.entity.courses.Courses; import com.teaching.backend.model.entity.courses.Courses;
import com.teaching.backend.model.entity.know.*; import com.teaching.backend.model.entity.know.*;
import com.teaching.backend.model.entity.knowtmp.Knowtmp; 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.KnowVO;
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 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.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.data.neo4j.core.Neo4jTemplate;
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.io.IOException;
import java.util.*; import java.util.*;
import java.util.stream.Collectors;
/** /**
* @Author:youhang * @Author:youhang
@ -169,7 +151,85 @@ public class knowServiceImpl implements KnowService {
return ResultUtils.success(baseKnowReturn); return ResultUtils.success(baseKnowReturn);
} }
public BaseResponse<BaseKnowReturn> getDepthNodeByCourseId(String courseId, Long depth) {
Collection<Map<String, Object>> all =
neo4jClient.query("match(n:Know)-[r:contain*0.." + depth + "]->(p:Know) where n.courseId = '" + courseId + "' return n as `n`,r as `r`,p as `p`,length(r) as `d`").fetch().all();
Collection<Map<String, Object>> all2 =
neo4jClient.query("match(n:Know)-[r*0.." + depth + "]->(p:Know) where n.courseId = '" + courseId + "' return r as `r`").fetch().all();
Iterator<Map<String, Object>> iterator = all.iterator();
Iterator<Map<String, Object>> iterator2 = all2.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));
if (node1 != null) {
Long id1 = node1.id();
String name1 = node1.get("name").asString();
knowVO.setId(id1);
knowVO.setLabel(name1);
knowList.add(knowVO);
knowVO.setColor(colorChoose.get(group));
}
node2 = (List) element.get("r");
if (!node2.isEmpty()) {
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());
if ("contain".equals(e.type())) {
links.setLabel("包含");
} else if ("order".equals(e.type())) {
links.setLabel("顺序");
} else if ("dependent".equals(e.type())) {
links.setLabel("依赖");
}
linksList.add(links);
}
}
}
while (iterator2.hasNext()) {
Map<String, Object> element = iterator2.next();
node2 = (List) element.get("r");
if (!node2.isEmpty()) {
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());
if ("contain".equals(e.type())) {
links.setLabel("包含");
} else if ("order".equals(e.type())) {
links.setLabel("顺序");
} else if ("dependent".equals(e.type())) {
links.setLabel("依赖");
}
linksList.add(links);
}
}
}
BaseKnowReturn baseKnowReturn = new BaseKnowReturn(knowList, linksList);
return ResultUtils.success(baseKnowReturn);
}
@Override @Override
public BaseResponse<String> showGraphJson(String courseId) { public BaseResponse<String> showGraphJson(String courseId) {
// 创建 JSON 对象数组 // 创建 JSON 对象数组
@ -337,7 +397,8 @@ public class knowServiceImpl implements KnowService {
} }
@Override @Override
public BaseResponse<BaseKnowReturn> knowLearnPath(String corseId) { public BaseResponse<List<KnowPathVO>> knowLearnPath(String corseId) {
//查询第一个知识点-最后一个知识点 //查询第一个知识点-最后一个知识点
List<Long> knowIds = new ArrayList<>(); List<Long> knowIds = new ArrayList<>();
List<Chapter> chapterList = chapterMapper.selectChapterPIDByCourseId(corseId); List<Chapter> chapterList = chapterMapper.selectChapterPIDByCourseId(corseId);
@ -354,59 +415,25 @@ public class knowServiceImpl implements KnowService {
} }
} }
// 生成学习路径
BaseKnowReturn baseKnowReturn = new BaseKnowReturn(); // 生成学习路径
String str = "MATCH p = (:Know{knowId:" + knowIds.get(0) + "})-[*]->(:Know{knowId:" + knowIds.get(knowIds.size() - 1) + "}) WITH p, REDUCE(totalWeight = 0.0, r IN relationships(p) | totalWeight + r.weight) AS pathWeight " + String str = "MATCH p = (:Know{knowId:" + knowIds.get(0) + "})-[*]->(:Know{knowId:" + knowIds.get(knowIds.size() - 1) + "}) WITH p, REDUCE(totalWeight = 0.0, r IN relationships(p) | totalWeight + r.weight) AS pathWeight " +
"RETURN nodes(p) as `p`, relationships(p) as `r`, pathWeight " + "RETURN [x IN nodes(p)|x.name] AS path,pathWeight ORDER BY pathWeight desc;" ;
"ORDER BY pathWeight DESC LIMIT 1;";
Collection<Map<String, Object>> result = neo4jClient.query(str).fetch().all(); Collection<Map<String, Object>> result = neo4jClient.query(str).fetch().all();
Iterator<Map<String, Object>> iterator = result.iterator(); Iterator<Map<String, Object>> iterator = result.iterator();
Set<KnowVO> knowList = new HashSet<>(); List<KnowPathVO>knowPathVOList = new ArrayList<>();
Set<Links> linksList = new HashSet<>(); KnowPathVO knowPathVO;
while (iterator.hasNext()) { while (iterator.hasNext()) {
Map<String, Object> element = iterator.next(); Map<String, Object> element = iterator.next();
KnowVO knowVO; knowPathVO= new KnowPathVO();
List node1 = new ArrayList<>(); List list = new ArrayList<>();
node1 = (List) element.get("p"); list = (List) element.get("path");
knowPathVO.setNodeList(list);
if (node1 != null) { Double pathWeight = (Double) element.get("pathWeight");
for (int i = 0; i < node1.size(); i++) { knowPathVO.setWeight(pathWeight);
Node e = (Node) node1.get(i); knowPathVOList.add(knowPathVO);
Long id1 = e.id(); }
String name1 = e.get("name").asString(); return ResultUtils.success(knowPathVOList);
knowVO = new KnowVO();
knowVO.setId(id1);
knowVO.setLabel(name1);
knowVO.setColor(colorList[0]);
knowList.add(knowVO);
}
}
List node2 = new ArrayList<>();
node2 = (List) element.get("r");
if (!node2.isEmpty()) {
for (int i = 0; i < node2.size(); i++) {
InternalRelationship e = (InternalRelationship) node2.get(i);
Links links = new Links();
links.setId(e.id());
links.setSource(e.startNodeId());
links.setTarget(e.endNodeId());
if ("contain".equals(e.type())) {
links.setLabel("包含");
} else if ("order".equals(e.type())) {
links.setLabel("顺序");
}else if ("dependent".equals(e.type())) {
links.setLabel("依赖");
}
linksList.add(links);
}
}
}
baseKnowReturn.setKnowList(knowList);
baseKnowReturn.setLinksList(linksList);
return ResultUtils.success(baseKnowReturn);
} }
@Override @Override

@ -45,58 +45,53 @@ public class ResourceGraphServiceImpl implements ResourceGraphService {
@Override @Override
public BaseResponse<String> addResourcesByIdAndResourcesIds(Long id, List<Long> resourcesIds) { public BaseResponse<String> addResourcesByIdAndResourcesId(Long id,Long resourcesId) {
// 查询知识点是否存在 ,资源是否存在 // 查询知识点是否存在 ,资源是否存在
int f = knowRepository.queryNode(id); int f = knowRepository.queryNode(id);
if(f <= 0){ if(f <= 0){
return ResultUtils.error(ErrorCode.PARAMS_ERROR,"知识点不存在"); return ResultUtils.error(ErrorCode.PARAMS_ERROR,"知识点不存在");
} }
Set<Resources>resourcesSet = resourcesRepository.queryResourcesByIds(resourcesIds); Resources resources = resourcesRepository.queryResourcesByIds(resourcesId);
if(resources == null){
if(resourcesSet.size() < resourcesIds.size()){
return ResultUtils.error(ErrorCode.PARAMS_ERROR,"资源不存在"); return ResultUtils.error(ErrorCode.PARAMS_ERROR,"资源不存在");
} }
//查询关系是否存在 //查询关系是否存在
for (int i = 0; i < resourcesIds.size(); i++) { int g = resourcesRepository.queryExisitRel(id,resourcesId);
int count = resourcesRepository.queryExisitRel(id,resourcesIds.get(i)); if(g >0){
if(count <= 0){ return ResultUtils.error(ErrorCode.PARAMS_ERROR,"关系已经存在");
}
//添加关系 addResourcesAndKnowById //添加关系 addResourcesAndKnowById
f = resourcesRepository.addResourcesAndKnowById(id,resourcesIds.get(i)); f = resourcesRepository.addResourcesAndKnowById(id,resourcesId);
if(f<= 0){ if(f<= 0){
return ResultUtils.error(ErrorCode.PARAMS_ERROR,"创建关系失败"); return ResultUtils.error(ErrorCode.PARAMS_ERROR,"创建关系失败");
} }
}
}
return ResultUtils.success("添加关系成功"); return ResultUtils.success("添加关系成功");
} }
@Override @Override
public BaseResponse<String> deleteResourcesAndKnowById(Long id, List<Long> resourcesIds) { public BaseResponse<String> deleteResourcesAndKnowById(Long id, Long resourcesId) {
// 查询知识点是否存在 ,资源是否存在 // 查询知识点是否存在 ,资源是否存在
int f = knowRepository.queryNode(id); int f = knowRepository.queryNode(id);
if(f <= 0){ if(f <= 0){
return ResultUtils.error(ErrorCode.PARAMS_ERROR,"知识点不存在"); return ResultUtils.error(ErrorCode.PARAMS_ERROR,"知识点不存在");
} }
Set<Resources>resourcesSet = resourcesRepository.queryResourcesByIds(resourcesIds); Resources resources = resourcesRepository.queryResourcesByIds(resourcesId);
if(resourcesSet.size() < resourcesIds.size()){ if(resources == null){
return ResultUtils.error(ErrorCode.PARAMS_ERROR,"资源不存在"); return ResultUtils.error(ErrorCode.PARAMS_ERROR,"资源不存在");
} }
//查询关系是否存在 //查询关系是否存在
for (int i = 0; i < resourcesIds.size(); i++) { int g = resourcesRepository.queryExisitRel(id,resourcesId);
int count = resourcesRepository.queryExisitRel(id,resourcesIds.get(i)); if(g < 0){
if(count <= 0){ return ResultUtils.error(ErrorCode.PARAMS_ERROR,"关系未存在");
//添加关系 addResourcesAndKnowById }
f = resourcesRepository.deleteResourcesAndKnowById(id,resourcesIds.get(i));
//删除关系
f = resourcesRepository.deleteResourcesAndKnowById(id,resourcesId);
if(f<= 0){ if(f<= 0){
return ResultUtils.error(ErrorCode.PARAMS_ERROR,"删除关系失败"); return ResultUtils.error(ErrorCode.PARAMS_ERROR,"删除关系失败");
} }
}
}
return ResultUtils.success("删除关系成功"); return ResultUtils.success("删除关系成功");
} }

@ -19,9 +19,9 @@ import java.util.Set;
public interface ResourceGraphService { public interface ResourceGraphService {
public BaseResponse<String> deleteResourcesAndKnowById(@RequestParam Long id, @RequestParam List<Long> resourcesIds); public BaseResponse<String> deleteResourcesAndKnowById(Long id, Long resourcesId);
BaseResponse<String> addResourcesByIdAndResourcesIds(Long id, List<Long> resourcesIds); BaseResponse<String> addResourcesByIdAndResourcesId(Long id, Long resourcesId);
//查询课程下资源 //查询课程下资源

Loading…
Cancel
Save