diff --git a/src/main/java/com/teaching/backend/service/impl/courses/CoursesServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/courses/CoursesServiceImpl.java index 48b2dac..34c62e3 100644 --- a/src/main/java/com/teaching/backend/service/impl/courses/CoursesServiceImpl.java +++ b/src/main/java/com/teaching/backend/service/impl/courses/CoursesServiceImpl.java @@ -263,11 +263,15 @@ public class CoursesServiceImpl extends ServiceImpl impl //删除课程的同时删除对应的记录 //先通过id查出对应的记录 + System.out.println("删!"); LambdaQueryWrapper 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 list = learningRecordsMapper.selectList(lambdaQueryWrapper); + if (list.size() > 0){ + learningRecordsMapper.deleteBatchIds(list); + } + System.out.println("无记录!"); } @Override 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 index 5fb69a9..acb8a15 100644 --- a/src/main/java/com/teaching/backend/service/impl/records/LearningRecordsServiceImpl.java +++ b/src/main/java/com/teaching/backend/service/impl/records/LearningRecordsServiceImpl.java @@ -127,7 +127,7 @@ public class LearningRecordsServiceImpl extends ServiceImpl lambdaQueryWrapper = new LambdaQueryWrapper<>(); lambdaQueryWrapper @@ -144,15 +144,16 @@ public class LearningRecordsServiceImpl extends ServiceImpl 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){//如果没有就新增并记录学习方式是打开还是下载