学习记录观看人数是否加1

master
wenyu441069198 4 months ago
parent 395f909cf2
commit a094f7c2ff
  1. 8
      src/main/java/com/teaching/backend/service/impl/courses/CoursesServiceImpl.java
  2. 13
      src/main/java/com/teaching/backend/service/impl/records/LearningRecordsServiceImpl.java

@ -263,11 +263,15 @@ public class CoursesServiceImpl extends ServiceImpl<CoursesMapper, Courses> impl
//删除课程的同时删除对应的记录
//先通过id查出对应的记录
System.out.println("删!");
LambdaQueryWrapper<LearningRecords> lambdaQueryWrapper = new LambdaQueryWrapper<>();
System.out.println("id:"+id);
lambdaQueryWrapper.eq(LearningRecords::getCoursesId, id).eq(LearningRecords::getType, 1);//课程的type为1
System.out.println("学习记录删除:"+learningRecordsMapper.selectList(lambdaQueryWrapper));
learningRecordsMapper.delete(lambdaQueryWrapper);
List<LearningRecords> list = learningRecordsMapper.selectList(lambdaQueryWrapper);
if (list.size() > 0){
learningRecordsMapper.deleteBatchIds(list);
}
System.out.println("无记录!");
}
@Override

@ -127,7 +127,7 @@ public class LearningRecordsServiceImpl extends ServiceImpl<LearningRecordsMappe
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
System.out.println("学习记录:"+learningRecords);
// System.out.println("学习记录:"+learningRecords);
//查找该用户是否观看过该学习资源
LambdaQueryWrapper<LearningRecords> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper
@ -144,15 +144,16 @@ public class LearningRecordsServiceImpl extends ServiceImpl<LearningRecordsMappe
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 one1 = query().eq("courses_id", coursesId).eq("type", learningRecords.getType()).eq("user_id", userId).one();
int number = list.size();
//该用户是否学习过
if (one1 != null){//学习过观看人数不加
learningRecords.setNumber(number);
list.forEach(learningRecords1 -> {
learningRecords1.setNumber(number);
});
} else {
number = 0;
} else {//否则观看人数加1
learningRecords.setNumber(number + 1);
}
updateBatchById(list);
if (count == 0){//如果没有就新增并记录学习方式是打开还是下载

Loading…
Cancel
Save