From 0e8b4d2e0e8b9c65f7eed1bc345a09c801bd6c4b Mon Sep 17 00:00:00 2001 From: wuchunlei Date: Tue, 11 Feb 2025 09:48:04 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BF=83=E7=81=B5=E7=A9=BA=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/UserCourseStudyingService.java | 7 + .../impl/UserCourseStudyingServiceImpl.java | 13 ++ .../controller/PsycheCourseController.java | 153 ++++++++++++++++++ .../controller/PsycheHomeController.java | 55 ++++++- .../sys/controller/VisitorController.java | 40 +++++ 5 files changed, 265 insertions(+), 3 deletions(-) create mode 100644 src/main/java/com/peanut/modules/common/service/UserCourseStudyingService.java create mode 100644 src/main/java/com/peanut/modules/common/service/impl/UserCourseStudyingServiceImpl.java create mode 100644 src/main/java/com/peanut/modules/psyche/controller/PsycheCourseController.java diff --git a/src/main/java/com/peanut/modules/common/service/UserCourseStudyingService.java b/src/main/java/com/peanut/modules/common/service/UserCourseStudyingService.java new file mode 100644 index 00000000..63dc4022 --- /dev/null +++ b/src/main/java/com/peanut/modules/common/service/UserCourseStudyingService.java @@ -0,0 +1,7 @@ +package com.peanut.modules.common.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.peanut.modules.common.entity.UserCourseStudying; + +public interface UserCourseStudyingService extends IService { +} diff --git a/src/main/java/com/peanut/modules/common/service/impl/UserCourseStudyingServiceImpl.java b/src/main/java/com/peanut/modules/common/service/impl/UserCourseStudyingServiceImpl.java new file mode 100644 index 00000000..cdf20846 --- /dev/null +++ b/src/main/java/com/peanut/modules/common/service/impl/UserCourseStudyingServiceImpl.java @@ -0,0 +1,13 @@ +package com.peanut.modules.common.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.peanut.modules.common.dao.UserCourseStudyingDao; +import com.peanut.modules.common.entity.UserCourseStudying; +import com.peanut.modules.common.service.UserCourseStudyingService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +@Slf4j +@Service("commonUserCourseStudyingService") +public class UserCourseStudyingServiceImpl extends ServiceImpl implements UserCourseStudyingService { +} diff --git a/src/main/java/com/peanut/modules/psyche/controller/PsycheCourseController.java b/src/main/java/com/peanut/modules/psyche/controller/PsycheCourseController.java new file mode 100644 index 00000000..c3b77089 --- /dev/null +++ b/src/main/java/com/peanut/modules/psyche/controller/PsycheCourseController.java @@ -0,0 +1,153 @@ +package com.peanut.modules.psyche.controller; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.github.yulichang.wrapper.MPJLambdaWrapper; +import com.peanut.common.utils.R; +import com.peanut.common.utils.ShiroUtils; +import com.peanut.modules.common.entity.*; +import com.peanut.modules.common.service.UserCourseStudyingService; +import com.peanut.modules.common.service.UserVipService; +import com.peanut.modules.master.service.CourseCatalogueService; +import com.peanut.modules.master.service.CourseService; +import com.peanut.modules.master.service.UserCourseBuyService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@Slf4j +@RestController("psycheCourse") +@RequestMapping("psyche/course") +public class PsycheCourseController { + @Autowired + private CourseService courseService; + @Autowired + private CourseCatalogueService coursecatalogueService; + @Autowired + private UserVipService userVipService; + @Autowired + private UserCourseBuyService userCoursebuyService; + @Autowired + private UserCourseStudyingService userCourseStudyingService; + + + //我的课程-全部 + @RequestMapping("/getUserCourseBuy") + public R getUserCourseBuy(){ + MPJLambdaWrapper wrapper = new MPJLambdaWrapper<>(); + wrapper.leftJoin(CourseCatalogueEntity.class,CourseCatalogueEntity::getCourseId,CourseEntity::getId); + wrapper.leftJoin(CourseToPsyche.class,CourseToPsyche::getCourseId,CourseEntity::getId); + 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); + return R.ok().put("courseList",courseList); + } + + //我的课程-过期课程 + @RequestMapping("/getCourseExpire") + public R getCourseExpire(@RequestBody Map param){ + String vip = ShiroUtils.getUser().getVip(); + List courseEntities = null; + if (!"1".equals(vip)){ + MPJLambdaWrapper wrapper = new MPJLambdaWrapper<>(); + wrapper.distinct(); + wrapper.leftJoin(CourseCatalogueEntity.class,CourseCatalogueEntity::getCourseId,CourseEntity::getId); + //关掉本次查询del_flg = 0的条件,查询过期课程 + wrapper.disableSubLogicDel().rightJoin(UserCourseBuyEntity.class,UserCourseBuyEntity::getCatalogueId,CourseCatalogueEntity::getId); + wrapper.rightJoin(CourseToPsyche.class,CourseToPsyche::getCourseId,CourseEntity::getId); + wrapper.eq(UserCourseBuyEntity::getUserId,ShiroUtils.getUId()); + wrapper.eq(UserCourseBuyEntity::getDelFlag,-1); + wrapper.selectAll(CourseEntity.class); + wrapper.selectAs(CourseCatalogueEntity::getId,"catalogueId"); + wrapper.selectAs(CourseCatalogueEntity::getTitle,"catalogueTitle"); + wrapper.orderByAsc(CourseEntity::getSort); + wrapper.orderByAsc(CourseCatalogueEntity::getSort); + courseEntities = courseService.listMaps(wrapper); + } + return R.ok().put("courseList",courseEntities); + } + + //我的课程-正在学习(收藏) + @RequestMapping("/getUserCourseStudying") + public R getUserCourseStudying(){ + MyUserEntity user = ShiroUtils.getUser(); + MPJLambdaWrapper wrapper = new MPJLambdaWrapper<>(); + wrapper.leftJoin(CourseToPsyche.class,CourseToPsyche::getCourseId,CourseEntity::getId); + wrapper.leftJoin(UserCourseStudying.class,UserCourseStudying::getCourseId,CourseEntity::getId); + wrapper.eq(UserCourseStudying::getUserId,ShiroUtils.getUId()); + 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 userVipList = userVipService.list(new LambdaQueryWrapper() + .eq(UserVip::getUserId, user.getId())); + List userCourseBuyList = userCoursebuyService.list(new LambdaQueryWrapper() + .eq(UserCourseBuyEntity::getUserId, ShiroUtils.getUId()).eq(UserCourseBuyEntity::getCatalogueId, courseCatalogueEntity.getId())); + //是否购买,生效时间 + if ("1".equals(user.getVip())){ + //是超级会员或者国学会员 + if (userVipList.size() > 0) { + courseCatalogueEntity.setStartTime(userVipList.get(0).getStartTime()); + courseCatalogueEntity.setEndTime(userVipList.get(0).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); + } + + //加入收藏(加入正在学习) + @RequestMapping("/addUserCourseStudying") + public R addUserCourseStudying(@RequestBody Map map){ + int isExist = userCourseStudyingService.count(new LambdaQueryWrapper() + .eq(UserCourseStudying::getUserId,ShiroUtils.getUId()) + .eq(UserCourseStudying::getCourseId,map.get("courseId"))); + if (isExist>0){ + return R.error("已存在"); + }else { + UserCourseStudying userCourseStudying = new UserCourseStudying(); + userCourseStudying.setUserId(ShiroUtils.getUId()); + userCourseStudying.setCourseId(map.get("courseId")); + userCourseStudyingService.save(userCourseStudying); + return R.ok().put("result",userCourseStudying); + } + } + + //移出收藏(移出正在学习) + @RequestMapping("/removeUserCourseStudying") + public R removeUserCourseStudying(@RequestBody Map map){ + userCourseStudyingService.remove(new LambdaQueryWrapper() + .eq(UserCourseStudying::getUserId,ShiroUtils.getUId()).eq(UserCourseStudying::getCourseId,map.get("courseId"))); + return R.ok(); + } + +} diff --git a/src/main/java/com/peanut/modules/psyche/controller/PsycheHomeController.java b/src/main/java/com/peanut/modules/psyche/controller/PsycheHomeController.java index 1589c726..4bca8201 100644 --- a/src/main/java/com/peanut/modules/psyche/controller/PsycheHomeController.java +++ b/src/main/java/com/peanut/modules/psyche/controller/PsycheHomeController.java @@ -4,11 +4,15 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.github.yulichang.wrapper.MPJLambdaWrapper; import com.peanut.common.utils.R; -import com.peanut.modules.common.entity.CourseEntity; -import com.peanut.modules.common.entity.CoursePsyche; -import com.peanut.modules.common.entity.CourseToPsyche; +import com.peanut.common.utils.ShiroUtils; +import com.peanut.modules.common.entity.*; import com.peanut.modules.common.service.CoursePsycheService; +import com.peanut.modules.common.service.UserCourseStudyingService; +import com.peanut.modules.common.service.UserVipService; +import com.peanut.modules.master.service.CourseCatalogueService; import com.peanut.modules.master.service.CourseService; +import com.peanut.modules.master.service.UserCourseBuyService; +import com.peanut.modules.sociology.service.ShopProductService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RequestBody; @@ -26,6 +30,8 @@ public class PsycheHomeController { private CoursePsycheService coursePsycheService; @Autowired private CourseService courseService; + @Autowired + private ShopProductService shopProductService; //获取标签列表 @RequestMapping("/getPsycheLabels") @@ -49,5 +55,48 @@ public class PsycheHomeController { return R.ok().put("courses",courseEntityPage); } + //营销标签下商品列表 + @RequestMapping("/getPsycheMarketProductList") + public R getPsycheMarketProductList(@RequestBody Map params){ + MPJLambdaWrapper wrapper = new MPJLambdaWrapper<>(); + wrapper.selectAll(ShopProduct.class); + wrapper.leftJoin(ShopProductToPsycheMarket.class,ShopProductToPsycheMarket::getProductId,ShopProduct::getProductId); + wrapper.eq(ShopProductToPsycheMarket::getPsycheMarketId,params.get("shopProductToPsycheMarketId")); + wrapper.orderByAsc(ShopProductToPsycheMarket::getSort); + Page shopProductPage = shopProductService.page(new Page<>( + Long.parseLong(params.get("page").toString()), Long.parseLong(params.get("limit").toString())),wrapper); + return R.ok().put("shopProductPage",shopProductPage); + } + + //营销标签下课程列表 + @RequestMapping("/getPsycheMarketCourseList") + public R getPsycheMarketCourseList(@RequestBody Map params){ + MPJLambdaWrapper wrapper = new MPJLambdaWrapper<>(); + wrapper.selectAll(CourseEntity.class); + wrapper.leftJoin(CourseToPsycheMarket.class, CourseToPsycheMarket::getCourseId,CourseEntity::getId); + wrapper.eq(CourseToPsycheMarket::getPsycheMarketId,params.get("courseToPsycheMarketId")); + wrapper.orderByAsc(CourseToPsycheMarket::getSort); + Page courseEntityPage = courseService.page(new Page<>( + Long.parseLong(params.get("page").toString()), Long.parseLong(params.get("limit").toString())),wrapper); + return R.ok().put("courseEntityPage",courseEntityPage); + } + + //最近学习课程列表 + @RequestMapping("/getUserLateCourseList") + public R getUserLateCourseList(){ + MPJLambdaWrapper wrapper = new MPJLambdaWrapper<>(); + wrapper.selectAll(CourseEntity.class); + wrapper.distinct(); + wrapper.leftJoin(UserToCourseEntity.class,UserToCourseEntity::getCourseId,CourseEntity::getId); + wrapper.eq(UserToCourseEntity::getUserId, ShiroUtils.getUId()); + wrapper.orderByDesc(UserToCourseEntity::getUpdateTime); + wrapper.exists("select * from course_to_psyche where course_id = t.id"); + wrapper.last("Limit 4"); + List courseList = courseService.list(wrapper); + return R.ok().put("courseList",courseList); + } + + + } diff --git a/src/main/java/com/peanut/modules/sys/controller/VisitorController.java b/src/main/java/com/peanut/modules/sys/controller/VisitorController.java index eb7b3f4e..367c84a8 100644 --- a/src/main/java/com/peanut/modules/sys/controller/VisitorController.java +++ b/src/main/java/com/peanut/modules/sys/controller/VisitorController.java @@ -12,8 +12,11 @@ import com.peanut.modules.common.entity.*; import com.peanut.modules.common.service.CoursePsycheService; import com.peanut.modules.common.service.MessageService; import com.peanut.modules.common.to.ParamTo; +import com.peanut.modules.master.service.CourseCatalogueService; +import com.peanut.modules.master.service.CourseToSociologyService; import com.peanut.modules.medical.service.CourseMedicalService; import com.peanut.modules.medical.service.CourseService; +import com.peanut.modules.sociology.service.CourseCatalogueChapterService; import com.peanut.modules.sociology.service.CourseSociologyService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; @@ -51,6 +54,10 @@ public class VisitorController { @Autowired private CourseSociologyService sociologyService; @Autowired + private CourseCatalogueService courseCatalogueService; + @Autowired + private CourseCatalogueChapterService courseCatalogueChapterService; + @Autowired private com.peanut.modules.medical.service.ShopProductService productService; @Autowired private CourseService courseService; @@ -254,6 +261,39 @@ public class VisitorController { List labelsTree = sociologyService.getCourseSociologyTree(); return R.ok().put("labels",labelsTree); } + + //获取标签下课程 + @RequestMapping("/getCourseBySociologyId") + public R getCourseBySociology(@RequestBody Map params){ + MPJLambdaWrapper wrapper = new MPJLambdaWrapper(); + wrapper.selectAll(CourseEntity.class); + wrapper.leftJoin(CourseToSociologyEntity.class,CourseToSociologyEntity::getCourseId,CourseEntity::getId); + wrapper.eq(CourseToSociologyEntity::getSociologyId,params.get("sociologyId")); + List courseList = courseService.list(wrapper); + return R.ok().put("courseList",courseList); + } + //课程详情 + @RequestMapping("/getSociologyCourseInfo") + public R getSociologyCourseInfo(@RequestBody Map params){ + Map courseDetail = new HashMap<>(); + //基础信息 + CourseEntity course = courseService.getById(params.get("courseId").toString()); + courseDetail.put("course",course); + //目录信息 + List courseCatalogueEntities = courseCatalogueService.list(new LambdaQueryWrapper() + .eq(CourseCatalogueEntity::getCourseId, course.getId()).orderByAsc(CourseCatalogueEntity::getSort)); + courseDetail.put("catalogues",courseCatalogueEntities); + return R.ok().put("data",courseDetail); + } + //课程章节 + @RequestMapping("/getSociologyCourseCatalogueInfo") + public R getSociologyCourseCatalogueInfo(@RequestBody Map params){ + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(CourseCatalogueChapterEntity::getCatalogueId,params.get("catalogueId")); + wrapper.orderByAsc(CourseCatalogueChapterEntity::getSort); + List list = courseCatalogueChapterService.list(wrapper); + return R.ok().put("list",list); + } /** * 国学营销标签下商品列表 */