From 76a984b5330ddb9baa536b2cf1b1c13f8d8478f9 Mon Sep 17 00:00:00 2001 From: you hang <2998465706@qq.com> Date: Thu, 29 Aug 2024 12:31:59 +0800 Subject: [PATCH] =?UTF-8?q?=E7=9F=A5=E8=AF=86=E7=82=B9xiugai?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/Know/KnowController.java | 10 +- .../backend/controller/Know/KnowPathVO.java | 21 +++ .../resource/ResourceGraphController.java | 8 +- .../backend/mapper/know/KnowRepository.java | 6 +- .../mapper/resource/ResourcesRepository.java | 24 +-- .../backend/service/Know/KnowService.java | 4 +- .../service/impl/know/knowServiceImpl.java | 161 ++++++++++-------- .../resource/ResourceGraphServiceImpl.java | 51 +++--- .../resource/ResourceGraphService.java | 4 +- 9 files changed, 171 insertions(+), 118 deletions(-) create mode 100644 src/main/java/com/teaching/backend/controller/Know/KnowPathVO.java diff --git a/src/main/java/com/teaching/backend/controller/Know/KnowController.java b/src/main/java/com/teaching/backend/controller/Know/KnowController.java index a63e279..2d4b44a 100644 --- a/src/main/java/com/teaching/backend/controller/Know/KnowController.java +++ b/src/main/java/com/teaching/backend/controller/Know/KnowController.java @@ -47,7 +47,7 @@ public class KnowController { //生成知识点学习路径 默认从第一个知识点到第最后个知识点 @ApiOperation(value = "生成知识点学习路径") @GetMapping("/knowLearnPath") - BaseResponse knowLearnPath(@RequestParam String corseId){ + BaseResponse> knowLearnPath(@RequestParam String corseId){ return knowService.knowLearnPath(corseId); } @@ -58,6 +58,13 @@ public class KnowController { return knowService.getNodeByDepth(id,depth); } + //通过courseId 返回depth层知识点 + @ApiOperation(value = "通过courseId-返回depth层知识点") + @GetMapping("/getDepthNodeByCourseId") + BaseResponse getDepthNodeByCourseId(@RequestParam String courseId,@RequestParam Long depth){ + return knowService.getDepthNodeByCourseId(courseId,depth); + } + //返回课程下指定关系的知识图谱 @ApiOperation(value = "返回课程下指定关系的知识图谱") @@ -65,6 +72,7 @@ public class KnowController { BaseResponse getRelsNodesByCourseId(@RequestParam String courseId,@RequestParam Listtypes){ return knowService.getRelsNodesByCourseId(courseId,types); } + //返回知识点的前后知识点 @ApiOperation(value = "返回知识点的前后知识点") @GetMapping("/getFontedAndBackKnows") diff --git a/src/main/java/com/teaching/backend/controller/Know/KnowPathVO.java b/src/main/java/com/teaching/backend/controller/Know/KnowPathVO.java new file mode 100644 index 0000000..9fec2bc --- /dev/null +++ b/src/main/java/com/teaching/backend/controller/Know/KnowPathVO.java @@ -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 ListnodeList; + private Double weight; + +} diff --git a/src/main/java/com/teaching/backend/controller/resource/ResourceGraphController.java b/src/main/java/com/teaching/backend/controller/resource/ResourceGraphController.java index f1fa86d..72655fe 100644 --- a/src/main/java/com/teaching/backend/controller/resource/ResourceGraphController.java +++ b/src/main/java/com/teaching/backend/controller/resource/ResourceGraphController.java @@ -35,14 +35,14 @@ public class ResourceGraphController { @GetMapping("/addRelationship/BetweenKnowAndResources") @ApiOperation(value = "添加知识点资源关系") - public BaseResponse addResourcesByIdAndResourcesIds(@RequestParam Long id,@RequestParam List resourcesIds){ - return resourceGraphService.addResourcesByIdAndResourcesIds(id,resourcesIds); + public BaseResponse addResourcesByIdAndResourcesId(@RequestParam Long id,@RequestParam Long resourcesId){ + return resourceGraphService.addResourcesByIdAndResourcesId(id,resourcesId); } @GetMapping("/deleteRelationship/BetweenKnowAndResources") @ApiOperation(value = "删除知识点资源关系") - public BaseResponse deleteResourcesAndKnowById(@RequestParam Long id, @RequestParam List resourcesIds){ - return resourceGraphService.deleteResourcesAndKnowById(id,resourcesIds); + public BaseResponse deleteResourcesAndKnowById(@RequestParam Long id, @RequestParam Long resourcesId){ + return resourceGraphService.deleteResourcesAndKnowById(id,resourcesId); } //查询课程下资源 diff --git a/src/main/java/com/teaching/backend/mapper/know/KnowRepository.java b/src/main/java/com/teaching/backend/mapper/know/KnowRepository.java index dcbd7e0..653b429 100644 --- a/src/main/java/com/teaching/backend/mapper/know/KnowRepository.java +++ b/src/main/java/com/teaching/backend/mapper/know/KnowRepository.java @@ -23,7 +23,7 @@ import java.util.Set; public interface KnowRepository extends Neo4jRepository { - @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); @@ -61,10 +61,10 @@ public interface KnowRepository extends Neo4jRepository { //============================= - @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); - @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); @Query("MATCH (p:Know {courseId:$courseId }) delete p RETURN count(p);") diff --git a/src/main/java/com/teaching/backend/mapper/resource/ResourcesRepository.java b/src/main/java/com/teaching/backend/mapper/resource/ResourcesRepository.java index d32bc7b..9267e73 100644 --- a/src/main/java/com/teaching/backend/mapper/resource/ResourcesRepository.java +++ b/src/main/java/com/teaching/backend/mapper/resource/ResourcesRepository.java @@ -17,15 +17,15 @@ import java.util.Set; public interface ResourcesRepository extends Neo4jRepository { //查询资源 - @Query("MATCH (b:Resources) WHERE ID(b) in $resourceIds RETURN b") - Set queryResourcesByIds(List resourceIds); + @Query("MATCH (b:Resources) WHERE ID(b) = $resourceIds RETURN b") + 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); //添加知识点与资源关系 - @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); @@ -35,37 +35,37 @@ public interface ResourcesRepository extends Neo4jRepository { 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 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 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); //添加知识点与资源关系 - @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 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 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 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 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 queryResourcesByKnowId(Long KnowId); diff --git a/src/main/java/com/teaching/backend/service/Know/KnowService.java b/src/main/java/com/teaching/backend/service/Know/KnowService.java index fc184a6..e7b4d5d 100644 --- a/src/main/java/com/teaching/backend/service/Know/KnowService.java +++ b/src/main/java/com/teaching/backend/service/Know/KnowService.java @@ -1,6 +1,7 @@ package com.teaching.backend.service.Know; 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.entity.know.*; import com.teaching.backend.model.entity.knowtmp.Knowtmp; @@ -18,9 +19,10 @@ import java.util.Set; * @Description: */ public interface KnowService { + public BaseResponse getDepthNodeByCourseId(String CourseId,Long depth); public BaseResponse getNodeByDepth(long id,Long depth); - BaseResponse knowLearnPath(String corseId); + BaseResponse> knowLearnPath(String corseId); BaseResponse updateLinks(List linksList); BaseResponse deleteAllByCourseId(String courseId1); diff --git a/src/main/java/com/teaching/backend/service/impl/know/knowServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/know/knowServiceImpl.java index 9663d9c..d4f1a64 100644 --- a/src/main/java/com/teaching/backend/service/impl/know/knowServiceImpl.java +++ b/src/main/java/com/teaching/backend/service/impl/know/knowServiceImpl.java @@ -4,21 +4,10 @@ import cn.hutool.json.JSONArray; import cn.hutool.json.JSONObject; import cn.hutool.json.JSONUtil; 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.ErrorCode; import com.teaching.backend.common.ResultUtils; -import com.teaching.backend.controller.Know.Edge; -import com.teaching.backend.controller.Know.KnowJson; -import com.teaching.backend.controller.Know.KnowJsonListVO; +import com.teaching.backend.controller.Know.KnowPathVO; import com.teaching.backend.mapper.Knowtemp.KnowstrMapper; import com.teaching.backend.mapper.Knowtemp.KnowtmpMapper; 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.know.*; 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.data.neo4j.core.Neo4jTemplate; import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; -import java.io.IOException; import java.util.*; -import java.util.stream.Collectors; /** * @Author:youhang @@ -169,7 +151,85 @@ public class knowServiceImpl implements KnowService { return ResultUtils.success(baseKnowReturn); } + public BaseResponse getDepthNodeByCourseId(String courseId, Long depth) { + Collection> 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> all2 = + neo4jClient.query("match(n:Know)-[r*0.." + depth + "]->(p:Know) where n.courseId = '" + courseId + "' return r as `r`").fetch().all(); + + + Iterator> iterator = all.iterator(); + Iterator> iterator2 = all2.iterator(); + Set knowList = new HashSet<>(); + Set linksList = new HashSet<>(); + KnowVO knowVO; + List node2 = new ArrayList<>(); + Links links; + int p = 0; + + while (iterator.hasNext()) { + Map 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 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 public BaseResponse showGraphJson(String courseId) { // 创建 JSON 对象数组 @@ -337,7 +397,8 @@ public class knowServiceImpl implements KnowService { } @Override - public BaseResponse knowLearnPath(String corseId) { + public BaseResponse> knowLearnPath(String corseId) { + //查询第一个知识点-最后一个知识点 List knowIds = new ArrayList<>(); List 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 " + - "RETURN nodes(p) as `p`, relationships(p) as `r`, pathWeight " + - "ORDER BY pathWeight DESC LIMIT 1;"; + "RETURN [x IN nodes(p)|x.name] AS path,pathWeight ORDER BY pathWeight desc;" ; Collection> result = neo4jClient.query(str).fetch().all(); Iterator> iterator = result.iterator(); - Set knowList = new HashSet<>(); - Set linksList = new HashSet<>(); - + ListknowPathVOList = new ArrayList<>(); + KnowPathVO knowPathVO; while (iterator.hasNext()) { Map element = iterator.next(); - KnowVO knowVO; - List node1 = new ArrayList<>(); - node1 = (List) element.get("p"); - - if (node1 != null) { - for (int i = 0; i < node1.size(); i++) { - Node e = (Node) node1.get(i); - Long id1 = e.id(); - String name1 = e.get("name").asString(); - 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); + knowPathVO= new KnowPathVO(); + List list = new ArrayList<>(); + list = (List) element.get("path"); + knowPathVO.setNodeList(list); + Double pathWeight = (Double) element.get("pathWeight"); + knowPathVO.setWeight(pathWeight); + knowPathVOList.add(knowPathVO); + } + return ResultUtils.success(knowPathVOList); } @Override diff --git a/src/main/java/com/teaching/backend/service/impl/resource/ResourceGraphServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/resource/ResourceGraphServiceImpl.java index d033251..0526202 100644 --- a/src/main/java/com/teaching/backend/service/impl/resource/ResourceGraphServiceImpl.java +++ b/src/main/java/com/teaching/backend/service/impl/resource/ResourceGraphServiceImpl.java @@ -45,58 +45,53 @@ public class ResourceGraphServiceImpl implements ResourceGraphService { @Override - public BaseResponse addResourcesByIdAndResourcesIds(Long id, List resourcesIds) { + public BaseResponse addResourcesByIdAndResourcesId(Long id,Long resourcesId) { // 查询知识点是否存在 ,资源是否存在 int f = knowRepository.queryNode(id); if(f <= 0){ return ResultUtils.error(ErrorCode.PARAMS_ERROR,"知识点不存在"); } - SetresourcesSet = resourcesRepository.queryResourcesByIds(resourcesIds); - - if(resourcesSet.size() < resourcesIds.size()){ + Resources resources = resourcesRepository.queryResourcesByIds(resourcesId); + if(resources == null){ return ResultUtils.error(ErrorCode.PARAMS_ERROR,"资源不存在"); } - //查询关系是否存在 - for (int i = 0; i < resourcesIds.size(); i++) { - int count = resourcesRepository.queryExisitRel(id,resourcesIds.get(i)); - if(count <= 0){ - //添加关系 addResourcesAndKnowById - f = resourcesRepository.addResourcesAndKnowById(id,resourcesIds.get(i)); - if(f<= 0){ - return ResultUtils.error(ErrorCode.PARAMS_ERROR,"创建关系失败"); - } - } + int g = resourcesRepository.queryExisitRel(id,resourcesId); + if(g >0){ + return ResultUtils.error(ErrorCode.PARAMS_ERROR,"关系已经存在"); + } + //添加关系 addResourcesAndKnowById + f = resourcesRepository.addResourcesAndKnowById(id,resourcesId); + if(f<= 0){ + return ResultUtils.error(ErrorCode.PARAMS_ERROR,"创建关系失败"); } - return ResultUtils.success("添加关系成功"); + return ResultUtils.success("添加关系成功"); } @Override - public BaseResponse deleteResourcesAndKnowById(Long id, List resourcesIds) { + public BaseResponse deleteResourcesAndKnowById(Long id, Long resourcesId) { // 查询知识点是否存在 ,资源是否存在 int f = knowRepository.queryNode(id); if(f <= 0){ return ResultUtils.error(ErrorCode.PARAMS_ERROR,"知识点不存在"); } - SetresourcesSet = resourcesRepository.queryResourcesByIds(resourcesIds); + Resources resources = resourcesRepository.queryResourcesByIds(resourcesId); - if(resourcesSet.size() < resourcesIds.size()){ + if(resources == null){ return ResultUtils.error(ErrorCode.PARAMS_ERROR,"资源不存在"); } - //查询关系是否存在 - for (int i = 0; i < resourcesIds.size(); i++) { - int count = resourcesRepository.queryExisitRel(id,resourcesIds.get(i)); - if(count <= 0){ - //添加关系 addResourcesAndKnowById - f = resourcesRepository.deleteResourcesAndKnowById(id,resourcesIds.get(i)); - if(f<= 0){ - return ResultUtils.error(ErrorCode.PARAMS_ERROR,"删除关系失败"); - } - } + int g = resourcesRepository.queryExisitRel(id,resourcesId); + if(g < 0){ + return ResultUtils.error(ErrorCode.PARAMS_ERROR,"关系未存在"); } + //删除关系 + f = resourcesRepository.deleteResourcesAndKnowById(id,resourcesId); + if(f<= 0){ + return ResultUtils.error(ErrorCode.PARAMS_ERROR,"删除关系失败"); + } return ResultUtils.success("删除关系成功"); } diff --git a/src/main/java/com/teaching/backend/service/resource/ResourceGraphService.java b/src/main/java/com/teaching/backend/service/resource/ResourceGraphService.java index 5811177..d2f6817 100644 --- a/src/main/java/com/teaching/backend/service/resource/ResourceGraphService.java +++ b/src/main/java/com/teaching/backend/service/resource/ResourceGraphService.java @@ -19,9 +19,9 @@ import java.util.Set; public interface ResourceGraphService { - public BaseResponse deleteResourcesAndKnowById(@RequestParam Long id, @RequestParam List resourcesIds); + public BaseResponse deleteResourcesAndKnowById(Long id, Long resourcesId); - BaseResponse addResourcesByIdAndResourcesIds(Long id, List resourcesIds); + BaseResponse addResourcesByIdAndResourcesId(Long id, Long resourcesId); //查询课程下资源