资源收藏

master
youahng 6 months ago committed by yh
parent 806e7b365f
commit 870338437e
  1. 6
      src/main/java/com/teaching/backend/common/ErrorCode.java
  2. 78
      src/main/java/com/teaching/backend/controller/KnowGraph/KnowController.java
  3. 21
      src/main/java/com/teaching/backend/controller/KnowGraph/ResourcesController.java
  4. 210
      src/main/java/com/teaching/backend/controller/favour/SeCourseFavourController.java
  5. 25
      src/main/java/com/teaching/backend/mapper/KnowGraph/KnowRepository.java
  6. 10
      src/main/java/com/teaching/backend/mapper/KnowGraph/ResourcesRepository.java
  7. 9
      src/main/java/com/teaching/backend/model/dto/KnowGraph/KnowRequest.java
  8. 5
      src/main/java/com/teaching/backend/model/dto/KnowGraph/KnowUpdateRequest.java
  9. 3
      src/main/java/com/teaching/backend/model/entity/KnowGraph/Know.java
  10. 8
      src/main/java/com/teaching/backend/model/entity/favour/SeCourseFavour.java
  11. 98
      src/main/java/com/teaching/backend/service/KnowGraph/KnowService.java
  12. 24
      src/main/java/com/teaching/backend/service/KnowGraph/ResourcesService.java
  13. 8
      src/main/java/com/teaching/backend/service/favour/SeCourseFavourService.java
  14. 6
      src/main/java/com/teaching/backend/service/impl/courses/CoursesServiceImpl.java
  15. 314
      src/main/java/com/teaching/backend/service/impl/favour/SeCourseFavourServiceImpl.java
  16. 34
      src/main/java/com/teaching/backend/utils/knowGraph/AddNeoKnowByCourse.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, "系统内部异常"),

