diff --git a/src/main/java/com/teaching/backend/controller/Knowtmp/KnowtmpController.java b/src/main/java/com/teaching/backend/controller/Knowtmp/KnowtmpController.java index 8b28b1b..dbb122a 100644 --- a/src/main/java/com/teaching/backend/controller/Knowtmp/KnowtmpController.java +++ b/src/main/java/com/teaching/backend/controller/Knowtmp/KnowtmpController.java @@ -43,6 +43,11 @@ public class KnowtmpController { return knowtmpService.delete(id); } + //查询通过chapterId List + @GetMapping("/query") + BaseResponse query(Long id){ + return knowtmpService.query(id); + } //查询通过chapterId List @GetMapping("/queryKnow") BaseResponse> queryByChapterId(Long chapterId){ diff --git a/src/main/java/com/teaching/backend/controller/records/ResourceLearningRecordController.java b/src/main/java/com/teaching/backend/controller/records/ResourceLearningRecordController.java index e025d4d..29a3aca 100644 --- a/src/main/java/com/teaching/backend/controller/records/ResourceLearningRecordController.java +++ b/src/main/java/com/teaching/backend/controller/records/ResourceLearningRecordController.java @@ -1,102 +1,102 @@ -package com.teaching.backend.controller.records; - -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import com.teaching.backend.common.BaseResponse; -import com.teaching.backend.common.ResultUtils; -import com.teaching.backend.filter.ValidateParams; -import com.teaching.backend.mapper.records.ResourceLearningRecordMapper; -import com.teaching.backend.model.entity.records.KnowledgeLearningRecord; -import com.teaching.backend.model.entity.records.ResourceLearningRecord; -import com.teaching.backend.service.impl.records.KnowledgeLearningRecordServiceImpl; -import com.teaching.backend.service.impl.records.ResourceLearningRecordServiceImpl; -import com.teaching.backend.utils.UploadUtils; -import io.swagger.annotations.ApiOperation; -import org.springframework.http.MediaType; -import org.springframework.web.bind.annotation.*; -import org.springframework.web.multipart.MultipartFile; - -import javax.annotation.Resource; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.io.File; -import java.io.IOException; -import java.util.List; - -@RestController -@RequestMapping("/api/resourcelearningrecords") -public class ResourceLearningRecordController { - @Resource - private ResourceLearningRecordServiceImpl resourceLearningRecordService; - @Resource - private ResourceLearningRecordMapper resourceLearningRecordMapper; - - - - @ApiOperation("添加资源学习记录") -// @ValidateParams({"userId","type","coursesId"}) - @PostMapping("/saverecords") - public BaseResponse 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); - } - - /** - * 统计单个学生学习资源数量 - * @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) throws IOException { - //调用ser - System.out.println(filedata.getResource()); - System.out.println(UploadUtils.saveFileByDirectory(filedata)); -// File file = filedata.getResource().getFile(); -// UploadUtils.Chunk(file); -// UploadUtils.Merge(file); - //源文件 -// File sourseFile = (File) file; - return ResultUtils.success("hello"); - }; - - @GetMapping("/bf") - public BaseResponse bf(@RequestParam String path, File file,HttpServletRequest request, HttpServletResponse response){ - File sourseFile = new File(path); - return ResultUtils.success(path); - }; - -} +//package com.teaching.backend.controller.records; +// +//import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +//import com.teaching.backend.common.BaseResponse; +//import com.teaching.backend.common.ResultUtils; +//import com.teaching.backend.filter.ValidateParams; +//import com.teaching.backend.mapper.records.ResourceLearningRecordMapper; +//import com.teaching.backend.model.entity.records.KnowledgeLearningRecord; +//import com.teaching.backend.model.entity.records.ResourceLearningRecord; +//import com.teaching.backend.service.impl.records.KnowledgeLearningRecordServiceImpl; +//import com.teaching.backend.service.impl.records.ResourceLearningRecordServiceImpl; +//import com.teaching.backend.utils.UploadUtils; +//import io.swagger.annotations.ApiOperation; +//import org.springframework.http.MediaType; +//import org.springframework.web.bind.annotation.*; +//import org.springframework.web.multipart.MultipartFile; +// +//import javax.annotation.Resource; +//import javax.servlet.http.HttpServletRequest; +//import javax.servlet.http.HttpServletResponse; +//import java.io.File; +//import java.io.IOException; +//import java.util.List; +// +//@RestController +//@RequestMapping("/api/resourcelearningrecords") +//public class ResourceLearningRecordController { +// @Resource +// private ResourceLearningRecordServiceImpl resourceLearningRecordService; +// @Resource +// private ResourceLearningRecordMapper resourceLearningRecordMapper; +// +// +// +// @ApiOperation("添加资源学习记录") +//// @ValidateParams({"userId","type","coursesId"}) +// @PostMapping("/saverecords") +// public BaseResponse 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); +// } +// +// /** +// * 统计单个学生学习资源数量 +// * @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) throws IOException { +// //调用ser +// System.out.println(filedata.getResource()); +// System.out.println(UploadUtils.saveFileByDirectory(filedata)); +//// File file = filedata.getResource().getFile(); +//// UploadUtils.Chunk(file); +//// UploadUtils.Merge(file); +// //源文件 +//// File sourseFile = (File) file; +// return ResultUtils.success("hello"); +// }; +// +// @GetMapping("/bf") +// public BaseResponse 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/service/impl/knowtmp/KnowtmpServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/knowtmp/KnowtmpServiceImpl.java index a1b9ddd..8165dae 100644 --- a/src/main/java/com/teaching/backend/service/impl/knowtmp/KnowtmpServiceImpl.java +++ b/src/main/java/com/teaching/backend/service/impl/knowtmp/KnowtmpServiceImpl.java @@ -62,6 +62,12 @@ public class KnowtmpServiceImpl implements KnowtmpService { } } + @Override + public BaseResponse query(Long id) { + Knowtmp knowtmp = knowtmpMapper.selectById(id); + return ResultUtils.success(knowtmp); + } + @Override public BaseResponse> queryByChapterId(Long chapterId) { Knowtmp knowtmp = new Knowtmp(); 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 0c10b1f..cfe8d3e 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 @@ -9,20 +9,23 @@ 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.knowtmp.Knowtmp; 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.Know.KnowService; import com.teaching.backend.service.impl.courses.CourseLearningNumberServiceImpl; import com.teaching.backend.service.impl.knowledge.KnowledgeLearningNumberServiceImpl; +import com.teaching.backend.service.knowtmp.KnowtmpService; import com.teaching.backend.service.records.IKnowledgeLearningRecordService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -52,7 +55,7 @@ public class KnowledgeLearningRecordServiceImpl extends ServiceImpl saveCoursesRecords(KnowledgeLearningRecord knowledgeLearningRecord) { @@ -145,7 +148,7 @@ public class KnowledgeLearningRecordServiceImpl extends ServiceImpl knowledgeIdList = knowledgeLearningRecordMapper.queryStudyKnowledgeMaxNumber(); for (String knowledgeId : knowledgeIdList) { - BaseResponse knowledge = knowService.query(Long.valueOf(knowledgeId)); + BaseResponse knowledge = knowtmpService.query(Long.valueOf(knowledgeId)); if (knowledge.getData() != null){ knowVO = new KnowVO(); knowVO.setId(knowledge.getData().getId()); @@ -159,7 +162,7 @@ public class KnowledgeLearningRecordServiceImpl extends ServiceImpl knowledgeIdList = knowledgeLearningRecordMapper.queryStudyMaxKnowledgeId(userId); for (String knowledgeId : knowledgeIdList) { - BaseResponse knowledge = knowService.query(Long.valueOf(knowledgeId)); + BaseResponse knowledge = knowtmpService.query(Long.valueOf(knowledgeId)); if (knowledge.getData() != null) { knowVO = new KnowVO(); knowVO.setId(knowledge.getData().getId()); 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 14270e6..be8672c 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,127 +1,127 @@ -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; - -/** - *

