From 870338437e5e5d34b2fb95af19c32a223c88b6e0 Mon Sep 17 00:00:00 2001 From: youahng <2998465706@qq.com> Date: Sun, 28 Jul 2024 11:05:33 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B5=84=E6=BA=90=E6=94=B6=E8=97=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../teaching/backend/common/ErrorCode.java | 6 + .../controller/KnowGraph/KnowController.java | 78 +++-- .../KnowGraph/ResourcesController.java | 21 +- .../favour/SeCourseFavourController.java | 210 ++++++------ .../mapper/KnowGraph/KnowRepository.java | 25 +- .../mapper/KnowGraph/ResourcesRepository.java | 10 +- .../model/dto/KnowGraph/KnowRequest.java | 9 - .../dto/KnowGraph/KnowUpdateRequest.java | 5 - .../backend/model/entity/KnowGraph/Know.java | 3 - .../model/entity/favour/SeCourseFavour.java | 8 + .../service/KnowGraph/KnowService.java | 98 ++++-- .../service/KnowGraph/ResourcesService.java | 24 +- .../service/favour/SeCourseFavourService.java | 8 - .../impl/courses/CoursesServiceImpl.java | 6 + .../favour/SeCourseFavourServiceImpl.java | 314 +++++++++--------- .../utils/knowGraph/AddNeoKnowByCourse.java | 34 ++ 16 files changed, 491 insertions(+), 368 deletions(-) create mode 100644 src/main/java/com/teaching/backend/utils/knowGraph/AddNeoKnowByCourse.java diff --git a/src/main/java/com/teaching/backend/common/ErrorCode.java b/src/main/java/com/teaching/backend/common/ErrorCode.java index 1a038df..6685de7 100644 --- a/src/main/java/com/teaching/backend/common/ErrorCode.java +++ b/src/main/java/com/teaching/backend/common/ErrorCode.java @@ -38,6 +38,12 @@ public enum ErrorCode { PARAMS_RESOURCE_NOTEXISTS(4003,"资源不存在"), PARAMS_COURSE_NOTEXISTS(4004,"课程不存在"), + PARAMS_EMPTY(40004, "参数为空"), + + DELETE_FAILED(40005, "删除失败"), + UPLOAD_FAILED(40006, "上传失败"), + + DELETE_RELATIONSHIP_FAILED(40006, "添加关系失败"), SYSTEM_ERROR(50000, "系统内部异常"), UNKNOW_ERROR(50002, "系统内部异常"), diff --git a/src/main/java/com/teaching/backend/controller/KnowGraph/KnowController.java b/src/main/java/com/teaching/backend/controller/KnowGraph/KnowController.java index 2dd3a8b..fbc1e68 100644 --- a/src/main/java/com/teaching/backend/controller/KnowGraph/KnowController.java +++ b/src/main/java/com/teaching/backend/controller/KnowGraph/KnowController.java @@ -8,10 +8,14 @@ package com.teaching.backend.controller.KnowGraph; import com.teaching.backend.common.BaseResponse; import com.teaching.backend.common.ResultUtils; import com.teaching.backend.model.dto.KnowGraph.*; +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.chapter.Chapter; +import com.teaching.backend.model.entity.courses.Courses; import com.teaching.backend.service.KnowGraph.KnowService; import org.springframework.web.bind.annotation.*; @@ -37,63 +41,87 @@ public class KnowController { //添加知识点 @PostMapping("/add") - public Know createKnow(@RequestBody KnowRequest knowRequest) { + public BaseResponse createKnow(@RequestBody KnowRequest knowRequest) { return knowService.createKnow(knowRequest); } + //修改知识点 + @PostMapping ("/update") + public BaseResponse updateKnow(@RequestBody KnowUpdateRequest knowUpdateRequest) { + return knowService.updateKnow(knowUpdateRequest); + } + //删除知识点 + @GetMapping ("delete/{id}") + public BaseResponse deleteKnow(@PathVariable Long id) { + return knowService.deleteKnow(id); + } //添加知识点 - 课程 - @PostMapping("/addKnowCourse") - public KnowCourse createCourseKnow(@RequestBody KnowCourseCreateRequest knowCourseCreateRequest) { - return knowService.createCourseKnow(knowCourseCreateRequest); + @PostMapping("/add/KnowCourse") + public BaseResponse createCourseKnow(@RequestBody Courses courses) { + return knowService.createCourseKnow(courses); } + + //修改知识点 - 课程 + @PostMapping("/update/KnowCourse") + public BaseResponse updateCourseKnow(@RequestBody Courses courses) { + return knowService.createCourseKnow(courses); + } + + //删除知识点 - 课程 + @PostMapping("/delete/KnowCourse") + public BaseResponse deleteCourseKnow(@RequestParam String courseId) { + return knowService.deleteCourseKnow(courseId); + } + //添加知识点 - 章节 @PostMapping("/addKnowChapter") - public KnowChapter createKnowChapter(@RequestBody KnowChapterCreateRequest knowChapterCreateRequest) { - return knowService.createKnowChapter(knowChapterCreateRequest); + public BaseResponse createKnowChapter(@RequestBody Chapter chapter) { + return knowService.createKnowChapter(chapter); } + //修改知识点 - 章节 + @PostMapping("/update/KnowChapter") + public BaseResponse updateKnowChapter(@RequestBody Chapter chapter) { + return knowService.updateKnowChapter(chapter); + } + //删除知识点 - 章节 + @PostMapping("/delete/KnowChapter") + public BaseResponse deleteKnowChapter(@RequestParam String chapterId) { + return knowService.deleteKnowChapter(chapterId); + } - - //修改知识点 - @PostMapping ("/update") - public Know updateKnow(@RequestBody KnowUpdateRequest knowUpdateRequest) { - return knowService.updateKnow(knowUpdateRequest); + @GetMapping("/KnowBychapterId") + public Set queryByChapterId(@RequestParam String chapterId) { + return knowService.queryByChapterId(chapterId); } - //删除知识点 - @GetMapping ("delete/{id}") - public void deleteKnow(@PathVariable Long id) { - knowService.deleteKnow(id); - } //添加知识点与知识点的关系 related @PostMapping ("/addKnowRelatedKnow") - public void addKnowRelatedKnow(@RequestBody RelationshipKnowRequest relationshipKnowRequest) { - knowService.addKnowRelatedKnow(relationshipKnowRequest); + public BaseResponse addKnowRelatedKnow(@RequestBody RelationshipKnowRequest relationshipKnowRequest) { + return knowService.addKnowRelatedKnow(relationshipKnowRequest); } - //添加知识点与知识点的关系 related + //添加知识点与知识点的关系 fatherandSon @PostMapping ("/addKnowFatherAndSonKnow") - public void addKnowFatherAndSonKnow(@RequestBody RelationshipKnowRequest relationshipKnowRequest) { - knowService.addKnowFatherAndSonKnow(relationshipKnowRequest); + public BaseResponse addKnowFatherAndSonKnow(@RequestBody RelationshipKnowRequest relationshipKnowRequest) { + return knowService.addKnowFatherAndSonKnow(relationshipKnowRequest); } + //获取该节点下所有的节点 @GetMapping("/all") public BaseResponse getKnowAll(@RequestParam String id) { BaseKnowReturn baseKnowReturn =knowService.getKnowAll(id); return ResultUtils.success(baseKnowReturn); } + //返回该节点以及二级节点 @GetMapping("/KnowById") public BaseResponse getKnowById(@RequestParam Long id) { BaseKnowReturn baseKnowReturn =knowService.getKnowById(id); return ResultUtils.success(baseKnowReturn); } - @GetMapping("/KnowBychapterId") - public Set queryByChapterId(@RequestParam String chapterId) { - return knowService.queryByChapterId(chapterId); - } } diff --git a/src/main/java/com/teaching/backend/controller/KnowGraph/ResourcesController.java b/src/main/java/com/teaching/backend/controller/KnowGraph/ResourcesController.java index a1c9d21..9892f91 100644 --- a/src/main/java/com/teaching/backend/controller/KnowGraph/ResourcesController.java +++ b/src/main/java/com/teaching/backend/controller/KnowGraph/ResourcesController.java @@ -7,6 +7,7 @@ package com.teaching.backend.controller.KnowGraph; */ +import com.teaching.backend.common.BaseResponse; import com.teaching.backend.model.dto.KnowGraph.*; import com.teaching.backend.model.entity.KnowGraph.Know; @@ -27,25 +28,24 @@ import java.util.Set; public class ResourcesController { private ResourcesService resourcesService; + public ResourcesController(ResourcesService resourcesService) { + this.resourcesService = resourcesService; + } //添加知识点 @PostMapping("/upload") - public String uploadFile(@RequestParam("file")MultipartFile file) { - System.out.println(file.getOriginalFilename()); + public BaseResponse uploadFile(@RequestParam("file")MultipartFile file) { return resourcesService.uploadFile(file); } - public ResourcesController(ResourcesService resourcesService) { - this.resourcesService = resourcesService; - } - //根据 id查询所关联的所有结点 + //根据 id查询所关联的resources结点 @PostMapping ("/query/{id}") public List queryKnowAllKnowById(@PathVariable Long id) { return resourcesService.queryKnowAllResources(id); } - //添加知识点 + //添加资源 @PostMapping("/add") public Resources createResources(@RequestBody ResourcesAddRequest resourceAddRequest) { return resourcesService.createResource(resourceAddRequest); @@ -81,4 +81,11 @@ public class ResourcesController { return resourcesService.queryCourseKnowToResources(KnowId); } + @GetMapping ("queryBesidesKnowToResources/{KnowId}") + public Set queryBesidesKnowToResources(@PathVariable Long KnowId) { + return resourcesService.queryBesidesKnowToResources(KnowId); + } + + + } diff --git a/src/main/java/com/teaching/backend/controller/favour/SeCourseFavourController.java b/src/main/java/com/teaching/backend/controller/favour/SeCourseFavourController.java index 2f78ce9..f09fc43 100644 --- a/src/main/java/com/teaching/backend/controller/favour/SeCourseFavourController.java +++ b/src/main/java/com/teaching/backend/controller/favour/SeCourseFavourController.java @@ -1,114 +1,96 @@ -//package com.teaching.backend.controller.favour; -// -//import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -//import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -//import com.teaching.backend.common.BaseResponse; -//import com.teaching.backend.common.ErrorCode; -//import com.teaching.backend.common.ResultUtils; -//import com.teaching.backend.exception.BusinessException; -//import com.teaching.backend.model.dto.favour.courseFavour.CourseFavourAddRequest; -//import com.teaching.backend.model.dto.favour.courseFavour.CourseFavourAllRequest; -//import com.teaching.backend.model.dto.favour.courseFavour.CourseFavourQueryRequest; -//import com.teaching.backend.model.entity.courses.Courses; -//import com.teaching.backend.model.vo.favour.CourseFavourDetailVO; -//import com.teaching.backend.service.favour.SeCourseFavourService; -//import lombok.extern.slf4j.Slf4j; -//import org.apache.commons.lang3.StringUtils; -//import org.springframework.web.bind.annotation.PostMapping; -//import org.springframework.web.bind.annotation.RequestBody; -//import org.springframework.web.bind.annotation.RequestMapping; -//import org.springframework.web.bind.annotation.RestController; -// -//import javax.annotation.Resource; -//import java.util.List; -// -///** -// * @Author:youhang -// * @Date:2024-05-30-20:22 -// * @Description: -// */ -//@RestController -//@RequestMapping("/api/course_favour") -//@Slf4j -//public class SeCourseFavourController { -// -// @Resource -// private SeCourseFavourService seCourseFavourService; -// -// -// -// /** -// * 收藏/取消收藏 -// * -// * @param courseFavourAddRequest -// * @return result 执行情况 -// */ -// @PostMapping("/add") -// // 加上 HttpServletRequest request 在一个fitter里面进行鉴权操作 -// public BaseResponse doFavour(@RequestBody CourseFavourAddRequest courseFavourAddRequest) { -// System.out.println(courseFavourAddRequest); -// //判断字段是否为空 -// if (StringUtils.isAnyBlank(courseFavourAddRequest.getCourseId(), courseFavourAddRequest.getUserId())) { -// throw new BusinessException(ErrorCode.PARAMS_ERROR); -// } -// -// return seCourseFavourService.doCourseFavour(courseFavourAddRequest.getCourseId(), courseFavourAddRequest.getUserId()); -// -// } -// -// -// /** -// * 课程点赞总数 -// * -// * @param courseFavourAddRequest -// * @return result 课程点赞总数 -// */ -// @PostMapping("/count") -// // HttpServletRequest request 在一个fitter里面进行鉴权操作 -// public BaseResponse favourCount(@RequestBody CourseFavourAddRequest courseFavourAddRequest) { -// if (StringUtils.isAnyBlank(courseFavourAddRequest.getCourseId())) { -// throw new BusinessException(ErrorCode.PARAMS_ERROR, "请求参数不能为空"); -// } -// return seCourseFavourService.favourCount(courseFavourAddRequest.getCourseId()); -// } -// -// /** -// * 课程下资源和知识点点赞总数 -// * -// * @param courseFavourAllRequest -// * @return result 课程下资源和知识点点赞总数 -// */ -// @PostMapping("/countAll") -// // todo 后期加上 HttpServletRequest request 在一个fitter里面进行鉴权操作 -// public BaseResponse courseCount(@RequestBody CourseFavourAllRequest courseFavourAllRequest) { -// if (StringUtils.isAnyBlank(courseFavourAllRequest.getCourseId())) { -// throw new BusinessException(ErrorCode.PARAMS_ERROR, "请求参数不能为空"); -// } -// // todo 从数据库中校验是否存在courseid -// -// return seCourseFavourService.courseCount(courseFavourAllRequest.getCourseId()); -// } -// -// -// -// /** -// * 分页获取课程列表 -// * -// * @return -// */ -// @PostMapping("/list/page") -// public BaseResponse> listPostByPage(@RequestBody CourseFavourQueryRequest courseFavourQueryRequest) { -// System.out.println(courseFavourQueryRequest); -// long current = courseFavourQueryRequest.getCurrent(); -// long size = courseFavourQueryRequest.getPageSize(); -// String userId = courseFavourQueryRequest.getUserId(); -// List ids = seCourseFavourService.courseList(userId); -// QueryWrapper courseQueryWrapper = new QueryWrapper<>(); -// courseQueryWrapper.in("id", ids); -// Page courseFavourDetailVOPage = seCourseFavourService.listCourseFavourByPage(new Page<>(current, size), courseQueryWrapper); -// -// return ResultUtils.success(courseFavourDetailVOPage); -// } -// -// -//} +package com.teaching.backend.controller.favour; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.teaching.backend.common.BaseResponse; +import com.teaching.backend.common.ErrorCode; +import com.teaching.backend.common.ResultUtils; +import com.teaching.backend.exception.BusinessException; +import com.teaching.backend.model.dto.favour.courseFavour.CourseFavourAddRequest; +import com.teaching.backend.model.dto.favour.courseFavour.CourseFavourAllRequest; +import com.teaching.backend.model.dto.favour.courseFavour.CourseFavourQueryRequest; +import com.teaching.backend.model.entity.courses.Courses; +import com.teaching.backend.model.vo.favour.CourseFavourDetailVO; +import com.teaching.backend.service.favour.SeCourseFavourService; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.Resource; +import java.util.List; + +/** + * @Author:youhang + * @Date:2024-05-30-20:22 + * @Description: + */ +@RestController +@RequestMapping("/api/course_favour") +@Slf4j +public class SeCourseFavourController { + + @Resource + private SeCourseFavourService seCourseFavourService; + + + + /** + * 收藏/取消收藏 + * + * @param courseFavourAddRequest + * @return result 执行情况 + */ + @PostMapping("/add") + // 加上 HttpServletRequest request 在一个fitter里面进行鉴权操作 + public BaseResponse doFavour(@RequestBody CourseFavourAddRequest courseFavourAddRequest) { + System.out.println(courseFavourAddRequest); + //判断字段是否为空 + if (StringUtils.isAnyBlank(courseFavourAddRequest.getCourseId(), courseFavourAddRequest.getUserId())) { + throw new BusinessException(ErrorCode.PARAMS_ERROR); + } + + return seCourseFavourService.doCourseFavour(courseFavourAddRequest.getCourseId(), courseFavourAddRequest.getUserId()); + + } + + + /** + * 课程点赞总数 + * + * @param courseFavourAddRequest + * @return result 课程点赞总数 + */ + @PostMapping("/count") + // HttpServletRequest request 在一个fitter里面进行鉴权操作 + public BaseResponse favourCount(@RequestBody CourseFavourAddRequest courseFavourAddRequest) { + if (StringUtils.isAnyBlank(courseFavourAddRequest.getCourseId())) { + throw new BusinessException(ErrorCode.PARAMS_ERROR, "请求参数不能为空"); + } + return seCourseFavourService.favourCount(courseFavourAddRequest.getCourseId()); + } + + + /** + * 分页获取课程列表 + * + * @return + */ + @PostMapping("/list/page") + public BaseResponse> listPostByPage(@RequestBody CourseFavourQueryRequest courseFavourQueryRequest) { + System.out.println(courseFavourQueryRequest); + long current = courseFavourQueryRequest.getCurrent(); + long size = courseFavourQueryRequest.getPageSize(); + String userId = courseFavourQueryRequest.getUserId(); + List ids = seCourseFavourService.courseList(userId); + QueryWrapper courseQueryWrapper = new QueryWrapper<>(); + courseQueryWrapper.in("id", ids); + Page courseFavourDetailVOPage = seCourseFavourService.listCourseFavourByPage(new Page<>(current, size), courseQueryWrapper); + + return ResultUtils.success(courseFavourDetailVOPage); + } + + +} diff --git a/src/main/java/com/teaching/backend/mapper/KnowGraph/KnowRepository.java b/src/main/java/com/teaching/backend/mapper/KnowGraph/KnowRepository.java index 3a2efdb..5a0664f 100644 --- a/src/main/java/com/teaching/backend/mapper/KnowGraph/KnowRepository.java +++ b/src/main/java/com/teaching/backend/mapper/KnowGraph/KnowRepository.java @@ -20,11 +20,14 @@ import java.util.Set; public interface KnowRepository extends Neo4jRepository { - @Query("MATCH (p:Know), (c:Know) WHERE ID(p) = $id AND ID(c) IN $KnowIds CREATE (p)-[:related]->(c),(c)-[:related]->(p)") - void addKnowRelatedKnow(Long id, List KnowIds); + @Query("MATCH (p:Know) where ID(p) = $id RETURN count(p);") + Boolean deleteKnow(Long id); - @Query("MATCH (p:Know), (c:Know) WHERE ID(p) = $id AND ID(c) IN $KnowIds CREATE (p)-[:FatherAndSon]->(c)") - void addKnowFatherAndSonKnow(Long id, List KnowIds); + @Query("MATCH (p:Know), (c:Know) WHERE ID(p) = $id AND ID(c) IN $KnowIds CREATE (p)-[r:related]->(c),(c)-[:related]->(p) return count(r)") + int addKnowRelatedKnow(Long id, List KnowIds); + + @Query("MATCH (p:Know), (c:Know) WHERE ID(p) = $id AND ID(c) IN $KnowIds CREATE (p)-[r:FatherAndSon]->(c) return r") + int addKnowFatherAndSonKnow(Long id, List KnowIds); @Query("MATCH(n)-[r:related]->(nn:Know) where ID(nn) = $id RETURN n") List queryKnowAllKnowById(Long id); @@ -33,9 +36,21 @@ public interface KnowRepository extends Neo4jRepository { @Query("CREATE (n:Know {name: $name, courseId: $courseId,info:$info}) return n") KnowCourse createKnowCourse(String courseId, String name, String info); - @Query("CREATE (n:Know {name: $name, chapterId: $chapterId,info:$info}) return n") + @Query("MATCH (p:Know {courseId:$courseId }) SET p.name = $name set p.info= $info RETURN p;") + Boolean updateKnowCourse(String courseId, String name, String info); + + @Query("MATCH (p:Know {courseId:$courseId }) RETURN count(p);") + Boolean deleteKnowCourse(String courseId); + + @Query("CREATE (n:Know {name: $name, chapterId: $chapterId,info:$info}) return count(n)") KnowChapter createKnowChapter(String chapterId, String name, String info); + @Query("MATCH (p:Know {chapterId:$chapterId }) SET p.name = $name set p.info= $info RETURN p;") + Boolean updateKnowChapter(String chapterId, String name, String info); + + @Query("MATCH (p:Know {chapterId:$chapterId }) RETURN count(p);") + Boolean deleteKnowChapter(String chapterId); + @Query("MATCH(n:Know)-[r:FatherAndSon*]->(nn:Know) where n.chapterId = $chapterId RETURN nn") Set queryByChapterId(String chapterId); diff --git a/src/main/java/com/teaching/backend/mapper/KnowGraph/ResourcesRepository.java b/src/main/java/com/teaching/backend/mapper/KnowGraph/ResourcesRepository.java index b0c456f..98de5e8 100644 --- a/src/main/java/com/teaching/backend/mapper/KnowGraph/ResourcesRepository.java +++ b/src/main/java/com/teaching/backend/mapper/KnowGraph/ResourcesRepository.java @@ -5,7 +5,7 @@ package com.teaching.backend.mapper.KnowGraph; * @Date:2024-06-09-8:59 * @Description: */ - +import java.util.concurrent.*; import com.teaching.backend.model.entity.KnowGraph.Know; @@ -20,6 +20,10 @@ import java.util.Set; public interface ResourcesRepository extends Neo4jRepository { + @Query("MATCH(n:Resources) where n.resourcesId = $resourcesId RETURN n") + Resources queryResources(String resourcesId); + + @Query("MATCH (p:Know), (c:Resources) WHERE ID(p) = $id AND ID(c) in $ResourcesIds CREATE (p)-[r:resources]->(c)") void addResourceRelatedKnow(Long id, List ResourcesIds); @@ -30,5 +34,9 @@ public interface ResourcesRepository extends Neo4jRepository { @Query("MATCH p = (a:Know)-[rels*]-(b:Resources) WHERE ID(a) = $KnowId and ANY(rel IN rels WHERE TYPE(rel) = 'resources') RETURN b") Set queryCourseKnowToResources(Long KnowId); + @Query(" MATCH (p:Know)-[:FatherAndSon]->(n:Know)-[:resources]->(m:Resources) WHERE ID(p) = $KnowId RETURN m") + Set queryBesidesKnowToResources(Long KnowId); + + } diff --git a/src/main/java/com/teaching/backend/model/dto/KnowGraph/KnowRequest.java b/src/main/java/com/teaching/backend/model/dto/KnowGraph/KnowRequest.java index b3e07ae..13061f1 100644 --- a/src/main/java/com/teaching/backend/model/dto/KnowGraph/KnowRequest.java +++ b/src/main/java/com/teaching/backend/model/dto/KnowGraph/KnowRequest.java @@ -9,7 +9,6 @@ import java.util.List; @Data public class KnowRequest implements Serializable { - /** * 知识点名称 */ @@ -22,13 +21,5 @@ public class KnowRequest implements Serializable { private String info; - - /** - * 知识点所关联的资源 - */ - @Property - private List resourceList; - - } diff --git a/src/main/java/com/teaching/backend/model/dto/KnowGraph/KnowUpdateRequest.java b/src/main/java/com/teaching/backend/model/dto/KnowGraph/KnowUpdateRequest.java index 6e1b20b..e3955d2 100644 --- a/src/main/java/com/teaching/backend/model/dto/KnowGraph/KnowUpdateRequest.java +++ b/src/main/java/com/teaching/backend/model/dto/KnowGraph/KnowUpdateRequest.java @@ -27,11 +27,6 @@ public class KnowUpdateRequest implements Serializable { private String info; - /** - * 知识点所关联的资源 - */ - @Property - private List resourceList; } diff --git a/src/main/java/com/teaching/backend/model/entity/KnowGraph/Know.java b/src/main/java/com/teaching/backend/model/entity/KnowGraph/Know.java index 79af7ca..10eff7f 100644 --- a/src/main/java/com/teaching/backend/model/entity/KnowGraph/Know.java +++ b/src/main/java/com/teaching/backend/model/entity/KnowGraph/Know.java @@ -13,7 +13,6 @@ import java.util.List; @Data public class Know implements Serializable { - /** * id */ @@ -34,7 +33,5 @@ public class Know implements Serializable { @Property private String info; - - } diff --git a/src/main/java/com/teaching/backend/model/entity/favour/SeCourseFavour.java b/src/main/java/com/teaching/backend/model/entity/favour/SeCourseFavour.java index 947a2a8..436fe99 100644 --- a/src/main/java/com/teaching/backend/model/entity/favour/SeCourseFavour.java +++ b/src/main/java/com/teaching/backend/model/entity/favour/SeCourseFavour.java @@ -1,5 +1,6 @@ package com.teaching.backend.model.entity.favour; +import cn.hutool.core.date.DateTime; import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; @@ -30,6 +31,13 @@ public class SeCourseFavour implements Serializable { */ private String userId; + /** + * 创建用户 id + */ + private DateTime createtime; + + + @TableField(exist = false) private static final long serialVersionUID = 1L; } diff --git a/src/main/java/com/teaching/backend/service/KnowGraph/KnowService.java b/src/main/java/com/teaching/backend/service/KnowGraph/KnowService.java index a4c1dba..f18a008 100644 --- a/src/main/java/com/teaching/backend/service/KnowGraph/KnowService.java +++ b/src/main/java/com/teaching/backend/service/KnowGraph/KnowService.java @@ -1,11 +1,18 @@ package com.teaching.backend.service.KnowGraph; +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.model.dto.KnowGraph.*; +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.chapter.Chapter; +import com.teaching.backend.model.entity.courses.Courses; import com.teaching.backend.model.vo.knowGraph.KnowVO; import org.neo4j.driver.internal.InternalRelationship; import org.neo4j.driver.types.Node; @@ -14,6 +21,7 @@ import org.springframework.data.neo4j.core.Neo4jClient; import org.springframework.stereotype.Service; import javax.annotation.Resource; +import java.time.LocalDateTime; import java.util.*; /** @@ -39,39 +47,89 @@ public class KnowService { } - public Know createKnow(KnowRequest knowRequest ) { + public BaseResponse 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 knowRepository.save(know); + return ResultUtils.success(knowRepository.save(know)) ; } - public KnowCourse createCourseKnow(KnowCourseCreateRequest knowCourseCreateRequest ) { - return knowRepository.createKnowCourse(knowCourseCreateRequest.getCourseId(),knowCourseCreateRequest.getName(),knowCourseCreateRequest.getInfo()); - + public BaseResponse 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 deleteKnow(Long id) { + Boolean f = knowRepository.deleteKnow(id); + if(f)return ResultUtils.success("删除成功"); + return ResultUtils.error(ErrorCode.DELETE_FAILED); + } + - public KnowChapter createKnowChapter(KnowChapterCreateRequest knowChapterCreateRequest ) { - return knowRepository.createKnowChapter(knowChapterCreateRequest.getChapterId(),knowChapterCreateRequest.getName(),knowChapterCreateRequest.getInfo()); + public BaseResponse createCourseKnow( Courses courses) { + String courseId = courses.getId(); + String name = courses.getName(); + String description = courses.getDescription(); + return ResultUtils.success(knowRepository.createKnowCourse(courseId,name,description)); } - public void deleteKnow(Long id) { - knowRepository.deleteById(id); + public BaseResponse deleteCourseKnow( String courseId) { + boolean f = knowRepository.deleteKnowCourse(courseId); + if(f)return ResultUtils.success("删除成功"); + return ResultUtils.error(ErrorCode.DELETE_FAILED); } - public Know updateKnow(KnowUpdateRequest knowUpdateRequest ) { - Know know = new Know(); - know = knowRepository.findById(knowUpdateRequest.getId()).orElseThrow(() -> new RuntimeException("知识点 not found")); - BeanUtils.copyProperties(knowUpdateRequest,know); - return knowRepository.save(know); + 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 createKnowChapter(Chapter chapter) { + return ResultUtils.success(knowRepository.createKnowChapter(chapter.getId(), chapter.getName(), chapter.getContent())); - public void addKnowRelatedKnow( RelationshipKnowRequest relationshipKnowRequest) { - knowRepository.addKnowRelatedKnow(relationshipKnowRequest.getId(),relationshipKnowRequest.getKnowIds()); } - public void addKnowFatherAndSonKnow( RelationshipKnowRequest relationshipKnowRequest) { - knowRepository.addKnowFatherAndSonKnow(relationshipKnowRequest.getId(),relationshipKnowRequest.getKnowIds()); + public BaseResponse updateKnowChapter(Chapter chapter) { + return ResultUtils.success(knowRepository.createKnowChapter(chapter.getId(), chapter.getName(), chapter.getContent())); + } + public BaseResponse deleteKnowChapter(String chapterId) { + boolean f = knowRepository.deleteKnowChapter(chapterId); + if(f)return ResultUtils.success("删除成功"); + return ResultUtils.error(ErrorCode.DELETE_FAILED); + } + public Set queryByChapterId(String chapterId){ + Set knows = knowRepository.queryByChapterId(chapterId); + return knows; + } + + + + public BaseResponse 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 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); } @@ -174,9 +232,5 @@ public class KnowService { return baseKnowReturn; } - public Set queryByChapterId(String chapterId){ - Set knows = knowRepository.queryByChapterId(chapterId); - return knows; - } } diff --git a/src/main/java/com/teaching/backend/service/KnowGraph/ResourcesService.java b/src/main/java/com/teaching/backend/service/KnowGraph/ResourcesService.java index a5760bd..4a9498f 100644 --- a/src/main/java/com/teaching/backend/service/KnowGraph/ResourcesService.java +++ b/src/main/java/com/teaching/backend/service/KnowGraph/ResourcesService.java @@ -3,6 +3,9 @@ package com.teaching.backend.service.KnowGraph; import cn.hutool.core.io.FileUtil; import cn.hutool.http.HttpRequest; import cn.hutool.http.HttpResponse; +import com.teaching.backend.common.BaseResponse; +import com.teaching.backend.common.ErrorCode; +import com.teaching.backend.common.ResultUtils; import com.teaching.backend.mapper.KnowGraph.ResourcesRepository; import com.teaching.backend.model.dto.KnowGraph.*; import com.teaching.backend.model.entity.KnowGraph.Resources; @@ -39,6 +42,15 @@ public class ResourcesService { public Resources createResource(ResourcesAddRequest resourceAddRequest ) { + String resourcesId = resourceAddRequest.getResourcesId(); + try { + Resources resourcesOld = resourcesRepository.queryResources(resourcesId); + }catch (RuntimeException e){ + System.out.println("not found"); + } + String name = resourceAddRequest.getName(); + Integer type = resourceAddRequest.getType(); + String path = resourceAddRequest.getPath(); Resources resources = new Resources(); BeanUtils.copyProperties(resourceAddRequest,resources); return resourcesRepository.save(resources); @@ -65,21 +77,25 @@ public class ResourcesService { return resourcesRepository.queryCourseKnowToResources(KnowId); } - public String uploadFile(MultipartFile file) { + public Set queryBesidesKnowToResources(Long KnowId){ + return resourcesRepository.queryBesidesKnowToResources(KnowId); + } + + public BaseResponse uploadFile(MultipartFile file) { String userDir = System.getProperty("user.dir"); String globalFilePathName = userDir + File.separator + GLOBAL_CODE_DIR_NAME; if (!FileUtil.exist(globalFilePathName)) { FileUtil.mkdir(globalFilePathName); } - // 把用户的代码隔离存放 + // 把用户的文件隔离存放 File userCodeFile = null; try { String userCodeParentPath = globalFilePathName + File.separator + UUID.randomUUID(); String userCodePath = userCodeParentPath + File.separator + file.getOriginalFilename(); userCodeFile = FileUtil.writeFromStream(file.getInputStream(), userCodePath); } catch (Exception e) { - System.out.println("失败"); + return ResultUtils.error(ErrorCode.UPLOAD_FAILED); } - return userCodeFile.getPath(); + return ResultUtils.success(userCodeFile.getPath()); } } diff --git a/src/main/java/com/teaching/backend/service/favour/SeCourseFavourService.java b/src/main/java/com/teaching/backend/service/favour/SeCourseFavourService.java index 5c53de1..9cb0d40 100644 --- a/src/main/java/com/teaching/backend/service/favour/SeCourseFavourService.java +++ b/src/main/java/com/teaching/backend/service/favour/SeCourseFavourService.java @@ -36,14 +36,6 @@ public interface SeCourseFavourService extends IService { BaseResponse favourCount(String courseId); - /** - * 课程下资源和知识点的收藏总数 - * - * @param courseId - * @return - */ - BaseResponse courseCount(String courseId); - /** * 某个用户课程列表 diff --git a/src/main/java/com/teaching/backend/service/impl/courses/CoursesServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/courses/CoursesServiceImpl.java index 07efd11..5cd8d7f 100644 --- a/src/main/java/com/teaching/backend/service/impl/courses/CoursesServiceImpl.java +++ b/src/main/java/com/teaching/backend/service/impl/courses/CoursesServiceImpl.java @@ -27,6 +27,7 @@ import com.teaching.backend.model.vo.courses.CourseObjectivesTreeVO; import com.teaching.backend.model.vo.courses.CoursesVO; import com.teaching.backend.service.courses.ICoursesService; import com.teaching.backend.utils.CourseCode; +import com.teaching.backend.utils.knowGraph.AddNeoKnowByCourse; import org.apache.poi.xwpf.usermodel.*; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; @@ -81,6 +82,9 @@ public class CoursesServiceImpl extends ServiceImpl impl @Autowired private LearningRecordsMapper learningRecordsMapper; + @Autowired + private AddNeoKnowByCourse addNeoKnowByCourse; + @Override @Transactional @@ -131,6 +135,8 @@ public class CoursesServiceImpl extends ServiceImpl impl courseObjectivesMapper.updateById(courseTotalObjectives); } } + //将课程同步到图数据库中 + addNeoKnowByCourse.addCourse(courses); return "添加成功"; } else { throw new BusinessException(ErrorCode.OPERATION_ERROR, "这个课程已经存在了!请联系系统相关人员为您导入课程数据!"); diff --git a/src/main/java/com/teaching/backend/service/impl/favour/SeCourseFavourServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/favour/SeCourseFavourServiceImpl.java index 0801d15..a442c5a 100644 --- a/src/main/java/com/teaching/backend/service/impl/favour/SeCourseFavourServiceImpl.java +++ b/src/main/java/com/teaching/backend/service/impl/favour/SeCourseFavourServiceImpl.java @@ -1,165 +1,149 @@ -//package com.teaching.backend.service.impl.favour; -// -//import cn.hutool.core.collection.CollUtil; -//import com.baomidou.mybatisplus.core.conditions.Wrapper; -//import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -//import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -//import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -//import com.teaching.backend.common.BaseResponse; -//import com.teaching.backend.common.ErrorCode; -//import com.teaching.backend.common.ResultUtils; -//import com.teaching.backend.exception.BusinessException; -//import com.teaching.backend.mapper.courses.CoursesMapper; -//import com.teaching.backend.mapper.favour.SeCourseFavourMapper; -//import com.teaching.backend.model.entity.courses.Courses; -//import com.teaching.backend.model.entity.favour.SeCourseFavour; -//import com.teaching.backend.model.entity.favour.SeKnowFavour; -//import com.teaching.backend.model.entity.favour.SeResourceFavour; -//import com.teaching.backend.model.vo.favour.CourseFavourDetailVO; -//import com.teaching.backend.service.courses.ICoursesService; -//import com.teaching.backend.service.favour.SeCourseFavourService; -//import com.teaching.backend.service.favour.SeKnowFavourService; -//import com.teaching.backend.service.favour.SeResourceFavourService; -//import org.springframework.beans.BeanUtils; -//import org.springframework.beans.factory.annotation.Autowired; -//import org.springframework.stereotype.Service; -// -//import javax.annotation.Resource; -//import java.util.ArrayList; -//import java.util.List; -//import java.util.concurrent.locks.Lock; -//import java.util.concurrent.locks.ReentrantLock; -//import java.util.stream.Collectors; -// -// -///** -// * @Author:youhang -// * @Date:2024-05-30-20:23 -// * @Description: -// */ -//@Service -//public class SeCourseFavourServiceImpl extends ServiceImpl implements SeCourseFavourService { -// -// -// @Resource -// private SeResourceFavourService seResourceFavourService; -// -// @Resource -// SeKnowFavourService seKnowFavourService; -// -// @Autowired -// CoursesMapper coursesMapper; -// -// @Autowired -// ICoursesService coursesService; -// -// -// -// @Override -// public BaseResponse doCourseFavour(String courseId, String userId) { -// System.out.println("进入点赞" + courseId + userId); -// //从数据库中校验是否存在courseid -// Courses courses = coursesMapper.selectById(courseId); -// boolean result = false; -// if(courses == null){ -// return ResultUtils.error(ErrorCode.NOT_FOUND_ERROR,"课程不存在"); -// } -// //查询数据库记录,该用户是否点赞 -// SeCourseFavour seCourseFavour = new SeCourseFavour(); -// seCourseFavour.setCourseId(courseId); -// seCourseFavour.setUserId(userId); -// QueryWrapper favourQueryWrapper = new QueryWrapper<>(seCourseFavour); -// SeCourseFavour oldSeCourseFavour = this.getOne(favourQueryWrapper); -// //已点赞 -// if (oldSeCourseFavour != null) { -// // 取消点赞 删除记录 -// result = this.remove(favourQueryWrapper); -// if (result) { -// System.out.println("取消点赞成功"); -// return ResultUtils.success(result); -// } else { -// throw new BusinessException(ErrorCode.SYSTEM_ERROR); -// } -// } else { -// // 每个用户串行点赞 -// // 锁必须要包裹住事务方法 -// Lock lock = new ReentrantLock(); -// lock.lock(); -// try { -// result = this.save(seCourseFavour); -// } catch (Exception e) { -// throw new BusinessException(ErrorCode.OPERATION_ERROR); -// } finally { -// lock.unlock(); -// System.out.println("点赞成功"); -// return ResultUtils.success(result); -// } -// } -// } -// -// @Override -// public BaseResponsefavourCount(String courseId) { -// //从数据库中校验是否存在courseid -// QueryWrapper favourQueryWrapper = new QueryWrapper<>(); -// favourQueryWrapper.eq("course_id", courseId); -// long result = this.count(favourQueryWrapper); -// if (result == 0) { -// throw new BusinessException(ErrorCode.SYSTEM_ERROR, "查询参数不存在"); -// } else { -// return ResultUtils.success(result); -// } -// } -// -// @Override -// public BaseResponse courseCount(String courseId) { -// -// QueryWrapper ResourceQueryWrapper = new QueryWrapper<>(); -// ResourceQueryWrapper.eq("course_id", courseId); -// long result1 = seResourceFavourService.count(ResourceQueryWrapper); -// QueryWrapper KnowQueryWrapper = new QueryWrapper<>(); -// KnowQueryWrapper.eq("course_id", courseId); -// long result2 = seKnowFavourService.count(KnowQueryWrapper); -// long result = result1 + result2; -// if (result == 0) { -// throw new BusinessException(ErrorCode.SYSTEM_ERROR, "查询参数不存在"); -// } else { -// return ResultUtils.success(result); -// } -// } -// -// /** -// * 某个用户课程列表 -// * -// * @param userId -// * @return -// */ -// @Override -// public List courseList(String userId) { -// QueryWrapper courseQueryWrapper = new QueryWrapper<>(); -// courseQueryWrapper.eq("user_id", userId); -// List list = this.list(courseQueryWrapper).stream().map(SeCourseFavour::getCourseId).collect(Collectors.toList()); -// return list; -// } -// -// @Override -// public Page listCourseFavourByPage(Page page, Wrapper queryWrapper) { -// Page coursePage = coursesService.page(page, queryWrapper); -// Page courseFavourVOPage = new Page<>(coursePage.getCurrent(), coursePage.getSize(), coursePage.getTotal()); -// List courseFavourList = coursePage.getRecords(); -// //若数据为空,直接返回 -// if (CollUtil.isEmpty(courseFavourList)) { -// return courseFavourVOPage; -// } -// //过滤字段 -// List courseFavourDetailVOList = new ArrayList<>(); -// for (int i = 0; i < courseFavourList.size(); i++) { -// CourseFavourDetailVO courseFavourDetailVO = new CourseFavourDetailVO(); -// BeanUtils.copyProperties(courseFavourList.get(i), courseFavourDetailVO); -// courseFavourDetailVOList.add(courseFavourDetailVO); -// } -// courseFavourVOPage.setRecords(courseFavourDetailVOList); -// return courseFavourVOPage; -// } -// -// -//} +package com.teaching.backend.service.impl.favour; + +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.date.DateTime; +import com.baomidou.mybatisplus.core.conditions.Wrapper; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.teaching.backend.common.BaseResponse; +import com.teaching.backend.common.ErrorCode; +import com.teaching.backend.common.ResultUtils; +import com.teaching.backend.exception.BusinessException; +import com.teaching.backend.mapper.courses.CoursesMapper; +import com.teaching.backend.mapper.favour.SeCourseFavourMapper; +import com.teaching.backend.model.entity.courses.Courses; +import com.teaching.backend.model.entity.favour.SeCourseFavour; +import com.teaching.backend.model.entity.favour.SeKnowFavour; +import com.teaching.backend.model.entity.favour.SeResourceFavour; +import com.teaching.backend.model.vo.favour.CourseFavourDetailVO; +import com.teaching.backend.service.courses.ICoursesService; +import com.teaching.backend.service.favour.SeCourseFavourService; +import com.teaching.backend.service.favour.SeKnowFavourService; + +import org.springframework.beans.BeanUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.locks.Lock; +import java.util.concurrent.locks.ReentrantLock; +import java.util.stream.Collectors; + + +/** + * @Author:youhang + * @Date:2024-05-30-20:23 + * @Description: + */ +@Service +public class SeCourseFavourServiceImpl extends ServiceImpl implements SeCourseFavourService { + + + + @Resource + SeKnowFavourService seKnowFavourService; + + @Autowired + CoursesMapper coursesMapper; + + @Autowired + ICoursesService coursesService; + + + + @Override + public BaseResponse doCourseFavour(String courseId, String userId) { + System.out.println("进入点赞" + courseId + userId); + //从数据库中校验是否存在courseid + Courses courses = coursesMapper.selectById(courseId); + boolean result = false; + if(courses == null){ + return ResultUtils.error(ErrorCode.NOT_FOUND_ERROR,"课程不存在"); + } + //查询数据库记录,该用户是否点赞 + SeCourseFavour seCourseFavour = new SeCourseFavour(); + seCourseFavour.setCourseId(courseId); + seCourseFavour.setUserId(userId); + seCourseFavour.setCreatetime(DateTime.now()); + QueryWrapper favourQueryWrapper = new QueryWrapper<>(seCourseFavour); + SeCourseFavour oldSeCourseFavour = this.getOne(favourQueryWrapper); + //已点赞 + if (oldSeCourseFavour != null) { + // 取消点赞 删除记录 + result = this.remove(favourQueryWrapper); + if (result) { + System.out.println("取消点赞成功"); + return ResultUtils.success(result); + } else { + throw new BusinessException(ErrorCode.SYSTEM_ERROR); + } + } else { + // 每个用户串行点赞 + // 锁必须要包裹住事务方法 + Lock lock = new ReentrantLock(); + lock.lock(); + try { + result = this.save(seCourseFavour); + } catch (Exception e) { + throw new BusinessException(ErrorCode.OPERATION_ERROR); + } finally { + lock.unlock(); + System.out.println("点赞成功"); + return ResultUtils.success(result); + } + } + } + + @Override + public BaseResponsefavourCount(String courseId) { + //从数据库中校验是否存在courseid + QueryWrapper favourQueryWrapper = new QueryWrapper<>(); + favourQueryWrapper.eq("course_id", courseId); + long result = this.count(favourQueryWrapper); + if (result == 0) { + throw new BusinessException(ErrorCode.SYSTEM_ERROR, "查询参数不存在"); + } else { + return ResultUtils.success(result); + } + } + + + /** + * 某个用户课程列表 + * + * @param userId + * @return + */ + @Override + public List courseList(String userId) { + QueryWrapper courseQueryWrapper = new QueryWrapper<>(); + courseQueryWrapper.eq("user_id", userId); + List list = this.list(courseQueryWrapper).stream().map(SeCourseFavour::getCourseId).collect(Collectors.toList()); + return list; + } + + @Override + public Page listCourseFavourByPage(Page page, Wrapper queryWrapper) { + Page coursePage = coursesService.page(page, queryWrapper); + Page courseFavourVOPage = new Page<>(coursePage.getCurrent(), coursePage.getSize(), coursePage.getTotal()); + List courseFavourList = coursePage.getRecords(); + //若数据为空,直接返回 + if (CollUtil.isEmpty(courseFavourList)) { + return courseFavourVOPage; + } + //过滤字段 + List courseFavourDetailVOList = new ArrayList<>(); + for (int i = 0; i < courseFavourList.size(); i++) { + CourseFavourDetailVO courseFavourDetailVO = new CourseFavourDetailVO(); + BeanUtils.copyProperties(courseFavourList.get(i), courseFavourDetailVO); + courseFavourDetailVOList.add(courseFavourDetailVO); + } + courseFavourVOPage.setRecords(courseFavourDetailVOList); + return courseFavourVOPage; + } + + +} diff --git a/src/main/java/com/teaching/backend/utils/knowGraph/AddNeoKnowByCourse.java b/src/main/java/com/teaching/backend/utils/knowGraph/AddNeoKnowByCourse.java new file mode 100644 index 0000000..77a7074 --- /dev/null +++ b/src/main/java/com/teaching/backend/utils/knowGraph/AddNeoKnowByCourse.java @@ -0,0 +1,34 @@ +package com.teaching.backend.utils.knowGraph; + +import com.teaching.backend.common.BaseResponse; +import com.teaching.backend.model.dto.chapter.ChapterDTO; +import com.teaching.backend.model.dto.courses.CoursesDTO; +import com.teaching.backend.model.entity.KnowGraph.KnowChapter; +import com.teaching.backend.model.entity.KnowGraph.KnowCourse; +import com.teaching.backend.model.entity.chapter.Chapter; +import com.teaching.backend.model.entity.courses.Courses; +import com.teaching.backend.service.KnowGraph.KnowService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import org.springframework.web.bind.annotation.RequestBody; + +/** + * @Author:youhang + * @Date:2024-07-26-17:57 + * @Description: + */ +@Component +public class AddNeoKnowByCourse { + + @Autowired + private KnowService knowService; + + public BaseResponse addCourse(Courses courses){ + return knowService.createCourseKnow(courses); + } + + public BaseResponse addChapter(Chapter chapter){ + return knowService.createKnowChapter(chapter); + } + +}