@ -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<Know> createKnow(@RequestBody KnowRequest knowRequest) {
return knowService.createKnow(knowRequest);
}
//修改知识点
@PostMapping ("/update")
public BaseResponse<Know> updateKnow(@RequestBody KnowUpdateRequest knowUpdateRequest) {
return knowService.updateKnow(knowUpdateRequest);
}
//删除知识点
@GetMapping ("delete/{id}")
public BaseResponse<String> 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<KnowCourse> createCourseKnow(@RequestBody Courses courses) {
return knowService.createCourseKnow(courses);
}
//修改知识点 - 课程
@PostMapping("/update/KnowCourse")
public BaseResponse<KnowCourse> updateCourseKnow(@RequestBody Courses courses) {
return knowService.createCourseKnow(courses);
}
//删除知识点 - 课程
@PostMapping("/delete/KnowCourse")
public BaseResponse<String> deleteCourseKnow(@RequestParam String courseId) {
return knowService.deleteCourseKnow(courseId);
}
//添加知识点 - 章节
@PostMapping("/addKnowChapter")
public KnowChapter createKnowChapter(@RequestBody KnowChapterCreateRequest knowChapterCreateRequest) {
return knowService.createKnowChapter(knowChapterCreateRequest);
public BaseResponse<KnowChapter> createKnowChapter(@RequestBody Chapter chapter) {
return knowService.createKnowChapter(chapter);
}
//修改知识点 - 章节
@PostMapping("/update/KnowChapter")
public BaseResponse<KnowChapter> updateKnowChapter(@RequestBody Chapter chapter) {
return knowService.updateKnowChapter(chapter);
}
//删除知识点 - 章节
@PostMapping("/delete/KnowChapter")
public BaseResponse<String> deleteKnowChapter(@RequestParam String chapterId) {
return knowService.deleteKnowChapter(chapterId);
}
//修改知识点
@PostMapping ("/update")
public Know updateKnow(@RequestBody KnowUpdateRequest knowUpdateRequest) {
return knowService.updateKnow(knowUpdateRequest);
@GetMapping("/KnowBychapterId")
public Set<Know> 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<String> addKnowRelatedKnow(@RequestBody RelationshipKnowRequest relationshipKnowRequest) {
return knowService.addKnowRelatedKnow(relationshipKnowRequest);
}
//添加知识点与知识点的关系 related
//添加知识点与知识点的关系 fatherandSon
@PostMapping ("/addKnowFatherAndSonKnow")
public void addKnowFatherAndSonKnow(@RequestBody RelationshipKnowRequest relationshipKnowRequest) {
knowService.addKnowFatherAndSonKnow(relationshipKnowRequest);
public BaseResponse<String> addKnowFatherAndSonKnow(@RequestBody RelationshipKnowRequest relationshipKnowRequest) {
return knowService.addKnowFatherAndSonKnow(relationshipKnowRequest);
}
//获取该节点下所有的节点
@GetMapping("/all")
public BaseResponse<BaseKnowReturn> getKnowAll(@RequestParam String id) {
BaseKnowReturn baseKnowReturn =knowService.getKnowAll(id);
return ResultUtils.success(baseKnowReturn);
}
//返回该节点以及二级节点
@GetMapping("/KnowById")
public BaseResponse<BaseKnowReturn> getKnowById(@RequestParam Long id) {
BaseKnowReturn baseKnowReturn =knowService.getKnowById(id);
return ResultUtils.success(baseKnowReturn);
}
@GetMapping("/KnowBychapterId")
public Set<Know> queryByChapterId(@RequestParam String chapterId) {
return knowService.queryByChapterId(chapterId);
}
}

@ -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<String> uploadFile(@RequestParam("file")MultipartFile file) {
return resourcesService.uploadFile(file);
}
public ResourcesController(ResourcesService resourcesService) {
this.resourcesService = resourcesService;
}
//根据 id查询所关联的所有结点
//根据 id查询所关联的resources结点
@PostMapping ("/query/{id}")
public List<Resources> 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<Resources> queryBesidesKnowToResources(@PathVariable Long KnowId) {
return resourcesService.queryBesidesKnowToResources(KnowId);
}
}

@ -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<Boolean> 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<Long> 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<Long> 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<Page<CourseFavourDetailVO>> listPostByPage(@RequestBody CourseFavourQueryRequest courseFavourQueryRequest) {
// System.out.println(courseFavourQueryRequest);
// long current = courseFavourQueryRequest.getCurrent();
// long size = courseFavourQueryRequest.getPageSize();
// String userId = courseFavourQueryRequest.getUserId();
// List<String> ids = seCourseFavourService.courseList(userId);
// QueryWrapper<Courses> courseQueryWrapper = new QueryWrapper<>();
// courseQueryWrapper.in("id", ids);
// Page<CourseFavourDetailVO> 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<Boolean> 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<Long> 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<Page<CourseFavourDetailVO>> listPostByPage(@RequestBody CourseFavourQueryRequest courseFavourQueryRequest) {
System.out.println(courseFavourQueryRequest);
long current = courseFavourQueryRequest.getCurrent();
long size = courseFavourQueryRequest.getPageSize();
String userId = courseFavourQueryRequest.getUserId();
List<String> ids = seCourseFavourService.courseList(userId);
QueryWrapper<Courses> courseQueryWrapper = new QueryWrapper<>();
courseQueryWrapper.in("id", ids);
Page<CourseFavourDetailVO> courseFavourDetailVOPage = seCourseFavourService.listCourseFavourByPage(new Page<>(current, size), courseQueryWrapper);
return ResultUtils.success(courseFavourDetailVOPage);
}
}

@ -20,11 +20,14 @@ import java.util.Set;
public interface KnowRepository extends Neo4jRepository<Know, Long> {
@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<Long> 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<Long> 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<Long> 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<Long> KnowIds);
@Query("MATCH(n)-[r:related]->(nn:Know) where ID(nn) = $id RETURN n")
List<Know> queryKnowAllKnowById(Long id);
@ -33,9 +36,21 @@ public interface KnowRepository extends Neo4jRepository<Know, Long> {
@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<Know> queryByChapterId(String chapterId);

@ -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<Resources, Long> {
@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<Long> ResourcesIds);
@ -30,5 +34,9 @@ public interface ResourcesRepository extends Neo4jRepository<Resources, Long> {
@Query("MATCH p = (a:Know)-[rels*]-(b:Resources) WHERE ID(a) = $KnowId and ANY(rel IN rels WHERE TYPE(rel) = 'resources') RETURN b")
Set<Resources> queryCourseKnowToResources(Long KnowId);
@Query(" MATCH (p:Know)-[:FatherAndSon]->(n:Know)-[:resources]->(m:Resources) WHERE ID(p) = $KnowId RETURN m")
Set<Resources> queryBesidesKnowToResources(Long KnowId);
}

@ -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<Integer> resourceList;
}

