From a094f7c2ffcdb4e23db8bab3ea4c4218a0bcfbb8 Mon Sep 17 00:00:00 2001 From: wenyu441069198 <14186472+wenyu441069198@user.noreply.gitee.com> Date: Thu, 25 Jul 2024 12:33:51 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AD=A6=E4=B9=A0=E8=AE=B0=E5=BD=95=E8=A7=82?= =?UTF-8?q?=E7=9C=8B=E4=BA=BA=E6=95=B0=E6=98=AF=E5=90=A6=E5=8A=A01?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/courses/CoursesServiceImpl.java | 8 ++++++-- .../impl/records/LearningRecordsServiceImpl.java | 13 +++++++------ 2 files changed, 13 insertions(+), 8 deletions(-) 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){//如果没有就新增并记录学习方式是打开还是下载