Merge branch 'master' of 39.106.16.162:/home/git/teaching-backend/teaching-backend

# Conflicts:
#	src/main/java/com/teaching/backend/controller/records/ResourceLearningRecordController.java
#	src/main/java/com/teaching/backend/service/impl/records/ResourceLearningRecordServiceImpl.java
#	src/main/java/com/teaching/backend/service/records/IResourceLearningRecordService.java
master
yh 5 months ago
commit 205de3c972
  1. 19
      pom.xml
  2. 2
      src/main/java/com/teaching/backend/common/ErrorCode.java
  3. 23
      src/main/java/com/teaching/backend/config/NonStaticResourceHttpRequestHandler.java
  4. 22
      src/main/java/com/teaching/backend/controller/courses/CoursesController.java
  5. 1
      src/main/java/com/teaching/backend/controller/courses/ObjectiveContentsController.java
  6. 4
      src/main/java/com/teaching/backend/controller/favour/SeCourseFavourController.java
  7. 46
      src/main/java/com/teaching/backend/controller/records/BaseSourceApiController.java
  8. 56
      src/main/java/com/teaching/backend/controller/records/Bf.java
  9. 2
      src/main/java/com/teaching/backend/controller/records/CourseLearningRecordController.java
  10. 66
      src/main/java/com/teaching/backend/controller/records/KnowledgeLearningRecordController.java
  11. 93
      src/main/java/com/teaching/backend/controller/records/ResourceLearningRecordController.java
  12. 6
      src/main/java/com/teaching/backend/controller/umsAdmin/ReportController.java
  13. 6
      src/main/java/com/teaching/backend/mapper/favour/SeCourseFavourMapper.java
  14. 11
      src/main/java/com/teaching/backend/mapper/records/KnowledgeLearningRecordMapper.java
  15. 6
      src/main/java/com/teaching/backend/mapper/records/ResourceLearningRecordMapper.java
  16. 32
      src/main/java/com/teaching/backend/model/dto/upload/UploadFileParamsDto.java
  17. 4
      src/main/java/com/teaching/backend/model/entity/records/KnowledgeLearningRecord.java
  18. 4
      src/main/java/com/teaching/backend/model/entity/records/ResourceLearningRecord.java
  19. 44
      src/main/java/com/teaching/backend/model/vo/courses/PersonalCenterStudentListVO.java
  20. 1
      src/main/java/com/teaching/backend/model/vo/knowGraph/KnowVO.java
  21. 4
      src/main/java/com/teaching/backend/model/vo/records/CourseLearningRecordsVo.java
  22. 37
      src/main/java/com/teaching/backend/model/vo/records/KnowledgeLearningRecordVo.java
  23. 29
      src/main/java/com/teaching/backend/model/vo/records/ResourceLearingRecordVo.java
  24. 3
      src/main/java/com/teaching/backend/service/courses/ICoursesService.java
  25. 2
      src/main/java/com/teaching/backend/service/favour/SeCourseFavourService.java
  26. 40
      src/main/java/com/teaching/backend/service/impl/courses/CourseObjectivesServiceImpl.java
  27. 86
      src/main/java/com/teaching/backend/service/impl/courses/CoursesServiceImpl.java
  28. 29
      src/main/java/com/teaching/backend/service/impl/courses/ObjectiveContentKnowServiceImpl.java
  29. 2
      src/main/java/com/teaching/backend/service/impl/courses/ObjectiveContentsServiceImpl.java
  30. 22
      src/main/java/com/teaching/backend/service/impl/favour/SeCourseFavourServiceImpl.java
  31. 6
      src/main/java/com/teaching/backend/service/impl/records/CourseLearningRecordServiceImpl.java
  32. 116
      src/main/java/com/teaching/backend/service/impl/records/KnowledgeLearningRecordServiceImpl.java
  33. 147
      src/main/java/com/teaching/backend/service/impl/records/ResourceLearningRecordServiceImpl.java
  34. 29
      src/main/java/com/teaching/backend/service/impl/report/ReportServiceImpl.java
  35. 13
      src/main/java/com/teaching/backend/service/records/IKnowledgeLearningRecordService.java
  36. 9
      src/main/java/com/teaching/backend/service/records/IResourceLearningRecordService.java
  37. 2
      src/main/java/com/teaching/backend/service/report/ReportService.java
  38. 5
      src/main/java/com/teaching/backend/utils/Constants.java
  39. 4
      src/main/java/com/teaching/backend/utils/CourseCode.java
  40. 115
      src/main/java/com/teaching/backend/utils/UploadUtils.java
  41. 5
      src/main/resources/mapper/CourseLearningRecordMapper.xml
  42. 20
      src/main/resources/mapper/KnowledgeLearningRecordMapper.xml
  43. 4
      src/main/resources/mapper/SeCourseFavourMapper.xml
  44. 101
      src/test/java/com/teaching/MinioTest.java
  45. 36
      src/test/java/com/teaching/test.java

@ -227,6 +227,25 @@
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
<!-- 文件下载-->
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3.1</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.4.10</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.6</version>
</dependency>
</dependencies>

