Compare commits

...

6 Commits

  1. 2
      src/main/java/com/teaching/backend/common/BaseResponse.java
  2. 20
      src/main/java/com/teaching/backend/controller/KnowMysql/KnowtmpController.java
  3. 8
      src/main/java/com/teaching/backend/controller/KnowNeo4j/KnowController.java
  4. 123
      src/main/java/com/teaching/backend/controller/chapter/ChapterController.java
  5. 142
      src/main/java/com/teaching/backend/controller/chapter/ChapterController2.java
  6. 35
      src/main/java/com/teaching/backend/controller/chapter/LRUCache.java
  7. 10
      src/main/java/com/teaching/backend/controller/cms/CmsEssayController.java
  8. 96
      src/main/java/com/teaching/backend/controller/courseResource/CourseResourceController.java
  9. 91
      src/main/java/com/teaching/backend/controller/courses/CourseObjectivesController.java
  10. 35
      src/main/java/com/teaching/backend/controller/courses/CoursesController.java
  11. 84
      src/main/java/com/teaching/backend/controller/courses/CoursesController2.java
  12. 50
      src/main/java/com/teaching/backend/controller/courses/ObjectiveContentKnowController.java
  13. 62
      src/main/java/com/teaching/backend/controller/courses/ObjectiveContentsController.java
  14. 180
      src/main/java/com/teaching/backend/controller/resource/ResourceController.java
  15. 78
      src/main/java/com/teaching/backend/controller/resource/ResourceGraphController.java
  16. 43
      src/main/java/com/teaching/backend/controller/resource/ResourceMysqlController.java
  17. 2
      src/main/java/com/teaching/backend/controller/umsAdmin/UmsUserController.java
  18. 102
      src/main/java/com/teaching/backend/exception/GlobalExceptionHandler.java
  19. 5
      src/main/java/com/teaching/backend/mapper/courses/CourseObjectivesMapper.java
  20. 2
      src/main/java/com/teaching/backend/mapper/courses/ObjectiveContentKnowMapper.java
  21. 7
      src/main/java/com/teaching/backend/mapper/know/KnowRepository.java
  22. 21
      src/main/java/com/teaching/backend/mapper/resource/ResourceMapper.java
  23. 4
      src/main/java/com/teaching/backend/mapper/resource/ResourceRelationshipMapper.java
  24. 28
      src/main/java/com/teaching/backend/mapper/resource/ResourcesRepository.java
  25. 7
      src/main/java/com/teaching/backend/model/dto/Know/KnowCourseCreateRequest.java
  26. 26
      src/main/java/com/teaching/backend/model/dto/Knowtmp/KnowObjective.java
  27. 1
      src/main/java/com/teaching/backend/model/dto/Knowtmp/KnowtempAdd.java
  28. 1
      src/main/java/com/teaching/backend/model/dto/Knowtmp/KnowtempUpdate.java
  29. 54
      src/main/java/com/teaching/backend/model/dto/chapter/ChapterAndNodeTreeVO.java
  30. 86
      src/main/java/com/teaching/backend/model/dto/chapter/ChapterChildreenVO.java
  31. 60
      src/main/java/com/teaching/backend/model/dto/chapter/ChapterDTO.java
  32. 35
      src/main/java/com/teaching/backend/model/dto/courses/CourseObjectivesDTO.java
  33. 31
      src/main/java/com/teaching/backend/model/dto/courses/CourseObjectivesUpdateDTO.java
  34. 12
      src/main/java/com/teaching/backend/model/dto/courses/CoursesDTO.java
  35. 103
      src/main/java/com/teaching/backend/model/dto/courses/CoursesUpdateDTO.java
  36. 31
      src/main/java/com/teaching/backend/model/dto/resource/ResourceRelationshipDto.java
  37. 29
      src/main/java/com/teaching/backend/model/entity/ResourceRelationship.java
  38. 3
      src/main/java/com/teaching/backend/model/entity/cms/CmsEssay.java
  39. 30
      src/main/java/com/teaching/backend/model/entity/courses/CourseObjectives.java
  40. 52
      src/main/java/com/teaching/backend/model/entity/courses/Testrr.java
  41. 6
      src/main/java/com/teaching/backend/model/entity/favour/SeCourseFavour.java
  42. 4
      src/main/java/com/teaching/backend/model/entity/know/Edge.java
  43. 5
      src/main/java/com/teaching/backend/model/entity/know/Know.java
  44. 2
      src/main/java/com/teaching/backend/model/entity/know/KnowChapter.java
  45. 1
      src/main/java/com/teaching/backend/model/entity/know/KnowCourse.java
  46. 2
      src/main/java/com/teaching/backend/model/entity/know/KnowJson.java
  47. 12
      src/main/java/com/teaching/backend/model/entity/knowtmp/Knowtmp.java
  48. 27
      src/main/java/com/teaching/backend/model/entity/resource/ResourceMysql.java
  49. 37
      src/main/java/com/teaching/backend/model/entity/resource/ResourceRelationship.java
  50. 11
      src/main/java/com/teaching/backend/model/entity/resource/Resources.java
  51. 26
      src/main/java/com/teaching/backend/model/vo/courses/CourseObjectivesTreeVO.java
  52. 2
      src/main/java/com/teaching/backend/model/vo/knowGraph/KnowChapterVO.java
  53. 2
      src/main/java/com/teaching/backend/model/vo/knowGraph/KnowCourseVO.java
  54. 6
      src/main/java/com/teaching/backend/model/vo/knowGraph/KnowJsonListVO.java
  55. 2
      src/main/java/com/teaching/backend/model/vo/knowGraph/KnowPathVO.java
  56. 25
      src/main/java/com/teaching/backend/model/vo/knowGraph/KnowVO1.java
  57. 2
      src/main/java/com/teaching/backend/model/vo/knowGraph/RelsNodesVO.java
  58. 7
      src/main/java/com/teaching/backend/service/Know/KnowService.java
  59. 3
      src/main/java/com/teaching/backend/service/chapter/IChapterService.java
  60. 2
      src/main/java/com/teaching/backend/service/cms/ICmsEssayService.java
  61. 22
      src/main/java/com/teaching/backend/service/courses/ICourseObjectivesService.java
  62. 7
      src/main/java/com/teaching/backend/service/courses/ICoursesService.java
  63. 21
      src/main/java/com/teaching/backend/service/courses/IObjectiveContentKnowService.java
  64. 73
      src/main/java/com/teaching/backend/service/impl/chapter/ChapterServiceImpl.java
  65. 20
      src/main/java/com/teaching/backend/service/impl/cms/CmsEssayServiceImpl.java
  66. 250
      src/main/java/com/teaching/backend/service/impl/courses/CourseObjectivesServiceImpl.java
  67. 367
      src/main/java/com/teaching/backend/service/impl/courses/CoursesServiceImpl.java
  68. 195
      src/main/java/com/teaching/backend/service/impl/courses/ObjectiveContentKnowServiceImpl.java
  69. 83
      src/main/java/com/teaching/backend/service/impl/courses/ObjectiveContentsServiceImpl.java
  70. 60
      src/main/java/com/teaching/backend/service/impl/favour/SeCourseFavourServiceImpl.java
  71. 35
      src/main/java/com/teaching/backend/service/impl/know/knowServiceImpl.java
  72. 171
      src/main/java/com/teaching/backend/service/impl/knowtmp/KnowtmpServiceImpl.java
  73. 6
      src/main/java/com/teaching/backend/service/impl/message/UserInboxServiceImpl.java
  74. 42
      src/main/java/com/teaching/backend/service/impl/resource/ResourceGraphServiceImpl.java
  75. 82
      src/main/java/com/teaching/backend/service/impl/resource/ResourceMysqlServiceImpl.java
  76. 93
      src/main/java/com/teaching/backend/service/impl/resource/ResourceRelationshipServiceImpl.java
  77. 338
      src/main/java/com/teaching/backend/service/impl/resource/ResourceServiceImpl.java
  78. 6
      src/main/java/com/teaching/backend/service/knowtmp/KnowtmpService.java
  79. 5
      src/main/java/com/teaching/backend/service/resource/ResourceGraphService.java
  80. 10
      src/main/java/com/teaching/backend/service/resource/ResourceMysqlService.java
  81. 30
      src/main/java/com/teaching/backend/service/resource/ResourceRelationshipService.java
  82. 34
      src/main/java/com/teaching/backend/service/resource/ResourceService.java
  83. 339
      src/main/java/com/teaching/backend/utils/AliyunOSSClientUtil.java
  84. 58
      src/main/java/com/teaching/backend/utils/AliyunOssFileTypeEnum.java
  85. 1
      src/main/java/com/teaching/backend/utils/MinioUtils.java
  86. 83
      src/main/resources/application-local.yml
  87. 59
      src/main/resources/application.yml
  88. 22
      src/main/resources/banner.txt
  89. 18
      src/main/resources/mapper/CourseObjectivesMapper.xml
  90. 13
      src/main/resources/mapper/ObjectiveContentKnowMapper.xml
  91. 5
      src/main/resources/mapper/ObjectiveContentsMapper.xml
  92. 2
      src/main/resources/mapper/UmsUserMapper.xml
  93. 3
      src/test/java/com/teaching/TeachingBackendApplicationTests.java
  94. 29
      src/test/java/com/teaching/yh/testTryCatch.java

