diff --git a/pom.xml b/pom.xml index bfd5080..3fd02d0 100644 --- a/pom.xml +++ b/pom.xml @@ -221,6 +221,25 @@ commons-lang 2.6 + + + + + commons-fileupload + commons-fileupload + 1.3.1 + + + org.apache.httpcomponents + httpcore + 4.4.10 + + + org.apache.httpcomponents + httpclient + 4.5.6 + + diff --git a/src/main/java/com/teaching/backend/config/NonStaticResourceHttpRequestHandler.java b/src/main/java/com/teaching/backend/config/NonStaticResourceHttpRequestHandler.java new file mode 100644 index 0000000..69b9ac9 --- /dev/null +++ b/src/main/java/com/teaching/backend/config/NonStaticResourceHttpRequestHandler.java @@ -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); + } +} diff --git a/src/main/java/com/teaching/backend/controller/records/BaseSourceApiController.java b/src/main/java/com/teaching/backend/controller/records/BaseSourceApiController.java new file mode 100644 index 0000000..5253649 --- /dev/null +++ b/src/main/java/com/teaching/backend/controller/records/BaseSourceApiController.java @@ -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) { + + } + } +} diff --git a/src/main/java/com/teaching/backend/controller/records/Bf.java b/src/main/java/com/teaching/backend/controller/records/Bf.java new file mode 100644 index 0000000..f0a8d95 --- /dev/null +++ b/src/main/java/com/teaching/backend/controller/records/Bf.java @@ -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("文件不存在"); + } + } +} diff --git a/src/main/java/com/teaching/backend/controller/records/KnowledgeLearningRecordController.java b/src/main/java/com/teaching/backend/controller/records/KnowledgeLearningRecordController.java index da94b8d..7d6aba9 100644 --- a/src/main/java/com/teaching/backend/controller/records/KnowledgeLearningRecordController.java +++ b/src/main/java/com/teaching/backend/controller/records/KnowledgeLearningRecordController.java @@ -1,5 +1,6 @@ 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; @@ -7,12 +8,10 @@ import com.teaching.backend.model.entity.records.CourseLearningRecord; import com.teaching.backend.model.entity.records.KnowledgeLearningRecord; 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") @@ -27,4 +26,30 @@ public class KnowledgeLearningRecordController { return knowledgeLearningRecordService.saveCoursesRecords(knowledgeLearningRecord); } + /** + * 获取当前登录用户的学习知识点记录 + * @param pagenum + * @param pagesize + * @return + */ + @ApiOperation("根据用户id查询学习记录") + @ValidateParams({"userId"}) + @GetMapping("/page") + public BaseResponse 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 deleteRecords(@RequestParam List ids){ + return knowledgeLearningRecordService.removeKnowledgeRecord(ids); + } } diff --git a/src/main/java/com/teaching/backend/controller/records/ResourceLearningRecordController.java b/src/main/java/com/teaching/backend/controller/records/ResourceLearningRecordController.java index efbb8f2..98ddfe4 100644 --- a/src/main/java/com/teaching/backend/controller/records/ResourceLearningRecordController.java +++ b/src/main/java/com/teaching/backend/controller/records/ResourceLearningRecordController.java @@ -1,18 +1,23 @@ 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.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 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.util.List; @RestController @RequestMapping("/api/resourcelearningrecords") @@ -26,4 +31,49 @@ public class ResourceLearningRecordController { public BaseResponse saveResourceRecords(@RequestBody ResourceLearningRecord resourceLearningRecord) { return resourceLearningRecordService.saveCoursesRecords(resourceLearningRecord); } + + /** + * 获取当前登录用户的学习资源记录 + * @param pagenum + * @param pagesize + * @return + */ + @ApiOperation("根据用户id查询学习记录") + @ValidateParams({"userId"}) + @GetMapping("/page") + public BaseResponse 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 deleteRecords(@RequestParam List ids){ + return resourceLearningRecordService.removeResourceRecord(ids); + } + + @ApiOperation("上传图片") + @PostMapping(value = "/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) + public BaseResponse upload(@RequestPart("filedata") MultipartFile filedata){ + //调用ser + + //源文件 +// File sourseFile = (File) file; + return ResultUtils.success("hello"); + }; + + @GetMapping("/bf") + public BaseResponse bf(@RequestParam String path, File file,HttpServletRequest request, HttpServletResponse response){ + File sourseFile = new File(path); + return ResultUtils.success(path); + }; + } diff --git a/src/main/java/com/teaching/backend/model/dto/upload/UploadFileParamsDto.java b/src/main/java/com/teaching/backend/model/dto/upload/UploadFileParamsDto.java new file mode 100644 index 0000000..c5a84bf --- /dev/null +++ b/src/main/java/com/teaching/backend/model/dto/upload/UploadFileParamsDto.java @@ -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; +} diff --git a/src/main/java/com/teaching/backend/model/entity/records/KnowledgeLearningRecord.java b/src/main/java/com/teaching/backend/model/entity/records/KnowledgeLearningRecord.java index 7d1f11c..37b4cab 100644 --- a/src/main/java/com/teaching/backend/model/entity/records/KnowledgeLearningRecord.java +++ b/src/main/java/com/teaching/backend/model/entity/records/KnowledgeLearningRecord.java @@ -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") diff --git a/src/main/java/com/teaching/backend/model/entity/records/ResourceLearningRecord.java b/src/main/java/com/teaching/backend/model/entity/records/ResourceLearningRecord.java index c33d691..d7dd115 100644 --- a/src/main/java/com/teaching/backend/model/entity/records/ResourceLearningRecord.java +++ b/src/main/java/com/teaching/backend/model/entity/records/ResourceLearningRecord.java @@ -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; diff --git a/src/main/java/com/teaching/backend/model/vo/records/CourseLearningRecordsVo.java b/src/main/java/com/teaching/backend/model/vo/records/CourseLearningRecordsVo.java index 1260a73..acd047f 100644 --- a/src/main/java/com/teaching/backend/model/vo/records/CourseLearningRecordsVo.java +++ b/src/main/java/com/teaching/backend/model/vo/records/CourseLearningRecordsVo.java @@ -17,6 +17,10 @@ public class CourseLearningRecordsVo { * 课程学习id */ private String id; + /** + * 课程id + */ + private String courseId; /** * 课程名称 */ diff --git a/src/main/java/com/teaching/backend/model/vo/records/KnowledgeLearningRecordVo.java b/src/main/java/com/teaching/backend/model/vo/records/KnowledgeLearningRecordVo.java new file mode 100644 index 0000000..c550f19 --- /dev/null +++ b/src/main/java/com/teaching/backend/model/vo/records/KnowledgeLearningRecordVo.java @@ -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; +} diff --git a/src/main/java/com/teaching/backend/model/vo/records/ResourceLearingRecordVo.java b/src/main/java/com/teaching/backend/model/vo/records/ResourceLearingRecordVo.java new file mode 100644 index 0000000..09a738e --- /dev/null +++ b/src/main/java/com/teaching/backend/model/vo/records/ResourceLearingRecordVo.java @@ -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; +} diff --git a/src/main/java/com/teaching/backend/service/impl/records/CourseLearningRecordServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/records/CourseLearningRecordServiceImpl.java index b8e4809..2ce1a62 100644 --- a/src/main/java/com/teaching/backend/service/impl/records/CourseLearningRecordServiceImpl.java +++ b/src/main/java/com/teaching/backend/service/impl/records/CourseLearningRecordServiceImpl.java @@ -61,19 +61,21 @@ public class CourseLearningRecordServiceImpl extends ServiceImpl 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(); diff --git a/src/main/java/com/teaching/backend/service/impl/records/KnowledgeLearningRecordServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/records/KnowledgeLearningRecordServiceImpl.java index fe3d252..c26e3d9 100644 --- a/src/main/java/com/teaching/backend/service/impl/records/KnowledgeLearningRecordServiceImpl.java +++ b/src/main/java/com/teaching/backend/service/impl/records/KnowledgeLearningRecordServiceImpl.java @@ -2,20 +2,30 @@ 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.model.entity.KnowGraph.KnowledgeLearningNumber; import com.teaching.backend.model.entity.courses.CourseLearningNumber; + import com.teaching.backend.model.entity.records.KnowledgeLearningRecord; + +import com.teaching.backend.model.vo.records.KnowledgeLearningRecordVo; 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.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; /** *

@@ -44,7 +54,10 @@ public class KnowledgeLearningRecordServiceImpl extends ServiceImpl 0){ //自己没学过,人数加1 if (count1 == 0){ @@ -68,4 +81,38 @@ public class KnowledgeLearningRecordServiceImpl extends ServiceImpl getPage(int pagenum, int pagesize, String userId, String courseId) { + //格式化时间 + String strDateFormat = "yyyy-MM-dd HH:mm:ss"; + SimpleDateFormat sdf = new SimpleDateFormat(strDateFormat); + //分页查询 + Page page = query() + .orderByDesc("times") + .eq("user_id", userId) + .eq("courses_id",courseId).page(new Page<>(pagenum, pagesize)); + Page page1 = new Page<>(); + List records = page.getRecords(); + BeanUtil.copyProperties(page, page1); + List 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 removeKnowledgeRecord(List ids) { + removeByIds(ids); + return ResultUtils.success("删除成功!"); + } } diff --git a/src/main/java/com/teaching/backend/service/impl/records/ResourceLearningRecordServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/records/ResourceLearningRecordServiceImpl.java index 1220371..14270e6 100644 --- a/src/main/java/com/teaching/backend/service/impl/records/ResourceLearningRecordServiceImpl.java +++ b/src/main/java/com/teaching/backend/service/impl/records/ResourceLearningRecordServiceImpl.java @@ -1,18 +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; /** *

@@ -44,7 +54,11 @@ public class ResourceLearningRecordServiceImpl extends ServiceImpl 0){ //自己没学过,人数加1 if (count1 == 0){ @@ -73,4 +87,41 @@ public class ResourceLearningRecordServiceImpl extends ServiceImpl 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 page = query() + .orderByDesc("times") + .eq("user_id", userId) + .eq("knowledge_id",knowledgeId) + .eq("courses_id",courseId).page(new Page<>(pagenum, pagesize)); + Page page1 = new Page<>(); + List records = page.getRecords(); + BeanUtil.copyProperties(page, page1); + List 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 removeResourceRecord(List ids) { + removeByIds(ids); + return ResultUtils.success("删除成功!"); + } + + } diff --git a/src/main/java/com/teaching/backend/service/records/IKnowledgeLearningRecordService.java b/src/main/java/com/teaching/backend/service/records/IKnowledgeLearningRecordService.java index ac279a5..252d176 100644 --- a/src/main/java/com/teaching/backend/service/records/IKnowledgeLearningRecordService.java +++ b/src/main/java/com/teaching/backend/service/records/IKnowledgeLearningRecordService.java @@ -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.KnowledgeLearningRecord; +import java.util.List; + /** *

* 服务类 @@ -16,4 +19,9 @@ import com.teaching.backend.model.entity.records.KnowledgeLearningRecord; public interface IKnowledgeLearningRecordService extends IService { BaseResponse saveCoursesRecords(KnowledgeLearningRecord knowledgeLearningRecord); + + BaseResponse getPage(int pagenum, int pagesize, String userId, String courseId); + + BaseResponse removeKnowledgeRecord(List ids); } + diff --git a/src/main/java/com/teaching/backend/service/records/IResourceLearningRecordService.java b/src/main/java/com/teaching/backend/service/records/IResourceLearningRecordService.java index 2b53014..1282e23 100644 --- a/src/main/java/com/teaching/backend/service/records/IResourceLearningRecordService.java +++ b/src/main/java/com/teaching/backend/service/records/IResourceLearningRecordService.java @@ -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; + /** *

* 服务类 @@ -16,4 +19,8 @@ import com.teaching.backend.model.entity.records.ResourceLearningRecord; public interface IResourceLearningRecordService extends IService { BaseResponse saveCoursesRecords(ResourceLearningRecord resourceLearningRecord); + + BaseResponse getPage(int pagenum, int pagesize, String userId, String knowledgeId, String courseId); + + BaseResponse removeResourceRecord(List ids); } diff --git a/src/test/java/com/teaching/MinioTest.java b/src/test/java/com/teaching/MinioTest.java new file mode 100644 index 0000000..cbdb77d --- /dev/null +++ b/src/test/java/com/teaching/MinioTest.java @@ -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 fileList = Arrays.asList(files); + //对分块文件排序 + Collections.sort(fileList, new Comparator() { + @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接口合并分块 + + + //批量清理分块文件 + + +}