master
youahng 5 months ago committed by yh
parent f2086ebf35
commit c02e61d35f
  1. 6
      pom.xml
  2. 1
      src/main/java/com/teaching/backend/config/CorsConfig.java
  3. 16
      src/main/java/com/teaching/backend/config/SecurityConfig.java
  4. 74
      src/main/java/com/teaching/backend/constant/ViewContentTypeEnum.java
  5. 129
      src/main/java/com/teaching/backend/controller/Know/KnowController.java
  6. 164
      src/main/java/com/teaching/backend/controller/KnowGraph/KnowController.java
  7. 56
      src/main/java/com/teaching/backend/controller/KnowGraph/KnowGraphController.java
  8. 90
      src/main/java/com/teaching/backend/controller/KnowGraph/ResourcesController.java
  9. 51
      src/main/java/com/teaching/backend/controller/Knowtmp/KnowtmpController.java
  10. 12
      src/main/java/com/teaching/backend/controller/records/ResourceLearningRecordController.java
  11. 81
      src/main/java/com/teaching/backend/controller/resource/ResourceController.java
  12. 78
      src/main/java/com/teaching/backend/mapper/KnowGraph/KnowRepository.java
  13. 43
      src/main/java/com/teaching/backend/mapper/KnowGraph/ResourcesRepository.java
  14. 15
      src/main/java/com/teaching/backend/mapper/Knowtemp/KnowtempMapper.java
  15. 18
      src/main/java/com/teaching/backend/mapper/Knowtemp/KnowtmpMapper.java
  16. 66
      src/main/java/com/teaching/backend/mapper/know/KnowRepository.java
  17. 17
      src/main/java/com/teaching/backend/mapper/resource/ResourceLearningNumberMapper.java
  18. 20
      src/main/java/com/teaching/backend/mapper/resource/ResourcesMapper.java
  19. 64
      src/main/java/com/teaching/backend/mapper/resource/ResourcesRepository.java
  20. 4
      src/main/java/com/teaching/backend/model/dto/Know/BaseKnowReturn.java
  21. 4
      src/main/java/com/teaching/backend/model/dto/Know/KnowChapterCreateRequest.java
  22. 4
      src/main/java/com/teaching/backend/model/dto/Know/KnowCourseCreateRequest.java
  23. 4
      src/main/java/com/teaching/backend/model/dto/Know/KnowRequest.java
  24. 4
      src/main/java/com/teaching/backend/model/dto/Know/KnowUpdateRequest.java
  25. 2
      src/main/java/com/teaching/backend/model/dto/Know/RelationshipKnowRequest.java
  26. 2
      src/main/java/com/teaching/backend/model/dto/Know/RelationshipResourceRequest.java
  27. 22
      src/main/java/com/teaching/backend/model/dto/KnowGraph/ResourceUpdateRequest.java
  28. 19
      src/main/java/com/teaching/backend/model/dto/KnowGraph/ResourcesAddRequest.java
  29. 15
      src/main/java/com/teaching/backend/model/dto/KnowGraph/ResourcesRequest.java
  30. 6
      src/main/java/com/teaching/backend/model/dto/Knowtmp/KnowtempAdd.java
  31. 5
      src/main/java/com/teaching/backend/model/dto/Knowtmp/KnowtempUpdate.java
  32. 31
      src/main/java/com/teaching/backend/model/dto/resource/BucketPolicyConfigDto.java
  33. 22
      src/main/java/com/teaching/backend/model/dto/resource/ResourceUploadDto.java
  34. 6
      src/main/java/com/teaching/backend/model/entity/chapter/Chapter.java
  35. 4
      src/main/java/com/teaching/backend/model/entity/know/Know.java
  36. 5
      src/main/java/com/teaching/backend/model/entity/know/KnowChapter.java
  37. 3
      src/main/java/com/teaching/backend/model/entity/know/KnowCourse.java
  38. 2
      src/main/java/com/teaching/backend/model/entity/know/Links.java
  39. 10
      src/main/java/com/teaching/backend/model/entity/knowtmp/Knowtmp.java
  40. 47
      src/main/java/com/teaching/backend/model/entity/resource/Resource.java
  41. 47
      src/main/java/com/teaching/backend/model/entity/resource/ResourceLearningNumber.java
  42. 8
      src/main/java/com/teaching/backend/model/entity/resource/Resources.java
  43. 74
      src/main/java/com/teaching/backend/service/Know/KnowService.java
  44. 138
      src/main/java/com/teaching/backend/service/KnowGraph/KnowGraphService.java
  45. 431
      src/main/java/com/teaching/backend/service/KnowGraph/KnowService.java
  46. 107
      src/main/java/com/teaching/backend/service/KnowGraph/ResourcesService.java
  47. 22
      src/main/java/com/teaching/backend/service/impl/chapter/ChapterServiceImpl.java
  48. 3
      src/main/java/com/teaching/backend/service/impl/courses/CoursesServiceImpl.java
  49. 252
      src/main/java/com/teaching/backend/service/impl/know/knowServiceImpl.java
  50. 73
      src/main/java/com/teaching/backend/service/impl/knowtmp/KnowtmpServiceImpl.java
  51. 96
      src/main/java/com/teaching/backend/service/impl/records/ResourceLearningRecordServiceImpl.java
  52. 22
      src/main/java/com/teaching/backend/service/impl/resource/ResourceLearningNumberServiceImpl.java
  53. 171
      src/main/java/com/teaching/backend/service/impl/resource/ResourceServiceImpl.java
  54. 28
      src/main/java/com/teaching/backend/service/knowtmp/KnowtmpService.java
  55. 2
      src/main/java/com/teaching/backend/service/records/IResourceLearningRecordService.java
  56. 17
      src/main/java/com/teaching/backend/service/resource/IResourceLearningNumberService.java
  57. 33
      src/main/java/com/teaching/backend/service/resource/ResourceService.java
  58. 154
      src/main/java/com/teaching/backend/utils/MinioUtils.java
  59. 35
      src/main/java/com/teaching/backend/utils/knowGraph/AddNeoKnowByCourse.java
  60. 9
      src/main/resources/application.yml

@ -45,6 +45,12 @@
<artifactId>poi-ooxml</artifactId>
</dependency>
<!--MinIO Java SDK依赖-->
<dependency>
<groupId>io.minio</groupId>
<artifactId>minio</artifactId>
<version>8.2.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-fileupload/commons-fileupload -->
<dependency>
<groupId>commons-fileupload</groupId>