@ -27,11 +27,6 @@ public class KnowUpdateRequest implements Serializable {
private String info;
/**
* 知识点所关联的资源
*/
@Property
private List<Integer> resourceList;
}

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

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

@ -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<Know> createKnow(KnowRequest knowRequest ) {
String name = knowRequest.getName();
String info = knowRequest.getInfo();
if("".equals(name) || name.length()<=0){
return ResultUtils.error(ErrorCode.PARAMS_EMPTY);
}
Know know = new Know();
BeanUtils.copyProperties(knowRequest,know);
return 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<Know> updateKnow(KnowUpdateRequest knowUpdateRequest ) {
Know know = new Know();
try {
know = knowRepository.findById(knowUpdateRequest.getId()).orElseThrow(() -> new RuntimeException("知识点 not found"));
}catch (RuntimeException e){
return ResultUtils.error(ErrorCode.NOT_FOUND_ERROR);
}
String name = knowUpdateRequest.getName();
String info = knowUpdateRequest.getInfo();
if("".equals(name) || name.length()<=0){
return ResultUtils.error(ErrorCode.PARAMS_EMPTY);
}
BeanUtils.copyProperties(knowUpdateRequest,know);
return ResultUtils.success(knowRepository.save(know));
}
public BaseResponse<String> deleteKnow(Long id) {
Boolean f = knowRepository.deleteKnow(id);
if(f)return ResultUtils.success("删除成功");
return ResultUtils.error(ErrorCode.DELETE_FAILED);
}
public KnowChapter createKnowChapter(KnowChapterCreateRequest knowChapterCreateRequest ) {
return knowRepository.createKnowChapter(knowChapterCreateRequest.getChapterId(),knowChapterCreateRequest.getName(),knowChapterCreateRequest.getInfo());
public BaseResponse<KnowCourse> createCourseKnow( Courses courses) {
String courseId = courses.getId();
String name = courses.getName();
String description = courses.getDescription();
return ResultUtils.success(knowRepository.createKnowCourse(courseId,name,description));
}
public void deleteKnow(Long id) {
knowRepository.deleteById(id);
public BaseResponse<String> 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<KnowChapter> 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<KnowChapter> updateKnowChapter(Chapter chapter) {
return ResultUtils.success(knowRepository.createKnowChapter(chapter.getId(), chapter.getName(), chapter.getContent()));
}
public BaseResponse<String> deleteKnowChapter(String chapterId) {
boolean f = knowRepository.deleteKnowChapter(chapterId);
if(f)return ResultUtils.success("删除成功");
return ResultUtils.error(ErrorCode.DELETE_FAILED);
}
public Set<Know> queryByChapterId(String chapterId){
Set<Know> knows = knowRepository.queryByChapterId(chapterId);
return knows;
}
public BaseResponse<String> addKnowRelatedKnow(RelationshipKnowRequest relationshipKnowRequest) {
int num = knowRepository.addKnowRelatedKnow(relationshipKnowRequest.getId(),relationshipKnowRequest.getKnowIds());
if(num == relationshipKnowRequest.getKnowIds().size())return ResultUtils.success("添加关系成功,共添加了"+num+" 条关系");
return ResultUtils.error(ErrorCode.DELETE_RELATIONSHIP_FAILED);
}
public BaseResponse<String> addKnowFatherAndSonKnow( RelationshipKnowRequest relationshipKnowRequest) {
int num = knowRepository.addKnowFatherAndSonKnow(relationshipKnowRequest.getId(),relationshipKnowRequest.getKnowIds());
if(num == relationshipKnowRequest.getKnowIds().size())return ResultUtils.success("添加关系成功,共添加了"+num+" 条关系");
return ResultUtils.error(ErrorCode.DELETE_RELATIONSHIP_FAILED);
}
@ -174,9 +232,5 @@ public class KnowService {
return baseKnowReturn;
}
public Set<Know> queryByChapterId(String chapterId){
Set<Know> knows = knowRepository.queryByChapterId(chapterId);
return knows;
}
}

@ -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<Resources> queryBesidesKnowToResources(Long KnowId){
return resourcesRepository.queryBesidesKnowToResources(KnowId);
}
public BaseResponse<String> 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());
}
}

