From bb95bd444eb4a5406174593b4b150a17d082b94c Mon Sep 17 00:00:00 2001 From: Alan <3052806735@qq.com> Date: Sat, 3 Aug 2024 18:27:15 +0800 Subject: [PATCH 01/11] =?UTF-8?q?=E8=AF=BE=E7=A8=8B=E7=9B=AE=E6=A0=87?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../teaching/backend/common/ErrorCode.java | 2 +- .../controller/courses/CoursesController.java | 17 +--- .../courses/ObjectiveContentsController.java | 1 - .../courses/CourseObjectivesServiceImpl.java | 40 ++++---- .../impl/courses/CoursesServiceImpl.java | 98 ++++++++++--------- .../ObjectiveContentKnowServiceImpl.java | 29 +++--- .../courses/ObjectiveContentsServiceImpl.java | 2 +- .../teaching/backend/utils/CourseCode.java | 4 +- 8 files changed, 93 insertions(+), 100 deletions(-) diff --git a/src/main/java/com/teaching/backend/common/ErrorCode.java b/src/main/java/com/teaching/backend/common/ErrorCode.java index 4b2a66e..95830fb 100644 --- a/src/main/java/com/teaching/backend/common/ErrorCode.java +++ b/src/main/java/com/teaching/backend/common/ErrorCode.java @@ -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, "未登录"), diff --git a/src/main/java/com/teaching/backend/controller/courses/CoursesController.java b/src/main/java/com/teaching/backend/controller/courses/CoursesController.java index 07fb7f2..8840c0c 100644 --- a/src/main/java/com/teaching/backend/controller/courses/CoursesController.java +++ b/src/main/java/com/teaching/backend/controller/courses/CoursesController.java @@ -3,19 +3,14 @@ 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.service.courses.ICoursesService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -24,7 +19,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; /** *

@@ -87,7 +84,6 @@ public class CoursesController { @ApiOperation("查询课程列表") @ValidateParams({"userId"}) @GetMapping("/page") -// @PostMapping("/page") public BaseResponse> getCourses(CourseQuery courseQuery){ PageDTO coursesList = coursesService.queryCourses(courseQuery); return ResultUtils.success(coursesList); @@ -97,9 +93,6 @@ public class CoursesController { @ValidateParams({"id"}) @GetMapping("/{id}") public BaseResponse 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 +107,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("删除成功"); } diff --git a/src/main/java/com/teaching/backend/controller/courses/ObjectiveContentsController.java b/src/main/java/com/teaching/backend/controller/courses/ObjectiveContentsController.java index 17a9462..cbe1c5e 100644 --- a/src/main/java/com/teaching/backend/controller/courses/ObjectiveContentsController.java +++ b/src/main/java/com/teaching/backend/controller/courses/ObjectiveContentsController.java @@ -39,7 +39,6 @@ public class ObjectiveContentsController { @ValidateParams({"id"}) @DeleteMapping("/{id}") public BaseResponse deleteContent(@PathVariable String id){ -// objectiveContentsService.removeById(id); String data = objectiveContentsService.deleteById(id); return ResultUtils.success(data); } diff --git a/src/main/java/com/teaching/backend/service/impl/courses/CourseObjectivesServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/courses/CourseObjectivesServiceImpl.java index f5682e6..435f710 100644 --- a/src/main/java/com/teaching/backend/service/impl/courses/CourseObjectivesServiceImpl.java +++ b/src/main/java/com/teaching/backend/service/impl/courses/CourseObjectivesServiceImpl.java @@ -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; + /** *

* 服务实现类 @@ -54,33 +56,33 @@ public class CourseObjectivesServiceImpl extends ServiceImpl() .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() .eq(ObjectiveContentKnow::getObjectiveOrContent, id)); if(count > CourseCode.KNOWS_EXIT.getValue()){ @@ -121,9 +123,9 @@ public class CourseObjectivesServiceImpl extends ServiceImpl 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 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 queryWrapper = new QueryWrapper<>(); - queryWrapper.eq("code", code); - Long count = coursesMapper.selectCount(queryWrapper); - if (count == 0) { - int insert = coursesMapper.insert(courses); - if (insert > 0) { - Courses coursesNew = coursesMapper.selectById(courseId); - 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().eq(CourseObjectives::getCourseId, courseId)); - String courseTotalObjectivesId = courseTotalObjectives.getId(); - List objectivesTypes = objectivesTypeMapper.selectList(new LambdaQueryWrapper()); - ArrayList 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); - courseObjectivesF.setPid(courseTotalObjectivesId); - courseObjectivesFList.add(courseObjectivesF); - } - } - courseObjectivesMapper.insertBatch(courseObjectivesFList); - courseTotalObjectives.setHasChild(1); - courseObjectivesMapper.updateById(courseTotalObjectives); - } - } - return "添加成功"; - } else { + Long count = query().eq("code", code).count(); + if (count > 0) { throw new BusinessException(ErrorCode.OPERATION_ERROR, "这个课程已经存在了!请联系系统相关人员为您导入课程数据!"); } + // 插入课程信息 + int insert = coursesMapper.insert(courses); + if (insert <= 0) { + throw new BusinessException(ErrorCode.OPERATION_ERROR, "课程插入失败!"); + } + + // 插入课程目标信息 + CourseObjectives courseObjectives = new CourseObjectives(); + courseObjectives.setCourseId(courseId); + courseObjectives.setType(CourseCode.TOTAL_OBJECTIVE_TYPE.getValue()); + int insertTotal = courseObjectivesMapper.insert(courseObjectives); + if (insertTotal <= 0) { + throw new BusinessException(ErrorCode.OPERATION_ERROR, "课程目标插入失败!"); + } + + // 获取插入后的课程目标信息 + CourseObjectives courseTotalObjectives = courseObjectivesMapper.selectOne( + new LambdaQueryWrapper().eq(CourseObjectives::getCourseId, courseId) + ); + String courseTotalObjectivesId = courseTotalObjectives.getId(); + + // 获取所有目标类型并插入子目标 + List objectivesTypes = objectivesTypeMapper.selectList(new LambdaQueryWrapper<>()); + ArrayList courseObjectivesFList = new ArrayList<>(); + for (ObjectivesType objectivesType : objectivesTypes) { + if (!objectivesType.getId().equals(CourseCode.TOTAL_OBJECTIVE_TYPE.getValue())) { + CourseObjectives courseObjectivesF = new CourseObjectives(); + courseObjectivesF.setType(objectivesType.getId()); + courseObjectivesF.setPid(courseTotalObjectivesId); + courseObjectivesFList.add(courseObjectivesF); + } + } + + // 批量插入子目标并更新父目标的hasChild字段 + if (!courseObjectivesFList.isEmpty()) { + courseObjectivesMapper.insertBatch(courseObjectivesFList); + courseTotalObjectives.setHasChild(1); + courseObjectivesMapper.updateById(courseTotalObjectives); + } + + return "添加成功"; } + @Override public PageDTO queryCourses(CourseQuery courseQuery) { -// int roleId = Integer.parseInt(umsUserMapper.selectOne(new LambdaQueryWrapper() -// .eq(UmsUser::getUsername, courseQuery.getUsername())).getRoleId()); UmsUser umsUser = umsUserMapper.selectById(courseQuery.getUserId()); if (umsUser == null){ throw new BusinessException(ErrorCode.PARAMS_USER_NOTEXISTS); @@ -187,9 +193,11 @@ public class CoursesServiceImpl extends ServiceImpl impl Page 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); } @@ -204,6 +212,7 @@ public class CoursesServiceImpl extends ServiceImpl impl Page 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); } @@ -215,6 +224,7 @@ public class CoursesServiceImpl extends ServiceImpl 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); } diff --git a/src/main/java/com/teaching/backend/service/impl/courses/ObjectiveContentKnowServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/courses/ObjectiveContentKnowServiceImpl.java index f62b99a..13720df 100644 --- a/src/main/java/com/teaching/backend/service/impl/courses/ObjectiveContentKnowServiceImpl.java +++ b/src/main/java/com/teaching/backend/service/impl/courses/ObjectiveContentKnowServiceImpl.java @@ -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 objectiveContentKnows = objectiveContentKnowMapper.selectList( new LambdaQueryWrapper() .eq(ObjectiveContentKnow::getObjectiveOrContent, objectiveOrContentId)); @@ -105,16 +100,16 @@ public class ObjectiveContentKnowServiceImpl extends ServiceImpl objectiveContents = objectiveContentsMapper.selectList( - new LambdaQueryWrapper() + List objectiveContents = objectiveContentsMapper.selectList(new LambdaQueryWrapper() .eq(ObjectiveContents::getObjectiveId, objectiveOrContentId)); // 如果存在分项目标内容,处理并计算每个内容的相关数据 - if (objectiveContents != null && !objectiveContents.isEmpty()) { + if (!CollectionUtils.isEmpty(objectiveContents)) { List contentKnowVOs = objectiveContents.stream() .map(content -> createObjectiveContentKnowVO(content.getId(), objectiveContentKnowMapper.selectList( new LambdaQueryWrapper() @@ -123,10 +118,10 @@ public class ObjectiveContentKnowServiceImpl extends ServiceImpl { - 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 ServiceImpl0 ? "删除成功!" : "删除失败!"; + return delete > 0 ? "删除成功!" : "删除失败!"; } } diff --git a/src/main/java/com/teaching/backend/utils/CourseCode.java b/src/main/java/com/teaching/backend/utils/CourseCode.java index d736cd4..b7b2465 100644 --- a/src/main/java/com/teaching/backend/utils/CourseCode.java +++ b/src/main/java/com/teaching/backend/utils/CourseCode.java @@ -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, "课程正在修改中"); From 58d8f0b1cb9ec866ac3bbd1af8b0d5a3bc8562ef Mon Sep 17 00:00:00 2001 From: wenyu441069198 <14186472+wenyu441069198@user.noreply.gitee.com> Date: Mon, 5 Aug 2024 15:52:12 +0800 Subject: [PATCH 02/11] =?UTF-8?q?=E5=AD=A6=E4=B9=A0=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 19 ++++ .../NonStaticResourceHttpRequestHandler.java | 23 ++++ .../records/BaseSourceApiController.java | 46 ++++++++ .../backend/controller/records/Bf.java | 56 ++++++++++ .../KnowledgeLearningRecordController.java | 33 +++++- .../ResourceLearningRecordController.java | 58 +++++++++- .../model/dto/upload/UploadFileParamsDto.java | 32 ++++++ .../records/KnowledgeLearningRecord.java | 4 +- .../records/ResourceLearningRecord.java | 4 + .../vo/records/CourseLearningRecordsVo.java | 4 + .../vo/records/KnowledgeLearningRecordVo.java | 37 +++++++ .../vo/records/ResourceLearingRecordVo.java | 29 +++++ .../CourseLearningRecordServiceImpl.java | 6 +- .../KnowledgeLearningRecordServiceImpl.java | 49 ++++++++- .../ResourceLearningRecordServiceImpl.java | 53 ++++++++- .../IKnowledgeLearningRecordService.java | 8 ++ .../IResourceLearningRecordService.java | 7 ++ src/test/java/com/teaching/MinioTest.java | 101 ++++++++++++++++++ 18 files changed, 555 insertions(+), 14 deletions(-) create mode 100644 src/main/java/com/teaching/backend/config/NonStaticResourceHttpRequestHandler.java create mode 100644 src/main/java/com/teaching/backend/controller/records/BaseSourceApiController.java create mode 100644 src/main/java/com/teaching/backend/controller/records/Bf.java create mode 100644 src/main/java/com/teaching/backend/model/dto/upload/UploadFileParamsDto.java create mode 100644 src/main/java/com/teaching/backend/model/vo/records/KnowledgeLearningRecordVo.java create mode 100644 src/main/java/com/teaching/backend/model/vo/records/ResourceLearingRecordVo.java create mode 100644 src/test/java/com/teaching/MinioTest.java 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接口合并分块 + + + //批量清理分块文件 + + +} From cd9df0f9aae0d3ddf4962241058aef885bd00ec8 Mon Sep 17 00:00:00 2001 From: wenyu441069198 <14186472+wenyu441069198@user.noreply.gitee.com> Date: Mon, 5 Aug 2024 16:21:18 +0800 Subject: [PATCH 03/11] =?UTF-8?q?=E8=82=96=E6=B5=B7=E5=8D=97=E5=AD=A6?= =?UTF-8?q?=E7=94=9F=E5=88=97=E8=A1=A8=E5=B0=8F=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/controller/courses/CoursesController.java | 4 ++-- .../records/KnowledgeLearningRecordController.java | 2 ++ .../teaching/backend/service/courses/ICoursesService.java | 2 +- .../backend/service/impl/courses/CoursesServiceImpl.java | 6 ++++-- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/teaching/backend/controller/courses/CoursesController.java b/src/main/java/com/teaching/backend/controller/courses/CoursesController.java index 8840c0c..9809dd5 100644 --- a/src/main/java/com/teaching/backend/controller/courses/CoursesController.java +++ b/src/main/java/com/teaching/backend/controller/courses/CoursesController.java @@ -131,8 +131,8 @@ public class CoursesController { @ApiOperation("查询学生列表") @PostMapping("/studentList") - public CommonResult> getStudentList(CourseQuery courseQuery){ - LinkedHashSet umsStudentList = coursesService.queryStudentList(courseQuery); + public CommonResult> getStudentList(@RequestParam String userId){ + LinkedHashSet umsStudentList = coursesService.queryStudentList(userId); return CommonResult.success(umsStudentList); } 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 7d6aba9..867889c 100644 --- a/src/main/java/com/teaching/backend/controller/records/KnowledgeLearningRecordController.java +++ b/src/main/java/com/teaching/backend/controller/records/KnowledgeLearningRecordController.java @@ -52,4 +52,6 @@ public class KnowledgeLearningRecordController { public BaseResponse deleteRecords(@RequestParam List ids){ return knowledgeLearningRecordService.removeKnowledgeRecord(ids); } + + } diff --git a/src/main/java/com/teaching/backend/service/courses/ICoursesService.java b/src/main/java/com/teaching/backend/service/courses/ICoursesService.java index 9a06641..11ec74f 100644 --- a/src/main/java/com/teaching/backend/service/courses/ICoursesService.java +++ b/src/main/java/com/teaching/backend/service/courses/ICoursesService.java @@ -46,5 +46,5 @@ public interface ICoursesService extends IService { Map getPagePageSize2(int page, int pageSize); - LinkedHashSet queryStudentList(CourseQuery courseQuery); + LinkedHashSet queryStudentList(String userId); } diff --git a/src/main/java/com/teaching/backend/service/impl/courses/CoursesServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/courses/CoursesServiceImpl.java index 3504a58..dc52e6d 100644 --- a/src/main/java/com/teaching/backend/service/impl/courses/CoursesServiceImpl.java +++ b/src/main/java/com/teaching/backend/service/impl/courses/CoursesServiceImpl.java @@ -352,8 +352,10 @@ public class CoursesServiceImpl extends ServiceImpl impl } @Override - public LinkedHashSet queryStudentList(CourseQuery courseQuery) { - String roleId = umsUserMapper.getbyIdRoleId(courseQuery.getUserId()); + public LinkedHashSet queryStudentList(String userId) { + String roleId = umsUserMapper.getbyIdRoleId(userId); + CourseQuery courseQuery = new CourseQuery(); + courseQuery.setUserId(userId); if (roleId.equals("1")){ PageDTO queryCourses = queryCourses(courseQuery); List coursesList = queryCourses.getList(); From a1f4aaa646aa0c555ad062f7a93bbe0e63ff5173 Mon Sep 17 00:00:00 2001 From: wenyu441069198 <14186472+wenyu441069198@user.noreply.gitee.com> Date: Mon, 5 Aug 2024 16:54:56 +0800 Subject: [PATCH 04/11] =?UTF-8?q?=E8=82=96=E6=B5=B7=E5=8D=97=E5=AD=A6?= =?UTF-8?q?=E7=94=9F=E5=88=97=E8=A1=A8=E8=BF=94=E5=9B=9E=E5=80=BC=E5=B0=8F?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/courses/CoursesController.java | 5 ++- .../courses/PersonalCenterStudentListVO.java | 44 +++++++++++++++++++ .../service/courses/ICoursesService.java | 3 +- .../impl/courses/CoursesServiceImpl.java | 12 +++-- 4 files changed, 58 insertions(+), 6 deletions(-) create mode 100644 src/main/java/com/teaching/backend/model/vo/courses/PersonalCenterStudentListVO.java diff --git a/src/main/java/com/teaching/backend/controller/courses/CoursesController.java b/src/main/java/com/teaching/backend/controller/courses/CoursesController.java index 9809dd5..7e14395 100644 --- a/src/main/java/com/teaching/backend/controller/courses/CoursesController.java +++ b/src/main/java/com/teaching/backend/controller/courses/CoursesController.java @@ -11,6 +11,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.service.courses.ICoursesService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -131,8 +132,8 @@ public class CoursesController { @ApiOperation("查询学生列表") @PostMapping("/studentList") - public CommonResult> getStudentList(@RequestParam String userId){ - LinkedHashSet umsStudentList = coursesService.queryStudentList(userId); + public CommonResult> getStudentList(@RequestParam String userId){ + LinkedHashSet umsStudentList = coursesService.queryStudentList(userId); return CommonResult.success(umsStudentList); } diff --git a/src/main/java/com/teaching/backend/model/vo/courses/PersonalCenterStudentListVO.java b/src/main/java/com/teaching/backend/model/vo/courses/PersonalCenterStudentListVO.java new file mode 100644 index 0000000..e0fe434 --- /dev/null +++ b/src/main/java/com/teaching/backend/model/vo/courses/PersonalCenterStudentListVO.java @@ -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; + +/** + *

+ * + *

+ * + * @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; + +} diff --git a/src/main/java/com/teaching/backend/service/courses/ICoursesService.java b/src/main/java/com/teaching/backend/service/courses/ICoursesService.java index 11ec74f..dcd643c 100644 --- a/src/main/java/com/teaching/backend/service/courses/ICoursesService.java +++ b/src/main/java/com/teaching/backend/service/courses/ICoursesService.java @@ -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 { Map getPagePageSize2(int page, int pageSize); - LinkedHashSet queryStudentList(String userId); + LinkedHashSet queryStudentList(String userId); } diff --git a/src/main/java/com/teaching/backend/service/impl/courses/CoursesServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/courses/CoursesServiceImpl.java index dc52e6d..454688b 100644 --- a/src/main/java/com/teaching/backend/service/impl/courses/CoursesServiceImpl.java +++ b/src/main/java/com/teaching/backend/service/impl/courses/CoursesServiceImpl.java @@ -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; @@ -352,7 +353,7 @@ public class CoursesServiceImpl extends ServiceImpl impl } @Override - public LinkedHashSet queryStudentList(String userId) { + public LinkedHashSet queryStudentList(String userId) { String roleId = umsUserMapper.getbyIdRoleId(userId); CourseQuery courseQuery = new CourseQuery(); courseQuery.setUserId(userId); @@ -360,7 +361,7 @@ public class CoursesServiceImpl extends ServiceImpl impl PageDTO queryCourses = queryCourses(courseQuery); List coursesList = queryCourses.getList(); List courseIds = coursesList.stream().map(CoursesVO::getId).collect(Collectors.toList()); - LinkedHashSet studentNameList = new LinkedHashSet<>(); + LinkedHashSet studentNameList = new LinkedHashSet<>(); for (String courseId : courseIds) { List studentUsernames = studentCoursesMapper.selectBatchSomeStudent(courseId); List courseLearningRecordList = new ArrayList<>(); @@ -371,7 +372,12 @@ public class CoursesServiceImpl extends ServiceImpl 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; From 2bd2968cc653a157b4140a0e8a856f49da560485 Mon Sep 17 00:00:00 2001 From: wenyu441069198 <14186472+wenyu441069198@user.noreply.gitee.com> Date: Mon, 5 Aug 2024 17:55:00 +0800 Subject: [PATCH 05/11] =?UTF-8?q?=E8=82=96=E6=B5=B7=E5=8D=97=E4=B8=AA?= =?UTF-8?q?=E4=BA=BA=E4=BF=A1=E6=81=AF=E6=94=B6=E8=97=8F=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../favour/SeCourseFavourController.java | 4 +-- .../CourseLearningRecordController.java | 2 +- .../mapper/favour/SeCourseFavourMapper.java | 6 +++-- .../service/favour/SeCourseFavourService.java | 2 +- .../favour/SeCourseFavourServiceImpl.java | 26 ++++++++++++------- .../mapper/CourseLearningRecordMapper.xml | 5 ++-- .../resources/mapper/SeCourseFavourMapper.xml | 4 +-- 7 files changed, 28 insertions(+), 21 deletions(-) diff --git a/src/main/java/com/teaching/backend/controller/favour/SeCourseFavourController.java b/src/main/java/com/teaching/backend/controller/favour/SeCourseFavourController.java index 5a61c49..fe2548b 100644 --- a/src/main/java/com/teaching/backend/controller/favour/SeCourseFavourController.java +++ b/src/main/java/com/teaching/backend/controller/favour/SeCourseFavourController.java @@ -99,8 +99,8 @@ public class SeCourseFavourController { */ @ApiOperation("查询最新收藏") @PostMapping("/newCollect") - public CommonResult newCollect(@RequestParam String userId) { - CoursesVO newCoursesVO = seCourseFavourService.queryNewCollect(userId); + public CommonResult> newCollect(@RequestParam String userId) { + List newCoursesVO = seCourseFavourService.queryNewCollect(userId); if (newCoursesVO == null){ CommonResult.failed("用户或角色错误"); } diff --git a/src/main/java/com/teaching/backend/controller/records/CourseLearningRecordController.java b/src/main/java/com/teaching/backend/controller/records/CourseLearningRecordController.java index 808cb8e..ed7b1b3 100644 --- a/src/main/java/com/teaching/backend/controller/records/CourseLearningRecordController.java +++ b/src/main/java/com/teaching/backend/controller/records/CourseLearningRecordController.java @@ -61,7 +61,7 @@ public class CourseLearningRecordController { * 个人中心课程列表 * @return */ - @ApiOperation("查询前4的课程") + @ApiOperation("按新旧排序查询的课程列表") @PostMapping("/courseList") public CommonResult> courseList(@RequestParam String userId) { List coursesVOList = courseLearningRecordService.queryCourseList(userId); diff --git a/src/main/java/com/teaching/backend/mapper/favour/SeCourseFavourMapper.java b/src/main/java/com/teaching/backend/mapper/favour/SeCourseFavourMapper.java index 3c9c766..55adb81 100644 --- a/src/main/java/com/teaching/backend/mapper/favour/SeCourseFavourMapper.java +++ b/src/main/java/com/teaching/backend/mapper/favour/SeCourseFavourMapper.java @@ -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 { - String queryAllNewCollectCourse(); + List queryAllNewCollectCourse(); - String queryStudentNewCollectCourse(String userId); + List queryStudentNewCollectCourse(String userId); } diff --git a/src/main/java/com/teaching/backend/service/favour/SeCourseFavourService.java b/src/main/java/com/teaching/backend/service/favour/SeCourseFavourService.java index 9723cbf..a8d1076 100644 --- a/src/main/java/com/teaching/backend/service/favour/SeCourseFavourService.java +++ b/src/main/java/com/teaching/backend/service/favour/SeCourseFavourService.java @@ -61,5 +61,5 @@ public interface SeCourseFavourService extends IService { * @param userId * @return */ - CoursesVO queryNewCollect(String userId); + List queryNewCollect(String userId); } diff --git a/src/main/java/com/teaching/backend/service/impl/favour/SeCourseFavourServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/favour/SeCourseFavourServiceImpl.java index bebe162..a260644 100644 --- a/src/main/java/com/teaching/backend/service/impl/favour/SeCourseFavourServiceImpl.java +++ b/src/main/java/com/teaching/backend/service/impl/favour/SeCourseFavourServiceImpl.java @@ -156,21 +156,27 @@ public class SeCourseFavourServiceImpl extends ServiceImpl queryNewCollect(String userId) { String roleId = umsUserMapper.getbyIdRoleId(userId); - CoursesVO coursesVO = new CoursesVO(); + List coursesList = new ArrayList<>(); if (roleId.equals("1")){ //老师 - String courseId = seCourseFavourMapper.queryAllNewCollectCourse(); - Courses courses = coursesMapper.selectById(courseId); - BeanUtil.copyProperties(courses,coursesVO); - return coursesVO; + List courseIdList = seCourseFavourMapper.queryAllNewCollectCourse(); + for (String courseId : courseIdList) { + Courses courses = coursesMapper.selectById(courseId); + coursesList.add(courses); + } + List coursesVOList = BeanUtil.copyToList(coursesList, CoursesVO.class); + return coursesVOList; }else if (roleId.equals("2")){ //学生 - String courseId = seCourseFavourMapper.queryStudentNewCollectCourse(userId); - Courses courses = coursesMapper.selectById(courseId); - BeanUtil.copyProperties(courses,coursesVO); - return coursesVO; + List courseIdList = seCourseFavourMapper.queryStudentNewCollectCourse(userId); + for (String courseId : courseIdList) { + Courses courses = coursesMapper.selectById(courseId); + coursesList.add(courses); + } + List coursesVOList = BeanUtil.copyToList(coursesList,CoursesVO.class); + return coursesVOList; }else { return null; } diff --git a/src/main/resources/mapper/CourseLearningRecordMapper.xml b/src/main/resources/mapper/CourseLearningRecordMapper.xml index 65d9f52..d117fc7 100644 --- a/src/main/resources/mapper/CourseLearningRecordMapper.xml +++ b/src/main/resources/mapper/CourseLearningRecordMapper.xml @@ -19,14 +19,13 @@ course_learning_number cln ORDER BY number - DESC LIMIT 4; + DESC; diff --git a/src/main/resources/mapper/SeCourseFavourMapper.xml b/src/main/resources/mapper/SeCourseFavourMapper.xml index 26ae03d..f310d5d 100644 --- a/src/main/resources/mapper/SeCourseFavourMapper.xml +++ b/src/main/resources/mapper/SeCourseFavourMapper.xml @@ -10,7 +10,7 @@ se_course_favour scf ORDER BY createtime - DESC LIMIT 1; + DESC; From a4ae842a4acf7a7ff32d39e4e7893b9c8c39aa65 Mon Sep 17 00:00:00 2001 From: wenyu441069198 <14186472+wenyu441069198@user.noreply.gitee.com> Date: Tue, 6 Aug 2024 09:49:54 +0800 Subject: [PATCH 06/11] =?UTF-8?q?=E8=82=96=E6=B5=B7=E5=8D=97=E8=AE=BF?= =?UTF-8?q?=E9=97=AE=E8=AE=B0=E5=BD=95=E6=8E=A5=E5=8F=A3=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/umsAdmin/ReportController.java | 4 ++-- .../impl/report/ReportServiceImpl.java | 20 ++++++++++++------- .../backend/service/report/ReportService.java | 2 +- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/teaching/backend/controller/umsAdmin/ReportController.java b/src/main/java/com/teaching/backend/controller/umsAdmin/ReportController.java index 15b86c9..06deea1 100644 --- a/src/main/java/com/teaching/backend/controller/umsAdmin/ReportController.java +++ b/src/main/java/com/teaching/backend/controller/umsAdmin/ReportController.java @@ -35,9 +35,9 @@ public class ReportController { */ @PostMapping("/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(); } diff --git a/src/main/java/com/teaching/backend/service/impl/report/ReportServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/report/ReportServiceImpl.java index 3cabf56..e3ee1a3 100644 --- a/src/main/java/com/teaching/backend/service/impl/report/ReportServiceImpl.java +++ b/src/main/java/com/teaching/backend/service/impl/report/ReportServiceImpl.java @@ -59,13 +59,19 @@ public class ReportServiceImpl extends ServiceImpl 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 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; } diff --git a/src/main/java/com/teaching/backend/service/report/ReportService.java b/src/main/java/com/teaching/backend/service/report/ReportService.java index 5fbe678..74c1fcc 100644 --- a/src/main/java/com/teaching/backend/service/report/ReportService.java +++ b/src/main/java/com/teaching/backend/service/report/ReportService.java @@ -17,5 +17,5 @@ public interface ReportService extends IService { * 接收每日浏览量 * @return */ - boolean getReceptionBrowse(ReportDTO reportDTO); + boolean getReceptionBrowse(); } From 5a4749ae9d33238de58250d84af8330031580a57 Mon Sep 17 00:00:00 2001 From: wenyu441069198 <14186472+wenyu441069198@user.noreply.gitee.com> Date: Tue, 6 Aug 2024 16:19:03 +0800 Subject: [PATCH 07/11] =?UTF-8?q?=E8=82=96=E6=B5=B7=E5=8D=97=E4=B8=AA?= =?UTF-8?q?=E4=BA=BA=E4=B8=AD=E5=BF=83=E5=AD=A6=E4=B9=A0=E8=AE=B0=E5=BD=95?= =?UTF-8?q?=EF=BC=88=E7=9F=A5=E8=AF=86=E7=82=B9=EF=BC=89=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../KnowledgeLearningRecordController.java | 18 +++++++ .../KnowledgeLearningRecordMapper.java | 5 ++ .../backend/model/vo/knowGraph/KnowVO.java | 1 - .../KnowledgeLearningRecordServiceImpl.java | 52 +++++++++++++++++++ .../IKnowledgeLearningRecordService.java | 3 ++ .../mapper/KnowledgeLearningRecordMapper.xml | 20 +++++++ 6 files changed, 98 insertions(+), 1 deletion(-) create mode 100644 src/main/resources/mapper/KnowledgeLearningRecordMapper.xml 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 867889c..dac49ac 100644 --- a/src/main/java/com/teaching/backend/controller/records/KnowledgeLearningRecordController.java +++ b/src/main/java/com/teaching/backend/controller/records/KnowledgeLearningRecordController.java @@ -2,10 +2,13 @@ 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.model.entity.records.CourseLearningRecord; 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.service.impl.records.KnowledgeLearningRecordServiceImpl; import io.swagger.annotations.ApiOperation; import org.springframework.web.bind.annotation.*; @@ -53,5 +56,20 @@ public class KnowledgeLearningRecordController { return knowledgeLearningRecordService.removeKnowledgeRecord(ids); } + /** + * 获取学习最多的知识点 + * + * @return + */ + @ApiOperation("查询学习最多的知识点") + @PostMapping("/studyMaxKnowledge") + public CommonResult> studyMaxKnowledge(@RequestParam String userId) { + List knowVO = knowledgeLearningRecordService.queryMaxKnowledge(userId); + if (knowVO == null){ + CommonResult.failed("用户或角色错误"); + } + return CommonResult.success(knowVO); + } + } diff --git a/src/main/java/com/teaching/backend/mapper/records/KnowledgeLearningRecordMapper.java b/src/main/java/com/teaching/backend/mapper/records/KnowledgeLearningRecordMapper.java index d9dbbe5..78f4ada 100644 --- a/src/main/java/com/teaching/backend/mapper/records/KnowledgeLearningRecordMapper.java +++ b/src/main/java/com/teaching/backend/mapper/records/KnowledgeLearningRecordMapper.java @@ -4,6 +4,8 @@ package com.teaching.backend.mapper.records; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.teaching.backend.model.entity.records.KnowledgeLearningRecord; +import java.util.List; + /** *

* Mapper 接口 @@ -14,4 +16,7 @@ import com.teaching.backend.model.entity.records.KnowledgeLearningRecord; */ public interface KnowledgeLearningRecordMapper extends BaseMapper { + List queryStudyKnowledgeMaxNumber(); + + List queryStudyMaxKnowledgeId(String userId); } diff --git a/src/main/java/com/teaching/backend/model/vo/knowGraph/KnowVO.java b/src/main/java/com/teaching/backend/model/vo/knowGraph/KnowVO.java index d6a60a2..beaa1a2 100644 --- a/src/main/java/com/teaching/backend/model/vo/knowGraph/KnowVO.java +++ b/src/main/java/com/teaching/backend/model/vo/knowGraph/KnowVO.java @@ -3,7 +3,6 @@ package com.teaching.backend.model.vo.knowGraph; import lombok.Data; import java.io.Serializable; -import java.util.List; @Data 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 c26e3d9..da5e2be 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 @@ -8,15 +8,23 @@ 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; @@ -39,6 +47,12 @@ import java.util.List; public class KnowledgeLearningRecordServiceImpl extends ServiceImpl implements IKnowledgeLearningRecordService { @Resource private KnowledgeLearningNumberServiceImpl knowledgeLearningNumberService; + @Autowired + private UmsUserMapper umsUserMapper; + @Autowired + private KnowledgeLearningRecordMapper knowledgeLearningRecordMapper; + @Resource + private KnowService knowService; @Override public BaseResponse saveCoursesRecords(KnowledgeLearningRecord knowledgeLearningRecord) { @@ -115,4 +129,42 @@ public class KnowledgeLearningRecordServiceImpl extends ServiceImpl queryMaxKnowledge(String userId) { + String roleId = umsUserMapper.getbyIdRoleId(userId); + List coursesList = new ArrayList<>(); + KnowVO knowVO = null; + if (roleId.equals("1")){ + //老师 + List knowledgeIdList = knowledgeLearningRecordMapper.queryStudyKnowledgeMaxNumber(); + for (String knowledgeId : knowledgeIdList) { + BaseResponse 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 knowledgeIdList = knowledgeLearningRecordMapper.queryStudyMaxKnowledgeId(userId); + for (String knowledgeId : knowledgeIdList) { + BaseResponse 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; + } + } } 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 252d176..977aad0 100644 --- a/src/main/java/com/teaching/backend/service/records/IKnowledgeLearningRecordService.java +++ b/src/main/java/com/teaching/backend/service/records/IKnowledgeLearningRecordService.java @@ -5,6 +5,7 @@ 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 com.teaching.backend.model.vo.knowGraph.KnowVO; import java.util.List; @@ -23,5 +24,7 @@ public interface IKnowledgeLearningRecordService extends IService getPage(int pagenum, int pagesize, String userId, String courseId); BaseResponse removeKnowledgeRecord(List ids); + + List queryMaxKnowledge(String userId); } diff --git a/src/main/resources/mapper/KnowledgeLearningRecordMapper.xml b/src/main/resources/mapper/KnowledgeLearningRecordMapper.xml new file mode 100644 index 0000000..3ea0405 --- /dev/null +++ b/src/main/resources/mapper/KnowledgeLearningRecordMapper.xml @@ -0,0 +1,20 @@ + + + + + + + From 6329dec57dd278dcd3f1995f368c272e299a237a Mon Sep 17 00:00:00 2001 From: wenyu441069198 <14186472+wenyu441069198@user.noreply.gitee.com> Date: Tue, 6 Aug 2024 20:22:24 +0800 Subject: [PATCH 08/11] =?UTF-8?q?=E8=82=96=E6=B5=B7=E5=8D=97=E6=B5=8F?= =?UTF-8?q?=E8=A7=88=E5=B0=8F=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../teaching/backend/controller/umsAdmin/ReportController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/teaching/backend/controller/umsAdmin/ReportController.java b/src/main/java/com/teaching/backend/controller/umsAdmin/ReportController.java index 06deea1..439ea74 100644 --- a/src/main/java/com/teaching/backend/controller/umsAdmin/ReportController.java +++ b/src/main/java/com/teaching/backend/controller/umsAdmin/ReportController.java @@ -33,7 +33,7 @@ public class ReportController { * 接收每日浏览量 * @return */ - @PostMapping("/receptionBrowse") + @GetMapping("/receptionBrowse") @ApiOperation("接收每日浏览量") public CommonResult receptionBrowse(){ From e7c9fcbd077aff4f64653787d89dd0c88fa2be32 Mon Sep 17 00:00:00 2001 From: wenyu441069198 <14186472+wenyu441069198@user.noreply.gitee.com> Date: Tue, 6 Aug 2024 20:52:06 +0800 Subject: [PATCH 09/11] =?UTF-8?q?=E8=82=96=E6=B5=B7=E5=8D=97=E6=B5=8F?= =?UTF-8?q?=E8=A7=88=E5=B0=8F=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/report/ReportServiceImpl.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/teaching/backend/service/impl/report/ReportServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/report/ReportServiceImpl.java index e3ee1a3..dd42ddc 100644 --- a/src/main/java/com/teaching/backend/service/impl/report/ReportServiceImpl.java +++ b/src/main/java/com/teaching/backend/service/impl/report/ReportServiceImpl.java @@ -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 impleme @Override public BrowseReportVO getBrowseStatistics() { //存放访问的前一天至前七天的每天对应的日期 - List dateList = new ArrayList<>(); + List dateList = new ArrayList<>(); //存放这个月访问的前一天至前七天的每天对应的浏览量 List ThisMonthBrowseList = new ArrayList<>(); //存放上个月访问的前一天至前七天的每天对应的浏览量 @@ -36,7 +37,9 @@ public class ReportServiceImpl extends ServiceImpl 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 impleme LocalDate lastMonth = lastMonthToday.minusDays(i); //查询上个月的今天对应的浏览量 String lastMonthBrowse = reportMapper.getBrowseByTime(lastMonth); + + LastMonthBrowseList.add(lastMonthBrowse); } @@ -62,7 +67,7 @@ public class ReportServiceImpl extends ServiceImpl impleme public boolean getReceptionBrowse() { //查询今日有无记录 List 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(); From f4e78612f79276e0dcf9a31dde90033736000bdb Mon Sep 17 00:00:00 2001 From: wenyu441069198 <14186472+wenyu441069198@user.noreply.gitee.com> Date: Wed, 7 Aug 2024 17:23:07 +0800 Subject: [PATCH 10/11] =?UTF-8?q?=E6=96=87=E4=BB=B6=E4=B8=8A=E4=BC=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../KnowledgeLearningRecordController.java | 15 ++- .../ResourceLearningRecordController.java | 27 +++- .../KnowledgeLearningRecordMapper.java | 6 + .../records/ResourceLearningRecordMapper.java | 6 + .../KnowledgeLearningRecordServiceImpl.java | 15 ++- .../IKnowledgeLearningRecordService.java | 2 + .../com/teaching/backend/utils/Constants.java | 5 + .../teaching/backend/utils/UploadUtils.java | 115 ++++++++++++++++++ src/test/java/com/teaching/test.java | 37 ++++++ 9 files changed, 221 insertions(+), 7 deletions(-) create mode 100644 src/main/java/com/teaching/backend/utils/Constants.java create mode 100644 src/main/java/com/teaching/backend/utils/UploadUtils.java create mode 100644 src/test/java/com/teaching/test.java 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 dac49ac..f723a2d 100644 --- a/src/main/java/com/teaching/backend/controller/records/KnowledgeLearningRecordController.java +++ b/src/main/java/com/teaching/backend/controller/records/KnowledgeLearningRecordController.java @@ -5,9 +5,9 @@ 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.courses.CoursesVO; import com.teaching.backend.model.vo.knowGraph.KnowVO; import com.teaching.backend.service.impl.records.KnowledgeLearningRecordServiceImpl; import io.swagger.annotations.ApiOperation; @@ -21,6 +21,8 @@ import java.util.List; public class KnowledgeLearningRecordController { @Resource private KnowledgeLearningRecordServiceImpl knowledgeLearningRecordService; + @Resource + private KnowledgeLearningRecordMapper knowledgeLearningRecordMapper; @ApiOperation("添加知识点学习记录") // @ValidateParams({"userId","type","coursesId"}) @@ -56,6 +58,17 @@ public class KnowledgeLearningRecordController { return knowledgeLearningRecordService.removeKnowledgeRecord(ids); } + /** + * 统计单个学生学习知识点数量 + * @param userId + * @return + */ + @ApiOperation("统计单个学生学习知识点数量") + @GetMapping("/countknowledgenumber") + public BaseResponse countKnowledgeNumber(@RequestParam String userId) { + return ResultUtils.success(knowledgeLearningRecordMapper.selectDistinctKnowledgeIdsByUser(userId).size()); + } + /** * 获取学习最多的知识点 * 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 98ddfe4..e025d4d 100644 --- a/src/main/java/com/teaching/backend/controller/records/ResourceLearningRecordController.java +++ b/src/main/java/com/teaching/backend/controller/records/ResourceLearningRecordController.java @@ -4,10 +4,12 @@ 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.http.MediaType; import org.springframework.web.bind.annotation.*; @@ -17,6 +19,7 @@ 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 @@ -24,6 +27,10 @@ import java.util.List; public class ResourceLearningRecordController { @Resource private ResourceLearningRecordServiceImpl resourceLearningRecordService; + @Resource + private ResourceLearningRecordMapper resourceLearningRecordMapper; + + @ApiOperation("添加资源学习记录") // @ValidateParams({"userId","type","coursesId"}) @@ -60,11 +67,27 @@ public class ResourceLearningRecordController { return resourceLearningRecordService.removeResourceRecord(ids); } + /** + * 统计单个学生学习资源数量 + * @param userId + * @return + */ + @ApiOperation("统计单个学生学习资源数量") + @GetMapping("/countresourcenumber") + public BaseResponse countResourceNumber(@RequestParam String userId) { + return ResultUtils.success(resourceLearningRecordMapper.selectDistinctResourceIdsByUser(userId).size()); + } + + @ApiOperation("上传图片") @PostMapping(value = "/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) - public BaseResponse upload(@RequestPart("filedata") MultipartFile filedata){ + public BaseResponse 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"); diff --git a/src/main/java/com/teaching/backend/mapper/records/KnowledgeLearningRecordMapper.java b/src/main/java/com/teaching/backend/mapper/records/KnowledgeLearningRecordMapper.java index 78f4ada..2ddda90 100644 --- a/src/main/java/com/teaching/backend/mapper/records/KnowledgeLearningRecordMapper.java +++ b/src/main/java/com/teaching/backend/mapper/records/KnowledgeLearningRecordMapper.java @@ -3,6 +3,10 @@ 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; @@ -16,6 +20,8 @@ import java.util.List; */ public interface KnowledgeLearningRecordMapper extends BaseMapper { + @Select("SELECT knowledge_id FROM knowledge_learning_record WHERE user_id = #{userId} GROUP BY knowledge_id") + List selectDistinctKnowledgeIdsByUser(@Param("userId") String userId); List queryStudyKnowledgeMaxNumber(); List queryStudyMaxKnowledgeId(String userId); diff --git a/src/main/java/com/teaching/backend/mapper/records/ResourceLearningRecordMapper.java b/src/main/java/com/teaching/backend/mapper/records/ResourceLearningRecordMapper.java index c1235c1..4f7151f 100644 --- a/src/main/java/com/teaching/backend/mapper/records/ResourceLearningRecordMapper.java +++ b/src/main/java/com/teaching/backend/mapper/records/ResourceLearningRecordMapper.java @@ -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; /** *

@@ -13,5 +17,7 @@ import com.teaching.backend.model.entity.records.ResourceLearningRecord; * @since 2024-07-24 */ public interface ResourceLearningRecordMapper extends BaseMapper { + @Select("SELECT resource_id FROM resource_learning_record WHERE user_id = #{userId} GROUP BY resource_id") + List selectDistinctResourceIdsByUser(@Param("userId") String userId); } 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 da5e2be..0c10b1f 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 @@ -72,13 +72,18 @@ public class KnowledgeLearningRecordServiceImpl extends ServiceImpl 0){ + 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); @@ -96,6 +101,7 @@ public class KnowledgeLearningRecordServiceImpl extends ServiceImpl getPage(int pagenum, int pagesize, String userId, String courseId) { //格式化时间 @@ -167,4 +173,5 @@ public class KnowledgeLearningRecordServiceImpl extends ServiceImpl removeKnowledgeRecord(List ids); + List queryMaxKnowledge(String userId); } diff --git a/src/main/java/com/teaching/backend/utils/Constants.java b/src/main/java/com/teaching/backend/utils/Constants.java new file mode 100644 index 0000000..821d3f2 --- /dev/null +++ b/src/main/java/com/teaching/backend/utils/Constants.java @@ -0,0 +1,5 @@ +package com.teaching.backend.utils; + +public class Constants { + public static final String UPLOAD_URL = "E:\\workspace\\file\\"; +} diff --git a/src/main/java/com/teaching/backend/utils/UploadUtils.java b/src/main/java/com/teaching/backend/utils/UploadUtils.java new file mode 100644 index 0000000..bd844af --- /dev/null +++ b/src/main/java/com/teaching/backend/utils/UploadUtils.java @@ -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 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("文件合并成功!"); + } + } +} diff --git a/src/test/java/com/teaching/test.java b/src/test/java/com/teaching/test.java new file mode 100644 index 0000000..9fe8f16 --- /dev/null +++ b/src/test/java/com/teaching/test.java @@ -0,0 +1,37 @@ +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 { + + @Resource + private KnowledgeLearningCountServiceImpl knowledgeLearningCountService; + @Test + public void countknowledge(){ + String userId = "2"; +// System.out.println(knowledgeLearningCountService.list()); +// List list = knowledgeLearningCountService.query().eq("user_id", userId).list(); +// HashSet 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); +// } + } +} From e72468ec03414f90e97698afda75e29a806ac3c2 Mon Sep 17 00:00:00 2001 From: wenyu441069198 <14186472+wenyu441069198@user.noreply.gitee.com> Date: Wed, 7 Aug 2024 17:24:17 +0800 Subject: [PATCH 11/11] test --- src/test/java/com/teaching/test.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/test/java/com/teaching/test.java b/src/test/java/com/teaching/test.java index 9fe8f16..6d75620 100644 --- a/src/test/java/com/teaching/test.java +++ b/src/test/java/com/teaching/test.java @@ -11,8 +11,7 @@ import javax.annotation.Resource; @SpringBootTest public class test { - @Resource - private KnowledgeLearningCountServiceImpl knowledgeLearningCountService; + @Test public void countknowledge(){ String userId = "2";