diff --git a/src/main/java/com/peanut/modules/common/controller/HomeSearchController.java b/src/main/java/com/peanut/modules/common/controller/HomeSearchController.java new file mode 100644 index 00000000..f280c9b9 --- /dev/null +++ b/src/main/java/com/peanut/modules/common/controller/HomeSearchController.java @@ -0,0 +1,83 @@ +package com.peanut.modules.common.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.book.service.ShopProductService; +import com.peanut.modules.common.dao.ShopProductCourseDao; +import com.peanut.modules.common.entity.*; +import com.peanut.modules.common.service.UserVipService; +import com.peanut.modules.master.service.CourseCatalogueService; +import com.peanut.modules.medical.service.CourseService; +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.List; +import java.util.Map; + +//首页搜索 +@Slf4j +@RestController("commonHomeSearch") +@RequestMapping("common/homeSearch") +public class HomeSearchController { + + @Autowired + private ShopProductService shopProductService; + @Autowired + private CourseService courseService; + @Autowired + private CourseCatalogueService courseCatalogueService; + @Autowired + private ShopProductCourseDao shopProductCourseDao; + @Autowired + private UserVipService userVipService; + + //首页搜索 + @RequestMapping("/searchData") + public R searchData(@RequestBody Map params) { + List shopProductList = shopProductService.list(new LambdaQueryWrapper() + .ne(ShopProduct::getGoodsType,"05") + .like(ShopProduct::getProductName, params.get("keyWord").toString())); + for (ShopProduct shopProduct : shopProductList) { + shopProduct.setVipPrice(shopProductService.getVipPrice(shopProduct)); + if (userVipService.isVip()&&shopProduct.getIsVipPrice()==1){ + shopProduct.setVipPrice(shopProductService.getVipPrice(shopProduct)); + } + } + MPJLambdaWrapper wrapper = new MPJLambdaWrapper<>(); + wrapper.leftJoin(CourseCatalogueEntity.class,CourseCatalogueEntity::getCourseId,CourseEntity::getId); + wrapper.select("DISTINCT t.id,t.title,t.image,t.square_image squareImage,t.content"); + String appName = "course_to_medicine"; + if ("zmzm".equals(params.get("appName").toString())) { + appName = "course_to_sociology"; + }else if ("xlkj".equals(params.get("appName").toString())) { + appName = "course_to_psyche"; + } + wrapper.select("(select level from "+appName+" where course_id = t.id and del_flag = 0 limit 1) level"); + wrapper.select("(select selective from "+appName+" where course_id = t.id and del_flag = 0 limit 1) selective"); + //第一版没用上,用来判断用户是否拥有课程 + wrapper.select("(select count(1) from user_course_buy where user_id = "+ ShiroUtils.getUId() +" and course_id = t.id and del_flag = 0) valid"); + wrapper.select("(select count(1) from user_course_buy where user_id = "+ ShiroUtils.getUId() +" and course_id = t.id and del_flag = -1) expired"); + wrapper.like(CourseEntity::getTitle,params.get("keyWord").toString()); + wrapper.apply("(t.id in (select course_id from "+appName+" where del_flag = 0))"); + List> courseEntities = courseService.listMaps(wrapper); + for (Map map : courseEntities) { + List courseCatalogueEntities = courseCatalogueService.list(new LambdaQueryWrapper() + .eq(CourseCatalogueEntity::getCourseId, map.get("id")) + .orderByAsc(CourseCatalogueEntity::getSort)); + for (CourseCatalogueEntity co : courseCatalogueEntities){ + MPJLambdaWrapper shopProductCourseEntityMPJLambdaWrapper = new MPJLambdaWrapper<>(); + shopProductCourseEntityMPJLambdaWrapper.selectAll(ShopProduct.class); + shopProductCourseEntityMPJLambdaWrapper.leftJoin(ShopProduct.class,ShopProduct::getProductId,ShopProductCourseEntity::getProductId); + shopProductCourseEntityMPJLambdaWrapper.eq(ShopProductCourseEntity::getCatalogueId,co.getId()); + List shopProducts = shopProductCourseDao.selectJoinList(ShopProduct.class, shopProductCourseEntityMPJLambdaWrapper); + co.setProductList(shopProducts); + } + map.put("courseCatalogueEntityList",courseCatalogueEntities); + } + return R.ok().put("shopProductList", shopProductList).put("courseEntities", courseEntities); + } +}