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

master
yh 4 months ago
commit 23a31c3a51
  1. 204
      src/main/java/com/teaching/backend/controller/records/ResourceLearningRecordController.java
  2. 17
      src/main/java/com/teaching/backend/mapper/records/ResourceLearningNumberMapper.java
  3. 47
      src/main/java/com/teaching/backend/model/entity/records/ResourceLearningNumber.java
  4. 22
      src/main/java/com/teaching/backend/service/impl/records/ResourceLearningNumberServiceImpl.java
  5. 252
      src/main/java/com/teaching/backend/service/impl/records/ResourceLearningRecordServiceImpl.java
  6. 17
      src/main/java/com/teaching/backend/service/records/IResourceLearningNumberService.java

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

@ -0,0 +1,17 @@
package com.teaching.backend.mapper.records;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.teaching.backend.model.entity.records.ResourceLearningNumber;
/**
* <p>
* Mapper 接口
* </p>
*
* @author author
* @since 2024-07-29
*/
public interface ResourceLearningNumberMapper extends BaseMapper<ResourceLearningNumber> {
}

@ -0,0 +1,47 @@
package com.teaching.backend.model.entity.records;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import java.io.Serializable;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
/**
* <p>
*
* </p>
*
* @author author
* @since 2024-07-29
*/
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName("resource_learning_number")
@ApiModel(value="ResourceLearningNumber对象", description="")
public class ResourceLearningNumber implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "资源学习记录id")
@TableId(value = "id", type = IdType.ASSIGN_ID)
private String id;
@ApiModelProperty(value = "课程id")
private String courseId;
@ApiModelProperty(value = "知识点id")
private String knowledgeId;
@ApiModelProperty(value = "资源id")
private String resourceId;
@ApiModelProperty(value = "学习人数")
private Integer number;
}

@ -0,0 +1,22 @@
package com.teaching.backend.service.impl.records;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.teaching.backend.mapper.records.ResourceLearningNumberMapper;
import com.teaching.backend.model.entity.records.ResourceLearningNumber;
import com.teaching.backend.service.records.IResourceLearningNumberService;
import org.springframework.stereotype.Service;
/**
* <p>
* 服务实现类
* </p>
*
* @author author
* @since 2024-07-29
*/
@Service
public class ResourceLearningNumberServiceImpl extends ServiceImpl<ResourceLearningNumberMapper, ResourceLearningNumber> implements IResourceLearningNumberService {
}

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

@ -0,0 +1,17 @@
package com.teaching.backend.service.records;
import com.baomidou.mybatisplus.extension.service.IService;
import com.teaching.backend.model.entity.records.ResourceLearningNumber;
/**
* <p>
* 服务类
* </p>
*
* @author author
* @since 2024-07-29
*/
public interface IResourceLearningNumberService extends IService<ResourceLearningNumber> {
}
Loading…
Cancel
Save