@ -11,6 +11,7 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class CorsConfig implements WebMvcConfigurer {
@Override
public void addCorsMappings(CorsRegistry registry) {
// 覆盖所有请求

@ -12,6 +12,8 @@ import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.security.web.SecurityFilterChain;
import org.springframework.security.web.access.intercept.FilterSecurityInterceptor;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
import org.springframework.security.web.firewall.HttpFirewall;
import org.springframework.security.web.firewall.StrictHttpFirewall;
/**
@ -35,6 +37,20 @@ public class SecurityConfig {
@Autowired(required = false)
private DynamicSecurityFilter dynamicSecurityFilter;
/**
* 配置地址栏不能识别 // 的情况
* @return
*/
@Bean
public HttpFirewall allowUrlEncodedSlashHttpFirewall() {
StrictHttpFirewall firewall = new StrictHttpFirewall();
//此处可添加别的规则,目前只设置 允许双 //
firewall.setAllowUrlEncodedDoubleSlash(true);
return firewall;
}
@Bean
SecurityFilterChain filterChain(HttpSecurity httpSecurity) throws Exception {
ExpressionUrlAuthorizationConfigurer<HttpSecurity>.ExpressionInterceptUrlRegistry registry = httpSecurity

@ -0,0 +1,74 @@
package com.teaching.backend.constant;
import org.apache.commons.lang3.StringUtils;
import java.util.HashMap;
import java.util.Map;
/**
* @Author:youhang
* @Date:2024-08-07-9:14
* @Description:
*/
public enum ViewContentTypeEnum {
DEFAULT("default","application/octet-stream"),
PNG("png", "image/png"),
JPEG("jpeg", "image/jpeg"),
JPG("jpg", "image/jpeg"),
GIF("gif", "image/gif"),
WBMP("wbmp", "image/vnd.wap.wbmp"),
TIFF("tiff", "image/tiff"),
JFIF("jfif", "image/jpeg"),
TIF("tif", "image/tiff"),
FAX("fax", "image/fax"),
JPE("jpe", "image/jpeg"),
NET("net", "image/pnetvue"),
RP("rp", "image/vnd.rn-realpix"),
ICO("ico", "image/x-icon");
private String prefix;
private String type;
private static final Map<String, ViewContentTypeEnum> ENUM_MAP = new HashMap<>();
static {
ViewContentTypeEnum[] values = values();
for (ViewContentTypeEnum value : values) {
ENUM_MAP.put(value.getPrefix(), value);
}
}
public static String getTypeByPrefix(String prefix) {
ViewContentTypeEnum viewContentTypeEnum = ENUM_MAP.get(prefix);
if (viewContentTypeEnum == null) {
return prefix;
}
return viewContentTypeEnum.getType();
}
public static String getContentType(String prefix){
if(StringUtils.isEmpty(prefix)){
return DEFAULT.getType();
}
prefix = prefix.substring(prefix.lastIndexOf(".") + 1);
String type = getTypeByPrefix(prefix);
if (StringUtils.isNotEmpty(type)) {
return type;
}
return DEFAULT.getType();
}
ViewContentTypeEnum(String prefix, String type) {
this.prefix = prefix;
this.type = type;
}
public String getPrefix() {
return prefix;
}
public String getType() {
return type;
}
}

@ -0,0 +1,129 @@
package com.teaching.backend.controller.Know;
/**
* @Author:youhang
* @Date:2024-06-09-9:55
* @Description:
*/
import com.teaching.backend.common.BaseResponse;
import com.teaching.backend.model.dto.Know.*;
import com.teaching.backend.model.entity.know.Know;
import com.teaching.backend.model.entity.know.KnowChapter;
import com.teaching.backend.model.entity.know.KnowCourse;
import com.teaching.backend.model.entity.resource.Resources;
import com.teaching.backend.model.vo.knowGraph.KnowVO1;
import com.teaching.backend.service.Know.KnowService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.Set;
@RestController
@RequestMapping("/knowNeo")
public class KnowController {
@Autowired
private KnowService knowService;
// 添加知识点
@PostMapping("/addKnow")
BaseResponse<String> addKnow(@RequestBody KnowRequest knowRequest){
return knowService.addKnow(knowRequest);
}
// 修改知识点
@PostMapping("/updateKnow")
BaseResponse<String> updateKnow(@RequestBody KnowUpdateRequest knowUpdateRequest){
return knowService.updateKnow(knowUpdateRequest);
}
// 删除知识点
@GetMapping("/deleteKnow")
BaseResponse<String> deleteKnow(@RequestParam Long id){
return knowService.deleteKnow(id);
}
//查询知识点通过id
@GetMapping("/queryKnow")
BaseResponse<Know> queryKnow(@RequestParam Long id){
return knowService.queryKnow(id);
}
//======================================
// 添加课程
@PostMapping("/addCourse")
BaseResponse<String> addCourse(@RequestBody KnowCourseCreateRequest knowCourseCreateRequest){
return knowService.addCourse(knowCourseCreateRequest);
}
// 修改课程
@PostMapping("/updateCourse")
BaseResponse<String> updateCourse(@RequestBody KnowCourseCreateRequest knowCourseCreateRequest){
return knowService.updateCourse(knowCourseCreateRequest);
}
// 删除课程
@PostMapping("/deleteCourse")
BaseResponse<String> deleteCourse(@RequestParam String courseId){
return knowService.deleteCourse(courseId);
}
//查询课程通过courseid
@GetMapping ("/queryCourse")
BaseResponse<KnowCourse> queryCourse(@RequestParam String courseId){
return knowService.queryCourse(courseId);
}
//=========================
// 添加章节
@PostMapping("/addChapter")
BaseResponse<String> addChapter(@RequestBody KnowChapterCreateRequest knowChapterCreateRequest){
return knowService.addChapter(knowChapterCreateRequest);
}
// 修改章节
@PostMapping("/updateChapter")
BaseResponse<String> updateChapter(@RequestBody KnowChapterCreateRequest knowChapterCreateRequest){
return knowService.updateChapter(knowChapterCreateRequest);
}
// 删除章节
@GetMapping("/deleteChapter")
BaseResponse<String> deleteChapter(@RequestParam Long chapterId){
return knowService.deleteChapter(chapterId);
}
//查询章节通过chapterId
@PostMapping("/queryChapter")
BaseResponse<KnowChapter> queryChapter(@RequestParam Long chapterId){
return knowService.queryChapter(chapterId);
}
//=====================
//获取课程下的所有知识点
@GetMapping("/getAllKnowByCourseId")
BaseKnowReturn getAllKnowByCourseId(@RequestParam String id){
return knowService.getAllKnowByCourseId(id);
}
//获取课程下的所有资源
@GetMapping("/getAllResourcesByCourseId")
BaseResponse<Set<KnowVO1>> getAllResourcesByCourseId(@RequestParam String id){
return knowService.getAllResourcesByCourseId(id);
}
//获取知识点下二级的所有资源
@GetMapping("/getSecondResources")
Set<Resources> getSecondResources(@RequestParam Long id){
return knowService.getSecondResources(id);
}
}

@ -1,164 +0,0 @@
package com.teaching.backend.controller.KnowGraph;
/**
* @Author:youhang
* @Date:2024-06-09-9:55
* @Description:
*/
import com.teaching.backend.common.BaseResponse;
import com.teaching.backend.common.ResultUtils;
import com.teaching.backend.model.dto.KnowGraph.BaseKnowReturn;
import com.teaching.backend.model.dto.Knowtemp.KnowtempAdd;
import com.teaching.backend.model.dto.Knowtemp.KnowtempUpdate;
import com.teaching.backend.model.entity.Knowtemp.Knowtemp;
import com.teaching.backend.model.vo.knowGraph.KnowVO;
import com.teaching.backend.model.vo.knowGraph.KnowVO1;
import com.teaching.backend.service.KnowGraph.KnowService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Set;
@RestController
@RequestMapping("/know")
public class KnowController {
@Autowired
private KnowService knowService;
//根据 章节id 创建知识点到mysql中
@PostMapping("/add")
public BaseResponse<String> add(@RequestBody KnowtempAdd knowtempAdd) {
return knowService.add(knowtempAdd);
}
@PostMapping("/update")
public BaseResponse<String> update(@RequestBody KnowtempUpdate knowtempUpdate) {
return knowService.update(knowtempUpdate);
}
@PostMapping("/delete")
public BaseResponse<String> delete(@RequestParam Long id) {
return knowService.delete(id);
}
@PostMapping("/query")
public BaseResponse<Knowtemp> query(@RequestParam Long id) {
return knowService.query(id);
}
//根据 课程id 从chapter表中获取List 章节
@PostMapping("/addAll")
public BaseResponse<String> addAll(@RequestParam String id) {
return knowService.saveKnowToNeo(id);
}
// 改变节点关系
@PostMapping("/update/relationship")
public BaseResponse<String> updateRelationship(@RequestParam Long id, @RequestParam List<Long> ids, @RequestParam String relationship) {
return knowService.updateRelationship(id,ids,relationship);
}
//获取该节点下所有的节点
@GetMapping("/all")
public BaseResponse<BaseKnowReturn> getKnowAll(@RequestParam String id) {
BaseKnowReturn baseKnowReturn =knowService.getKnowAll(id);
return ResultUtils.success(baseKnowReturn);
}
@GetMapping("/getAllByCourseId")
public BaseResponse<Set<KnowVO1>> getKnowByCourseId(String id) {
return knowService.getKnowByCourseId(id);
}
// //根据 id查询所关联的所有结点
// @PostMapping ("/query/{id}")
// public List<Know> queryKnowAllKnowById(@PathVariable Long id) {
// return knowService.queryKnowAllKnowById(id);
// }
//
// //添加知识点
// @PostMapping("/add")
// 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("/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 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 Long chapterId) {
// return knowService.deleteKnowChapter(chapterId);
// }
//
// @GetMapping("/KnowBychapterId")
// public Set<Know> queryByChapterId(@RequestParam Long chapterId) {
// return knowService.queryByChapterId(chapterId);
// }
//
//
//
// //添加知识点与知识点的关系 related
// @PostMapping ("/addKnowRelatedKnow")
// public BaseResponse<String> addKnowRelatedKnow(@RequestBody RelationshipKnowRequest relationshipKnowRequest) {
// return knowService.addKnowRelatedKnow(relationshipKnowRequest);
// }
//
// //添加知识点与知识点的关系 fatherandSon
// @PostMapping ("/addKnowFatherAndSonKnow")
// 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);
// }
}

@ -1,56 +0,0 @@
//package com.teaching.backend.controller.KnowGraph;
//
//import com.teaching.backend.common.BaseResponse;
//import com.teaching.backend.model.dto.Knowtemp.KnowtempAdd;
//import com.teaching.backend.model.dto.Knowtemp.KnowtempUpdate;
//import com.teaching.backend.model.entity.KnowGraph.Know;
//import com.teaching.backend.model.entity.Knowtemp.Knowtemp;
//import com.teaching.backend.model.entity.chapter.Chapter;
//import com.teaching.backend.service.KnowGraph.KnowGraphService;
//import io.swagger.models.auth.In;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.web.bind.annotation.*;
//
//import java.util.List;
//
///**
// * @Author:youhang
// * @Date:2024-07-29-10:32
// * @Description:
// */
//@RestController
//@RequestMapping("/knowGraph")
//public class KnowGraphController {
//
// @Autowired
// private KnowGraphService knowGraphService;
//
// //add knowtemp
// @PostMapping("/add")
// public BaseResponse<String> add(@RequestBody KnowtempAdd knowtempAdd) {
// return knowGraphService.add(knowtempAdd);
// }
//
// @PostMapping("/update")
// public BaseResponse<String> update(@RequestBody KnowtempUpdate knowtempUpdate) {
// return knowGraphService.update(knowtempUpdate);
// }
// @PostMapping("/delete")
// public BaseResponse<String> delete(@RequestParam Integer id) {
// return knowGraphService.delete(id);
// }
// @PostMapping("/query")
// public BaseResponse<Knowtemp> query(@RequestParam Integer id) {
// return knowGraphService.query(id);
// }
//
//
// //根据 课程id 从chapter表中获取List 章节
// @PostMapping("/addAll")
// public BaseResponse<String> addAll(@PathVariable String id) {
// return knowGraphService.saveKnowToNeo(id);
// }
//
//
//
//}

@ -1,90 +0,0 @@
package com.teaching.backend.controller.KnowGraph;
/**
* @Author:youhang
* @Date:2024-06-09-9:55
* @Description:
*/
import com.teaching.backend.common.BaseResponse;
import com.teaching.backend.model.dto.KnowGraph.*;
import com.teaching.backend.model.entity.KnowGraph.Know;
import com.teaching.backend.model.entity.KnowGraph.Resources;
import com.teaching.backend.service.KnowGraph.ResourcesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.util.List;
import java.util.Set;
@RestController
@RequestMapping("/resources")
public class ResourcesController {
@Autowired
private ResourcesService resourcesService;
//添加知识点
@PostMapping("/upload")
public BaseResponse<String> uploadFile(@RequestParam("file")MultipartFile file) {
return resourcesService.uploadFile(file);
}
//根据 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);
}
//添加知识点 - 课程
@PostMapping("/addKnowResources")
public void createCourseKnow(@RequestBody RelationshipResourceRequest relationshipResourceRequest) {
resourcesService.addKnowWithResources(relationshipResourceRequest);
}
//修改知识点
@PostMapping ("/update")
public Resources updateKnow(@RequestBody ResourceUpdateRequest resourceUpdateRequest ) {
return resourcesService.updateResources(resourceUpdateRequest);
}
//删除知识点
@GetMapping ("delete/{id}")
public void deleteResource(@PathVariable Long id) {
resourcesService.deleteResources(id);
}
//添加知识点与资源的关系
@PostMapping ("/addKnowResourcesResources")
public void addKnowWithResource(@RequestBody RelationshipResourceRequest relationshipResourceRequest) {
resourcesService.addKnowWithResources(relationshipResourceRequest);
}
@GetMapping ("queryCourseKnow/{KnowId}")
public Set<Resources> queryCourseKnowToResources(@PathVariable Long KnowId) {
return resourcesService.queryCourseKnowToResources(KnowId);
}
@GetMapping ("queryBesidesKnowToResources/{KnowId}")
public List<MultipartFile> queryBesidesKnowToResources(@PathVariable Long KnowId) {
return resourcesService.queryBesidesKnowToResources(KnowId);
}
}

@ -0,0 +1,51 @@
package com.teaching.backend.controller.Knowtmp;
import com.teaching.backend.common.BaseResponse;
import com.teaching.backend.model.dto.Knowtmp.KnowtempAdd;
import com.teaching.backend.model.dto.Knowtmp.KnowtempUpdate;
import com.teaching.backend.model.entity.knowtmp.Knowtmp;
import com.teaching.backend.service.knowtmp.KnowtmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* @Author:youhang
* @Date:2024-08-07-19:38
* @Description:
*/
@RestController
@RequestMapping("/knowtmp")
public class KnowtmpController {
@Autowired
private KnowtmpService knowtmpService;
// 添加知识点
@PostMapping("/addKnow")
BaseResponse<String> add(@RequestBody KnowtempAdd knowtempAdd){
return knowtmpService.add(knowtempAdd);
}
//修改知识点
@PostMapping("/updateKnow")
BaseResponse<String> update(@RequestBody KnowtempUpdate knowtempUpdate){
return knowtmpService.update(knowtempUpdate);
}
//删除知识点
@GetMapping("/deleteKnow")
BaseResponse<String> delete(Long id){
return knowtmpService.delete(id);
}
//查询通过chapterId List
@GetMapping("/queryKnow")
BaseResponse<List<Knowtmp>> queryByChapterId(Long chapterId){
return knowtmpService.queryByChapterId(chapterId);
}
}

@ -20,10 +20,10 @@ public class ResourceLearningRecordController {
@Resource
private ResourceLearningRecordServiceImpl resourceLearningRecordService;
@ApiOperation("添加资源学习记录")
// @ValidateParams({"userId","type","coursesId"})
@PostMapping("/saverecords")
public BaseResponse<String> saveResourceRecords(@RequestBody ResourceLearningRecord resourceLearningRecord) {
return resourceLearningRecordService.saveCoursesRecords(resourceLearningRecord);
}
// @ApiOperation("添加资源学习记录")
//// @ValidateParams({"userId","type","coursesId"})
// @PostMapping("/saverecords")
// public BaseResponse<String> saveResourceRecords(@RequestBody ResourceLearningRecord resourceLearningRecord) {
// return resourceLearningRecordService.saveCoursesRecords(resourceLearningRecord);
// }
}

@ -1,52 +1,83 @@
package com.teaching.backend.controller.resource;
import com.teaching.backend.common.BaseResponse;
import com.teaching.backend.common.ResultUtils;
import com.teaching.backend.service.KnowGraph.ResourcesService;
/**
* @Author:youhang
* @Date:2024-06-09-9:55
* @Description:
*/
import com.teaching.backend.common.BaseResponse;
import com.teaching.backend.model.dto.resource.ResourceUploadDto;
import com.teaching.backend.model.entity.resource.Resources;
import com.teaching.backend.service.resource.ResourceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.InputStreamResource;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Set;
import java.io.*;
/**
* ClassName: CommonController
* Package: com.teaching.backend.controller
* Description:
*
* @Author 姜钧瀚
* @Create 2024/6/1 10:30
* @Version 1.0
*/
@RestController
@RequestMapping("/resource")
public class ResourceController {
@Autowired
private ResourcesService resourcesService;
private ResourceService resourceService;
//添加知识点
@PostMapping("/upload")
public BaseResponse<String> uploadFile(@RequestParam("file")MultipartFile file) {
return resourcesService.uploadFile(file);
@ResponseBody
public BaseResponse<ResourceUploadDto> uploadFile(@RequestPart("file") MultipartFile file) {
return resourceService.upload(file);
}
//删除资源
@GetMapping ("delete")
@ResponseBody
public BaseResponse<String> deleteResource(@RequestParam("filename") String filename) {
return resourceService.delete(filename);
}
@GetMapping("/read")
public ResponseEntity<InputStreamResource> readFile(@RequestParam String filename) {
return resourceService.readFile(filename);
}
@GetMapping("/addRelationship/BetweenCourseAndResources")
public BaseResponse<String> addResourcesAndKnowByCourseId(@RequestParam String courseId, @RequestParam List<Long> resourcesIds){
return resourceService.addResourcesAndKnowByCourseId(courseId,resourcesIds);
}
@GetMapping("/addRelationship/BetweenChapterAndResources")
public BaseResponse<String> addResourcesAndKnowByChapterId(@RequestParam Long chapterId,@RequestParam List<Long> resourcesIds){
return resourceService.addResourcesAndKnowByChapterId(chapterId,resourcesIds);
}
@GetMapping("/addRelationship/BetweenKnowAndResources")
public BaseResponse<String> addResourcesAndKnowById(@RequestParam Long id, @RequestParam List<Long> resourcesIds){
return resourceService.addResourcesAndKnowById(id,resourcesIds);
}
}
//查询课程下资源
@GetMapping("/queryByCourseId")
Set<Resources> queryResourcesByCourseId(String courseId){
return resourceService.queryResourcesByCourseId(courseId);
}
//查询章节下资源
@GetMapping("/queryByChapterId")
Set<Resources> queryResourcesByChapterId(Long chapterId){
return resourceService.queryResourcesByChapterId(chapterId);
}
//查询二级节点下资源
@GetMapping("/queryBesidesKnow")
Set<Resources> queryBesidesKnowToResources(Long KnowId){
return resourceService.queryBesidesKnowToResources(KnowId);
}
}

@ -1,78 +0,0 @@
package com.teaching.backend.mapper.KnowGraph;
/**
* @Author:youhang
* @Date:2024-06-09-8:59
* @Description:
*/
import com.teaching.backend.model.dto.KnowGraph.KnowCourseCreateRequest;
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 org.springframework.data.neo4j.repository.Neo4jRepository;
import org.springframework.data.neo4j.repository.query.Query;
import java.util.List;
import java.util.Set;
public interface KnowRepository extends Neo4jRepository<Know, Long> {
@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)-[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);
@Query("CREATE (n:Know {name: $name, courseId: $courseId,info:$info}) return count(n)")
int createKnowCourse(String courseId, String name, String info);
@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)")
int createKnowChapter(Long chapterId, String name, String info);
@Query("MATCH (p:Know {chapterId:$chapterId }) SET p.name = $name set p.info= $info RETURN p;")
Boolean updateKnowChapter(Long chapterId, String name, String info);
@Query("MATCH (p:Know {chapterId:$chapterId }) RETURN count(p);")
Boolean deleteKnowChapter(Long chapterId);
@Query("MATCH(n:Know)-[r:FatherAndSon*]->(nn:Know) where n.chapterId = $chapterId RETURN nn")
Set<Know> queryByChapterId(Long chapterId);
//在章节表里面添加章与课程的关系
@Query("MATCH (p:Know), (c:Know) WHERE p.courseId = $courseId AND c.chapterId = $ChapterId CREATE (p)-[r:FatherAndSon]->(c) return count(r)")
int addChapterAndCourse(String courseId, Long ChapterId);
//添加章与节的关系
@Query("MATCH (p:Know), (c:Know) WHERE p.chapterId = $ChapterId1 AND c.chapterId = $ChapterId2 CREATE (p)-[r:FatherAndSon]->(c) return count(r)")
int addChapterAndCourse( Long ChapterId1, Long ChapterId2);
//创造知识点并,添加节与知识点的关系
@Query("MATCH (p:Know) WHERE p.chapterId = $ChapterId CREATE (c:Know{name:$name,info:$info}),(p)-[r:FatherAndSon]->(c) return count(r)")
int CreateKnowaddChapter( Long ChapterId, String name,String info);
@Query("MATCH (p:Know), (c:Know) WHERE ID(p) = $id AND ID(c) IN $KnowIds CREATE (p)-[r:FatherAndSon]->(c),(c)-[:related]->(p) return count(r)")
int addKnowWithFaherAndSon(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 addKnowWithRelated(Long id, List<Long> KnowIds);
@Query("MATCH (p:Know), (c:Know) WHERE ID(p) = $id AND ID(c) IN $KnowIds CREATE (p)-[r:PreCondition]->(c),(c)-[:related]->(p) return count(r)")
int addKnowWithPreCondition(Long id, List<Long> KnowIds);
}

@ -1,43 +0,0 @@
package com.teaching.backend.mapper.KnowGraph;
/**
* @Author:youhang
* @Date:2024-06-09-8:59
* @Description:
*/
import java.util.concurrent.*;
import com.teaching.backend.model.entity.KnowGraph.Know;
import com.teaching.backend.model.entity.KnowGraph.Resources;
import org.neo4j.driver.Result;
import org.springframework.data.neo4j.repository.Neo4jRepository;
import org.springframework.data.neo4j.repository.query.Query;
import java.util.List;
import java.util.Set;
public interface ResourcesRepository extends Neo4jRepository<Resources, Long> {
@Query("MATCH(n:Resources) where n.resourcesId = $resourcesId RETURN n")
Resources queryResources(Long resourcesId);
@Query("MATCH (p:Know), (c:Resources) WHERE ID(p) = $id AND ID(c) in $ResourcesIds CREATE (p)-[r:resources]->(c)")
void addResourceResourcesKnow(Long id, List<Long> ResourcesIds);
@Query("MATCH(n:Know)-[r:resources]->(nn:Resources) where ID(nn) = $id RETURN nn")
List<Resources> queryResourceAllId(Long id);
@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);
@Query(" MATCH (p:Know)-[:resources]->(m:Resources) WHERE ID(p) = 272 RETURN m")
Set<Resources> queryKnowToResources(Long KnowId);
}

