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 f44ee58..63a3f0d 100644 --- a/src/main/java/com/teaching/backend/controller/records/CourseLearningRecordController.java +++ b/src/main/java/com/teaching/backend/controller/records/CourseLearningRecordController.java @@ -32,7 +32,7 @@ public class CourseLearningRecordController { * @return */ @ApiOperation("根据用户id查询学习记录") - @ValidateParams({"userId"}) +// @ValidateParams({"userId"}) @GetMapping("/page") public BaseResponse getAll(@RequestParam(value = "pagenum", defaultValue = "1") int pagenum, @RequestParam(value = "pagesize", defaultValue = "10") int pagesize, 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 eb924c9..da94b8d 100644 --- a/src/main/java/com/teaching/backend/controller/records/KnowledgeLearningRecordController.java +++ b/src/main/java/com/teaching/backend/controller/records/KnowledgeLearningRecordController.java @@ -24,8 +24,7 @@ public class KnowledgeLearningRecordController { // @ValidateParams({"userId","type","coursesId"}) @PostMapping("/saverecords") public BaseResponse saveKnowledgeRecords(@RequestBody KnowledgeLearningRecord knowledgeLearningRecord){ - knowledgeLearningRecordService.save(knowledgeLearningRecord); - return ResultUtils.success("添加成功"); + return knowledgeLearningRecordService.saveCoursesRecords(knowledgeLearningRecord); } } 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 751f0fa..efbb8f2 100644 --- a/src/main/java/com/teaching/backend/controller/records/ResourceLearningRecordController.java +++ b/src/main/java/com/teaching/backend/controller/records/ResourceLearningRecordController.java @@ -24,7 +24,6 @@ public class ResourceLearningRecordController { // @ValidateParams({"userId","type","coursesId"}) @PostMapping("/saverecords") public BaseResponse saveResourceRecords(@RequestBody ResourceLearningRecord resourceLearningRecord) { - resourceLearningRecordService.save(resourceLearningRecord); - return ResultUtils.success("添加成功"); + return resourceLearningRecordService.saveCoursesRecords(resourceLearningRecord); } } diff --git a/src/main/java/com/teaching/backend/mapper/KnowGraph/KnowledgeLearningNumberMapper.java b/src/main/java/com/teaching/backend/mapper/KnowGraph/KnowledgeLearningNumberMapper.java new file mode 100644 index 0000000..0f66e8e --- /dev/null +++ b/src/main/java/com/teaching/backend/mapper/KnowGraph/KnowledgeLearningNumberMapper.java @@ -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; + +/** + *

+ * Mapper 接口 + *

+ * + * @author author + * @since 2024-07-29 + */ +public interface KnowledgeLearningNumberMapper extends BaseMapper { + +} diff --git a/src/main/java/com/teaching/backend/mapper/resource/ResourceLearningNumberMapper.java b/src/main/java/com/teaching/backend/mapper/resource/ResourceLearningNumberMapper.java new file mode 100644 index 0000000..8542b97 --- /dev/null +++ b/src/main/java/com/teaching/backend/mapper/resource/ResourceLearningNumberMapper.java @@ -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; + +/** + *

+ * Mapper 接口 + *

+ * + * @author author + * @since 2024-07-29 + */ +public interface ResourceLearningNumberMapper extends BaseMapper { + +} diff --git a/src/main/java/com/teaching/backend/model/entity/KnowGraph/KnowledgeLearningNumber.java b/src/main/java/com/teaching/backend/model/entity/KnowGraph/KnowledgeLearningNumber.java new file mode 100644 index 0000000..7fea27b --- /dev/null +++ b/src/main/java/com/teaching/backend/model/entity/KnowGraph/KnowledgeLearningNumber.java @@ -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; + +/** + *

+ * + *

+ * + * @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; + + +} diff --git a/src/main/java/com/teaching/backend/model/entity/records/CourseLearningRecord.java b/src/main/java/com/teaching/backend/model/entity/records/CourseLearningRecord.java index 142cfd5..1617d15 100644 --- a/src/main/java/com/teaching/backend/model/entity/records/CourseLearningRecord.java +++ b/src/main/java/com/teaching/backend/model/entity/records/CourseLearningRecord.java @@ -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; 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 2aa091b..7d1f11c 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 @@ -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; } 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 2b9f027..c33d691 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 @@ -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,15 +51,15 @@ 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") - private Integer download; + @TableField("download") + private Integer download; @ApiModelProperty(value = "学习时长") @TableField("duration") @@ -74,8 +74,8 @@ public class ResourceLearningRecord implements Serializable { private String img; @ApiModelProperty(value = "最近学习时间") - @TableField("time") - private LocalDateTime time; + @TableField("times") + private LocalDateTime times; } diff --git a/src/main/java/com/teaching/backend/model/entity/resource/ResourceLearningNumber.java b/src/main/java/com/teaching/backend/model/entity/resource/ResourceLearningNumber.java new file mode 100644 index 0000000..4ae2ee2 --- /dev/null +++ b/src/main/java/com/teaching/backend/model/entity/resource/ResourceLearningNumber.java @@ -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; + +/** + *

+ * + *

+ * + * @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; + + +} diff --git a/src/main/java/com/teaching/backend/service/KnowGraph/IKnowledgeLearningNumberService.java b/src/main/java/com/teaching/backend/service/KnowGraph/IKnowledgeLearningNumberService.java new file mode 100644 index 0000000..5d6864c --- /dev/null +++ b/src/main/java/com/teaching/backend/service/KnowGraph/IKnowledgeLearningNumberService.java @@ -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; + +/** + *

+ * 服务类 + *

+ * + * @author author + * @since 2024-07-29 + */ +public interface IKnowledgeLearningNumberService extends IService { + +} diff --git a/src/main/java/com/teaching/backend/service/impl/knowledge/KnowledgeLearningNumberServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/knowledge/KnowledgeLearningNumberServiceImpl.java new file mode 100644 index 0000000..2a1d42f --- /dev/null +++ b/src/main/java/com/teaching/backend/service/impl/knowledge/KnowledgeLearningNumberServiceImpl.java @@ -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; + +/** + *

+ * 服务实现类 + *

+ * + * @author author + * @since 2024-07-29 + */ +@Service +public class KnowledgeLearningNumberServiceImpl extends ServiceImpl implements IKnowledgeLearningNumberService { + +} 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 14a9795..425d74c 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 @@ -80,7 +80,7 @@ public class CourseLearningRecordServiceImpl extends ServiceImpl page = query() - .orderByDesc("time") + .orderByDesc("times") .eq("user_id", userId).page(new Page<>(pagenum, pagesize)); Page page1 = new Page<>(); List records = page.getRecords(); @@ -92,8 +92,6 @@ public class CourseLearningRecordServiceImpl extends ServiceImpl removeCoursesRecords(List ids) { removeByIds(ids); +// System.out.println(ids); // List list = query().in("id", ids).list(); // removeBatchByIds(list); return ResultUtils.success("删除成功!"); 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 f4d8a5f..fe3d252 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 @@ -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; + /** *

* 服务实现类 @@ -18,5 +27,45 @@ import org.springframework.stereotype.Service; */ @Service public class KnowledgeLearningRecordServiceImpl extends ServiceImpl implements IKnowledgeLearningRecordService { + @Resource + private KnowledgeLearningNumberServiceImpl knowledgeLearningNumberService; + @Override + public BaseResponse 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("添加成功"); + } } 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 19d34aa..1220371 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 @@ -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; + /** *

* 服务实现类 @@ -18,4 +25,52 @@ import org.springframework.stereotype.Service; @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).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("添加成功"); + } } diff --git a/src/main/java/com/teaching/backend/service/impl/resource/ResourceLearningNumberServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/resource/ResourceLearningNumberServiceImpl.java new file mode 100644 index 0000000..72f2136 --- /dev/null +++ b/src/main/java/com/teaching/backend/service/impl/resource/ResourceLearningNumberServiceImpl.java @@ -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; + +/** + *

+ * 服务实现类 + *

+ * + * @author author + * @since 2024-07-29 + */ +@Service +public class ResourceLearningNumberServiceImpl extends ServiceImpl implements IResourceLearningNumberService { + +} 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 c8387d1..ac279a5 100644 --- a/src/main/java/com/teaching/backend/service/records/IKnowledgeLearningRecordService.java +++ b/src/main/java/com/teaching/backend/service/records/IKnowledgeLearningRecordService.java @@ -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 { + BaseResponse saveCoursesRecords(KnowledgeLearningRecord knowledgeLearningRecord); } 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 8b191b6..2b53014 100644 --- a/src/main/java/com/teaching/backend/service/records/IResourceLearningRecordService.java +++ b/src/main/java/com/teaching/backend/service/records/IResourceLearningRecordService.java @@ -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 { + BaseResponse saveCoursesRecords(ResourceLearningRecord resourceLearningRecord); } diff --git a/src/main/java/com/teaching/backend/service/resource/IResourceLearningNumberService.java b/src/main/java/com/teaching/backend/service/resource/IResourceLearningNumberService.java new file mode 100644 index 0000000..f35e1f4 --- /dev/null +++ b/src/main/java/com/teaching/backend/service/resource/IResourceLearningNumberService.java @@ -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; + +/** + *

+ * 服务类 + *

+ * + * @author author + * @since 2024-07-29 + */ +public interface IResourceLearningNumberService extends IService { + +}