@ -18,7 +18,7 @@ public enum ErrorCode {
STUDENT_NOT_EXIT(40006, "缺少学生信息"),
COURSES_NOT_EXIT(40007, "缺少课程信息"),
CONTENT_NOT_EXIT(40008, "内容id不存在"),
KNOWS_EXIT(40009, "该项下面存在关联的知识点"),
KNOWS_EXIT(40009, "该项下面存在关联的知识点,请在删除关联的知识点后再来操作!"),
INVALID_ROLE(400010, "角色不存在"),
NOT_LOGIN_ERROR(40100, "未登录"),

@ -0,0 +1,23 @@
package com.teaching.backend.config;
import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.Resource;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.resource.ResourceHttpRequestHandler;
import javax.servlet.http.HttpServletRequest;
/**
* @author longge93
*/
@Component
public class NonStaticResourceHttpRequestHandler extends ResourceHttpRequestHandler {
public final static String ATTR_FILE = "NON-STATIC-FILE";
@Override
protected Resource getResource(HttpServletRequest request) {
String filePath = (String) request.getAttribute(ATTR_FILE);
return new FileSystemResource(filePath);
}
}

@ -3,19 +3,15 @@ package com.teaching.backend.controller.courses;
import com.teaching.backend.common.BaseResponse;
import com.teaching.backend.common.CommonResult;
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.dto.courses.PageDTO;
import com.teaching.backend.model.entity.courses.Courses;
import com.teaching.backend.model.entity.umsAdmin.UmsStudent;
import com.teaching.backend.model.query.CourseQuery;
import com.teaching.backend.model.vo.courses.CoursesVO;
import com.teaching.backend.model.vo.umsAdmin.UmsStudentVO;
import com.teaching.backend.model.vo.courses.PersonalCenterStudentListVO;
import com.teaching.backend.service.courses.ICoursesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@ -24,7 +20,9 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.util.*;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.Map;
/**
* <p>
@ -87,7 +85,6 @@ public class CoursesController {
@ApiOperation("查询课程列表")
@ValidateParams({"userId"})
@GetMapping("/page")
// @PostMapping("/page")
public BaseResponse<PageDTO<CoursesVO>> getCourses(CourseQuery courseQuery){
PageDTO<CoursesVO> coursesList = coursesService.queryCourses(courseQuery);
return ResultUtils.success(coursesList);
@ -97,9 +94,6 @@ public class CoursesController {
@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);
@ -114,16 +108,12 @@ public class CoursesController {
return ResultUtils.success("编辑成功");
}
//TODO:删除功能暂未完善,数据缺失
// 暂时发现有个漏洞 就是目标关联的有知识点的时候还是可以直接删除
// (当有内容的时候本来就是得先删除内容--关联也有知识点 所以内容下面的不用校验 )
@ApiOperation("根据id删除课程")
@ValidateParams({"id"})
@DeleteMapping("/{id}")
public BaseResponse deleteCourses(@PathVariable String id){
coursesService.deleteBatchByIds(id);
// coursesService.removeBatchByIds(ids);
return ResultUtils.success("删除成功");
}
@ -142,8 +132,8 @@ public class CoursesController {
@ApiOperation("查询学生列表")
@PostMapping("/studentList")
public CommonResult<LinkedHashSet<UmsStudent>> getStudentList(CourseQuery courseQuery){
LinkedHashSet<UmsStudent> umsStudentList = coursesService.queryStudentList(courseQuery);
public CommonResult<LinkedHashSet<PersonalCenterStudentListVO>> getStudentList(@RequestParam String userId){
LinkedHashSet<PersonalCenterStudentListVO> umsStudentList = coursesService.queryStudentList(userId);
return CommonResult.success(umsStudentList);
}

@ -39,7 +39,6 @@ public class ObjectiveContentsController {
@ValidateParams({"id"})
@DeleteMapping("/{id}")
public BaseResponse<String> deleteContent(@PathVariable String id){
// objectiveContentsService.removeById(id);
String data = objectiveContentsService.deleteById(id);
return ResultUtils.success(data);
}

@ -99,8 +99,8 @@ public class SeCourseFavourController {
*/
@ApiOperation("查询最新收藏")
@PostMapping("/newCollect")
public CommonResult<CoursesVO> newCollect(@RequestParam String userId) {
CoursesVO newCoursesVO = seCourseFavourService.queryNewCollect(userId);
public CommonResult<List<CoursesVO>> newCollect(@RequestParam String userId) {
List<CoursesVO> newCoursesVO = seCourseFavourService.queryNewCollect(userId);
if (newCoursesVO == null){
CommonResult.failed("用户或角色错误");
}

@ -0,0 +1,46 @@
package com.teaching.backend.controller.records;
import com.teaching.backend.config.NonStaticResourceHttpRequestHandler;
import org.mybatis.logging.Logger;
import org.mybatis.logging.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.nio.charset.StandardCharsets;
@RestController
@RequestMapping(value = "/api/baseResource")
public class BaseSourceApiController {
@Autowired
private NonStaticResourceHttpRequestHandler nonStaticResourceHttpRequestHandler;
private final Logger logger = LoggerFactory.getLogger(this.getClass());
@RequestMapping(value = "/video", method = RequestMethod.GET)
public void video(
HttpServletRequest request,
HttpServletResponse response
) {
try {
String path = "D:/Users/Desktop/image/剪映/7.18/7月20.mp4";
File file = new File(path);
if (file.exists()) {
request.setAttribute(NonStaticResourceHttpRequestHandler.ATTR_FILE, path);
nonStaticResourceHttpRequestHandler.handleRequest(request, response);
} else {
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
response.setCharacterEncoding(StandardCharsets.UTF_8.toString());
}
} catch (Exception e) {
}
}
}

@ -0,0 +1,56 @@
package com.teaching.backend.controller.records;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletResponse;
import java.io.FileInputStream;
import java.io.OutputStream;
@RestController
@RequestMapping("/api/bf")
public class Bf {
/**
* 根据本地图片全路径响应给浏览器1个图片流
*/
@RequestMapping("/showImage")
public void showImage(HttpServletResponse response, @RequestParam("fileName")String fileName) {
System.out.println(fileName);
show(response,fileName,"image");
}
/**
* 根据本地视频全路径响应给浏览器1个视频
*/
@RequestMapping("/showVideo")
public void showVideo(HttpServletResponse response, @RequestParam("fileName")String fileName) {
show(response,fileName,"video");
}
/**
* 响应文件
* @param response
* @param fileName 文件全路径
* @param type 响应流类型
*/
public void show(HttpServletResponse response, String fileName,String type){
try{
FileInputStream fis = new FileInputStream(fileName); // 以byte流的方式打开文件
int i=fis.available(); //得到文件大小
System.out.println(i);
byte data[]=new byte[i];
fis.read(data); //读数据
response.setContentType(type+"/*"); //设置返回的文件类型
OutputStream toClient=response.getOutputStream(); //得到向客户端输出二进制数据的对象
toClient.write(data); //输出数据
toClient.flush();
toClient.close();
fis.close();
}catch(Exception e){
e.printStackTrace();
System.out.println("文件不存在");
}
}
}

@ -61,7 +61,7 @@ public class CourseLearningRecordController {
* 个人中心课程列表
* @return
*/
@ApiOperation("查询前4的课程")
@ApiOperation("按新旧排序查询的课程列表")
@PostMapping("/courseList")
public CommonResult<List<CoursesVO>> courseList(@RequestParam String userId) {
List<CoursesVO> coursesVOList = courseLearningRecordService.queryCourseList(userId);

@ -1,24 +1,28 @@
package com.teaching.backend.controller.records;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.teaching.backend.common.BaseResponse;
import com.teaching.backend.common.CommonResult;
import com.teaching.backend.common.ResultUtils;
import com.teaching.backend.filter.ValidateParams;
import com.teaching.backend.mapper.records.KnowledgeLearningRecordMapper;
import com.teaching.backend.model.entity.records.CourseLearningRecord;
import com.teaching.backend.model.entity.records.KnowledgeLearningRecord;
import com.teaching.backend.model.vo.knowGraph.KnowVO;
import com.teaching.backend.service.impl.records.KnowledgeLearningRecordServiceImpl;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
@RestController
@RequestMapping("/api/knowledgelearning")
public class KnowledgeLearningRecordController {
@Resource
private KnowledgeLearningRecordServiceImpl knowledgeLearningRecordService;
@Resource
private KnowledgeLearningRecordMapper knowledgeLearningRecordMapper;
@ApiOperation("添加知识点学习记录")
// @ValidateParams({"userId","type","coursesId"})
@ -27,4 +31,58 @@ public class KnowledgeLearningRecordController {
return knowledgeLearningRecordService.saveCoursesRecords(knowledgeLearningRecord);
}
/**
* 获取当前登录用户的学习知识点记录
* @param pagenum
* @param pagesize
* @return
*/
@ApiOperation("根据用户id查询学习记录")
@ValidateParams({"userId"})
@GetMapping("/page")
public BaseResponse<Page> getAll(@RequestParam(value = "pagenum", defaultValue = "1") int pagenum,
@RequestParam(value = "pagesize", defaultValue = "10") int pagesize,
@RequestParam String userId,
@RequestParam String courseId){
return knowledgeLearningRecordService.getPage(pagenum, pagesize, userId, courseId);
}
/**
* 根据ids删除
* @param ids
* @return
*/
@ApiOperation("学习记录删除")
@DeleteMapping("/delete")
public BaseResponse<String> deleteRecords(@RequestParam List<Long> ids){
return knowledgeLearningRecordService.removeKnowledgeRecord(ids);
}
/**
* 统计单个学生学习知识点数量
* @param userId
* @return
*/
@ApiOperation("统计单个学生学习知识点数量")
@GetMapping("/countknowledgenumber")
public BaseResponse<Integer> countKnowledgeNumber(@RequestParam String userId) {
return ResultUtils.success(knowledgeLearningRecordMapper.selectDistinctKnowledgeIdsByUser(userId).size());
}
/**
* 获取学习最多的知识点
*
* @return
*/
@ApiOperation("查询学习最多的知识点")
@PostMapping("/studyMaxKnowledge")
public CommonResult<List<KnowVO>> studyMaxKnowledge(@RequestParam String userId) {
List<KnowVO> knowVO = knowledgeLearningRecordService.queryMaxKnowledge(userId);
if (knowVO == null){
CommonResult.failed("用户或角色错误");
}
return CommonResult.success(knowVO);
}
}

@ -1,29 +1,102 @@
package com.teaching.backend.controller.records;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.teaching.backend.common.BaseResponse;
import com.teaching.backend.common.ResultUtils;
import com.teaching.backend.filter.ValidateParams;
import com.teaching.backend.mapper.records.ResourceLearningRecordMapper;
import com.teaching.backend.model.entity.records.KnowledgeLearningRecord;
import com.teaching.backend.model.entity.records.ResourceLearningRecord;
import com.teaching.backend.service.impl.records.KnowledgeLearningRecordServiceImpl;
import com.teaching.backend.service.impl.records.ResourceLearningRecordServiceImpl;
import com.teaching.backend.utils.UploadUtils;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.util.List;
@RestController
@RequestMapping("/api/resourcelearningrecords")
public class ResourceLearningRecordController {
@Resource
private ResourceLearningRecordServiceImpl resourceLearningRecordService;
@Resource
private ResourceLearningRecordMapper resourceLearningRecordMapper;
@ApiOperation("添加资源学习记录")
// @ValidateParams({"userId","type","coursesId"})
@PostMapping("/saverecords")
public BaseResponse<String> saveResourceRecords(@RequestBody ResourceLearningRecord resourceLearningRecord) {
return resourceLearningRecordService.saveCoursesRecords(resourceLearningRecord);
}
/**
* 获取当前登录用户的学习资源记录
* @param pagenum
* @param pagesize
* @return
*/
@ApiOperation("根据用户id查询学习记录")
@ValidateParams({"userId"})
@GetMapping("/page")
public BaseResponse<Page> getAll(@RequestParam(value = "pagenum", defaultValue = "1") int pagenum,
@RequestParam(value = "pagesize", defaultValue = "10") int pagesize,
@RequestParam String userId,
@RequestParam String courseId,
@RequestParam String knowledgeId){
return resourceLearningRecordService.getPage(pagenum, pagesize, userId, knowledgeId,courseId);
}
/**
* 根据ids删除
* @param ids
* @return
*/
@ApiOperation("学习记录删除")
@DeleteMapping("/delete")
public BaseResponse<String> deleteRecords(@RequestParam List<Long> ids){
return resourceLearningRecordService.removeResourceRecord(ids);
}
/**
* 统计单个学生学习资源数量
* @param userId
* @return
*/
@ApiOperation("统计单个学生学习资源数量")
@GetMapping("/countresourcenumber")
public BaseResponse<Integer> countResourceNumber(@RequestParam String userId) {
return ResultUtils.success(resourceLearningRecordMapper.selectDistinctResourceIdsByUser(userId).size());
}
@ApiOperation("上传图片")
@PostMapping(value = "/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public BaseResponse<String> upload(@RequestPart("filedata") MultipartFile filedata) throws IOException {
//调用ser
System.out.println(filedata.getResource());
System.out.println(UploadUtils.saveFileByDirectory(filedata));
// File file = filedata.getResource().getFile();
// UploadUtils.Chunk(file);
// UploadUtils.Merge(file);
//源文件
// File sourseFile = (File) file;
return ResultUtils.success("hello");
};
@GetMapping("/bf")
public BaseResponse<String> bf(@RequestParam String path, File file,HttpServletRequest request, HttpServletResponse response){
File sourseFile = new File(path);
return ResultUtils.success(path);
};
// @ApiOperation("添加资源学习记录")
//// @ValidateParams({"userId","type","coursesId"})
// @PostMapping("/saverecords")
// public BaseResponse<String> saveResourceRecords(@RequestBody ResourceLearningRecord resourceLearningRecord) {
// return resourceLearningRecordService.saveCoursesRecords(resourceLearningRecord);
// }
}

@ -33,11 +33,11 @@ public class ReportController {
* 接收每日浏览量
* @return
*/
@PostMapping("/receptionBrowse")
@GetMapping("/receptionBrowse")
@ApiOperation("接收每日浏览量")
public CommonResult receptionBrowse(@RequestBody ReportDTO reportDTO){
public CommonResult receptionBrowse(){
boolean receptionBrowse = reportService.getReceptionBrowse(reportDTO);
boolean receptionBrowse = reportService.getReceptionBrowse();
if (receptionBrowse == false){
return CommonResult.failed();
}

@ -4,15 +4,17 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.teaching.backend.model.entity.courses.Courses;
import com.teaching.backend.model.entity.favour.SeCourseFavour;
import java.util.List;
/**
* 课程点赞数据库操作
*/
public interface SeCourseFavourMapper extends BaseMapper<SeCourseFavour> {
String queryAllNewCollectCourse();
List<String> queryAllNewCollectCourse();
String queryStudentNewCollectCourse(String userId);
List<String> queryStudentNewCollectCourse(String userId);
}

@ -3,6 +3,12 @@ package com.teaching.backend.mapper.records;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.teaching.backend.model.entity.records.KnowledgeLearningRecord;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.util.List;
import java.util.List;
/**
* <p>
@ -14,4 +20,9 @@ import com.teaching.backend.model.entity.records.KnowledgeLearningRecord;
*/
public interface KnowledgeLearningRecordMapper extends BaseMapper<KnowledgeLearningRecord> {
@Select("SELECT knowledge_id FROM knowledge_learning_record WHERE user_id = #{userId} GROUP BY knowledge_id")
List<String > selectDistinctKnowledgeIdsByUser(@Param("userId") String userId);
List<String> queryStudyKnowledgeMaxNumber();
List<String> queryStudyMaxKnowledgeId(String userId);
}

@ -3,6 +3,10 @@ package com.teaching.backend.mapper.records;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.teaching.backend.model.entity.records.ResourceLearningRecord;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.util.List;
/**
* <p>
@ -13,5 +17,7 @@ import com.teaching.backend.model.entity.records.ResourceLearningRecord;
* @since 2024-07-24
*/
public interface ResourceLearningRecordMapper extends BaseMapper<ResourceLearningRecord> {
@Select("SELECT resource_id FROM resource_learning_record WHERE user_id = #{userId} GROUP BY resource_id")
List<String> selectDistinctResourceIdsByUser(@Param("userId") String userId);
}

@ -0,0 +1,32 @@
package com.teaching.backend.model.dto.upload;
import lombok.Data;
@Data
public class UploadFileParamsDto {
/**
* 文件名称
*/
private String filename;
/**
* 文件类型(文档音频视频)
*/
private String fileType;
/**
* 文件大小
*/
private Long fileSize;
/**
* 标签
*/
private String tags;
/**
* 上传人
*/
private String username;
/**
* 备注
*/
private String remark;
}

@ -37,8 +37,8 @@ public class KnowledgeLearningRecord implements Serializable {
@TableField("knowledge_id")
private String knowledgeId;
@ApiModelProperty(value = "知识点id")
@TableField("knowledge_id")
@ApiModelProperty(value = "知识点名称")
@TableField("knowledge_name")
private String knowledgeName;
@ApiModelProperty(value = "课程id")

@ -37,6 +37,10 @@ public class ResourceLearningRecord implements Serializable {
@TableField("resource_id")
private String resourceId;
@ApiModelProperty(value = "资源名称")
@TableField("resource_name")
private String resourceName;
@ApiModelProperty(value = "知识点id")
@TableField("knowledge_id")
private String knowledgeId;

@ -0,0 +1,44 @@
package com.teaching.backend.model.vo.courses;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import java.io.Serializable;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
/**
* <p>
*
* </p>
*
* @author zjh
* @since 2024-06-12
*/
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
public class PersonalCenterStudentListVO implements Serializable {
/**
* 头像
*/
private String icon;
/**
* 姓名
*/
private String name;
/**
* 学号
*/
private String number;
}

@ -3,7 +3,6 @@ package com.teaching.backend.model.vo.knowGraph;
import lombok.Data;
import java.io.Serializable;
import java.util.List;
@Data

@ -17,6 +17,10 @@ public class CourseLearningRecordsVo {
* 课程学习id
*/
private String id;
/**
* 课程id
*/
private String courseId;
/**
* 课程名称
*/

@ -0,0 +1,37 @@
package com.teaching.backend.model.vo.records;
import io.swagger.annotations.ApiModel;
import lombok.Data;
@Data
@ApiModel(description = "知识点学习记录")
public class KnowledgeLearningRecordVo {
/**
* 知识点学习id
*/
private String id;
/**
* 课程id
*/
private String coursesId;
/**
* 知识点id
*/
private String knowledgeId;
/**
* 知识点名称
*/
private String knowledgeName;
/**
* 用户id
*/
private String userId;
/**
* 学习人数
*/
private Integer number;
/**
* 学习时间
*/
private String time;
}

@ -0,0 +1,29 @@
package com.teaching.backend.model.vo.records;
import io.swagger.annotations.ApiModel;
import lombok.Data;
@Data
@ApiModel(description = "资源学习记录")
public class ResourceLearingRecordVo {
/**
* 资源学习id
*/
private String id;
/**
* 资源名称
*/
private String resourceName;
/**
* 用户id
*/
private String userId;
/**
* 学习人数
*/
private Integer number;
/**
* 学习时间
*/
private String time;
}

@ -8,6 +8,7 @@ import com.teaching.backend.model.entity.courses.Courses;
import com.teaching.backend.model.entity.umsAdmin.UmsStudent;
import com.teaching.backend.model.query.CourseQuery;
import com.teaching.backend.model.vo.courses.CoursesVO;
import com.teaching.backend.model.vo.courses.PersonalCenterStudentListVO;
import com.teaching.backend.model.vo.umsAdmin.UmsStudentVO;
import javax.servlet.http.HttpServletResponse;
@ -46,5 +47,5 @@ public interface ICoursesService extends IService<Courses> {
Map<String, Object> getPagePageSize2(int page, int pageSize);
LinkedHashSet<UmsStudent> queryStudentList(CourseQuery courseQuery);
LinkedHashSet<PersonalCenterStudentListVO> queryStudentList(String userId);
}

@ -61,5 +61,5 @@ public interface SeCourseFavourService extends IService<SeCourseFavour> {
* @param userId
* @return
*/
CoursesVO queryNewCollect(String userId);
List<CoursesVO> queryNewCollect(String userId);
}

@ -25,6 +25,8 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static com.teaching.backend.utils.CourseCode.TOTAL_OBJECTIVE_HAS_NO_CHILD;
/**
* <p>
* 服务实现类
@ -54,33 +56,33 @@ public class CourseObjectivesServiceImpl extends ServiceImpl<CourseObjectivesMap
CourseObjectives courseObjectivesNew = new CourseObjectives();
BeanUtil.copyProperties(courseObjectivesDTO,courseObjectivesNew);
String pid = courseObjectivesDTO.getPid();
// if(pid.equals(null)){
// throw new BusinessException(ErrorCode.NOT_FOUND_ERROR,"pid父节点不能为空");
// }
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,"该类型的目标已存在,禁止重复添加!");
}
if (type!=CourseCode.SI_ZHENG_TYPE.getValue()){
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,"请在添加完思政目标以后再添加此类型目标!");
}
}
courseObjectivesMapper.insert(courseObjectivesNew);
//插入新的课程目标
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);
}
}
return "添加成功";
//往表里面写分项目标
// courseObjectivesMapper.insert(courseObjectivesNew);
// //插入数据以后要把总体目标那边的haschild改成1
// CourseObjectives courseObjectivesOld = courseObjectivesMapper.selectById(pid);
// courseObjectivesOld.setHasChild(1);
// courseObjectivesMapper.updateById(courseObjectivesOld);
}
private Long SZ_EXIT(CourseObjectivesDTO courseObjectivesDTO) {
@ -110,7 +112,7 @@ public class CourseObjectivesServiceImpl extends ServiceImpl<CourseObjectivesMap
if (type == CourseCode.TOTAL_OBJECTIVE_TYPE.getValue()){
throw new BusinessException(ErrorCode.OPERATION_ERROR,"课程总目标只需清除所列内容即可!");
}
//TODO:等到删完内容后判断还是上来就判断?
//等到删完内容后判断还是上来就判断?
Long count = objectiveContentKnowMapper.selectCount(new LambdaQueryWrapper<ObjectiveContentKnow>()
.eq(ObjectiveContentKnow::getObjectiveOrContent, id));
if(count > CourseCode.KNOWS_EXIT.getValue()){
@ -121,9 +123,9 @@ public class CourseObjectivesServiceImpl extends ServiceImpl<CourseObjectivesMap
LambdaQueryWrapper<CourseObjectives> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(CourseObjectives::getPid, pid);
Long countSZ = courseObjectivesMapper.selectCount(queryWrapper);
if (countSZ==CourseCode.SI_ZHENG_EXIT.getValue()){
if (countSZ.equals(CourseCode.SI_ZHENG_EXIT.getValue())){
Long countContentsSZ = getCount(id);
if (countContentsSZ<(CourseCode.CONTENT_EXIT.getValue()))
if (countContentsSZ == (CourseCode.CONTENT_EXIT.getValue()))
{
// 删除操作和更新父目标状态
deleteObjectiveAndUpdateParent(id, pid);
@ -140,7 +142,7 @@ public class CourseObjectivesServiceImpl extends ServiceImpl<CourseObjectivesMap
}
else {
Long countContentsF = getCount(id);
if (countContentsF<CourseCode.CONTENT_EXIT.getValue()){
if (countContentsF == CourseCode.CONTENT_EXIT.getValue()){
courseObjectivesMapper.deleteById(id);
return "删除成功";
}
@ -160,7 +162,7 @@ public class CourseObjectivesServiceImpl extends ServiceImpl<CourseObjectivesMap
private void deleteObjectiveAndUpdateParent(String id, String pid) {
courseObjectivesMapper.deleteById(id);
CourseObjectives parentObjective = courseObjectivesMapper.selectById(pid);
parentObjective.setHasChild(0);
parentObjective.setHasChild(TOTAL_OBJECTIVE_HAS_NO_CHILD.getValue());
courseObjectivesMapper.updateById(parentObjective);
}

@ -29,6 +29,7 @@ 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.umsAdmin.UmsStudentVO;
import com.teaching.backend.service.courses.ICoursesService;
import com.teaching.backend.utils.CourseCode;
@ -38,6 +39,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ResourceUtils;
import org.springframework.util.StringUtils;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
@ -96,63 +98,68 @@ public class CoursesServiceImpl extends ServiceImpl<CoursesMapper, Courses> impl
@Override
@Transactional
public String saveCourseWithObjective(CoursesDTO coursesDTO) {
// String teacher = coursesDTO.getTeacher();
// if (teacher == null || teacher.equals("")) {
// throw new BusinessException(ErrorCode.USERNAME_NOT_EXIT);
// }
// 初始化并生成新的课程ID
Courses courses = new Courses();
String courseId = UUID.randomUUID().toString().replace("-", "");
CourseObjectives courseObjectives = new CourseObjectives();
// 拷贝属性并设置创建时间和ID
BeanUtils.copyProperties(coursesDTO, courses);
courses.setCreateTime(LocalDateTime.now());
courses.setId(courseId);
// 检查课程代码是否已存在
String code = coursesDTO.getCode();
QueryWrapper<Courses> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("code", code);
Long count = coursesMapper.selectCount(queryWrapper);
if (count == 0) {
Long count = query().eq("code", code).count();
if (count > 0) {
throw new BusinessException(ErrorCode.OPERATION_ERROR, "这个课程已经存在了!请联系系统相关人员为您导入课程数据!");
}
// 插入课程信息
int insert = coursesMapper.insert(courses);
if (insert > 0) {
Courses coursesNew = coursesMapper.selectById(courseId);
if (insert <= 0) {
throw new BusinessException(ErrorCode.OPERATION_ERROR, "课程插入失败!");
}
// 插入课程目标信息
CourseObjectives courseObjectives = new CourseObjectives();
courseObjectives.setCourseId(courseId);
courseObjectives.setType(CourseCode.TOTAL_OBJECTIVE_TYPE.getValue());
// courseObjectives.setName(coursesNew.getName() + "课程总体目标");
int insertTotal = courseObjectivesMapper.insert(courseObjectives);
if (insertTotal>0){
CourseObjectives courseTotalObjectives = courseObjectivesMapper.selectOne
(new LambdaQueryWrapper<CourseObjectives>().eq(CourseObjectives::getCourseId, courseId));
if (insertTotal <= 0) {
throw new BusinessException(ErrorCode.OPERATION_ERROR, "课程目标插入失败!");
}
// 获取插入后的课程目标信息
CourseObjectives courseTotalObjectives = courseObjectivesMapper.selectOne(
new LambdaQueryWrapper<CourseObjectives>().eq(CourseObjectives::getCourseId, courseId)
);
String courseTotalObjectivesId = courseTotalObjectives.getId();
List<ObjectivesType> objectivesTypes = objectivesTypeMapper.selectList(new LambdaQueryWrapper<ObjectivesType>());
// 获取所有目标类型并插入子目标
List<ObjectivesType> objectivesTypes = objectivesTypeMapper.selectList(new LambdaQueryWrapper<>());
ArrayList<CourseObjectives> courseObjectivesFList = new ArrayList<>();
CourseObjectives courseObjectivesF = null;
for (ObjectivesType objectivesType : objectivesTypes) {
Integer typeId = objectivesType.getId();
if (!typeId.equals(CourseCode.TOTAL_OBJECTIVE_TYPE.getValue())){
// String typeName = objectivesType.getTypeName();
courseObjectivesF = new CourseObjectives();
courseObjectivesF.setType(typeId);
// courseObjectivesF.setName(typeName);
if (!objectivesType.getId().equals(CourseCode.TOTAL_OBJECTIVE_TYPE.getValue())) {
CourseObjectives courseObjectivesF = new CourseObjectives();
courseObjectivesF.setType(objectivesType.getId());
courseObjectivesF.setPid(courseTotalObjectivesId);
courseObjectivesFList.add(courseObjectivesF);
}
}
// 批量插入子目标并更新父目标的hasChild字段
if (!courseObjectivesFList.isEmpty()) {
courseObjectivesMapper.insertBatch(courseObjectivesFList);
courseTotalObjectives.setHasChild(1);
courseObjectivesMapper.updateById(courseTotalObjectives);
}
}
return "添加成功";
} else {
throw new BusinessException(ErrorCode.OPERATION_ERROR, "这个课程已经存在了!请联系系统相关人员为您导入课程数据!");
}
}
@Override
public PageDTO<CoursesVO> queryCourses(CourseQuery courseQuery) {
// int roleId = Integer.parseInt(umsUserMapper.selectOne(new LambdaQueryWrapper<UmsUser>()
// .eq(UmsUser::getUsername, courseQuery.getUsername())).getRoleId());
UmsUser umsUser = umsUserMapper.selectById(courseQuery.getUserId());
if (umsUser == null){
throw new BusinessException(ErrorCode.PARAMS_USER_NOTEXISTS);
@ -184,9 +191,11 @@ public class CoursesServiceImpl extends ServiceImpl<CoursesMapper, Courses> impl
Page<Courses> p = lambdaQuery()
.like(courseQuery.getName() != null, Courses::getName, courseQuery.getName())
.apply("FIND_IN_SET({0}, teacher)", courseQuery.getUserId())
.eq(courseQuery.getCategory() != null && !courseQuery.getCategory().isEmpty(), Courses::getCategory, courseQuery.getCategory())
.eq(StringUtils.hasText(courseQuery.getCategory()), Courses::getCategory, courseQuery.getCategory())
// .eq(courseQuery.getCategory() != null && !courseQuery.getCategory().isEmpty(), Courses::getCategory, courseQuery.getCategory())
.eq(courseQuery.getNature() != null && !courseQuery.getNature().isEmpty(), Courses::getNature, courseQuery.getNature())
.eq(courseQuery.getAssessmenttype() != null &&!courseQuery.getAssessmenttype().isEmpty(), Courses::getAssessmenttype, courseQuery.getAssessmenttype())
.select(Courses::getId,Courses::getTeacher,Courses::getImg,Courses::getName,Courses::getCredit,Courses::getClasshours)
.page(page);
return PageDTO.of(p,CoursesVO.class);
}
@ -201,6 +210,7 @@ public class CoursesServiceImpl extends ServiceImpl<CoursesMapper, Courses> impl
Page<Courses> p = lambdaQuery()
.like(courseQuery.getName() != null, Courses::getName, courseQuery.getName())
.in(Courses::getId, coursesList)
.select(Courses::getId,Courses::getTeacher,Courses::getImg,Courses::getName,Courses::getCredit,Courses::getClasshours)
.page(page);
return PageDTO.of(p, CoursesVO.class);
}
@ -212,6 +222,7 @@ public class CoursesServiceImpl extends ServiceImpl<CoursesMapper, Courses> impl
.eq(courseQuery.getNature() != null && !courseQuery.getNature().isEmpty(), Courses::getNature, courseQuery.getNature())
.eq(courseQuery.getAssessmenttype() != null &&!courseQuery.getAssessmenttype().isEmpty(), Courses::getAssessmenttype, courseQuery.getAssessmenttype())
.apply(courseQuery.getTeacher() != null && !courseQuery.getTeacher().isEmpty(), "FIND_IN_SET({0}, teacher)", courseQuery.getTeacher())
.select(Courses::getId,Courses::getTeacher,Courses::getImg,Courses::getName,Courses::getCredit,Courses::getClasshours)
.page(page);
return PageDTO.of(p, CoursesVO.class);
}
@ -339,13 +350,15 @@ public class CoursesServiceImpl extends ServiceImpl<CoursesMapper, Courses> impl
}
@Override
public LinkedHashSet<UmsStudent> queryStudentList(CourseQuery courseQuery) {
String roleId = umsUserMapper.getbyIdRoleId(courseQuery.getUserId());
public LinkedHashSet<PersonalCenterStudentListVO> queryStudentList(String userId) {
String roleId = umsUserMapper.getbyIdRoleId(userId);
CourseQuery courseQuery = new CourseQuery();
courseQuery.setUserId(userId);
if (roleId.equals("1")){
PageDTO<CoursesVO> queryCourses = queryCourses(courseQuery);
List<CoursesVO> coursesList = queryCourses.getList();
List<String> courseIds = coursesList.stream().map(CoursesVO::getId).collect(Collectors.toList());
LinkedHashSet<UmsStudent> studentNameList = new LinkedHashSet<>();
LinkedHashSet<PersonalCenterStudentListVO> studentNameList = new LinkedHashSet<>();
for (String courseId : courseIds) {
List<StudentCourses> studentUsernames = studentCoursesMapper.selectBatchSomeStudent(courseId);
List<CourseLearningRecord> courseLearningRecordList = new ArrayList<>();
@ -356,7 +369,12 @@ public class CoursesServiceImpl extends ServiceImpl<CoursesMapper, Courses> impl
courseLearningRecordList = courseLearningRecordList.stream().sorted(Comparator.comparing(CourseLearningRecord::getTimes).reversed()).collect(Collectors.toList());
for (CourseLearningRecord courseLearningRecord : courseLearningRecordList) {
UmsStudent umsStudent = umsStudentMapper.selectByUserId(Integer.valueOf(courseLearningRecord.getUserId()));
studentNameList.add(umsStudent);
UmsUser user = umsUserMapper.selectById(courseLearningRecord.getUserId());
PersonalCenterStudentListVO pcsl = new PersonalCenterStudentListVO();
pcsl.setName(umsStudent.getName());
pcsl.setNumber(umsStudent.getNumber());
pcsl.setIcon(user.getIcon());
studentNameList.add(pcsl);
}
}
return studentNameList;

@ -18,6 +18,7 @@ import com.teaching.backend.service.courses.IObjectiveContentKnowService;
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;
@ -71,7 +72,6 @@ public class ObjectiveContentKnowServiceImpl extends ServiceImpl<ObjectiveConten
objectiveContentKnow.setKnow(knowId);
objectiveContentKnowList.add(objectiveContentKnow);
}
try {
objectiveContentKnowMapper.insertBatchSomeColumn(objectiveContentKnowList);
} catch (Exception e) {
@ -84,12 +84,7 @@ public class ObjectiveContentKnowServiceImpl extends ServiceImpl<ObjectiveConten
@Override
public ObjectiveContentKnowVO getCountData(String objectiveOrContentId) {
// 检查objectiveOrContentId是否为空,如果为空则抛出异常
if (objectiveOrContentId == null) {
throw new BusinessException(ErrorCode.OBJECTIVE_OR_CONTENT_NOT_EXIT);
}
// 查询分项目标关联的知识点数据
// 查询分项目标或者是下面的内容关联的知识点数据(按设计要求,这个传的就是分项目标的id)
List<ObjectiveContentKnow> objectiveContentKnows = objectiveContentKnowMapper.selectList(
new LambdaQueryWrapper<ObjectiveContentKnow>()
.eq(ObjectiveContentKnow::getObjectiveOrContent, objectiveOrContentId));
@ -105,16 +100,16 @@ public class ObjectiveContentKnowServiceImpl extends ServiceImpl<ObjectiveConten
Integer classhours = coursesMapper.selectById(courseId).getClasshours();
// 计算并设置比例(百分比)
BigDecimal percentage = calculatePercentage(objectiveContentKnowVO.getKnowsTime(), classhours);
objectiveContentKnowVO.setPersent(percentage + "%");
// BigDecimal percentage = calculatePercentage(objectiveContentKnowVO.getKnowsTime(), classhours);
// objectiveContentKnowVO.setPersent(percentage + "%");
// 查找分项目标下的内容
List<ObjectiveContents> objectiveContents = objectiveContentsMapper.selectList(
new LambdaQueryWrapper<ObjectiveContents>()
List<ObjectiveContents> objectiveContents = objectiveContentsMapper.selectList(new LambdaQueryWrapper<ObjectiveContents>()
.eq(ObjectiveContents::getObjectiveId, objectiveOrContentId));
// 如果存在分项目标内容,处理并计算每个内容的相关数据
if (objectiveContents != null && !objectiveContents.isEmpty()) {
if (!CollectionUtils.isEmpty(objectiveContents)) {
List<ObjectiveContentKnowVO> contentKnowVOs = objectiveContents.stream()
.map(content -> createObjectiveContentKnowVO(content.getId(), objectiveContentKnowMapper.selectList(
new LambdaQueryWrapper<ObjectiveContentKnow>()
@ -123,10 +118,10 @@ public class ObjectiveContentKnowServiceImpl extends ServiceImpl<ObjectiveConten
.collect(Collectors.toList());
// 计算每个内容的知识点总学时的比例(百分比)
contentKnowVOs.forEach(contentKnowVO -> {
BigDecimal contentPercentage = calculatePercentage(contentKnowVO.getKnowsTime(), classhours);
contentKnowVO.setPersent(contentPercentage + "%");
});
// contentKnowVOs.forEach(contentKnowVO -> {
// BigDecimal contentPercentage = calculatePercentage(contentKnowVO.getKnowsTime(), classhours);
// contentKnowVO.setPersent(contentPercentage + "%");
// });
// 设置内容的知识点数据
objectiveContentKnowVO.setContentKnowsData(contentKnowVOs);
@ -168,6 +163,4 @@ public class ObjectiveContentKnowServiceImpl extends ServiceImpl<ObjectiveConten
// 计算knowsTime占classhours的比例,先除以classhours再乘以100,保留两位小数,并四舍五入
return knowsTime.divide(classHoursBigDecimal, 4, RoundingMode.HALF_UP).multiply(new BigDecimal(100)).setScale(2, RoundingMode.HALF_UP);
}
}

@ -41,6 +41,6 @@ public class ObjectiveContentsServiceImpl extends ServiceImpl<ObjectiveContentsM
throw new BusinessException(ErrorCode.KNOWS_EXIT);
}
int delete = objectiveContentsMapper.deleteById(id);
return delete>0 ? "删除成功!" : "删除失败!";
return delete > 0 ? "删除成功!" : "删除失败!";
}
}

@ -156,21 +156,27 @@ public class SeCourseFavourServiceImpl extends ServiceImpl<SeCourseFavourMapper,
}
@Override
public CoursesVO queryNewCollect(String userId) {
public List<CoursesVO> queryNewCollect(String userId) {
String roleId = umsUserMapper.getbyIdRoleId(userId);
CoursesVO coursesVO = new CoursesVO();
List<Courses> coursesList = new ArrayList<>();
if (roleId.equals("1")){
//老师
String courseId = seCourseFavourMapper.queryAllNewCollectCourse();
List<String> courseIdList = seCourseFavourMapper.queryAllNewCollectCourse();
for (String courseId : courseIdList) {
Courses courses = coursesMapper.selectById(courseId);
BeanUtil.copyProperties(courses,coursesVO);
return coursesVO;
coursesList.add(courses);
}
List<CoursesVO> coursesVOList = BeanUtil.copyToList(coursesList, CoursesVO.class);
return coursesVOList;
}else if (roleId.equals("2")){
//学生
String courseId = seCourseFavourMapper.queryStudentNewCollectCourse(userId);
List<String> courseIdList = seCourseFavourMapper.queryStudentNewCollectCourse(userId);
for (String courseId : courseIdList) {
Courses courses = coursesMapper.selectById(courseId);
BeanUtil.copyProperties(courses,coursesVO);
return coursesVO;
coursesList.add(courses);
}
List<CoursesVO> coursesVOList = BeanUtil.copyToList(coursesList,CoursesVO.class);
return coursesVOList;
}else {
return null;
}

@ -61,19 +61,21 @@ public class CourseLearningRecordServiceImpl extends ServiceImpl<CourseLearningR
Long count = courseLearningNumberService.query()
.eq("course_id", courseId).count();
//2.2判断自己是否学习过
Long count1 = query().eq("user_id", userId).count();
Long count1 = query().eq("user_id", userId).eq("course_id", courseId).count();
if (count > 0){
//自己没学过,人数加1
if (count1 == 0){
courseLearningNumberService.update().setSql("number = number + 1").eq("course_id",courseId).update();
// System.out.println("用户:"+userId+"第一次学这门课");
//System.out.println("用户:"+userId+"第一次学这门课");
}
//System.out.println("重复学习");
}else {
//该课程第一次被学,人数设置为1
CourseLearningNumber courseLearningNumber = new CourseLearningNumber();
courseLearningNumber.setNumber(1);
courseLearningNumber.setCourseId(courseId);
courseLearningNumberService.save(courseLearningNumber);
//System.out.println("该课程第一次被学习");
}
//设置人数
String numberId = courseLearningNumberService.query().eq("course_id", courseId).one().getId();

@ -2,20 +2,38 @@ package com.teaching.backend.service.impl.records;
import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.teaching.backend.common.BaseResponse;
import com.teaching.backend.common.ResultUtils;
import com.teaching.backend.mapper.records.KnowledgeLearningRecordMapper;
import com.teaching.backend.mapper.umsAdmin.UmsUserMapper;
import com.teaching.backend.model.entity.KnowGraph.Know;
import com.teaching.backend.model.entity.KnowGraph.KnowledgeLearningNumber;
import com.teaching.backend.model.entity.Knowtemp.Knowtemp;
import com.teaching.backend.model.entity.courses.CourseLearningNumber;
import com.teaching.backend.model.entity.courses.Courses;
import com.teaching.backend.model.entity.records.KnowledgeLearningRecord;
import com.teaching.backend.model.vo.courses.CoursesVO;
import com.teaching.backend.model.vo.knowGraph.KnowVO;
import com.teaching.backend.model.vo.records.KnowledgeLearningRecordVo;
import com.teaching.backend.service.KnowGraph.KnowService;
import com.teaching.backend.service.impl.courses.CourseLearningNumberServiceImpl;
import com.teaching.backend.service.impl.knowledge.KnowledgeLearningNumberServiceImpl;
import com.teaching.backend.service.records.IKnowledgeLearningRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
* <p>
@ -29,6 +47,12 @@ import java.time.LocalDateTime;
public class KnowledgeLearningRecordServiceImpl extends ServiceImpl<KnowledgeLearningRecordMapper, KnowledgeLearningRecord> implements IKnowledgeLearningRecordService {
@Resource
private KnowledgeLearningNumberServiceImpl knowledgeLearningNumberService;
@Autowired
private UmsUserMapper umsUserMapper;
@Autowired
private KnowledgeLearningRecordMapper knowledgeLearningRecordMapper;
@Resource
private KnowService knowService;
@Override
public BaseResponse<String> saveCoursesRecords(KnowledgeLearningRecord knowledgeLearningRecord) {
@ -44,14 +68,22 @@ public class KnowledgeLearningRecordServiceImpl extends ServiceImpl<KnowledgeLea
.eq("course_id", courseId)
.eq("knowledge_id",knowledgeId).count();
//2.2判断自己是否学习过
Long count1 = query().eq("user_id", userId).count();
if (count > 0){
Long count1 = query()
.eq("user_id", userId)
.eq("courses_id", courseId)
.eq("knowledge_id",knowledgeId).count();
if (count > 0){//有人学过
//自己没学过,人数加1
if (count1 == 0){
knowledgeLearningNumberService.update().setSql("number = number + 1").eq("course_id", courseId).eq("knowledge_id",knowledgeId).update();
// System.out.println("用户:"+userId+"第一次学这门课");
//该知识点学习人数
knowledgeLearningNumberService.update()
.setSql("number = number + 1")
.eq("course_id", courseId)
.eq("knowledge_id",knowledgeId).update();
System.out.println("用户:"+userId+":第一次学这门课");
}
}else {
}else {//没人学过(自己肯定也没学)
//该课程第一次被学,人数设置为1
KnowledgeLearningNumber knowledgeLearningNumber = new KnowledgeLearningNumber();
knowledgeLearningNumber.setNumber(1);
@ -68,4 +100,78 @@ public class KnowledgeLearningRecordServiceImpl extends ServiceImpl<KnowledgeLea
save(knowledgeLearningRecord);
return ResultUtils.success("添加成功");
}
@Override
public BaseResponse<Page> getPage(int pagenum, int pagesize, String userId, String courseId) {
//格式化时间
String strDateFormat = "yyyy-MM-dd HH:mm:ss";
SimpleDateFormat sdf = new SimpleDateFormat(strDateFormat);
//分页查询
Page<KnowledgeLearningRecord> page = query()
.orderByDesc("times")
.eq("user_id", userId)
.eq("courses_id",courseId).page(new Page<>(pagenum, pagesize));
Page<KnowledgeLearningRecordVo> page1 = new Page<>();
List<KnowledgeLearningRecord> records = page.getRecords();
BeanUtil.copyProperties(page, page1);
List<KnowledgeLearningRecordVo> recordsVos = new ArrayList<>();
//copy集合
records.forEach(knowledgeLearningRecord -> {
KnowledgeLearningRecordVo knowledgeLearningRecordVo = new KnowledgeLearningRecordVo();
BeanUtil.copyProperties(knowledgeLearningRecord,knowledgeLearningRecordVo);
Date date = Date.from(knowledgeLearningRecord.getTimes().atZone(ZoneId.systemDefault()).toInstant());
knowledgeLearningRecordVo.setTime(sdf.format(date));
// //填充学习人数
knowledgeLearningRecordVo.setNumber(knowledgeLearningNumberService.getById(knowledgeLearningRecord.getNumber()).getNumber());
recordsVos.add(knowledgeLearningRecordVo);
});
page1.setRecords(recordsVos);
return ResultUtils.success(page1);
}
@Override
public BaseResponse<String> removeKnowledgeRecord(List<Long> ids) {
removeByIds(ids);
return ResultUtils.success("删除成功!");
}
@Override
public List<KnowVO> queryMaxKnowledge(String userId) {
String roleId = umsUserMapper.getbyIdRoleId(userId);
List<KnowVO> coursesList = new ArrayList<>();
KnowVO knowVO = null;
if (roleId.equals("1")){
//老师
List<String> knowledgeIdList = knowledgeLearningRecordMapper.queryStudyKnowledgeMaxNumber();
for (String knowledgeId : knowledgeIdList) {
BaseResponse<Knowtemp> knowledge = knowService.query(Long.valueOf(knowledgeId));
if (knowledge.getData() != null){
knowVO = new KnowVO();
knowVO.setId(knowledge.getData().getId());
knowVO.setLabel(knowledge.getData().getName());
knowVO.setColor(knowledge.getData().getInfo());
coursesList.add(knowVO);
}
}
return coursesList;
}else if (roleId.equals("2")){
//学生
List<String> knowledgeIdList = knowledgeLearningRecordMapper.queryStudyMaxKnowledgeId(userId);
for (String knowledgeId : knowledgeIdList) {
BaseResponse<Knowtemp> knowledge = knowService.query(Long.valueOf(knowledgeId));
if (knowledge.getData() != null) {
knowVO = new KnowVO();
knowVO.setId(knowledge.getData().getId());
knowVO.setLabel(knowledge.getData().getName());
knowVO.setColor(knowledge.getData().getInfo());
coursesList.add(knowVO);
}
}
return coursesList;
}else {
return null;
}
}
}

@ -1,16 +1,28 @@
package com.teaching.backend.service.impl.records;
import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.teaching.backend.common.BaseResponse;
import com.teaching.backend.common.ResultUtils;
import com.teaching.backend.mapper.records.ResourceLearningRecordMapper;
import com.teaching.backend.model.entity.records.KnowledgeLearningRecord;
import com.teaching.backend.model.entity.records.ResourceLearningRecord;
import com.teaching.backend.model.entity.resource.ResourceLearningNumber;
import com.teaching.backend.model.vo.records.KnowledgeLearningRecordVo;
import com.teaching.backend.model.vo.records.ResourceLearingRecordVo;
import com.teaching.backend.service.impl.resource.ResourceLearningNumberServiceImpl;
import com.teaching.backend.service.records.IResourceLearningRecordService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
* <p>
@ -23,52 +35,93 @@ import java.time.LocalDateTime;
@Service
public class ResourceLearningRecordServiceImpl extends ServiceImpl<ResourceLearningRecordMapper, ResourceLearningRecord> implements IResourceLearningRecordService {
// @Resource
// private ResourceLearningNumberServiceImpl resourceLearningNumberService;
@Resource
private ResourceLearningNumberServiceImpl resourceLearningNumberService;
@Override
public BaseResponse<String> saveCoursesRecords(ResourceLearningRecord resourceLearningRecord) {
//课程id
String courseId = resourceLearningRecord.getCoursesId();
String knowledgeId = resourceLearningRecord.getKnowledgeId();
String resourceId = resourceLearningRecord.getResourceId();
String userId = resourceLearningRecord.getUserId();
//1.生成学习时间
resourceLearningRecord.setTimes(LocalDateTime.now());
//2.设置人数
//2.1查人数
Long count = resourceLearningNumberService.query()
.eq("course_id", courseId)
.eq("knowledge_id",knowledgeId)
.eq("resource_id",resourceId).count();
//2.2判断自己是否学习过
Long count1 = query()
.eq("user_id", userId)
.eq("courses_id", courseId)
.eq("knowledge_id",knowledgeId)
.eq("resource_id",resourceId).count();
if (count > 0){
//自己没学过,人数加1
if (count1 == 0){
resourceLearningNumberService.update().setSql("number = number + 1")
.eq("course_id",courseId)
.eq("knowledge_id",knowledgeId)
.eq("resource_id",resourceId).update();
// System.out.println("用户:"+userId+"第一次学这门课");
}
}else {
//该课程第一次被学,人数设置为1
ResourceLearningNumber resourceLearningNumber = new ResourceLearningNumber();
resourceLearningNumber.setNumber(1);
resourceLearningNumber.setCourseId(courseId);
resourceLearningNumber.setKnowledgeId(knowledgeId);
resourceLearningNumber.setResourceId(resourceId);
resourceLearningNumberService.save(resourceLearningNumber);
}
//设置人数
String numberId = resourceLearningNumberService.query()
.eq("course_id", courseId)
.eq("knowledge_id",knowledgeId)
.eq("resource_id",resourceId).one().getId();
resourceLearningRecord.setNumber(numberId);
//保存记录
save(resourceLearningRecord);
return ResultUtils.success("添加成功");
}
@Override
public BaseResponse<Page> getPage(int pagenum, int pagesize, String userId, String knowledgeId, String courseId) {
//格式化时间
String strDateFormat = "yyyy-MM-dd HH:mm:ss";
SimpleDateFormat sdf = new SimpleDateFormat(strDateFormat);
//分页查询
Page<ResourceLearningRecord> page = query()
.orderByDesc("times")
.eq("user_id", userId)
.eq("knowledge_id",knowledgeId)
.eq("courses_id",courseId).page(new Page<>(pagenum, pagesize));
Page<ResourceLearingRecordVo> page1 = new Page<>();
List<ResourceLearningRecord> records = page.getRecords();
BeanUtil.copyProperties(page, page1);
List<ResourceLearingRecordVo> recordsVos = new ArrayList<>();
//copy集合
records.forEach(resourceLearningRecord -> {
ResourceLearingRecordVo resourceLearingRecordVo = new ResourceLearingRecordVo();
BeanUtil.copyProperties(resourceLearningRecord,resourceLearingRecordVo);
Date date = Date.from(resourceLearningRecord.getTimes().atZone(ZoneId.systemDefault()).toInstant());
resourceLearingRecordVo.setTime(sdf.format(date));
// //填充学习人数
resourceLearingRecordVo.setNumber(resourceLearningNumberService.getById(resourceLearningRecord.getNumber()).getNumber());
recordsVos.add(resourceLearingRecordVo);
});
page1.setRecords(recordsVos);
return ResultUtils.success(page1);
}
@Override
public BaseResponse<String> removeResourceRecord(List<Long> ids) {
removeByIds(ids);
return ResultUtils.success("删除成功!");
}
// @Override
// public BaseResponse<String> saveCoursesRecords(ResourceLearningRecord resourceLearningRecord) {
// //课程id
// String courseId = resourceLearningRecord.getCoursesId();
// String knowledgeId = resourceLearningRecord.getKnowledgeId();
// String resourceId = resourceLearningRecord.getResourceId();
// String userId = resourceLearningRecord.getUserId();
// //1.生成学习时间
// resourceLearningRecord.setTimes(LocalDateTime.now());
// //2.设置人数
// //2.1查人数
// Long count = resourceLearningNumberService.query()
// .eq("course_id", courseId)
// .eq("knowledge_id",knowledgeId)
// .eq("resource_id",resourceId).count();
// //2.2判断自己是否学习过
// Long count1 = query().eq("user_id", userId).count();
// if (count > 0){
// //自己没学过,人数加1
// if (count1 == 0){
// resourceLearningNumberService.update().setSql("number = number + 1")
// .eq("course_id",courseId)
// .eq("knowledge_id",knowledgeId)
// .eq("resource_id",resourceId).update();
//// System.out.println("用户:"+userId+"第一次学这门课");
// }
// }else {
// //该课程第一次被学,人数设置为1
// ResourceLearningNumber resourceLearningNumber = new ResourceLearningNumber();
// resourceLearningNumber.setNumber(1);
// resourceLearningNumber.setCourseId(courseId);
// resourceLearningNumber.setKnowledgeId(knowledgeId);
// resourceLearningNumber.setResourceId(resourceId);
// resourceLearningNumberService.save(resourceLearningNumber);
// }
// //设置人数
// String numberId = resourceLearningNumberService.query()
// .eq("course_id", courseId)
// .eq("knowledge_id",knowledgeId)
// .eq("resource_id",resourceId).one().getId();
// resourceLearningRecord.setNumber(numberId);
// //保存记录
// save(resourceLearningRecord);
// return ResultUtils.success("添加成功");
// }
}

@ -11,6 +11,7 @@ import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
@ -24,7 +25,7 @@ public class ReportServiceImpl extends ServiceImpl<ReportMapper, Report> impleme
@Override
public BrowseReportVO getBrowseStatistics() {
//存放访问的前一天至前七天的每天对应的日期
List<LocalDate> dateList = new ArrayList<>();
List<String> dateList = new ArrayList<>();
//存放这个月访问的前一天至前七天的每天对应的浏览量
List<String> ThisMonthBrowseList = new ArrayList<>();
//存放上个月访问的前一天至前七天的每天对应的浏览量
@ -36,7 +37,9 @@ public class ReportServiceImpl extends ServiceImpl<ReportMapper, Report> impleme
// 获取前七天的日期
for (int i = 1; i <= 7; i++) {
LocalDate day = end.minusDays(i);
dateList.add(day);
// 定义一个仅包含月日的格式化器
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM-dd");
dateList.add(day.format(formatter));
//查询今天对应的浏览量
String browse = reportMapper.getBrowseByTime(day);
@ -47,6 +50,8 @@ public class ReportServiceImpl extends ServiceImpl<ReportMapper, Report> impleme
LocalDate lastMonth = lastMonthToday.minusDays(i);
//查询上个月的今天对应的浏览量
String lastMonthBrowse = reportMapper.getBrowseByTime(lastMonth);
LastMonthBrowseList.add(lastMonthBrowse);
}
@ -59,13 +64,19 @@ public class ReportServiceImpl extends ServiceImpl<ReportMapper, Report> impleme
}
@Override
public boolean getReceptionBrowse(ReportDTO reportDTO) {
if (reportDTO.getCreateTime() == null || reportDTO.getPageView() == null){
return false;
}
boolean todayBrowse = reportMapper.addTodayBrowse(reportDTO);
if (todayBrowse == false){
return false;
public boolean getReceptionBrowse() {
//查询今日有无记录
List<Report> list = lambdaQuery().eq(Report::getCreateTime, LocalDate.now()).list();
if (list.size() > 0){
//有,给记录加一
update().setSql("page_view = page_view + 1").eq("create_time",LocalDate.now()).update();
}else {
//无,创建一个记录
Report report = new Report();
report.setCreateTime(LocalDate.now());
report.setPageView("1");
save(report);
}
return true;
}

@ -1,9 +1,14 @@
package com.teaching.backend.service.records;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.teaching.backend.common.BaseResponse;
import com.teaching.backend.model.entity.records.KnowledgeLearningRecord;
import io.swagger.models.auth.In;
import com.teaching.backend.model.vo.knowGraph.KnowVO;
import java.util.List;
/**
* <p>
@ -16,4 +21,12 @@ import com.teaching.backend.model.entity.records.KnowledgeLearningRecord;
public interface IKnowledgeLearningRecordService extends IService<KnowledgeLearningRecord> {
BaseResponse<String> saveCoursesRecords(KnowledgeLearningRecord knowledgeLearningRecord);
BaseResponse<Page> getPage(int pagenum, int pagesize, String userId, String courseId);
BaseResponse<String> removeKnowledgeRecord(List<Long> ids);
List<KnowVO> queryMaxKnowledge(String userId);
}

@ -1,10 +1,13 @@
package com.teaching.backend.service.records;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.teaching.backend.common.BaseResponse;
import com.teaching.backend.model.entity.records.ResourceLearningRecord;
import java.util.List;
/**
* <p>
* 服务类
@ -15,5 +18,9 @@ import com.teaching.backend.model.entity.records.ResourceLearningRecord;
*/
public interface IResourceLearningRecordService extends IService<ResourceLearningRecord> {
// BaseResponse<String> saveCoursesRecords(ResourceLearningRecord resourceLearningRecord);
BaseResponse<String> saveCoursesRecords(ResourceLearningRecord resourceLearningRecord);
BaseResponse<Page> getPage(int pagenum, int pagesize, String userId, String knowledgeId, String courseId);
BaseResponse<String> removeResourceRecord(List<Long> ids);
}

@ -17,5 +17,5 @@ public interface ReportService extends IService<Report> {
* 接收每日浏览量
* @return
*/
boolean getReceptionBrowse(ReportDTO reportDTO);
boolean getReceptionBrowse();
}

@ -0,0 +1,5 @@
package com.teaching.backend.utils;
public class Constants {
public static final String UPLOAD_URL = "E:\\workspace\\file\\";
}

@ -4,14 +4,14 @@ public enum CourseCode {
HAS_CHILD(1, "存在子节点"),
OBJECTIVE_EXIT(1,"目标存在"),
CONTENT_EXIT(1, "存在内容"),
CONTENT_EXIT(0, "存在内容"),
SI_ZHENG_TYPE(1, "思政目标类型"),
SI_ZHENG_EXIT(1, "思政目标存在"),
KNOWS_EXIT(0, "存在关联的知识点"),
TEACHER_ROLE_ID(1, "教师的角色id是1"),
TOTAL_OBJECTIVE_TYPE(0, "课程总目标"),
TOTAL_OBJECTIVE_HAS_NO_CHILD(0, "课程总目标下面没有分项目标"),
Total_EXIT(0, "课程总目标"),
COURSE_UPDATING(1, "课程正在修改中");

@ -0,0 +1,115 @@
package com.teaching.backend.utils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.io.FileUtils;
import org.springframework.util.DigestUtils;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.util.*;
import static com.teaching.backend.utils.Constants.UPLOAD_URL;
@Slf4j
//文件上传工具类
public class UploadUtils {
public static String saveFileByDirectory (MultipartFile file) {
String url = "";
try {
// 将文件保存在服务器目录中
// 文件名称
String uuid = UUID.randomUUID().toString();
// 得到上传文件后缀
String originalName = file.getOriginalFilename();
String ext = "." + FilenameUtils.getExtension(originalName);
// 新生成的文件名称
String fileName = uuid + ext;
// 复制文件
File targetFile = new File(UPLOAD_URL, fileName);
url = UPLOAD_URL + fileName;
FileUtils.writeByteArrayToFile(targetFile, file.getBytes());
System.out.println("保存成功");
} catch (IOException e) {
log.error("保存文件到服务器(本地)失败",e);
}
return url;
}
public static void Chunk(File sourseFile) throws IOException {
// //源文件
// File sourseFile = new File("D:/Users/Desktop/image/剪映/7.18/7月20.mp4");
//分块文件存储路径
String chunkFilePath = "E:\\workspace\\chunk";
//分块文件大小
int chunkSize = 1024 * 1024 * 1;
//分块文件个数
int chunkNum = (int) Math.ceil(sourseFile.length() * 1.0 / chunkSize);
//使用流从源文件读数据,向分块文件中写数据
RandomAccessFile raf_r = new RandomAccessFile(sourseFile, "r");
//缓存区
byte[] bytes = new byte[1024];
for (int i = 0; i < chunkNum; i++) {
File chunkFile = new File(chunkFilePath + i);
//分块文件写入流
RandomAccessFile raf_rw = new RandomAccessFile(chunkFile, "rw");
int len = -1;
while((len=raf_r.read(bytes)) != -1){
raf_rw.write(bytes, 0, len);
if (chunkFile.length() >= chunkSize){
break;
}
}
raf_rw.close();
}
raf_r.close();
}
public static void Merge(File sourseFile) throws IOException {
//块文件目录
File chunkFolder = new File("E:\\workspace\\chunk");
// //源文件
// File sourseFile = new File("D:/Users/Desktop/image/剪映/7.18/7月20.mp4");
//合并后的文件
File mergeFile = new File("E:\\workspace\\file\\"+sourseFile.getName());
//取出所有分块文件
File[] files = chunkFolder.listFiles();
//将数组转成list
List<File> fileList = Arrays.asList(files);
//对分块文件排序
Collections.sort(fileList, new Comparator<File>() {
@Override
public int compare(File o1, File o2) {
return Integer.parseInt(o1.getName()) - Integer.parseInt(o2.getName()); //升序
}
});
//向合并文件写的流
RandomAccessFile raf_rw = new RandomAccessFile(mergeFile, "rw");
//缓存区
byte[] bytes = new byte[1024];
//遍历分块文件,向合并的文件写
for (File file : fileList) {
//读分块的流
RandomAccessFile raf_r = new RandomAccessFile(file, "r");
int len = -1;
while((len = raf_r.read(bytes)) != -1){
raf_rw.write(bytes, 0, len);
}
raf_r.close();
}
raf_rw.close();
//合并文件完成后对合并的文件校验
FileInputStream fileInputStream_merge = new FileInputStream(mergeFile);
FileInputStream fileInputStream_source = new FileInputStream(sourseFile);
String md5_merge = DigestUtils.md5DigestAsHex(fileInputStream_merge);
String md5_source = DigestUtils.md5DigestAsHex(fileInputStream_source);
if (md5_merge.equals(md5_source)){
System.out.println("文件合并成功!");
}
}
}

@ -19,14 +19,13 @@
course_learning_number cln
ORDER BY
number
DESC LIMIT 4;
DESC;
</select>
<select id="selectMaxCourseId" resultType="java.lang.String" parameterType="java.lang.String">
SELECT course_id, COUNT(*) as frequency
FROM course_learning_record
WHERE user_id = #{userId}
GROUP BY course_id
ORDER BY frequency DESC
LIMIT 4;
ORDER BY frequency DESC;
</select>
</mapper>

@ -0,0 +1,20 @@
<?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.records.KnowledgeLearningRecordMapper">
<select id="queryStudyKnowledgeMaxNumber" resultType="java.lang.String">
SELECT
kln.knowledge_id knowledgeId
FROM
knowledge_learning_number kln
ORDER BY
number
DESC;
</select>
<select id="queryStudyMaxKnowledgeId" resultType="java.lang.String">
SELECT knowledge_id,knowledge_name
FROM knowledge_learning_record
WHERE user_id = #{userId}
ORDER BY times DESC;
</select>
</mapper>

@ -10,7 +10,7 @@
se_course_favour scf
ORDER BY
createtime
DESC LIMIT 1;
DESC;
</select>
<select id="queryStudentNewCollectCourse" resultType="java.lang.String">
SELECT
@ -21,7 +21,7 @@
scf.user_id = #{userId}
ORDER BY
createtime
DESC LIMIT 1;
DESC;
</select>
</mapper>

@ -0,0 +1,101 @@
package com.teaching;
import org.junit.jupiter.api.Test;
import org.springframework.util.DigestUtils;
import java.io.*;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
public class MinioTest {
//分块测试
@Test
public void testChunk() throws IOException {
//源文件
File sourseFile = new File("D:/Users/Desktop/image/剪映/7.18/7月20.mp4");
//分块文件存储路径
String chunkFilePath = "D:/Users/Desktop/image/剪映/7.18/chunk/";
//分块文件大小
int chunkSize = 1024 * 1024 * 1;
//分块文件个数
int chunkNum = (int) Math.ceil(sourseFile.length() * 1.0 / chunkSize);
//使用流从源文件读数据,向分块文件中写数据
RandomAccessFile raf_r = new RandomAccessFile(sourseFile, "r");
//缓存区
byte[] bytes = new byte[1024];
for (int i = 0; i < chunkNum; i++) {
File chunkFile = new File(chunkFilePath + i);
//分块文件写入流
RandomAccessFile raf_rw = new RandomAccessFile(chunkFile, "rw");
int len = -1;
while((len=raf_r.read(bytes)) != -1){
raf_rw.write(bytes, 0, len);
if (chunkFile.length() >= chunkSize){
break;
}
}
raf_rw.close();
}
raf_r.close();
}
//将分块进行合并
@Test
public void testMerge() throws IOException {
//块文件目录
File chunkFolder = new File("D:\\Users\\Desktop\\image\\剪映\\7.18\\chunk");
//源文件
File sourseFile = new File("D:/Users/Desktop/image/剪映/7.18/7月20.mp4");
//合并后的文件
File mergeFile = new File("D:/Users/Desktop/image/剪映/7.18/7月20_merge.mp4");
//取出所有分块文件
File[] files = chunkFolder.listFiles();
//将数组转成list
List<File> fileList = Arrays.asList(files);
//对分块文件排序
Collections.sort(fileList, new Comparator<File>() {
@Override
public int compare(File o1, File o2) {
return Integer.parseInt(o1.getName()) - Integer.parseInt(o2.getName()); //升序
}
});
//向合并文件写的流
RandomAccessFile raf_rw = new RandomAccessFile(mergeFile, "rw");
//缓存区
byte[] bytes = new byte[1024];
//遍历分块文件,向合并的文件写
for (File file : fileList) {
//读分块的流
RandomAccessFile raf_r = new RandomAccessFile(file, "r");
int len = -1;
while((len = raf_r.read(bytes)) != -1){
raf_rw.write(bytes, 0, len);
}
raf_r.close();
}
raf_rw.close();
//合并文件完成后对合并的文件校验
FileInputStream fileInputStream_merge = new FileInputStream(mergeFile);
FileInputStream fileInputStream_source = new FileInputStream(sourseFile);
String md5_merge = DigestUtils.md5DigestAsHex(fileInputStream_merge);
String md5_source = DigestUtils.md5DigestAsHex(fileInputStream_source);
if (md5_merge.equals(md5_source)){
System.out.println("文件合并成功!");
}
}
//将分块文件上传到minio
public void uploadChunk(){
}
//调用minio接口合并分块
//批量清理分块文件
}

@ -0,0 +1,36 @@
package com.teaching;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import javax.annotation.Resource;
@Slf4j
@SpringBootTest
public class test {
@Test
public void countknowledge(){
String userId = "2";
// System.out.println(knowledgeLearningCountService.list());
// List<KnowledgeLearningCount> list = knowledgeLearningCountService.query().eq("user_id", userId).list();
// HashSet<KnowledgeLearningCount> set = new HashSet<>(list);
// System.out.println(set.size());
// Long count = knowledgeLearningCountService.query().eq("user_id", userId).count();
// if (count == 0){
// KnowledgeLearningCount knowledgeLearningCount = new KnowledgeLearningCount();
// knowledgeLearningCount.setUserId(userId);
// knowledgeLearningCount.setNumber(1);
// knowledgeLearningCountService.save(knowledgeLearningCount);
// }else {
// //该用户学习知识点数+1
// boolean is = knowledgeLearningCountService.update()
// .setSql("number = "+set.size())
// .eq("user_id", userId).update();
// System.out.println(is);
// }
}
}
Loading…
Cancel
Save