@ -36,14 +36,6 @@ public interface SeCourseFavourService extends IService<SeCourseFavour> {
BaseResponse<Long> favourCount(String courseId);
/**
* 课程下资源和知识点的收藏总数
*
* @param courseId
* @return
*/
BaseResponse<Long> courseCount(String courseId);
/**
* 某个用户课程列表

@ -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<CoursesMapper, Courses> impl
@Autowired
private LearningRecordsMapper learningRecordsMapper;
@Autowired
private AddNeoKnowByCourse addNeoKnowByCourse;
@Override
@Transactional
@ -131,6 +135,8 @@ public class CoursesServiceImpl extends ServiceImpl<CoursesMapper, Courses> impl
courseObjectivesMapper.updateById(courseTotalObjectives);
}
}
//将课程同步到图数据库中
addNeoKnowByCourse.addCourse(courses);
return "添加成功";
} else {
throw new BusinessException(ErrorCode.OPERATION_ERROR, "这个课程已经存在了!请联系系统相关人员为您导入课程数据!");

@ -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<SeCourseFavourMapper, SeCourseFavour> implements SeCourseFavourService {
//
//
// @Resource
// private SeResourceFavourService seResourceFavourService;
//
// @Resource
// SeKnowFavourService seKnowFavourService;
//
// @Autowired
// CoursesMapper coursesMapper;
//
// @Autowired
// ICoursesService coursesService;
//
//
//
// @Override
// public BaseResponse<Boolean> 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<SeCourseFavour> 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 BaseResponse<Long>favourCount(String courseId) {
// //从数据库中校验是否存在courseid
// QueryWrapper<SeCourseFavour> 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<Long> courseCount(String courseId) {
//
// QueryWrapper<SeResourceFavour> ResourceQueryWrapper = new QueryWrapper<>();
// ResourceQueryWrapper.eq("course_id", courseId);
// long result1 = seResourceFavourService.count(ResourceQueryWrapper);
// QueryWrapper<SeKnowFavour> 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<String> courseList(String userId) {
// QueryWrapper<SeCourseFavour> courseQueryWrapper = new QueryWrapper<>();
// courseQueryWrapper.eq("user_id", userId);
// List<String> list = this.list(courseQueryWrapper).stream().map(SeCourseFavour::getCourseId).collect(Collectors.toList());
// return list;
// }
//
// @Override
// public Page<CourseFavourDetailVO> listCourseFavourByPage(Page<Courses> page, Wrapper<Courses> queryWrapper) {
// Page<Courses> coursePage = coursesService.page(page, queryWrapper);
// Page<CourseFavourDetailVO> courseFavourVOPage = new Page<>(coursePage.getCurrent(), coursePage.getSize(), coursePage.getTotal());
// List<Courses> courseFavourList = coursePage.getRecords();
// //若数据为空,直接返回
// if (CollUtil.isEmpty(courseFavourList)) {
// return courseFavourVOPage;
// }
// //过滤字段
// List<CourseFavourDetailVO> 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<SeCourseFavourMapper, SeCourseFavour> implements SeCourseFavourService {
@Resource
SeKnowFavourService seKnowFavourService;
@Autowired
CoursesMapper coursesMapper;
@Autowired
ICoursesService coursesService;
@Override
public BaseResponse<Boolean> 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<SeCourseFavour> 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 BaseResponse<Long>favourCount(String courseId) {
//从数据库中校验是否存在courseid
QueryWrapper<SeCourseFavour> 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<String> courseList(String userId) {
QueryWrapper<SeCourseFavour> courseQueryWrapper = new QueryWrapper<>();
courseQueryWrapper.eq("user_id", userId);
List<String> list = this.list(courseQueryWrapper).stream().map(SeCourseFavour::getCourseId).collect(Collectors.toList());
return list;
}
@Override
public Page<CourseFavourDetailVO> listCourseFavourByPage(Page<Courses> page, Wrapper<Courses> queryWrapper) {
Page<Courses> coursePage = coursesService.page(page, queryWrapper);
Page<CourseFavourDetailVO> courseFavourVOPage = new Page<>(coursePage.getCurrent(), coursePage.getSize(), coursePage.getTotal());
List<Courses> courseFavourList = coursePage.getRecords();
//若数据为空,直接返回
if (CollUtil.isEmpty(courseFavourList)) {
return courseFavourVOPage;
}
//过滤字段
List<CourseFavourDetailVO> 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;
}
}

@ -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<KnowCourse> addCourse(Courses courses){
return knowService.createCourseKnow(courses);
}
public BaseResponse<KnowChapter> addChapter(Chapter chapter){
return knowService.createKnowChapter(chapter);
}
}
Loading…
Cancel
Save