- * 服务实现类 - *

- * - * @author author - * @since 2024-07-24 - */ -@Service -public class ResourceLearningRecordServiceImpl extends ServiceImpl implements IResourceLearningRecordService { - - @Resource - private ResourceLearningNumberServiceImpl resourceLearningNumberService; - - @Override - public BaseResponse saveCoursesRecords(ResourceLearningRecord resourceLearningRecord) { - //课程id - String courseId = resourceLearningRecord.getCoursesId(); - String knowledgeId = resourceLearningRecord.getKnowledgeId(); - String resourceId = resourceLearningRecord.getResourceId(); - String userId = resourceLearningRecord.getUserId(); - //1.生成学习时间 - resourceLearningRecord.setTimes(LocalDateTime.now()); - //2.设置人数 - //2.1查人数 - Long count = resourceLearningNumberService.query() - .eq("course_id", courseId) - .eq("knowledge_id",knowledgeId) - .eq("resource_id",resourceId).count(); - //2.2判断自己是否学习过 - Long count1 = query() - .eq("user_id", userId) - .eq("courses_id", courseId) - .eq("knowledge_id",knowledgeId) - .eq("resource_id",resourceId).count(); - if (count > 0){ - //自己没学过,人数加1 - if (count1 == 0){ - resourceLearningNumberService.update().setSql("number = number + 1") - .eq("course_id",courseId) - .eq("knowledge_id",knowledgeId) - .eq("resource_id",resourceId).update(); -// System.out.println("用户:"+userId+"第一次学这门课"); - } - }else { - //该课程第一次被学,人数设置为1 - ResourceLearningNumber resourceLearningNumber = new ResourceLearningNumber(); - resourceLearningNumber.setNumber(1); - resourceLearningNumber.setCourseId(courseId); - resourceLearningNumber.setKnowledgeId(knowledgeId); - resourceLearningNumber.setResourceId(resourceId); - resourceLearningNumberService.save(resourceLearningNumber); - } - //设置人数 - String numberId = resourceLearningNumberService.query() - .eq("course_id", courseId) - .eq("knowledge_id",knowledgeId) - .eq("resource_id",resourceId).one().getId(); - resourceLearningRecord.setNumber(numberId); - //保存记录 - save(resourceLearningRecord); - return ResultUtils.success("添加成功"); - } - - @Override - public BaseResponse 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("删除成功!"); - } - - -} +//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; +// +///** +// *

+// * 服务实现类 +// *

+// * +// * @author author +// * @since 2024-07-24 +// */ +//@Service +//public class ResourceLearningRecordServiceImpl extends ServiceImpl implements IResourceLearningRecordService { +// +// @Resource +// private ResourceLearningNumberServiceImpl resourceLearningNumberService; +// +// @Override +// public BaseResponse saveCoursesRecords(ResourceLearningRecord resourceLearningRecord) { +// //课程id +// String courseId = resourceLearningRecord.getCoursesId(); +// String knowledgeId = resourceLearningRecord.getKnowledgeId(); +// String resourceId = resourceLearningRecord.getResourceId(); +// String userId = resourceLearningRecord.getUserId(); +// //1.生成学习时间 +// resourceLearningRecord.setTimes(LocalDateTime.now()); +// //2.设置人数 +// //2.1查人数 +// Long count = resourceLearningNumberService.query() +// .eq("course_id", courseId) +// .eq("knowledge_id",knowledgeId) +// .eq("resource_id",resourceId).count(); +// //2.2判断自己是否学习过 +// Long count1 = query() +// .eq("user_id", userId) +// .eq("courses_id", courseId) +// .eq("knowledge_id",knowledgeId) +// .eq("resource_id",resourceId).count(); +// if (count > 0){ +// //自己没学过,人数加1 +// if (count1 == 0){ +// resourceLearningNumberService.update().setSql("number = number + 1") +// .eq("course_id",courseId) +// .eq("knowledge_id",knowledgeId) +// .eq("resource_id",resourceId).update(); +//// System.out.println("用户:"+userId+"第一次学这门课"); +// } +// }else { +// //该课程第一次被学,人数设置为1 +// ResourceLearningNumber resourceLearningNumber = new ResourceLearningNumber(); +// resourceLearningNumber.setNumber(1); +// resourceLearningNumber.setCourseId(courseId); +// resourceLearningNumber.setKnowledgeId(knowledgeId); +// resourceLearningNumber.setResourceId(resourceId); +// resourceLearningNumberService.save(resourceLearningNumber); +// } +// //设置人数 +// String numberId = resourceLearningNumberService.query() +// .eq("course_id", courseId) +// .eq("knowledge_id",knowledgeId) +// .eq("resource_id",resourceId).one().getId(); +// resourceLearningRecord.setNumber(numberId); +// //保存记录 +// save(resourceLearningRecord); +// return ResultUtils.success("添加成功"); +// } +// +// @Override +// public BaseResponse 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/knowtmp/KnowtmpService.java b/src/main/java/com/teaching/backend/service/knowtmp/KnowtmpService.java index aad7b68..193fe44 100644 --- a/src/main/java/com/teaching/backend/service/knowtmp/KnowtmpService.java +++ b/src/main/java/com/teaching/backend/service/knowtmp/KnowtmpService.java @@ -22,6 +22,9 @@ public interface KnowtmpService { //删除知识点 BaseResponse delete(Long id); + //查询 + BaseResponse query(Long id); + //查询通过chapterId List BaseResponse> queryByChapterId(Long chapterId);