学习记录

master
wenyu441069198 4 months ago
parent b0a99cefdf
commit 8d2e3e86ba
  1. 2
      src/main/java/com/teaching/backend/controller/records/CourseLearningRecordController.java
  2. 3
      src/main/java/com/teaching/backend/controller/records/KnowledgeLearningRecordController.java
  3. 3
      src/main/java/com/teaching/backend/controller/records/ResourceLearningRecordController.java
  4. 17
      src/main/java/com/teaching/backend/mapper/KnowGraph/KnowledgeLearningNumberMapper.java
  5. 17
      src/main/java/com/teaching/backend/mapper/resource/ResourceLearningNumberMapper.java
  6. 48
      src/main/java/com/teaching/backend/model/entity/KnowGraph/KnowledgeLearningNumber.java
  7. 7
      src/main/java/com/teaching/backend/model/entity/records/CourseLearningRecord.java
  8. 12
      src/main/java/com/teaching/backend/model/entity/records/KnowledgeLearningRecord.java
  9. 10
      src/main/java/com/teaching/backend/model/entity/records/ResourceLearningRecord.java
  10. 47
      src/main/java/com/teaching/backend/model/entity/resource/ResourceLearningNumber.java
  11. 17
      src/main/java/com/teaching/backend/service/KnowGraph/IKnowledgeLearningNumberService.java
  12. 21
      src/main/java/com/teaching/backend/service/impl/knowledge/KnowledgeLearningNumberServiceImpl.java
  13. 5
      src/main/java/com/teaching/backend/service/impl/records/CourseLearningRecordServiceImpl.java
  14. 49
      src/main/java/com/teaching/backend/service/impl/records/KnowledgeLearningRecordServiceImpl.java
  15. 55
      src/main/java/com/teaching/backend/service/impl/records/ResourceLearningRecordServiceImpl.java
  16. 22
      src/main/java/com/teaching/backend/service/impl/resource/ResourceLearningNumberServiceImpl.java
  17. 2
      src/main/java/com/teaching/backend/service/records/IKnowledgeLearningRecordService.java
  18. 2
      src/main/java/com/teaching/backend/service/records/IResourceLearningRecordService.java
  19. 17
      src/main/java/com/teaching/backend/service/resource/IResourceLearningNumberService.java

@ -32,7 +32,7 @@ public class CourseLearningRecordController {
* @return
*/
@ApiOperation("根据用户id查询学习记录")
@ValidateParams({"userId"})
// @ValidateParams({"userId"})
@GetMapping("/page")
public BaseResponse<Page> getAll(@RequestParam(value = "pagenum", defaultValue = "1") int pagenum,
@RequestParam(value = "pagesize", defaultValue = "10") int pagesize,

@ -24,8 +24,7 @@ public class KnowledgeLearningRecordController {
// @ValidateParams({"userId","type","coursesId"})
@PostMapping("/saverecords")
public BaseResponse<String> saveKnowledgeRecords(@RequestBody KnowledgeLearningRecord knowledgeLearningRecord){
knowledgeLearningRecordService.save(knowledgeLearningRecord);
return ResultUtils.success("添加成功");
return knowledgeLearningRecordService.saveCoursesRecords(knowledgeLearningRecord);
}
}

@ -24,7 +24,6 @@ public class ResourceLearningRecordController {
// @ValidateParams({"userId","type","coursesId"})
@PostMapping("/saverecords")
public BaseResponse<String> saveResourceRecords(@RequestBody ResourceLearningRecord resourceLearningRecord) {
resourceLearningRecordService.save(resourceLearningRecord);
return ResultUtils.success("添加成功");
return resourceLearningRecordService.saveCoursesRecords(resourceLearningRecord);
}
}

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

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

@ -0,0 +1,48 @@
package com.teaching.backend.model.entity.KnowGraph;
import com.baomidou.mybatisplus.annotation.TableField;
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("knowledge_learning_number")
@ApiModel(value="KnowledgeLearningNumber对象", description="")
public class KnowledgeLearningNumber implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "知识点学习记录id")
@TableId(value = "id", type = IdType.ASSIGN_ID)
private String id;
@ApiModelProperty(value = "课程id")
@TableField("course_id")
private String courseId;
@ApiModelProperty(value = "知识点id")
@TableField("knowledge_id")
private String knowledgeId;
@ApiModelProperty(value = "学习人数")
@TableField("number")
private Integer number;
}