@ -3,6 +3,7 @@ package com.teaching.backend.common;
import lombok.Data;
import java.io.Serializable;
import java.util.HashMap;
/**
* 通用返回类
@ -12,6 +13,7 @@ import java.io.Serializable;
@Data
public class BaseResponse<T> implements Serializable {
private int code;
private T data;

@ -1,13 +1,12 @@
package com.teaching.backend.controller.Knowtmp;
package com.teaching.backend.controller.KnowMysql;
import com.teaching.backend.common.BaseResponse;
import com.teaching.backend.model.dto.Know.BaseKnowReturn;
import com.teaching.backend.model.dto.Knowtmp.KnowObjective;
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 io.swagger.annotations.Api;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@ -28,8 +27,6 @@ public class KnowtmpController {
private KnowtmpService knowtmpService;
//返回课程下所有知识点
@ApiOperation(value = "返回课程下所有知识点")
@GetMapping("/getAllKnows")
@ -73,4 +70,17 @@ public class KnowtmpController {
BaseResponse<List<Knowtmp>> queryByChapterId(Long chapterId){
return knowtmpService.queryByChapterId(chapterId);
}
//给知识点绑定课程目标
@ApiOperation(value = "给知识点绑定课程目标")
@PostMapping("/objectiveaddKnow")
BaseResponse<String> objectiveaddKnow(@RequestBody KnowObjective knowObjective){
return knowtmpService.addObjective(knowObjective.getObjectiveIds(), knowObjective.getKnowId());
}
@ApiOperation(value = "查询知识点下课程目标")
@PostMapping("/knowObjects")
BaseResponse<List<String>> knowObjects(@RequestParam Long knowId){
return knowtmpService.knowObjects(knowId);
}
}

@ -1,4 +1,4 @@
package com.teaching.backend.controller.Know;
package com.teaching.backend.controller.KnowNeo4j;
/**
* @Author:youhang
@ -8,11 +8,11 @@ package com.teaching.backend.controller.Know;
import com.teaching.backend.common.BaseResponse;
import com.teaching.backend.model.dto.Know.*;
import com.teaching.backend.model.entity.know.*;
import com.teaching.backend.model.entity.knowtmp.Knowtmp;
import com.teaching.backend.model.vo.knowGraph.KnowPathVO;
import com.teaching.backend.model.vo.knowGraph.KnowVO;
import com.teaching.backend.model.vo.knowGraph.RelsNodesVO;
import com.teaching.backend.service.Know.KnowService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@ -30,7 +30,7 @@ public class KnowController {
//通过courseId 查询所有结点,存储成JSON
@ApiOperation(value = "通过courseId 查询所有点,存储成JSON")
@ApiOperation(value = "通过courseId 查询所有知识点,存储成JSON")
@GetMapping("/showGraphJson")
BaseResponse<String> showGraphJson(@RequestParam String courseId){
return knowService.showGraphJson(courseId);

@ -1,80 +1,107 @@
package com.teaching.backend.controller.chapter;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.teaching.backend.common.BaseResponse;
import com.teaching.backend.common.ErrorCode;
import com.teaching.backend.common.ResultUtils;
import com.teaching.backend.model.dto.chapter.ChapterAndNodeTreeVO;
import com.teaching.backend.model.dto.chapter.ChapterDTO;
import com.teaching.backend.model.entity.chapter.Chapter;
import com.teaching.backend.model.vo.chapter.ChapterVo;
import com.teaching.backend.service.chapter.IChapterService;
import com.teaching.backend.service.impl.chapter.ChapterExcelServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.util.LinkedList;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;
/**
* ClassName: ChapterController2
* Package: com.teaching.backend.controller.chapter
* Description:
*
* @Author 姜钧瀚
* @Create 2024/7/23 17:16
* @Version 1.0
*/
@Api(tags = "课程章节管理接口")
@RestController
@RequestMapping("/chapter")
@RequestMapping("/api/chapter")
public class ChapterController {
@Autowired
private IChapterService chapterService;
@ApiOperation("查看所有章节")
IChapterService chapterService;
@Autowired
ChapterExcelServiceImpl chapterExcelService;
@ApiOperation("查询全部的章节")
@GetMapping("/list")
public BaseResponse<List<Chapter>> AllList(){
List<Chapter> list = chapterService.list();
return ResultUtils.success(list);
}
@ApiOperation("添加章节")
@PostMapping("/add")
public BaseResponse<Boolean> addChapter(@RequestBody Chapter chapter){
chapter.setNumshow(chapterService.updateNumShow(chapter));
System.out.println("-=-=--=-000"+chapter.getNumshow());
boolean save = chapterService.save(chapter);
return ResultUtils.success(save);
}
@ApiOperation("删除章节信息")
@DeleteMapping("/{id}")
public BaseResponse<Boolean> delete(@PathVariable String id){
Boolean chapter = chapterService.deleteAfterUpdate(id);
return ResultUtils.success(chapter);
public BaseResponse<Page<Chapter>> AllList(@RequestParam(value = "page",defaultValue = "1") int page,
@RequestParam(value = "pageSize",defaultValue = "5") int pageSize){
return ResultUtils.success(chapterService.getAllChapters(page,pageSize));
}
@ApiOperation("更新章节")
@PutMapping
public BaseResponse<Boolean> updateChapter(@RequestBody Chapter chapter){
System.out.println(chapter);
boolean b = chapterService.updateById(chapter);
return ResultUtils.success(b);
// @ApiOperation("根据课程id查出对应的父子章节")
// @GetMapping("/chapter")
// public BaseResponse<List<Chapter>> getCourseChapters2(@RequestParam String courseId){
// return ResultUtils.success(chapterService.getChapterTree(courseId));
// }
@ApiOperation("根据课程id查出对应的父子章节")
@GetMapping("/chapter2")
public BaseResponse<List<ChapterAndNodeTreeVO>> getCourseChapters3(@RequestParam String courseId){
return ResultUtils.success(chapterService.getChapterTree2(courseId));
}
@ApiOperation("查看所有章节linkedlist")
@GetMapping("/listall/{courseid}")
public BaseResponse<LinkedList<Chapter>> getAll(@PathVariable String courseid){
LinkedList<Chapter> list =chapterService.getCourseChapter(courseid);
System.out.println(list);
return ResultUtils.success(list);
@ApiOperation("根据课程id查出对应的详细章节信息")
@GetMapping("/select/chapter/{chapterId}")
public BaseResponse<Chapter>selectChapter(@PathVariable Long chapterId){
return ResultUtils.success(chapterService.selectChapter(chapterId));
}
@ApiOperation("添加章节")
@PostMapping("/add")
public BaseResponse<String> addChapter2(@Valid @RequestBody ChapterDTO chapterDTO) {
BigDecimal remainingHours = chapterService.saveChapter(chapterDTO);
if (remainingHours.compareTo(BigDecimal.ZERO) == 0) {
return ResultUtils.success("添加成功!所有学时分配完成");
} else {
return ResultUtils.success("添加成功!还剩下" + remainingHours + "学时待分配");
}
}
@ApiOperation("章节顺序linkedlist")
@GetMapping("/aaa/{courseid}")
public BaseResponse<LinkedList<ChapterVo>> get(@PathVariable String courseid){
LinkedList<ChapterVo> list =chapterService.getChapterSection(courseid);
System.out.println(list);
return ResultUtils.success(list);
@ApiOperation("插入章节")
@PostMapping("/insert")
public BaseResponse<String> addChapter3(@RequestBody ChapterDTO chapterDTO, Long chapterId1, Long chapterId2){
chapterService.insertChapter(chapterId1,chapterId2,chapterDTO);
return ResultUtils.success("添加成功!!!!!!!!");
}
@ApiOperation("删除章节")
@DeleteMapping("/delete/{id}")
public BaseResponse<String> dlChapter(@PathVariable Long id){
chapterService.deleteChapter(id);
return ResultUtils.success("删除成功");
}
@ApiOperation("计算章的个数")
@GetMapping("/count/{courseid}")
public BaseResponse<Long> getChapterCount(@PathVariable String courseid){
LinkedList<Chapter> list =chapterService.getCourseChapter(courseid);
Long count=list.stream()
.filter( str -> !str.getNumshow().contains("-"))
.count();
return ResultUtils.success(count);
@ApiOperation("修改章节")
@PutMapping("/update")
public BaseResponse<String> udChapter(@RequestBody Chapter chapter){
chapter.setUpdateTime(LocalDateTime.now());
chapterService.updateById(chapter);
return ResultUtils.success("修改成功");
}
}

@ -1,142 +0,0 @@
package com.teaching.backend.controller.chapter;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.teaching.backend.common.BaseResponse;
import com.teaching.backend.common.ErrorCode;
import com.teaching.backend.common.ResultUtils;
import com.teaching.backend.model.dto.chapter.ChapterDTO;
import com.teaching.backend.model.entity.chapter.Chapter;
import com.teaching.backend.service.chapter.IChapterService;
import com.teaching.backend.service.impl.chapter.ChapterExcelServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;
/**
* ClassName: ChapterController2
* Package: com.teaching.backend.controller.chapter
* Description:
*
* @Author 姜钧瀚
* @Create 2024/7/23 17:16
* @Version 1.0
*/
@Api(tags = "课程章节管理接口2")
@RestController
@RequestMapping("/api/chapter2")
public class ChapterController2 {
@Autowired
IChapterService chapterService;
@Autowired
ChapterExcelServiceImpl chapterExcelService;
@ApiOperation("查询全部的章节")
@GetMapping("/list")
public BaseResponse<Page<Chapter>> AllList(@RequestParam(value = "page",defaultValue = "1") int page,
@RequestParam(value = "pageSize",defaultValue = "5") int pageSize){
return ResultUtils.success(chapterService.getAllChapters(page,pageSize));
}
@ApiOperation("根据课程id查出对应的父子章节")
@GetMapping("/chapter")
public BaseResponse<List<Chapter>> getCourseChapters2(@RequestParam String courseId){
return ResultUtils.success(chapterService.getChapterTree(courseId));
}
@ApiOperation("根据课程id查出对应的详细章节信息")
@GetMapping("/select/chapter/{chapterId}")
public BaseResponse<Chapter>selectChapter(@PathVariable Long chapterId){
return ResultUtils.success(chapterService.selectChapter(chapterId));
}
@ApiOperation("添加章节")
@PostMapping("/add")
public BaseResponse<String> addChapter2(@Valid @RequestBody ChapterDTO chapterDTO) {
BigDecimal remainingHours = chapterService.saveChapter(chapterDTO);
if (remainingHours.compareTo(BigDecimal.ZERO) == 0) {
return ResultUtils.success("添加成功!所有学时分配完成");
} else {
return ResultUtils.success("添加成功!还剩下" + remainingHours + "学时待分配");
}
}
@ApiOperation("插入章节")
@PostMapping("/insert")
public BaseResponse<String> addChapter3(@RequestBody ChapterDTO chapterDTO, Long chapterId1, Long chapterId2){
chapterService.insertChapter(chapterId1,chapterId2,chapterDTO);
return ResultUtils.success("添加成功!!!!!!!!");
}
@ApiOperation("删除章节")
@DeleteMapping("/delete/{id}")
public BaseResponse<String> dlChapter(@PathVariable Long id){
chapterService.deleteChapter(id);
return ResultUtils.success("删除成功");
}
@ApiOperation("下载Excel模版")
@GetMapping("/downExcel")
public void downExcel2(HttpServletResponse response) throws IOException {
chapterService.downExcel(response);
}
@ApiOperation("导入excel")
@PostMapping("/uploadExcel")
public BaseResponse<String> addChapter3(MultipartFile file, String courseId) {
try {
List<String> validationErrors = chapterExcelService.uploadExcel(file, courseId);
if (!validationErrors.isEmpty()) {
StringBuilder errorMessage = new StringBuilder();
for (String error : validationErrors) {
errorMessage.append(error).append("\n");
}
return ResultUtils.error(ErrorCode.OPERATION_ERROR, errorMessage.toString());
} else {
return ResultUtils.success("添加成功!!!!!!!!");
}
} catch (Exception e) {
return ResultUtils.error(ErrorCode.SYSTEM_ERROR, "系统错误: " + e.getMessage());
}
}
@ApiOperation("导出数据")
@GetMapping(value = "/downLoadExcel")
public void downLoadXlsx(HttpServletResponse response,String courseId) throws Exception{
chapterService.downLoadXlsx(response,courseId);
}
@ApiOperation("修改章节")
@PutMapping("/update")
public BaseResponse<String> udChapter(@RequestBody Chapter chapter){
chapter.setUpdateTime(LocalDateTime.now());
chapterService.updateById(chapter);
return ResultUtils.success("修改成功");
}
@ApiOperation("将章节上移")
@PostMapping("/upper")
public BaseResponse<String> increase(@RequestParam Long chapterId){
chapterService.upChapter(chapterId);
return ResultUtils.success("上移成功");
}
@ApiOperation("将章节下移")
@PostMapping("/down")
public BaseResponse<String> decrease(@RequestParam Long chapterId){
chapterService.downChapter(chapterId);
return ResultUtils.success("下移成功");
}
}

@ -0,0 +1,35 @@
package com.teaching.backend.controller.chapter;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
class LRUCache {
public static Map<Integer,Integer> map;
public static Map<Integer,Integer> nums;
private int capacity;
private int res;
public LRUCache(int capacity) {
map = new LinkedHashMap<>();
this.capacity = capacity;
res = 0;
}
public int get(int key) {
return map.get(key);
}
public void put(int key, int value) {
capacity++;
if(capacity > res){
}
map.put(key,value);
int counts = nums.get(key);
}
}

@ -87,4 +87,14 @@ public class CmsEssayController {
public BaseResponse<String> editStatus(@RequestBody CmsEssay cmsEssay){
return cmsEssayService.editStatus(cmsEssay);
}
/**
* 浏览量
* @param id
* @return
*/
@PutMapping("/views/{id}")
public BaseResponse<String> views(@PathVariable Integer id){
return cmsEssayService.views(id);
}
}

@ -1,96 +0,0 @@
//package com.teaching.backend.controller.courseResource;
//
//import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
//import com.teaching.backend.common.BaseResponse;
//import com.teaching.backend.common.ResultUtils;
//
//import com.teaching.backend.model.entity.resource.CourseResources;
//import io.swagger.annotations.ApiOperation;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.web.bind.annotation.*;
//
//import java.util.ArrayList;
//import java.util.List;
//
//@RestController
//@RequestMapping("/api/courses")
//public class CourseResourceController {
// @Autowired
// private CourseResourcesServiceImpl courseResourcesService;
// @ApiOperation("查询全部课程资源记录")
// @GetMapping("/all")
// public BaseResponse<List<CourseResources>> All(){
// System.out.println("学习记录:"+courseResourcesService.list());
// return ResultUtils.success(courseResourcesService.list());
// }
//
// @ApiOperation("按type查询课程资源")
// @GetMapping("/getall")
// public BaseResponse<Page> getAll(@RequestParam(value = "pagenum", defaultValue = "1") int pagenum,
// @RequestParam(value = "pagesize", defaultValue = "10") int pagesize,
// String type) {
//
// List<CourseResources> cs = courseResourcesService.getByType(type);
// List<CourseResources> pageCs = new ArrayList<>();
// //当前页面
// for(int i = (pagenum - 1) * pagesize; i < cs.size() && i < (pagenum) * pagesize; i++){
// pageCs.add(cs.get(i));
// }
// long total = cs.size(); // 总记录数
// Page<CourseResources> pageInfo = new Page<>(pagenum,pagesize,total);
// pageInfo.setRecords(pageCs);
// pageInfo.setPages((int)(Math.ceil((double) total / pagesize)));//设置总页数
// return ResultUtils.success(pageInfo);
// }
//
// /**
// * 根据ids删除
// * @param ids
// * @return
// */
// @ApiOperation("根据ids删除")
// @DeleteMapping("/delete")
// public BaseResponse<String> deleteRecords(@RequestParam List<Long> ids){
// courseResourcesService.removeCourseResources(ids);
//// courseResourcesService.removeBatchByIds(ids);
// return ResultUtils.success("删除成功!!");
// }
//
// /**
// * 新增
// * @param courseResources
// * @return
// */
// @ApiOperation("新增课程资源")
// @PostMapping("/save")
// public BaseResponse<String> saveCourseResource(@RequestBody CourseResources courseResources){
// System.out.println(courseResources);
// courseResourcesService.saveCourseResource(courseResources);
// return ResultUtils.success("添加成功!");
// }
//
// /**
// * 编辑
// * @param resources
// * @return
// */
// @ApiOperation("编辑课程资源")
// @PutMapping("/edit")
// public BaseResponse<String> editCourseResource(@RequestBody CourseResources resources){
// System.out.println(resources);
// courseResourcesService.updateById(resources);
// return ResultUtils.success("编辑成功");
// }
//
// /**
// * 根据id查询课程资源
// * @param resourceId
// * @return
// */
// @ApiOperation("根据id查询课程资源")
// @PostMapping("/getone")
// public BaseResponse<CourseResources> getOne(@RequestParam String resourceId){
// System.out.println(resourceId);
// return ResultUtils.success(courseResourcesService.getById(resourceId));
// }
//}

@ -2,20 +2,24 @@ package com.teaching.backend.controller.courses;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.date.DateTime;
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.filter.ValidateParams;
import com.teaching.backend.mapper.courses.CourseObjectivesMapper;
import com.teaching.backend.model.dto.courses.CourseObjectivesDTO;
import com.teaching.backend.model.dto.courses.CourseObjectivesUpdateDTO;
import com.teaching.backend.model.entity.courses.CourseObjectives;
import com.teaching.backend.model.vo.courses.CourseObjectivesTreeVO;
import com.teaching.backend.model.vo.courses.CourseObjectivesVO;
import com.teaching.backend.service.courses.ICourseObjectivesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;
/**
@ -38,16 +42,14 @@ public class CourseObjectivesController {
@Autowired
CourseObjectivesMapper courseObjectivesMapper;
@ApiOperation("新增分项目标-默认第一个必须添加思政目标")
@ValidateParams({"name","type","pid"})
@ApiOperation("新增分项目标")
@PostMapping("/addobjectives")
public BaseResponse<String> saveCourseObjectives(@RequestBody CourseObjectivesDTO courseObjectivesDTO){
String data = courseObjectivesService.addObjectives(courseObjectivesDTO);
return ResultUtils.success(data);
}
@ApiOperation("删除分项目标-只能最后一个删除思政目标-总目标只需删除关联的内容")
@ValidateParams({"id"})
@ApiOperation("删除分项目标")
@DeleteMapping("/{id}")
public BaseResponse<String> deleteCourseObjectivesByIds(@PathVariable String id){
String data = courseObjectivesService.deleteObjectives(id);
@ -55,34 +57,81 @@ public class CourseObjectivesController {
}
/**
* @param courseObjectivesDTO
* @param
* @return
*/
//TODO:分项目标按理说不能编辑,只可以新增 删除
@ApiOperation("编辑分项目标")
@PutMapping
public BaseResponse<String> updateCourseObjectives(@RequestBody CourseObjectivesDTO courseObjectivesDTO){
String pid = courseObjectivesDTO.getPid();
CourseObjectives courseObjectives = courseObjectivesMapper.selectById(pid);
BeanUtil.copyProperties(courseObjectivesDTO, courseObjectives);
public BaseResponse<String> updateCourseObjectives(@RequestBody CourseObjectivesUpdateDTO courseObjectivesUpdateDTO){
String id = courseObjectivesUpdateDTO.getId();
String courseId = courseObjectivesUpdateDTO.getCourseId();
Integer type = courseObjectivesUpdateDTO.getType();
String name = courseObjectivesUpdateDTO.getName();
String pid = courseObjectivesUpdateDTO.getPid();
String content = courseObjectivesUpdateDTO.getContent();
if(id == null){
return ResultUtils.error(ErrorCode.PARAMS_ERROR,"id不能为空");
}
if(courseId == null){
return ResultUtils.error(ErrorCode.PARAMS_ERROR,"courseId不能为空");
}
if(name == null){
return ResultUtils.error(ErrorCode.PARAMS_ERROR,"name不能为空");
}
if(type == null){
return ResultUtils.error(ErrorCode.PARAMS_ERROR,"type不能为空");
}
QueryWrapper<CourseObjectives> courseObjectivesQueryWrapper = new QueryWrapper<>();
courseObjectivesQueryWrapper.eq("id",courseObjectivesUpdateDTO.getId());
CourseObjectives courseObjectives = courseObjectivesMapper.selectOne(courseObjectivesQueryWrapper);
if(name != null){
courseObjectives.setName(name);
}
if(content != null){
courseObjectives.setContent(content);
}
courseObjectives.setCreateTime(new DateTime().toLocalDateTime());
courseObjectivesService.updateById(courseObjectives);
return ResultUtils.success("编辑成功");
}
@ApiOperation("查询课程目标内容")
@ApiOperation("查询一个课程下所有目标内容")
@ValidateParams({"id"})
@GetMapping("/list/{id}")
public BaseResponse<List<CourseObjectivesTreeVO>> queryCourseObjectivesTree(@PathVariable String id){
List<CourseObjectivesTreeVO> courseObjectivesTreeVO = courseObjectivesService.queryCourseObjectivesTree(id);
return ResultUtils.success(courseObjectivesTreeVO);
public BaseResponse<List<CourseObjectives>> queryCourseObjectivesTree(@PathVariable String id){
List<CourseObjectives> CourseObjectivesList = courseObjectivesService.selectObjectivesList(id);
return ResultUtils.success(CourseObjectivesList);
}
@ApiOperation("查询目标下知识点个数")
@ValidateParams({"id"})
@GetMapping("/objective/knowcount")
public BaseResponse<Long> knowcount(@RequestParam String id){
return courseObjectivesService.knowcount(id);
}
@ApiOperation("查询目标下学时")
@ValidateParams({"id"})
@GetMapping("/objective/knowtime")
public BaseResponse<Double> knowtime(@RequestParam String id){
return courseObjectivesService.knowtime(id);
}
@ApiOperation("列表显示分项目标(用于添加目标内容时选择)")
@GetMapping("/objectiveslist/{courseId}")
public BaseResponse<List<CourseObjectivesVO>> queryCourseObjectivesForAdd(@PathVariable String courseId){
List<CourseObjectivesVO> courseObjectivesVOS = courseObjectivesService.queryCourseObjectivesForAdd(courseId);
return ResultUtils.success(courseObjectivesVOS);
@ApiOperation("查询目标下学时占总目标的百分比")
@ValidateParams({"id","courseId"})
@GetMapping("/objective/knowtimepercent")
public BaseResponse<Double> knowtimepercent(@RequestParam String courseId , @RequestParam String id)throws Exception{
return courseObjectivesService.knowtimepercent(courseId,id);
}
}

@ -6,6 +6,7 @@ import com.teaching.backend.common.CommonResult;
import com.teaching.backend.common.ResultUtils;
import com.teaching.backend.filter.ValidateParams;
import com.teaching.backend.model.dto.courses.CoursesDTO;
import com.teaching.backend.model.dto.courses.CoursesUpdateDTO;
import com.teaching.backend.model.dto.courses.PageDTO;
import com.teaching.backend.model.entity.courses.Courses;
import com.teaching.backend.model.entity.umsAdmin.UmsStudent;
@ -44,21 +45,6 @@ public class CoursesController {
// @ApiOperation("网站首页")
// @GetMapping("/index")
// public BaseResponse<Map<String,Object>> getData(@RequestParam("page") int page, @RequestParam("pageSize") int pageSize) {
// List<CoursesVO> coursesVo = coursesService.getPagePageSize(page, pageSize);
//// System.out.println(coursesVo);
// long totalcount = coursesService.count();
// long toatlPages = (int) Math.ceil((double)totalcount / pageSize);
// Map<String,Object> objectMap = new HashMap<>();
// objectMap.put("content",coursesVo);
// objectMap.put("totalcount", totalcount);
// objectMap.put("totalPages", toatlPages);
// objectMap.put("currentPage", page);
// return ResultUtils.success(objectMap);
// }
@ApiOperation("网站首页")
@GetMapping("/index")
public BaseResponse<Map<String,Object>> getData(@RequestParam("page") int page, @RequestParam("pageSize") int pageSize) {
@ -75,7 +61,7 @@ public class CoursesController {
}
@ApiOperation("新增课程--同步新增课程的总体目标并同时添加所有的分项目标")
@ApiOperation("新增课程--默认创建一个课程总目标")
@ValidateParams({"teacher","img", "category", "nature","name","code","credit","classhours","assessmenttype","assessmentway"}) // 需要校验的参数
@PostMapping("/addcourse")
public BaseResponse<String> saveCourse(@RequestBody CoursesDTO coursesDTO){
@ -105,8 +91,8 @@ public class CoursesController {
@ApiOperation("根据id修改课程")
@ValidateParams({"id","teacher","img", "category", "nature","name","code","credit","classhours","assessmenttype","assessmentway"})
@PutMapping
public BaseResponse<String> editCourse(@RequestBody CoursesDTO coursesDTO){
coursesService.updateCourse(coursesDTO);
public BaseResponse<String> editCourse(@RequestBody CoursesUpdateDTO coursesUpdateDTO){
coursesService.updateCourse(coursesUpdateDTO);
return ResultUtils.success("编辑成功");
}
@ -119,18 +105,6 @@ public class CoursesController {
return ResultUtils.success("删除成功");
}
/**
* 导出word
* @param response
* @throws Exception
*/
@ApiOperation("导出word")
@GetMapping(value = "/down")
public void test( HttpServletResponse response) throws Exception{
//-------------------------查询课程通过课程id查
String id = "de3100cad98f76be3176dd39aa748a9e";
coursesService.down(response, id);
}
@ApiOperation("查询学生列表")
@PostMapping("/studentList")
@ -139,6 +113,7 @@ public class CoursesController {
return CommonResult.success(umsStudentList);
}
@ApiOperation("根据用户id,查询与用户有关的课程列表,并在课程列表显示所有用户信息")
@ValidateParams({"userId"})
@GetMapping("/page/courseusers")

@ -1,84 +0,0 @@
//package com.teaching.backend.controller.courses;
//
//import com.teaching.backend.common.BaseResponse;
//import com.teaching.backend.common.ErrorCode;
//import com.teaching.backend.common.ResultUtils;
//import com.teaching.backend.exception.BusinessException;
//import com.teaching.backend.filter.ValidateParams;
//import com.teaching.backend.model.dto.courses.CoursesDTO;
//import com.teaching.backend.model.entity.courses.Courses;
//import com.teaching.backend.service.courses.ICoursesService;
//import io.swagger.annotations.ApiOperation;
//import org.springframework.beans.BeanUtils;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.web.bind.annotation.*;
//
//import java.util.HashMap;
//import java.util.List;
//import java.util.Map;
//
///**
// * ClassName: CoursesController2
// * Package: com.teaching.backend.controller.courses
// * Description:
// *
// * @Author 姜钧瀚
// * @Create 2024/7/22 17:52
// * @Version 1.0
// */
//@RestController
//@RequestMapping("/api/coursesteacher2")
//public class CoursesController2 {
// @Autowired
// ICoursesService coursesService;
//
// @ApiOperation("网站首页2")
// @GetMapping("/index2")
// public BaseResponse<Map<String,Object>> getData(@RequestParam("page") int page, @RequestParam("pageSize") int pageSize) {
// Map<String, Object> result = coursesService.getPagePageSize2(page, pageSize);
//
// // 将结果放入新的Map对象中返回
// Map<String, Object> objectMap = new HashMap<>();
// objectMap.put("content", result.get("courses"));
// objectMap.put("totalcount", result.get("totalcount"));
// objectMap.put("totalPages", result.get("totalPages"));
// objectMap.put("currentPage", result.get("currentPage"));
//
// return ResultUtils.success(objectMap);
// }
//
//
// @ApiOperation("根据id查询课程")
// @ValidateParams({"id"})
// @GetMapping("/{id}")
// public BaseResponse<CoursesDTO> getByIdCourse(@PathVariable String id){
// if(id==null){
// throw new BusinessException(ErrorCode.PARAMS_ERROR,"课程id为空");
// }
// Courses course = coursesService.getById(id);
// CoursesDTO coursesDTO = new CoursesDTO();
// BeanUtils.copyProperties(course,coursesDTO);
// return ResultUtils.success(coursesDTO);
// }
//
// @ApiOperation("点击详情课程根据id查询对应课程的资源")
// @GetMapping("/resource/{id}")
// public BaseResponse<List<CourseResources>> getResource(@PathVariable String id) {
// List<CourseResources> relatedResources = resourcesRelationshipService.getResource(id);
// return ResultUtils.success(relatedResources);
// }
//
// @ApiOperation("点击详情课程根据id和type查询对应课程的资源")
// @GetMapping("/resource/list")
// public BaseResponse<List<CourseResources>> getResource2(@RequestParam String id,@RequestParam Integer type) {
// List<CourseResources> relatedResources = resourcesRelationshipService.getResource2(id,type);
// return ResultUtils.success(relatedResources);
// }
//
//
// }
//
//
//
//
//

@ -1,50 +0,0 @@
package com.teaching.backend.controller.courses;
import com.teaching.backend.common.BaseResponse;
import com.teaching.backend.common.ResultUtils;
import com.teaching.backend.filter.ValidateParams;
import com.teaching.backend.model.dto.courses.CoursesDTO;
import com.teaching.backend.model.dto.courses.ObjectiveContentKnowDTO;
import com.teaching.backend.model.vo.courses.ObjectiveContentKnowVO;
import com.teaching.backend.service.courses.IObjectiveContentKnowService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;
/**
* <p>
* 前端控制器
* </p>
*
* @author zjh
* @since 2024-06-13
*/
@Api(tags = "目标-内容 关联的知识点接口")
@RestController
@RequestMapping("/api/objective_content_know")
public class ObjectiveContentKnowController {
@Autowired
IObjectiveContentKnowService objectiveContentKnowService;
@ApiOperation("给知识点关联--目标内容")
@ValidateParams({"objectiveContentId","knowId"})
@PostMapping("/addknows")
public BaseResponse<String> saveKnowsWithObjectiveContent(@RequestBody ObjectiveContentKnowDTO objectiveContentKnowDTO){
String data = objectiveContentKnowService.saveKnowsWithObjectiveContent(objectiveContentKnowDTO);
return ResultUtils.success(data);
}
@ApiOperation("针对分项目标统计,支撑分项目标知识点的个数、学时合计、占比")
@ValidateParams({"objectiveId"})
@GetMapping("/{objectiveId}")
public BaseResponse<ObjectiveContentKnowVO> getCountData(@PathVariable String objectiveId){
ObjectiveContentKnowVO objectiveContentKnowVO= objectiveContentKnowService.getCountData(objectiveId);
return ResultUtils.success(objectiveContentKnowVO);
}
}

@ -1,62 +0,0 @@
package com.teaching.backend.controller.courses;
import com.teaching.backend.common.BaseResponse;
import com.teaching.backend.common.ResultUtils;
import com.teaching.backend.filter.ValidateParams;
import com.teaching.backend.model.entity.courses.ObjectiveContents;
import com.teaching.backend.service.courses.IObjectiveContentsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
/**
* <p>
* 前端控制器
* </p>
*
* @author zjh
* @since 2024-06-05
*/
@RestController
@RequestMapping("/api/objective_contents")
@Api(tags = "目标内容接口")
public class ObjectiveContentsController {
@Autowired
IObjectiveContentsService objectiveContentsService;
@ApiOperation("添加目标内容")
@ValidateParams({"objectiveId"})
@PostMapping("/addcontent")
public BaseResponse<String> saveContent(@RequestBody ObjectiveContents objectiveContents){
String data = objectiveContentsService.saveWithCheck(objectiveContents);
return ResultUtils.success(data);
}
@ApiOperation("删除目标内容")
@ValidateParams({"id"})
@DeleteMapping("/{id}")
public BaseResponse<String> deleteContent(@PathVariable String id){
String data = objectiveContentsService.deleteById(id);
return ResultUtils.success(data);
}
@ApiOperation("修改目标内容")
@ValidateParams({"id","objectiveId"})
@PutMapping("/update")
public BaseResponse<String> updateContent(@RequestBody ObjectiveContents objectiveContents){
objectiveContentsService.updateById(objectiveContents);
return ResultUtils.success("修改成功");
}
@ApiOperation("根据id查询目标内容")
@ValidateParams({"id"})
@GetMapping("/{id}")
public BaseResponse<ObjectiveContents> updateContent(@PathVariable String id){
ObjectiveContents objectiveContent = objectiveContentsService.getById(id);
return ResultUtils.success(objectiveContent);
}
}

@ -8,8 +8,13 @@ package com.teaching.backend.controller.resource;
import com.teaching.backend.common.BaseResponse;
import com.teaching.backend.model.dto.resource.ResourceRelationshipDto;
import com.teaching.backend.model.dto.resource.ResourceUploadDto;
import com.teaching.backend.model.entity.resource.ResourceMysql;
import com.teaching.backend.model.entity.resource.Resources;
import com.teaching.backend.service.resource.ResourceGraphService;
import com.teaching.backend.service.resource.ResourceMysqlService;
import com.teaching.backend.service.resource.ResourceRelationshipService;
import com.teaching.backend.service.resource.ResourceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@ -19,6 +24,13 @@ import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.io.InputStream;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Set;
@RestController
@RequestMapping("/api/resource")
@ -28,28 +40,176 @@ public class ResourceController {
@Autowired
private ResourceService resourceService;
@Autowired
private ResourceGraphService resourceGraphService;
@Autowired
private ResourceRelationshipService resourceRelationshipService;
@Autowired
private ResourceMysqlService resourceMysqlService;
//添加知识点
@PostMapping("/upload")
// //添加知识点
// @PostMapping("/upload")
// @ResponseBody
// @ApiOperation(value = "添加资源")
// public BaseResponse<ResourceUploadDto> uploadFile(@RequestPart("file") MultipartFile file) {
// return resourceService.upload(file);
// }
//
// //删除资源
// @GetMapping ("/deleteFile")
// @ResponseBody
// @ApiOperation(value = "删除资源")
// public BaseResponse<String> deleteResource(@RequestParam("filename") String filename) {
// return resourceService.delete(filename);
// }
//
// @GetMapping("/read")
// @ApiOperation(value = "查询资源")
// public ResponseEntity<InputStreamResource> readFile(@RequestParam String filename) {
// return resourceService.readFile(filename);
// }
@PostMapping("/upload/OSS")
@ResponseBody
@ApiOperation(value = "添加资源")
public BaseResponse<Resources> uploadFile(@RequestPart("file") MultipartFile file) {
return resourceService.upload(file);
public BaseResponse<String> uploadFileOSS(@RequestPart("file") MultipartFile file) throws IOException {
try {
return resourceService.uploadOSS(file);
}catch (IOException e){
throw e;
}
}
//删除资源
@GetMapping ("delete")
@GetMapping ("/deleteFileOss")
@ResponseBody
@ApiOperation(value = "删除资源")
public BaseResponse<String> deleteResource(@RequestParam("filename") String filename) {
return resourceService.delete(filename);
public BaseResponse<String> deleteFileOss(@RequestParam("filename") String filename) {
return resourceService.deleteFileOss(filename);
}
@GetMapping("/read")
@GetMapping("/read/oss")
@ApiOperation(value = "查询资源")
public ResponseEntity<InputStreamResource> readFile(@RequestParam String filename) {
return resourceService.readFile(filename);
public BaseResponse<InputStream> readFileOss(@RequestParam String filename) {
return resourceService.readFile(filename);
}
@PostMapping("/add/mysql")
@ResponseBody
@ApiOperation(value = "添加资源-mysql")
public BaseResponse<String> addResourceForMysql(@RequestPart("file") MultipartFile file){
return resourceService.addResourceForMysql(file);
}
@GetMapping("/delete/mysql")
@ApiOperation(value = "删除资源-mysql")
public BaseResponse<String> deleteResourceForMysql(@RequestParam long Id){
return resourceService.deleteResourceForMysql(Id);
}
@PostMapping("/add")
@ResponseBody
@ApiOperation(value = "添加资源-mysql-neo")
public BaseResponse<ResourceMysql> addResource(@RequestPart("file") MultipartFile file){
return resourceService.addResource(file);
}
@GetMapping("/delete")
@ApiOperation(value = "删除资源-mysq-neo")
public BaseResponse<String> deleteResource(@RequestParam long Id){
return resourceService.deleteResource(Id);
}
// 添加知识点与资源 mysql表
@PostMapping("/addResourcesRel")
@ApiOperation(value = "添加知识点资源关系 -mysql")
public BaseResponse<String> addResourcesRel(@RequestBody ResourceRelationshipDto resourceRelationshipDto){
return resourceRelationshipService.addResourcesRel(resourceRelationshipDto);
}
@GetMapping("/deleteResourcesRel")
@ApiOperation(value = "删除知识点资源关系 -mysql")
public BaseResponse<String> deleteResourcesRel(@RequestParam Long KnowId, @RequestParam Long resourceId){
return resourceRelationshipService.deleteResourcesRel(KnowId,resourceId);
}
@PostMapping("/myself/recoverdata")
@ResponseBody
@ApiOperation(value = "recoverdatal-neo")
public BaseResponse<String> recoverdata(){
return resourceService.recoverdata();
}
//图谱 - 知识点-资源关系
// @GetMapping("/addRelationship/BetweenKnowAndResources")
// @ApiOperation(value = "添加知识点资源关系 -neo4j")
// public BaseResponse<String> addResourcesByIdAndResourcesId(@RequestParam Long id,@RequestParam Long resourcesId){
// return resourceGraphService.addResourcesByIdAndResourcesId(id,resourcesId);
// }
//
// @GetMapping("/deleteRelationship/BetweenKnowAndResources")
// @ApiOperation(value = "删除知识点资源关系 -neo4j")
// public BaseResponse<String> deleteResourcesAndKnowById(@RequestParam Long id, @RequestParam Long resourcesId){
// return resourceGraphService.deleteResourcesAndKnowById(id,resourcesId);
// }
//查询课程下资源
@GetMapping("/queryByCourseId")
@ApiOperation(value = "查询课程下所有资源 -neo4j")
BaseResponse<Set<Resources>> queryResourcesByCourseIdToNeo4j(@RequestParam String courseId){
return resourceGraphService.queryResourcesByCourseId(courseId);
}
//查询章节下资源
@GetMapping("/queryByChapterId")
@ApiOperation(value = "查询章节下所有资源 -neo4j")
BaseResponse<Set<Resources>> queryResourcesByChapterId(@RequestParam Long chapterId){
return resourceGraphService.queryResourcesByChapterId(chapterId);
}
//查询二级节点下资源 -neo4j
@ApiOperation(value = "查询二级节点下所有资源 -neo4j")
@GetMapping("/queryBesidesKnow")
BaseResponse<Set<Resources>> queryBesidesKnowToResources(@RequestParam Long knowId){
return resourceGraphService.queryBesidesKnowToResources(knowId);
}
//查询知识点下资源 -neo4j
@GetMapping("/queryResourcesByKnowId")
@ApiOperation(value = "查询知识点下所有资源 -neo4j")
BaseResponse<Set<Resources>> queryResourcesById(@RequestParam Long knowId){
return resourceGraphService.queryResourcesById(knowId);
}
//查询知识点下资源 -mysql
@GetMapping("/mysql/queryResourcesByKnowId")
@ApiOperation(value = "查询知识点下所有资源 -mysql")
BaseResponse<List<ResourceMysql>> queryResourcesByKnowId(@RequestParam Long knowId){
return resourceMysqlService.queryResourcesByKnowId(knowId);
}
//查询课程下资源 -mysql
@GetMapping("/mysql/queryByCourseId")
@ApiOperation(value = "查询课程下所有资源 -mysql")
BaseResponse<List<ResourceMysql>> queryResourcesByCourseIdToMysql(@RequestParam String courseId){
return resourceMysqlService.queryResourcesByCourseId(courseId);
}
}

@ -1,78 +0,0 @@
package com.teaching.backend.controller.resource;
/**
* @Author:youhang
* @Date:2024-06-09-9:55
* @Description:
*/
import com.teaching.backend.common.BaseResponse;
import com.teaching.backend.model.entity.resource.Resources;
import com.teaching.backend.service.resource.ResourceGraphService;
import com.teaching.backend.service.resource.ResourceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
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 java.util.List;
import java.util.Set;
@RestController
@RequestMapping("/api/resource/graph")
@Api(tags= "资源与图管理")
public class ResourceGraphController {
@Autowired
private ResourceGraphService resourceGraphService;
@GetMapping("/addRelationship/BetweenKnowAndResources")
@ApiOperation(value = "添加知识点资源关系")
public BaseResponse<String> addResourcesByIdAndResourcesId(@RequestParam Long id,@RequestParam Long resourcesId){
return resourceGraphService.addResourcesByIdAndResourcesId(id,resourcesId);
}
@GetMapping("/deleteRelationship/BetweenKnowAndResources")
@ApiOperation(value = "删除知识点资源关系")
public BaseResponse<String> deleteResourcesAndKnowById(@RequestParam Long id, @RequestParam Long resourcesId){
return resourceGraphService.deleteResourcesAndKnowById(id,resourcesId);
}
//查询课程下资源
@GetMapping("/queryByCourseId")
@ApiOperation(value = "查询课程下资源")
BaseResponse<Set<Resources>> queryResourcesByCourseId(@RequestParam String courseId){
return resourceGraphService.queryResourcesByCourseId(courseId);
}
//查询章节下资源
@GetMapping("/queryByChapterId")
@ApiOperation(value = "查询章节下资源")
BaseResponse<Set<Resources>> queryResourcesByChapterId(@RequestParam Long chapterId){
return resourceGraphService.queryResourcesByChapterId(chapterId);
}
//查询二级节点下资源
@ApiOperation(value = "查询二级节点下资源")
@GetMapping("/queryBesidesKnow")
BaseResponse<Set<Resources>> queryBesidesKnowToResources(@RequestParam Long knowId){
return resourceGraphService.queryBesidesKnowToResources(knowId);
}
//查询知识点下资源
@GetMapping("/queryResourcesByKnowId")
@ApiOperation(value = "查询知识点下资源")
BaseResponse<Set<Resources>> queryResourcesByKnowId(@RequestParam Long knowId){
return resourceGraphService.queryResourcesByKnowId(knowId);
}
}

@ -1,43 +0,0 @@
package com.teaching.backend.controller.resource;
import com.teaching.backend.common.BaseResponse;
import com.teaching.backend.common.ResultUtils;
import com.teaching.backend.model.entity.resource.ResourceMysql;
import com.teaching.backend.service.impl.resource.ResourceMysqlServiceImpl;
import com.teaching.backend.service.impl.resource.ResourceServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
/**
* <p>
* 前端控制器
* </p>
*
* @author author
* @since 2024-09-02
*/
@RestController
@RequestMapping("/resourcemysql")
@Api(tags= "数据库资源管理")
public class ResourceMysqlController {
private ResourceMysqlServiceImpl resourceMysqlService;
private ResourceServiceImpl resourceService;
//添加资源
@PostMapping("/add")
@ApiOperation(value = "添加资源")
public BaseResponse<String> addFile(@RequestPart("file") MultipartFile file, ResourceMysql resourceMysql) {
System.out.println("资源:"+ resourceMysql);
System.out.println(file);
String url = resourceService.upload(file).getData().getUrl();
System.out.println(url);
//return ResultUtils.success("添加xx");
return resourceMysqlService.resourceUpload(file, resourceMysql);
}
}

@ -30,7 +30,7 @@ import java.util.Map;
* @Description:login
*/
@RestController
@Api(tags = "UmsUserController")
@Api(tags = "用户管理")
@RequestMapping("/api/user")
@Slf4j
public class UmsUserController {

@ -3,10 +3,13 @@ package com.teaching.backend.exception;
import com.teaching.backend.common.BaseResponse;
import com.teaching.backend.common.ErrorCode;
import com.teaching.backend.common.ResultUtils;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.context.annotation.Bean;
import org.springframework.validation.FieldError;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
@ -14,54 +17,63 @@ import java.util.HashMap;
import java.util.Map;
@RestControllerAdvice
@ControllerAdvice
@Slf4j
public class GlobalExceptionHandler {
@ExceptionHandler(MethodArgumentNotValidException.class)
public ResponseEntity<Map<String, String>> handleValidationExceptions(MethodArgumentNotValidException ex) {
Map<String, String> errors = new HashMap<>();
ex.getBindingResult().getAllErrors().forEach((error) -> {
String fieldName = ((FieldError) error).getField();
String errorMessage = error.getDefaultMessage();
errors.put(fieldName, errorMessage);
});
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(errors);
}
@ExceptionHandler(BusinessException.class)
public ResponseEntity<ErrorResponse> handleBusinessException(BusinessException ex) {
ErrorResponse errorResponse = new ErrorResponse(ex.getCode(), ex.getMessage());
return new ResponseEntity<>(errorResponse, HttpStatus.BAD_REQUEST);
}
// @ExceptionHandler(MethodArgumentNotValidException.class)
// //ResponseEntity<Map<String, String>>
// public BaseResponse<String> handleValidationExceptions(MethodArgumentNotValidException ex) {
// Map<String, String> errors = new HashMap<>();
// ex.getBindingResult().getAllErrors().forEach((error) -> {
// String fieldName = ((FieldError) error).getField();
// String errorMessage = error.getDefaultMessage();
// errors.put(fieldName, errorMessage);
// });
// log.info("发生异常: ",ex);
//// return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(errors);
// return ResultUtils.error(ErrorCode.OPERATION_ERROR,"内部异常: "+ex);
// }
// @ExceptionHandler(Exception.class)
// public BaseResponse handleException(Exception ex) {
// return ResultUtils.error(ErrorCode.UNKNOW_ERROR, ex.getMessage());
// public BaseResponse<String> handleBusinessException(BusinessException ex) {
// ErrorResponse errorResponse = new ErrorResponse(ex.getCode(), ex.getMessage());
// log.info("发生异常: ",ex);
// return ResultUtils.error(ErrorCode.OPERATION_ERROR,"内部异常:"+ex);
// }
// 其他异常处理器可以按需添加
public static class ErrorResponse {
private int code;
private String message;
public ErrorResponse(int code, String message) {
this.code = code;
this.message = message;
}
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}
@ExceptionHandler(Exception.class)
public BaseResponse handleException(Exception ex) {
return ResultUtils.error(ErrorCode.UNKNOW_ERROR, ex.getMessage());
}
public String getMessage() {
return message;
}
// 其他异常处理器可以按需添加
public void setMessage(String message) {
this.message = message;
}
}
// public static class ErrorResponse {
// private int code;
//
// private T data;
// private String message;
//
// public ErrorResponse(int code, String message) {
// this.code = code;
// this.message = message;
// this.data = null;
// }
//
// public int getCode() {
// return code;
// }
//
// public void setCode(int code) {
// this.code = code;
// }
//
// public String getMessage() {
// return message;
// }
//
// public void setMessage(String message) {
// this.message = message;
// }
// }
}

@ -2,7 +2,7 @@ package com.teaching.backend.mapper.courses;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.teaching.backend.model.entity.courses.CourseObjectives;
import com.teaching.backend.model.vo.courses.CourseObjectivesTreeVO;
import java.util.ArrayList;
import java.util.List;
@ -17,7 +17,4 @@ import java.util.List;
*/
public interface CourseObjectivesMapper extends BaseMapper<CourseObjectives> {
List<CourseObjectivesTreeVO> selectTreeNodes(String courseObjectivesId);
void insertBatch(ArrayList<CourseObjectives> courseObjectivesFList);
}

@ -15,5 +15,5 @@ import java.util.List;
*/
public interface ObjectiveContentKnowMapper extends BaseMapper<ObjectiveContentKnow> {
void insertBatchSomeColumn(List<ObjectiveContentKnow> objectiveContentKnowList);
// void insertBatchSomeColumn(List<ObjectiveContentKnow> objectiveContentKnowList);
}

@ -52,6 +52,13 @@ public interface KnowRepository extends Neo4jRepository<Know, Long> {
@Query("MATCH (p:Know) where ID(p) = $id RETURN count(p);")
int queryNode(Long id);
@Query("MATCH (p:Know) where p.knowId = $knowId RETURN ID(p);")
Long queryNodeByKnowId(Long knowId);
@Query("MATCH (p:Know) where p.courseId = $courseId RETURN ID(p);")
Long queryNodeByCourseId(String courseId);
@Query("MATCH (p:Know) where ID(p) = $id RETURN p;")
Know queryNodeT(Long id);

@ -0,0 +1,21 @@
package com.teaching.backend.mapper.resource;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.teaching.backend.model.entity.resource.ResourceMysql;
import com.teaching.backend.model.entity.resource.Resources;
import org.springframework.transaction.annotation.Transactional;
/**
* <p>
* Mapper 接口
* </p>
*
* @author author
* @since 2024-09-02
*/
public interface ResourceMapper extends BaseMapper<ResourceMysql> {
}

@ -3,6 +3,7 @@ package com.teaching.backend.mapper.resource;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.teaching.backend.model.entity.resource.ResourceMysql;
import com.teaching.backend.model.entity.resource.ResourceRelationship;
/**
* <p>
@ -12,6 +13,7 @@ import com.teaching.backend.model.entity.resource.ResourceMysql;
* @author author
* @since 2024-09-02
*/
public interface ResourceMysqlMapper extends BaseMapper<ResourceMysql> {
public interface ResourceRelationshipMapper extends BaseMapper<ResourceRelationship> {
}

@ -7,33 +7,47 @@ package com.teaching.backend.mapper.resource;
*/
import com.sun.org.apache.xpath.internal.operations.Bool;
import com.teaching.backend.model.entity.resource.ResourceMysql;
import com.teaching.backend.model.entity.resource.Resources;
import org.springframework.data.neo4j.repository.Neo4jRepository;
import org.springframework.data.neo4j.repository.query.Query;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import java.util.Set;
@Transactional(value="transactionManager")
public interface ResourcesRepository extends Neo4jRepository<Resources, Long> {
//查询资源
@Query("MATCH (b:Resources) WHERE ID(b) = $resourceIds RETURN b")
Resources queryResourcesByIds(Long resourceIds);
@Query("MATCH (b:Resources) WHERE b.resourceId = $resourceId RETURN b")
Resources queryResourcesByResourceId(Long resourceId);
//查询资源 - 知识点
@Query("MATCH (p:Know)<-[r:resources]-(c:Resources) WHERE ID(p) = $id AND ID(c) = $resourcesId return count(r)")
int queryExisitRel(Long id, Long resourcesId);
//添加知识点与资源关系
@Query("MATCH (p:Know), (c:Resources) WHERE ID(p) = $id AND ID(c) = $resourcesId CREATE (c)-[r:resources]->(p) return count(r)")
@Query("MATCH (p:Know), (c:Resources) WHERE ID(p) = $id AND ID(c) = $resourceId CREATE (c)-[r:resources]->(p) return count(r)")
int addResourcesAndKnowById(Long id, Long resourcesId);
//添加知识点与资源关系根据resourceId
@Query("MATCH (p:Know), (c:Resources) WHERE ID(p) = $id AND c.resourceId = $resourceId CREATE (c)-[r:resources]->(p) return count(r)")
int addResourcesAndKnowById2(Long id, Long resourceId);
//删除资源节点
@Query("MATCH(n:Resources) where n.name = $name DETACH DELETE n RETURN COUNT(n) >0;")
Boolean deleteByobjectName(String name);
//删除资源节点
@Query("MATCH(n:Resources) where n.resourceId = $resourceId DETACH DELETE n RETURN COUNT(n) >0;")
Boolean deleteByResourceId(Long resourceId);
//添加课程与资源关系
@Query("MATCH (p:Know), (c:Resources) WHERE p.courseId = $courseId AND ID(c) in $resourcesIds CREATE (c)-[r:resources]->(p) return count(r)")
int addResourcesAndKnowByCourseId(String courseId, List<Long> resourcesIds);
@ -69,6 +83,16 @@ public interface ResourcesRepository extends Neo4jRepository<Resources, Long> {
Set<Resources> queryResourcesByKnowId(Long KnowId);
// @Query("CREATE (n:Resources {"
// +"name: $rs.getName(),"
// +"resourceId: $rs.getId()+,"
// +"url: $rs.getUrl(),"
// +"status: $rs.getStatus(),"
// +"type: $rs.getType()+,"
// +"tags: $rs.getTags(),"
// +"description: $rs.getDescription()}) return ID(n)")
// int recoverdata(ResourceMysql rs);
//

@ -24,11 +24,6 @@ public class KnowCourseCreateRequest implements Serializable {
private String info;
private double hour;
}

@ -0,0 +1,26 @@
package com.teaching.backend.model.dto.Knowtmp;
import lombok.Data;
import org.springframework.web.bind.annotation.RequestParam;
import java.io.Serializable;
import java.util.List;
/**
* <p>
*
* </p>
*
* @author author
* @since 2024-05-31
*/
@Data
public class KnowObjective implements Serializable {
private List<String> objectiveIds;
private Long knowId;
}

@ -21,7 +21,6 @@ public class KnowtempAdd implements Serializable {
private Long chapterid;
private Integer ordernum;
private double hour;

@ -23,7 +23,6 @@ public class KnowtempUpdate implements Serializable {
private Long chapterid;
private Integer ordernum;
private double hour;

@ -0,0 +1,54 @@
package com.teaching.backend.model.dto.chapter;
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.knowtmp.Knowtmp;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import javax.validation.constraints.Digits;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.List;
/**
* <p>
*
* </p>
*
* @author author
* @since 2024-05-31
*/
@Data
public class ChapterAndNodeTreeVO implements Serializable {
@ApiModelProperty(value = "主键")
private Long id;
@ApiModelProperty(value = "序号")
private Double orderNum;
@ApiModelProperty(value = "名称")
private String name;
@ApiModelProperty(value = "简介")
private String content;
@ApiModelProperty(value = "父级节点")
private Long pid;
@ApiModelProperty(value = "总学时")
@Digits(integer = 10, fraction = 1, message = "总学时只能保留一位小数")
private double totalClassHours;
@ApiModelProperty(value = "子章节")
private List<ChapterAndNodeTreeVO> children; // 用于存储子章节
}

@ -0,0 +1,86 @@
package com.teaching.backend.model.dto.chapter;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.teaching.backend.model.entity.knowtmp.Knowtmp;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.Digits;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.List;
/**
* <p>
*
* </p>
*
* @author author
* @since 2024-05-31
*/
@Data
public class ChapterChildreenVO implements Serializable {
@ApiModelProperty(value = "主键")
@TableId(value = "id", type = IdType.AUTO)
private Long id;
@ApiModelProperty(value = "创建人")
private String createBy;
@ApiModelProperty(value = "创建日期")
private LocalDateTime createTime;
@ApiModelProperty(value = "更新人")
private String updateBy;
@ApiModelProperty(value = "更新日期")
private LocalDateTime updateTime;
@ApiModelProperty(value = "所属部门")
private String sysOrgCode;
@ApiModelProperty(value = "序号")
private Double orderNum;
@ApiModelProperty(value = "名称")
private String name;
@ApiModelProperty(value = "简介")
private String content;
@ApiModelProperty(value = "父级节点")
private Long pid;
@ApiModelProperty(value = "课程")
private String courseId;
@ApiModelProperty(value = "课程目标")
private String courseObjectivesId;
@ApiModelProperty(value = "总学时")
@Digits(integer = 10, fraction = 1, message = "总学时只能保留一位小数")
private double totalClassHours;
@ApiModelProperty(value = "要求")
private String requirement;
@ApiModelProperty(value = "线上学时")
private String onlineClassHours;
@ApiModelProperty(value = "周次")
private String zc;
@ApiModelProperty(value = "内部序号显示")
private String numshow;
@ApiModelProperty(value = "子章节")
@TableField(exist = false)
private List<Knowtmp> children; // 用于存储子章节
}

@ -32,23 +32,23 @@ public class ChapterDTO implements Serializable {
@ApiModelProperty(value = "总学时")
private double totalClassHours;
@ApiModelProperty(value = "创建人")
private String createBy;
// @ApiModelProperty(value = "创建人")
// private String createBy;
//
// @ApiModelProperty(value = "创建日期")
// @JsonFormat(pattern = "yyyy/M/d HH:mm:ss")
// private LocalDateTime createTime;
@ApiModelProperty(value = "创建日期")
@JsonFormat(pattern = "yyyy/M/d HH:mm:ss")
private LocalDateTime createTime;
// @ApiModelProperty(value = "更新人")
// private String updateBy;
@ApiModelProperty(value = "更新人")
private String updateBy;
// @ApiModelProperty(value = "更新日期")
// @JsonFormat(pattern = "yyyy/M/d HH-mm-ss")
// private LocalDateTime updateTime;
@ApiModelProperty(value = "更新日期")
@JsonFormat(pattern = "yyyy/M/d HH-mm-ss")
private LocalDateTime updateTime;
@ApiModelProperty(value = "所属部门")
private String sysOrgCode;
// @ApiModelProperty(value = "所属部门")
// private String sysOrgCode;
@ApiModelProperty(value = "序号")
private Double orderNum;
@ -65,30 +65,30 @@ public class ChapterDTO implements Serializable {
@ApiModelProperty(value = "课程id")
private String courseId;
@ApiModelProperty(value = "课程目标")
private String courseObjectivesId;
// @ApiModelProperty(value = "课程目标")
// private String courseObjectivesId;
@ApiModelProperty(value = "要求")
private String requirement;
@ApiModelProperty(value = "线上学时")
private String onlineClassHours;
// @ApiModelProperty(value = "要求")
// private String requirement;
@ApiModelProperty(value = "周次")
private String zc;
// @ApiModelProperty(value = "线上学时")
// private String onlineClassHours;
// @ApiModelProperty(value = "周次")
// private String zc;
@ApiModelProperty(value = "内部序号显示")
private String numshow;
@ApiModelProperty(value = "excel上级序号")
@TableField(exist = false)
private Long ParentExcelId;
// @ApiModelProperty(value = "内部序号显示")
// private String numshow;
@ApiModelProperty(value = "excel序号")
@TableField(exist = false)
private Long ExcelId;
// @ApiModelProperty(value = "excel上级序号")
// @TableField(exist = false)
// private Long ParentExcelId;
//
// @ApiModelProperty(value = "excel序号")
// @TableField(exist = false)
// private Long ExcelId;
}

@ -1,5 +1,7 @@
package com.teaching.backend.model.dto.courses;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.teaching.backend.model.entity.courses.ObjectiveContents;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
@ -11,31 +13,20 @@ import java.util.List;
@Data
@ApiModel(description = "分项目标参数实体")
public class CourseObjectivesDTO implements Serializable {
/**
* 内部编号
*/
@ApiModelProperty("id")
private String id;
/**
* 分项目标名称
*/
@ApiModelProperty(value = "分项目标名称",required = true)
private String name;
/**
* 分项目标类型 思政 知识素质价值
*/
@ApiModelProperty(value = "分项目标类型",required = true)
private Integer type;
/**
* 父节点
*/
@ApiModelProperty(value = "父节点pid",required = true)
private String pid;
@ApiModelProperty(value = "课程id")
private String courseId;
// 1 思政目标/2 知识目标/3 素质目标/4 价值目标
@ApiModelProperty(value = "目标类型 1 /2 /3 /4")
private Integer type;
@ApiModelProperty(value = "目标名称")
private String name;
@ApiModelProperty(value = "目标内容")
private String content;
@ApiModelProperty(value = "总目标id")
private String pid;
}

@ -0,0 +1,31 @@
package com.teaching.backend.model.dto.courses;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
@Data
@ApiModel(description = "分项目标参数实体")
public class CourseObjectivesUpdateDTO implements Serializable {
@ApiModelProperty(value = "目标id")
private String Id;
@ApiModelProperty(value = "课程id")
private String courseId;
@ApiModelProperty(value = "目标类型")
private Integer type;
@ApiModelProperty(value = "目标名称")
private String name;
@ApiModelProperty(value = "总目标id")
private String pid;
@ApiModelProperty(value = "目标内容")
private String content;
}

@ -10,21 +10,13 @@ import java.time.LocalDateTime;
@Data
@ApiModel(description = "教师创建课程参数实体")
public class CoursesDTO {
/**
* 内部编号
*/
@ApiModelProperty("id")
private String id;
/**
* 创建人 教师id
*/
@ApiModelProperty(value = "负责教师",required = true)
private String teacher;
/**
* 创建日期
*/
@ApiModelProperty("创建日期")
private LocalDateTime createTime;
/**
* 课程封面
*/

@ -0,0 +1,103 @@
package com.teaching.backend.model.dto.courses;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.math.BigDecimal;
import java.time.LocalDateTime;
@Data
@ApiModel(description = "教师创建课程参数实体")
public class CoursesUpdateDTO {
/**
* 内部编号
*/
@ApiModelProperty("id")
private String id;
/**
* 创建人 教师id
*/
@ApiModelProperty(value = "负责教师",required = true)
private String teacher;
/**
* 创建日期
*/
@ApiModelProperty("创建日期")
private LocalDateTime createTime;
/**
* 课程封面
*/
@ApiModelProperty(value = "图片",required = true)
private String img;
/**
* 课程类别 专业教育 通识教育
*/
@ApiModelProperty(value = "课程类别:专业教育1 通识教育2",required = true)
private String category;
/**
* 课程性质 必修选修任修
*/
@ApiModelProperty(value = "课程性质:必修1 选修2 任修3",required = true)
private String nature;
/**
* 课程名称
*/
@ApiModelProperty(value = "课程名称",required = true)
private String name;
/**
* 课程编码
*/
@ApiModelProperty(value = "课程编码",required = true)
private String code;
/**
* 课程学分
*/
@ApiModelProperty(value = "课程学分",required = true)
private BigDecimal credit;
/**
* 课程学时
*/
@ApiModelProperty(value = "课程学时",required = true)
private Integer classhours;
/**
* 考核类型 考试 考查
*/
@ApiModelProperty(value = "考核类型:考试1 考查2",required = true)
private String assessmenttype;
/**
* 考核方式 开卷 闭卷 其他
*/
@ApiModelProperty(value = "考核方式:开卷1 闭卷2 其他3",required = true)
private String assessmentway;
/**
* 教学方法
*/
@ApiModelProperty("教学方法")
private String teachermethod;
/**
* 教学方式
*/
@ApiModelProperty("教学方式")
private String teacherway;
/**
* 课程简介
*/
@ApiModelProperty("课程简介")
private String description;
}

@ -0,0 +1,31 @@
package com.teaching.backend.model.dto.resource;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @Author:youhang
* @Date:2024-10-21-15:53
* @Description:
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ResourceRelationshipDto {
@ApiModelProperty(value = "知识点Id")
private Long knowId;
@ApiModelProperty(value = "资源Id")
private Long resourceId;
@ApiModelProperty(value = "课程Id")
private String courseId;
}

@ -1,29 +0,0 @@
package com.teaching.backend.model.entity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;
/**
* ClassName: ResourcesRelationship
* Package: com.teaching.backend.model.entity
* Description:
*
* @Author 姜钧瀚
* @Create 2024/6/12 21:03
* @Version 1.0
*/
@Data
@ToString
@NoArgsConstructor
@AllArgsConstructor
public class ResourceRelationship {
private String Id;
private String courseid;
private String chapterid;
private String knowid;
private String resourceid;
}

@ -58,6 +58,9 @@ public class CmsEssay implements Serializable {
@ApiModelProperty(value = "发布文章的用户id")
private Integer userId;
// @TableField(exist = false)
private String username;
@ApiModelProperty(value = "文章文件")
private String file;

@ -1,12 +1,15 @@
package com.teaching.backend.model.entity.courses;
import cn.hutool.core.date.DateTime;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import java.io.Serializable;
@ -14,7 +17,7 @@ import java.time.LocalDateTime;
/**
* <p>
*
*
* </p>
*
* @author zjh
@ -25,6 +28,8 @@ import java.time.LocalDateTime;
@Accessors(chain = true)
@TableName("course_objectives")
@ApiModel(value="CourseObjectives对象", description="")
@AllArgsConstructor
@NoArgsConstructor
public class CourseObjectives implements Serializable {
private static final long serialVersionUID = 1L;
@ -33,25 +38,26 @@ public class CourseObjectives implements Serializable {
@TableId(value = "id", type = IdType.ASSIGN_UUID)
private String id;
@ApiModelProperty(value = "父级节点")
private String pid;
@ApiModelProperty(value = "是否有子节点")
private Integer hasChild;
@ApiModelProperty(value = "课程id")
private String courseId;
@ApiModelProperty(value = "目标类型")
private Integer type;
@ApiModelProperty(value = "课程id")
private String courseId;
@ApiModelProperty(value = "目标名称")
private String name;
@ApiModelProperty(value = "目标内容")
private String content;
@ApiModelProperty(value = "总目标id")
private String pid;
@ApiModelProperty(value = "毕业要求id")
private String requireid;
@ApiModelProperty(value = "创建时间")
private LocalDateTime createTime;
@ApiModelProperty(value = "毕业要求")
private String temp;
}

@ -0,0 +1,52 @@
package com.teaching.backend.model.entity.courses;
import java.util.Scanner;
/**
* @Author:youhang
* @Date:2024-10-08-19:10
* @Description:
*/
public class Testrr {
public static void main(String[] args) {
System.out.println("jj");
Scanner sc = new Scanner(System.in);
while (sc.hasNext()){
String s = sc.nextLine();
String t = reverse2(s);
System.out.println(t);
}
}
// toCharArray
public static String reverse2(String str) {
char[] chars = str.toCharArray();
int[] arr = new int[100];
String reverse = "";
int k = 0;
for(int i = 0; i < chars.length; i++){
if(chars[i] == 'a' && chars[i+1] == 'l' && chars[i+2] == 'l'){
arr[k++] = i+2;
}
}
int f = 1;
for (int i = chars.length - 1; i >= 0; i--) {
for (int j = 0; j < k; j++) {
if(i == arr[j]){
reverse += Character.toLowerCase(chars[i-2]) ;
reverse += Character.toLowerCase(chars[i-1]);
reverse += Character.toLowerCase(chars[i]);
f = 0;
i--;
i--;
break;
}
}
if(f == 1){
reverse += chars[i];
}
f = 1;
}
return reverse;
}
}

@ -31,12 +31,6 @@ public class SeCourseFavour implements Serializable {
*/
private String userId;
/**
* 创建用户 id
*/
private DateTime createtime;
@TableField(exist = false)
private static final long serialVersionUID = 1L;

@ -1,4 +1,4 @@
package com.teaching.backend.controller.Know;
package com.teaching.backend.model.entity.know;
import lombok.AllArgsConstructor;
import lombok.Data;
@ -19,3 +19,5 @@ public class Edge {
private Integer sta; // 1 课程-章节 2 章节 - 章节 3 章节 - 知识点 4 点 - 点
}

@ -7,6 +7,7 @@ import org.springframework.data.neo4j.core.schema.Node;
import org.springframework.data.neo4j.core.schema.Property;
import java.io.Serializable;
import java.time.LocalDateTime;
@Node
@Data
@ -37,5 +38,9 @@ public class Know implements Serializable {
@Property
private double hour;
@Property
private LocalDateTime createTime;
}

@ -44,5 +44,7 @@ public class KnowChapter implements Serializable {
private double hour;
}

@ -35,6 +35,7 @@ public class KnowCourse implements Serializable {
* 信息
*/
private String info;
private double hour;

@ -1,4 +1,4 @@
package com.teaching.backend.controller.Know;
package com.teaching.backend.model.entity.know;
import lombok.AllArgsConstructor;
import lombok.Data;

@ -4,9 +4,14 @@ 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.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;
/**
* <p>
@ -18,6 +23,8 @@ import java.io.Serializable;
*/
@Data
@TableName(value = "knowtmp")
@AllArgsConstructor
@NoArgsConstructor
public class Knowtmp implements Serializable {
@TableField(exist = false)
@ -30,10 +37,13 @@ public class Knowtmp implements Serializable {
private String info;
private Integer ordernum;
private double ordernum;
private Long chapterid;
private double hour;
@ApiModelProperty(value = "创建日期")
private LocalDateTime createTime;
}

@ -1,13 +1,14 @@
package com.teaching.backend.model.entity.resource;
import com.baomidou.mybatisplus.annotation.TableField;
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 io.swagger.models.auth.In;
import lombok.*;
import lombok.experimental.Accessors;
/**
@ -19,26 +20,18 @@ import lombok.experimental.Accessors;
* @since 2024-09-02
*/
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName("resource")
@ApiModel(value="Resource对象", description="")
@AllArgsConstructor
@NoArgsConstructor
public class ResourceMysql implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "主键")
@TableId(value = "id", type = IdType.ASSIGN_ID)
private String id;
@TableId(value = "id", type = IdType.AUTO)
private Long id;
@ApiModelProperty(value = "课程id")
private String courseId;
@ApiModelProperty(value = "章节id")
private String chapterId;
@ApiModelProperty(value = "知识点id")
private String knowledgeId;
@ApiModelProperty(value = "资源名称")
private String name;
@ -47,7 +40,7 @@ public class ResourceMysql implements Serializable {
private Integer type;
@ApiModelProperty(value = "资源路径")
private String path;
private String url;
@ApiModelProperty(value = "资源状态")
private Integer status;
@ -58,8 +51,4 @@ public class ResourceMysql implements Serializable {
@ApiModelProperty(value = "简介")
private String description;
@ApiModelProperty(value = "封面")
private String img;
}

@ -0,0 +1,37 @@
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 io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @Author:youhang
* @Date:2024-10-21-15:53
* @Description:
*/
@Data
@TableName("resource_relationship")
@ApiModel(value="resource_relationship对象", description="")
@AllArgsConstructor
@NoArgsConstructor
public class ResourceRelationship {
@ApiModelProperty(value = "主键")
@TableId(value = "id", type = IdType.AUTO)
private Long id;
@ApiModelProperty(value = "知识点Id")
private Long knowId;
@ApiModelProperty(value = "资源Id")
private Long resourceId;
@ApiModelProperty(value = "课程Id")
private String courseId;
}

@ -1,5 +1,6 @@
package com.teaching.backend.model.entity.resource;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.data.neo4j.core.schema.GeneratedValue;
import org.springframework.data.neo4j.core.schema.Id;
@ -21,14 +22,22 @@ public class Resources {
@Property
private String name;
@Property
private Integer status;
@Property
private Integer type;
@Property
private Long resourceId;
@Property
private String url;
@Property
private String tags;
@Property
private String description;
}

@ -1,26 +0,0 @@
package com.teaching.backend.model.vo.courses;
import com.teaching.backend.model.entity.courses.CourseObjectives;
import com.teaching.backend.model.entity.courses.ObjectiveContents;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.List;
@Data
@ApiModel(description = "课程目标参数实体")
public class CourseObjectivesTreeVO extends CourseObjectives implements Serializable {
@ApiModelProperty(value = "目标名称")
private String name;
@ApiModelProperty(value = "目标内容列表")
private List<ObjectiveContents> contents;
@ApiModelProperty(value = "课程目标")
private List<CourseObjectivesTreeVO> courseObjectivesTrees;
}

@ -1,4 +1,4 @@
package com.teaching.backend.controller.Know;
package com.teaching.backend.model.vo.knowGraph;
import lombok.Data;

@ -1,4 +1,4 @@
package com.teaching.backend.controller.Know;
package com.teaching.backend.model.vo.knowGraph;
import lombok.Data;

@ -1,8 +1,6 @@
package com.teaching.backend.controller.Know;
package com.teaching.backend.model.vo.knowGraph;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import com.teaching.backend.model.entity.know.KnowJson;
import java.io.Serializable;
import java.util.List;

@ -1,4 +1,4 @@
package com.teaching.backend.controller.Know;
package com.teaching.backend.model.vo.knowGraph;
import lombok.AllArgsConstructor;
import lombok.Data;

@ -1,25 +0,0 @@
package com.teaching.backend.model.vo.knowGraph;
import lombok.Data;
import java.io.Serializable;
@Data
public class KnowVO1 implements Serializable {
/**
* id
*/
private Long id;
/**
* 知识点名称
*/
private String label;
}

@ -1,4 +1,4 @@
package com.teaching.backend.controller.Know;
package com.teaching.backend.model.vo.knowGraph;
import lombok.AllArgsConstructor;
import lombok.Data;

@ -1,17 +1,12 @@
package com.teaching.backend.service.Know;
import com.teaching.backend.common.BaseResponse;
import com.teaching.backend.controller.Know.KnowPathVO;
import com.teaching.backend.model.vo.knowGraph.KnowPathVO;
import com.teaching.backend.model.dto.Know.*;
import com.teaching.backend.model.entity.know.*;
import com.teaching.backend.model.entity.knowtmp.Knowtmp;
import com.teaching.backend.model.entity.resource.Resources;
import com.teaching.backend.model.vo.knowGraph.KnowVO;
import com.teaching.backend.model.vo.knowGraph.KnowVO1;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.List;
import java.util.Set;
/**
* @Author:youhang

@ -3,6 +3,7 @@ package com.teaching.backend.service.chapter;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.teaching.backend.model.dto.chapter.ChapterAndNodeTreeVO;
import com.teaching.backend.model.dto.chapter.ChapterDTO;
import com.teaching.backend.model.dto.chapter.ChapterExcelDTO;
import com.teaching.backend.model.entity.chapter.Chapter;
@ -33,6 +34,8 @@ public interface IChapterService extends IService<Chapter> {
List<Chapter> getChapterTree(String courseId);
List<ChapterAndNodeTreeVO> getChapterTree2(String courseId);
BigDecimal saveChapter(ChapterDTO chapterDTO);

@ -28,4 +28,6 @@ public interface ICmsEssayService extends IService<CmsEssay> {
BaseResponse<String> editStatus(CmsEssay cmsEssay);
BaseResponse<CmsEssay> queryEssayById(Integer essayId);
BaseResponse<String> views(Integer id);
}

@ -1,10 +1,11 @@
package com.teaching.backend.service.courses;
import com.baomidou.mybatisplus.extension.service.IService;
import com.teaching.backend.common.BaseResponse;
import com.teaching.backend.model.dto.courses.CourseObjectivesDTO;
import com.teaching.backend.model.entity.courses.CourseObjectives;
import com.teaching.backend.model.vo.courses.CourseObjectivesTreeVO;
import com.teaching.backend.model.vo.courses.CourseObjectivesVO;
import io.swagger.models.auth.In;
import java.util.List;
@ -32,12 +33,15 @@ public interface ICourseObjectivesService extends IService<CourseObjectives> {
*/
String deleteObjectives(String id);
/**
* 查询课程目标以及相关内容
* @param id
* @return
*/
List<CourseObjectivesTreeVO> queryCourseObjectivesTree(String id);
CourseObjectives selectObjectives(String id);
List<CourseObjectives> selectObjectivesList(String id);
BaseResponse<Long> knowcount(String id);
BaseResponse<Double> knowtime(String id);
BaseResponse<Double> knowtimepercent(String courseId,String id);
List<CourseObjectivesVO> queryCourseObjectivesForAdd(String courseId);
}

@ -3,6 +3,7 @@ package com.teaching.backend.service.courses;
import com.baomidou.mybatisplus.extension.service.IService;
import com.teaching.backend.model.dto.courses.CoursesDTO;
import com.teaching.backend.model.dto.courses.CoursesUpdateDTO;
import com.teaching.backend.model.dto.courses.PageDTO;
import com.teaching.backend.model.dto.umsAdmin.UmsStudentPageQueryDTO;
import com.teaching.backend.model.entity.courses.Courses;
@ -43,9 +44,9 @@ public interface ICoursesService extends IService<Courses> {
List<CoursesVO> getPagePageSize(int page, int pageSize);
void updateCourse(CoursesDTO coursesDTO);
void down(HttpServletResponse response, String id) throws Exception;
void updateCourse(CoursesUpdateDTO coursesUpdateDTO);
//
// void down(HttpServletResponse response, String id) throws Exception;
CoursesVO getByIdCourseVo(String courseid);

@ -1,21 +0,0 @@
package com.teaching.backend.service.courses;
import com.baomidou.mybatisplus.extension.service.IService;
import com.teaching.backend.model.dto.courses.ObjectiveContentKnowDTO;
import com.teaching.backend.model.entity.courses.ObjectiveContentKnow;
import com.teaching.backend.model.vo.courses.ObjectiveContentKnowVO;
/**
* <p>
* 服务类
* </p>
*
* @author zjh
* @since 2024-06-13
*/
public interface IObjectiveContentKnowService extends IService<ObjectiveContentKnow> {
String saveKnowsWithObjectiveContent(ObjectiveContentKnowDTO objectiveContentKnowDTO);
ObjectiveContentKnowVO getCountData(String objectiveId);
}

@ -13,6 +13,7 @@ import com.teaching.backend.mapper.Knowtemp.KnowtmpMapper;
import com.teaching.backend.mapper.chapter.ChapterMapper;
import com.teaching.backend.mapper.chapter.TemporaryChapterMapper;
import com.teaching.backend.mapper.courses.CoursesMapper;
import com.teaching.backend.model.dto.chapter.ChapterAndNodeTreeVO;
import com.teaching.backend.model.dto.chapter.ChapterDTO;
import com.teaching.backend.model.dto.chapter.ChapterExcelDTO;
@ -215,6 +216,78 @@ public class ChapterServiceImpl extends ServiceImpl<ChapterMapper, Chapter> impl
return roots;
}
@Override
public List<ChapterAndNodeTreeVO> getChapterTree2(String courseId) {
List<Chapter> chapters = baseMapper.selectSectionsByCourseId(courseId);
List<ChapterAndNodeTreeVO> chapterAndNodeTreeVOS = new ArrayList<>();
Map<Long, ChapterAndNodeTreeVO> chapterAndNodeTreeVOMap = new HashMap<>();
ChapterAndNodeTreeVO chapterAndNodeTreeVO;
for (Chapter chapter : chapters) {
chapterAndNodeTreeVO = new ChapterAndNodeTreeVO();
BeanUtil.copyProperties(chapter,chapterAndNodeTreeVO);
chapter.setChildren(new ArrayList<>());
chapterAndNodeTreeVO.setChildren(new ArrayList<>());
chapterAndNodeTreeVOS.add(chapterAndNodeTreeVO);
chapterAndNodeTreeVOMap.put(chapterAndNodeTreeVO.getId(), chapterAndNodeTreeVO);
}
for (ChapterAndNodeTreeVO ch : chapterAndNodeTreeVOS) {
chapterAndNodeTreeVOMap.put(ch.getId(), ch);
}
//将子章节添加到父章节
List<Long> ChapterIds = new ArrayList<>();
for (ChapterAndNodeTreeVO ch : chapterAndNodeTreeVOS) {
Long parentId = ch.getPid();
if (parentId != 0) {
//代表是节
ChapterIds.add(ch.getId());
ChapterAndNodeTreeVO parentchapterAndNodeTree = chapterAndNodeTreeVOMap.get(parentId);
if (parentchapterAndNodeTree != null) {
parentchapterAndNodeTree.getChildren().add(ch);
}
}
}
//根据Ids查询知识点
QueryWrapper<Knowtmp> queryWrapper = new QueryWrapper<>();
queryWrapper.in("chapterId", ChapterIds);
List<Knowtmp> knows = knowtmpMapper.selectList(queryWrapper);
//将子章节添加到父章节
for (Knowtmp knowtmp : knows) {
Long id = knowtmp.getId();
String name = knowtmp.getName();
String info = knowtmp.getInfo();
double ordernum = knowtmp.getOrdernum();
double hour = knowtmp.getHour();
Long chapterid = knowtmp.getChapterid();
ChapterAndNodeTreeVO chapterAndNodeTreeVO1 = new ChapterAndNodeTreeVO();
chapterAndNodeTreeVO1.setId(id);
chapterAndNodeTreeVO1.setOrderNum(ordernum);
chapterAndNodeTreeVO1.setName(name);
chapterAndNodeTreeVO1.setContent(info);
chapterAndNodeTreeVO1.setTotalClassHours(hour);
//在Map中查询 节ID
ChapterAndNodeTreeVO parentchapterAndNodeTree = chapterAndNodeTreeVOMap.get(chapterid);
if (parentchapterAndNodeTree != null) {
parentchapterAndNodeTree.getChildren().add(chapterAndNodeTreeVO1);
}
}
chapterAndNodeTreeVOS = chapterAndNodeTreeVOS.stream()
.filter(ch -> ch.getPid() == 0)
.sorted(Comparator.comparing(ChapterAndNodeTreeVO::getOrderNum))
.collect(Collectors.toList());
return chapterAndNodeTreeVOS;
}
private void loadKnowledgePointsRecursively(Chapter chapter) {
List<Chapter> sortedChildren = chapter.getChildren().stream()

@ -6,9 +6,12 @@ import com.teaching.backend.common.BaseResponse;
import com.teaching.backend.common.ResultUtils;
import com.teaching.backend.mapper.cms.CmsEssayMapper;
import com.teaching.backend.model.entity.cms.CmsEssay;
import com.teaching.backend.model.entity.umsAdmin.UmsUser;
import com.teaching.backend.service.cms.ICmsEssayService;
import com.teaching.backend.service.impl.umsAdmin.UmsUserServiceImpl;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.time.LocalDate;
import java.util.List;
@ -23,10 +26,18 @@ import java.util.List;
@Service
public class CmsEssayServiceImpl extends ServiceImpl<CmsEssayMapper, CmsEssay> implements ICmsEssayService {
@Resource
private UmsUserServiceImpl userService;
@Override
public BaseResponse<String> addEssay(CmsEssay cmsEssay) {
//设置文章发布时间
cmsEssay.setPublishTime(LocalDate.now());
//设置发布人姓名
String nickName = userService.getById(cmsEssay.getUserId()).getNickName();
cmsEssay.setUsername(nickName);
//将浏览次数设置为0
cmsEssay.setReadingNumber(0);
//如果数据库里没有文章,文章id设为2
Long count = query().count();
if (count == 0){
@ -48,6 +59,9 @@ public class CmsEssayServiceImpl extends ServiceImpl<CmsEssayMapper, CmsEssay> i
@Override
public BaseResponse<String> editEssay(CmsEssay cmsEssay) {
//设置发布人姓名
String nickName = userService.getById(cmsEssay.getUserId()).getNickName();
cmsEssay.setUsername(nickName);
//获取要修改的文章id
Integer id = cmsEssay.getId();
//判断文章id是否为1
@ -80,4 +94,10 @@ public class CmsEssayServiceImpl extends ServiceImpl<CmsEssayMapper, CmsEssay> i
public BaseResponse<CmsEssay> queryEssayById(Integer essayId) {
return ResultUtils.success(getById(essayId));
}
@Override
public BaseResponse<String> views(Integer id) {
boolean update = update().setSql("reading_number = reading_number + 1 where id = " + id).update();
return update ? ResultUtils.success("浏览次数加1") : ResultUtils.success("error!!!");
}
}

@ -1,20 +1,23 @@
package com.teaching.backend.service.impl.courses;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.date.DateTime;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.teaching.backend.common.BaseResponse;
import com.teaching.backend.common.ErrorCode;
import com.teaching.backend.common.ResultUtils;
import com.teaching.backend.exception.BusinessException;
import com.teaching.backend.mapper.courses.CourseObjectivesMapper;
import com.teaching.backend.mapper.courses.ObjectiveContentKnowMapper;
import com.teaching.backend.mapper.courses.ObjectiveContentsMapper;
import com.teaching.backend.mapper.courses.ObjectivesTypeMapper;
import com.teaching.backend.mapper.Knowtemp.KnowtmpMapper;
import com.teaching.backend.mapper.courses.*;
import com.teaching.backend.model.dto.courses.CourseObjectivesDTO;
import com.teaching.backend.model.entity.courses.CourseObjectives;
import com.teaching.backend.model.entity.courses.Courses;
import com.teaching.backend.model.entity.courses.ObjectiveContentKnow;
import com.teaching.backend.model.entity.courses.ObjectiveContents;
import com.teaching.backend.model.vo.courses.CourseObjectivesTreeVO;
import com.teaching.backend.model.vo.courses.CourseObjectivesVO;
import com.teaching.backend.model.entity.knowtmp.Knowtmp;
import com.teaching.backend.service.courses.ICourseObjectivesService;
import com.teaching.backend.utils.CourseCode;
import lombok.extern.slf4j.Slf4j;
@ -22,10 +25,9 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;
import static com.teaching.backend.utils.CourseCode.TOTAL_OBJECTIVE_HAS_NO_CHILD;
import static com.teaching.backend.utils.CourseCode.TOTAL_OBJECTIVE_TYPE;
@ -50,51 +52,42 @@ public class CourseObjectivesServiceImpl extends ServiceImpl<CourseObjectivesMap
ObjectiveContentsMapper objectiveContentsMapper;
@Autowired
ObjectiveContentKnowMapper objectiveContentKnowMapper;
@Autowired
ObjectivesTypeMapper objectivesTypeMapper;
@Autowired
private KnowtmpMapper knowtmpMapper;
@Autowired
private CoursesMapper coursesMapper;
@Override
@Transactional
public String addObjectives(CourseObjectivesDTO courseObjectivesDTO) {
CourseObjectives courseObjectivesNew = new CourseObjectives();
BeanUtil.copyProperties(courseObjectivesDTO,courseObjectivesNew);
String pid = courseObjectivesDTO.getPid();
Integer type = courseObjectivesDTO.getType();
//判断是否已经添加过该类型的目标(每个类型的目标只能有一个)
Long count = courseObjectivesMapper.selectCount(new LambdaQueryWrapper<CourseObjectives>()
.eq(CourseObjectives::getPid, pid)
.eq(CourseObjectives::getType, type));
if (count==CourseCode.OBJECTIVE_EXIT.getValue()){
throw new BusinessException(ErrorCode.CONTENT_EXISTS,"该类型的目标已存在,禁止重复添加!");
//判断课程存在
String courseId = courseObjectivesDTO.getCourseId();
if(courseId == null || "".equals(courseId)){
return "courseId 不能为空";
}
if (!type.equals(CourseCode.SI_ZHENG_TYPE.getValue())){
Long sz = SZ_EXIT(courseObjectivesDTO);
if (sz!=CourseCode.SI_ZHENG_EXIT.getValue()){
throw new BusinessException(ErrorCode.PARAMS_ILLEGAL,"请在添加完思政目标以后再添加此类型目标!");
}
Courses courses = coursesMapper.selectById(courseId);
if (courses == null){
return "课程不存在";
}
//插入新的课程目标
int insert = courseObjectivesMapper.insert(courseObjectivesNew);
//插入数据以后要把总体目标那边的haschild改成1
if (insert>0){
CourseObjectives courseObjectivesOld = courseObjectivesMapper.selectById(pid);
if (courseObjectivesOld.getHasChild() == TOTAL_OBJECTIVE_HAS_NO_CHILD.getValue()) {
courseObjectivesOld.setHasChild(1);
courseObjectivesMapper.updateById(courseObjectivesOld);
}
String name = courseObjectivesDTO.getName();
if(name == null || "".equals(name)){
return "name 不能为空";
}
return "添加成功";
CourseObjectives courseObjectivesNew = new CourseObjectives();
BeanUtil.copyProperties(courseObjectivesDTO,courseObjectivesNew);
courseObjectivesNew.setCreateTime(new DateTime().toLocalDateTime());
int ans = courseObjectivesMapper.insert(courseObjectivesNew);
if(ans>0){
return "添加成功";
}
return "添加失败";
}
private Long SZ_EXIT(CourseObjectivesDTO courseObjectivesDTO) {
Long count = courseObjectivesMapper.selectCount(new LambdaQueryWrapper<CourseObjectives>()
.eq(CourseObjectives::getPid, courseObjectivesDTO.getPid())
.eq(CourseObjectives::getType, CourseCode.SI_ZHENG_TYPE.getValue()));
return count;
}
/**
* 删除课程目标
@ -110,128 +103,97 @@ public class CourseObjectivesServiceImpl extends ServiceImpl<CourseObjectivesMap
CourseObjectives courseObjectives = courseObjectivesMapper.selectById(id);
if (courseObjectives == null) {
throw new BusinessException(ErrorCode.NOT_FOUND_ERROR);
return "删除失败";
}
Integer type = courseObjectives.getType();
if (type == TOTAL_OBJECTIVE_TYPE.getValue()){
throw new BusinessException(ErrorCode.OPERATION_ERROR,"课程总目标禁止删除!");
int ans =courseObjectivesMapper.deleteById(id);
if(ans>0){
return "删除成功";
}
//等到删完内容后判断还是上来就判断?
Long count = objectiveContentKnowMapper.selectCount(new LambdaQueryWrapper<ObjectiveContentKnow>()
.eq(ObjectiveContentKnow::getObjectiveContentId, id));
if(count > CourseCode.KNOWS_EXIT.getValue()){
throw new BusinessException(ErrorCode.KNOWS_EXIT);
}
String pid = courseObjectives.getPid();
if (type.equals(CourseCode.SI_ZHENG_TYPE.getValue())){
LambdaQueryWrapper<CourseObjectives> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(CourseObjectives::getPid, pid);
Long countSZ = courseObjectivesMapper.selectCount(queryWrapper);
if (countSZ.equals(CourseCode.SI_ZHENG_EXIT.getValue())){
Long countContentsSZ = getCount(id);
if (countContentsSZ == (CourseCode.CONTENT_EXIT.getValue()))
{
// 删除操作和更新父目标状态
deleteObjectiveAndUpdateParent(id, pid);
return "删除成功";
}
else {
throw new BusinessException(ErrorCode.CONTENT_EXISTS, "请删除该目标下的内容后,再删除该目标");
}
}
else
{
throw new BusinessException(ErrorCode.OPERATION_ERROR, "请删除其他类型的分目标后,再来删除思政目标");
}
}
else {
Long countContentsF = getCount(id);
if (countContentsF == CourseCode.CONTENT_EXIT.getValue()){
courseObjectivesMapper.deleteById(id);
return "删除成功";
}
else {
throw new BusinessException(ErrorCode.CONTENT_EXISTS, "请删除该目标下的内容后,再删除该目标");
}
}
}
return "删除失败";
private Long getCount(String id) {
LambdaQueryWrapper<ObjectiveContents> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(ObjectiveContents::getObjectiveId, id);
Long count = objectiveContentsMapper.selectCount(queryWrapper);
return count;
}
private void deleteObjectiveAndUpdateParent(String id, String pid) {
courseObjectivesMapper.deleteById(id);
CourseObjectives parentObjective = courseObjectivesMapper.selectById(pid);
parentObjective.setHasChild(TOTAL_OBJECTIVE_HAS_NO_CHILD.getValue());
courseObjectivesMapper.updateById(parentObjective);
@Override
public CourseObjectives selectObjectives(String id) {
CourseObjectives courseObjectives = courseObjectivesMapper.selectById(id);
// if (courseObjectives == null) {
// }
return courseObjectives;
}
@Override
public List<CourseObjectivesTreeVO> queryCourseObjectivesTree(String id) {
LambdaQueryWrapper<CourseObjectives> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(CourseObjectives::getCourseId, id);
public List<CourseObjectives> selectObjectivesList(String courseId) {
CourseObjectives courseObjectives = courseObjectivesMapper.selectOne(queryWrapper);
QueryWrapper<CourseObjectives>queryWrapper = new QueryWrapper<>();
queryWrapper.eq("course_id",courseId);
List<CourseObjectives> courseObjectives = courseObjectivesMapper.selectList(queryWrapper);
if (courseObjectives == null || courseObjectives.size()<=0) {
throw new BusinessException(ErrorCode.NOT_FOUND_ERROR);
}
return courseObjectives;
}
String courseObjectivesId = courseObjectives.getId();
List<CourseObjectivesTreeVO> objectives = courseObjectivesMapper.selectTreeNodes(courseObjectivesId);
@Override
public BaseResponse<Long> knowcount(String id) {
QueryWrapper<ObjectiveContentKnow>queryWrapper = new QueryWrapper<>();
queryWrapper.eq("objective_content_id",id);
Long ids = objectiveContentKnowMapper.selectCount(queryWrapper);
if (ids == null || ids <= 0) {
throw new BusinessException(ErrorCode.NOT_FOUND_ERROR);
}
return ResultUtils.success(ids);
}
Map<String, CourseObjectivesTreeVO> map = new HashMap<>();
for (CourseObjectivesTreeVO objective : objectives) {
objective.setName(objectivesTypeMapper.selectById(objective.getType()).getTypeName());
map.put(objective.getId(), objective);
@Override
public BaseResponse<Double> knowtime(String id){
//查询课程目标id是否存在
if(id == null || "".equals(id)){
return ResultUtils.error(ErrorCode.PARAMS_ERROR,"id 不能为空");
}
CourseObjectives courseObjectives = courseObjectivesMapper.selectById(id);
if(courseObjectives == null){
return ResultUtils.error(ErrorCode.PARAMS_ERROR,"课程目标不存在");
}
// 构建树结构
List<CourseObjectivesTreeVO> roots = new ArrayList<>();
for (CourseObjectivesTreeVO objective : objectives) {
if ("0".equals(objective.getPid())) {
roots.add(objective);
} else {
CourseObjectivesTreeVO parent = map.get(objective.getPid());
if (parent != null) {
if (parent.getCourseObjectivesTrees() == null) {
parent.setCourseObjectivesTrees(new ArrayList<>());
}
parent.getCourseObjectivesTrees().add(objective);
}
}
// 填充内容
List<ObjectiveContents> contents = fetchContentsForObjective(objective.getId());
objective.setContents(contents);
QueryWrapper<ObjectiveContentKnow>queryWrapper = new QueryWrapper<>();
queryWrapper.eq("objective_content_id",id);
List<ObjectiveContentKnow> list = objectiveContentKnowMapper.selectList(queryWrapper);
if (list == null || list.size() <= 0) {
return ResultUtils.error(ErrorCode.PARAMS_ERROR,"ids不存在");
}
List<Long> ids = list.stream().map(item -> item.getKnowId()).collect(Collectors.toList());
List<Knowtmp> knowtmps = knowtmpMapper.selectBatchIds(ids);
return roots;
DoubleSummaryStatistics summaryStatistics = knowtmps.stream().mapToDouble(item -> item.getHour()).summaryStatistics();
return ResultUtils.success(summaryStatistics.getSum());
}
@Override
public List<CourseObjectivesVO> queryCourseObjectivesForAdd(String courseId) {
CourseObjectives courseObjectives = courseObjectivesMapper.selectOne(new LambdaQueryWrapper<>(CourseObjectives.class)
.eq(CourseObjectives::getCourseId, courseId));
if (courseObjectives == null){
log.error("课程相关数据不存在:{}",courseId);
public BaseResponse<Double> knowtimepercent(String courseId,String id) {
Courses courses = coursesMapper.selectById(courseId);
double hourtotal = courses.getClasshours();
QueryWrapper<ObjectiveContentKnow>queryWrapper = new QueryWrapper<>();
queryWrapper.eq("objective_content_id",id);
List<ObjectiveContentKnow> list = objectiveContentKnowMapper.selectList(queryWrapper);
if (list == null || list.size() <= 0) {
throw new BusinessException(ErrorCode.NOT_FOUND_ERROR);
}
String courseTotalObjectiveId = courseObjectives.getId();
List<CourseObjectives> objectivesLists = courseObjectivesMapper.selectList(new LambdaQueryWrapper<>(CourseObjectives.class)
.eq(CourseObjectives::getPid, courseTotalObjectiveId)
.select(CourseObjectives::getId,CourseObjectives::getType)
.orderByAsc(CourseObjectives::getType)
);
List<CourseObjectivesVO> courseObjectivesVOS = new ArrayList<>(objectivesLists.size());
for (CourseObjectives objectives : objectivesLists) {
CourseObjectivesVO courseObjectivesVO = new CourseObjectivesVO();
courseObjectivesVO.setId(objectives.getId());
courseObjectivesVO.setName(objectivesTypeMapper.selectById(objectives.getType()).getTypeName());
courseObjectivesVOS.add(courseObjectivesVO);
}
return courseObjectivesVOS;
List<Long> ids = list.stream().map(item -> item.getKnowId()).collect(Collectors.toList());
List<Knowtmp> knowtmps = knowtmpMapper.selectBatchIds(ids);
DoubleSummaryStatistics summaryStatistics = knowtmps.stream().mapToDouble(item -> item.getHour()).summaryStatistics();
BigDecimal b1 = new BigDecimal(Double.toString(summaryStatistics.getSum()));
BigDecimal b2 = new BigDecimal(Double.toString(hourtotal));
int scale = 3;
double percent = b1.divide(b2, scale, BigDecimal.ROUND_HALF_UP).doubleValue(); //ROUND_HALF_UP:四舍五入
return ResultUtils.success(percent);
}
// 获取目标的内容列表
private List<ObjectiveContents> fetchContentsForObjective(String objectiveId) {
LambdaQueryWrapper<ObjectiveContents> queryWrapper = new LambdaQueryWrapper<>();

@ -3,12 +3,14 @@ package com.teaching.backend.service.impl.courses;
import cn.afterturn.easypoi.word.WordExportUtil;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.lang.UUID;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.teaching.backend.common.ErrorCode;
import com.teaching.backend.common.ResultUtils;
import com.teaching.backend.exception.BusinessException;
import com.teaching.backend.mapper.chapter.ChapterMapper;
import com.teaching.backend.mapper.courses.*;
@ -19,6 +21,7 @@ import com.teaching.backend.mapper.umsAdmin.UmsStudentMapper;
import com.teaching.backend.mapper.umsAdmin.UmsTeacherMapper;
import com.teaching.backend.mapper.umsAdmin.UmsUserMapper;
import com.teaching.backend.model.dto.courses.CoursesDTO;
import com.teaching.backend.model.dto.courses.CoursesUpdateDTO;
import com.teaching.backend.model.dto.courses.PageDTO;
import com.teaching.backend.model.dto.umsAdmin.UmsStudentPageQueryDTO;
import com.teaching.backend.model.entity.chapter.Chapter;
@ -30,12 +33,12 @@ import com.teaching.backend.model.entity.umsAdmin.UmsStudentManage;
import com.teaching.backend.model.entity.umsAdmin.UmsTeacher;
import com.teaching.backend.model.entity.umsAdmin.UmsUser;
import com.teaching.backend.model.query.CourseQuery;
import com.teaching.backend.model.vo.courses.CourseObjectivesTreeVO;
import com.teaching.backend.model.vo.courses.CoursesVO;
import com.teaching.backend.model.vo.courses.PersonalCenterStudentListVO;
import com.teaching.backend.model.vo.message.CourseUserInfVO;
import com.teaching.backend.model.vo.message.UserReadMessageTimeVO;
import com.teaching.backend.model.vo.umsAdmin.UmsStudentVO;
import com.teaching.backend.service.courses.ICourseObjectivesService;
import com.teaching.backend.service.courses.ICoursesService;
import com.teaching.backend.utils.CourseCode;
import lombok.extern.slf4j.Slf4j;
@ -105,9 +108,42 @@ public class CoursesServiceImpl extends ServiceImpl<CoursesMapper, Courses> impl
private UmsStudentManageMapper umsStudentManageMapper;
@Override
@Transactional
public String saveCourseWithObjective(CoursesDTO coursesDTO) {
//检验参数
String img = coursesDTO.getImg();
String category = coursesDTO.getCategory();
String nature = coursesDTO.getNature();
String name = coursesDTO.getName();
BigDecimal credit = coursesDTO.getCredit();
String assessmenttype = coursesDTO.getAssessmenttype();
String assessmentway = coursesDTO.getAssessmentway();
if(img == null){
return "图片不能为空";
}
if(category == null){
return "课程类别不能为空";
}
if(nature == null){
return "课程性质不能为空";
}
if(credit == null){
return "课程学分不能为空";
}
if(name == null){
return "课程名称不能为空";
}
if(assessmenttype == null){
return "考核类型不能为空";
}
if(assessmentway == null){
return "考核方式不能为空";
}
// 初始化并生成新的课程ID
Courses courses = new Courses();
String courseId = UUID.randomUUID().toString().replace("-", "");
@ -127,50 +163,18 @@ public class CoursesServiceImpl extends ServiceImpl<CoursesMapper, Courses> impl
// 插入课程信息
int insert = coursesMapper.insert(courses);
if (insert <= 0) {
throw new BusinessException(ErrorCode.OPERATION_ERROR, "课程插入失败!");
return "课程插入失败!";
}
// 插入课程目标信息
CourseObjectives courseObjectives = new CourseObjectives();
courseObjectives.setCourseId(courseId);
courseObjectives.setType(CourseCode.TOTAL_OBJECTIVE_TYPE.getValue());
int insertTotal = courseObjectivesMapper.insert(courseObjectives);
if (insertTotal <= 0) {
throw new BusinessException(ErrorCode.OPERATION_ERROR, "课程目标插入失败!");
}
courseObjectives.setCreateTime(new DateTime().toLocalDateTime());
courseObjectives.setName("整体目标");
courseObjectives.setType(0);
// 获取插入后的课程目标信息
CourseObjectives courseTotalObjectives = courseObjectivesMapper.selectOne(
new LambdaQueryWrapper<CourseObjectives>().eq(CourseObjectives::getCourseId, courseId)
);
String courseTotalObjectivesId = courseTotalObjectives.getId();
// 获取所有目标类型并插入子目标
List<ObjectivesType> objectivesTypes = objectivesTypeMapper.selectList(new LambdaQueryWrapper<>());
ArrayList<CourseObjectives> courseObjectivesFList = new ArrayList<>();
for (ObjectivesType objectivesType : objectivesTypes) {
if (!objectivesType.getId().equals(CourseCode.TOTAL_OBJECTIVE_TYPE.getValue())) {
CourseObjectives courseObjectivesF = new CourseObjectives();
courseObjectivesF.setType(objectivesType.getId());
courseObjectivesF.setPid(courseTotalObjectivesId);
courseObjectivesFList.add(courseObjectivesF);
}
}
//默认创建一个空的课程目标
courseObjectivesMapper.insert(courseObjectives);
// 批量插入子目标并更新父目标的hasChild字段
if (!courseObjectivesFList.isEmpty()) {
courseObjectivesMapper.insertBatch(courseObjectivesFList);
courseTotalObjectives.setHasChild(1);
courseObjectivesMapper.updateById(courseTotalObjectives);
}
// 在总目标里面插入一个内容
ObjectiveContents objectiveContents = new ObjectiveContents();
objectiveContents.setObjectiveId(courseTotalObjectivesId);
objectiveContents.setContent("请添加课程总目标");
objectiveContentsMapper.insert(objectiveContents);
return "添加成功";
return"添加成功";
}
@ -268,37 +272,36 @@ public class CoursesServiceImpl extends ServiceImpl<CoursesMapper, Courses> impl
@Override
public void deleteBatchByIds(String id) {
// if(id==null){
// throw new BusinessException(ErrorCode.PARAMS_ERROR,"课程id为空");
// }
CourseObjectives courseObjectives= courseObjectivesMapper.selectOne
(new LambdaQueryWrapper<CourseObjectives>().eq(CourseObjectives::getCourseId, id));
if(courseObjectives == null){
coursesMapper.deleteById(id);
}
String objectivesId = courseObjectives.getId();
List<CourseObjectivesTreeVO> courseObjectivesTreeVOList = courseObjectivesMapper.selectTreeNodes(objectivesId);
int contents = 0;
int knows = 0;
List<String> objectiveIds = new ArrayList<>();
for (CourseObjectivesTreeVO courseObjectivesTreeVO : courseObjectivesTreeVOList) {
String objectiveId = courseObjectivesTreeVO.getId();
objectiveIds.add(objectiveId);
Long content = objectiveContentsMapper.selectCount(new LambdaQueryWrapper<ObjectiveContents>()
.eq(ObjectiveContents::getObjectiveId, objectiveId));
contents+=content;
Long know = objectiveContentKnowMapper.selectCount(new LambdaQueryWrapper<ObjectiveContentKnow>()
.eq(ObjectiveContentKnow::getObjectiveContentId, objectiveId));
knows+=know;
}
if(contents > 0){
throw new BusinessException(ErrorCode.CONTENT_EXISTS, "该课程的目标下面还有内容,请把相关内容清空后再来删除课程");
}
if (knows > 0){
throw new BusinessException(ErrorCode.KNOWS_EXISTS,"该课程的目标下面还有关联的知识点,请把相关知识点清空后再来删除课程");
}
courseObjectivesMapper.deleteBatchIds(objectiveIds);
// todo
// List<CourseObjectivesTreeVO> courseObjectivesTreeVOList = courseObjectivesMapper.selectTreeNodes(objectivesId);
// int contents = 0;
// int knows = 0;
// List<String> objectiveIds = new ArrayList<>();
// for (CourseObjectivesTreeVO courseObjectivesTreeVO : courseObjectivesTreeVOList) {
// String objectiveId = courseObjectivesTreeVO.getId();
// objectiveIds.add(objectiveId);
// Long content = objectiveContentsMapper.selectCount(new LambdaQueryWrapper<ObjectiveContents>()
// .eq(ObjectiveContents::getObjectiveId, objectiveId));
// contents+=content;
//
// Long know = objectiveContentKnowMapper.selectCount(new LambdaQueryWrapper<ObjectiveContentKnow>()
// .eq(ObjectiveContentKnow::getObjectiveContentId, objectiveId));
// knows+=know;
// }
// if(contents > 0){
// throw new BusinessException(ErrorCode.CONTENT_EXISTS, "该课程的目标下面还有内容,请把相关内容清空后再来删除课程");
// }
// if (knows > 0){
// throw new BusinessException(ErrorCode.KNOWS_EXISTS,"该课程的目标下面还有关联的知识点,请把相关知识点清空后再来删除课程");
// }
// courseObjectivesMapper.deleteBatchIds(objectiveIds);
coursesMapper.deleteById(id);
//删除课程的同时删除对应的记录
@ -521,137 +524,137 @@ public class CoursesServiceImpl extends ServiceImpl<CoursesMapper, Courses> impl
/**
* 修改课程信息
* @param coursesDTO
* @param coursesUpdateDTO
*/
@Override
@Transactional
public void updateCourse(CoursesDTO coursesDTO) {
String courseId = coursesDTO.getId();
public void updateCourse(CoursesUpdateDTO coursesUpdateDTO) {
String courseId = coursesUpdateDTO.getId();
Courses course = coursesMapper.selectById(courseId);
if (course.getStatus()==CourseCode.COURSE_UPDATING.getValue()){
throw new BusinessException(ErrorCode.SYSTEM_ERROR,"课程正在修改中,请等待修改完成后再进行操作");
}
course.setStatus(CourseCode.COURSE_UPDATING.getValue());
coursesMapper.updateById(course);
BeanUtil.copyProperties(coursesDTO, course);
BeanUtil.copyProperties(coursesUpdateDTO, course);
course.setStatus(0);
course.setUpdateTime(LocalDateTime.now());
coursesMapper.updateById(course);
}
@Override
public void down(HttpServletResponse response, String id) throws Exception {
File rootPath = new File(ResourceUtils.getURL("classpath:").getPath()); //SpringBoot项目获取根目录的方式
File templatePath = new File(rootPath.getAbsolutePath(),"/templates/courses.docx");//------------------需要模板的地址
// // 加载Word模板------------------路径换成服务器里文件的绝对路径(要是相对路径也行也OK)
// FileInputStream template = new FileInputStream("D:\\Users\\Desktop\\teaching-backend\\src\\main\\resources\\templates\\courses.docx");
// new XWPFDocument(template);
XWPFDocument document;
//准备导出数据
//查询课程通过课程id查--课程简介
Courses courses = this.getById(id);
// System.out.println("课程:"+courses);
//准备数据
String course_name = courses.getName();
String course_code = courses.getCode();
String course_nature = courses.getNature();
BigDecimal course_credit = courses.getCredit();
Integer course_classhour = courses.getClasshours();
String course_description = courses.getDescription();
//查询课程目标
List<CourseObjectivesTreeVO> courseObjectivesTreeVO = objectivesService.queryCourseObjectivesTree(id);
//准备数据
//总目标
StringBuilder overall_goal = new StringBuilder();
List<ObjectiveContents> contents = courseObjectivesTreeVO.get(0).getContents();
for (int i = 0; i < contents.size(); i++) {
ObjectiveContents content = contents.get(i);
overall_goal.append(content.getContent());
}
//分项目标
StringBuilder sub_objectives = new StringBuilder();
//课程目标数
int course_number = 0;
for (int i = 0; i < courseObjectivesTreeVO.get(0).getCourseObjectivesTrees().size(); i++){
CourseObjectivesTreeVO content = courseObjectivesTreeVO.get(0).getCourseObjectivesTrees().get(i);
String name = content.getName();
sub_objectives.append(name).append(":");
for (int j = 0; j < content.getContents().size(); j++) {
course_number++;
sub_objectives.append("\r\n ").append("课程目标").append(course_number).append(":").append(content.getContents().get(i).getContent());
}
if (i != courseObjectivesTreeVO.get(0).getCourseObjectivesTrees().size() - 1){
sub_objectives.append("\r\n ");
}
}
System.out.println("课程目标数:"+course_number);
Map<String,Object> params = new HashMap<String,Object>();
params.put("course_name",course_name);
params.put("course_code",course_code);
params.put("course_nature",course_nature);
params.put("course_credit",course_credit);
params.put("course_classhour",course_classhour);
params.put("course_description",course_description);
//课程目标
params.put("overall_goal", overall_goal);
params.put("sub_objectives", sub_objectives);
//根据模板+数据 导出文档
document = WordExportUtil.exportWord07(templatePath.getPath(), params);
//----------------修改表格模版在导入参数之后
//获取第2个表格----------
XWPFTable table = document.getTables().get(1);
for (int i = 0; i < course_number - 1; i++) {
//新增一行单元格
XWPFTableRow newRow = table.createRow();
newRow.getCell(0).setText("课程目标" + (i + 2));
newRow.getCell(0).getParagraphArray(0).setAlignment(ParagraphAlignment.CENTER);//水平居中
newRow.getCell(0).setVerticalAlignment(XWPFTableCell.XWPFVertAlign.CENTER);//垂直居中
}
//获取第5个表格
XWPFTable table5 = document.getTables().get(4);
for (int i = 0; i < course_number - 1; i++) {
//新增一行单元格
XWPFTableRow newRow = table5.createRow();
newRow.getCell(0).setText(Integer.valueOf(i+2).toString());
newRow.getCell(0).getParagraphArray(0).setAlignment(ParagraphAlignment.CENTER);//水平居中
newRow.getCell(0).setVerticalAlignment(XWPFTableCell.XWPFVertAlign.CENTER);//垂直居中
//课程目标
newRow.getCell(1).setText("课程目标" + (i + 2));
newRow.getCell(1).getParagraphArray(0).setAlignment(ParagraphAlignment.CENTER);//水平居中
newRow.getCell(1).setVerticalAlignment(XWPFTableCell.XWPFVertAlign.CENTER);//垂直居中
//扩四列
for (int j = 0; j < 4; j++) {
newRow.createCell();
}
}
String filename= courses.getName()+"课程标准.docx";
//设置文件的打开方式和mime类型
ServletOutputStream outputStream = response.getOutputStream();
response.setHeader( "Content-Disposition", "attachment;filename=" + new String(filename.getBytes(),"ISO8859-1"));
response.setContentType("application/vnd.openxmlformats-officedocument.wordprocessingml.document");
document.write(outputStream);
}
// @Override
// public void down(HttpServletResponse response, String id) throws Exception {
// File rootPath = new File(ResourceUtils.getURL("classpath:").getPath()); //SpringBoot项目获取根目录的方式
// File templatePath = new File(rootPath.getAbsolutePath(),"/templates/courses.docx");//------------------需要模板的地址
//
//// // 加载Word模板------------------路径换成服务器里文件的绝对路径(要是相对路径也行也OK)
//// FileInputStream template = new FileInputStream("D:\\Users\\Desktop\\teaching-backend\\src\\main\\resources\\templates\\courses.docx");
//// new XWPFDocument(template);
// XWPFDocument document;
//
// //准备导出数据
// //查询课程通过课程id查--课程简介
// Courses courses = this.getById(id);
//// System.out.println("课程:"+courses);
// //准备数据
// String course_name = courses.getName();
// String course_code = courses.getCode();
// String course_nature = courses.getNature();
// BigDecimal course_credit = courses.getCredit();
// Integer course_classhour = courses.getClasshours();
// String course_description = courses.getDescription();
//
// //查询课程目标
// List<CourseObjectivesTreeVO> courseObjectivesTreeVO = objectivesService.queryCourseObjectivesTree(id);
// //准备数据
// //总目标
// StringBuilder overall_goal = new StringBuilder();
// List<ObjectiveContents> contents = courseObjectivesTreeVO.get(0).getContents();
// for (int i = 0; i < contents.size(); i++) {
// ObjectiveContents content = contents.get(i);
// overall_goal.append(content.getContent());
// }
// //分项目标
// StringBuilder sub_objectives = new StringBuilder();
// //课程目标数
// int course_number = 0;
// for (int i = 0; i < courseObjectivesTreeVO.get(0).getCourseObjectivesTrees().size(); i++){
// CourseObjectivesTreeVO content = courseObjectivesTreeVO.get(0).getCourseObjectivesTrees().get(i);
// String name = content.getName();
// sub_objectives.append(name).append(":");
// for (int j = 0; j < content.getContents().size(); j++) {
// course_number++;
// sub_objectives.append("\r\n ").append("课程目标").append(course_number).append(":").append(content.getContents().get(i).getContent());
//
// }
// if (i != courseObjectivesTreeVO.get(0).getCourseObjectivesTrees().size() - 1){
// sub_objectives.append("\r\n ");
// }
// }
// System.out.println("课程目标数:"+course_number);
// Map<String,Object> params = new HashMap<String,Object>();
// params.put("course_name",course_name);
// params.put("course_code",course_code);
// params.put("course_nature",course_nature);
// params.put("course_credit",course_credit);
// params.put("course_classhour",course_classhour);
// params.put("course_description",course_description);
//
// //课程目标
// params.put("overall_goal", overall_goal);
// params.put("sub_objectives", sub_objectives);
//
//
//
// //根据模板+数据 导出文档
//
// document = WordExportUtil.exportWord07(templatePath.getPath(), params);
//
// //----------------修改表格模版在导入参数之后
//
// //获取第2个表格----------
// XWPFTable table = document.getTables().get(1);
//
// for (int i = 0; i < course_number - 1; i++) {
// //新增一行单元格
// XWPFTableRow newRow = table.createRow();
// newRow.getCell(0).setText("课程目标" + (i + 2));
// newRow.getCell(0).getParagraphArray(0).setAlignment(ParagraphAlignment.CENTER);//水平居中
// newRow.getCell(0).setVerticalAlignment(XWPFTableCell.XWPFVertAlign.CENTER);//垂直居中
//
// }
//
// //获取第5个表格
// XWPFTable table5 = document.getTables().get(4);
//
// for (int i = 0; i < course_number - 1; i++) {
// //新增一行单元格
// XWPFTableRow newRow = table5.createRow();
//
// newRow.getCell(0).setText(Integer.valueOf(i+2).toString());
// newRow.getCell(0).getParagraphArray(0).setAlignment(ParagraphAlignment.CENTER);//水平居中
// newRow.getCell(0).setVerticalAlignment(XWPFTableCell.XWPFVertAlign.CENTER);//垂直居中
//
// //课程目标
// newRow.getCell(1).setText("课程目标" + (i + 2));
// newRow.getCell(1).getParagraphArray(0).setAlignment(ParagraphAlignment.CENTER);//水平居中
// newRow.getCell(1).setVerticalAlignment(XWPFTableCell.XWPFVertAlign.CENTER);//垂直居中
// //扩四列
// for (int j = 0; j < 4; j++) {
// newRow.createCell();
// }
// }
//
//
//
//
// String filename= courses.getName()+"课程标准.docx";
// //设置文件的打开方式和mime类型
// ServletOutputStream outputStream = response.getOutputStream();
// response.setHeader( "Content-Disposition", "attachment;filename=" + new String(filename.getBytes(),"ISO8859-1"));
// response.setContentType("application/vnd.openxmlformats-officedocument.wordprocessingml.document");
// document.write(outputStream);
// }
@Override
public List<CourseUserInfVO> getUserInfByCourse(Long userId) {

@ -1,195 +0,0 @@
package com.teaching.backend.service.impl.courses;
import cn.hutool.core.lang.generator.SnowflakeGenerator;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
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.KnowtmpMapper;
import com.teaching.backend.mapper.courses.CourseObjectivesMapper;
import com.teaching.backend.mapper.courses.CoursesMapper;
import com.teaching.backend.mapper.courses.ObjectiveContentKnowMapper;
import com.teaching.backend.mapper.courses.ObjectiveContentsMapper;
import com.teaching.backend.model.dto.courses.ObjectiveContentKnowDTO;
import com.teaching.backend.model.entity.courses.CourseObjectives;
import com.teaching.backend.model.entity.courses.ObjectiveContentKnow;
import com.teaching.backend.model.entity.courses.ObjectiveContents;
import com.teaching.backend.model.entity.knowtmp.Knowtmp;
import com.teaching.backend.model.vo.courses.ObjectiveContentKnowVO;
import com.teaching.backend.model.vo.knowtmp.KnowTmpVO;
import com.teaching.backend.service.courses.IObjectiveContentKnowService;
import com.teaching.backend.utils.CourseCode;
import lombok.extern.slf4j.Slf4j;
import org.neo4j.driver.internal.value.StringValue;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* <p>
* 服务实现类
* </p>
*
* @author zjh
* @since 2024-06-13
*/
@Service
@Slf4j
public class ObjectiveContentKnowServiceImpl extends ServiceImpl<ObjectiveContentKnowMapper, ObjectiveContentKnow> implements IObjectiveContentKnowService {
@Autowired
ObjectiveContentKnowMapper objectiveContentKnowMapper;
@Autowired
KnowtmpMapper knowtmpMapper;
@Autowired
CourseObjectivesMapper courseObjectivesMapper;
@Autowired
CoursesMapper coursesMapper;
@Autowired
ObjectiveContentsMapper objectiveContentsMapper;
@Autowired
SnowflakeGenerator snowflakeGenerator;
@Override
@Transactional
public String saveKnowsWithObjectiveContent(ObjectiveContentKnowDTO objectiveContentKnowDTO) {
//暂时约定前端传过来的的knows是“1,2,3” 用 , 隔开的
// String knows = objectiveContentKnowDTO.getKnow();
// if (knows == null || knows.equals("")){
// throw new BusinessException(ErrorCode.KONWID_NOT_EXIT);
// }
// List<String> knowIds = new ArrayList<>(Arrays.asList(knows.split(",")));
// List<ObjectiveContentKnow> objectiveContentKnowList = new ArrayList<>();
// for (String knowId : knowIds) {
// ObjectiveContentKnow objectiveContentKnow = new ObjectiveContentKnow();
//// objectiveContentKnow.setId(snowflakeGenerator.next());
// objectiveContentKnow.setObjectiveOrContent(objectiveOrContent);
// objectiveContentKnow.setKnow(knowId);
// objectiveContentKnowList.add(objectiveContentKnow);
// }
// try {
// objectiveContentKnowMapper.insertBatchSomeColumn(objectiveContentKnowList);
// } catch (Exception e) {
// e.printStackTrace();
// throw new BusinessException(ErrorCode.OBJECTIVE_OR_CONTENT_EXIT);
// }
//添加逻辑变了 变成了给知识点添加关联的--课程目标
ObjectiveContents objectiveContents = objectiveContentsMapper.selectById(objectiveContentKnowDTO.getObjectiveContentId());
if (objectiveContents == null) {
throw new BusinessException(ErrorCode.OBJECTIVE_CONTENT_NOT_EXIT);
}
int insert = objectiveContentKnowMapper.insert(objectiveContentKnowDTO);
return insert > 0 ? "添加成功" : "添加失败";
}
@Override
public ObjectiveContentKnowVO getCountData(String objectiveContentId) {
// 创建ObjectiveContentKnowVO对象,用于存储和返回计算结果
ObjectiveContentKnowVO objectiveContentKnowVO = new ObjectiveContentKnowVO();
// 根据传入的目标内容ID找到课程ID和总学时
String objectiveID = objectiveContentsMapper.selectById(objectiveContentId).getObjectiveId();
CourseObjectives courseObjective = courseObjectivesMapper.selectOne(new LambdaQueryWrapper<CourseObjectives>()
.eq(CourseObjectives::getId, objectiveID));
String pid = courseObjective.getPid();
//当前内容属于总目标类型的
String courseId;
if(pid.equals(String.valueOf(CourseCode.CONTENT_BELONGS_TO_TOTAL_OBJECTIVE.getValue()))){
courseId = courseObjective.getCourseId();
}
else {
courseId = courseObjectivesMapper.selectOne(new LambdaQueryWrapper<CourseObjectives>()
.eq(CourseObjectives::getId, pid)).getCourseId();
}
Integer classhours = coursesMapper.selectById(courseId).getClasshours();
// 获取当前目标内容下关联的知识点数据
List<ObjectiveContentKnow> objectiveContentKnows = objectiveContentKnowMapper.selectList(
new LambdaQueryWrapper<ObjectiveContentKnow>()
.eq(ObjectiveContentKnow::getObjectiveContentId, objectiveContentId)
);
if(objectiveContentKnows.isEmpty()){
log.warn("当前课程目标下面没有关联的知识点contentId:{}",objectiveContentId);
throw new BusinessException(ErrorCode.CONTENT_HAS_NO_KNOWS);
}
// 创建并设置ObjectiveContentKnowVO对象的属性
objectiveContentKnowVO = createObjectiveContentKnowVO(objectiveContentId, objectiveContentKnows);
// 计算并设置该内容的知识点总学时的比例(百分比)
Double contentPercentage = calculatePercentage(objectiveContentKnowVO.getKnowsTime(), classhours);
objectiveContentKnowVO.setPersent(contentPercentage);
// 返回最终结果
return objectiveContentKnowVO;
}
// 创建ObjectiveContentKnowVO对象,并计算知识点数量、总时间和关联的知识点部分数据
private ObjectiveContentKnowVO createObjectiveContentKnowVO(String objectiveOrContentId, List<ObjectiveContentKnow> objectiveContentKnows) {
ObjectiveContentKnowVO vo = new ObjectiveContentKnowVO();
vo.setObjectiveOrContent(objectiveOrContentId);
vo.setKnowsNumber(objectiveContentKnows.size());
// 提取所有的 Know IDs
List<Long> knowIds = objectiveContentKnows.stream()
.map(ObjectiveContentKnow::getKnowId)
.collect(Collectors.toList());
// 一次性查询所有需要的 Knowtmp 数据
List<Knowtmp> knows = knowtmpMapper.selectList(new LambdaQueryWrapper<Knowtmp>()
.in(Knowtmp::getId, knowIds));
// 使用 Map 来存储 Knowtmp 数据,以便快速查找
Map<Long, Knowtmp> knowMap = knows.stream()
.collect(Collectors.toMap(Knowtmp::getId, know -> know));
Double knowsTime = 0.0;
List<KnowTmpVO> knowTmpVOList = new ArrayList<>();
for (ObjectiveContentKnow contentKnow : objectiveContentKnows) {
Knowtmp know = knowMap.get(contentKnow.getKnowId());
if (know == null) {
log.warn("知识点不存在,id:{}", contentKnow.getKnowId());
// throw new BusinessException(ErrorCode.KNOW_NOT_EXIT);
continue; // 知识点不存在时跳过
}
knowsTime += know.getHour();
// 将当前知识点数据添加到knowTmpVOList中
KnowTmpVO knowTmpVO = new KnowTmpVO();
knowTmpVO.setId(know.getId());
knowTmpVO.setName(know.getName());
knowTmpVO.setHour(know.getHour());
knowTmpVOList.add(knowTmpVO);
}
vo.setKnowsTime(knowsTime);
vo.setKnowTmpVOList(knowTmpVOList); // 设置知识点的部分数据列表
return vo;
}
// 计算知识点学时占总学时的比例,并返回百分比形式的结果
private Double calculatePercentage(Double knowsTime, Integer classhours) {
if (classhours == null || classhours == 0) {
return 0.0;
}
return new BigDecimal(knowsTime)
.divide(new BigDecimal(classhours), 4, RoundingMode.HALF_UP)
.multiply(new BigDecimal(100))
.setScale(2, RoundingMode.HALF_UP)
.doubleValue();
}
}

@ -1,83 +0,0 @@
package com.teaching.backend.service.impl.courses;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
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.courses.CourseObjectivesMapper;
import com.teaching.backend.mapper.courses.ObjectiveContentKnowMapper;
import com.teaching.backend.mapper.courses.ObjectiveContentsMapper;
import com.teaching.backend.model.entity.courses.CourseObjectives;
import com.teaching.backend.model.entity.courses.ObjectiveContentKnow;
import com.teaching.backend.model.entity.courses.ObjectiveContents;
import com.teaching.backend.service.courses.IObjectiveContentsService;
import com.teaching.backend.utils.CourseCode;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import static com.teaching.backend.utils.CourseCode.*;
/**
* <p>
* 服务实现类
* </p>
*
* @author zjh
* @since 2024-06-05
*/
@Service
@Slf4j
public class ObjectiveContentsServiceImpl extends ServiceImpl<ObjectiveContentsMapper, ObjectiveContents> implements IObjectiveContentsService {
@Autowired
ObjectiveContentKnowMapper objectiveContentKnowMapper;
@Autowired
ObjectiveContentsMapper objectiveContentsMapper;
@Autowired
CourseObjectivesMapper courseObjectivesMapper;
@Override
public String deleteById(String id) {
if (id == null){
throw new BusinessException(ErrorCode.CONTENT_NOT_EXIT);
}
Long count = objectiveContentKnowMapper.selectCount(new LambdaQueryWrapper<ObjectiveContentKnow>()
.eq(ObjectiveContentKnow::getObjectiveContentId, id));
if(count > CourseCode.KNOWS_EXIT.getValue()){
throw new BusinessException(ErrorCode.KNOWS_EXIT);
}
String objectiveId = objectiveContentsMapper.selectById(id).getObjectiveId();
Integer type = courseObjectivesMapper.selectById(objectiveId).getType();
if (type == TOTAL_OBJECTIVE_TYPE.getValue()){
throw new BusinessException(ErrorCode.TOTOAL_OBJECTIVE_CANT_DELETE);
}
int delete = objectiveContentsMapper.deleteById(id);
return delete > 0 ? "删除成功!" : "删除失败!";
}
/**
* 在添加内容的时候需要校验总目标和思政目标只有一个内容
* @param objectiveContents
* @return
*/
@Override
public String saveWithCheck(ObjectiveContents objectiveContents) {
CourseObjectives courseObjective = courseObjectivesMapper.selectOne(new LambdaQueryWrapper<>(CourseObjectives.class)
.eq(CourseObjectives::getId, objectiveContents.getObjectiveId()));
if (courseObjective == null){
log.error("课程目标数据不存在:{}",objectiveContents.getObjectiveId());
throw new BusinessException(ErrorCode.NOT_FOUND_ERROR);
}
if (courseObjective.getType() == SI_ZHENG_TYPE.getValue() || courseObjective.getType() == TOTAL_OBJECTIVE_TYPE.getValue()){
Long count = objectiveContentsMapper.selectCount(new LambdaQueryWrapper<>(ObjectiveContents.class)
.eq(ObjectiveContents::getObjectiveId, objectiveContents.getObjectiveId()));
if (count>CONTENT_EXIT.getValue()){
throw new BusinessException(ErrorCode.CONTENT_EXISTS,"该目标下面已存在一条内容,无需再次添加");
}
}
int insert = objectiveContentsMapper.insert(objectiveContents);
return insert > 0 ? "添加内容成功" : "添加内容失败";
}
}

@ -4,6 +4,7 @@ import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateTime;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@ -66,40 +67,41 @@ public class SeCourseFavourServiceImpl extends ServiceImpl<SeCourseFavourMapper,
System.out.println("进入点赞" + courseId + userId);
//从数据库中校验是否存在courseid
Courses courses = coursesMapper.selectById(courseId);
boolean result = false;
if(courses == null){
return ResultUtils.error(ErrorCode.NOT_FOUND_ERROR,"课程不存在");
if (courses == null) {
return ResultUtils.error(ErrorCode.NOT_FOUND_ERROR, "课程不存在");
}
//查询数据库记录,该用户是否点赞
SeCourseFavour seCourseFavour = new SeCourseFavour();
seCourseFavour.setCourseId(courseId);
seCourseFavour.setUserId(userId);
seCourseFavour.setCreatetime(DateTime.now());
QueryWrapper<SeCourseFavour> favourQueryWrapper = new QueryWrapper<>(seCourseFavour);
SeCourseFavour oldSeCourseFavour = this.getOne(favourQueryWrapper);
LambdaQueryWrapper<SeCourseFavour> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.eq(SeCourseFavour::getCourseId, courseId)
.eq(SeCourseFavour::getUserId, userId);
SeCourseFavour oldSeCourseFavour = seCourseFavourMapper.selectOne(lambdaQueryWrapper);
System.out.println("查询条件: courseId=" + courseId + ", userId=" + userId);
System.out.println("查询结果: " + oldSeCourseFavour);
//已点赞
if (oldSeCourseFavour != null) {
// 取消点赞 删除记录
result = this.remove(favourQueryWrapper);
if (result) {
System.out.println("取消点赞成功");
return ResultUtils.success(result);
if (oldSeCourseFavour == null) {
// 如果没有记录,则添加收藏
SeCourseFavour newSeCourseFavour = new SeCourseFavour();
newSeCourseFavour.setCourseId(courseId);
newSeCourseFavour.setUserId(userId);
int insertResult = seCourseFavourMapper.insert(newSeCourseFavour);
if (insertResult > 0) {
return ResultUtils.success(true);
} else {
throw new BusinessException(ErrorCode.SYSTEM_ERROR);
return ResultUtils.error(ErrorCode.OPERATION_ERROR);
}
} else {
// 每个用户串行点赞
// 锁必须要包裹住事务方法
Lock lock = new ReentrantLock();
lock.lock();
try {
result = this.save(seCourseFavour);
} catch (Exception e) {
throw new BusinessException(ErrorCode.OPERATION_ERROR);
} finally {
lock.unlock();
System.out.println("点赞成功");
return ResultUtils.success(result);
// 如果有记录,则删除记录,也就是取消收藏
int deleteResult = seCourseFavourMapper.delete(lambdaQueryWrapper);
if (deleteResult > 0) {
return ResultUtils.success(false);
} else {
return ResultUtils.error(ErrorCode.OPERATION_ERROR);
}
}
}

@ -7,7 +7,9 @@ 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.controller.Know.KnowPathVO;
import com.teaching.backend.mapper.resource.ResourceRelationshipMapper;
import com.teaching.backend.model.entity.resource.ResourceRelationship;
import com.teaching.backend.model.vo.knowGraph.KnowPathVO;
import com.teaching.backend.mapper.Knowtemp.KnowstrMapper;
import com.teaching.backend.mapper.Knowtemp.KnowtmpMapper;
import com.teaching.backend.mapper.chapter.ChapterMapper;
@ -21,11 +23,15 @@ import com.teaching.backend.model.entity.knowtmp.Knowtmp;
import com.teaching.backend.model.vo.knowGraph.KnowVO;
import com.teaching.backend.service.Know.KnowService;
import com.teaching.backend.service.knowtmp.KnowtmpService;
import com.teaching.backend.service.resource.ResourceGraphService;
import com.teaching.backend.service.resource.ResourceService;
import org.neo4j.driver.internal.InternalRelationship;
import org.neo4j.driver.types.Node;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.data.neo4j.core.Neo4jClient;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.*;
@ -50,6 +56,11 @@ public class knowServiceImpl implements KnowService {
@Autowired
private KnowtmpService knowtmpService;
@Autowired
private ResourceGraphService resourceGraphService;
@Autowired
private ResourceRelationshipMapper resourceRelationshipMapper;
@Autowired
@ -72,6 +83,9 @@ public class knowServiceImpl implements KnowService {
}
public BaseResponse<BaseKnowReturn> getNodeByDepth(long id, Long depth) {
if(depth > 2){
depth--;
}
Collection<Map<String, Object>> all =
neo4jClient.query("match(n:Know)-[r:contain*0.." + depth + "]->(p:Know) where ID(n) = " + id + " return n as `n`,r as `r`,p as `p`,length(r) as `d`").fetch().all();
Collection<Map<String, Object>> all2 =
@ -658,7 +672,15 @@ public class knowServiceImpl implements KnowService {
//根据json串生成 图谱 保证事务
@Transactional(value="transactionManager")
public BaseResponse<String> generateGraph(String courseId1) {
//先查询课程id的节点是否存在
Long l = knowRepository.queryNodeByCourseId(courseId1);
if(l != null){
deleteAllByCourseId(courseId1);
}
QueryWrapper<KnowStr> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("course_id", courseId1);
KnowStr knowStr = knowstrMapper.selectOne(queryWrapper);
@ -739,6 +761,17 @@ public class knowServiceImpl implements KnowService {
return ResultUtils.error(ErrorCode.SYSTEM_ERROR, "添加节点关系失败");
}
}
//根据mysql KnowId 建立资源与neo4j 节点资源关系
QueryWrapper<ResourceRelationship>queryWrapper1 = new QueryWrapper<>();
queryWrapper1.eq("course_id",courseId1);
List<ResourceRelationship> resourceRelationships = resourceRelationshipMapper.selectList(queryWrapper1);
for (int i = 0; i < resourceRelationships.size(); i++) {
ResourceRelationship resourceRelationship = resourceRelationships.get(i);
Long knowId = resourceRelationship.getKnowId();
Long resourceId = resourceRelationship.getResourceId();
String s = resourceGraphService.addResourcesByKnowId(knowId,resourceId).getData();
System.out.println(s);
}
return ResultUtils.success("添加节点关系成功");
}

@ -1,23 +1,34 @@
package com.teaching.backend.service.impl.knowtmp;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
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.exception.BusinessException;
import com.teaching.backend.mapper.Knowtemp.KnowtmpMapper;
import com.teaching.backend.mapper.chapter.ChapterMapper;
import com.teaching.backend.mapper.courses.CourseObjectivesMapper;
import com.teaching.backend.mapper.courses.ObjectiveContentKnowMapper;
import com.teaching.backend.model.dto.Knowtmp.KnowtempAdd;
import com.teaching.backend.model.dto.Knowtmp.KnowtempUpdate;
import com.teaching.backend.model.entity.chapter.Chapter;
import com.teaching.backend.model.entity.courses.CourseObjectives;
import com.teaching.backend.model.entity.courses.ObjectiveContentKnow;
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 org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
/**
* @Author:youhang
@ -34,8 +45,26 @@ public class KnowtmpServiceImpl implements KnowtmpService {
@Autowired
private KnowtmpMapper knowtmpMapper;
@Autowired
private ObjectiveContentKnowMapper objectiveContentKnowMapper;
@Autowired
CourseObjectivesMapper courseObjectivesMapper;
@Override
public BaseResponse<String> objectiveaddKnow(String ObjectiveId, Long KnowId) {
ObjectiveContentKnow objectiveContentKnow = new ObjectiveContentKnow();
objectiveContentKnow.setKnowId(KnowId);
objectiveContentKnow.setObjectiveContentId(ObjectiveId);
int ans = objectiveContentKnowMapper.insert(objectiveContentKnow);
if(ans > 0){
return ResultUtils.success("添加课程目标成功");
}
return ResultUtils.error(ErrorCode.OPERATION_ERROR,"添加课程目标失败");
}
@Override
public BaseResponse<Long> getAllKnows(String courseId) {
// 3 从章节表查出章节节点 并添加到 neo
@ -49,24 +78,152 @@ public class KnowtmpServiceImpl implements KnowtmpService {
@Override
public BaseResponse<String> add(KnowtempAdd knowtempAdd) {
//判断章节是否存在
Chapter chapter = chapterMapper.selectById(knowtempAdd.getChapterid());
if(chapter == null){
return ResultUtils.error(ErrorCode.PARAMS_ERROR,"章节id 不存在");
}
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,"添加失败");
//顺序计算 分配学时以及顺序
Long chapterid = knowtempAdd.getChapterid();
BigDecimal remainingHours = BigDecimal.ZERO; // 初始化剩余学时
BigDecimal classHours = chapterMapper.getChapterHours(chapterid);
LambdaQueryWrapper<Knowtmp> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.eq(Knowtmp::getChapterid, chapterid);
List<Knowtmp> knowtmpList = knowtmpMapper.selectList(lambdaQueryWrapper);
BigDecimal totalChapterHours = knowtmpList.stream()
.map(Knowtmp::getHour)
.map(BigDecimal::new)
.reduce(BigDecimal.ZERO, BigDecimal::add);
remainingHours = classHours.subtract(totalChapterHours).setScale(1, RoundingMode.HALF_UP);
BigDecimal newKnowHours = BigDecimal.valueOf(knowtmp.getHour()); // 根据实际返回类型调整
if (newKnowHours.compareTo(remainingHours) <= 0) {
LambdaQueryWrapper<Knowtmp> maxSortWrapper = new LambdaQueryWrapper<>();
maxSortWrapper.eq(Knowtmp::getChapterid, chapterid).orderByDesc(Knowtmp::getOrdernum).last("limit 1");
Knowtmp maxSortKnow= knowtmpMapper.selectOne(maxSortWrapper);
double newSort = 1;
if (maxSortKnow != null) {
newSort = maxSortKnow.getOrdernum() + 1;
}
knowtmp.setOrdernum(newSort);
knowtmp.setCreateTime(LocalDateTime.now());
int f = knowtmpMapper.insert(knowtmp);
if(f > 0) {
return ResultUtils.success("添加成功");
}
remainingHours = remainingHours.subtract(newKnowHours).setScale(1, RoundingMode.HALF_UP);
} else {
return ResultUtils.error(ErrorCode.OPERATION_ERROR,"添加失败"+"当前添加的学时为:"+newKnowHours+"当前剩余学时为:"+remainingHours);
}
return ResultUtils.error(ErrorCode.OPERATION_ERROR,"添加失败");
}
@Override
@Transactional
public BaseResponse<String> addObjective(List<String> objectiveIds,Long knowId) {
//查询知识点是否存在
if(knowId == null){
return ResultUtils.error(ErrorCode.PARAMS_ERROR,"课程id不能为空");
}
Knowtmp knowtmp = knowtmpMapper.selectById(knowId);
if(knowtmp == null){
return ResultUtils.error(ErrorCode.PARAMS_ERROR,"知识点不存在");
}
//传id 如果传空数组 那就是删除掉
if(objectiveIds.size() <= 0){
QueryWrapper<ObjectiveContentKnow>queryWrapper = new QueryWrapper<>();
queryWrapper.eq("know_id",knowId);
objectiveContentKnowMapper.delete(queryWrapper);
return ResultUtils.success("添加目标成功");
}
//查询出知识点的课程id - 校验知识点和课程目标是在同一课下
Chapter chapter = chapterMapper.selectById(knowtmp.getChapterid());
String courseId1 = chapter.getCourseId();
for (int i = 0; i < objectiveIds.size(); i++) {
String objectiveId = objectiveIds.get(i);
//查询课程目标id是否存在
if(objectiveId == null || "".equals(objectiveId)){
return ResultUtils.error(ErrorCode.PARAMS_ERROR,"课程目标id不能为空");
}
CourseObjectives courseObjectives = courseObjectivesMapper.selectById(objectiveId);
if(courseObjectives == null){
return ResultUtils.error(ErrorCode.PARAMS_ERROR,"课程目标不存在");
}
String courseId2 = courseObjectives.getCourseId();
//判断
if(!courseId2.equals(courseId1)){
return ResultUtils.error(ErrorCode.PARAMS_ERROR,"知识点和课程目标不在同一课程下");
}
QueryWrapper<ObjectiveContentKnow>queryWrapper = new QueryWrapper<>();
queryWrapper.eq("objective_content_id",objectiveId);
queryWrapper.eq("know_id",knowId);
ObjectiveContentKnow objectiveContentKnow1 = objectiveContentKnowMapper.selectOne(queryWrapper);
if(objectiveContentKnow1 != null){
objectiveContentKnowMapper.delete(queryWrapper);
}
ObjectiveContentKnow objectiveContentKnow = new ObjectiveContentKnow();
objectiveContentKnow.setObjectiveContentId(objectiveId);
objectiveContentKnow.setKnowId(knowId);
int ans = objectiveContentKnowMapper.insert(objectiveContentKnow);
if(ans<0){
return ResultUtils.error(ErrorCode.SYSTEM_ERROR,"添加目标失败");
}
}
return ResultUtils.success("添加目标成功");
}
@Override
public BaseResponse<List<String>> knowObjects(Long knowId) {
QueryWrapper<ObjectiveContentKnow> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("know_id",knowId);
List<ObjectiveContentKnow> courseObjectives = objectiveContentKnowMapper.selectList(queryWrapper);
List<String> ids = courseObjectives.stream().map(item->item.getObjectiveContentId()).collect(Collectors.toList());
return ResultUtils.success(ids);
}
@Override
public BaseResponse<String> update(KnowtempUpdate knowtempUpdate) {
Knowtmp knowtmp = new Knowtmp();
BeanUtils.copyProperties(knowtempUpdate,knowtmp);
Knowtmp knowtmpOld = knowtmpMapper.selectById(knowtmp.getId());
Long id = knowtempUpdate.getId();
String name = knowtempUpdate.getName();
String info = knowtempUpdate.getInfo();
Long chapterid = knowtempUpdate.getChapterid();
double hour = knowtempUpdate.getHour();
Knowtmp knowtmpOld = knowtmpMapper.selectById(id);
if(knowtmpOld == null){
return ResultUtils.error(ErrorCode.OPERATION_ERROR,"数据不存在");
}
if(info != null){
knowtmp.setInfo(info);
}
if(name != null){
knowtmp.setName(name);
}
if(chapterid != null){
knowtmp.setChapterid(chapterid);
}
if(hour != 0){
knowtmp.setHour(hour);
}
int f = knowtmpMapper.updateById(knowtmp);
if(f > 0){
return ResultUtils.success("修改成功");

@ -79,7 +79,7 @@ public class UserInboxServiceImpl extends ServiceImpl<UserInboxMapper, UserInbox
Page<SysMessages> p = messagesService.page(page,
new LambdaQueryWrapper<SysMessages>()
.in(SysMessages::getId,messageIds)
.select(SysMessages::getId,SysMessages::getCourseId,SysMessages::getTitle,SysMessages::getSenderId,SysMessages::getSendTime)
.select(SysMessages::getId,SysMessages::getCourseId,SysMessages::getTitle,SysMessages::getContent,SysMessages::getSenderId,SysMessages::getSendTime)
);
// 将Page<SysMessages>转换为PageDTO<SysMessageVO>
@ -125,7 +125,7 @@ public class UserInboxServiceImpl extends ServiceImpl<UserInboxMapper, UserInbox
@Override
public PageDTO<SysMessageVO> querySendMessages(MessagesQuery messagesQuery) {
// 1. 初始化一个按发送时间降序排序的Page对象
// 1. 初始化/一个按发送时间降序排序的Page对象
Page<SysMessages> page = messagesQuery.toMpPage("send_time", false);
// 2. 根据条件查询SysMessages表
@ -134,7 +134,7 @@ public class UserInboxServiceImpl extends ServiceImpl<UserInboxMapper, UserInbox
.eq(SysMessages::getSenderId, messagesQuery.getUserId())
.eq(SysMessages::getIsSend, messagesQuery.getIsSend())
.eq(SysMessages::getIsDelete, messagesQuery.getIsDelete())
.select(SysMessages::getId, SysMessages::getCourseId, SysMessages::getTitle, SysMessages::getSendTime)
.select(SysMessages::getId, SysMessages::getCourseId, SysMessages::getTitle, SysMessages::getContent,SysMessages::getSendTime)
);
// 3. 将Page<SysMessages>转换为PageDTO<SysMessageVO>

@ -1,14 +1,21 @@
package com.teaching.backend.service.impl.resource;
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.mapper.know.KnowRepository;
import com.teaching.backend.mapper.resource.ResourceMapper;
import com.teaching.backend.mapper.resource.ResourceRelationshipMapper;
import com.teaching.backend.mapper.resource.ResourcesRepository;
import com.teaching.backend.model.dto.resource.ResourceUploadDto;
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.ResourceMysql;
import com.teaching.backend.model.entity.resource.ResourceRelationship;
import com.teaching.backend.model.entity.resource.Resources;
import com.teaching.backend.service.resource.ResourceGraphService;
import com.teaching.backend.service.resource.ResourceService;
@ -24,6 +31,7 @@ import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
@ -39,9 +47,15 @@ public class ResourceGraphServiceImpl implements ResourceGraphService {
@Autowired
private ResourcesRepository resourcesRepository;
@Autowired
private ResourceMapper resourceMapper;
@Autowired
private KnowRepository knowRepository;
@Autowired
private ResourceRelationshipMapper resourceRelationshipMapper;
@Override
@ -69,6 +83,31 @@ public class ResourceGraphServiceImpl implements ResourceGraphService {
return ResultUtils.success("添加关系成功");
}
@Override
public BaseResponse<String> addResourcesByKnowId(Long knowId, Long resourcesId) {
// 查询知识点是否存在 ,资源是否存在
Long id = knowRepository.queryNodeByKnowId(knowId);
if(id == null){
return ResultUtils.error(ErrorCode.PARAMS_ERROR,"知识点不存在");
}
Resources resources = resourcesRepository.queryResourcesByResourceId(resourcesId);
if(resources == null){
return ResultUtils.error(ErrorCode.PARAMS_ERROR,"资源不存在");
}
//查询关系是否存在
int g = resourcesRepository.queryExisitRel(id,resourcesId);
if(g >0){
return ResultUtils.error(ErrorCode.PARAMS_ERROR,"关系已经存在");
}
//添加关系 addResourcesAndKnowById
int f = resourcesRepository.addResourcesAndKnowById2(id,resourcesId);
if(f<= 0){
return ResultUtils.error(ErrorCode.PARAMS_ERROR,"创建关系失败");
}
return ResultUtils.success("添加关系成功");
}
@Override
public BaseResponse<String> deleteResourcesAndKnowById(Long id, Long resourcesId) {
// 查询知识点是否存在 ,资源是否存在
@ -132,7 +171,7 @@ public class ResourceGraphServiceImpl implements ResourceGraphService {
}
@Override
public BaseResponse<Set<Resources>> queryResourcesByKnowId(Long knowId) {
public BaseResponse<Set<Resources>> queryResourcesById(Long knowId) {
// 判空,查询
int i = knowRepository.queryNode(knowId);
if(i <= 0){
@ -143,4 +182,5 @@ public class ResourceGraphServiceImpl implements ResourceGraphService {
}
}

@ -1,16 +1,31 @@
package com.teaching.backend.service.impl.resource;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.teaching.backend.common.BaseResponse;
import com.teaching.backend.common.ErrorCode;
import com.teaching.backend.common.ResultUtils;
import com.teaching.backend.mapper.resource.ResourceMysqlMapper;
import com.teaching.backend.mapper.courses.CoursesMapper;
import com.teaching.backend.mapper.know.KnowRepository;
import com.teaching.backend.mapper.resource.ResourceMapper;
import com.teaching.backend.mapper.resource.ResourceRelationshipMapper;
import com.teaching.backend.mapper.resource.ResourcesRepository;
import com.teaching.backend.model.entity.courses.Courses;
import com.teaching.backend.model.entity.resource.ResourceMysql;
import com.teaching.backend.service.resource.IResourceMysqlService;
import com.teaching.backend.model.entity.resource.ResourceRelationship;
import com.teaching.backend.service.resource.ResourceMysqlService;
import org.apache.ibatis.annotations.Results;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import java.util.ArrayList;
import java.util.List;
/**
* <p>
* 服务实现类
@ -20,15 +35,60 @@ import org.springframework.web.multipart.MultipartFile;
* @since 2024-09-02
*/
@Service
public class ResourceMysqlServiceImpl extends ServiceImpl<ResourceMysqlMapper, ResourceMysql> implements IResourceMysqlService {
private ResourceServiceImpl resourceService;
public class ResourceMysqlServiceImpl implements ResourceMysqlService {
@Autowired
private ResourcesRepository resourcesRepository;
@Autowired
private ResourceMapper resourceMapper;
@Autowired
private KnowRepository knowRepository;
@Autowired
private ResourceRelationshipMapper resourceRelationshipMapper;
@Autowired
private CoursesMapper coursesMapper;
@Override
public BaseResponse<String> resourceUpload(MultipartFile file, ResourceMysql resourceMysql) {
System.out.println(1);
System.out.println(file);
String url = resourceService.upload(file).getData().getUrl();
resourceMysql.setPath(url);
save(resourceMysql);
return ResultUtils.success("添加成功");
public BaseResponse<List<ResourceMysql>> queryResourcesByKnowId(Long knowId) {
QueryWrapper<ResourceRelationship> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("know_id",knowId);
List<ResourceRelationship> resourceRelationshipList = resourceRelationshipMapper.selectList(queryWrapper);
List<ResourceMysql>resourceMysqlList=new ArrayList<>();
for (ResourceRelationship rc:resourceRelationshipList) {
Long resourceId = rc.getResourceId();
ResourceMysql resourceMysql = resourceMapper.selectById(resourceId);
resourceMysqlList.add(resourceMysql);
}
return ResultUtils.success(resourceMysqlList);
}
@Override
public BaseResponse<List<ResourceMysql>> queryResourcesByCourseId(String courseId) {
Courses courses = coursesMapper.selectById(courseId);
if(courses == null){
return ResultUtils.error(ErrorCode.PARAMS_ERROR,"课程为空");
}
QueryWrapper<ResourceRelationship>queryWrapper=new QueryWrapper<>();
queryWrapper.eq("course_id",courseId);
List<ResourceRelationship> resourceRelationshipList = resourceRelationshipMapper.selectList(queryWrapper);
if (resourceRelationshipList == null){
return ResultUtils.error(ErrorCode.PARAMS_ERROR,"查询资源为空");
}
List<ResourceMysql>resourceMysqlList=new ArrayList<>();
for (ResourceRelationship rc:resourceRelationshipList) {
Long resourceId = rc.getResourceId();
ResourceMysql resourceMysql = resourceMapper.selectById(resourceId);
resourceMysqlList.add(resourceMysql);
}
return ResultUtils.success(resourceMysqlList);
}
}

@ -0,0 +1,93 @@
package com.teaching.backend.service.impl.resource;
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.mapper.know.KnowRepository;
import com.teaching.backend.mapper.resource.ResourceMapper;
import com.teaching.backend.mapper.resource.ResourceRelationshipMapper;
import com.teaching.backend.mapper.resource.ResourcesRepository;
import com.teaching.backend.model.dto.resource.ResourceRelationshipDto;
import com.teaching.backend.model.entity.know.KnowChapter;
import com.teaching.backend.model.entity.know.KnowCourse;
import com.teaching.backend.model.entity.knowtmp.Knowtmp;
import com.teaching.backend.model.entity.resource.ResourceMysql;
import com.teaching.backend.model.entity.resource.ResourceRelationship;
import com.teaching.backend.model.entity.resource.Resources;
import com.teaching.backend.service.resource.ResourceGraphService;
import com.teaching.backend.service.resource.ResourceRelationshipService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Set;
/**
* @Author:youhang
* @Date:2024-07-26-13:58
* @Description:
*/
@Service
public class ResourceRelationshipServiceImpl implements ResourceRelationshipService {
@Autowired
private ResourceMapper resourceMapper;
@Autowired
private ResourceRelationshipMapper resourceRelationshipMapper;
@Autowired
private KnowtmpMapper knowtmpMapper;
@Override
public BaseResponse<String> addResourcesRel(ResourceRelationshipDto resourceRelationshipDto) {
Long knowId = resourceRelationshipDto.getKnowId();
Long resourceId = resourceRelationshipDto.getResourceId();
String coursesId = resourceRelationshipDto.getCourseId();
//判空
if(knowId <= 0){
return ResultUtils.error(ErrorCode.PARAMS_ERROR,"knowId字段不能为空");
}
if(resourceId <= 0){
return ResultUtils.error(ErrorCode.PARAMS_ERROR,"resourceId字段不能为空");
}
if("".equals(coursesId) || coursesId == null){
return ResultUtils.error(ErrorCode.PARAMS_ERROR,"coursesId字段不能为空");
}
//查询知识点是否存在
Knowtmp knowtmp = knowtmpMapper.selectById(knowId);
if(knowtmp == null)
return ResultUtils.error(ErrorCode.PARAMS_ERROR,"知识点不存在");
ResourceMysql resourceMysql = resourceMapper.selectById(resourceId);
if(resourceMysql == null){
return ResultUtils.error(ErrorCode.PARAMS_ERROR,"资源不存在");
}
ResourceRelationship resourceRelationship = new ResourceRelationship();
resourceRelationship.setResourceId(resourceId);
resourceRelationship.setCourseId(coursesId);
resourceRelationship.setKnowId(knowId);
int ans = resourceRelationshipMapper.insert(resourceRelationship);
if(ans > 0){
return ResultUtils.success("添加成功");
}
return ResultUtils.error(ErrorCode.SYSTEM_ERROR,"添加失败");
}
@Override
public BaseResponse<String> deleteResourcesRel(Long knowId, Long resourceId) {
QueryWrapper<ResourceRelationship> resourceRelationshipQueryWrapper = new QueryWrapper<>();
resourceRelationshipQueryWrapper.eq("know_id",knowId).eq("resource_id",resourceId);
int ans = resourceRelationshipMapper.delete(resourceRelationshipQueryWrapper);
if(ans > 0){
return ResultUtils.success("删除成功");
}
return ResultUtils.error(ErrorCode.SYSTEM_ERROR,"删除失败");
}
}

@ -1,28 +1,53 @@
package com.teaching.backend.service.impl.resource;
import cn.hutool.core.date.DateTime;
import com.aliyun.oss.ClientException;
import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSException;
import com.aliyun.oss.model.OSSObject;
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.constant.TypeEnum;
import com.teaching.backend.mapper.know.KnowRepository;
import com.teaching.backend.mapper.resource.ResourceMapper;
import com.teaching.backend.mapper.resource.ResourceRelationshipMapper;
import com.teaching.backend.mapper.resource.ResourcesRepository;
import com.teaching.backend.model.dto.resource.ResourceUploadDto;
import com.teaching.backend.model.entity.know.Know;
import com.teaching.backend.model.entity.resource.ResourceMysql;
import com.teaching.backend.model.entity.resource.ResourceRelationship;
import com.teaching.backend.model.entity.resource.Resources;
import com.teaching.backend.service.resource.ResourceService;
import com.teaching.backend.utils.AliyunOSSClientUtil;
import com.teaching.backend.utils.MinioUtils;
import lombok.val;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.core.io.InputStreamResource;
import org.springframework.data.neo4j.core.Neo4jClient;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.parameters.P;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import java.io.*;
import java.text.SimpleDateFormat;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Map;
import static com.teaching.backend.utils.AliyunOSSClientUtil.*;
/**
@ -39,6 +64,12 @@ public class ResourceServiceImpl implements ResourceService {
@Autowired
private KnowRepository knowRepository;
@Autowired
private ResourceMapper resourceMapper;
@Autowired
private ResourceRelationshipMapper resourceRelationshipMapper;
private static final Logger LOGGER = LoggerFactory.getLogger(ResourceService.class);
@ -56,49 +87,294 @@ public class ResourceServiceImpl implements ResourceService {
private String SECRET_KEY;
String ossEndpoint = "oss-cn-beijing.aliyuncs.com";
String accessId = "LTAI5tPB2w8CTGcs5co4uU3Y";
String accessKey = "269HonqLmWuisTPjKn9qQLBrHpDw1x";
String bucketName = "youhang-edu";
@Resource
private Neo4jClient neo4jClient;
@Override
public BaseResponse<Resources> upload(MultipartFile file) {
ResourceUploadDto resourceUploadDto = minioUtils.upload(file);
if (resourceUploadDto == null) {
return ResultUtils.error(ErrorCode.OPERATION_ERROR, "上传失败");
public BaseResponse<String> uploadOSS(MultipartFile file) throws IOException {
// 初始化OSSClient
OSS ossClient = AliyunOSSClientUtil.getOssClient(ossEndpoint, accessId, accessKey);
InputStream is = file.getInputStream();
//文件名
String filename = file.getOriginalFilename();
//字符串截取
int dotIndex = filename.lastIndexOf('.');
String prefix = filename.substring(0,dotIndex);
String suffix = filename.substring(dotIndex+1,filename.length());
if(prefix.length() > 20){
prefix = prefix.substring(0,20);
}
filename = prefix+"."+suffix;
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
// 设置存储对象名称
String objectName = sdf.format(new Date()) + "/" + suffix + "/" + filename;
String ossPath = objectName;
String absolutePath = uploadFileOss(ossClient, bucketName, ossPath, is, filename);
System.out.println("absolutePath:"+absolutePath);
return ResultUtils.success("https://youhang-edu.oss-cn-beijing.aliyuncs.com/"+absolutePath);
}
@Override
public BaseResponse<String> deleteFileOss(String objectName) {
// 初始化OSSClient
OSS ossClient = AliyunOSSClientUtil.getOssClient(ossEndpoint, accessId, accessKey);
deleteObject(ossClient, bucketName, objectName);
return ResultUtils.success("删除成功");
}
public BaseResponse<InputStream> readFile(String filename) {
String objectName = filename;
// 初始化OSSClient
OSS ossClient = AliyunOSSClientUtil.getOssClient(ossEndpoint, accessId, accessKey);
InputStream content = null;
try {
// 调用ossClient.getObject返回一个OSSObject实例,该实例包含文件内容及文件元数据。
OSSObject ossObject = ossClient.getObject(bucketName, objectName);
// 调用ossObject.getObjectContent获取文件输入流,可读取此输入流获取其内容。
content = ossObject.getObjectContent();
if (content != null) {
BufferedReader reader = new BufferedReader(new InputStreamReader(content));
content.close();
}
} catch (OSSException oe) {
System.out.println("Caught an OSSException, which means your request made it to OSS, "
+ "but was rejected with an error response for some reason.");
System.out.println("Error Message:" + oe.getErrorMessage());
System.out.println("Error Code:" + oe.getErrorCode());
System.out.println("Request ID:" + oe.getRequestId());
System.out.println("Host ID:" + oe.getHostId());
} catch (ClientException ce) {
System.out.println("Caught an ClientException, which means the client encountered "
+ "a serious internal problem while trying to communicate with OSS, "
+ "such as not being able to access the network.");
System.out.println("Error Message:" + ce.getMessage());
} catch (IOException e) {
throw new RuntimeException(e);
}
return ResultUtils.success(content);
}
// @Override
// public BaseResponse<ResourceUploadDto> upload(MultipartFile file) {
// ResourceUploadDto resourceUploadDto = minioUtils.upload(file);
// if (resourceUploadDto == null) {
// return ResultUtils.error(ErrorCode.OPERATION_ERROR, "上传失败");
// }
// String url = resourceUploadDto.getUrl();
// String name = resourceUploadDto.getName();
// String objectName = resourceUploadDto.getObjectName();
//
// return ResultUtils.success(resourceUploadDto);
// }
//
// @Override
// public BaseResponse<String> delete(String objectName) {
// try {
// minioUtils.delete(objectName);
// }catch (Exception e){
// e.printStackTrace();
// LOGGER.info("删除失败,故障");
// return ResultUtils.error(ErrorCode.OPERATION_ERROR, "删除失败");
// }
// return ResultUtils.success("删除成功");
// }
//
//
// public ResponseEntity<InputStreamResource> readFile(String filename) {
// return minioUtils.readFile(filename);
// }
@Override
public BaseResponse<String> addResourceForMysql(MultipartFile file) {
try {
ResourceUploadDto resourceUploadDto = new ResourceUploadDto();
// 初始化OSSClient
OSS ossClient = AliyunOSSClientUtil.getOssClient(ossEndpoint, accessId, accessKey);
InputStream is = file.getInputStream();
//文件名
String filename = file.getOriginalFilename();
//字符串截取
int dotIndex = filename.lastIndexOf('.');
String prefix = filename.substring(0,dotIndex);
String suffix = filename.substring(dotIndex+1,filename.length());
if(prefix.length() > 20){
prefix = prefix.substring(0,20);
}
filename = prefix+"."+suffix;
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
// 设置存储对象名称
String objectName = sdf.format(new Date()) + "/" + suffix + "/" + filename;
String ossPath = objectName;
String absolutePath = uploadFileOss(ossClient, bucketName, ossPath, is, filename);
ResourceMysql resourceMysql = new ResourceMysql();
resourceMysql.setName(absolutePath);
resourceMysql.setType(TypeEnum.getTypeByPrefix(suffix));
resourceMysql.setStatus(0);
resourceMysql.setUrl("https://youhang-edu.oss-cn-beijing.aliyuncs.com/"+absolutePath);
int ans = resourceMapper.insert(resourceMysql);
if(ans >0){
return ResultUtils.success(resourceMysql.getUrl());
}
return ResultUtils.error(ErrorCode.OPERATION_ERROR,"添加资原失败");
}catch (IOException e){
e.printStackTrace();
return ResultUtils.error(ErrorCode.OPERATION_ERROR,"添加资原-OSS失败");
}
String url = resourceUploadDto.getUrl();
String name = resourceUploadDto.getName();
String objectName = resourceUploadDto.getObjectName();
//添加到图数据库中
Resources resource = new Resources();
resource.setType(resourceUploadDto.getType());
resource.setName(objectName);
resource.setStatus(0);
resource.setUrl(url);
resourcesRepository.save(resource);
return ResultUtils.success(resource);
}
@Override
public BaseResponse<String> delete(String objectName) {
try {
minioUtils.delete(objectName);
}catch (Exception e){
e.printStackTrace();
LOGGER.info("删除失败,故障");
@Transactional
public BaseResponse<ResourceMysql> addResource(MultipartFile file) {
try {
// 初始化OSSClient
OSS ossClient = AliyunOSSClientUtil.getOssClient(ossEndpoint, accessId, accessKey);
InputStream is = file.getInputStream();
//文件名
String filename = file.getOriginalFilename();
//字符串截取
int dotIndex = filename.lastIndexOf('.');
String prefix = filename.substring(0,dotIndex);
String suffix = filename.substring(dotIndex+1,filename.length());
if(prefix.length() > 20){
prefix = prefix.substring(0,20);
}
//删除图数据库
boolean f = resourcesRepository.deleteByobjectName(objectName);
if (f) {
return ResultUtils.success("删除成功");
} else {
return ResultUtils.error(ErrorCode.OPERATION_ERROR, "图数据库删除失败");
filename = prefix+"."+suffix;
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
// 设置存储对象名称
String objectName = sdf.format(new Date()) + "/" + suffix + "/" + filename;
String ossPath = objectName;
String absolutePath = uploadFileOss(ossClient, bucketName, ossPath, is, filename);
//添加mysql
ResourceMysql resourceMysql = new ResourceMysql();
resourceMysql.setName(absolutePath);
resourceMysql.setType(TypeEnum.getTypeByPrefix(suffix));
resourceMysql.setStatus(0);
resourceMysql.setUrl("https://youhang-edu.oss-cn-beijing.aliyuncs.com/"+absolutePath);
long ans = resourceMapper.insert(resourceMysql);
//添加neo4j
Resources resources = new Resources();
resources.setType(TypeEnum.getTypeByPrefix(suffix));
resources.setName(absolutePath);
resources.setStatus(0);
resources.setResourceId(resourceMysql.getId());
resources.setUrl("https://youhang-edu.oss-cn-beijing.aliyuncs.com/"+absolutePath);
Resources resourcesNew = resourcesRepository.save(resources);
if (resourcesNew != null && ans > 0) {
return ResultUtils.success(resourceMysql);
}
}catch (IOException e){
e.printStackTrace();
throw new RuntimeException("添加资原-neo4j失败");
}
return ResultUtils.error(ErrorCode.OPERATION_ERROR,"添加资原失败");
}
@Override
public BaseResponse<String> deleteResourceForMysql(long id) {
ResourceMysql resourceMysql = resourceMapper.selectById(id);
if(resourceMysql == null){
return ResultUtils.error(ErrorCode.PARAMS_ERROR,"删除ID不存在");
}
deleteFileOss(resourceMysql.getName());
int ans = resourceMapper.deleteById(id);
if (ans > 0) {
return ResultUtils.success("删除成功");
}
return ResultUtils.error(ErrorCode.PARAMS_ERROR,"删除失败");
}
@Override
@Transactional
public BaseResponse<String> deleteResource(long id) {
ResourceMysql resourceMysql = resourceMapper.selectById(id);
if(resourceMysql == null){
return ResultUtils.error(ErrorCode.PARAMS_ERROR,"删除ID不存在");
}
deleteFileOss(resourceMysql.getName());
int ans = resourceMapper.deleteById(id);
if (ans <= 0) {
return ResultUtils.error(ErrorCode.PARAMS_ERROR,"删除-mysql-失败");
}
//查询资源-关系表
QueryWrapper<ResourceRelationship> resourceRelationshipQueryWrapper = new QueryWrapper<>();
resourceRelationshipQueryWrapper.eq("resource_id",id);
List<ResourceRelationship> resourceRelationshipList = resourceRelationshipMapper.selectList(resourceRelationshipQueryWrapper);
if(resourceRelationshipList != null){
int delete = resourceRelationshipMapper.delete(resourceRelationshipQueryWrapper);
if(delete <= 0){
return ResultUtils.error(ErrorCode.PARAMS_ERROR,"删除-mysql-resource关系失败");
}
}
boolean f = resourcesRepository.deleteByResourceId(id);
if(f){
return ResultUtils.success("删除成功");
}
return ResultUtils.error(ErrorCode.PARAMS_ERROR,"删除失败");
}
@Override
public BaseResponse<String> recoverdata() {
resourcesRepository.deleteAll();
QueryWrapper<ResourceMysql> resourceMysqlQueryWrapper = new QueryWrapper<>();
List<ResourceMysql> resourceMysqls = resourceMapper.selectList(resourceMysqlQueryWrapper);
for (ResourceMysql rs:resourceMysqls) {
String temp = "CREATE (n:Resources {"
+"name: '"+rs.getName()+"',"
+"resourceId: "+rs.getId()+","
+"url: '"+rs.getUrl()+"',"
+"status: "+rs.getStatus()+","
+"type: "+rs.getType()+","
+"tags: '"+rs.getTags()+"',"
+"description: '"+rs.getDescription()
+"'}) return ID(n)";
Collection<Map<String, Object>> all = neo4jClient.query(temp).fetch().all();
if(all == null){
return ResultUtils.success("恢复失败");
}
System.out.println(all);
}
return ResultUtils.success("恢复成功");
public ResponseEntity<InputStreamResource> readFile(String filename) {
return minioUtils.readFile(filename);
}
}

@ -4,6 +4,7 @@ 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 org.springframework.web.bind.annotation.RequestParam;
import java.util.List;
@ -16,6 +17,8 @@ public interface KnowtmpService {
BaseResponse<String> objectiveaddKnow(String ObjectiveId, Long KnowId);
//查询
BaseResponse<Long> getAllKnows(String courseId);
@ -23,6 +26,9 @@ public interface KnowtmpService {
// 添加知识点
BaseResponse<String> add(KnowtempAdd knowtempAdd);
BaseResponse<String> addObjective( List<String> objectiveIds,Long knowId);
BaseResponse<List<String>> knowObjects( Long knowId);
//修改知识点
BaseResponse<String> update(KnowtempUpdate knowtempUpdate);

@ -2,6 +2,7 @@ package com.teaching.backend.service.resource;
import com.teaching.backend.common.BaseResponse;
import com.teaching.backend.model.entity.resource.ResourceMysql;
import com.teaching.backend.model.entity.resource.Resources;
import org.springframework.core.io.InputStreamResource;
import org.springframework.http.ResponseEntity;
@ -23,6 +24,8 @@ public interface ResourceGraphService {
BaseResponse<String> addResourcesByIdAndResourcesId(Long id, Long resourcesId);
BaseResponse<String> addResourcesByKnowId(Long knowId, Long resourcesId);
//查询课程下资源
BaseResponse<Set<Resources>> queryResourcesByCourseId(String courseId);
@ -33,7 +36,7 @@ public interface ResourceGraphService {
//查询二级节点下资源
BaseResponse<Set<Resources>> queryBesidesKnowToResources(Long knowId);
BaseResponse<Set<Resources>> queryResourcesByKnowId(Long knowId);
BaseResponse<Set<Resources>> queryResourcesById(Long knowId);
}

@ -5,6 +5,8 @@ import com.teaching.backend.common.BaseResponse;
import com.teaching.backend.model.entity.resource.ResourceMysql;
import org.springframework.web.multipart.MultipartFile;
import java.util.List;
/**
* <p>
* 服务类
@ -13,7 +15,11 @@ import org.springframework.web.multipart.MultipartFile;
* @author author
* @since 2024-09-02
*/
public interface IResourceMysqlService extends IService<ResourceMysql> {
public interface ResourceMysqlService {
BaseResponse<List<ResourceMysql>> queryResourcesByKnowId(Long knowId);
BaseResponse<List<ResourceMysql>> queryResourcesByCourseId(String courseId);
BaseResponse<String> resourceUpload(MultipartFile file, ResourceMysql resourceMysql);
}

@ -0,0 +1,30 @@
package com.teaching.backend.service.resource;
import com.teaching.backend.common.BaseResponse;
import com.teaching.backend.model.dto.resource.ResourceRelationshipDto;
import com.teaching.backend.model.entity.resource.Resources;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.io.InputStream;
import java.util.Set;
/**
* @Author:youhang
* @Date:2024-07-26-13:55
* @Description:
*/
public interface ResourceRelationshipService {
BaseResponse<String> addResourcesRel(ResourceRelationshipDto resourceRelationshipDto);
BaseResponse<String> deleteResourcesRel(Long knowId, Long resourceId);
}

@ -2,12 +2,17 @@ package com.teaching.backend.service.resource;
import com.teaching.backend.common.BaseResponse;
import com.teaching.backend.model.dto.resource.ResourceUploadDto;
import com.teaching.backend.model.entity.resource.ResourceMysql;
import com.teaching.backend.model.entity.resource.Resources;
import org.springframework.core.io.InputStreamResource;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.io.InputStream;
/**
* @Author:youhang
* @Date:2024-07-26-13:55
@ -16,10 +21,33 @@ import org.springframework.web.multipart.MultipartFile;
public interface ResourceService {
BaseResponse<Resources> upload(MultipartFile file) ;
// BaseResponse<ResourceUploadDto> upload(MultipartFile file) ;
//
// BaseResponse<String> delete(String filename) ;
//
// ResponseEntity<InputStreamResource> readFile(String filename);
BaseResponse<String> uploadOSS(MultipartFile file) throws IOException;
BaseResponse<String> deleteFileOss(String filename) ;
BaseResponse<InputStream> readFile(String filename);
//
BaseResponse<String> addResourceForMysql(MultipartFile file);
BaseResponse<ResourceMysql> addResource(MultipartFile file);
BaseResponse<String> deleteResourceForMysql(long id);
BaseResponse<String> deleteResource(long id);
BaseResponse<String> recoverdata();
BaseResponse<String> delete(String filename) ;
ResponseEntity<InputStreamResource> readFile(String filename);
}

@ -0,0 +1,339 @@
package com.teaching.backend.utils;
import cn.hutool.core.date.DateTime;
import com.aliyun.oss.*;
import com.aliyun.oss.model.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.multipart.MultipartFile;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.Date;
public class AliyunOSSClientUtil {
// log日志
private static Logger logger = LoggerFactory.getLogger(AliyunOSSClientUtil.class);
//oss客户端连接
private static OSS ossclient = null;
public static String getFileName(String filename){
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
// 字符串截取
int dotIndex = filename.lastIndexOf('.');
String prefix = filename.substring(0,dotIndex);
String suffix = filename.substring(dotIndex+1,filename.length());
if(prefix.length() > 10){
prefix = prefix.substring(0,10);
}
filename = prefix+"-"+sdf.format(new DateTime())+"."+suffix;
sdf = new SimpleDateFormat("yyyyMMdd");
// 设置存储对象名称
String objectName = sdf.format(new Date()) + "/" + suffix + "/" + filename;
return objectName;
}
/**
* 获得阿里云OSS客户端对象
* 备注阿里云OSS SDK中提供了自动重连的功能以确保应用程序在遇到网络问题时仍能与OSS有效通信
*
* @param ossEndpoint
* @param accessId
* @param accessKey
* @return
*/
public static OSS getOssClient(String ossEndpoint, String accessId, String accessKey) {
if (ossclient == null) {
ClientBuilderConfiguration conf = new ClientBuilderConfiguration();
// 设置OSSClient允许打开的最大HTTP连接数,默认为1024个。
conf.setMaxConnections(500);
// 设置Socket层传输数据的超时时间,默认为50000毫秒。
conf.setSocketTimeout(10000);
// 设置建立连接的超时时间,默认为50000毫秒。
conf.setConnectionTimeout(10000);
// 设置从连接池中获取连接的超时时间(单位:毫秒),默认不超时。
conf.setConnectionRequestTimeout(10000);
// 设置连接空闲超时时间。超时则关闭连接,默认为60000毫秒。
conf.setIdleConnectionTime(10000);
// 设置失败请求重试次数,默认为3次。
conf.setMaxErrorRetry(5);
ossclient = new OSSClientBuilder().build(ossEndpoint, accessId, accessKey, conf);
}
return ossclient;
}
/**
* 创建存储空间
*
* @param ossClient OSS连接
* @param bucketName 存储空间
* @return
*/
public static String createBucketName(OSS ossClient, String bucketName) {
// 存储空间
final String bucketNames = bucketName;
if (!ossClient.doesBucketExist(bucketName)) {
// 创建存储空间
Bucket bucket = ossClient.createBucket(bucketName);
logger.info("创建存储空间成功");
return bucket.getName();
}
return bucketNames;
}
/**
* 删除存储空间bucketName
*
* @param ossClient oss对象
* @param bucketName 存储空间
*/
public static void deleteBucket(OSS ossClient, String bucketName) {
ossClient.deleteBucket(bucketName);
logger.info("删除" + bucketName + "Bucket成功");
}
/**
* 创建模拟文件夹:多级目录
*
* @param ossClient oss连接
* @param bucketName 存储空间
* @param folder 模拟文件夹名如"upload/2023/01/11/"
* @return 文件夹名
*/
public static String createFolder(OSS ossClient, String bucketName, String folder) {
// 文件夹名
final String keySuffixWithSlash = folder;
// 判断文件夹是否存在,不存在则创建
if (!ossClient.doesObjectExist(bucketName, keySuffixWithSlash)) {
// 创建文件夹
ossClient.putObject(bucketName, keySuffixWithSlash, new ByteArrayInputStream(new byte[0]));
logger.info("创建文件夹成功");
// 得到文件夹名
OSSObject object = ossClient.getObject(bucketName, keySuffixWithSlash);
String fileDir = object.getKey();
return fileDir;
}
return keySuffixWithSlash;
}
/**
* 根据key删除OSS服务器上的文件
*
* @param ossClient oss连接
* @param bucketName 存储空间
* @param key Bucket下的文件的路径名+文件名 "upload/2023/01/11/cake.jpg"
*/
public static void deleteObject(OSS ossClient, String bucketName, String key) {
ossClient.deleteObject(bucketName, key);
logger.info("删除" + bucketName + "下的文件" + key + "成功");
}
/**
* 上传文件
*
* @param ossClient oss连接
* @param bucketName 存储空间
* @param ossPath 上传文件相对路径+文件名如"upload/2023/01/11/cake.jpg"
* @param is 以输入流的形式上传文件
* @param fileName 上传文件后新文件名
* @return String 返回的唯一MD5数字签名
*/
public static String uploadFileOss(OSS ossClient, String bucketName, String ossPath, InputStream is, String fileName) {
try {
// 文件大小
long fileSize = is.available();
// 创建上传Object的Metadata
ObjectMetadata metadata = new ObjectMetadata();
// 上传的文件的长度
metadata.setContentLength(is.available());
// 指定该Object被下载时的网页的缓存行为
metadata.setCacheControl("no-cache");
// 指定该Object下设置Header
metadata.setHeader("Pragma", "no-cache");
// 指定该Object被下载时的内容编码格式
metadata.setContentEncoding("utf-8");
// 文件的MIME,定义文件的类型及网页编码,决定浏览器将以什么形式、什么编码读取文件。如果用户没有指定则根据Key或文件名的扩展名生成,
// 如果没有扩展名则填默认值application/octet-stream
metadata.setContentType(getContentType(fileName));
// 指定该Object被下载时的名称(指示MINME用户代理如何显示附加的文件,打开或下载,及文件名称)
metadata.setContentDisposition("filename/filesize=" + fileName + "/" + fileSize + "Byte");
//上传文件到OSS时需要指定包含文件后缀在内的完整路径如ossPath="upload/2023/01/11/cake.jpg"
// PutObjectResult putResult = ossClient.putObject(bucketName, ossPath, is, metadata);
PutObjectResult putResult = ossClient.putObject(bucketName, ossPath, is, metadata);
// 解析结果
String resultStr = putResult.getETag();
logger.info("唯一MD5数字签名:" + resultStr);
//上传文件后相对路径如"upload/2023/01/11/cake.jpg"
String path = ossPath;
return path;
} catch (Exception e) {
e.printStackTrace();
logger.error("上传阿里云OSS服务器异常." + e.getMessage(), e);
return null;
}
}
/**
* 下载文件到本地
*
* @param ossClient oss连接
* @param bucketName 存储空间
* @param key Bucket下的文件的路径名+文件名 "upload/2023/01/11/cake.jpg"
* @param localFilePath 下载本地文件绝对路径如"C:\Users\Administrator\Desktop\oss-download\xxx.pdf"
*/
public static void downloadFileOss(OSS ossClient, String bucketName, String key, String localFilePath) {
try {
//创建本地文件
File file = new File(localFilePath);
GetObjectRequest objectRequest = new GetObjectRequest(bucketName, key);
//下载OSS文件到本地文件,若指定的本地文件存在则覆盖,否则新建
ossClient.getObject(objectRequest, file);
logger.info("下载文件到本地成功");
} catch (OSSException e) {
e.printStackTrace();
} catch (ClientException e) {
e.printStackTrace();
}
}
/**
* 获取上传文件对象
* 备注最重要的是获取上传文件的输出流InputStream
*
* @param ossClient oss连接
* @param bucketName 存储空间
* @param key Bucket下的文件的路径名+文件名 "upload/2023/01/11/cake.jpg"
* @return
*/
public static OSSObject getObject(OSS ossClient, String bucketName, String key) {
OSSObject object = null;
try {
object = ossClient.getObject(bucketName, key);
//文件大小
long fileSize = object.getObjectMetadata().getContentLength();
//文件相对路径
String ossPath = object.getKey();
//文件输入流
InputStream is = object.getObjectContent();
logger.info("success to getObject,fileSize:" + fileSize + "\nossPath:" + ossPath + "\ninputStream:" + is);
} catch (OSSException e) {
e.printStackTrace();
} catch (ClientException e) {
e.printStackTrace();
}
return object;
}
/**
* 获取上传文件url
*
* @param ossClient
* @param bucketName
* @param key
* @return
*/
public static String getUrl(OSS ossClient, String bucketName, String key) {
//设置URl过期时间为99年:3600L*1000*24*365*99
Date expiration = new Date(new Date().getTime() + 3600l * 1000 * 24 * 365 * 99);
GeneratePresignedUrlRequest generatePresignedUrlRequest = new GeneratePresignedUrlRequest(bucketName, key);
generatePresignedUrlRequest.setExpiration(expiration);
URL url = ossClient.generatePresignedUrl(generatePresignedUrlRequest);
String returnUrl = url.toString();
return returnUrl;
}
/**
* 通过文件名判断并获取OSS服务文件上传时文件的contentType
*
* @param fileName 文件名
* @return 文件的contentType
*/
public static String getContentType(String fileName) {
// 文件的后缀名
String fileExtension = fileName.substring(fileName.lastIndexOf("."));
logger.info("getContentType->fileName={},fileExtension={}", fileName, fileExtension);
for (AliyunOssFileTypeEnum e : AliyunOssFileTypeEnum.values()) {
if (e.getCode().equalsIgnoreCase(fileExtension)) {
return e.getText();
}
}
// 默认返回类型
return AliyunOssFileTypeEnum.TXT.getText();
}
// 测试
public static void main(String[] args) throws FileNotFoundException {
//阿里云OSS账号自行到阿里云官网申请
String ossEndpoint = "XXX";
String accessId = "XXX";
String accessKey = "XXX";
String bucketName = "test";
// 初始化OSSClient
OSS ossClient = AliyunOSSClientUtil.getOssClient(ossEndpoint, accessId, accessKey);
//测试创建多级目录
/*String tmpDir = "upload/2023/01/11/";
String folder = createFolder(ossClient, bucketName, tmpDir);
System.out.println("folder:"+folder);*/
//测试删除文件
/*String key="upload/2023/01/11/xxx.pdf";
deleteObject(ossClient,bucketName,key);*/
//测试上传文件
/*String pathAndname = "C:\\Users\\Administrator\\Desktop\\测试文件上传\\xxx.pdf";
File file = new File(pathAndname);
//原始文件名:带后缀
String oldfilename = file.getName();
//新文件名:带后缀
String newfilename = "9065df0f3ab72419b36d2dec088e11d6.pdf";//可以自行生成随机唯一文件名
String newpath = "C:\\Users\\Administrator\\Desktop\\upload\\2023\\01\\11\\";
String ossPath = newpath + newfilename;
InputStream is = new FileInputStream(file);
String absolutePath = uploadFileOss(ossClient, bucketName, ossPath, is, newfilename);
System.out.println("absolutePath:"+absolutePath);*/
//测试获取文件url
/*String key="upload/2023/01/11/9065df0f3ab72419b36d2dec088e11d6.pdf";
String url = getUrl(ossClient, bucketName, key);
System.out.println("url:"+url);*/
//测试获取上传对象
/*String key = "upload/2023/01/11/9065df0f3ab72419b36d2dec088e11d6.pdf";
getObject(ossClient, bucketName, key);*/
//测试下载文件到本地
/*String key = "upload/2023/01/11/9065df0f3ab72419b36d2dec088e11d6.pdf";
String localFilePath = "C:\\Users\\Administrator\\Desktop\\oss-download\\xxx.pdf";
downloadFileOss(ossClient, bucketName, key, localFilePath);*/
}
}

@ -0,0 +1,58 @@
package com.teaching.backend.utils;
public enum AliyunOssFileTypeEnum {
BMP(".bmp","image/bmp"),
GIF(".gif","image/gif"),
JPEG(".jpeg","image/jpeg"),
JPG(".jpg","image/jpeg"),
PNG(".png","image/jpeg"),
HTML(".html","text/html"),
XML(".xml","text/xml"),
TXT(".txt","application/octet-stream"),
SQL(".sql","application/octet-stream"),
VSD(".vsd","application/vnd.visio"),
PDF(".pdf","application/pdf"),
PPT(".ppt","application/vnd.ms-powerpoint"),
PPTX(".pptx","application/vnd.ms-powerpoint"),
DOC(".doc","application/msword"),
DOCX(".docx","application/msword"),
XLS(".xls","application/vnd.ms-excel"),
XLSX(".xlsx","application/vnd.ms-excel"),
CSV(".csv","application/vnd.ms-excel");
String code;
String text;
AliyunOssFileTypeEnum() {
}
AliyunOssFileTypeEnum(String code, String text) {
this.code = code;
this.text = text;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
}

@ -90,6 +90,7 @@ public class MinioUtils {
.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);

@ -0,0 +1,83 @@
server:
port: 8080
spring:
application:
name: teaching-backend
servlet:
multipart:
enabled: true
max-file-size: 10MB
max-request-size: 10MB
neo4j:
uri: bolt://10.121.12.242:7687
authentication:
username: neo4j # 连接Neo4j数据P库的用户名
password: neo4j123456 # 连接Neo4j数据库的密码
mvc:
pathmatch:
matching-strategy: ant_path_matcher
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://10.121.12.242:3306/teaching_db2
username: root
password: root
mybatis:
configuration:
map-underscore-to-camel-case: true
mapper-locations:
- classpath:mapper/*.xml
- classpath*:com/**/mapper/*.xml
jwt:
tokenHeader: Authorization
secret: mySecret
expiration: 604800
tokenHead: Bearer
knife4j:
enable: true
openapi:
title: 111
description: "123"
concat: zjh
version: v1.0.0
group:
default:
group-name: default
api-rule: package
api-rule-resources:
- com.teaching.backend.controller
secure:
ignored:
urls:
# - /swagger-ui/
# - /swagger-resources/**
# - /**/v2/api-docs
# - /**/*.html
# - /**/*.js
# - /**/*.css
# - /**/*.png
# - /**/*.map
# - /favicon.ico
# - /actuator/**
# - /druid/**
# - /user/**
# - /user/login
# - /user/register
# - /user/info
# - /user/logout
# - /minio/upload
- /**
aliyun:
oss:
endpoint: oss-cn-wuhan-lr.aliyuncs.com
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

@ -9,34 +9,32 @@ spring:
max-file-size: 10MB
max-request-size: 10MB
neo4j:
uri: bolt://39.106.16.162:7687
uri: bolt://10.121.12.242:7687
authentication:
username: neo4j # 连接Neo4j数据P库的用户名
password: 123456 # 连接Neo4j数据库的密码
username: neo4j # 连接Neo4j数据库的用户名
password: neo4j123456 # 连接Neo4j数据库的密码
mvc:
pathmatch:
matching-strategy: ant_path_matcher
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
# url: jdbc:mysql://127.0.0.1:3306/teaching_db
# username: root
# password: root
url: jdbc:mysql://rm-bp189rd5595301145do.mysql.rds.aliyuncs.com:3306/teaching_db
username: root123
password: Zjh@111111
# url: jdbc:mysql://127.0.0.1:3306/teaching_db
# username: root
# password: root
url: jdbc:mysql://10.121.12.242:3306/teaching_db2
username: root
password: root
mybatis:
configuration:
map-underscore-to-camel-case: true
mapper-locations:
- classpath:mapper/*.xml
- classpath*:com/**/mapper/*.xml
jwt:
tokenHeader: Authorization
secret: mySecret
expiration: 604800
tokenHead: Bearer
knife4j:
enable: true
openapi:
@ -53,38 +51,35 @@ knife4j:
secure:
ignored:
urls:
# - /swagger-ui/
# - /swagger-resources/**
# - /**/v2/api-docs
# - /**/*.html
# - /**/*.js
# - /**/*.css
# - /**/*.png
# - /**/*.map
# - /favicon.ico
# - /actuator/**
# - /druid/**
# - /user/**
# - /user/login
# - /user/register
# - /user/info
# - /user/logout
# - /minio/upload
# - /swagger-ui/
# - /swagger-resources/**
# - /**/v2/api-docs
# - /**/*.html
# - /**/*.js
# - /**/*.css
# - /**/*.png
# - /**/*.map
# - /favicon.ico
# - /actuator/**
# - /druid/**
# - /user/**
# - /user/login
# - /user/register
# - /user/info
# - /user/logout
# - /minio/upload
- /**
aliyun:
oss:
endpoint: oss-cn-wuhan-lr.aliyuncs.com
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

@ -0,0 +1,22 @@
${AnsiColor.BRIGHT_RED}_ooOoo_ ${AnsiColor.BRIGHT_YELLOW}
${AnsiColor.BRIGHT_RED}o8888888o ${AnsiColor.BRIGHT_YELLOW}
${AnsiColor.BRIGHT_RED}88${AnsiColor.BRIGHT_YELLOW}" . "${AnsiColor.BRIGHT_RED}88 ${AnsiColor.BRIGHT_YELLOW}
(| -_- |) ${AnsiColor.BRIGHT_YELLOW}
${AnsiColor.BLUE}O${AnsiColor.BRIGHT_YELLOW}\ = /${AnsiColor.BLUE}O ${AnsiColor.BRIGHT_YELLOW}
____/`---'\____ ${AnsiColor.BRIGHT_YELLOW}
.' \\| |// `. ${AnsiColor.BRIGHT_YELLOW}
/ \\||| : |||// \ ${AnsiColor.BRIGHT_YELLOW}
/ _||||| -:- |||||- \ ${AnsiColor.BRIGHT_YELLOW}
| | \\\ - /// | | ${AnsiColor.BRIGHT_YELLOW}
| \_| ''\---/'' | | ${AnsiColor.BRIGHT_YELLOW}
\ .-\__ `-` ___/-. / ${AnsiColor.BRIGHT_YELLOW}
___`. .' /--.--\ `. . __ ${AnsiColor.BRIGHT_YELLOW}
."" '< `.___\_<|>_/___.' >'"". ${AnsiColor.BRIGHT_YELLOW}
| | : `- \`.;`\ _ /`;.`/ - ` : | | ${AnsiColor.BRIGHT_YELLOW}
\ \ `-. \_ __\ /__ _/ .-` / / ${AnsiColor.BRIGHT_YELLOW}
${AnsiColor.BRIGHT_MAGENTA}======${AnsiColor.BRIGHT_YELLOW}`-.____`-.___\_____/___.-`____.-'${AnsiColor.BRIGHT_MAGENTA}======
`=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
^ 佛祖保佑 永无BUG ^
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

@ -2,23 +2,5 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.teaching.backend.mapper.courses.CourseObjectivesMapper">
<select id="selectTreeNodes" resultType="com.teaching.backend.model.vo.courses.CourseObjectivesTreeVO"
parameterType="string">
with recursive t1 as (
select * from course_objectives where id=#{courseObjectivesId}
union all
select t2.* from course_objectives t2 inner join t1 on t1.id = t2.pid
)
select * from t1
order by t1.type
</select>
<insert id="insertBatch" parameterType="java.util.List">
INSERT INTO course_objectives (id, type, pid)
VALUES
<foreach collection="list" item="item" index="index" separator=",">
(#{item.id}, #{item.type},#{item.pid})
</foreach>
</insert>
</mapper>

@ -1,13 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.teaching.backend.mapper.courses.ObjectiveContentKnowMapper">
<insert id="insertBatchSomeColumn" parameterType="java.util.List">
INSERT INTO objective_content_know (objective_or_content, know)
VALUES
<foreach collection="list" item="item" index="index" separator=",">
(#{item.objectiveOrContent}, #{item.know})
</foreach>
</insert>
</mapper>

@ -1,5 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.teaching.backend.mapper.courses.ObjectiveContentsMapper">
</mapper>

@ -70,7 +70,7 @@
s.major major,
s.year_age yearAge,
s.class_name className,
S.user_id userId
s.user_id userId
FROM
ums_student s
WHERE

@ -2,11 +2,14 @@ package com.teaching;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import java.util.*;
@SpringBootTest
@EnableTransactionManagement
class TeachingBackendApplicationTests {
public static void main(String[] args) {

@ -0,0 +1,29 @@
package com.teaching.yh;
/**
* @Author:youhang
* @Date:2024-10-12-7:31
* @Description:
*/
public class testTryCatch {
}
class Test04 {
public static void main(String[] args) {
System.out.println(test());
}
private static int test() {
int temp = 1;
try {
System.out.println(temp);
} catch (Exception e) {
System.out.println(temp);
return ++temp;
} finally {
++temp;
System.out.println(temp);
}
return ++temp;
}
}
Loading…
Cancel
Save