From 6f6365c52b6e43ca6a65960fe86a82208027c692 Mon Sep 17 00:00:00 2001
From: wenyu441069198 <14186472+wenyu441069198@user.noreply.gitee.com>
Date: Fri, 7 Jun 2024 19:34:13 +0800
Subject: [PATCH] =?UTF-8?q?=E5=AD=A6=E4=B9=A0=E8=AE=B0=E5=BD=95init?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
pom.xml | 8 +
.../backend/controller/ChapterController.java | 20 --
.../controller/chapter/ChapterController.java | 28 ---
.../records/LearningRecordsController.java | 89 +++++++++
.../backend/mapper/ChapterMapper.java | 16 --
.../mapper/know}/KnowMapper.java | 4 +-
.../mapper/records/LearningRecordsMapper.java | 15 ++
.../backend/model/entity/chapter/Chapter.java | 1 -
.../model/entity/know}/Know.java | 3 +-
.../model/entity/records/LearningRecords.java | 96 +++++++++
.../model/vo/records/LearningRecordsVo.java | 59 ++++++
.../backend/service/IChapterService.java | 16 --
.../service/impl/ChapterServiceImpl.java | 20 --
.../service/impl/know/IknowServiceimpl.java | 12 ++
.../records/LearningRecordsServiceImpl.java | 185 ++++++++++++++++++
.../service/know}/IknowService.java | 5 +-
.../records/LearningRecordsService.java | 19 ++
.../service/impl/IknowServiceimpl.java | 13 --
18 files changed, 488 insertions(+), 121 deletions(-)
delete mode 100644 src/main/java/com/teaching/backend/controller/ChapterController.java
delete mode 100644 src/main/java/com/teaching/backend/controller/chapter/ChapterController.java
create mode 100644 src/main/java/com/teaching/backend/controller/records/LearningRecordsController.java
delete mode 100644 src/main/java/com/teaching/backend/mapper/ChapterMapper.java
rename src/main/java/com/teaching/{mapper => backend/mapper/know}/KnowMapper.java (64%)
create mode 100644 src/main/java/com/teaching/backend/mapper/records/LearningRecordsMapper.java
rename src/main/java/com/teaching/{model/entity => backend/model/entity/know}/Know.java (91%)
create mode 100644 src/main/java/com/teaching/backend/model/entity/records/LearningRecords.java
create mode 100644 src/main/java/com/teaching/backend/model/vo/records/LearningRecordsVo.java
delete mode 100644 src/main/java/com/teaching/backend/service/IChapterService.java
delete mode 100644 src/main/java/com/teaching/backend/service/impl/ChapterServiceImpl.java
create mode 100644 src/main/java/com/teaching/backend/service/impl/know/IknowServiceimpl.java
create mode 100644 src/main/java/com/teaching/backend/service/impl/records/LearningRecordsServiceImpl.java
rename src/main/java/com/teaching/{service => backend/service/know}/IknowService.java (51%)
create mode 100644 src/main/java/com/teaching/backend/service/records/LearningRecordsService.java
delete mode 100644 src/main/java/com/teaching/service/impl/IknowServiceimpl.java
diff --git a/pom.xml b/pom.xml
index 803f420..6e12190 100644
--- a/pom.xml
+++ b/pom.xml
@@ -97,6 +97,14 @@
hutool-all
5.8.11
+
+
+
+ com.github.pagehelper
+ pagehelper
+ 4.1.6
+
+
diff --git a/src/main/java/com/teaching/backend/controller/ChapterController.java b/src/main/java/com/teaching/backend/controller/ChapterController.java
deleted file mode 100644
index f10ad15..0000000
--- a/src/main/java/com/teaching/backend/controller/ChapterController.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package com.teaching.backend.controller;
-
-
-import org.springframework.web.bind.annotation.RequestMapping;
-
-import org.springframework.web.bind.annotation.RestController;
-
-/**
- *
- * 前端控制器
- *
- *
- * @author author
- * @since 2024-06-07
- */
-@RestController
-@RequestMapping("/chapter")
-public class ChapterController {
-
-}
diff --git a/src/main/java/com/teaching/backend/controller/chapter/ChapterController.java b/src/main/java/com/teaching/backend/controller/chapter/ChapterController.java
deleted file mode 100644
index 7fc04f0..0000000
--- a/src/main/java/com/teaching/backend/controller/chapter/ChapterController.java
+++ /dev/null
@@ -1,28 +0,0 @@
-package com.teaching.backend.controller.chapter;
-
-
-
-import com.teaching.backend.service.chapter.IChapterService;
-import io.swagger.annotations.Api;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
-
-import java.util.List;
-
-/**
- *
- * @author author
- * @since 2024-05-31
- */
-@Slf4j
-@Api(tags = "章节管理")
-@RestController
-@RequestMapping("/chapter")
-public class ChapterController {
- @Autowired
- private IChapterService chapterService;
-
-}
diff --git a/src/main/java/com/teaching/backend/controller/records/LearningRecordsController.java b/src/main/java/com/teaching/backend/controller/records/LearningRecordsController.java
new file mode 100644
index 0000000..a007aaa
--- /dev/null
+++ b/src/main/java/com/teaching/backend/controller/records/LearningRecordsController.java
@@ -0,0 +1,89 @@
+package com.teaching.backend.controller.records;
+
+
+import com.github.pagehelper.PageHelper;
+import com.github.pagehelper.PageInfo;
+import com.teaching.backend.common.BaseResponse;
+import com.teaching.backend.common.ResultUtils;
+
+import com.teaching.backend.model.entity.records.LearningRecords;
+import com.teaching.backend.model.vo.records.LearningRecordsVo;
+import com.teaching.backend.service.impl.records.LearningRecordsServiceImpl;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.ui.Model;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.ArrayList;
+import java.util.List;
+
+@RestController
+@RequestMapping("/learningrecords")
+public class LearningRecordsController {
+
+ @Autowired
+ private LearningRecordsServiceImpl learningRecordsService;
+
+
+ /**
+ * 获取当前登录用户的学习记录
+ * @param m
+ * @param pagenum
+ * @param pagesize
+ * @return
+ */
+ @GetMapping("/getall")
+ public BaseResponse getAll(Model m,
+ @RequestParam(value = "pagenum", defaultValue = "1") int pagenum,
+ @RequestParam(value = "pagesize", defaultValue = "15") int pagesize,
+ @RequestParam String userId){
+ PageHelper.startPage(pagenum,pagesize,"id desc");
+ List cs= learningRecordsService.getAll(userId);
+ List pageCs = new ArrayList<>();
+ //当前页面
+ for(int i = (pagenum - 1) * pagesize; i < cs.size() && i < (pagenum) * pagesize; i++){
+ pageCs.add(cs.get(i));
+ }
+ PageInfo pageInfo = new PageInfo<>(pageCs);
+ System.out.println("当前页面:"+pagenum);
+ System.out.println("当前页面大小:"+pagesize);
+ System.out.println("当前页面内容:"+pageCs);
+// PageInfo pageInfo = new PageInfo<>(cs);
+ pageInfo.setPageSize(pagesize);//设置当前页面大小
+ pageInfo.setPageNum(pagenum);//设置当前页码
+ pageInfo.setSize(pagesize);//不知道是啥,---------
+ pageInfo.setTotal(cs.size());//设置总条数
+ long total = pageInfo.getTotal(); // 总记录数
+ pageInfo.setPages((int)(Math.ceil((double) total / pagesize)));//设置总页数
+ return ResultUtils.success(pageInfo);
+ }
+
+ @GetMapping("/all")
+ public BaseResponse> All(){
+ System.out.println("学习记录:"+learningRecordsService.list());
+ return ResultUtils.success(learningRecordsService.list());
+ }
+
+ //资源类型: 1,课程学习记录,2,知识点学习记录,3课程资源学习记录
+ /**
+ * 添加课程记录
+ * @param learningRecords
+ * @return
+ */
+ @PostMapping("/saverecords")
+ public BaseResponse saveRecords(@RequestBody LearningRecords learningRecords){
+ System.out.println(learningRecords);
+ return ResultUtils.success(learningRecordsService.saveRecords(learningRecords));
+ }
+
+ /**
+ * 根据id删除
+ * @param ids
+ * @return
+ */
+ @DeleteMapping("/delete")
+ public BaseResponse deleteRecords(@RequestParam List ids){
+
+ return ResultUtils.success(learningRecordsService.delete(ids));
+ }
+
+}
diff --git a/src/main/java/com/teaching/backend/mapper/ChapterMapper.java b/src/main/java/com/teaching/backend/mapper/ChapterMapper.java
deleted file mode 100644
index 375a19c..0000000
--- a/src/main/java/com/teaching/backend/mapper/ChapterMapper.java
+++ /dev/null
@@ -1,16 +0,0 @@
-package com.teaching.backend.mapper;
-
-import com.teaching.backend.entity.Chapter;
-import com.baomidou.mybatisplus.core.mapper.BaseMapper;
-
-/**
- *
- * Mapper 接口
- *
- *
- * @author author
- * @since 2024-06-07
- */
-public interface ChapterMapper extends BaseMapper {
-
-}
diff --git a/src/main/java/com/teaching/mapper/KnowMapper.java b/src/main/java/com/teaching/backend/mapper/know/KnowMapper.java
similarity index 64%
rename from src/main/java/com/teaching/mapper/KnowMapper.java
rename to src/main/java/com/teaching/backend/mapper/know/KnowMapper.java
index 00e6cf3..d6c2237 100644
--- a/src/main/java/com/teaching/mapper/KnowMapper.java
+++ b/src/main/java/com/teaching/backend/mapper/know/KnowMapper.java
@@ -1,7 +1,7 @@
-package com.teaching.mapper;
+package com.teaching.backend.mapper.know;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
-import com.teaching.model.entity.Know;
+import com.teaching.backend.model.entity.know.Know;
import org.apache.ibatis.annotations.Mapper;
@Mapper
diff --git a/src/main/java/com/teaching/backend/mapper/records/LearningRecordsMapper.java b/src/main/java/com/teaching/backend/mapper/records/LearningRecordsMapper.java
new file mode 100644
index 0000000..55d587d
--- /dev/null
+++ b/src/main/java/com/teaching/backend/mapper/records/LearningRecordsMapper.java
@@ -0,0 +1,15 @@
+package com.teaching.backend.mapper.records;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+
+import com.teaching.backend.model.entity.records.LearningRecords;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+
+@Mapper
+public interface LearningRecordsMapper extends BaseMapper {
+ IPage selectPageList(Page page, @Param("model")LearningRecords model);
+
+}
diff --git a/src/main/java/com/teaching/backend/model/entity/chapter/Chapter.java b/src/main/java/com/teaching/backend/model/entity/chapter/Chapter.java
index 0a7cafb..8861632 100644
--- a/src/main/java/com/teaching/backend/model/entity/chapter/Chapter.java
+++ b/src/main/java/com/teaching/backend/model/entity/chapter/Chapter.java
@@ -25,7 +25,6 @@ import java.time.LocalDateTime;
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName("chapter")
-@ApiModel(value="Chapter对象", description="")
public class Chapter implements Serializable {
private static final long serialVersionUID = 1L;
diff --git a/src/main/java/com/teaching/model/entity/Know.java b/src/main/java/com/teaching/backend/model/entity/know/Know.java
similarity index 91%
rename from src/main/java/com/teaching/model/entity/Know.java
rename to src/main/java/com/teaching/backend/model/entity/know/Know.java
index 0a8724a..b2e580f 100644
--- a/src/main/java/com/teaching/model/entity/Know.java
+++ b/src/main/java/com/teaching/backend/model/entity/know/Know.java
@@ -1,4 +1,4 @@
-package com.teaching.model.entity;
+package com.teaching.backend.model.entity.know;
import io.swagger.annotations.Api;
import lombok.AllArgsConstructor;
@@ -6,7 +6,6 @@ import lombok.Data;
import lombok.NoArgsConstructor;
-import javax.persistence.Table;
import java.io.Serializable;
import java.time.LocalDateTime;
diff --git a/src/main/java/com/teaching/backend/model/entity/records/LearningRecords.java b/src/main/java/com/teaching/backend/model/entity/records/LearningRecords.java
new file mode 100644
index 0000000..be7d920
--- /dev/null
+++ b/src/main/java/com/teaching/backend/model/entity/records/LearningRecords.java
@@ -0,0 +1,96 @@
+package com.teaching.backend.model.entity.records;
+
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+
+import java.time.LocalDateTime;
+
+
+@Data
+@EqualsAndHashCode(callSuper = false)
+@Accessors(chain = true)
+@TableName("learning_records")
+public class LearningRecords {
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * 内部编号
+ */
+ @TableId(value = "id", type = IdType.ASSIGN_ID)
+ private String id;
+
+ /**
+ * 用户id
+ */
+ private String userId;
+
+ /**
+ * 课程id
+ */
+ private String coursesId;
+ /**
+ * 章节id
+ */
+ private String chapterId;
+ /**
+ * 知识点id
+ */
+ private String knowledgePointId;
+ /**
+ * 资源id
+ */
+ private String resourceId;
+ /**
+ * 访问时间
+ */
+ private LocalDateTime accessTime;
+
+ /**
+ * 学习方式:打开; 1,打开过,2未打开
+ */
+ private String learningMethod1;
+ /**
+ * 学习方式:下载; 1下载过, 2未下载
+ */
+ private String learningMethod2;
+ /**
+ *视频学习时长
+ */
+ private String videoDuration;
+
+ /**
+ *是否完成观看:1,已完成,0未完成
+ */
+ private String isCompleted;
+
+ /**
+ * 记录封面图片
+ */
+ private String content;
+ /**
+ * 资源地址
+ */
+ private String address;
+
+ /**
+ * 是否存在: 1存在;0不存在;
+ */
+ private String status;
+ /**
+ * 类型, 如:1,课程; 2,章节; 3,知识点; 4,学习资源
+ */
+ private String type;
+ /**
+ * 父节点
+ */
+ private String parentNode;
+
+
+
+
+}
diff --git a/src/main/java/com/teaching/backend/model/vo/records/LearningRecordsVo.java b/src/main/java/com/teaching/backend/model/vo/records/LearningRecordsVo.java
new file mode 100644
index 0000000..e9b3ab2
--- /dev/null
+++ b/src/main/java/com/teaching/backend/model/vo/records/LearningRecordsVo.java
@@ -0,0 +1,59 @@
+package com.teaching.backend.model.vo.records;
+
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+
+@Data
+@EqualsAndHashCode(callSuper = false)
+@Accessors(chain = true)
+public class LearningRecordsVo {
+// private static final long serialVersionUID = 1L;
+
+ /**
+ * 内部编号
+ */
+ private String id;
+
+ /**
+ * 课程名称
+ */
+ private String coursesName;
+
+// /**
+// * 资源类型
+// */
+// private String type;
+
+ /**
+ * 封面
+ */
+ private String content;
+
+ /**
+ * 资源观看人数
+ */
+ private Long number;
+
+
+ /**
+ * 上次观看时间
+ */
+ private String time;
+ /**
+ * 地址
+ */
+ private String address;
+// /**
+// * 创建日期
+// */
+// private LocalDateTime createTime;
+//
+// /**
+// * 更新日期
+// */
+// private LocalDateTime updateTime;
+
+
+
+}
diff --git a/src/main/java/com/teaching/backend/service/IChapterService.java b/src/main/java/com/teaching/backend/service/IChapterService.java
deleted file mode 100644
index 4d3ff34..0000000
--- a/src/main/java/com/teaching/backend/service/IChapterService.java
+++ /dev/null
@@ -1,16 +0,0 @@
-package com.teaching.backend.service;
-
-import com.teaching.backend.entity.Chapter;
-import com.baomidou.mybatisplus.extension.service.IService;
-
-/**
- *
- * 服务类
- *
- *
- * @author author
- * @since 2024-06-07
- */
-public interface IChapterService extends IService {
-
-}
diff --git a/src/main/java/com/teaching/backend/service/impl/ChapterServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/ChapterServiceImpl.java
deleted file mode 100644
index 7cfafc6..0000000
--- a/src/main/java/com/teaching/backend/service/impl/ChapterServiceImpl.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package com.teaching.backend.service.impl;
-
-import com.teaching.backend.entity.Chapter;
-import com.teaching.backend.mapper.ChapterMapper;
-import com.teaching.backend.service.IChapterService;
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import org.springframework.stereotype.Service;
-
-/**
- *
- * 服务实现类
- *
- *
- * @author author
- * @since 2024-06-07
- */
-@Service
-public class ChapterServiceImpl extends ServiceImpl implements IChapterService {
-
-}
diff --git a/src/main/java/com/teaching/backend/service/impl/know/IknowServiceimpl.java b/src/main/java/com/teaching/backend/service/impl/know/IknowServiceimpl.java
new file mode 100644
index 0000000..fb99ff7
--- /dev/null
+++ b/src/main/java/com/teaching/backend/service/impl/know/IknowServiceimpl.java
@@ -0,0 +1,12 @@
+package com.teaching.backend.service.impl.know;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.teaching.backend.mapper.know.KnowMapper;
+import com.teaching.backend.model.entity.know.Know;
+import com.teaching.backend.service.know.IknowService;
+import org.springframework.stereotype.Service;
+
+@Service
+public class IknowServiceimpl extends ServiceImpl implements IknowService {
+
+}
diff --git a/src/main/java/com/teaching/backend/service/impl/records/LearningRecordsServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/records/LearningRecordsServiceImpl.java
new file mode 100644
index 0000000..9bf49af
--- /dev/null
+++ b/src/main/java/com/teaching/backend/service/impl/records/LearningRecordsServiceImpl.java
@@ -0,0 +1,185 @@
+package com.teaching.backend.service.impl.records;
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+
+import com.teaching.backend.mapper.records.LearningRecordsMapper;
+
+import com.teaching.backend.model.entity.records.LearningRecords;
+import com.teaching.backend.model.vo.records.LearningRecordsVo;
+import com.teaching.backend.service.impl.chapter.ChapterServiceImpl;
+import com.teaching.backend.service.impl.courses.CoursesServiceImpl;
+import com.teaching.backend.service.impl.know.IknowServiceimpl;
+import com.teaching.backend.service.records.LearningRecordsService;
+import org.springframework.beans.BeanUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.text.SimpleDateFormat;
+import java.time.LocalDateTime;
+import java.time.ZoneId;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+@Service
+public class LearningRecordsServiceImpl extends ServiceImpl implements LearningRecordsService {
+
+ @Autowired
+ private CoursesServiceImpl coursesService;
+ @Autowired
+ private LearningRecordsMapper learningRecordsMapper;
+// @Autowired
+// private LearningResourceServiceImpl learningResourceService;
+ @Autowired
+ private IknowServiceimpl knowledgePointService;
+ @Autowired
+ private ChapterServiceImpl chapterService;
+
+ @Override
+ public IPage selectPageList(Page page, LearningRecords model) {
+ return learningRecordsMapper.selectPageList(page,model);
+ }
+
+ @Override
+ public String delete(List ids) {
+ LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>();
+ lambdaQueryWrapper.in(LearningRecords::getId, ids);
+ List list = this.list(lambdaQueryWrapper);
+ //把即将要删除的记录状态调成0
+ for (LearningRecords learningRecords : list) {
+ learningRecords.setStatus("0");
+ }
+ this.updateBatchById(list);
+// System.out.println(this.updateBatchById(list));
+// this.remove(lambdaQueryWrapper);
+ return "删除成功";
+ }
+
+ @Override
+ public List getAll(String userId){
+ //格式化时间
+ //格式化时间
+ String strDateFormat = "yyyy-MM-dd HH:mm:ss";
+ SimpleDateFormat sdf = new SimpleDateFormat(strDateFormat);
+
+ List list = new ArrayList<>();
+ //将学习记录实体转成学习记录Vo实体
+ LambdaQueryWrapper lambdaQueryWrapper1 = new LambdaQueryWrapper<>();
+ lambdaQueryWrapper1
+ .orderByDesc(LearningRecords::getAccessTime)
+ .eq(LearningRecords::getUserId, userId)
+ .eq(LearningRecords::getStatus, "1");
+ System.out.println(this.list(lambdaQueryWrapper1));
+ //如果为空-------------------?????
+ for (LearningRecords learningRecords : this.list(lambdaQueryWrapper1)) {
+ //查找该用户的学习记录
+// if (learningRecords.getUserId().equals(userId) && learningRecords.getStatus().equals("1")){
+ LearningRecordsVo learningRecordsVo = new LearningRecordsVo();//好像可以拿出去-----------??
+ BeanUtils.copyProperties(learningRecords,learningRecordsVo);//从多传到少(缺少人数,和资源名称,时间需要转格式)
+ //添加时间
+ //LocalDateTime转Date
+ Date date = Date.from(learningRecords.getAccessTime().atZone(ZoneId.systemDefault()).toInstant());
+ learningRecordsVo.setTime(sdf.format(date));
+ LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>();
+ lambdaQueryWrapper.eq(LearningRecords::getCoursesId, learningRecords.getCoursesId());
+// System.out.println(learningRecords.getResourceId());
+// System.out.println("1");
+
+ //添加课程名称
+ switch (learningRecords.getType()) {
+ case "4": //如果是资源学习
+ learningRecordsVo.setCoursesName("学习资源");//设置名称 --------------------------------------------待完善
+
+ break;
+ case "3": //如果是知识点学习记录
+ learningRecordsVo.setCoursesName(knowledgePointService.getById(learningRecords.getCoursesId()).getName());
+
+ break;
+ case "2": //如果是章节学习记录
+ learningRecordsVo.setCoursesName(chapterService.getById(learningRecords.getCoursesId()).getName());
+
+ break;
+ case "1": //如果是课程学习记录
+ learningRecordsVo.setCoursesName(coursesService.getById(learningRecords.getCoursesId()).getName());
+ break;
+ }
+ //添加观看人数
+ //统计记录表里有多少人查看过这门资源
+ long count = this.count(lambdaQueryWrapper);
+ System.out.println(count);
+ learningRecordsVo.setNumber(count);
+ //把整合后该用户的学习记录添加到List里
+ list.add(learningRecordsVo);
+// }
+ }
+ System.out.println(list);
+ return list;
+ }
+
+ /**
+ * 根据用户id和学习资源id来判断记录是否存在
+ * @param learningRecords
+ * @return
+ */
+ @Override
+ public String saveRecords(LearningRecords learningRecords) {
+ String userId = learningRecords.getUserId();
+ String coursesId = learningRecords.getCoursesId();
+ System.out.println("学习记录:"+learningRecords);
+ //查找该用户是否观看过该学习资源
+ LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>();
+ lambdaQueryWrapper
+ .eq(LearningRecords::getUserId, userId)
+ .eq(LearningRecords::getCoursesId, coursesId)
+ .eq(LearningRecords::getType, learningRecords.getType());
+ long count = this.count(lambdaQueryWrapper);
+ System.out.println("数据库:"+count);
+ learningRecords.setStatus("1");//将该记录的状态设置为1
+ //更新观看时间
+ learningRecords.setAccessTime(LocalDateTime.now());
+ //设置默认封面
+ if (learningRecords.getContent() == null || learningRecords.getContent().equals("")){
+ learningRecords.setContent("https://teaching-edu123.oss-cn-beijing.aliyuncs.com/Borovets_ZH-CN5914681811_UHD.jpg");
+ }
+// //添加记录封面
+// switch (learningRecords.getType()) {
+// case "4": //如果是资源学习
+// learningRecords.setContent(learningResourceService.getById(learningRecords.getCoursesId()).getContent());//设置封面
+// break;
+// case "3": //如果是知识点学习记录
+// learningRecords.setContent(knowledgePointService.getById(learningRecords.getCoursesId()).getContent());//设置封面
+//
+// break;
+// case "2": //如果是章节学习记录
+// learningRecords.setContent(chapterService.getById(learningRecords.getCoursesId()).getContent());//设置封面
+//
+// break;
+// case "1": //如果是课程学习记录
+// learningRecords.setContent(coursesService.getById(learningRecords.getCoursesId()).getImg());//设置封面
+// break;
+// }
+ if (count == 0){//如果没有就新增并记录学习方式是打开还是下载
+ //根据传上来的type设置
+// learningRecords.setType(learningRecords.getType());
+ this.save(learningRecords);
+ return "添加成功";
+ }else {//有就修改记录,更新学习方式
+ LearningRecords one = this.getOne(lambdaQueryWrapper);
+ System.out.println(one);
+ learningRecords.setId(one.getId());//找到该条记录的id并赋值给本次观看记录
+ if ( one.getLearningMethod1() != null && one.getLearningMethod1().equals("1")){
+ learningRecords.setLearningMethod1(one.getLearningMethod1());
+ }
+ if (one.getLearningMethod2() != null && one.getLearningMethod2().equals("1")){
+ learningRecords.setLearningMethod2(one.getLearningMethod2());
+ }
+ this.updateById(learningRecords);
+ return "修改成功";
+ }
+ }
+
+
+}
diff --git a/src/main/java/com/teaching/service/IknowService.java b/src/main/java/com/teaching/backend/service/know/IknowService.java
similarity index 51%
rename from src/main/java/com/teaching/service/IknowService.java
rename to src/main/java/com/teaching/backend/service/know/IknowService.java
index 29a4f1b..d49fed1 100644
--- a/src/main/java/com/teaching/service/IknowService.java
+++ b/src/main/java/com/teaching/backend/service/know/IknowService.java
@@ -1,8 +1,7 @@
-package com.teaching.service;
+package com.teaching.backend.service.know;
import com.baomidou.mybatisplus.extension.service.IService;
-import com.teaching.model.entity.Know;
-import org.springframework.stereotype.Service;
+import com.teaching.backend.model.entity.know.Know;
public interface IknowService extends IService {
diff --git a/src/main/java/com/teaching/backend/service/records/LearningRecordsService.java b/src/main/java/com/teaching/backend/service/records/LearningRecordsService.java
new file mode 100644
index 0000000..d2acb1b
--- /dev/null
+++ b/src/main/java/com/teaching/backend/service/records/LearningRecordsService.java
@@ -0,0 +1,19 @@
+package com.teaching.backend.service.records;
+
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.teaching.backend.model.entity.records.LearningRecords;
+import com.teaching.backend.model.vo.records.LearningRecordsVo;
+
+
+import java.util.List;
+
+public interface LearningRecordsService extends IService {
+ public List getAll(String username);
+ public String saveRecords(LearningRecords learningRecords);
+ IPage selectPageList(Page page, LearningRecords model);
+
+ public String delete(List ids);
+
+}
diff --git a/src/main/java/com/teaching/service/impl/IknowServiceimpl.java b/src/main/java/com/teaching/service/impl/IknowServiceimpl.java
deleted file mode 100644
index 556471e..0000000
--- a/src/main/java/com/teaching/service/impl/IknowServiceimpl.java
+++ /dev/null
@@ -1,13 +0,0 @@
-package com.teaching.service.impl;
-
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import com.teaching.mapper.KnowMapper;
-import com.teaching.model.entity.Know;
-import com.teaching.service.IknowService;
-import org.springframework.stereotype.Service;
-
-@Service
-public class IknowServiceimpl extends ServiceImpl implements IknowServic
- e {
-
-}