@ -37,6 +37,11 @@ public class CourseLearningRecord implements Serializable {
@TableField("course_id")
private String courseId;
@ApiModelProperty(value = "课程名称")
@TableField("course_name")
private String courseName;
@ApiModelProperty(value = "用户id")
@TableField("user_id")
private String userId;
@ -50,7 +55,7 @@ public class CourseLearningRecord implements Serializable {
private String img;
@ApiModelProperty(value = "最近学习时间")
@TableField("time")
@TableField("times")
private LocalDateTime times;

@ -30,13 +30,17 @@ public class KnowledgeLearningRecord implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "知识点学习记录id")
@TableId(value = "id", type = IdType.AUTO)
@TableId(value = "id", type = IdType.ASSIGN_ID)
private String id;
@ApiModelProperty(value = "知识点id")
@TableField("knowledge_id")
private String knowledgeId;
@ApiModelProperty(value = "知识点id")
@TableField("knowledge_id")
private String knowledgeName;
@ApiModelProperty(value = "课程id")
@TableField("courses_id")
private String coursesId;
@ -47,15 +51,15 @@ public class KnowledgeLearningRecord implements Serializable {
@ApiModelProperty(value = "观看人数")
@TableField("number")
private Integer number;
private String number;
@ApiModelProperty(value = "记录封面")
@TableField("img")
private String img;
@ApiModelProperty(value = "最近访问时间")
@TableField("time")
private LocalDateTime time;
@TableField("times")
private LocalDateTime times;
}

@ -30,7 +30,7 @@ public class ResourceLearningRecord implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "资源学习记录id")
@TableId(value = "id", type = IdType.AUTO)
@TableId(value = "id", type = IdType.ASSIGN_ID)
private String id;
@ApiModelProperty(value = "资源id")
@ -51,14 +51,14 @@ public class ResourceLearningRecord implements Serializable {
@ApiModelProperty(value = "观看人数")
@TableField("number")
private Integer number;
private String number;
@ApiModelProperty(value = "是否打开, 1:开打了; 2:未打开;")
@TableField("open")
private Integer open;
@ApiModelProperty(value = "是否下载, 1:下载了; 2:未下载;")
@TableField(" download")
@TableField("download")
private Integer download;
@ApiModelProperty(value = "学习时长")
@ -74,8 +74,8 @@ public class ResourceLearningRecord implements Serializable {
private String img;
@ApiModelProperty(value = "最近学习时间")
@TableField("time")
private LocalDateTime time;
@TableField("times")
private LocalDateTime times;
}

@ -0,0 +1,47 @@
package com.teaching.backend.model.entity.resource;
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,17 @@
package com.teaching.backend.service.KnowGraph;
import com.baomidou.mybatisplus.extension.service.IService;
import com.teaching.backend.model.entity.KnowGraph.KnowledgeLearningNumber;
/**
* <p>
* 服务类
* </p>
*
* @author author
* @since 2024-07-29
*/
public interface IKnowledgeLearningNumberService extends IService<KnowledgeLearningNumber> {
}

@ -0,0 +1,21 @@
package com.teaching.backend.service.impl.knowledge;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.teaching.backend.mapper.KnowGraph.KnowledgeLearningNumberMapper;
import com.teaching.backend.model.entity.KnowGraph.KnowledgeLearningNumber;
import com.teaching.backend.service.KnowGraph.IKnowledgeLearningNumberService;
import org.springframework.stereotype.Service;
/**
* <p>
* 服务实现类
* </p>
*
* @author author
* @since 2024-07-29
*/
@Service
public class KnowledgeLearningNumberServiceImpl extends ServiceImpl<KnowledgeLearningNumberMapper, KnowledgeLearningNumber> implements IKnowledgeLearningNumberService {
}

@ -80,7 +80,7 @@ public class CourseLearningRecordServiceImpl extends ServiceImpl<CourseLearningR
SimpleDateFormat sdf = new SimpleDateFormat(strDateFormat);
//分页查询
Page<CourseLearningRecord> page = query()
.orderByDesc("time")
.orderByDesc("times")
.eq("user_id", userId).page(new Page<>(pagenum, pagesize));
Page<CourseLearningRecordsVo> page1 = new Page<>();
List<CourseLearningRecord> records = page.getRecords();
@ -92,8 +92,6 @@ public class CourseLearningRecordServiceImpl extends ServiceImpl<CourseLearningR
BeanUtil.copyProperties(courseLearningRecord,courseLearningRecordsVo);
Date date = Date.from(courseLearningRecord.getTimes().atZone(ZoneId.systemDefault()).toInstant());
courseLearningRecordsVo.setTime(sdf.format(date));
//填充课程名称
courseLearningRecordsVo.setCourseName(coursesService.getById(courseLearningRecord.getCourseId()).getName());
// //填充学习人数
courseLearningRecordsVo.setNumber(courseLearningNumberService.getById(courseLearningRecord.getNumber()).getNumber());
recordsVos.add(courseLearningRecordsVo);
@ -105,6 +103,7 @@ public class CourseLearningRecordServiceImpl extends ServiceImpl<CourseLearningR
@Override
public BaseResponse<String> removeCoursesRecords(List<Long> ids) {
removeByIds(ids);
// System.out.println(ids);
// List<CourseLearningRecord> list = query().in("id", ids).list();
// removeBatchByIds(list);
return ResultUtils.success("删除成功!");

@ -3,11 +3,20 @@ package com.teaching.backend.service.impl.records;
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.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.time.LocalDateTime;
/**
* <p>
* 服务实现类
@ -18,5 +27,45 @@ import org.springframework.stereotype.Service;
*/
@Service
public class KnowledgeLearningRecordServiceImpl extends ServiceImpl<KnowledgeLearningRecordMapper, KnowledgeLearningRecord> implements IKnowledgeLearningRecordService {
@Resource
private KnowledgeLearningNumberServiceImpl knowledgeLearningNumberService;
@Override
public BaseResponse<String> saveCoursesRecords(KnowledgeLearningRecord knowledgeLearningRecord) {
//知识点id
String courseId = knowledgeLearningRecord.getCoursesId();
String knowledgeId = knowledgeLearningRecord.getKnowledgeId();
String userId = knowledgeLearningRecord.getUserId();
//1.生成学习时间
knowledgeLearningRecord.setTimes(LocalDateTime.now());
//2.设置人数
//2.1查人数
Long count = knowledgeLearningNumberService.query()
.eq("course_id", courseId)
.eq("knowledge_id",knowledgeId).count();
//2.2判断自己是否学习过
Long count1 = query().eq("user_id", userId).count();
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+"第一次学这门课");
}
}else {
//该课程第一次被学,人数设置为1
KnowledgeLearningNumber knowledgeLearningNumber = new KnowledgeLearningNumber();
knowledgeLearningNumber.setNumber(1);
knowledgeLearningNumber.setCourseId(courseId);
knowledgeLearningNumber.setKnowledgeId(knowledgeId);
knowledgeLearningNumberService.save(knowledgeLearningNumber);
}
//设置人数
String numberId = knowledgeLearningNumberService.query()
.eq("course_id", courseId)
.eq("knowledge_id",knowledgeId).one().getId();
knowledgeLearningRecord.setNumber(numberId);
//保存记录
save(knowledgeLearningRecord);
return ResultUtils.success("添加成功");
}
}

