parent
6f6365c52b
commit
69344986ec
5 changed files with 312 additions and 311 deletions
@ -1,89 +1,89 @@ |
|||||||
package com.teaching.backend.controller.records; |
//package com.teaching.backend.controller.records;
|
||||||
|
//
|
||||||
|
//
|
||||||
import com.github.pagehelper.PageHelper; |
//import com.github.pagehelper.PageHelper;
|
||||||
import com.github.pagehelper.PageInfo; |
//import com.github.pagehelper.PageInfo;
|
||||||
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.model.entity.records.LearningRecords; |
//import com.teaching.backend.model.entity.records.LearningRecords;
|
||||||
import com.teaching.backend.model.vo.records.LearningRecordsVo; |
//import com.teaching.backend.model.vo.records.LearningRecordsVo;
|
||||||
import com.teaching.backend.service.impl.records.LearningRecordsServiceImpl; |
//import com.teaching.backend.service.impl.records.LearningRecordsServiceImpl;
|
||||||
import org.springframework.beans.factory.annotation.Autowired; |
//import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.ui.Model; |
//import org.springframework.ui.Model;
|
||||||
import org.springframework.web.bind.annotation.*; |
//import org.springframework.web.bind.annotation.*;
|
||||||
|
//
|
||||||
import java.util.ArrayList; |
//import java.util.ArrayList;
|
||||||
import java.util.List; |
//import java.util.List;
|
||||||
|
//
|
||||||
@RestController |
//@RestController
|
||||||
@RequestMapping("/learningrecords") |
//@RequestMapping("/learningrecords")
|
||||||
public class LearningRecordsController { |
//public class LearningRecordsController {
|
||||||
|
//
|
||||||
@Autowired |
// @Autowired
|
||||||
private LearningRecordsServiceImpl learningRecordsService; |
// private LearningRecordsServiceImpl learningRecordsService;
|
||||||
|
//
|
||||||
|
//
|
||||||
/** |
// /**
|
||||||
* 获取当前登录用户的学习记录 |
// * 获取当前登录用户的学习记录
|
||||||
* @param m |
// * @param m
|
||||||
* @param pagenum |
// * @param pagenum
|
||||||
* @param pagesize |
// * @param pagesize
|
||||||
* @return |
// * @return
|
||||||
*/ |
// */
|
||||||
@GetMapping("/getall") |
// @GetMapping("/getall")
|
||||||
public BaseResponse<PageInfo> getAll(Model m, |
// public BaseResponse<PageInfo> getAll(Model m,
|
||||||
@RequestParam(value = "pagenum", defaultValue = "1") int pagenum, |
// @RequestParam(value = "pagenum", defaultValue = "1") int pagenum,
|
||||||
@RequestParam(value = "pagesize", defaultValue = "15") int pagesize, |
// @RequestParam(value = "pagesize", defaultValue = "15") int pagesize,
|
||||||
@RequestParam String userId){ |
// @RequestParam String userId){
|
||||||
PageHelper.startPage(pagenum,pagesize,"id desc"); |
// PageHelper.startPage(pagenum,pagesize,"id desc");
|
||||||
List<LearningRecordsVo> cs= learningRecordsService.getAll(userId); |
// List<LearningRecordsVo> cs= learningRecordsService.getAll(userId);
|
||||||
List<LearningRecordsVo> pageCs = new ArrayList<>(); |
// List<LearningRecordsVo> pageCs = new ArrayList<>();
|
||||||
//当前页面
|
// //当前页面
|
||||||
for(int i = (pagenum - 1) * pagesize; i < cs.size() && i < (pagenum) * pagesize; i++){ |
// for(int i = (pagenum - 1) * pagesize; i < cs.size() && i < (pagenum) * pagesize; i++){
|
||||||
pageCs.add(cs.get(i)); |
// pageCs.add(cs.get(i));
|
||||||
} |
// }
|
||||||
PageInfo<LearningRecordsVo> pageInfo = new PageInfo<>(pageCs); |
// PageInfo<LearningRecordsVo> pageInfo = new PageInfo<>(pageCs);
|
||||||
System.out.println("当前页面:"+pagenum); |
// System.out.println("当前页面:"+pagenum);
|
||||||
System.out.println("当前页面大小:"+pagesize); |
// System.out.println("当前页面大小:"+pagesize);
|
||||||
System.out.println("当前页面内容:"+pageCs); |
// System.out.println("当前页面内容:"+pageCs);
|
||||||
// PageInfo<LearningRecordsVo> pageInfo = new PageInfo<>(cs);
|
//// PageInfo<LearningRecordsVo> pageInfo = new PageInfo<>(cs);
|
||||||
pageInfo.setPageSize(pagesize);//设置当前页面大小
|
// pageInfo.setPageSize(pagesize);//设置当前页面大小
|
||||||
pageInfo.setPageNum(pagenum);//设置当前页码
|
// pageInfo.setPageNum(pagenum);//设置当前页码
|
||||||
pageInfo.setSize(pagesize);//不知道是啥,---------
|
// pageInfo.setSize(pagesize);//不知道是啥,---------
|
||||||
pageInfo.setTotal(cs.size());//设置总条数
|
// pageInfo.setTotal(cs.size());//设置总条数
|
||||||
long total = pageInfo.getTotal(); // 总记录数
|
// long total = pageInfo.getTotal(); // 总记录数
|
||||||
pageInfo.setPages((int)(Math.ceil((double) total / pagesize)));//设置总页数
|
// pageInfo.setPages((int)(Math.ceil((double) total / pagesize)));//设置总页数
|
||||||
return ResultUtils.success(pageInfo); |
// return ResultUtils.success(pageInfo);
|
||||||
} |
// }
|
||||||
|
//
|
||||||
@GetMapping("/all") |
// @GetMapping("/all")
|
||||||
public BaseResponse<List<LearningRecords>> All(){ |
// public BaseResponse<List<LearningRecords>> All(){
|
||||||
System.out.println("学习记录:"+learningRecordsService.list()); |
// System.out.println("学习记录:"+learningRecordsService.list());
|
||||||
return ResultUtils.success(learningRecordsService.list()); |
// return ResultUtils.success(learningRecordsService.list());
|
||||||
} |
// }
|
||||||
|
//
|
||||||
//资源类型: 1,课程学习记录,2,知识点学习记录,3课程资源学习记录
|
// //资源类型: 1,课程学习记录,2,知识点学习记录,3课程资源学习记录
|
||||||
/** |
// /**
|
||||||
* 添加课程记录 |
// * 添加课程记录
|
||||||
* @param learningRecords |
// * @param learningRecords
|
||||||
* @return |
// * @return
|
||||||
*/ |
// */
|
||||||
@PostMapping("/saverecords") |
// @PostMapping("/saverecords")
|
||||||
public BaseResponse<String> saveRecords(@RequestBody LearningRecords learningRecords){ |
// public BaseResponse<String> saveRecords(@RequestBody LearningRecords learningRecords){
|
||||||
System.out.println(learningRecords); |
// System.out.println(learningRecords);
|
||||||
return ResultUtils.success(learningRecordsService.saveRecords(learningRecords)); |
// return ResultUtils.success(learningRecordsService.saveRecords(learningRecords));
|
||||||
} |
// }
|
||||||
|
//
|
||||||
/** |
// /**
|
||||||
* 根据id删除 |
// * 根据id删除
|
||||||
* @param ids |
// * @param ids
|
||||||
* @return |
// * @return
|
||||||
*/ |
// */
|
||||||
@DeleteMapping("/delete") |
// @DeleteMapping("/delete")
|
||||||
public BaseResponse<String> deleteRecords(@RequestParam List<Long> ids){ |
// public BaseResponse<String> deleteRecords(@RequestParam List<Long> ids){
|
||||||
|
//
|
||||||
return ResultUtils.success(learningRecordsService.delete(ids)); |
// return ResultUtils.success(learningRecordsService.delete(ids));
|
||||||
} |
// }
|
||||||
|
//
|
||||||
} |
//}
|
||||||
|
@ -1,15 +1,16 @@ |
|||||||
package com.teaching.backend.mapper.records; |
//package com.teaching.backend.mapper.records;
|
||||||
|
//
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
//import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage; |
//import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
//import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
//
|
||||||
import com.teaching.backend.model.entity.records.LearningRecords; |
//import com.teaching.backend.model.entity.records.LearningRecords;
|
||||||
import org.apache.ibatis.annotations.Mapper; |
//import org.apache.ibatis.annotations.Mapper;
|
||||||
import org.apache.ibatis.annotations.Param; |
//import org.apache.ibatis.annotations.Param;
|
||||||
|
//
|
||||||
@Mapper |
//@Mapper
|
||||||
public interface LearningRecordsMapper extends BaseMapper<LearningRecords> { |
//public interface LearningRecordsMapper extends BaseMapper<LearningRecords> {
|
||||||
IPage<LearningRecords> selectPageList(Page<LearningRecords> page, @Param("model")LearningRecords model); |
// IPage<LearningRecords> selectPageList(Page<LearningRecords> page, @Param("model")LearningRecords model);
|
||||||
|
//
|
||||||
} |
//}
|
||||||
|
////
|
||||||
|
@ -1,185 +1,185 @@ |
|||||||
package com.teaching.backend.service.impl.records; |
//package com.teaching.backend.service.impl.records;
|
||||||
|
//
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
//import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage; |
//import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
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.mapper.records.LearningRecordsMapper; |
//import com.teaching.backend.mapper.records.LearningRecordsMapper;
|
||||||
|
//
|
||||||
import com.teaching.backend.model.entity.records.LearningRecords; |
//import com.teaching.backend.model.entity.records.LearningRecords;
|
||||||
import com.teaching.backend.model.vo.records.LearningRecordsVo; |
//import com.teaching.backend.model.vo.records.LearningRecordsVo;
|
||||||
import com.teaching.backend.service.impl.chapter.ChapterServiceImpl; |
//import com.teaching.backend.service.impl.chapter.ChapterServiceImpl;
|
||||||
import com.teaching.backend.service.impl.courses.CoursesServiceImpl; |
//import com.teaching.backend.service.impl.courses.CoursesServiceImpl;
|
||||||
import com.teaching.backend.service.impl.know.IknowServiceimpl; |
//import com.teaching.backend.service.impl.know.IknowServiceimpl;
|
||||||
import com.teaching.backend.service.records.LearningRecordsService; |
//import com.teaching.backend.service.records.LearningRecordsService;
|
||||||
import org.springframework.beans.BeanUtils; |
//import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired; |
//import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service; |
//import org.springframework.stereotype.Service;
|
||||||
|
//
|
||||||
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;
|
||||||
|
//
|
||||||
@Service |
//@Service
|
||||||
public class LearningRecordsServiceImpl extends ServiceImpl<LearningRecordsMapper, LearningRecords> implements LearningRecordsService { |
//public class LearningRecordsServiceImpl extends ServiceImpl<LearningRecordsMapper, LearningRecords> implements LearningRecordsService {
|
||||||
|
//
|
||||||
@Autowired |
// @Autowired
|
||||||
private CoursesServiceImpl coursesService; |
// private CoursesServiceImpl coursesService;
|
||||||
@Autowired |
|
||||||
private LearningRecordsMapper learningRecordsMapper; |
|
||||||
// @Autowired
|
// @Autowired
|
||||||
// private LearningResourceServiceImpl learningResourceService;
|
// private LearningRecordsMapper learningRecordsMapper;
|
||||||
@Autowired |
//// @Autowired
|
||||||
private IknowServiceimpl knowledgePointService; |
//// private LearningResourceServiceImpl learningResourceService;
|
||||||
@Autowired |
// @Autowired
|
||||||
private ChapterServiceImpl chapterService; |
// private IknowServiceimpl knowledgePointService;
|
||||||
|
// @Autowired
|
||||||
@Override |
// private ChapterServiceImpl chapterService;
|
||||||
public IPage<LearningRecords> selectPageList(Page<LearningRecords> page, LearningRecords model) { |
//
|
||||||
return learningRecordsMapper.selectPageList(page,model); |
// @Override
|
||||||
} |
// public IPage<LearningRecords> selectPageList(Page<LearningRecords> page, LearningRecords model) {
|
||||||
|
// return learningRecordsMapper.selectPageList(page,model);
|
||||||
@Override |
|
||||||
public String delete(List<Long> ids) { |
|
||||||
LambdaQueryWrapper<LearningRecords> lambdaQueryWrapper = new LambdaQueryWrapper<>(); |
|
||||||
lambdaQueryWrapper.in(LearningRecords::getId, ids); |
|
||||||
List<LearningRecords> 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<LearningRecordsVo> getAll(String userId){ |
|
||||||
//格式化时间
|
|
||||||
//格式化时间
|
|
||||||
String strDateFormat = "yyyy-MM-dd HH:mm:ss"; |
|
||||||
SimpleDateFormat sdf = new SimpleDateFormat(strDateFormat); |
|
||||||
|
|
||||||
List<LearningRecordsVo> list = new ArrayList<>(); |
|
||||||
//将学习记录实体转成学习记录Vo实体
|
|
||||||
LambdaQueryWrapper<LearningRecords> 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<LearningRecords> 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); |
// @Override
|
||||||
return list; |
// public String delete(List<Long> ids) {
|
||||||
} |
// LambdaQueryWrapper<LearningRecords> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
// lambdaQueryWrapper.in(LearningRecords::getId, ids);
|
||||||
/** |
// List<LearningRecords> list = this.list(lambdaQueryWrapper);
|
||||||
* 根据用户id和学习资源id来判断记录是否存在 |
// //把即将要删除的记录状态调成0
|
||||||
* @param learningRecords |
// for (LearningRecords learningRecords : list) {
|
||||||
* @return |
// learningRecords.setStatus("0");
|
||||||
*/ |
// }
|
||||||
@Override |
// this.updateBatchById(list);
|
||||||
public String saveRecords(LearningRecords learningRecords) { |
//// System.out.println(this.updateBatchById(list));
|
||||||
String userId = learningRecords.getUserId(); |
//// this.remove(lambdaQueryWrapper);
|
||||||
String coursesId = learningRecords.getCoursesId(); |
// return "删除成功";
|
||||||
System.out.println("学习记录:"+learningRecords); |
// }
|
||||||
//查找该用户是否观看过该学习资源
|
//
|
||||||
LambdaQueryWrapper<LearningRecords> lambdaQueryWrapper = new LambdaQueryWrapper<>(); |
// @Override
|
||||||
lambdaQueryWrapper |
// public List<LearningRecordsVo> getAll(String userId){
|
||||||
.eq(LearningRecords::getUserId, userId) |
// //格式化时间
|
||||||
.eq(LearningRecords::getCoursesId, coursesId) |
// //格式化时间
|
||||||
.eq(LearningRecords::getType, learningRecords.getType()); |
// String strDateFormat = "yyyy-MM-dd HH:mm:ss";
|
||||||
long count = this.count(lambdaQueryWrapper); |
// SimpleDateFormat sdf = new SimpleDateFormat(strDateFormat);
|
||||||
System.out.println("数据库:"+count); |
//
|
||||||
learningRecords.setStatus("1");//将该记录的状态设置为1
|
// List<LearningRecordsVo> list = new ArrayList<>();
|
||||||
//更新观看时间
|
// //将学习记录实体转成学习记录Vo实体
|
||||||
learningRecords.setAccessTime(LocalDateTime.now()); |
// LambdaQueryWrapper<LearningRecords> lambdaQueryWrapper1 = new LambdaQueryWrapper<>();
|
||||||
//设置默认封面
|
// lambdaQueryWrapper1
|
||||||
if (learningRecords.getContent() == null || learningRecords.getContent().equals("")){ |
// .orderByDesc(LearningRecords::getAccessTime)
|
||||||
learningRecords.setContent("https://teaching-edu123.oss-cn-beijing.aliyuncs.com/Borovets_ZH-CN5914681811_UHD.jpg"); |
// .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<LearningRecords> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
// lambdaQueryWrapper.eq(LearningRecords::getCoursesId, learningRecords.getCoursesId());
|
||||||
|
//// System.out.println(learningRecords.getResourceId());
|
||||||
|
//// System.out.println("1");
|
||||||
|
//
|
||||||
|
// //添加课程名称
|
||||||
// switch (learningRecords.getType()) {
|
// switch (learningRecords.getType()) {
|
||||||
// case "4": //如果是资源学习
|
// case "4": //如果是资源学习
|
||||||
// learningRecords.setContent(learningResourceService.getById(learningRecords.getCoursesId()).getContent());//设置封面
|
// learningRecordsVo.setCoursesName("学习资源");//设置名称 --------------------------------------------待完善
|
||||||
|
//
|
||||||
// break;
|
// break;
|
||||||
// case "3": //如果是知识点学习记录
|
// case "3": //如果是知识点学习记录
|
||||||
// learningRecords.setContent(knowledgePointService.getById(learningRecords.getCoursesId()).getContent());//设置封面
|
// learningRecordsVo.setCoursesName(knowledgePointService.getById(learningRecords.getCoursesId()).getName());
|
||||||
//
|
//
|
||||||
// break;
|
// break;
|
||||||
// case "2": //如果是章节学习记录
|
// case "2": //如果是章节学习记录
|
||||||
// learningRecords.setContent(chapterService.getById(learningRecords.getCoursesId()).getContent());//设置封面
|
// learningRecordsVo.setCoursesName(chapterService.getById(learningRecords.getCoursesId()).getName());
|
||||||
//
|
//
|
||||||
// break;
|
// break;
|
||||||
// case "1": //如果是课程学习记录
|
// case "1": //如果是课程学习记录
|
||||||
// learningRecords.setContent(coursesService.getById(learningRecords.getCoursesId()).getImg());//设置封面
|
// learningRecordsVo.setCoursesName(coursesService.getById(learningRecords.getCoursesId()).getName());
|
||||||
// break;
|
// break;
|
||||||
// }
|
// }
|
||||||
if (count == 0){//如果没有就新增并记录学习方式是打开还是下载
|
// //添加观看人数
|
||||||
//根据传上来的type设置
|
// //统计记录表里有多少人查看过这门资源
|
||||||
// learningRecords.setType(learningRecords.getType());
|
// long count = this.count(lambdaQueryWrapper);
|
||||||
this.save(learningRecords); |
// System.out.println(count);
|
||||||
return "添加成功"; |
// learningRecordsVo.setNumber(count);
|
||||||
}else {//有就修改记录,更新学习方式
|
// //把整合后该用户的学习记录添加到List里
|
||||||
LearningRecords one = this.getOne(lambdaQueryWrapper); |
// list.add(learningRecordsVo);
|
||||||
System.out.println(one); |
//// }
|
||||||
learningRecords.setId(one.getId());//找到该条记录的id并赋值给本次观看记录
|
// }
|
||||||
if ( one.getLearningMethod1() != null && one.getLearningMethod1().equals("1")){ |
// System.out.println(list);
|
||||||
learningRecords.setLearningMethod1(one.getLearningMethod1()); |
// return list;
|
||||||
} |
// }
|
||||||
if (one.getLearningMethod2() != null && one.getLearningMethod2().equals("1")){ |
//
|
||||||
learningRecords.setLearningMethod2(one.getLearningMethod2()); |
// /**
|
||||||
} |
// * 根据用户id和学习资源id来判断记录是否存在
|
||||||
this.updateById(learningRecords); |
// * @param learningRecords
|
||||||
return "修改成功"; |
// * @return
|
||||||
} |
// */
|
||||||
} |
// @Override
|
||||||
|
// public String saveRecords(LearningRecords learningRecords) {
|
||||||
|
// String userId = learningRecords.getUserId();
|
||||||
} |
// String coursesId = learningRecords.getCoursesId();
|
||||||
|
// System.out.println("学习记录:"+learningRecords);
|
||||||
|
// //查找该用户是否观看过该学习资源
|
||||||
|
// LambdaQueryWrapper<LearningRecords> 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 "修改成功";
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//}
|
||||||
|
@ -1,19 +1,19 @@ |
|||||||
package com.teaching.backend.service.records; |
//package com.teaching.backend.service.records;
|
||||||
|
//
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage; |
//import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
//import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.baomidou.mybatisplus.extension.service.IService; |
//import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
import com.teaching.backend.model.entity.records.LearningRecords; |
//import com.teaching.backend.model.entity.records.LearningRecords;
|
||||||
import com.teaching.backend.model.vo.records.LearningRecordsVo; |
//import com.teaching.backend.model.vo.records.LearningRecordsVo;
|
||||||
|
//
|
||||||
|
//
|
||||||
import java.util.List; |
//import java.util.List;
|
||||||
|
//
|
||||||
public interface LearningRecordsService extends IService<LearningRecords> { |
//public interface LearningRecordsService extends IService<LearningRecords> {
|
||||||
public List<LearningRecordsVo> getAll(String username); |
// public List<LearningRecordsVo> getAll(String username);
|
||||||
public String saveRecords(LearningRecords learningRecords); |
// public String saveRecords(LearningRecords learningRecords);
|
||||||
IPage<LearningRecords> selectPageList(Page<LearningRecords> page, LearningRecords model); |
// IPage<LearningRecords> selectPageList(Page<LearningRecords> page, LearningRecords model);
|
||||||
|
//
|
||||||
public String delete(List<Long> ids); |
// public String delete(List<Long> ids);
|
||||||
|
//
|
||||||
} |
//}
|
||||||
|
Loading…
Reference in new issue