parent
205de3c972
commit
0592c2ed53
6 changed files with 252 additions and 235 deletions
@ -1,102 +1,102 @@ |
|||||||
package com.teaching.backend.controller.records; |
//package com.teaching.backend.controller.records;
|
||||||
|
//
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
//import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.teaching.backend.common.BaseResponse; |
//import com.teaching.backend.common.BaseResponse;
|
||||||
import com.teaching.backend.common.ResultUtils; |
//import com.teaching.backend.common.ResultUtils;
|
||||||
import com.teaching.backend.filter.ValidateParams; |
//import com.teaching.backend.filter.ValidateParams;
|
||||||
import com.teaching.backend.mapper.records.ResourceLearningRecordMapper; |
//import com.teaching.backend.mapper.records.ResourceLearningRecordMapper;
|
||||||
import com.teaching.backend.model.entity.records.KnowledgeLearningRecord; |
//import com.teaching.backend.model.entity.records.KnowledgeLearningRecord;
|
||||||
import com.teaching.backend.model.entity.records.ResourceLearningRecord; |
//import com.teaching.backend.model.entity.records.ResourceLearningRecord;
|
||||||
import com.teaching.backend.service.impl.records.KnowledgeLearningRecordServiceImpl; |
//import com.teaching.backend.service.impl.records.KnowledgeLearningRecordServiceImpl;
|
||||||
import com.teaching.backend.service.impl.records.ResourceLearningRecordServiceImpl; |
//import com.teaching.backend.service.impl.records.ResourceLearningRecordServiceImpl;
|
||||||
import com.teaching.backend.utils.UploadUtils; |
//import com.teaching.backend.utils.UploadUtils;
|
||||||
import io.swagger.annotations.ApiOperation; |
//import io.swagger.annotations.ApiOperation;
|
||||||
import org.springframework.http.MediaType; |
//import org.springframework.http.MediaType;
|
||||||
import org.springframework.web.bind.annotation.*; |
//import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.multipart.MultipartFile; |
//import org.springframework.web.multipart.MultipartFile;
|
||||||
|
//
|
||||||
import javax.annotation.Resource; |
//import javax.annotation.Resource;
|
||||||
import javax.servlet.http.HttpServletRequest; |
//import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse; |
//import javax.servlet.http.HttpServletResponse;
|
||||||
import java.io.File; |
//import java.io.File;
|
||||||
import java.io.IOException; |
//import java.io.IOException;
|
||||||
import java.util.List; |
//import java.util.List;
|
||||||
|
//
|
||||||
@RestController |
//@RestController
|
||||||
@RequestMapping("/api/resourcelearningrecords") |
//@RequestMapping("/api/resourcelearningrecords")
|
||||||
public class ResourceLearningRecordController { |
//public class ResourceLearningRecordController {
|
||||||
@Resource |
// @Resource
|
||||||
private ResourceLearningRecordServiceImpl resourceLearningRecordService; |
// private ResourceLearningRecordServiceImpl resourceLearningRecordService;
|
||||||
@Resource |
// @Resource
|
||||||
private ResourceLearningRecordMapper resourceLearningRecordMapper; |
// private ResourceLearningRecordMapper resourceLearningRecordMapper;
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
@ApiOperation("添加资源学习记录") |
// @ApiOperation("添加资源学习记录")
|
||||||
// @ValidateParams({"userId","type","coursesId"})
|
//// @ValidateParams({"userId","type","coursesId"})
|
||||||
@PostMapping("/saverecords") |
// @PostMapping("/saverecords")
|
||||||
public BaseResponse<String> saveResourceRecords(@RequestBody ResourceLearningRecord resourceLearningRecord) { |
// public BaseResponse<String> saveResourceRecords(@RequestBody ResourceLearningRecord resourceLearningRecord) {
|
||||||
return resourceLearningRecordService.saveCoursesRecords(resourceLearningRecord); |
// return resourceLearningRecordService.saveCoursesRecords(resourceLearningRecord);
|
||||||
} |
// }
|
||||||
|
//
|
||||||
/** |
// /**
|
||||||
* 获取当前登录用户的学习资源记录 |
// * 获取当前登录用户的学习资源记录
|
||||||
* @param pagenum |
// * @param pagenum
|
||||||
* @param pagesize |
// * @param pagesize
|
||||||
* @return |
// * @return
|
||||||
*/ |
// */
|
||||||
@ApiOperation("根据用户id查询学习记录") |
// @ApiOperation("根据用户id查询学习记录")
|
||||||
@ValidateParams({"userId"}) |
// @ValidateParams({"userId"})
|
||||||
@GetMapping("/page") |
// @GetMapping("/page")
|
||||||
public BaseResponse<Page> getAll(@RequestParam(value = "pagenum", defaultValue = "1") int pagenum, |
// public BaseResponse<Page> getAll(@RequestParam(value = "pagenum", defaultValue = "1") int pagenum,
|
||||||
@RequestParam(value = "pagesize", defaultValue = "10") int pagesize, |
// @RequestParam(value = "pagesize", defaultValue = "10") int pagesize,
|
||||||
@RequestParam String userId, |
// @RequestParam String userId,
|
||||||
@RequestParam String courseId, |
// @RequestParam String courseId,
|
||||||
@RequestParam String knowledgeId){ |
// @RequestParam String knowledgeId){
|
||||||
return resourceLearningRecordService.getPage(pagenum, pagesize, userId, knowledgeId,courseId); |
// return resourceLearningRecordService.getPage(pagenum, pagesize, userId, knowledgeId,courseId);
|
||||||
|
//
|
||||||
} |
// }
|
||||||
/** |
// /**
|
||||||
* 根据ids删除 |
// * 根据ids删除
|
||||||
* @param ids |
// * @param ids
|
||||||
* @return |
// * @return
|
||||||
*/ |
// */
|
||||||
@ApiOperation("学习记录删除") |
// @ApiOperation("学习记录删除")
|
||||||
@DeleteMapping("/delete") |
// @DeleteMapping("/delete")
|
||||||
public BaseResponse<String> deleteRecords(@RequestParam List<Long> ids){ |
// public BaseResponse<String> deleteRecords(@RequestParam List<Long> ids){
|
||||||
return resourceLearningRecordService.removeResourceRecord(ids); |
// return resourceLearningRecordService.removeResourceRecord(ids);
|
||||||
} |
// }
|
||||||
|
//
|
||||||
/** |
// /**
|
||||||
* 统计单个学生学习资源数量 |
// * 统计单个学生学习资源数量
|
||||||
* @param userId |
// * @param userId
|
||||||
* @return |
// * @return
|
||||||
*/ |
// */
|
||||||
@ApiOperation("统计单个学生学习资源数量") |
// @ApiOperation("统计单个学生学习资源数量")
|
||||||
@GetMapping("/countresourcenumber") |
// @GetMapping("/countresourcenumber")
|
||||||
public BaseResponse<Integer> countResourceNumber(@RequestParam String userId) { |
// public BaseResponse<Integer> countResourceNumber(@RequestParam String userId) {
|
||||||
return ResultUtils.success(resourceLearningRecordMapper.selectDistinctResourceIdsByUser(userId).size()); |
// return ResultUtils.success(resourceLearningRecordMapper.selectDistinctResourceIdsByUser(userId).size());
|
||||||
} |
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
@ApiOperation("上传图片") |
// @ApiOperation("上传图片")
|
||||||
@PostMapping(value = "/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) |
// @PostMapping(value = "/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||||
public BaseResponse<String> upload(@RequestPart("filedata") MultipartFile filedata) throws IOException { |
// public BaseResponse<String> upload(@RequestPart("filedata") MultipartFile filedata) throws IOException {
|
||||||
//调用ser
|
// //调用ser
|
||||||
System.out.println(filedata.getResource()); |
// System.out.println(filedata.getResource());
|
||||||
System.out.println(UploadUtils.saveFileByDirectory(filedata)); |
// System.out.println(UploadUtils.saveFileByDirectory(filedata));
|
||||||
// File file = filedata.getResource().getFile();
|
//// File file = filedata.getResource().getFile();
|
||||||
// UploadUtils.Chunk(file);
|
//// UploadUtils.Chunk(file);
|
||||||
// UploadUtils.Merge(file);
|
//// UploadUtils.Merge(file);
|
||||||
//源文件
|
// //源文件
|
||||||
// File sourseFile = (File) file;
|
//// File sourseFile = (File) file;
|
||||||
return ResultUtils.success("hello"); |
// return ResultUtils.success("hello");
|
||||||
}; |
// };
|
||||||
|
//
|
||||||
@GetMapping("/bf") |
// @GetMapping("/bf")
|
||||||
public BaseResponse<String> bf(@RequestParam String path, File file,HttpServletRequest request, HttpServletResponse response){ |
// public BaseResponse<String> bf(@RequestParam String path, File file,HttpServletRequest request, HttpServletResponse response){
|
||||||
File sourseFile = new File(path); |
// File sourseFile = new File(path);
|
||||||
return ResultUtils.success(path); |
// return ResultUtils.success(path);
|
||||||
}; |
// };
|
||||||
|
//
|
||||||
} |
//}
|
||||||
|
@ -1,127 +1,127 @@ |
|||||||
package com.teaching.backend.service.impl.records; |
//package com.teaching.backend.service.impl.records;
|
||||||
|
//
|
||||||
|
//
|
||||||
import cn.hutool.core.bean.BeanUtil; |
//import cn.hutool.core.bean.BeanUtil;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
//import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
//import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.teaching.backend.common.BaseResponse; |
//import com.teaching.backend.common.BaseResponse;
|
||||||
import com.teaching.backend.common.ResultUtils; |
//import com.teaching.backend.common.ResultUtils;
|
||||||
import com.teaching.backend.mapper.records.ResourceLearningRecordMapper; |
//import com.teaching.backend.mapper.records.ResourceLearningRecordMapper;
|
||||||
import com.teaching.backend.model.entity.records.KnowledgeLearningRecord; |
//import com.teaching.backend.model.entity.records.KnowledgeLearningRecord;
|
||||||
import com.teaching.backend.model.entity.records.ResourceLearningRecord; |
//import com.teaching.backend.model.entity.records.ResourceLearningRecord;
|
||||||
import com.teaching.backend.model.entity.resource.ResourceLearningNumber; |
//import com.teaching.backend.model.entity.resource.ResourceLearningNumber;
|
||||||
import com.teaching.backend.model.vo.records.KnowledgeLearningRecordVo; |
//import com.teaching.backend.model.vo.records.KnowledgeLearningRecordVo;
|
||||||
import com.teaching.backend.model.vo.records.ResourceLearingRecordVo; |
//import com.teaching.backend.model.vo.records.ResourceLearingRecordVo;
|
||||||
import com.teaching.backend.service.impl.resource.ResourceLearningNumberServiceImpl; |
//import com.teaching.backend.service.impl.resource.ResourceLearningNumberServiceImpl;
|
||||||
import com.teaching.backend.service.records.IResourceLearningRecordService; |
//import com.teaching.backend.service.records.IResourceLearningRecordService;
|
||||||
import org.springframework.stereotype.Service; |
//import org.springframework.stereotype.Service;
|
||||||
|
//
|
||||||
import javax.annotation.Resource; |
//import javax.annotation.Resource;
|
||||||
import java.text.SimpleDateFormat; |
//import java.text.SimpleDateFormat;
|
||||||
import java.time.LocalDateTime; |
//import java.time.LocalDateTime;
|
||||||
import java.time.ZoneId; |
//import java.time.ZoneId;
|
||||||
import java.util.ArrayList; |
//import java.util.ArrayList;
|
||||||
import java.util.Date; |
//import java.util.Date;
|
||||||
import java.util.List; |
//import java.util.List;
|
||||||
|
//
|
||||||
/** |
///**
|
||||||
* <p> |
// * <p>
|
||||||
* 服务实现类 |
// * 服务实现类
|
||||||
* </p> |
// * </p>
|
||||||
* |
// *
|
||||||
* @author author |
// * @author author
|
||||||
* @since 2024-07-24 |
// * @since 2024-07-24
|
||||||
*/ |
// */
|
||||||
@Service |
//@Service
|
||||||
public class ResourceLearningRecordServiceImpl extends ServiceImpl<ResourceLearningRecordMapper, ResourceLearningRecord> implements IResourceLearningRecordService { |
//public class ResourceLearningRecordServiceImpl extends ServiceImpl<ResourceLearningRecordMapper, ResourceLearningRecord> implements IResourceLearningRecordService {
|
||||||
|
//
|
||||||
@Resource |
// @Resource
|
||||||
private ResourceLearningNumberServiceImpl resourceLearningNumberService; |
// private ResourceLearningNumberServiceImpl resourceLearningNumberService;
|
||||||
|
//
|
||||||
@Override |
// @Override
|
||||||
public BaseResponse<String> saveCoursesRecords(ResourceLearningRecord resourceLearningRecord) { |
// public BaseResponse<String> saveCoursesRecords(ResourceLearningRecord resourceLearningRecord) {
|
||||||
//课程id
|
// //课程id
|
||||||
String courseId = resourceLearningRecord.getCoursesId(); |
// String courseId = resourceLearningRecord.getCoursesId();
|
||||||
String knowledgeId = resourceLearningRecord.getKnowledgeId(); |
// String knowledgeId = resourceLearningRecord.getKnowledgeId();
|
||||||
String resourceId = resourceLearningRecord.getResourceId(); |
// String resourceId = resourceLearningRecord.getResourceId();
|
||||||
String userId = resourceLearningRecord.getUserId(); |
// String userId = resourceLearningRecord.getUserId();
|
||||||
//1.生成学习时间
|
// //1.生成学习时间
|
||||||
resourceLearningRecord.setTimes(LocalDateTime.now()); |
// resourceLearningRecord.setTimes(LocalDateTime.now());
|
||||||
//2.设置人数
|
// //2.设置人数
|
||||||
//2.1查人数
|
// //2.1查人数
|
||||||
Long count = resourceLearningNumberService.query() |
// Long count = resourceLearningNumberService.query()
|
||||||
.eq("course_id", courseId) |
// .eq("course_id", courseId)
|
||||||
.eq("knowledge_id",knowledgeId) |
// .eq("knowledge_id",knowledgeId)
|
||||||
.eq("resource_id",resourceId).count(); |
// .eq("resource_id",resourceId).count();
|
||||||
//2.2判断自己是否学习过
|
// //2.2判断自己是否学习过
|
||||||
Long count1 = query() |
// Long count1 = query()
|
||||||
.eq("user_id", userId) |
// .eq("user_id", userId)
|
||||||
.eq("courses_id", courseId) |
// .eq("courses_id", courseId)
|
||||||
.eq("knowledge_id",knowledgeId) |
// .eq("knowledge_id",knowledgeId)
|
||||||
.eq("resource_id",resourceId).count(); |
// .eq("resource_id",resourceId).count();
|
||||||
if (count > 0){ |
// if (count > 0){
|
||||||
//自己没学过,人数加1
|
// //自己没学过,人数加1
|
||||||
if (count1 == 0){ |
// if (count1 == 0){
|
||||||
resourceLearningNumberService.update().setSql("number = number + 1") |
// resourceLearningNumberService.update().setSql("number = number + 1")
|
||||||
.eq("course_id",courseId) |
// .eq("course_id",courseId)
|
||||||
.eq("knowledge_id",knowledgeId) |
// .eq("knowledge_id",knowledgeId)
|
||||||
.eq("resource_id",resourceId).update(); |
// .eq("resource_id",resourceId).update();
|
||||||
// System.out.println("用户:"+userId+"第一次学这门课");
|
//// System.out.println("用户:"+userId+"第一次学这门课");
|
||||||
} |
// }
|
||||||
}else { |
// }else {
|
||||||
//该课程第一次被学,人数设置为1
|
// //该课程第一次被学,人数设置为1
|
||||||
ResourceLearningNumber resourceLearningNumber = new ResourceLearningNumber(); |
// ResourceLearningNumber resourceLearningNumber = new ResourceLearningNumber();
|
||||||
resourceLearningNumber.setNumber(1); |
// resourceLearningNumber.setNumber(1);
|
||||||
resourceLearningNumber.setCourseId(courseId); |
// resourceLearningNumber.setCourseId(courseId);
|
||||||
resourceLearningNumber.setKnowledgeId(knowledgeId); |
// resourceLearningNumber.setKnowledgeId(knowledgeId);
|
||||||
resourceLearningNumber.setResourceId(resourceId); |
// resourceLearningNumber.setResourceId(resourceId);
|
||||||
resourceLearningNumberService.save(resourceLearningNumber); |
// resourceLearningNumberService.save(resourceLearningNumber);
|
||||||
} |
// }
|
||||||
//设置人数
|
// //设置人数
|
||||||
String numberId = resourceLearningNumberService.query() |
// String numberId = resourceLearningNumberService.query()
|
||||||
.eq("course_id", courseId) |
// .eq("course_id", courseId)
|
||||||
.eq("knowledge_id",knowledgeId) |
// .eq("knowledge_id",knowledgeId)
|
||||||
.eq("resource_id",resourceId).one().getId(); |
// .eq("resource_id",resourceId).one().getId();
|
||||||
resourceLearningRecord.setNumber(numberId); |
// resourceLearningRecord.setNumber(numberId);
|
||||||
//保存记录
|
// //保存记录
|
||||||
save(resourceLearningRecord); |
// save(resourceLearningRecord);
|
||||||
return ResultUtils.success("添加成功"); |
// return ResultUtils.success("添加成功");
|
||||||
} |
// }
|
||||||
|
//
|
||||||
@Override |
// @Override
|
||||||
public BaseResponse<Page> getPage(int pagenum, int pagesize, String userId, String knowledgeId, String courseId) { |
// public BaseResponse<Page> getPage(int pagenum, int pagesize, String userId, String knowledgeId, String courseId) {
|
||||||
//格式化时间
|
////格式化时间
|
||||||
String strDateFormat = "yyyy-MM-dd HH:mm:ss"; |
// String strDateFormat = "yyyy-MM-dd HH:mm:ss";
|
||||||
SimpleDateFormat sdf = new SimpleDateFormat(strDateFormat); |
// SimpleDateFormat sdf = new SimpleDateFormat(strDateFormat);
|
||||||
//分页查询
|
// //分页查询
|
||||||
Page<ResourceLearningRecord> page = query() |
// Page<ResourceLearningRecord> page = query()
|
||||||
.orderByDesc("times") |
// .orderByDesc("times")
|
||||||
.eq("user_id", userId) |
// .eq("user_id", userId)
|
||||||
.eq("knowledge_id",knowledgeId) |
// .eq("knowledge_id",knowledgeId)
|
||||||
.eq("courses_id",courseId).page(new Page<>(pagenum, pagesize)); |
// .eq("courses_id",courseId).page(new Page<>(pagenum, pagesize));
|
||||||
Page<ResourceLearingRecordVo> page1 = new Page<>(); |
// Page<ResourceLearingRecordVo> page1 = new Page<>();
|
||||||
List<ResourceLearningRecord> records = page.getRecords(); |
// List<ResourceLearningRecord> records = page.getRecords();
|
||||||
BeanUtil.copyProperties(page, page1); |
// BeanUtil.copyProperties(page, page1);
|
||||||
List<ResourceLearingRecordVo> recordsVos = new ArrayList<>(); |
// List<ResourceLearingRecordVo> recordsVos = new ArrayList<>();
|
||||||
//copy集合
|
// //copy集合
|
||||||
records.forEach(resourceLearningRecord -> { |
// records.forEach(resourceLearningRecord -> {
|
||||||
ResourceLearingRecordVo resourceLearingRecordVo = new ResourceLearingRecordVo(); |
// ResourceLearingRecordVo resourceLearingRecordVo = new ResourceLearingRecordVo();
|
||||||
BeanUtil.copyProperties(resourceLearningRecord,resourceLearingRecordVo); |
// BeanUtil.copyProperties(resourceLearningRecord,resourceLearingRecordVo);
|
||||||
Date date = Date.from(resourceLearningRecord.getTimes().atZone(ZoneId.systemDefault()).toInstant()); |
// Date date = Date.from(resourceLearningRecord.getTimes().atZone(ZoneId.systemDefault()).toInstant());
|
||||||
resourceLearingRecordVo.setTime(sdf.format(date)); |
// resourceLearingRecordVo.setTime(sdf.format(date));
|
||||||
// //填充学习人数
|
//// //填充学习人数
|
||||||
resourceLearingRecordVo.setNumber(resourceLearningNumberService.getById(resourceLearningRecord.getNumber()).getNumber()); |
// resourceLearingRecordVo.setNumber(resourceLearningNumberService.getById(resourceLearningRecord.getNumber()).getNumber());
|
||||||
recordsVos.add(resourceLearingRecordVo); |
// recordsVos.add(resourceLearingRecordVo);
|
||||||
}); |
// });
|
||||||
page1.setRecords(recordsVos); |
// page1.setRecords(recordsVos);
|
||||||
return ResultUtils.success(page1); |
// return ResultUtils.success(page1);
|
||||||
} |
// }
|
||||||
|
//
|
||||||
@Override |
// @Override
|
||||||
public BaseResponse<String> removeResourceRecord(List<Long> ids) { |
// public BaseResponse<String> removeResourceRecord(List<Long> ids) {
|
||||||
removeByIds(ids); |
// removeByIds(ids);
|
||||||
return ResultUtils.success("删除成功!"); |
// return ResultUtils.success("删除成功!");
|
||||||
} |
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
} |
//}
|
||||||
|
Loading…
Reference in new issue