@ -1,15 +0,0 @@
package com.teaching.backend.mapper.Knowtemp;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.teaching.backend.model.entity.Knowtemp.Knowtemp;
/**
* 课程点赞数据库操作
*/
public interface KnowtempMapper extends BaseMapper<Knowtemp> {
}

@ -0,0 +1,18 @@
package com.teaching.backend.mapper.Knowtemp;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.teaching.backend.model.entity.knowtmp.Knowtmp;
import org.apache.ibatis.annotations.Mapper;
/**
*
*/
@Mapper
public interface KnowtmpMapper extends BaseMapper<Knowtmp> {
}

@ -0,0 +1,66 @@
package com.teaching.backend.mapper.know;
/**
* @Author:youhang
* @Date:2024-06-09-8:59
* @Description:
*/
import com.teaching.backend.model.entity.know.Know;
import com.teaching.backend.model.entity.know.KnowChapter;
import com.teaching.backend.model.entity.know.KnowCourse;
import com.teaching.backend.model.entity.resource.Resources;
import org.springframework.data.neo4j.repository.Neo4jRepository;
import org.springframework.data.neo4j.repository.query.Query;
import java.util.Set;
public interface KnowRepository extends Neo4jRepository<Know, Long> {
@Query("CREATE (n:Know {name: $name,info:$info}) return count(n)")
int addKnow(String name,String info);
@Query("MATCH ID(p:Know) = $id SET p.name = $name set p.info= $info RETURN count(p);")
int updateKnow(Long id, String name, String info);
@Query("MATCH ID(p:Know) = $id delete p RETURN count(p);")
int deleteKnow(Long id);
@Query("MATCH ID(p:Know) = $id RETURN p;")
Know queryKnow(Long id);
//=============================
@Query("CREATE (n:Know {name: $name, courseId: $courseId,info:$info}) return count(n)")
int addCourse(String courseId, String name, String info);
@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);")
int deleteCourse(String courseId);
@Query("MATCH (p:Know {courseId:$courseId }) RETURN p;")
KnowCourse queryCourse(String courseId);
//====================
@Query("CREATE (n:Know {name: $name, chapterId:$chapterId,info:$info}) return count(n)")
int addChapter(Long chapterId, String name, String info);
@Query("MATCH (p:Know {chapterId:$chapterId }) SET p.name = $name set p.info= $info RETURN count(p);")
int updateChapter(Long chapterId, String name, String info);
@Query("MATCH (p:Know {chapterId:$chapterId }) delete p RETURN count(p);")
int deleteChapter(Long chapterId);
@Query("MATCH (p:Know {chapterId:$chapterId }) RETURN p;")
KnowChapter queryChapter(Long chapterId);
//查询二级节点下资源
@Query("MATCH (p:Know)-[:FatherAndSon]->(n:Know)-[:resources]->(m:Resources) WHERE ID(p) = $id RETURN m")
Set<Resources> queryBesidesKnowToResources(Long id);
}

@ -1,17 +0,0 @@
package com.teaching.backend.mapper.resource;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.teaching.backend.model.entity.resource.ResourceLearningNumber;
/**
* <p>
* Mapper 接口
* </p>
*
* @author author
* @since 2024-07-29
*/
public interface ResourceLearningNumberMapper extends BaseMapper<ResourceLearningNumber> {
}

@ -1,20 +0,0 @@
package com.teaching.backend.mapper.resource;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.teaching.backend.model.entity.resource.Resource;
import org.apache.ibatis.annotations.Mapper;
/**
* ClassName: FileTableMapper
* Package: com.teaching.backend.mapper
* Description:
*
* @Author 姜钧瀚
* @Create 2024/6/4 11:51
* @Version 1.0
*/
@Mapper
public interface ResourcesMapper extends BaseMapper<Resource> {
}

@ -0,0 +1,64 @@
package com.teaching.backend.mapper.resource;
/**
* @Author:youhang
* @Date:2024-06-09-8:59
* @Description:
*/
import com.teaching.backend.model.entity.resource.Resources;
import org.springframework.data.neo4j.repository.Neo4jRepository;
import org.springframework.data.neo4j.repository.query.Query;
import java.util.List;
import java.util.Set;
public interface ResourcesRepository extends Neo4jRepository<Resources, Long> {
//删除资源节点
@Query("MATCH(n:Resources) where n.name = $name DETACH DELETE n RETURN COUNT(n) >0;")
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)")
int addResourcesAndKnowByCourseId(String courseId, List<Long> resourcesIds);
//添加章节与资源关系
@Query("MATCH (p:Know), (c:Resources) WHERE p.chapterId = $chapterId AND ID(c) in $resourcesIds CREATE (p)-[r:resources]->(c) return count(r)")
int addResourcesAndKnowByChapterId(Long chapterId, List<Long> resourcesIds);
//添加知识点与资源关系
@Query("MATCH (p:Know), (c:Resources) WHERE ID(p) = $id AND ID(c) in $resourcesIds CREATE (p)-[r:resources]->(c) return count(r)")
int addResourcesAndKnowById(Long id, List<Long> resourcesIds);
//查询课程下资源
@Query("MATCH p = (a:Know)-[rels*]-(b:Resources) WHERE a.courseId = $courseId and ANY(rel IN rels WHERE TYPE(rel) = 'resources') RETURN b")
Set<Resources> queryResourcesByCourseId(String courseId);
//查询章节下资源
@Query("MATCH p = (a:Know)-[rels*]-(b:Resources) WHERE a.chapterId = chapterId and ANY(rel IN rels WHERE TYPE(rel) = 'resources') RETURN b")
Set<Resources> queryResourcesByChapterId(Long chapterId);
//查询二级节点下资源
@Query("MATCH (p:Know)-[:FatherAndSon]->(n:Know)-[:resources]->(m:Resources) WHERE ID(p) = $KnowId RETURN m")
Set<Resources> queryBesidesKnowToResources(Long KnowId);
//
//
// @Query("MATCH(n:Know)-[r:resources]->(nn:Resources) where ID(nn) = $id RETURN nn")
// List<Resource> queryResourceAllId(Long id);
//
// @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)-[:resources]->(m:Resources) WHERE ID(p) = 272 RETURN m")
// Set<Resources> queryKnowToResources(Long KnowId);
}

@ -1,4 +1,4 @@
package com.teaching.backend.model.dto.KnowGraph;
package com.teaching.backend.model.dto.Know;
/**
* @Author:youhang
@ -7,7 +7,7 @@ package com.teaching.backend.model.dto.KnowGraph;
*/
import com.teaching.backend.model.entity.KnowGraph.Links;
import com.teaching.backend.model.entity.know.Links;
import com.teaching.backend.model.vo.knowGraph.KnowVO;
import lombok.AllArgsConstructor;
import lombok.Data;

