diff --git a/pom.xml b/pom.xml index bfd5080..19e0375 100644 --- a/pom.xml +++ b/pom.xml @@ -45,6 +45,12 @@ poi-ooxml + + + io.minio + minio + 8.2.1 + commons-fileupload diff --git a/src/main/java/com/teaching/backend/config/CorsConfig.java b/src/main/java/com/teaching/backend/config/CorsConfig.java index 9703e85..ba5230f 100644 --- a/src/main/java/com/teaching/backend/config/CorsConfig.java +++ b/src/main/java/com/teaching/backend/config/CorsConfig.java @@ -11,6 +11,7 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; @Configuration public class CorsConfig implements WebMvcConfigurer { + @Override public void addCorsMappings(CorsRegistry registry) { // 覆盖所有请求 diff --git a/src/main/java/com/teaching/backend/config/SecurityConfig.java b/src/main/java/com/teaching/backend/config/SecurityConfig.java index 6e5b527..41c5947 100644 --- a/src/main/java/com/teaching/backend/config/SecurityConfig.java +++ b/src/main/java/com/teaching/backend/config/SecurityConfig.java @@ -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.ExpressionInterceptUrlRegistry registry = httpSecurity diff --git a/src/main/java/com/teaching/backend/constant/ViewContentTypeEnum.java b/src/main/java/com/teaching/backend/constant/ViewContentTypeEnum.java new file mode 100644 index 0000000..cb5b6b2 --- /dev/null +++ b/src/main/java/com/teaching/backend/constant/ViewContentTypeEnum.java @@ -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 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; + } +} diff --git a/src/main/java/com/teaching/backend/controller/Know/KnowController.java b/src/main/java/com/teaching/backend/controller/Know/KnowController.java new file mode 100644 index 0000000..ee8b95d --- /dev/null +++ b/src/main/java/com/teaching/backend/controller/Know/KnowController.java @@ -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 addKnow(@RequestBody KnowRequest knowRequest){ + return knowService.addKnow(knowRequest); + } + + // 修改知识点 + @PostMapping("/updateKnow") + BaseResponse updateKnow(@RequestBody KnowUpdateRequest knowUpdateRequest){ + return knowService.updateKnow(knowUpdateRequest); + } + + // 删除知识点 + @GetMapping("/deleteKnow") + BaseResponse deleteKnow(@RequestParam Long id){ + return knowService.deleteKnow(id); + } + + //查询知识点通过id + @GetMapping("/queryKnow") + BaseResponse queryKnow(@RequestParam Long id){ + return knowService.queryKnow(id); + } + + //====================================== + + // 添加课程 + @PostMapping("/addCourse") + BaseResponse addCourse(@RequestBody KnowCourseCreateRequest knowCourseCreateRequest){ + return knowService.addCourse(knowCourseCreateRequest); + } + + // 修改课程 + @PostMapping("/updateCourse") + BaseResponse updateCourse(@RequestBody KnowCourseCreateRequest knowCourseCreateRequest){ + return knowService.updateCourse(knowCourseCreateRequest); + } + + + // 删除课程 + @PostMapping("/deleteCourse") + BaseResponse deleteCourse(@RequestParam String courseId){ + return knowService.deleteCourse(courseId); + } + + //查询课程通过courseid + @GetMapping ("/queryCourse") + BaseResponse queryCourse(@RequestParam String courseId){ + return knowService.queryCourse(courseId); + } + + + //========================= + + // 添加章节 + @PostMapping("/addChapter") + BaseResponse addChapter(@RequestBody KnowChapterCreateRequest knowChapterCreateRequest){ + return knowService.addChapter(knowChapterCreateRequest); + } + + // 修改章节 + @PostMapping("/updateChapter") + BaseResponse updateChapter(@RequestBody KnowChapterCreateRequest knowChapterCreateRequest){ + return knowService.updateChapter(knowChapterCreateRequest); + } + + // 删除章节 + @GetMapping("/deleteChapter") + BaseResponse deleteChapter(@RequestParam Long chapterId){ + return knowService.deleteChapter(chapterId); + } + + //查询章节通过chapterId + @PostMapping("/queryChapter") + BaseResponse queryChapter(@RequestParam Long chapterId){ + return knowService.queryChapter(chapterId); + } + + //===================== + + //获取课程下的所有知识点 + @GetMapping("/getAllKnowByCourseId") + BaseKnowReturn getAllKnowByCourseId(@RequestParam String id){ + return knowService.getAllKnowByCourseId(id); + } + + //获取课程下的所有资源 + @GetMapping("/getAllResourcesByCourseId") + BaseResponse> getAllResourcesByCourseId(@RequestParam String id){ + return knowService.getAllResourcesByCourseId(id); + } + + //获取知识点下二级的所有资源 + @GetMapping("/getSecondResources") + Set getSecondResources(@RequestParam Long id){ + return knowService.getSecondResources(id); + } + +} diff --git a/src/main/java/com/teaching/backend/controller/KnowGraph/KnowController.java b/src/main/java/com/teaching/backend/controller/KnowGraph/KnowController.java deleted file mode 100644 index 261bf7b..0000000 --- a/src/main/java/com/teaching/backend/controller/KnowGraph/KnowController.java +++ /dev/null @@ -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 add(@RequestBody KnowtempAdd knowtempAdd) { - return knowService.add(knowtempAdd); - } - - @PostMapping("/update") - public BaseResponse update(@RequestBody KnowtempUpdate knowtempUpdate) { - return knowService.update(knowtempUpdate); - } - @PostMapping("/delete") - public BaseResponse delete(@RequestParam Long id) { - return knowService.delete(id); - } - @PostMapping("/query") - public BaseResponse query(@RequestParam Long id) { - return knowService.query(id); - } - - //根据 课程id 从chapter表中获取List 章节 - @PostMapping("/addAll") - public BaseResponse addAll(@RequestParam String id) { - return knowService.saveKnowToNeo(id); - } - - // 改变节点关系 - @PostMapping("/update/relationship") - public BaseResponse updateRelationship(@RequestParam Long id, @RequestParam List ids, @RequestParam String relationship) { - return knowService.updateRelationship(id,ids,relationship); - } - - //获取该节点下所有的节点 - @GetMapping("/all") - public BaseResponse getKnowAll(@RequestParam String id) { - BaseKnowReturn baseKnowReturn =knowService.getKnowAll(id); - return ResultUtils.success(baseKnowReturn); - } - @GetMapping("/getAllByCourseId") - public BaseResponse> getKnowByCourseId(String id) { - return knowService.getKnowByCourseId(id); - } -// //根据 id查询所关联的所有结点 -// @PostMapping ("/query/{id}") -// public List queryKnowAllKnowById(@PathVariable Long id) { -// return knowService.queryKnowAllKnowById(id); -// } -// -// //添加知识点 -// @PostMapping("/add") -// public BaseResponse createKnow(@RequestBody KnowRequest knowRequest) { -// return knowService.createKnow(knowRequest); -// } -// //修改知识点 -// @PostMapping ("/update") -// public BaseResponse updateKnow(@RequestBody KnowUpdateRequest knowUpdateRequest) { -// return knowService.updateKnow(knowUpdateRequest); -// } -// //删除知识点 -// @GetMapping ("delete/{id}") -// public BaseResponse deleteKnow(@PathVariable Long id) { -// return knowService.deleteKnow(id); -// } -// -// //添加知识点 - 课程 -// @PostMapping("/add/KnowCourse") -// public BaseResponse createCourseKnow(@RequestBody Courses courses) { -// return knowService.createCourseKnow(courses); -// } -// -// //修改知识点 - 课程 -// @PostMapping("/update/KnowCourse") -// public BaseResponse updateCourseKnow(@RequestBody Courses courses) { -// return knowService.createCourseKnow(courses); -// } -// -// //删除知识点 - 课程 -// @PostMapping("/delete/KnowCourse") -// public BaseResponse deleteCourseKnow(@RequestParam String courseId) { -// return knowService.deleteCourseKnow(courseId); -// } -// -// //添加知识点 - 章节 -// @PostMapping("/addKnowChapter") -// public BaseResponse createKnowChapter(@RequestBody Chapter chapter) { -// return knowService.createKnowChapter(chapter); -// } -// -// //修改知识点 - 章节 -// @PostMapping("/update/KnowChapter") -// public BaseResponse updateKnowChapter(@RequestBody Chapter chapter) { -// return knowService.updateKnowChapter(chapter); -// } -// //删除知识点 - 章节 -// @PostMapping("/delete/KnowChapter") -// public BaseResponse deleteKnowChapter(@RequestParam Long chapterId) { -// return knowService.deleteKnowChapter(chapterId); -// } -// -// @GetMapping("/KnowBychapterId") -// public Set queryByChapterId(@RequestParam Long chapterId) { -// return knowService.queryByChapterId(chapterId); -// } -// -// -// -// //添加知识点与知识点的关系 related -// @PostMapping ("/addKnowRelatedKnow") -// public BaseResponse addKnowRelatedKnow(@RequestBody RelationshipKnowRequest relationshipKnowRequest) { -// return knowService.addKnowRelatedKnow(relationshipKnowRequest); -// } -// -// //添加知识点与知识点的关系 fatherandSon -// @PostMapping ("/addKnowFatherAndSonKnow") -// public BaseResponse addKnowFatherAndSonKnow(@RequestBody RelationshipKnowRequest relationshipKnowRequest) { -// return knowService.addKnowFatherAndSonKnow(relationshipKnowRequest); -// } -// -// //获取该节点下所有的节点 -// @GetMapping("/all") -// public BaseResponse getKnowAll(@RequestParam String id) { -// BaseKnowReturn baseKnowReturn =knowService.getKnowAll(id); -// return ResultUtils.success(baseKnowReturn); -// } -// -// //返回该节点以及二级节点 -// @GetMapping("/KnowById") -// public BaseResponse getKnowById(@RequestParam Long id) { -// BaseKnowReturn baseKnowReturn =knowService.getKnowById(id); -// return ResultUtils.success(baseKnowReturn); -// } - - -} diff --git a/src/main/java/com/teaching/backend/controller/KnowGraph/KnowGraphController.java b/src/main/java/com/teaching/backend/controller/KnowGraph/KnowGraphController.java deleted file mode 100644 index dcbc2d8..0000000 --- a/src/main/java/com/teaching/backend/controller/KnowGraph/KnowGraphController.java +++ /dev/null @@ -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 add(@RequestBody KnowtempAdd knowtempAdd) { -// return knowGraphService.add(knowtempAdd); -// } -// -// @PostMapping("/update") -// public BaseResponse update(@RequestBody KnowtempUpdate knowtempUpdate) { -// return knowGraphService.update(knowtempUpdate); -// } -// @PostMapping("/delete") -// public BaseResponse delete(@RequestParam Integer id) { -// return knowGraphService.delete(id); -// } -// @PostMapping("/query") -// public BaseResponse query(@RequestParam Integer id) { -// return knowGraphService.query(id); -// } -// -// -// //根据 课程id 从chapter表中获取List 章节 -// @PostMapping("/addAll") -// public BaseResponse addAll(@PathVariable String id) { -// return knowGraphService.saveKnowToNeo(id); -// } -// -// -// -//} diff --git a/src/main/java/com/teaching/backend/controller/KnowGraph/ResourcesController.java b/src/main/java/com/teaching/backend/controller/KnowGraph/ResourcesController.java deleted file mode 100644 index f8411eb..0000000 --- a/src/main/java/com/teaching/backend/controller/KnowGraph/ResourcesController.java +++ /dev/null @@ -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 uploadFile(@RequestParam("file")MultipartFile file) { - return resourcesService.uploadFile(file); - } - - - //根据 id查询所关联的resources结点 - @PostMapping ("/query/{id}") - public List queryKnowAllKnowById(@PathVariable Long id) { - return resourcesService.queryKnowAllResources(id); - } - - //添加资源 - @PostMapping("/add") - public Resources createResources(@RequestBody ResourcesAddRequest resourceAddRequest) { - return resourcesService.createResource(resourceAddRequest); - } - - //添加知识点 - 课程 - @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 queryCourseKnowToResources(@PathVariable Long KnowId) { - return resourcesService.queryCourseKnowToResources(KnowId); - } - - @GetMapping ("queryBesidesKnowToResources/{KnowId}") - public List queryBesidesKnowToResources(@PathVariable Long KnowId) { - return resourcesService.queryBesidesKnowToResources(KnowId); - } - - - -} diff --git a/src/main/java/com/teaching/backend/controller/Knowtmp/KnowtmpController.java b/src/main/java/com/teaching/backend/controller/Knowtmp/KnowtmpController.java new file mode 100644 index 0000000..8b28b1b --- /dev/null +++ b/src/main/java/com/teaching/backend/controller/Knowtmp/KnowtmpController.java @@ -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 add(@RequestBody KnowtempAdd knowtempAdd){ + return knowtmpService.add(knowtempAdd); + } + + + //修改知识点 + @PostMapping("/updateKnow") + BaseResponse update(@RequestBody KnowtempUpdate knowtempUpdate){ + return knowtmpService.update(knowtempUpdate); + } + + + //删除知识点 + @GetMapping("/deleteKnow") + BaseResponse delete(Long id){ + return knowtmpService.delete(id); + } + + //查询通过chapterId List + @GetMapping("/queryKnow") + BaseResponse> queryByChapterId(Long chapterId){ + return knowtmpService.queryByChapterId(chapterId); + } +} diff --git a/src/main/java/com/teaching/backend/controller/records/ResourceLearningRecordController.java b/src/main/java/com/teaching/backend/controller/records/ResourceLearningRecordController.java index efbb8f2..77adf9d 100644 --- a/src/main/java/com/teaching/backend/controller/records/ResourceLearningRecordController.java +++ b/src/main/java/com/teaching/backend/controller/records/ResourceLearningRecordController.java @@ -20,10 +20,10 @@ public class ResourceLearningRecordController { @Resource private ResourceLearningRecordServiceImpl resourceLearningRecordService; - @ApiOperation("添加资源学习记录") -// @ValidateParams({"userId","type","coursesId"}) - @PostMapping("/saverecords") - public BaseResponse saveResourceRecords(@RequestBody ResourceLearningRecord resourceLearningRecord) { - return resourceLearningRecordService.saveCoursesRecords(resourceLearningRecord); - } +// @ApiOperation("添加资源学习记录") +//// @ValidateParams({"userId","type","coursesId"}) +// @PostMapping("/saverecords") +// public BaseResponse saveResourceRecords(@RequestBody ResourceLearningRecord resourceLearningRecord) { +// return resourceLearningRecordService.saveCoursesRecords(resourceLearningRecord); +// } } diff --git a/src/main/java/com/teaching/backend/controller/resource/ResourceController.java b/src/main/java/com/teaching/backend/controller/resource/ResourceController.java index 16102ee..71b0884 100644 --- a/src/main/java/com/teaching/backend/controller/resource/ResourceController.java +++ b/src/main/java/com/teaching/backend/controller/resource/ResourceController.java @@ -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 uploadFile(@RequestParam("file")MultipartFile file) { - return resourcesService.uploadFile(file); + @ResponseBody + public BaseResponse uploadFile(@RequestPart("file") MultipartFile file) { + return resourceService.upload(file); } + //删除资源 + @GetMapping ("delete") + @ResponseBody + public BaseResponse deleteResource(@RequestParam("filename") String filename) { + return resourceService.delete(filename); + } + @GetMapping("/read") + public ResponseEntity readFile(@RequestParam String filename) { + return resourceService.readFile(filename); + } + @GetMapping("/addRelationship/BetweenCourseAndResources") + public BaseResponse addResourcesAndKnowByCourseId(@RequestParam String courseId, @RequestParam List resourcesIds){ + return resourceService.addResourcesAndKnowByCourseId(courseId,resourcesIds); + } + @GetMapping("/addRelationship/BetweenChapterAndResources") + public BaseResponse addResourcesAndKnowByChapterId(@RequestParam Long chapterId,@RequestParam List resourcesIds){ + return resourceService.addResourcesAndKnowByChapterId(chapterId,resourcesIds); + } + @GetMapping("/addRelationship/BetweenKnowAndResources") + public BaseResponse addResourcesAndKnowById(@RequestParam Long id, @RequestParam List resourcesIds){ + return resourceService.addResourcesAndKnowById(id,resourcesIds); + } -} - - - - - - - + //查询课程下资源 + @GetMapping("/queryByCourseId") + Set queryResourcesByCourseId(String courseId){ + return resourceService.queryResourcesByCourseId(courseId); + } + //查询章节下资源 + @GetMapping("/queryByChapterId") + Set queryResourcesByChapterId(Long chapterId){ + return resourceService.queryResourcesByChapterId(chapterId); + } + //查询二级节点下资源 + @GetMapping("/queryBesidesKnow") + Set queryBesidesKnowToResources(Long KnowId){ + return resourceService.queryBesidesKnowToResources(KnowId); + } +} diff --git a/src/main/java/com/teaching/backend/mapper/KnowGraph/KnowRepository.java b/src/main/java/com/teaching/backend/mapper/KnowGraph/KnowRepository.java deleted file mode 100644 index cbfbcf6..0000000 --- a/src/main/java/com/teaching/backend/mapper/KnowGraph/KnowRepository.java +++ /dev/null @@ -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 { - - - @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 KnowIds); - - @Query("MATCH(n)-[r:related]->(nn:Know) where ID(nn) = $id RETURN n") - List 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 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 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 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 KnowIds); - - -} diff --git a/src/main/java/com/teaching/backend/mapper/KnowGraph/ResourcesRepository.java b/src/main/java/com/teaching/backend/mapper/KnowGraph/ResourcesRepository.java deleted file mode 100644 index b4609af..0000000 --- a/src/main/java/com/teaching/backend/mapper/KnowGraph/ResourcesRepository.java +++ /dev/null @@ -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 { - - - @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 ResourcesIds); - - - @Query("MATCH(n:Know)-[r:resources]->(nn:Resources) where ID(nn) = $id RETURN nn") - List 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 queryCourseKnowToResources(Long KnowId); - - @Query("MATCH (p:Know)-[:FatherAndSon]->(n:Know)-[:resources]->(m:Resources) WHERE ID(p) = $KnowId RETURN m") - Set queryBesidesKnowToResources(Long KnowId); - - @Query(" MATCH (p:Know)-[:resources]->(m:Resources) WHERE ID(p) = 272 RETURN m") - Set queryKnowToResources(Long KnowId); - -} diff --git a/src/main/java/com/teaching/backend/mapper/Knowtemp/KnowtempMapper.java b/src/main/java/com/teaching/backend/mapper/Knowtemp/KnowtempMapper.java deleted file mode 100644 index 38c1cab..0000000 --- a/src/main/java/com/teaching/backend/mapper/Knowtemp/KnowtempMapper.java +++ /dev/null @@ -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 { - -} - - - - diff --git a/src/main/java/com/teaching/backend/mapper/Knowtemp/KnowtmpMapper.java b/src/main/java/com/teaching/backend/mapper/Knowtemp/KnowtmpMapper.java new file mode 100644 index 0000000..5aee0cb --- /dev/null +++ b/src/main/java/com/teaching/backend/mapper/Knowtemp/KnowtmpMapper.java @@ -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 { + +} + + + + diff --git a/src/main/java/com/teaching/backend/mapper/know/KnowRepository.java b/src/main/java/com/teaching/backend/mapper/know/KnowRepository.java new file mode 100644 index 0000000..9871a0d --- /dev/null +++ b/src/main/java/com/teaching/backend/mapper/know/KnowRepository.java @@ -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 { + + @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 queryBesidesKnowToResources(Long id); + +} diff --git a/src/main/java/com/teaching/backend/mapper/resource/ResourceLearningNumberMapper.java b/src/main/java/com/teaching/backend/mapper/resource/ResourceLearningNumberMapper.java deleted file mode 100644 index 8542b97..0000000 --- a/src/main/java/com/teaching/backend/mapper/resource/ResourceLearningNumberMapper.java +++ /dev/null @@ -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; - -/** - *

- * Mapper 接口 - *

- * - * @author author - * @since 2024-07-29 - */ -public interface ResourceLearningNumberMapper extends BaseMapper { - -} diff --git a/src/main/java/com/teaching/backend/mapper/resource/ResourcesMapper.java b/src/main/java/com/teaching/backend/mapper/resource/ResourcesMapper.java deleted file mode 100644 index de072b2..0000000 --- a/src/main/java/com/teaching/backend/mapper/resource/ResourcesMapper.java +++ /dev/null @@ -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 { - -} diff --git a/src/main/java/com/teaching/backend/mapper/resource/ResourcesRepository.java b/src/main/java/com/teaching/backend/mapper/resource/ResourcesRepository.java new file mode 100644 index 0000000..16286ed --- /dev/null +++ b/src/main/java/com/teaching/backend/mapper/resource/ResourcesRepository.java @@ -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 { + + //删除资源节点 + @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 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 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 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 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 queryResourcesByChapterId(Long chapterId); + + //查询二级节点下资源 + @Query("MATCH (p:Know)-[:FatherAndSon]->(n:Know)-[:resources]->(m:Resources) WHERE ID(p) = $KnowId RETURN m") + Set queryBesidesKnowToResources(Long KnowId); + + + + +// +// +// @Query("MATCH(n:Know)-[r:resources]->(nn:Resources) where ID(nn) = $id RETURN nn") +// List 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 queryCourseKnowToResources(Long KnowId); +// + +// +// @Query(" MATCH (p:Know)-[:resources]->(m:Resources) WHERE ID(p) = 272 RETURN m") +// Set queryKnowToResources(Long KnowId); + +} diff --git a/src/main/java/com/teaching/backend/model/dto/KnowGraph/BaseKnowReturn.java b/src/main/java/com/teaching/backend/model/dto/Know/BaseKnowReturn.java similarity index 80% rename from src/main/java/com/teaching/backend/model/dto/KnowGraph/BaseKnowReturn.java rename to src/main/java/com/teaching/backend/model/dto/Know/BaseKnowReturn.java index 8dc8bef..03e31df 100644 --- a/src/main/java/com/teaching/backend/model/dto/KnowGraph/BaseKnowReturn.java +++ b/src/main/java/com/teaching/backend/model/dto/Know/BaseKnowReturn.java @@ -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; diff --git a/src/main/java/com/teaching/backend/model/dto/KnowGraph/KnowChapterCreateRequest.java b/src/main/java/com/teaching/backend/model/dto/Know/KnowChapterCreateRequest.java similarity index 70% rename from src/main/java/com/teaching/backend/model/dto/KnowGraph/KnowChapterCreateRequest.java rename to src/main/java/com/teaching/backend/model/dto/Know/KnowChapterCreateRequest.java index 85f542b..293b44c 100644 --- a/src/main/java/com/teaching/backend/model/dto/KnowGraph/KnowChapterCreateRequest.java +++ b/src/main/java/com/teaching/backend/model/dto/Know/KnowChapterCreateRequest.java @@ -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 { diff --git a/src/main/java/com/teaching/backend/model/dto/KnowGraph/KnowCourseCreateRequest.java b/src/main/java/com/teaching/backend/model/dto/Know/KnowCourseCreateRequest.java similarity index 70% rename from src/main/java/com/teaching/backend/model/dto/KnowGraph/KnowCourseCreateRequest.java rename to src/main/java/com/teaching/backend/model/dto/Know/KnowCourseCreateRequest.java index 9e15c8e..61815f2 100644 --- a/src/main/java/com/teaching/backend/model/dto/KnowGraph/KnowCourseCreateRequest.java +++ b/src/main/java/com/teaching/backend/model/dto/Know/KnowCourseCreateRequest.java @@ -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 { diff --git a/src/main/java/com/teaching/backend/model/dto/KnowGraph/KnowRequest.java b/src/main/java/com/teaching/backend/model/dto/Know/KnowRequest.java similarity index 63% rename from src/main/java/com/teaching/backend/model/dto/KnowGraph/KnowRequest.java rename to src/main/java/com/teaching/backend/model/dto/Know/KnowRequest.java index 13061f1..14f8492 100644 --- a/src/main/java/com/teaching/backend/model/dto/KnowGraph/KnowRequest.java +++ b/src/main/java/com/teaching/backend/model/dto/Know/KnowRequest.java @@ -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 { diff --git a/src/main/java/com/teaching/backend/model/dto/KnowGraph/KnowUpdateRequest.java b/src/main/java/com/teaching/backend/model/dto/Know/KnowUpdateRequest.java similarity index 68% rename from src/main/java/com/teaching/backend/model/dto/KnowGraph/KnowUpdateRequest.java rename to src/main/java/com/teaching/backend/model/dto/Know/KnowUpdateRequest.java index e3955d2..feb2520 100644 --- a/src/main/java/com/teaching/backend/model/dto/KnowGraph/KnowUpdateRequest.java +++ b/src/main/java/com/teaching/backend/model/dto/Know/KnowUpdateRequest.java @@ -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 { diff --git a/src/main/java/com/teaching/backend/model/dto/KnowGraph/RelationshipKnowRequest.java b/src/main/java/com/teaching/backend/model/dto/Know/RelationshipKnowRequest.java similarity index 84% rename from src/main/java/com/teaching/backend/model/dto/KnowGraph/RelationshipKnowRequest.java rename to src/main/java/com/teaching/backend/model/dto/Know/RelationshipKnowRequest.java index ff3b1ae..d4d0bda 100644 --- a/src/main/java/com/teaching/backend/model/dto/KnowGraph/RelationshipKnowRequest.java +++ b/src/main/java/com/teaching/backend/model/dto/Know/RelationshipKnowRequest.java @@ -1,4 +1,4 @@ -package com.teaching.backend.model.dto.KnowGraph; +package com.teaching.backend.model.dto.Know; import lombok.Data; diff --git a/src/main/java/com/teaching/backend/model/dto/KnowGraph/RelationshipResourceRequest.java b/src/main/java/com/teaching/backend/model/dto/Know/RelationshipResourceRequest.java similarity index 84% rename from src/main/java/com/teaching/backend/model/dto/KnowGraph/RelationshipResourceRequest.java rename to src/main/java/com/teaching/backend/model/dto/Know/RelationshipResourceRequest.java index 3d46088..d7b7708 100644 --- a/src/main/java/com/teaching/backend/model/dto/KnowGraph/RelationshipResourceRequest.java +++ b/src/main/java/com/teaching/backend/model/dto/Know/RelationshipResourceRequest.java @@ -1,4 +1,4 @@ -package com.teaching.backend.model.dto.KnowGraph; +package com.teaching.backend.model.dto.Know; import lombok.Data; diff --git a/src/main/java/com/teaching/backend/model/dto/KnowGraph/ResourceUpdateRequest.java b/src/main/java/com/teaching/backend/model/dto/KnowGraph/ResourceUpdateRequest.java deleted file mode 100644 index 4775269..0000000 --- a/src/main/java/com/teaching/backend/model/dto/KnowGraph/ResourceUpdateRequest.java +++ /dev/null @@ -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; -} diff --git a/src/main/java/com/teaching/backend/model/dto/KnowGraph/ResourcesAddRequest.java b/src/main/java/com/teaching/backend/model/dto/KnowGraph/ResourcesAddRequest.java deleted file mode 100644 index 32b408d..0000000 --- a/src/main/java/com/teaching/backend/model/dto/KnowGraph/ResourcesAddRequest.java +++ /dev/null @@ -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; -} diff --git a/src/main/java/com/teaching/backend/model/dto/KnowGraph/ResourcesRequest.java b/src/main/java/com/teaching/backend/model/dto/KnowGraph/ResourcesRequest.java deleted file mode 100644 index 37e4bdf..0000000 --- a/src/main/java/com/teaching/backend/model/dto/KnowGraph/ResourcesRequest.java +++ /dev/null @@ -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; -} diff --git a/src/main/java/com/teaching/backend/model/dto/Knowtemp/KnowtempAdd.java b/src/main/java/com/teaching/backend/model/dto/Knowtmp/KnowtempAdd.java similarity index 55% rename from src/main/java/com/teaching/backend/model/dto/Knowtemp/KnowtempAdd.java rename to src/main/java/com/teaching/backend/model/dto/Knowtmp/KnowtempAdd.java index 953db74..3c09119 100644 --- a/src/main/java/com/teaching/backend/model/dto/Knowtemp/KnowtempAdd.java +++ b/src/main/java/com/teaching/backend/model/dto/Knowtmp/KnowtempAdd.java @@ -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; diff --git a/src/main/java/com/teaching/backend/model/dto/Knowtemp/KnowtempUpdate.java b/src/main/java/com/teaching/backend/model/dto/Knowtmp/KnowtempUpdate.java similarity index 73% rename from src/main/java/com/teaching/backend/model/dto/Knowtemp/KnowtempUpdate.java rename to src/main/java/com/teaching/backend/model/dto/Knowtmp/KnowtempUpdate.java index 427aa4b..2002e75 100644 --- a/src/main/java/com/teaching/backend/model/dto/Knowtemp/KnowtempUpdate.java +++ b/src/main/java/com/teaching/backend/model/dto/Knowtmp/KnowtempUpdate.java @@ -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; diff --git a/src/main/java/com/teaching/backend/model/dto/resource/BucketPolicyConfigDto.java b/src/main/java/com/teaching/backend/model/dto/resource/BucketPolicyConfigDto.java new file mode 100644 index 0000000..3242d3a --- /dev/null +++ b/src/main/java/com/teaching/backend/model/dto/resource/BucketPolicyConfigDto.java @@ -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; + + @Data + @EqualsAndHashCode + @Builder + public static class Statement { + private String Effect; + private String Principal; + private String Action; + private String Resource; + + } +} diff --git a/src/main/java/com/teaching/backend/model/dto/resource/ResourceUploadDto.java b/src/main/java/com/teaching/backend/model/dto/resource/ResourceUploadDto.java new file mode 100644 index 0000000..0fd2f4d --- /dev/null +++ b/src/main/java/com/teaching/backend/model/dto/resource/ResourceUploadDto.java @@ -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; +} diff --git a/src/main/java/com/teaching/backend/model/entity/chapter/Chapter.java b/src/main/java/com/teaching/backend/model/entity/chapter/Chapter.java index 4cadcb9..c7d6e80 100644 --- a/src/main/java/com/teaching/backend/model/entity/chapter/Chapter.java +++ b/src/main/java/com/teaching/backend/model/entity/chapter/Chapter.java @@ -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 knowledgePoints; // 用于存储章节下的知识点 + private List knowledgePoints; // 用于存储章节下的知识点 } diff --git a/src/main/java/com/teaching/backend/model/entity/KnowGraph/Know.java b/src/main/java/com/teaching/backend/model/entity/know/Know.java similarity index 88% rename from src/main/java/com/teaching/backend/model/entity/KnowGraph/Know.java rename to src/main/java/com/teaching/backend/model/entity/know/Know.java index 10eff7f..b570705 100644 --- a/src/main/java/com/teaching/backend/model/entity/KnowGraph/Know.java +++ b/src/main/java/com/teaching/backend/model/entity/know/Know.java @@ -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; - /** * 知识点名称 */ diff --git a/src/main/java/com/teaching/backend/model/entity/KnowGraph/KnowChapter.java b/src/main/java/com/teaching/backend/model/entity/know/KnowChapter.java similarity index 85% rename from src/main/java/com/teaching/backend/model/entity/KnowGraph/KnowChapter.java rename to src/main/java/com/teaching/backend/model/entity/know/KnowChapter.java index 3454ed0..07e330a 100644 --- a/src/main/java/com/teaching/backend/model/entity/KnowGraph/KnowChapter.java +++ b/src/main/java/com/teaching/backend/model/entity/know/KnowChapter.java @@ -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; /** diff --git a/src/main/java/com/teaching/backend/model/entity/KnowGraph/KnowCourse.java b/src/main/java/com/teaching/backend/model/entity/know/KnowCourse.java similarity index 89% rename from src/main/java/com/teaching/backend/model/entity/KnowGraph/KnowCourse.java rename to src/main/java/com/teaching/backend/model/entity/know/KnowCourse.java index 5860524..f85d1d2 100644 --- a/src/main/java/com/teaching/backend/model/entity/KnowGraph/KnowCourse.java +++ b/src/main/java/com/teaching/backend/model/entity/know/KnowCourse.java @@ -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 diff --git a/src/main/java/com/teaching/backend/model/entity/KnowGraph/Links.java b/src/main/java/com/teaching/backend/model/entity/know/Links.java similarity index 91% rename from src/main/java/com/teaching/backend/model/entity/KnowGraph/Links.java rename to src/main/java/com/teaching/backend/model/entity/know/Links.java index 139c1dd..b8d47ec 100644 --- a/src/main/java/com/teaching/backend/model/entity/KnowGraph/Links.java +++ b/src/main/java/com/teaching/backend/model/entity/know/Links.java @@ -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; diff --git a/src/main/java/com/teaching/backend/model/entity/Knowtemp/Knowtemp.java b/src/main/java/com/teaching/backend/model/entity/knowtmp/Knowtmp.java similarity index 65% rename from src/main/java/com/teaching/backend/model/entity/Knowtemp/Knowtemp.java rename to src/main/java/com/teaching/backend/model/entity/knowtmp/Knowtmp.java index 4538b48..1668352 100644 --- a/src/main/java/com/teaching/backend/model/entity/Knowtemp/Knowtemp.java +++ b/src/main/java/com/teaching/backend/model/entity/knowtmp/Knowtmp.java @@ -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; - } diff --git a/src/main/java/com/teaching/backend/model/entity/resource/Resource.java b/src/main/java/com/teaching/backend/model/entity/resource/Resource.java deleted file mode 100644 index 0b0a9da..0000000 --- a/src/main/java/com/teaching/backend/model/entity/resource/Resource.java +++ /dev/null @@ -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; -} diff --git a/src/main/java/com/teaching/backend/model/entity/resource/ResourceLearningNumber.java b/src/main/java/com/teaching/backend/model/entity/resource/ResourceLearningNumber.java deleted file mode 100644 index 4ae2ee2..0000000 --- a/src/main/java/com/teaching/backend/model/entity/resource/ResourceLearningNumber.java +++ /dev/null @@ -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; - -/** - *

- * - *

- * - * @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; - - -} diff --git a/src/main/java/com/teaching/backend/model/entity/KnowGraph/Resources.java b/src/main/java/com/teaching/backend/model/entity/resource/Resources.java similarity index 82% rename from src/main/java/com/teaching/backend/model/entity/KnowGraph/Resources.java rename to src/main/java/com/teaching/backend/model/entity/resource/Resources.java index bacbe59..c2cc9bb 100644 --- a/src/main/java/com/teaching/backend/model/entity/KnowGraph/Resources.java +++ b/src/main/java/com/teaching/backend/model/entity/resource/Resources.java @@ -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; } diff --git a/src/main/java/com/teaching/backend/service/Know/KnowService.java b/src/main/java/com/teaching/backend/service/Know/KnowService.java new file mode 100644 index 0000000..14cdb91 --- /dev/null +++ b/src/main/java/com/teaching/backend/service/Know/KnowService.java @@ -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 addKnow(KnowRequest knowRequest); + + // 修改知识点 + BaseResponse updateKnow(KnowUpdateRequest knowUpdateRequest); + + // 删除知识点 + BaseResponse deleteKnow(Long id); + + //查询知识点通过id + BaseResponse queryKnow(Long id); + + //====================================== + + // 添加课程 + BaseResponse addCourse(KnowCourseCreateRequest knowCourseCreateRequest); + + // 修改课程 + BaseResponse updateCourse(KnowCourseCreateRequest knowCourseCreateRequest); + + + // 删除课程 + BaseResponse deleteCourse(String courseId); + + //查询课程通过courseid + BaseResponse queryCourse(String courseId); + + + //========================= + + // 添加章节 + BaseResponse addChapter(KnowChapterCreateRequest knowChapterCreateRequest); + + // 修改章节 + BaseResponse updateChapter(KnowChapterCreateRequest knowChapterCreateRequest); + + // 删除章节 + BaseResponse deleteChapter(Long chapterId); + + //查询章节通过chapterId + BaseResponse queryChapter(Long chapterId); + + //===================== + + //获取课程下的所有知识点 + BaseKnowReturn getAllKnowByCourseId(String id); + + //获取课程下的所有资源 + BaseResponse> getAllResourcesByCourseId(String id); + + //获取知识点下二级的所有资源 + Set getSecondResources(Long id); + + +} diff --git a/src/main/java/com/teaching/backend/service/KnowGraph/KnowGraphService.java b/src/main/java/com/teaching/backend/service/KnowGraph/KnowGraphService.java deleted file mode 100644 index 8797762..0000000 --- a/src/main/java/com/teaching/backend/service/KnowGraph/KnowGraphService.java +++ /dev/null @@ -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 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 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 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 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 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 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 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("添加成功"); -//// } -// -// -//} diff --git a/src/main/java/com/teaching/backend/service/KnowGraph/KnowService.java b/src/main/java/com/teaching/backend/service/KnowGraph/KnowService.java deleted file mode 100644 index b74a779..0000000 --- a/src/main/java/com/teaching/backend/service/KnowGraph/KnowService.java +++ /dev/null @@ -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 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 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 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 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 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 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 queryWrapper = new QueryWrapper<>(); - queryWrapper.eq("courseid",id); - List 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 updateRelationship(Long id,List 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> 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(); - - MapcolorChoose = 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> iterator = all.iterator(); - Set knowList = new HashSet<>(); - SetlinksList = new HashSet<>(); - KnowVO knowVO; - List node2 = new ArrayList<>(); - Links links; - int p = 0; - while (iterator.hasNext()) { - Map element = iterator.next(); - knowVO = new KnowVO(); - Node node1 = (Node) element.get("p"); - - Long group = (Long) element.get("d"); - knowVO.setColor(colorChoose.get(group)); - - 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> getKnowByCourseId(String id) { - Collection> all = - neo4jClient.query( "match(n:Know)-[r*0..]->(p:Know) where n.courseId = '"+id+"' return p as `p`").fetch().all(); - Iterator> iterator = all.iterator(); - Set knowList = new HashSet<>(); - KnowVO1 knowVO; - while (iterator.hasNext()) { - Map 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 queryKnowAllKnowById(Long id) { -// return knowRepository.queryKnowAllKnowById(id); -// } -// -// -// public BaseResponse createKnow(KnowRequest knowRequest ) { -// String name = knowRequest.getName(); -// String info = knowRequest.getInfo(); -// if("".equals(name) || name.length()<=0){ -// return ResultUtils.error(ErrorCode.PARAMS_EMPTY); -// } -// Know know = new Know(); -// BeanUtils.copyProperties(knowRequest,know); -// return ResultUtils.success(knowRepository.save(know)) ; -// } -// -// public BaseResponse updateKnow(KnowUpdateRequest knowUpdateRequest ) { -// Know know = new Know(); -// try { -// know = knowRepository.findById(knowUpdateRequest.getId()).orElseThrow(() -> new RuntimeException("知识点 not found")); -// }catch (RuntimeException e){ -// return ResultUtils.error(ErrorCode.NOT_FOUND_ERROR); -// } -// String name = knowUpdateRequest.getName(); -// String info = knowUpdateRequest.getInfo(); -// if("".equals(name) || name.length()<=0){ -// return ResultUtils.error(ErrorCode.PARAMS_EMPTY); -// } -// BeanUtils.copyProperties(knowUpdateRequest,know); -// return ResultUtils.success(knowRepository.save(know)); -// } -// public BaseResponse deleteKnow(Long id) { -// Boolean f = knowRepository.deleteKnow(id); -// if(f)return ResultUtils.success("删除成功"); -// return ResultUtils.error(ErrorCode.DELETE_FAILED); -// } -// -// -// -// public BaseResponse createCourseKnow( Courses courses) { -// String courseId = courses.getId(); -// String name = courses.getName(); -// String description = courses.getDescription(); -// return ResultUtils.success(knowRepository.createKnowCourse(courseId,name,description)); -// } -// -// public BaseResponse 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 createKnowChapter(Chapter chapter) { -// return ResultUtils.success(knowRepository.createKnowChapter(chapter.getId(), chapter.getName(), chapter.getContent())); -// -// } -// public BaseResponse updateKnowChapter(Chapter chapter) { -// return ResultUtils.success(knowRepository.createKnowChapter(chapter.getId(), chapter.getName(), chapter.getContent())); -// } -// public BaseResponse deleteKnowChapter(Long chapterId) { -// boolean f = knowRepository.deleteKnowChapter(chapterId); -// if(f)return ResultUtils.success("删除成功"); -// return ResultUtils.error(ErrorCode.DELETE_FAILED); -// } -// public Set queryByChapterId(Long chapterId){ -// Set knows = knowRepository.queryByChapterId(chapterId); -// return knows; -// } -// -// -// -// public BaseResponse addKnowRelatedKnow(RelationshipKnowRequest relationshipKnowRequest) { -// int num = knowRepository.addKnowRelatedKnow(relationshipKnowRequest.getId(),relationshipKnowRequest.getKnowIds()); -// if(num == relationshipKnowRequest.getKnowIds().size())return ResultUtils.success("添加关系成功,共添加了"+num+" 条关系"); -// return ResultUtils.error(ErrorCode.DELETE_RELATIONSHIP_FAILED); -// } -// public BaseResponse addKnowFatherAndSonKnow( RelationshipKnowRequest relationshipKnowRequest) { -// int num = knowRepository.addKnowFatherAndSonKnow(relationshipKnowRequest.getId(),relationshipKnowRequest.getKnowIds()); -// if(num == relationshipKnowRequest.getKnowIds().size())return ResultUtils.success("添加关系成功,共添加了"+num+" 条关系"); -// return ResultUtils.error(ErrorCode.DELETE_RELATIONSHIP_FAILED); -// } -// -// -// public BaseKnowReturn getKnowAll(String id) { -// Collection> 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(); -// -// MapcolorChoose = 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> iterator = all.iterator(); -// Set knowList = new HashSet<>(); -// SetlinksList = new HashSet<>(); -// KnowVO knowVO; -// List node2 = new ArrayList<>(); -// Links links; -// int p = 0; -// while (iterator.hasNext()) { -// Map element = iterator.next(); -// knowVO = new KnowVO(); -// Node node1 = (Node) element.get("p"); -// -// Long group = (Long) element.get("d"); -// knowVO.setColor(colorChoose.get(group)); -// -// 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> 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(); -// MapcolorChoose = 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> iterator = all.iterator(); -// Set knowList = new HashSet<>(); -// SetlinksList = new HashSet<>(); -// KnowVO knowVO; -// List node2 = new ArrayList<>(); -// Links links; -// int p = 0; -// while (iterator.hasNext()) { -// Map element = iterator.next(); -// -// knowVO = new KnowVO(); -// Node node1 = (Node) element.get("p"); -// Long group = (Long) element.get("d"); -// knowVO.setColor(colorChoose.get(group)); -// 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; -// } - - -} diff --git a/src/main/java/com/teaching/backend/service/KnowGraph/ResourcesService.java b/src/main/java/com/teaching/backend/service/KnowGraph/ResourcesService.java deleted file mode 100644 index ffe73b4..0000000 --- a/src/main/java/com/teaching/backend/service/KnowGraph/ResourcesService.java +++ /dev/null @@ -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 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 queryCourseKnowToResources(Long KnowId){ - return resourcesRepository.queryCourseKnowToResources(KnowId); - } - - public List queryBesidesKnowToResources(Long KnowId){ - ListmultipartFileList = new ArrayList<>(); - SetresourcesSet = resourcesRepository.queryBesidesKnowToResources(KnowId); - resourcesSet = resourcesRepository.queryKnowToResources(KnowId); - Iteratoriterator = resourcesSet.iterator(); - while (iterator.hasNext()){ - Resources resources = iterator.next(); - MultipartFile multipartFile = FileUtils.fileUrlConvertToMultipartFile(resources.getPath()); - multipartFileList.add(multipartFile); - } - return multipartFileList; - } - - public BaseResponse uploadFile(MultipartFile file) { - String userDir = System.getProperty("user.dir"); - String globalFilePathName = userDir + File.separator + GLOBAL_CODE_DIR_NAME; - if (!FileUtil.exist(globalFilePathName)) { - FileUtil.mkdir(globalFilePathName); - } - // 把用户的文件隔离存放 - File userCodeFile = null; - try { - String userCodeParentPath = globalFilePathName + File.separator + UUID.randomUUID(); - String userCodePath = userCodeParentPath + File.separator + file.getOriginalFilename(); - userCodeFile = FileUtil.writeFromStream(file.getInputStream(), userCodePath); - } catch (Exception e) { - return ResultUtils.error(ErrorCode.UPLOAD_FAILED); - } - return ResultUtils.success(userCodeFile.getPath()); - } -} diff --git a/src/main/java/com/teaching/backend/service/impl/chapter/ChapterServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/chapter/ChapterServiceImpl.java index eea5e3d..3e869b7 100644 --- a/src/main/java/com/teaching/backend/service/impl/chapter/ChapterServiceImpl.java +++ b/src/main/java/com/teaching/backend/service/impl/chapter/ChapterServiceImpl.java @@ -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 impl private ChapterMapper chapterMapper; @Autowired - private KnowtempMapper knowtempMapper; + private KnowtmpMapper knowtmpMapper; // private int count=0; List list=new ArrayList<>(); - @Autowired - private KnowService knowService; + @Override public String updateNumShow(Chapter chapter) { @@ -206,10 +208,10 @@ public class ChapterServiceImpl extends ServiceImpl impl .collect(Collectors.toList()); chapter.setChildren(sortedChildren); - QueryWrapperqueryWrapper = new QueryWrapper<>(); + QueryWrapperqueryWrapper = new QueryWrapper<>(); for (Chapter child : sortedChildren) { queryWrapper.eq("chapterId",child.getId()); - List knows = knowtempMapper.selectList(queryWrapper); + List knows = knowtmpMapper.selectList(queryWrapper); child.setKnowledgePoints(new ArrayList<>(knows)); loadKnowledgePointsRecursively(child); @@ -417,9 +419,9 @@ public class ChapterServiceImpl extends ServiceImpl impl if (count>0){ throw new BusinessException(ErrorCode.OPERATION_ERROR,"存在子章节,无法删除"); } - QueryWrapperqueryWrapper1 = new QueryWrapper<>(); + QueryWrapperqueryWrapper1 = new QueryWrapper<>(); queryWrapper1.eq("chapterId",id); - List knows = knowtempMapper.selectList(queryWrapper1); + List knows = knowtmpMapper.selectList(queryWrapper1); if (!knows.isEmpty()) { throw new BusinessException(ErrorCode.OPERATION_ERROR, "子章节下存在知识点,无法删除"); diff --git a/src/main/java/com/teaching/backend/service/impl/courses/CoursesServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/courses/CoursesServiceImpl.java index eac87ef..48f83c4 100644 --- a/src/main/java/com/teaching/backend/service/impl/courses/CoursesServiceImpl.java +++ b/src/main/java/com/teaching/backend/service/impl/courses/CoursesServiceImpl.java @@ -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 impl @Autowired private LearningRecordsMapper learningRecordsMapper; @Autowired - private AddNeoKnowByCourse addNeoKnowByCourse; - @Autowired CourseLearningRecordMapper courseLearningRecordMapper; diff --git a/src/main/java/com/teaching/backend/service/impl/know/knowServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/know/knowServiceImpl.java new file mode 100644 index 0000000..ae58db6 --- /dev/null +++ b/src/main/java/com/teaching/backend/service/impl/know/knowServiceImpl.java @@ -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 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 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 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 queryKnow(Long id) { + Know know = knowRepository.queryKnow(id); + return ResultUtils.success(know); + } + + //======================== + + @Override + public BaseResponse 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 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 deleteCourse(String courseId) { + + int f = knowRepository.deleteCourse(courseId); + if(f > 0){ + return ResultUtils.success("删除知识点成功"); + }else{ + return ResultUtils.error(ErrorCode.OPERATION_ERROR,"删除知识点失败"); + } + } + + @Override + public BaseResponse queryCourse(String courseId) { + KnowCourse Knowcourse = knowRepository.queryCourse(courseId); + return ResultUtils.success(Knowcourse); + } + + //========================= + + + + @Override + public BaseResponse 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 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 deleteChapter(Long chapterId) { + int f = knowRepository.deleteChapter(chapterId); + if(f > 0){ + return ResultUtils.success("删除知识点成功"); + }else{ + return ResultUtils.error(ErrorCode.OPERATION_ERROR,"删除知识点失败"); + } + } + + @Override + public BaseResponse queryChapter(Long chapterId) { + KnowChapter knowChapter = knowRepository.queryChapter(chapterId); + return ResultUtils.success(knowChapter); + } + + //=============== + + //获取课程下的所有知识点 + @Override + public BaseKnowReturn getAllKnowByCourseId(String id) { + Collection> 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(); + + MapcolorChoose = 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> iterator = all.iterator(); + Set knowList = new HashSet<>(); + SetlinksList = new HashSet<>(); + KnowVO knowVO; + List node2 = new ArrayList<>(); + Links links; + int p = 0; + while (iterator.hasNext()) { + Map element = iterator.next(); + knowVO = new KnowVO(); + Node node1 = (Node) element.get("p"); + + Long group = (Long) element.get("d"); + knowVO.setColor(colorChoose.get(group)); + + 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> getAllResourcesByCourseId(String id) { + Collection> all = + neo4jClient.query( "match(n:Know)-[r*0..]->(p:Know) where n.courseId = '"+id+"' return p as `p`").fetch().all(); + Iterator> iterator = all.iterator(); + Set knowList = new HashSet<>(); + KnowVO1 knowVO; + while (iterator.hasNext()) { + Map 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 getSecondResources(Long id) { + SetresourcesSet ; + resourcesSet = knowRepository.queryBesidesKnowToResources(id); + return resourcesSet; + } + +} diff --git a/src/main/java/com/teaching/backend/service/impl/knowtmp/KnowtmpServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/knowtmp/KnowtmpServiceImpl.java new file mode 100644 index 0000000..a1b9ddd --- /dev/null +++ b/src/main/java/com/teaching/backend/service/impl/knowtmp/KnowtmpServiceImpl.java @@ -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 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 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 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> queryByChapterId(Long chapterId) { + Knowtmp knowtmp = new Knowtmp(); + final QueryWrapper knowtmpQueryWrapper = new QueryWrapper<>(); + knowtmpQueryWrapper.eq("chapterId",chapterId); + List knowtmps = knowtmpMapper.selectList(knowtmpQueryWrapper); + return ResultUtils.success(knowtmps); + } +} diff --git a/src/main/java/com/teaching/backend/service/impl/records/ResourceLearningRecordServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/records/ResourceLearningRecordServiceImpl.java index 1220371..c69e71d 100644 --- a/src/main/java/com/teaching/backend/service/impl/records/ResourceLearningRecordServiceImpl.java +++ b/src/main/java/com/teaching/backend/service/impl/records/ResourceLearningRecordServiceImpl.java @@ -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 implements IResourceLearningRecordService { - @Resource - private ResourceLearningNumberServiceImpl resourceLearningNumberService; +// @Resource +// private ResourceLearningNumberServiceImpl resourceLearningNumberService; - @Override - public BaseResponse 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 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("添加成功"); +// } } diff --git a/src/main/java/com/teaching/backend/service/impl/resource/ResourceLearningNumberServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/resource/ResourceLearningNumberServiceImpl.java deleted file mode 100644 index 72f2136..0000000 --- a/src/main/java/com/teaching/backend/service/impl/resource/ResourceLearningNumberServiceImpl.java +++ /dev/null @@ -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; - -/** - *

- * 服务实现类 - *

- * - * @author author - * @since 2024-07-29 - */ -@Service -public class ResourceLearningNumberServiceImpl extends ServiceImpl implements IResourceLearningNumberService { - -} diff --git a/src/main/java/com/teaching/backend/service/impl/resource/ResourceServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/resource/ResourceServiceImpl.java index f97adf8..b8ba096 100644 --- a/src/main/java/com/teaching/backend/service/impl/resource/ResourceServiceImpl.java +++ b/src/main/java/com/teaching/backend/service/impl/resource/ResourceServiceImpl.java @@ -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 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 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 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 addResourcesAndKnowByCourseId(String courseId, List 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 addResourcesAndKnowByChapterId(Long chapterId, List 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 addResourcesAndKnowById(Long id, List 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 queryResourcesByCourseId(String courseId){ + // todo 判空,查询 + SetresourcesSet; + resourcesSet = resourcesRepository.queryResourcesByCourseId(courseId); + return resourcesSet; + } + @Override + //查询章节下资源 + public Set queryResourcesByChapterId(Long chapterId){ + // todo 判空,查询 + SetresourcesSet ; + resourcesSet = resourcesRepository.queryResourcesByChapterId(chapterId); + return resourcesSet; + } + + @Override + //查询二级节点下资源 + public Set queryBesidesKnowToResources(Long KnowId){ + // todo 判空,查询 + SetresourcesSet ; + resourcesSet = resourcesRepository.queryBesidesKnowToResources(KnowId); + return resourcesSet; + } + + + } diff --git a/src/main/java/com/teaching/backend/service/knowtmp/KnowtmpService.java b/src/main/java/com/teaching/backend/service/knowtmp/KnowtmpService.java new file mode 100644 index 0000000..aad7b68 --- /dev/null +++ b/src/main/java/com/teaching/backend/service/knowtmp/KnowtmpService.java @@ -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 add(KnowtempAdd knowtempAdd); + + //修改知识点 + BaseResponse update(KnowtempUpdate knowtempUpdate); + + //删除知识点 + BaseResponse delete(Long id); + + //查询通过chapterId List + BaseResponse> queryByChapterId(Long chapterId); + +} diff --git a/src/main/java/com/teaching/backend/service/records/IResourceLearningRecordService.java b/src/main/java/com/teaching/backend/service/records/IResourceLearningRecordService.java index 2b53014..9ea73bc 100644 --- a/src/main/java/com/teaching/backend/service/records/IResourceLearningRecordService.java +++ b/src/main/java/com/teaching/backend/service/records/IResourceLearningRecordService.java @@ -15,5 +15,5 @@ import com.teaching.backend.model.entity.records.ResourceLearningRecord; */ public interface IResourceLearningRecordService extends IService { - BaseResponse saveCoursesRecords(ResourceLearningRecord resourceLearningRecord); +// BaseResponse saveCoursesRecords(ResourceLearningRecord resourceLearningRecord); } diff --git a/src/main/java/com/teaching/backend/service/resource/IResourceLearningNumberService.java b/src/main/java/com/teaching/backend/service/resource/IResourceLearningNumberService.java deleted file mode 100644 index f35e1f4..0000000 --- a/src/main/java/com/teaching/backend/service/resource/IResourceLearningNumberService.java +++ /dev/null @@ -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; - -/** - *

- * 服务类 - *

- * - * @author author - * @since 2024-07-29 - */ -public interface IResourceLearningNumberService extends IService { - -} diff --git a/src/main/java/com/teaching/backend/service/resource/ResourceService.java b/src/main/java/com/teaching/backend/service/resource/ResourceService.java index 1a0036e..a916e24 100644 --- a/src/main/java/com/teaching/backend/service/resource/ResourceService.java +++ b/src/main/java/com/teaching/backend/service/resource/ResourceService.java @@ -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 upload(MultipartFile file) ; + + BaseResponse delete(String filename) ; + + ResponseEntity readFile(String filename); + BaseResponse addResourcesAndKnowByCourseId(String courseId, List resourcesIds); + + BaseResponse addResourcesAndKnowByChapterId(Long chapterId, List resourcesIds); + + BaseResponse addResourcesAndKnowById(Long id, List resourcesIds); + + //查询课程下资源 + Set queryResourcesByCourseId(String courseId); + + //查询章节下资源 + Set queryResourcesByChapterId(Long chapterId); + + //查询二级节点下资源 + Set queryBesidesKnowToResources(Long KnowId); } diff --git a/src/main/java/com/teaching/backend/utils/MinioUtils.java b/src/main/java/com/teaching/backend/utils/MinioUtils.java new file mode 100644 index 0000000..e422d2a --- /dev/null +++ b/src/main/java/com/teaching/backend/utils/MinioUtils.java @@ -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 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(); + } + } + + + +} diff --git a/src/main/java/com/teaching/backend/utils/knowGraph/AddNeoKnowByCourse.java b/src/main/java/com/teaching/backend/utils/knowGraph/AddNeoKnowByCourse.java deleted file mode 100644 index 89a779c..0000000 --- a/src/main/java/com/teaching/backend/utils/knowGraph/AddNeoKnowByCourse.java +++ /dev/null @@ -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 addCourse(String courseId , String name, String description){ -// return knowService.createCourseKnow( courseId , name, description); -// } - -// public BaseResponse addChapter(Chapter chapter){ -// return knowService.createKnowChapter(chapter); -// } - -} diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 2419d7c..d0c7383 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -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