From 4bc47fc4ffd860d12b65863cc53083b0c391a286 Mon Sep 17 00:00:00 2001 From: wuchunlei Date: Tue, 25 Feb 2025 16:10:45 +0800 Subject: [PATCH] =?UTF-8?q?=E6=88=91=E7=9A=84=E8=AF=BE=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/PsycheCourseController.java | 47 ++----------------- 1 file changed, 5 insertions(+), 42 deletions(-) diff --git a/src/main/java/com/peanut/modules/psyche/controller/PsycheCourseController.java b/src/main/java/com/peanut/modules/psyche/controller/PsycheCourseController.java index 9a88e6c2..41c5aec6 100644 --- a/src/main/java/com/peanut/modules/psyche/controller/PsycheCourseController.java +++ b/src/main/java/com/peanut/modules/psyche/controller/PsycheCourseController.java @@ -27,10 +27,6 @@ public class PsycheCourseController { @Autowired private UserVipService userVipService; @Autowired - private CourseCatalogueService coursecatalogueService; - @Autowired - private UserCourseBuyService userCoursebuyService; - @Autowired private UserCourseStudyingService userCourseStudyingService; @@ -38,23 +34,20 @@ public class PsycheCourseController { @RequestMapping("/getUserCourseBuy") public R getUserCourseBuy(){ MPJLambdaWrapper wrapper = new MPJLambdaWrapper<>(); - wrapper.leftJoin(CourseCatalogueEntity.class,CourseCatalogueEntity::getCourseId,CourseEntity::getId); + wrapper.distinct(); wrapper.rightJoin(CourseToPsyche.class,CourseToPsyche::getCourseId,CourseEntity::getId); if (!userVipService.isPsycheVip()){ wrapper.leftJoin(UserCourseBuyEntity.class,UserCourseBuyEntity::getCourseId,CourseEntity::getId); } wrapper.eq(UserCourseBuyEntity::getUserId,ShiroUtils.getUId()); wrapper.selectAll(CourseEntity.class); - wrapper.selectAs(CourseCatalogueEntity::getId,"catalogueId"); - wrapper.selectAs(CourseCatalogueEntity::getTitle,"catalogueTitle"); wrapper.orderByAsc(CourseEntity::getSort); - wrapper.orderByAsc(CourseCatalogueEntity::getSort); - List> courseList = courseService.listMaps(wrapper); - for (Map map:courseList){ + List courseList = courseService.list(wrapper); + for (CourseEntity c:courseList){ int i = userCourseStudyingService.count(new LambdaQueryWrapper() - .eq(UserCourseStudying::getCourseId,map.get("id")) + .eq(UserCourseStudying::getCourseId,c.getId()) .eq(UserCourseStudying::getUserId,ShiroUtils.getUId())); - map.put("isStudying",i>0?1:0); + c.setIsStudying(i>0?1:0); } return R.ok().put("courseList",courseList); } @@ -96,36 +89,6 @@ public class PsycheCourseController { wrapper.selectAll(CourseEntity.class); wrapper.orderByAsc(CourseEntity::getSort); List courseEntities = courseService.list(wrapper); - if(courseEntities!=null&&courseEntities.size()>0){ - for (CourseEntity co:courseEntities){ - List courseCatalogueEntities = coursecatalogueService.list(new MPJLambdaWrapper() - .eq(CourseCatalogueEntity::getCourseId, co.getId()).orderByAsc(CourseCatalogueEntity::getSort)); - if (courseCatalogueEntities.size() > 0) { - //查询目录添加,购买的课程目录详细信息 - for (CourseCatalogueEntity courseCatalogueEntity : courseCatalogueEntities) { - List userCourseBuyList = userCoursebuyService.list(new LambdaQueryWrapper() - .eq(UserCourseBuyEntity::getUserId, ShiroUtils.getUId()).eq(UserCourseBuyEntity::getCatalogueId, courseCatalogueEntity.getId())); - //是否购买,生效时间 - UserVip userVip = userVipService.ownCourseCatalogueByVip(courseCatalogueEntity.getCourseId()); - if (userVip!=null){ - courseCatalogueEntity.setStartTime(userVip.getStartTime()); - courseCatalogueEntity.setEndTime(userVip.getEndTime()); - courseCatalogueEntity.setIsBuy(1); - }else{ - //普通用户 - if (userCourseBuyList.size() > 0) { - courseCatalogueEntity.setIsBuy(1); - courseCatalogueEntity.setStartTime(userCourseBuyList.get(0).getStartTime()); - courseCatalogueEntity.setEndTime(userCourseBuyList.get(0).getEndTime()); - }else { - courseCatalogueEntity.setIsBuy(0); - } - } - } - } - co.setCourseCatalogueEntityList(courseCatalogueEntities); - } - } return R.ok().put("courseList",courseEntities); }