@ -1,10 +1,8 @@
package com.teaching.backend.model.dto.KnowGraph;
package com.teaching.backend.model.dto.Know;
import lombok.Data;
import org.springframework.data.neo4j.core.schema.Property;
import java.io.Serializable;
import java.util.List;
@Data
public class KnowChapterCreateRequest implements Serializable {

@ -1,10 +1,8 @@
package com.teaching.backend.model.dto.KnowGraph;
package com.teaching.backend.model.dto.Know;
import lombok.Data;
import org.springframework.data.neo4j.core.schema.Property;
import java.io.Serializable;
import java.util.List;
@Data
public class KnowCourseCreateRequest implements Serializable {

@ -1,10 +1,8 @@
package com.teaching.backend.model.dto.KnowGraph;
package com.teaching.backend.model.dto.Know;
import lombok.Data;
import org.springframework.data.neo4j.core.schema.Property;
import java.io.Serializable;
import java.util.List;
@Data
public class KnowRequest implements Serializable {

@ -1,10 +1,8 @@
package com.teaching.backend.model.dto.KnowGraph;
package com.teaching.backend.model.dto.Know;
import lombok.Data;
import org.springframework.data.neo4j.core.schema.Property;
import java.io.Serializable;
import java.util.List;
@Data
public class KnowUpdateRequest implements Serializable {

@ -1,4 +1,4 @@
package com.teaching.backend.model.dto.KnowGraph;
package com.teaching.backend.model.dto.Know;
import lombok.Data;

@ -1,4 +1,4 @@
package com.teaching.backend.model.dto.KnowGraph;
package com.teaching.backend.model.dto.Know;
import lombok.Data;

@ -1,22 +0,0 @@
package com.teaching.backend.model.dto.KnowGraph;
import lombok.Data;
/**
* @Author:youhang
* @Date:2024-07-25-8:39
* @Description:
*/
@Data
public class ResourceUpdateRequest {
private Long id;
private String name;
private Integer type;
private String path;
}

@ -1,19 +0,0 @@
package com.teaching.backend.model.dto.KnowGraph;
import lombok.Data;
import org.springframework.data.neo4j.core.schema.Property;
/**
* @Author:youhang
* @Date:2024-07-25-8:39
* @Description:
*/
@Data
public class ResourcesAddRequest {
private String name;
private Integer type;
private String path;
}

@ -1,15 +0,0 @@
package com.teaching.backend.model.dto.KnowGraph;
import lombok.Data;
import org.springframework.web.multipart.MultipartFile;
/**
* @Author:youhang
* @Date:2024-07-25-8:39
* @Description:
*/
@Data
public class ResourcesRequest {
private MultipartFile file;
}

@ -1,8 +1,5 @@
package com.teaching.backend.model.dto.Knowtemp;
package com.teaching.backend.model.dto.Knowtmp;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import lombok.Data;
import java.io.Serializable;
@ -24,7 +21,6 @@ public class KnowtempAdd implements Serializable {
private Long chapterid;
private String courseid;
private Integer ordernum;

@ -1,6 +1,5 @@
package com.teaching.backend.model.dto.Knowtemp;
package com.teaching.backend.model.dto.Knowtmp;
import io.swagger.models.auth.In;
import lombok.Data;
import java.io.Serializable;
@ -23,8 +22,6 @@ public class KnowtempUpdate implements Serializable {
private String info;
private Long chapterid;
private String courseid;
private Integer ordernum;

@ -0,0 +1,31 @@
package com.teaching.backend.model.dto.resource;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.util.List;
/**
* Minio Bucket访问策略配置
* Created by macro on 2020/8/11.
*/
@Data
@EqualsAndHashCode
@Builder
public class BucketPolicyConfigDto {
private String Version;
private List<Statement> Statement;
@Data
@EqualsAndHashCode
@Builder
public static class Statement {
private String Effect;
private String Principal;
private String Action;
private String Resource;
}
}

@ -0,0 +1,22 @@
package com.teaching.backend.model.dto.resource;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
* 文件上传返回结果
* Created by macro on 2019/12/25.
*/
@Data
@EqualsAndHashCode
public class ResourceUploadDto {
private String url;
private String name;
private String objectName;
}

@ -4,8 +4,8 @@ import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.teaching.backend.model.entity.KnowGraph.Know;
import com.teaching.backend.model.entity.Knowtemp.Knowtemp;
import com.teaching.backend.model.entity.knowtmp.Knowtmp;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
@ -90,7 +90,7 @@ public class Chapter implements Serializable {
@ApiModelProperty(value = "知识点")
@TableField(exist = false)
private List<Knowtemp> knowledgePoints; // 用于存储章节下的知识点
private List<Knowtmp> knowledgePoints; // 用于存储章节下的知识点
}

@ -1,4 +1,4 @@
package com.teaching.backend.model.entity.KnowGraph;
package com.teaching.backend.model.entity.know;
import lombok.Data;
import org.springframework.data.neo4j.core.schema.GeneratedValue;
@ -7,7 +7,6 @@ import org.springframework.data.neo4j.core.schema.Node;
import org.springframework.data.neo4j.core.schema.Property;
import java.io.Serializable;
import java.util.List;
@Node
@Data
@ -20,7 +19,6 @@ public class Know implements Serializable {
@GeneratedValue
private Long id;
/**
* 知识点名称
*/

@ -1,4 +1,4 @@
package com.teaching.backend.model.entity.KnowGraph;
package com.teaching.backend.model.entity.know;
import lombok.Data;
import org.springframework.data.neo4j.core.schema.GeneratedValue;
@ -7,7 +7,6 @@ import org.springframework.data.neo4j.core.schema.Node;
import org.springframework.data.neo4j.core.schema.Property;
import java.io.Serializable;
import java.util.List;
@Node
@Data
@ -24,7 +23,7 @@ public class KnowChapter implements Serializable {
/**
* 章节id
*/
private String chapterId;
private Long chapterId;
/**

@ -1,4 +1,4 @@
package com.teaching.backend.model.entity.KnowGraph;
package com.teaching.backend.model.entity.know;
import lombok.Data;
import org.springframework.data.neo4j.core.schema.GeneratedValue;
@ -7,7 +7,6 @@ import org.springframework.data.neo4j.core.schema.Node;
import org.springframework.data.neo4j.core.schema.Property;
import java.io.Serializable;
import java.util.List;
@Node
@Data

@ -1,4 +1,4 @@
package com.teaching.backend.model.entity.KnowGraph;
package com.teaching.backend.model.entity.know;
import lombok.Data;
import org.springframework.data.neo4j.core.schema.GeneratedValue;

@ -1,13 +1,9 @@
package com.teaching.backend.model.entity.Knowtemp;
package com.teaching.backend.model.entity.knowtmp;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.models.auth.In;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import java.io.Serializable;
@ -20,7 +16,7 @@ import java.io.Serializable;
* @since 2024-05-31
*/
@Data
public class Knowtemp implements Serializable {
public class Knowtmp implements Serializable {
@TableField(exist = false)
private static final long serialVersionUID = 1L;
@ -36,7 +32,5 @@ public class Knowtemp implements Serializable {
private Long chapterid;
private String courseid;
}

@ -1,47 +0,0 @@
package com.teaching.backend.model.entity.resource;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;
import java.util.stream.Stream;
/**
* ClassName: FileTable
* Package: com.teaching.backend.model.entity
* Description:
*
* @Author youhang
* @Create 2024/6/4 11:48
* @Version 1.0
*/
@Data
@TableName("Resource")
public class Resource {
private static final long serialVersionUID = 1L;
/**
* 内部编号
*/
@TableId(value = "id", type = IdType.ASSIGN_ID)
private String id;
private String name;
private int type;
private int status;
private String tags;
private String path;
/**
* 简介
*/
private String description;
/**
* 封面
*/
private String img;
}

@ -1,47 +0,0 @@
package com.teaching.backend.model.entity.resource;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import java.io.Serializable;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
/**
* <p>
*
* </p>
*
* @author author
* @since 2024-07-29
*/
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName("resource_learning_number")
@ApiModel(value="ResourceLearningNumber对象", description="")
public class ResourceLearningNumber implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "资源学习记录id")
@TableId(value = "id", type = IdType.ASSIGN_ID)
private String id;
@ApiModelProperty(value = "课程id")
private String courseId;
@ApiModelProperty(value = "知识点id")
private String knowledgeId;
@ApiModelProperty(value = "资源id")
private String resourceId;
@ApiModelProperty(value = "学习人数")
private Integer number;
}

@ -1,4 +1,4 @@
package com.teaching.backend.model.entity.KnowGraph;
package com.teaching.backend.model.entity.resource;
import lombok.Data;
import org.springframework.data.neo4j.core.schema.GeneratedValue;
@ -18,13 +18,13 @@ public class Resources {
@GeneratedValue
private Long id;
@Property
private String name;
@Property
private Integer type;
private Integer status;
@Property
private String path;
private String url;
}

@ -0,0 +1,74 @@
package com.teaching.backend.service.Know;
import com.teaching.backend.common.BaseResponse;
import com.teaching.backend.model.dto.Know.*;
import com.teaching.backend.model.entity.know.Know;
import com.teaching.backend.model.entity.know.KnowChapter;
import com.teaching.backend.model.entity.know.KnowCourse;
import com.teaching.backend.model.entity.resource.Resources;
import com.teaching.backend.model.vo.knowGraph.KnowVO1;
import java.util.Set;
/**
* @Author:youhang
* @Date:2024-08-07-15:50
* @Description:
*/
public interface KnowService {
// 添加知识点
BaseResponse<String> addKnow(KnowRequest knowRequest);
// 修改知识点
BaseResponse<String> updateKnow(KnowUpdateRequest knowUpdateRequest);
// 删除知识点
BaseResponse<String> deleteKnow(Long id);
//查询知识点通过id
BaseResponse<Know> queryKnow(Long id);
//======================================
// 添加课程
BaseResponse<String> addCourse(KnowCourseCreateRequest knowCourseCreateRequest);
// 修改课程
BaseResponse<String> updateCourse(KnowCourseCreateRequest knowCourseCreateRequest);
// 删除课程
BaseResponse<String> deleteCourse(String courseId);
//查询课程通过courseid
BaseResponse<KnowCourse> queryCourse(String courseId);
//=========================
// 添加章节
BaseResponse<String> addChapter(KnowChapterCreateRequest knowChapterCreateRequest);
// 修改章节
BaseResponse<String> updateChapter(KnowChapterCreateRequest knowChapterCreateRequest);
// 删除章节
BaseResponse<String> deleteChapter(Long chapterId);
//查询章节通过chapterId
BaseResponse<KnowChapter> queryChapter(Long chapterId);
//=====================
//获取课程下的所有知识点
BaseKnowReturn getAllKnowByCourseId(String id);
//获取课程下的所有资源
BaseResponse<Set<KnowVO1>> getAllResourcesByCourseId(String id);
//获取知识点下二级的所有资源
Set<Resources> getSecondResources(Long id);
}

@ -1,138 +0,0 @@
//package com.teaching.backend.service.KnowGraph;
//
//import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
//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.mapper.Knowtemp.KnowtempMapper;
//import com.teaching.backend.mapper.chapter.ChapterMapper;
//import com.teaching.backend.mapper.courses.CoursesMapper;
//import com.teaching.backend.model.dto.Knowtemp.KnowtempAdd;
//import com.teaching.backend.model.dto.Knowtemp.KnowtempUpdate;
//import com.teaching.backend.model.entity.KnowGraph.Know;
//import com.teaching.backend.model.entity.Knowtemp.Knowtemp;
//import com.teaching.backend.model.entity.chapter.Chapter;
//import com.teaching.backend.model.entity.courses.Courses;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Service;
//
//import java.time.LocalDateTime;
//import java.util.ArrayList;
//import java.util.List;
//
///**
// * @Author:youhang
// * @Date:2024-07-29-10:33
// * @Description:
// */
//@Service
//public class KnowGraphService {
//
// @Autowired
// private ChapterMapper chapterMapper;
//
// @Autowired
// private KnowtempMapper knowtempMapper;
//
// @Autowired
// private CoursesMapper coursesMapper;
//
// @Autowired
// private KnowRepository knowRepository;
//
// public BaseResponse<String> add(KnowtempAdd knowtempAdd){
// String name = knowtempAdd.getName();
// String info = knowtempAdd.getInfo();
// Integer chapterId = knowtempAdd.getChapterId();
//
// Knowtemp knowtemp = new Knowtemp();
// knowtemp.setName(name);
// knowtemp.setInfo(info);
// knowtemp.setChapterId(chapterId);
// int insert = knowtempMapper.insert(knowtemp);
// if(insert > 0){
// return ResultUtils.success("添加成功");
// }
// return ResultUtils.error(ErrorCode.OPERATION_ERROR);
// }
//
//// public BaseResponse<String> update(KnowtempUpdate knowtempUpdate){
//// Integer id = knowtempUpdate.getId();
//// String name = knowtempUpdate.getName();
//// String info = knowtempUpdate.getInfo();
//// Integer chapterId = knowtempUpdate.getChapterId();
//// Knowtemp knowtemp = new Knowtemp();
//// knowtemp = knowtempMapper.selectById(id);
//// if(knowtemp == null){
//// return ResultUtils.error(ErrorCode.NOT_FOUND_ERROR);
//// }
//// knowtemp.setName(name);
//// knowtemp.setInfo(info);
//// knowtemp.setChapterId(chapterId);
//// int insert = knowtempMapper.updateById(knowtemp);
//// if(insert > 0){
//// return ResultUtils.success("修改成功");
//// }
//// return ResultUtils.error(ErrorCode.OPERATION_ERROR);
//// }
////
//// public BaseResponse<String> delete(Integer id){
//// Knowtemp knowtemp = new Knowtemp();
//// knowtemp = knowtempMapper.selectById(id);
//// if(knowtemp == null){
//// return ResultUtils.error(ErrorCode.NOT_FOUND_ERROR);
//// }
//// int insert = knowtempMapper.deleteById(id);
//// if(insert > 0){
//// return ResultUtils.success("删除成功");
//// }
//// return ResultUtils.error(ErrorCode.OPERATION_ERROR);
//// }
////
//// public BaseResponse<Knowtemp> query(Integer id){
//// Knowtemp knowtemp = new Knowtemp();
//// knowtemp = knowtempMapper.selectById(id);
//// if(knowtemp != null){
//// return ResultUtils.success(knowtemp);
//// }
//// return ResultUtils.error(ErrorCode.NOT_FOUND_ERROR);
//// }
//
//
//// public BaseResponse<String> saveKnowToNeo(String id) {
//// Courses courses = coursesMapper.selectById(id);
//// int f = knowRepository.createKnowCourse(courses.getId(),courses.getName(),courses.getDescription());
//// if(f <= 0)return ResultUtils.error(ErrorCode.OPERATION_ERROR);
////
//// List<Chapter> chapterList = chapterMapper.selectSectionsByCourseId(id);
//// for (int i = 0; i < chapterList.size(); i++) {
//// Chapter chapter = chapterList.get(i);
//// f = knowRepository.createKnowChapter(chapter.getId(),chapter.getName(),chapter.getContent());
//// if(f <= 0)return ResultUtils.error(ErrorCode.OPERATION_ERROR);
//// }
//// for (int i = 0; i < chapterList.size(); i++) {
//// Chapter chapter = chapterList.get(i);
//// if("".equals(chapter.getPid())){
//// f = knowRepository.addCourseFatherAndSonKnow(chapter.getCourseId(),chapter.getId());
//// if(f <= 0)return ResultUtils.error(ErrorCode.OPERATION_ERROR);
//// }else{
//// f = knowRepository.addChapterFatherAndSonKnow(chapter.getPid(),chapter.getId());
//// if(f <= 0)return ResultUtils.error(ErrorCode.OPERATION_ERROR);
//// }
////
//// }
//// QueryWrapper queryWrapper = new QueryWrapper<>();
//// queryWrapper.eq("courseid",id);
//// List<Knowtemp> list = knowtempMapper.selectList(queryWrapper);
//// for (int j = 0; j < list.size(); j++) {
//// Knowtemp knowtemp = list.get(j);
//// f = knowRepository.addFatherAndSonKnow(knowtemp.getChapterId(),knowtemp.getName(),knowtemp.getInfo());
//// if(f <= 0)return ResultUtils.error(ErrorCode.OPERATION_ERROR);
//// }
////
//// return ResultUtils.success("添加成功");
//// }
//
//
//}

@ -1,431 +0,0 @@
package com.teaching.backend.service.KnowGraph;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
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.mapper.Knowtemp.KnowtempMapper;
import com.teaching.backend.mapper.chapter.ChapterMapper;
import com.teaching.backend.mapper.courses.CoursesMapper;
import com.teaching.backend.model.dto.KnowGraph.*;
import com.teaching.backend.model.dto.Knowtemp.KnowtempAdd;
import com.teaching.backend.model.dto.Knowtemp.KnowtempUpdate;
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.Knowtemp.Knowtemp;
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 com.teaching.backend.model.vo.knowGraph.KnowVO1;
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.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.*;
/**
* @Author:youhang
* @Date:2024-07-21-14:46
* @Description:
*/
@Service
public class KnowService {
@Autowired
private KnowRepository knowRepository;
@Autowired
private ChapterMapper chapterMapper;
@Autowired
private KnowtempMapper knowtempMapper;
@Autowired
private CoursesMapper coursesMapper;
@Resource
private Neo4jClient neo4jClient;
public BaseResponse<String> add(KnowtempAdd knowtempAdd){
String name = knowtempAdd.getName();
String info = knowtempAdd.getInfo();
Long chapterId = knowtempAdd.getChapterid();
String courseid = knowtempAdd.getCourseid();
Knowtemp knowtemp = new Knowtemp();
knowtemp.setName(name);
knowtemp.setInfo(info);
knowtemp.setChapterid(chapterId);
knowtemp.setCourseid(courseid);
int insert = knowtempMapper.insert(knowtemp);
if(insert > 0){
return ResultUtils.success("添加成功");
}
return ResultUtils.error(ErrorCode.OPERATION_ERROR);
}
public BaseResponse<String> update(KnowtempUpdate knowtempUpdate){
Long id = knowtempUpdate.getId();
String name = knowtempUpdate.getName();
String info = knowtempUpdate.getInfo();
Long chapterId = knowtempUpdate.getChapterid();
String courseid = knowtempUpdate.getCourseid();
Knowtemp knowtemp = new Knowtemp();
knowtemp = knowtempMapper.selectById(id);
if(knowtemp == null){
return ResultUtils.error(ErrorCode.NOT_FOUND_ERROR);
}
knowtemp.setName(name);
knowtemp.setInfo(info);
knowtemp.setChapterid(chapterId);
knowtemp.setCourseid(courseid);
int insert = knowtempMapper.updateById(knowtemp);
if(insert > 0){
return ResultUtils.success("修改成功");
}
return ResultUtils.error(ErrorCode.OPERATION_ERROR);
}
public BaseResponse<String> delete(Long id){
Knowtemp knowtemp = new Knowtemp();
knowtemp = knowtempMapper.selectById(id);
if(knowtemp == null){
return ResultUtils.error(ErrorCode.NOT_FOUND_ERROR);
}
int insert = knowtempMapper.deleteById(id);
if(insert > 0){
return ResultUtils.success("删除成功");
}
return ResultUtils.error(ErrorCode.OPERATION_ERROR);
}
public BaseResponse<Knowtemp> query(Long id){
Knowtemp knowtemp = new Knowtemp();
knowtemp = knowtempMapper.selectById(id);
if(knowtemp != null){
return ResultUtils.success(knowtemp);
}
return ResultUtils.error(ErrorCode.NOT_FOUND_ERROR);
}
public BaseResponse<String> saveKnowToNeo(String id) {
Courses courses = coursesMapper.selectById(id);
int f = knowRepository.createKnowCourse(courses.getId(),courses.getName(),courses.getDescription());
if(f <= 0)return ResultUtils.error(ErrorCode.OPERATION_ERROR);
List<Chapter> chapterList = chapterMapper.selectSectionsByCourseId(id);
for (int i = 0; i < chapterList.size(); i++) {
Chapter chapter = chapterList.get(i);
f = knowRepository.createKnowChapter(chapter.getId(),chapter.getName(),chapter.getContent());
if(f <= 0)return ResultUtils.error(ErrorCode.OPERATION_ERROR);
}
for (int i = 0; i < chapterList.size(); i++) {
Chapter chapter = chapterList.get(i);
if(chapter.getPid()== 0){
f = knowRepository.addChapterAndCourse(chapter.getCourseId(),chapter.getId());
if(f <= 0)return ResultUtils.error(ErrorCode.OPERATION_ERROR);
}else{
f = knowRepository.addChapterAndCourse(chapter.getPid(),chapter.getId());
if(f <= 0)return ResultUtils.error(ErrorCode.OPERATION_ERROR);
}
}
QueryWrapper<Knowtemp> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("courseid",id);
List<Knowtemp> list = knowtempMapper.selectList(queryWrapper);
for (int j = 0; j < list.size(); j++) {
Knowtemp knowtemp = list.get(j);
f = knowRepository.CreateKnowaddChapter(knowtemp.getChapterid(),knowtemp.getName(),knowtemp.getInfo());
if(f <= 0)return ResultUtils.error(ErrorCode.OPERATION_ERROR);
}
return ResultUtils.success("添加成功");
}
public BaseResponse<String> updateRelationship(Long id,List<Long> ids,String relationship){
//必须先学id1的知识点才能学习id2的知识点
int f = -1;
if("PreCondition".equals(relationship)){
f = knowRepository.addKnowWithPreCondition(id,ids);
if(f<=0)return ResultUtils.error(ErrorCode.ADD_RELATION_FAILED);
} else if ("FatherAndSon".equals(relationship)) {
f = knowRepository.addKnowWithFaherAndSon(id,ids);
if(f<=0)return ResultUtils.error(ErrorCode.ADD_RELATION_FAILED);
}else{
f = knowRepository.addKnowWithRelated(id,ids);
if(f<=0)return ResultUtils.error(ErrorCode.ADD_RELATION_FAILED);
}
return ResultUtils.success("添加成功");
}
public BaseKnowReturn getKnowAll(String id) {
Collection<Map<String, Object>> all =
neo4jClient.query( "match(n:Know)-[r*0..]->(p:Know) where n.courseId = '"+id+"' return n as `n`,r as `r`,p as `p`,length(r) as `d`").fetch().all();
Map<Long,String>colorChoose = new HashMap<>();
String color[] = new String[10];
String[] colorList = {"#91CC75", "#5470C6", "#FAC858", "#EE6666", "#73C0DE", "#EA7CCC", "#5577FF", "#5577FF", "#9DBFFF", "#78A7FF"};
for (int i = 0; i < 10; i++) {
colorChoose.put((long) i,colorList[i]);
}
Iterator<Map<String, Object>> iterator = all.iterator();
Set<KnowVO> knowList = new HashSet<>();
Set<Links>linksList = new HashSet<>();
KnowVO knowVO;
List node2 = new ArrayList<>();
Links links;
int p = 0;
while (iterator.hasNext()) {
Map<String, Object> element = iterator.next();
knowVO = new KnowVO();
Node node1 = (Node) element.get("p");
Long group = (Long) element.get("d");
knowVO.setColor(colorChoose.get(group));
Long id1 = node1.id();
String name1 = node1.get("name").asString();
knowVO.setId(id1);
knowVO.setLabel(name1);
knowList.add(knowVO);
node2 = (List) element.get("r");
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());
links.setLabel(e.type());
linksList.add(links);
}
}
BaseKnowReturn baseKnowReturn = new BaseKnowReturn(knowList,linksList);
return baseKnowReturn;
}
public BaseResponse<Set<KnowVO1>> getKnowByCourseId(String id) {
Collection<Map<String, Object>> all =
neo4jClient.query( "match(n:Know)-[r*0..]->(p:Know) where n.courseId = '"+id+"' return p as `p`").fetch().all();
Iterator<Map<String, Object>> iterator = all.iterator();
Set<KnowVO1> knowList = new HashSet<>();
KnowVO1 knowVO;
while (iterator.hasNext()) {
Map<String, Object> element = iterator.next();
knowVO = new KnowVO1();
Node node1 = (Node) element.get("p");
Long id1 = node1.id();
String name1 = node1.get("name").asString();
knowVO.setId(id1);
knowVO.setLabel(name1);
knowList.add(knowVO);
}
return ResultUtils.success(knowList);
}
// public List<Know> queryKnowAllKnowById(Long id) {
// return knowRepository.queryKnowAllKnowById(id);
// }
//
//
// 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 ResultUtils.success(knowRepository.save(know)) ;
// }
//
// 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 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 BaseResponse<String> deleteCourseKnow( String courseId) {
// boolean f = knowRepository.deleteKnowCourse(courseId);
// if(f)return ResultUtils.success("删除成功");
// return ResultUtils.error(ErrorCode.DELETE_FAILED);
// }
//
// 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 BaseResponse<KnowChapter> updateKnowChapter(Chapter chapter) {
// return ResultUtils.success(knowRepository.createKnowChapter(chapter.getId(), chapter.getName(), chapter.getContent()));
// }
// public BaseResponse<String> deleteKnowChapter(Long chapterId) {
// boolean f = knowRepository.deleteKnowChapter(chapterId);
// if(f)return ResultUtils.success("删除成功");
// return ResultUtils.error(ErrorCode.DELETE_FAILED);
// }
// public Set<Know> queryByChapterId(Long 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);
// }
//
//
// public BaseKnowReturn getKnowAll(String id) {
// Collection<Map<String, Object>> all =
// neo4jClient.query( "match(n:Know)-[r*0..]->(p:Know) where n.courseId = '"+id+"' return n as `n`,r as `r`,p as `p`,length(r) as `d`").fetch().all();
//
// Map<Long,String>colorChoose = new HashMap<>();
// String color[] = new String[10];
// String[] colorList = {"#91CC75", "#5470C6", "#FAC858", "#EE6666", "#73C0DE", "#EA7CCC", "#5577FF", "#5577FF", "#9DBFFF", "#78A7FF"};
// for (int i = 0; i < 10; i++) {
// colorChoose.put((long) i,colorList[i]);
// }
//
// Iterator<Map<String, Object>> iterator = all.iterator();
// Set<KnowVO> knowList = new HashSet<>();
// Set<Links>linksList = new HashSet<>();
// KnowVO knowVO;
// List node2 = new ArrayList<>();
// Links links;
// int p = 0;
// while (iterator.hasNext()) {
// Map<String, Object> element = iterator.next();
// knowVO = new KnowVO();
// Node node1 = (Node) element.get("p");
//
// Long group = (Long) element.get("d");
// knowVO.setColor(colorChoose.get(group));
//
// Long id1 = node1.id();
// String name1 = node1.get("name").asString();
// knowVO.setId(id1);
// knowVO.setLabel(name1);
//
// knowList.add(knowVO);
//
// node2 = (List) element.get("r");
// 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());
// links.setLabel(e.type());
// linksList.add(links);
// }
//
//
// }
// BaseKnowReturn baseKnowReturn = new BaseKnowReturn(knowList,linksList);
// System.out.println(baseKnowReturn);
// return baseKnowReturn;
// }
//
// public BaseKnowReturn getKnowById(Long id) {
// Collection<Map<String, Object>> all =
// neo4jClient.query( "match(n:Know)-[r*0..2]->(p:Know) where ID(n) = "+id+" return n as `n`,r as `r`,p as `p`,length(r) as `d`").fetch().all();
// Map<Long,String>colorChoose = new HashMap<>();
// String color[] = new String[10];
// String[] colorList = {"#91CC75", "#5470C6", "#FAC858", "#EE6666", "#73C0DE", "#EA7CCC", "#5577FF", "#5577FF", "#9DBFFF", "#78A7FF"};
// for (int i = 0; i < 10; i++) {
// colorChoose.put((long) i,colorList[i]);
// }
//
// Iterator<Map<String, Object>> iterator = all.iterator();
// Set<KnowVO> knowList = new HashSet<>();
// Set<Links>linksList = new HashSet<>();
// KnowVO knowVO;
// List node2 = new ArrayList<>();
// Links links;
// int p = 0;
// while (iterator.hasNext()) {
// Map<String, Object> element = iterator.next();
//
// knowVO = new KnowVO();
// Node node1 = (Node) element.get("p");
// Long group = (Long) element.get("d");
// knowVO.setColor(colorChoose.get(group));
// Long id1 = node1.id();
// String name1 = node1.get("name").asString();
// knowVO.setId(id1);
// knowVO.setLabel(name1);
// knowList.add(knowVO);
//
// node2 = (List) element.get("r");
// 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());
// links.setLabel(e.type());
// linksList.add(links);
// }
//
//
// }
// BaseKnowReturn baseKnowReturn = new BaseKnowReturn(knowList,linksList);
// System.out.println(baseKnowReturn);
// return baseKnowReturn;
// }
}

@ -1,107 +0,0 @@
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;
import com.teaching.backend.utils.FileUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.neo4j.core.Neo4jClient;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.commons.CommonsMultipartFile;
import javax.annotation.Resource;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.*;
/**
* @Author:youhang
* @Date:2024-07-21-14:46
* @Description:
*/
@Service
public class ResourcesService {
private static final String GLOBAL_CODE_DIR_NAME = "tempFile";
@Autowired
private ResourcesRepository resourcesRepository;
@Resource
private Neo4jClient neo4jClient;
public List<Resources> queryKnowAllResources(Long id) {
return resourcesRepository.queryResourceAllId(id);
}
public Resources createResource(ResourcesAddRequest resourceAddRequest ) {
String name = resourceAddRequest.getName();
Integer type = resourceAddRequest.getType();
String path = resourceAddRequest.getPath();
Resources resources = new Resources();
BeanUtils.copyProperties(resourceAddRequest,resources);
return resourcesRepository.save(resources);
}
public void deleteResources(Long id) {
resourcesRepository.deleteById(id);
}
public Resources updateResources(ResourceUpdateRequest resourceUpdateRequest ) {
Resources resources = new Resources();
resources = resourcesRepository.findById(resourceUpdateRequest.getId()).orElseThrow(() -> new RuntimeException("知识点 not found"));
BeanUtils.copyProperties(resourceUpdateRequest,resources);
return resourcesRepository.save(resources);
}
public void addKnowWithResources( RelationshipResourceRequest relationshipResourceRequest) {
resourcesRepository.addResourceResourcesKnow(relationshipResourceRequest.getId(),relationshipResourceRequest.getResourceIds());
}
public Set<Resources> queryCourseKnowToResources(Long KnowId){
return resourcesRepository.queryCourseKnowToResources(KnowId);
}
public List<MultipartFile> queryBesidesKnowToResources(Long KnowId){
List<MultipartFile>multipartFileList = new ArrayList<>();
Set<Resources>resourcesSet = resourcesRepository.queryBesidesKnowToResources(KnowId);
resourcesSet = resourcesRepository.queryKnowToResources(KnowId);
Iterator<Resources>iterator = resourcesSet.iterator();
while (iterator.hasNext()){
Resources resources = iterator.next();
MultipartFile multipartFile = FileUtils.fileUrlConvertToMultipartFile(resources.getPath());
multipartFileList.add(multipartFile);
}
return multipartFileList;
}
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) {
return ResultUtils.error(ErrorCode.UPLOAD_FAILED);
}
return ResultUtils.success(userCodeFile.getPath());
}
}

@ -7,13 +7,16 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.teaching.backend.common.ErrorCode;
import com.teaching.backend.exception.BusinessException;
import com.teaching.backend.mapper.Knowtemp.KnowtempMapper;
import com.teaching.backend.mapper.Knowtemp.KnowtmpMapper;
import com.teaching.backend.mapper.chapter.ChapterMapper;
import com.teaching.backend.model.dto.chapter.ChapterDTO;
import com.teaching.backend.model.entity.Knowtemp.Knowtemp;
import com.teaching.backend.model.entity.chapter.Chapter;
import com.teaching.backend.model.entity.knowtmp.Knowtmp;
import com.teaching.backend.model.vo.chapter.ChapterVo;
import com.teaching.backend.service.KnowGraph.KnowService;
import com.teaching.backend.service.Know.KnowService;
import com.teaching.backend.service.chapter.IChapterService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
@ -34,12 +37,11 @@ public class ChapterServiceImpl extends ServiceImpl<ChapterMapper, Chapter> impl
private ChapterMapper chapterMapper;
@Autowired
private KnowtempMapper knowtempMapper;
private KnowtmpMapper knowtmpMapper;
// private int count=0;
List<Chapter> list=new ArrayList<>();
@Autowired
private KnowService knowService;
@Override
public String updateNumShow(Chapter chapter) {
@ -206,10 +208,10 @@ public class ChapterServiceImpl extends ServiceImpl<ChapterMapper, Chapter> impl
.collect(Collectors.toList());
chapter.setChildren(sortedChildren);
QueryWrapper<Knowtemp>queryWrapper = new QueryWrapper<>();
QueryWrapper<Knowtmp>queryWrapper = new QueryWrapper<>();
for (Chapter child : sortedChildren) {
queryWrapper.eq("chapterId",child.getId());
List<Knowtemp> knows = knowtempMapper.selectList(queryWrapper);
List<Knowtmp> knows = knowtmpMapper.selectList(queryWrapper);
child.setKnowledgePoints(new ArrayList<>(knows));
loadKnowledgePointsRecursively(child);
@ -417,9 +419,9 @@ public class ChapterServiceImpl extends ServiceImpl<ChapterMapper, Chapter> impl
if (count>0){
throw new BusinessException(ErrorCode.OPERATION_ERROR,"存在子章节,无法删除");
}
QueryWrapper<Knowtemp>queryWrapper1 = new QueryWrapper<>();
QueryWrapper<Knowtmp>queryWrapper1 = new QueryWrapper<>();
queryWrapper1.eq("chapterId",id);
List<Knowtemp> knows = knowtempMapper.selectList(queryWrapper1);
List<Knowtmp> knows = knowtmpMapper.selectList(queryWrapper1);
if (!knows.isEmpty()) {
throw new BusinessException(ErrorCode.OPERATION_ERROR, "子章节下存在知识点,无法删除");

@ -32,7 +32,6 @@ import com.teaching.backend.model.vo.courses.CoursesVO;
import com.teaching.backend.model.vo.umsAdmin.UmsStudentVO;
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;
@ -91,8 +90,6 @@ public class CoursesServiceImpl extends ServiceImpl<CoursesMapper, Courses> impl
@Autowired
private LearningRecordsMapper learningRecordsMapper;
@Autowired
private AddNeoKnowByCourse addNeoKnowByCourse;
@Autowired
CourseLearningRecordMapper courseLearningRecordMapper;

@ -0,0 +1,252 @@
package com.teaching.backend.service.impl.know;
import com.teaching.backend.common.BaseResponse;
import com.teaching.backend.common.ErrorCode;
import com.teaching.backend.common.ResultUtils;
import com.teaching.backend.mapper.know.KnowRepository;
import com.teaching.backend.model.dto.Know.*;
import com.teaching.backend.model.entity.know.Know;
import com.teaching.backend.model.entity.know.KnowChapter;
import com.teaching.backend.model.entity.know.KnowCourse;
import com.teaching.backend.model.entity.know.Links;
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 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.stereotype.Service;
import javax.annotation.Resource;
import java.util.*;
/**
* @Author:youhang
* @Date:2024-08-07-15:47
* @Description:
*/
@Service
public class knowServiceImpl implements KnowService {
@Autowired
private KnowRepository knowRepository;
@Resource
private Neo4jClient neo4jClient;
@Override
public BaseResponse<String> addKnow(KnowRequest knowRequest) {
Know know = new Know();
BeanUtils.copyProperties(knowRequest,know);
int f = knowRepository.addKnow(know.getName(),know.getInfo());
if(f > 0){
return ResultUtils.success("添加知识点成功");
}else{
return ResultUtils.error(ErrorCode.OPERATION_ERROR,"添加知识点失败");
}
}
@Override
public BaseResponse<String> updateKnow(KnowUpdateRequest knowUpdateRequest) {
Know know = new Know();
BeanUtils.copyProperties(knowUpdateRequest,know);
int f = knowRepository.updateKnow(know.getId(),know.getName(),know.getInfo());
if(f > 0){
return ResultUtils.success("修改知识点成功");
}else{
return ResultUtils.error(ErrorCode.OPERATION_ERROR,"修改知识点失败");
}
}
@Override
public BaseResponse<String> deleteKnow(Long id) {
// todo 判断知识点存在否
int f = knowRepository.deleteKnow(id);
if(f > 0){
return ResultUtils.success("删除知识点成功");
}else{
return ResultUtils.error(ErrorCode.OPERATION_ERROR,"删除知识点失败");
}
}
@Override
public BaseResponse<Know> queryKnow(Long id) {
Know know = knowRepository.queryKnow(id);
return ResultUtils.success(know);
}
//========================
@Override
public BaseResponse<String> addCourse(KnowCourseCreateRequest knowCourseCreateRequest) {
KnowCourse knowCourse = new KnowCourse();
BeanUtils.copyProperties(knowCourseCreateRequest,knowCourse);
int f = knowRepository.addCourse(knowCourse.getCourseId(),knowCourse.getName(),knowCourse.getInfo());
if(f > 0){
return ResultUtils.success("添加知识点成功");
}else{
return ResultUtils.error(ErrorCode.OPERATION_ERROR,"添加知识点失败");
}
}
@Override
public BaseResponse<String> updateCourse(KnowCourseCreateRequest knowCourseCreateRequest) {
KnowCourse knowCourse = new KnowCourse();
BeanUtils.copyProperties(knowCourseCreateRequest,knowCourse);
int f = knowRepository.updateCourse(knowCourse.getCourseId(),knowCourse.getName(),knowCourse.getInfo());
if(f > 0){
return ResultUtils.success("修改知识点成功");
}else{
return ResultUtils.error(ErrorCode.OPERATION_ERROR,"修改知识点失败");
}
}
@Override
public BaseResponse<String> deleteCourse(String courseId) {
int f = knowRepository.deleteCourse(courseId);
if(f > 0){
return ResultUtils.success("删除知识点成功");
}else{
return ResultUtils.error(ErrorCode.OPERATION_ERROR,"删除知识点失败");
}
}
@Override
public BaseResponse<KnowCourse> queryCourse(String courseId) {
KnowCourse Knowcourse = knowRepository.queryCourse(courseId);
return ResultUtils.success(Knowcourse);
}
//=========================
@Override
public BaseResponse<String> addChapter(KnowChapterCreateRequest knowChapterCreateRequest) {
KnowChapter knowChapter = new KnowChapter();
BeanUtils.copyProperties(knowChapterCreateRequest,knowChapter);
int f = knowRepository.addChapter(knowChapter.getChapterId(),knowChapter.getName(),knowChapter.getInfo());
if(f > 0){
return ResultUtils.success("添加知识点成功");
}else{
return ResultUtils.error(ErrorCode.OPERATION_ERROR,"添加知识点失败");
}
}
@Override
public BaseResponse<String> updateChapter(KnowChapterCreateRequest knowChapterCreateRequest) {
KnowChapter knowChapter = new KnowChapter();
BeanUtils.copyProperties(knowChapterCreateRequest,knowChapter);
int f = knowRepository.updateChapter(knowChapter.getChapterId(),knowChapter.getName(),knowChapter.getInfo());
if(f > 0){
return ResultUtils.success("修改知识点成功");
}else{
return ResultUtils.error(ErrorCode.OPERATION_ERROR,"修改知识点失败");
}
}
@Override
public BaseResponse<String> deleteChapter(Long chapterId) {
int f = knowRepository.deleteChapter(chapterId);
if(f > 0){
return ResultUtils.success("删除知识点成功");
}else{
return ResultUtils.error(ErrorCode.OPERATION_ERROR,"删除知识点失败");
}
}
@Override
public BaseResponse<KnowChapter> queryChapter(Long chapterId) {
KnowChapter knowChapter = knowRepository.queryChapter(chapterId);
return ResultUtils.success(knowChapter);
}
//===============
//获取课程下的所有知识点
@Override
public BaseKnowReturn getAllKnowByCourseId(String id) {
Collection<Map<String, Object>> all =
neo4jClient.query( "match(n:Know)-[r*0..]->(p:Know) where n.courseId = '"+id+"' return n as `n`,r as `r`,p as `p`,length(r) as `d`").fetch().all();
Map<Long,String>colorChoose = new HashMap<>();
String color[] = new String[10];
String[] colorList = {"#91CC75", "#5470C6", "#FAC858", "#EE6666", "#73C0DE", "#EA7CCC", "#5577FF", "#5577FF", "#9DBFFF", "#78A7FF"};
for (int i = 0; i < 10; i++) {
colorChoose.put((long) i,colorList[i]);
}
Iterator<Map<String, Object>> iterator = all.iterator();
Set<KnowVO> knowList = new HashSet<>();
Set<Links>linksList = new HashSet<>();
KnowVO knowVO;
List node2 = new ArrayList<>();
Links links;
int p = 0;
while (iterator.hasNext()) {
Map<String, Object> element = iterator.next();
knowVO = new KnowVO();
Node node1 = (Node) element.get("p");
Long group = (Long) element.get("d");
knowVO.setColor(colorChoose.get(group));
Long id1 = node1.id();
String name1 = node1.get("name").asString();
knowVO.setId(id1);
knowVO.setLabel(name1);
knowList.add(knowVO);
node2 = (List) element.get("r");
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());
links.setLabel(e.type());
linksList.add(links);
}
}
BaseKnowReturn baseKnowReturn = new BaseKnowReturn(knowList,linksList);
return baseKnowReturn;
}
//获取课程下的所有资源
@Override
public BaseResponse<Set<KnowVO1>> getAllResourcesByCourseId(String id) {
Collection<Map<String, Object>> all =
neo4jClient.query( "match(n:Know)-[r*0..]->(p:Know) where n.courseId = '"+id+"' return p as `p`").fetch().all();
Iterator<Map<String, Object>> iterator = all.iterator();
Set<KnowVO1> knowList = new HashSet<>();
KnowVO1 knowVO;
while (iterator.hasNext()) {
Map<String, Object> element = iterator.next();
knowVO = new KnowVO1();
Node node1 = (Node) element.get("p");
Long id1 = node1.id();
String name1 = node1.get("name").asString();
knowVO.setId(id1);
knowVO.setLabel(name1);
knowList.add(knowVO);
}
return ResultUtils.success(knowList);
}
//获取知识点下二级的所有资源
@Override
public Set<Resources> getSecondResources(Long id) {
Set<Resources>resourcesSet ;
resourcesSet = knowRepository.queryBesidesKnowToResources(id);
return resourcesSet;
}
}

@ -0,0 +1,73 @@
package com.teaching.backend.service.impl.knowtmp;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.teaching.backend.common.BaseResponse;
import com.teaching.backend.common.ErrorCode;
import com.teaching.backend.common.ResultUtils;
import com.teaching.backend.mapper.Knowtemp.KnowtmpMapper;
import com.teaching.backend.model.dto.Knowtmp.KnowtempAdd;
import com.teaching.backend.model.dto.Knowtmp.KnowtempUpdate;
import com.teaching.backend.model.entity.knowtmp.Knowtmp;
import com.teaching.backend.service.knowtmp.KnowtmpService;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* @Author:youhang
* @Date:2024-08-07-19:40
* @Description:
*/
@Service
public class KnowtmpServiceImpl implements KnowtmpService {
@Autowired
private KnowtmpMapper knowtmpMapper;
@Override
public BaseResponse<String> add(KnowtempAdd knowtempAdd) {
Knowtmp knowtmp = new Knowtmp();
BeanUtils.copyProperties(knowtempAdd,knowtmp);
int f = knowtmpMapper.insert(knowtmp);
if(f > 0){
return ResultUtils.success("添加成功");
}else{
return ResultUtils.error(ErrorCode.OPERATION_ERROR,"添加失败");
}
}
@Override
public BaseResponse<String> update(KnowtempUpdate knowtempUpdate) {
Knowtmp knowtmp = new Knowtmp();
BeanUtils.copyProperties(knowtempUpdate,knowtmp);
int f = knowtmpMapper.updateById(knowtmp);
if(f > 0){
return ResultUtils.success("修改成功");
}else{
return ResultUtils.error(ErrorCode.OPERATION_ERROR,"修改失败");
}
}
@Override
public BaseResponse<String> delete(Long id) {
// todo 查询 id
int f = knowtmpMapper.deleteById(id);
if(f > 0){
return ResultUtils.success("删除成功");
}else{
return ResultUtils.error(ErrorCode.OPERATION_ERROR,"删除失败");
}
}
@Override
public BaseResponse<List<Knowtmp>> queryByChapterId(Long chapterId) {
Knowtmp knowtmp = new Knowtmp();
final QueryWrapper<Knowtmp> knowtmpQueryWrapper = new QueryWrapper<>();
knowtmpQueryWrapper.eq("chapterId",chapterId);
List<Knowtmp> knowtmps = knowtmpMapper.selectList(knowtmpQueryWrapper);
return ResultUtils.success(knowtmps);
}
}

@ -6,8 +6,6 @@ import com.teaching.backend.common.BaseResponse;
import com.teaching.backend.common.ResultUtils;
import com.teaching.backend.mapper.records.ResourceLearningRecordMapper;
import com.teaching.backend.model.entity.records.ResourceLearningRecord;
import com.teaching.backend.model.entity.resource.ResourceLearningNumber;
import com.teaching.backend.service.impl.resource.ResourceLearningNumberServiceImpl;
import com.teaching.backend.service.records.IResourceLearningRecordService;
import org.springframework.stereotype.Service;
@ -25,52 +23,52 @@ import java.time.LocalDateTime;
@Service
public class ResourceLearningRecordServiceImpl extends ServiceImpl<ResourceLearningRecordMapper, ResourceLearningRecord> implements IResourceLearningRecordService {
@Resource
private ResourceLearningNumberServiceImpl resourceLearningNumberService;
// @Resource
// private ResourceLearningNumberServiceImpl resourceLearningNumberService;
@Override
public BaseResponse<String> saveCoursesRecords(ResourceLearningRecord resourceLearningRecord) {
//课程id
String courseId = resourceLearningRecord.getCoursesId();
String knowledgeId = resourceLearningRecord.getKnowledgeId();
String resourceId = resourceLearningRecord.getResourceId();
String userId = resourceLearningRecord.getUserId();
//1.生成学习时间
resourceLearningRecord.setTimes(LocalDateTime.now());
//2.设置人数
//2.1查人数
Long count = resourceLearningNumberService.query()
.eq("course_id", courseId)
.eq("knowledge_id",knowledgeId)
.eq("resource_id",resourceId).count();
//2.2判断自己是否学习过
Long count1 = query().eq("user_id", userId).count();
if (count > 0){
//自己没学过,人数加1
if (count1 == 0){
resourceLearningNumberService.update().setSql("number = number + 1")
.eq("course_id",courseId)
.eq("knowledge_id",knowledgeId)
.eq("resource_id",resourceId).update();
// System.out.println("用户:"+userId+"第一次学这门课");
}
}else {
//该课程第一次被学,人数设置为1
ResourceLearningNumber resourceLearningNumber = new ResourceLearningNumber();
resourceLearningNumber.setNumber(1);
resourceLearningNumber.setCourseId(courseId);
resourceLearningNumber.setKnowledgeId(knowledgeId);
resourceLearningNumber.setResourceId(resourceId);
resourceLearningNumberService.save(resourceLearningNumber);
}
//设置人数
String numberId = resourceLearningNumberService.query()
.eq("course_id", courseId)
.eq("knowledge_id",knowledgeId)
.eq("resource_id",resourceId).one().getId();
resourceLearningRecord.setNumber(numberId);
//保存记录
save(resourceLearningRecord);
return ResultUtils.success("添加成功");
}
// @Override
// public BaseResponse<String> saveCoursesRecords(ResourceLearningRecord resourceLearningRecord) {
// //课程id
// String courseId = resourceLearningRecord.getCoursesId();
// String knowledgeId = resourceLearningRecord.getKnowledgeId();
// String resourceId = resourceLearningRecord.getResourceId();
// String userId = resourceLearningRecord.getUserId();
// //1.生成学习时间
// resourceLearningRecord.setTimes(LocalDateTime.now());
// //2.设置人数
// //2.1查人数
// Long count = resourceLearningNumberService.query()
// .eq("course_id", courseId)
// .eq("knowledge_id",knowledgeId)
// .eq("resource_id",resourceId).count();
// //2.2判断自己是否学习过
// Long count1 = query().eq("user_id", userId).count();
// if (count > 0){
// //自己没学过,人数加1
// if (count1 == 0){
// resourceLearningNumberService.update().setSql("number = number + 1")
// .eq("course_id",courseId)
// .eq("knowledge_id",knowledgeId)
// .eq("resource_id",resourceId).update();
//// System.out.println("用户:"+userId+"第一次学这门课");
// }
// }else {
// //该课程第一次被学,人数设置为1
// ResourceLearningNumber resourceLearningNumber = new ResourceLearningNumber();
// resourceLearningNumber.setNumber(1);
// resourceLearningNumber.setCourseId(courseId);
// resourceLearningNumber.setKnowledgeId(knowledgeId);
// resourceLearningNumber.setResourceId(resourceId);
// resourceLearningNumberService.save(resourceLearningNumber);
// }
// //设置人数
// String numberId = resourceLearningNumberService.query()
// .eq("course_id", courseId)
// .eq("knowledge_id",knowledgeId)
// .eq("resource_id",resourceId).one().getId();
// resourceLearningRecord.setNumber(numberId);
// //保存记录
// save(resourceLearningRecord);
// return ResultUtils.success("添加成功");
// }
}

@ -1,22 +0,0 @@
package com.teaching.backend.service.impl.resource;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.teaching.backend.mapper.resource.ResourceLearningNumberMapper;
import com.teaching.backend.model.entity.resource.ResourceLearningNumber;
import com.teaching.backend.service.resource.IResourceLearningNumberService;
import org.springframework.stereotype.Service;
/**
* <p>
* 服务实现类
* </p>
*
* @author author
* @since 2024-07-29
*/
@Service
public class ResourceLearningNumberServiceImpl extends ServiceImpl<ResourceLearningNumberMapper, ResourceLearningNumber> implements IResourceLearningNumberService {
}

@ -1,45 +1,168 @@
package com.teaching.backend.service.impl.resource;
import cn.hutool.core.io.FileUtil;
import com.teaching.backend.mapper.KnowGraph.ResourcesRepository;
import com.teaching.backend.mapper.resource.ResourcesMapper;
import com.teaching.backend.model.entity.KnowGraph.Resources;
import com.teaching.backend.model.entity.resource.Resource;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.json.JSONUtil;
import com.teaching.backend.common.BaseResponse;
import com.teaching.backend.common.ErrorCode;
import com.teaching.backend.common.ResultUtils;
import com.teaching.backend.constant.ViewContentTypeEnum;
import com.teaching.backend.mapper.resource.ResourcesRepository;
import com.teaching.backend.model.dto.resource.BucketPolicyConfigDto;
import com.teaching.backend.model.dto.resource.ResourceUploadDto;
import com.teaching.backend.model.entity.resource.Resources;
import com.teaching.backend.service.resource.ResourceService;
import org.springframework.beans.BeanUtils;
import com.teaching.backend.utils.MinioUtils;
import io.minio.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.InputStreamResource;
import org.springframework.data.neo4j.core.Neo4jClient;
import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.util.UUID;
import javax.annotation.Resource;
import java.io.InputStream;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
* @Author:youhang
* @Date:2024-07-26-13:58
* @Description:
*/
@Service
public class ResourceServiceImpl implements ResourceService {
private static final String GLOBAL_CODE_DIR_NAME = "tempFile";
@Autowired
private ResourcesRepository resourcesRepository;
private ResourcesMapper resourcesMapper;
private static final Logger LOGGER = LoggerFactory.getLogger(ResourceService.class);
@Autowired
private MinioUtils minioUtils;
@Value("${minio.endpoint}")
private String ENDPOINT;
@Value("${minio.bucketName}")
private String BUCKET_NAME;
@Value("${minio.accessKey}")
private String ACCESS_KEY;
@Value("${minio.secretKey}")
private String SECRET_KEY;
@Resource
private Neo4jClient neo4jClient;
@Override
public BaseResponse<ResourceUploadDto> upload(MultipartFile file) {
ResourceUploadDto resourceUploadDto = minioUtils.upload(file);
if (resourceUploadDto == null) {
return ResultUtils.error(ErrorCode.OPERATION_ERROR, "上传失败");
}
String url = resourceUploadDto.getUrl();
String name = resourceUploadDto.getName();
String objectName = resourceUploadDto.getObjectName();
//添加到图数据库中
Resources resource = new Resources();
resource.setName(objectName);
resource.setStatus(0);
resource.setUrl(url);
resourcesRepository.save(resource);
return ResultUtils.success(resourceUploadDto);
}
@Override
public BaseResponse<String> delete(String objectName) {
try {
minioUtils.delete(objectName);
}catch (Exception e){
e.printStackTrace();
LOGGER.info("删除失败,故障");
}
//删除图数据库
boolean f = resourcesRepository.deleteByobjectName(objectName);
if (f) {
return ResultUtils.success("删除成功");
} else {
return ResultUtils.error(ErrorCode.OPERATION_ERROR, "图数据库删除失败");
}
}
public ResponseEntity<InputStreamResource> readFile(String filename) {
return minioUtils.readFile(filename);
}
@Override
public String upload(MultipartFile file) {
String userDir = System.getProperty("user.dir");
String globalFilePathName = userDir + File.separator + GLOBAL_CODE_DIR_NAME;
if (!FileUtil.exist(globalFilePathName)) {
FileUtil.mkdir(globalFilePathName);
public BaseResponse<String> addResourcesAndKnowByCourseId(String courseId, List<Long> resourcesIds){
// todo 查询课程是否存在 ,资源是否存在
int count = resourcesRepository.addResourcesAndKnowByCourseId(courseId,resourcesIds);
if(count == resourcesIds.size()){
return ResultUtils.success("添加关系成功");
}else{
return ResultUtils.error(ErrorCode.OPERATION_ERROR,"添加失败");
}
// 把用户的代码隔离存放
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("失败");
}
@Override
public BaseResponse<String> addResourcesAndKnowByChapterId(Long chapterId, List<Long> resourcesIds){
// todo 查询章节是否存在 ,资源是否存在
int count = resourcesRepository.addResourcesAndKnowByChapterId(chapterId,resourcesIds);
if(count == resourcesIds.size()){
return ResultUtils.success("添加关系成功");
}else{
return ResultUtils.error(ErrorCode.OPERATION_ERROR,"添加失败");
}
return userCodeFile.getPath();
}
@Override
public BaseResponse<String> addResourcesAndKnowById(Long id, List<Long> resourcesIds){
// todo 查询知识点是否存在 ,资源是否存在
int count = resourcesRepository.addResourcesAndKnowById(id,resourcesIds);
if(count == resourcesIds.size()){
return ResultUtils.success("添加关系成功");
}else{
return ResultUtils.error(ErrorCode.OPERATION_ERROR,"添加失败");
}
}
@Override
//查询课程下资源
public Set<Resources> queryResourcesByCourseId(String courseId){
// todo 判空,查询
Set<Resources>resourcesSet;
resourcesSet = resourcesRepository.queryResourcesByCourseId(courseId);
return resourcesSet;
}
@Override
//查询章节下资源
public Set<Resources> queryResourcesByChapterId(Long chapterId){
// todo 判空,查询
Set<Resources>resourcesSet ;
resourcesSet = resourcesRepository.queryResourcesByChapterId(chapterId);
return resourcesSet;
}
@Override
//查询二级节点下资源
public Set<Resources> queryBesidesKnowToResources(Long KnowId){
// todo 判空,查询
Set<Resources>resourcesSet ;
resourcesSet = resourcesRepository.queryBesidesKnowToResources(KnowId);
return resourcesSet;
}
}

@ -0,0 +1,28 @@
package com.teaching.backend.service.knowtmp;
import com.teaching.backend.common.BaseResponse;
import com.teaching.backend.model.dto.Knowtmp.KnowtempAdd;
import com.teaching.backend.model.dto.Knowtmp.KnowtempUpdate;
import com.teaching.backend.model.entity.knowtmp.Knowtmp;
import java.util.List;
/**
* @Author:youhang
* @Date:2024-08-07-15:09
* @Description:
*/
public interface KnowtmpService {
// 添加知识点
BaseResponse<String> add(KnowtempAdd knowtempAdd);
//修改知识点
BaseResponse<String> update(KnowtempUpdate knowtempUpdate);
//删除知识点
BaseResponse<String> delete(Long id);
//查询通过chapterId List
BaseResponse<List<Knowtmp>> queryByChapterId(Long chapterId);
}

@ -15,5 +15,5 @@ import com.teaching.backend.model.entity.records.ResourceLearningRecord;
*/
public interface IResourceLearningRecordService extends IService<ResourceLearningRecord> {
BaseResponse<String> saveCoursesRecords(ResourceLearningRecord resourceLearningRecord);
// BaseResponse<String> saveCoursesRecords(ResourceLearningRecord resourceLearningRecord);
}

@ -1,17 +0,0 @@
package com.teaching.backend.service.resource;
import com.baomidou.mybatisplus.extension.service.IService;
import com.teaching.backend.model.entity.resource.ResourceLearningNumber;
/**
* <p>
* 服务类
* </p>
*
* @author author
* @since 2024-07-29
*/
public interface IResourceLearningNumberService extends IService<ResourceLearningNumber> {
}

@ -1,17 +1,44 @@
package com.teaching.backend.service.resource;
import org.springframework.stereotype.Service;
import com.teaching.backend.common.BaseResponse;
import com.teaching.backend.model.dto.resource.ResourceUploadDto;
import com.teaching.backend.model.entity.resource.Resources;
import org.springframework.core.io.InputStreamResource;
import org.springframework.data.neo4j.repository.query.Query;
import org.springframework.http.ResponseEntity;
import org.springframework.web.multipart.MultipartFile;
import java.util.List;
import java.util.Set;
/**
* @Author:youhang
* @Date:2024-07-26-13:55
* @Description:
*/
@Service
public interface ResourceService {
public String upload(MultipartFile file);
BaseResponse<ResourceUploadDto> upload(MultipartFile file) ;
BaseResponse<String> delete(String filename) ;
ResponseEntity<InputStreamResource> readFile(String filename);
BaseResponse<String> addResourcesAndKnowByCourseId(String courseId, List<Long> resourcesIds);
BaseResponse<String> addResourcesAndKnowByChapterId(Long chapterId, List<Long> resourcesIds);
BaseResponse<String> addResourcesAndKnowById(Long id, List<Long> resourcesIds);
//查询课程下资源
Set<Resources> queryResourcesByCourseId(String courseId);
//查询章节下资源
Set<Resources> queryResourcesByChapterId(Long chapterId);
//查询二级节点下资源
Set<Resources> queryBesidesKnowToResources(Long KnowId);
}

@ -0,0 +1,154 @@
package com.teaching.backend.utils;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.json.JSONUtil;
import com.teaching.backend.common.BaseResponse;
import com.teaching.backend.common.ErrorCode;
import com.teaching.backend.common.ResultUtils;
import com.teaching.backend.constant.ViewContentTypeEnum;
import com.teaching.backend.model.dto.resource.BucketPolicyConfigDto;
import com.teaching.backend.model.dto.resource.ResourceUploadDto;
import com.teaching.backend.model.entity.resource.Resources;
import com.teaching.backend.service.resource.ResourceService;
import io.minio.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.InputStreamResource;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.io.InputStream;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* @Author:youhang
* @Date:2024-08-07-11:38
* @Description:
*/
@Component
public class MinioUtils {
private static final Logger LOGGER = LoggerFactory.getLogger(MinioUtils.class);
@Value("${filename.maxlength}")
private int MAX_FILENAMELENGTH;
@Value("${minio.endpoint}")
private String ENDPOINT;
@Value("${minio.bucketName}")
private String BUCKET_NAME;
@Value("${minio.accessKey}")
private String ACCESS_KEY;
@Value("${minio.secretKey}")
private String SECRET_KEY;
public ResourceUploadDto upload(MultipartFile file) {
ResourceUploadDto minioUploadDto = new ResourceUploadDto();
try {
//创建一个MinIO的Java客户端
MinioClient minioClient =MinioClient.builder()
.endpoint(ENDPOINT)
.credentials(ACCESS_KEY,SECRET_KEY)
.build();
boolean isExist = minioClient.bucketExists(BucketExistsArgs.builder().bucket(BUCKET_NAME).build());
if (isExist) {
LOGGER.info("存储桶已经存在!");
} else {
//创建存储桶并设置只读权限
minioClient.makeBucket(MakeBucketArgs.builder().bucket(BUCKET_NAME).build());
BucketPolicyConfigDto bucketPolicyConfigDto = createBucketPolicyConfigDto(BUCKET_NAME);
SetBucketPolicyArgs setBucketPolicyArgs = SetBucketPolicyArgs.builder()
.bucket(BUCKET_NAME)
.config(JSONUtil.toJsonStr(bucketPolicyConfigDto))
.build();
minioClient.setBucketPolicy(setBucketPolicyArgs);
}
String filename = file.getOriginalFilename();
SimpleDateFormat sdf = new SimpleDateFormat("yyyymmddhhmmss");
// todo 字符串截取
int dotIndex = filename.lastIndexOf('.');
String prefix = filename.substring(0,dotIndex);
String suffix = filename.substring(dotIndex+1,filename.length());
if(prefix.length() > MAX_FILENAMELENGTH){
prefix = prefix.substring(0,MAX_FILENAMELENGTH);
}
filename = prefix+"-"+sdf.format(new Date())+"."+suffix;
sdf = new SimpleDateFormat("yyyyMMdd");
// 设置存储对象名称
String objectName = sdf.format(new Date()) + "/" + suffix + "/" + filename;
// 使用putObject上传一个文件到存储桶中
PutObjectArgs putObjectArgs = PutObjectArgs.builder()
.bucket(BUCKET_NAME)
.object(objectName)
.contentType(ViewContentTypeEnum.getContentType(objectName))
.stream(file.getInputStream(), file.getSize(), ObjectWriteArgs.MIN_MULTIPART_SIZE).build();
minioClient.putObject(putObjectArgs);
LOGGER.info("文件上传成功!");
minioUploadDto.setName(filename);
minioUploadDto.setUrl(ENDPOINT + "/" + BUCKET_NAME + "/" + objectName);
minioUploadDto.setObjectName(objectName);
} catch (Exception e) {
e.printStackTrace();
LOGGER.info("上传发生错误: {}!", e.getMessage());
}
return minioUploadDto;
}
/**
* 创建存储桶的访问策略设置为只读权限
*/
private BucketPolicyConfigDto createBucketPolicyConfigDto(String bucketName) {
BucketPolicyConfigDto.Statement statement = BucketPolicyConfigDto.Statement.builder()
.Effect("Allow")
.Principal("*")
.Action("s3:GetObject")
.Resource("arn:aws:s3:::"+bucketName+"/*.**").build();
return BucketPolicyConfigDto.builder()
.Version("2012-10-17")
.Statement(CollUtil.toList(statement))
.build();
}
public void delete(String objectName) throws Exception {
MinioClient minioClient = MinioClient.builder()
.endpoint(ENDPOINT)
.credentials(ACCESS_KEY,SECRET_KEY)
.build();
minioClient.removeObject(RemoveObjectArgs.builder().bucket(BUCKET_NAME).object(objectName).build());
}
public ResponseEntity<InputStreamResource> readFile(String filename) {
try {
// 创建MinIO客户端
MinioClient minioClient = MinioClient.builder()
.endpoint(ENDPOINT)
.credentials(ACCESS_KEY, SECRET_KEY)
.build();
// 获取文件流
GetObjectResponse objectResponse = minioClient.getObject(GetObjectArgs.builder()
.bucket(BUCKET_NAME) // 替换为你实际的存储桶名称
.object(filename)
.build());
InputStream inputStream = objectResponse;
return ResponseEntity.ok()
.body(new InputStreamResource(inputStream));
} catch (Exception e) {
e.printStackTrace();
return ResponseEntity.notFound().build();
}
}
}

@ -1,35 +0,0 @@
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;
import org.springframework.web.bind.annotation.RequestParam;
/**
* @Author:youhang
* @Date:2024-07-26-17:57
* @Description:
*/
@Component
public class AddNeoKnowByCourse {
@Autowired
private KnowService knowService;
// public BaseResponse<KnowCourse> addCourse(String courseId , String name, String description){
// return knowService.createCourseKnow( courseId , name, description);
// }
// public BaseResponse<KnowChapter> addChapter(Chapter chapter){
// return knowService.createKnowChapter(chapter);
// }
}

@ -80,3 +80,12 @@ aliyun:
accessKeyId: LTAI5tFkdu3y5WddxbjgaG2F
accessKeySecret: 1xUchxUTlmUBoTV5JQIrKsVjSkmsLF
bucketName: ceshi132132
minio:
endpoint: http://39.106.16.162:9090 #MinIO服务所在地址
bucketName: teaching # 存储桶名称
accessKey: minioadmin # 访问的key
secretKey: minioadmin # 访问的秘钥
filename:
maxlength: 10

Loading…
Cancel
Save