From 0e4616054f5fb5c2f77db5e1584df4f1c721a042 Mon Sep 17 00:00:00 2001 From: hequan_waynaqua <1669738430@qq.com> Date: Tue, 18 Aug 2020 15:17:27 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E6=89=8B=E6=9C=BA=E7=AB=AF):=20=E4=B8=80?= =?UTF-8?q?=E7=BA=A7=E5=88=86=E7=B1=BB=E5=95=86=E5=93=81=E5=88=97=E8=A1=A8?= =?UTF-8?q?=20=E6=B7=BB=E5=8A=A0=E4=B8=80=E7=BA=A7=E5=88=86=E7=B1=BB?= =?UTF-8?q?=E5=95=86=E5=93=81=E5=88=97=E8=A1=A8=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/core/mapper/shop/GoodsMapper.java | 4 ++++ .../core/service/shop/IGoodsService.java | 9 ++++++++ .../service/shop/impl/GoodsServiceImpl.java | 5 +++++ .../resources/mapper/shop/GoodsMapper.xml | 14 +++++++++++++ .../api/controller/CategoryController.java | 21 ++++++++++++++++++- 5 files changed, 52 insertions(+), 1 deletion(-) diff --git a/waynboot-common/src/main/java/com/wayn/common/core/mapper/shop/GoodsMapper.java b/waynboot-common/src/main/java/com/wayn/common/core/mapper/shop/GoodsMapper.java index 12839b0..eebc855 100644 --- a/waynboot-common/src/main/java/com/wayn/common/core/mapper/shop/GoodsMapper.java +++ b/waynboot-common/src/main/java/com/wayn/common/core/mapper/shop/GoodsMapper.java @@ -5,6 +5,8 @@ import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.wayn.common.core.domain.shop.Goods; +import java.util.List; + /** *

* 商品基本信息表 Mapper 接口 @@ -16,4 +18,6 @@ import com.wayn.common.core.domain.shop.Goods; public interface GoodsMapper extends BaseMapper { IPage selectGoodsListPage(Page page,Goods goods); + + IPage selectGoodsListPageByl2CateId(Page page, List cateList); } diff --git a/waynboot-common/src/main/java/com/wayn/common/core/service/shop/IGoodsService.java b/waynboot-common/src/main/java/com/wayn/common/core/service/shop/IGoodsService.java index 67677fa..6400931 100644 --- a/waynboot-common/src/main/java/com/wayn/common/core/service/shop/IGoodsService.java +++ b/waynboot-common/src/main/java/com/wayn/common/core/service/shop/IGoodsService.java @@ -7,6 +7,7 @@ import com.wayn.common.core.domain.shop.Goods; import com.wayn.common.core.domain.vo.GoodsSaveRelatedVO; import com.wayn.common.util.R; +import java.util.List; import java.util.Map; /** @@ -67,4 +68,12 @@ public interface IGoodsService extends IService { * @return R */ R updateGoodsRelated(GoodsSaveRelatedVO goodsSaveRelatedVO); + + /** + * 根据二级分类Id集合获取对应商品 + * @param page 分页对象 + * @param l2cateList 二级分类Id集合 + * @return r + */ + R selectListPageByCateIds(Page page, List l2cateList); } diff --git a/waynboot-common/src/main/java/com/wayn/common/core/service/shop/impl/GoodsServiceImpl.java b/waynboot-common/src/main/java/com/wayn/common/core/service/shop/impl/GoodsServiceImpl.java index b9eb93a..6a051e6 100644 --- a/waynboot-common/src/main/java/com/wayn/common/core/service/shop/impl/GoodsServiceImpl.java +++ b/waynboot-common/src/main/java/com/wayn/common/core/service/shop/impl/GoodsServiceImpl.java @@ -174,4 +174,9 @@ public class GoodsServiceImpl extends ServiceImpl implements iGoodsProductService.updateBatchById(Arrays.asList(products)); return R.success(); } + + @Override + public R selectListPageByCateIds(Page page, List l2cateList) { + return R.success().add("data", goodsMapper.selectGoodsListPageByl2CateId(page, l2cateList).getRecords()); + } } diff --git a/waynboot-common/src/main/resources/mapper/shop/GoodsMapper.xml b/waynboot-common/src/main/resources/mapper/shop/GoodsMapper.xml index bf1dafa..5380bb2 100644 --- a/waynboot-common/src/main/resources/mapper/shop/GoodsMapper.xml +++ b/waynboot-common/src/main/resources/mapper/shop/GoodsMapper.xml @@ -56,4 +56,18 @@ order by create_time desc + + diff --git a/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/controller/CategoryController.java b/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/controller/CategoryController.java index d44dc94..548ca71 100644 --- a/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/controller/CategoryController.java +++ b/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/controller/CategoryController.java @@ -1,8 +1,13 @@ package com.wayn.mobile.api.controller; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.wayn.common.base.BaseController; import com.wayn.common.core.domain.shop.Category; +import com.wayn.common.core.domain.shop.Goods; import com.wayn.common.core.domain.vo.VanTreeSelectVo; import com.wayn.common.core.service.shop.ICategoryService; +import com.wayn.common.core.service.shop.IGoodsService; import com.wayn.common.util.R; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; @@ -12,14 +17,18 @@ import org.springframework.web.bind.annotation.RestController; import java.util.List; import java.util.Objects; +import java.util.stream.Collectors; @RestController @RequestMapping("category") -public class CategoryController { +public class CategoryController extends BaseController { @Autowired private ICategoryService iCategoryService; + @Autowired + private IGoodsService iGoodsService; + @GetMapping("index") public R index(@RequestParam(required = false) Long id) { R success = R.success(); @@ -48,4 +57,14 @@ public class CategoryController { success.add("subCategoryList", subCategoryList); return success; } + + @GetMapping("goods") + public R listGoodsByFirstCate(@RequestParam(defaultValue = "0") Long cateId) { + Page page = getPage(); + List categoryList = iCategoryService.list(new QueryWrapper().select("id").eq("pid", cateId)); + List cateList = categoryList.stream().map(Category::getId).collect(Collectors.toList()); + return iGoodsService.selectListPageByCateIds(page, cateList); + } + + }