|
|
@ -12,7 +12,6 @@ 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.CourseResourcesServiceImpl; |
|
|
|
import com.teaching.backend.service.impl.CourseResourcesServiceImpl; |
|
|
|
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.records.LearningRecordsService; |
|
|
|
import com.teaching.backend.service.records.LearningRecordsService; |
|
|
|
import org.springframework.beans.BeanUtils; |
|
|
|
import org.springframework.beans.BeanUtils; |
|
|
@ -36,8 +35,8 @@ public class LearningRecordsServiceImpl extends ServiceImpl<LearningRecordsMappe |
|
|
|
private LearningRecordsMapper learningRecordsMapper; |
|
|
|
private LearningRecordsMapper learningRecordsMapper; |
|
|
|
@Autowired |
|
|
|
@Autowired |
|
|
|
private CourseResourcesServiceImpl courseResourcesService; |
|
|
|
private CourseResourcesServiceImpl courseResourcesService; |
|
|
|
@Autowired |
|
|
|
// @Autowired
|
|
|
|
private ChapterServiceImpl chapterService; |
|
|
|
// private ChapterServiceImpl chapterService;
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public IPage<LearningRecords> selectPageList(Page<LearningRecords> page, LearningRecords model) { |
|
|
|
public IPage<LearningRecords> selectPageList(Page<LearningRecords> page, LearningRecords model) { |
|
|
@ -53,76 +52,64 @@ public class LearningRecordsServiceImpl extends ServiceImpl<LearningRecordsMappe |
|
|
|
for (LearningRecords learningRecords : list) { |
|
|
|
for (LearningRecords learningRecords : list) { |
|
|
|
learningRecords.setStatus("0"); |
|
|
|
learningRecords.setStatus("0"); |
|
|
|
} |
|
|
|
} |
|
|
|
this.updateBatchById(list); |
|
|
|
updateBatchById(list); |
|
|
|
// System.out.println(this.updateBatchById(list));
|
|
|
|
// System.out.println(this.updateBatchById(list));
|
|
|
|
// this.remove(lambdaQueryWrapper);
|
|
|
|
// this.remove(lambdaQueryWrapper);
|
|
|
|
return "删除成功"; |
|
|
|
return "删除成功"; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public List<LearningRecordsVo> getAll(String userId){ |
|
|
|
public List<LearningRecordsVo> getAll(List<LearningRecords> list){ |
|
|
|
//格式化时间
|
|
|
|
List<LearningRecordsVo> records = new ArrayList<>(); |
|
|
|
//格式化时间
|
|
|
|
//格式化时间
|
|
|
|
String strDateFormat = "yyyy-MM-dd HH:mm:ss"; |
|
|
|
String strDateFormat = "yyyy-MM-dd HH:mm:ss"; |
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat(strDateFormat); |
|
|
|
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)) { |
|
|
|
list.forEach(learningRecords -> { |
|
|
|
//查找该用户的学习记录
|
|
|
|
LearningRecordsVo learningRecordsVo = new LearningRecordsVo();//好像可以拿出去-----------??
|
|
|
|
// if (learningRecords.getUserId().equals(userId) && learningRecords.getStatus().equals("1")){
|
|
|
|
BeanUtils.copyProperties(learningRecords,learningRecordsVo);//从多传到少(时间需要转格式)
|
|
|
|
LearningRecordsVo learningRecordsVo = new LearningRecordsVo();//好像可以拿出去-----------??
|
|
|
|
Date date = Date.from(learningRecords.getTime().atZone(ZoneId.systemDefault()).toInstant()); |
|
|
|
BeanUtils.copyProperties(learningRecords,learningRecordsVo);//从多传到少(缺少人数,和资源名称,时间需要转格式)
|
|
|
|
learningRecordsVo.setTime(sdf.format(date)); |
|
|
|
//添加时间
|
|
|
|
// //统计记录表里有多少人查看过这门资源
|
|
|
|
//LocalDateTime转Date
|
|
|
|
// LambdaQueryWrapper<LearningRecords> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
|
Date date = Date.from(learningRecords.getAccessTime().atZone(ZoneId.systemDefault()).toInstant()); |
|
|
|
// lambdaQueryWrapper.eq(LearningRecords::getCoursesId, learningRecords.getCoursesId());
|
|
|
|
learningRecordsVo.setTime(sdf.format(date)); |
|
|
|
// long count = this.count(lambdaQueryWrapper);
|
|
|
|
LambdaQueryWrapper<LearningRecords> lambdaQueryWrapper = new LambdaQueryWrapper<>(); |
|
|
|
learningRecordsVo.setNumber(learningRecords.getNumber()); |
|
|
|
lambdaQueryWrapper.eq(LearningRecords::getCoursesId, learningRecords.getCoursesId()); |
|
|
|
//把整合后该用户的学习记录添加到List里
|
|
|
|
// System.out.println(learningRecords.getResourceId());
|
|
|
|
records.add(learningRecordsVo); |
|
|
|
// System.out.println("1");
|
|
|
|
}); |
|
|
|
|
|
|
|
// for (LearningRecords learningRecords : list) {
|
|
|
|
String name; |
|
|
|
// //查找该用户的学习记录
|
|
|
|
//添加课程名称
|
|
|
|
// LearningRecordsVo learningRecordsVo = new LearningRecordsVo();//好像可以拿出去-----------??
|
|
|
|
switch (learningRecords.getType()) { |
|
|
|
// BeanUtils.copyProperties(learningRecords,learningRecordsVo);//从多传到少(缺少人数,和资源名称,时间需要转格式)
|
|
|
|
case "4": //如果是资源学习
|
|
|
|
// //添加时间
|
|
|
|
learningRecordsVo.setCoursesName(courseResourcesService.getById(learningRecords.getCoursesId()).getName());//设置名称 --------------------------------------------待完善
|
|
|
|
// //LocalDateTime转Date
|
|
|
|
break; |
|
|
|
// Date date = Date.from(learningRecords.getTime().atZone(ZoneId.systemDefault()).toInstant());
|
|
|
|
case "3": //如果是知识点学习记录
|
|
|
|
// learningRecordsVo.setTime(sdf.format(date));
|
|
|
|
// learningRecordsVo.setCoursesName(knowledgePointService.getById(learningRecords.getCoursesId()).get());
|
|
|
|
// LambdaQueryWrapper<LearningRecords> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
|
// if (knowledgePointService.getById(learningRecords.getCoursesId()) != null){
|
|
|
|
// lambdaQueryWrapper.eq(LearningRecords::getCoursesId, learningRecords.getCoursesId());
|
|
|
|
// name=knowledgePointService.getById(learningRecords.getCoursesId()).getName();
|
|
|
|
// String name;
|
|
|
|
// }else {
|
|
|
|
// //添加课程名称
|
|
|
|
// name = "查无次记录";
|
|
|
|
// switch (learningRecords.getType()) {
|
|
|
|
|
|
|
|
// case "4": //如果是资源学习
|
|
|
|
|
|
|
|
// if (courseResourcesService.getById(learningRecords.getCoursesId()) != null){
|
|
|
|
|
|
|
|
// learningRecordsVo.setCoursesName(courseResourcesService.getById(learningRecords.getCoursesId()).getName());
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// learningRecordsVo.setCoursesName(knowledgePointService.getById(learningRecords.getCoursesId()).getName());
|
|
|
|
// break;
|
|
|
|
//如果对应的资源不存在
|
|
|
|
// case "1": //如果是课程学习记录
|
|
|
|
break; |
|
|
|
// if (coursesService.getById(learningRecords.getCoursesId()) != null){
|
|
|
|
case "2": //如果是章节学习记录
|
|
|
|
// learningRecordsVo.setCoursesName(coursesService.getById(learningRecords.getCoursesId()).getName());
|
|
|
|
learningRecordsVo.setCoursesName(chapterService.getById(learningRecords.getCoursesId()).getName()); |
|
|
|
// }
|
|
|
|
//如果对应的资源不存在
|
|
|
|
// break;
|
|
|
|
break; |
|
|
|
|
|
|
|
case "1": //如果是课程学习记录
|
|
|
|
|
|
|
|
learningRecordsVo.setCoursesName(coursesService.getById(learningRecords.getCoursesId()).getName()); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
//添加观看人数
|
|
|
|
|
|
|
|
//统计记录表里有多少人查看过这门资源
|
|
|
|
|
|
|
|
long count = this.count(lambdaQueryWrapper); |
|
|
|
|
|
|
|
learningRecordsVo.setNumber(count); |
|
|
|
|
|
|
|
//把整合后该用户的学习记录添加到List里
|
|
|
|
|
|
|
|
list.add(learningRecordsVo); |
|
|
|
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
} |
|
|
|
// //添加观看人数
|
|
|
|
// System.out.println("查询后结果:"+list);
|
|
|
|
// //统计记录表里有多少人查看过这门资源
|
|
|
|
return list; |
|
|
|
// long count = this.count(lambdaQueryWrapper);
|
|
|
|
|
|
|
|
// learningRecordsVo.setNumber(count);
|
|
|
|
|
|
|
|
// //把整合后该用户的学习记录添加到List里
|
|
|
|
|
|
|
|
// records.add(learningRecordsVo);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
return records; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -148,14 +135,26 @@ public class LearningRecordsServiceImpl extends ServiceImpl<LearningRecordsMappe |
|
|
|
.eq(LearningRecords::getCoursesId, coursesId) |
|
|
|
.eq(LearningRecords::getCoursesId, coursesId) |
|
|
|
.eq(LearningRecords::getType, learningRecords.getType()); |
|
|
|
.eq(LearningRecords::getType, learningRecords.getType()); |
|
|
|
long count = this.count(lambdaQueryWrapper); |
|
|
|
long count = this.count(lambdaQueryWrapper); |
|
|
|
System.out.println("数据库:"+count); |
|
|
|
//System.out.println("数据库:"+count);
|
|
|
|
learningRecords.setStatus("1");//将该记录的状态设置为1
|
|
|
|
learningRecords.setStatus("1");//将该记录的状态设置为1
|
|
|
|
//更新观看时间
|
|
|
|
//更新观看时间
|
|
|
|
learningRecords.setAccessTime(LocalDateTime.now()); |
|
|
|
learningRecords.setTime(LocalDateTime.now()); |
|
|
|
//设置默认封面
|
|
|
|
//设置默认封面
|
|
|
|
if (learningRecords.getContent() == null || learningRecords.getContent().equals("")){ |
|
|
|
if (learningRecords.getContent() == null || learningRecords.getContent().equals("")){ |
|
|
|
learningRecords.setContent("img/v2-c57eb7863ec4233f503176ca3f90f8d5_1440w.png"); |
|
|
|
learningRecords.setContent("img/v2-c57eb7863ec4233f503176ca3f90f8d5_1440w.png"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
List<LearningRecords> list = query().eq("courses_id", coursesId).eq("type", learningRecords.getType()).list(); |
|
|
|
|
|
|
|
int number; |
|
|
|
|
|
|
|
if (list != null){ |
|
|
|
|
|
|
|
number = list.get(0).getNumber() + 1; |
|
|
|
|
|
|
|
learningRecords.setNumber(number); |
|
|
|
|
|
|
|
list.forEach(learningRecords1 -> { |
|
|
|
|
|
|
|
learningRecords1.setNumber(number); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
number = 0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
updateBatchById(list); |
|
|
|
if (count == 0){//如果没有就新增并记录学习方式是打开还是下载
|
|
|
|
if (count == 0){//如果没有就新增并记录学习方式是打开还是下载
|
|
|
|
//根据传上来的type设置
|
|
|
|
//根据传上来的type设置
|
|
|
|
// learningRecords.setType(learningRecords.getType());
|
|
|
|
// learningRecords.setType(learningRecords.getType());
|
|
|
|