@ -2,11 +2,18 @@ package com.teaching.backend.service.impl.records;
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.ResourceLearningRecord;
import com.teaching.backend.model.entity.resource.ResourceLearningNumber;
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.time.LocalDateTime;
/**
* <p>
* 服务实现类
@ -18,4 +25,52 @@ import org.springframework.stereotype.Service;
@Service
public class ResourceLearningRecordServiceImpl extends ServiceImpl<ResourceLearningRecordMapper, ResourceLearningRecord> implements IResourceLearningRecordService {
@Resource
private ResourceLearningNumberServiceImpl resourceLearningNumberService;
@Override
public BaseResponse<String> 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).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("添加成功");
}
}

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

@ -2,6 +2,7 @@ package com.teaching.backend.service.records;
import com.baomidou.mybatisplus.extension.service.IService;
import com.teaching.backend.common.BaseResponse;
import com.teaching.backend.model.entity.records.KnowledgeLearningRecord;
/**
@ -14,4 +15,5 @@ import com.teaching.backend.model.entity.records.KnowledgeLearningRecord;
*/
public interface IKnowledgeLearningRecordService extends IService<KnowledgeLearningRecord> {
BaseResponse<String> saveCoursesRecords(KnowledgeLearningRecord knowledgeLearningRecord);
}

@ -2,6 +2,7 @@ package com.teaching.backend.service.records;
import com.baomidou.mybatisplus.extension.service.IService;
import com.teaching.backend.common.BaseResponse;
import com.teaching.backend.model.entity.records.ResourceLearningRecord;
/**
@ -14,4 +15,5 @@ import com.teaching.backend.model.entity.records.ResourceLearningRecord;
*/
public interface IResourceLearningRecordService extends IService<ResourceLearningRecord> {
BaseResponse<String> saveCoursesRecords(ResourceLearningRecord resourceLearningRecord);
}

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