From 931bbd1a4b8df37105b12a348704add94e91f91e Mon Sep 17 00:00:00 2001 From: dzq Date: Fri, 9 May 2025 15:26:06 +0800 Subject: [PATCH] =?UTF-8?q?feat(shop):=20=E6=B7=BB=E5=8A=A0=E6=A0=B9?= =?UTF-8?q?=E6=8D=AE=E5=BA=97=E9=93=BAID=E8=8E=B7=E5=8F=96=E5=95=86?= =?UTF-8?q?=E5=93=81=E5=88=97=E8=A1=A8=E7=9A=84=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在ShopGoodsService接口及其实现类中,新增了根据shopId过滤商品列表的功能。同时,更新了ShopController以支持通过shopId参数获取商品列表。这一改动是为了支持不同店铺展示其专属商品的需求。 --- .../agileboot/api/controller/ShopController.java | 15 +++++++++------ .../shop/goods/GoodsApplicationService.java | 4 ++-- .../shop/goods/db/SearchGoodsWithCabinetDO.java | 3 +++ .../domain/shop/goods/db/ShopGoodsMapper.java | 10 ++++++++++ .../domain/shop/goods/db/ShopGoodsService.java | 2 +- .../shop/goods/db/ShopGoodsServiceImpl.java | 11 +++++++++-- 6 files changed, 34 insertions(+), 11 deletions(-) diff --git a/agileboot-api/src/main/java/com/agileboot/api/controller/ShopController.java b/agileboot-api/src/main/java/com/agileboot/api/controller/ShopController.java index d215b34..6214e3c 100644 --- a/agileboot-api/src/main/java/com/agileboot/api/controller/ShopController.java +++ b/agileboot-api/src/main/java/com/agileboot/api/controller/ShopController.java @@ -39,7 +39,8 @@ public class ShopController { private final CategoryApplicationService categoryApplicationService; @GetMapping("/goods") - public ResponseDTO getShopGoodsInfo() { + public ResponseDTO getShopGoodsInfo(@RequestParam(required = false) Long shopId) { + log.info("getShopGoodsInfo shopId: {}", shopId); /*// 获取商品列表 List goodsList = goodsApplicationService.getGoodsAll(); goodsList.forEach(goods -> { @@ -52,7 +53,7 @@ public class ShopController { List categoryList = categoryApplicationService.getCategoryAll();*/ // 客户端显示商品列表按柜机格口 - List goodsWithCabinetList = goodsApplicationService.getGoodsWithCabinetList(); + List goodsWithCabinetList = goodsApplicationService.getGoodsWithCabinetList(shopId); goodsWithCabinetList.forEach(goodsWithCabinet -> { goodsWithCabinet.setCategoryId(goodsWithCabinet.getCabinetId()); }); @@ -75,12 +76,10 @@ public class ShopController { */ @GetMapping("/wechatAuth") public RedirectView wechatAuthRedirect(HttpServletRequest request) { - /*java.util.StringJoiner joiner = new java.util.StringJoiner("&"); + String shopId = request.getParameter("shopId"); request.getParameterMap().forEach((key, values) -> { - joiner.add(key + "=" + String.join(",", values)); log.info("wechatAuth key: {} value: {}", key, values[0]); }); - log.info("wechatAuth 参数:{}", joiner.toString());*/ // 从请求参数中提取包含token的参数名(参数名本身可能包含"token=") String token = request.getParameterMap().keySet().stream() @@ -99,10 +98,14 @@ public class ShopController { state = "state"; } + String redirect_uri = "http%3A%2F%2Fwxshop.ab98.cn%2Fshop"; + if (StringUtils.isNotBlank(shopId)) { + redirect_uri += "%3FshopId%3D" + shopId; + } // 构造微信网页授权URL String authUrl = "https://open.weixin.qq.com/connect/oauth2/authorize" + "?appid=" + WeixinConstants.appid - + "&redirect_uri=http%3A%2F%2Fwxshop.ab98.cn%2Fshop" + + "&redirect_uri=" + redirect_uri + "&response_type=code" + "&scope=snsapi_base" + "&state=" + state diff --git a/agileboot-domain/src/main/java/com/agileboot/domain/shop/goods/GoodsApplicationService.java b/agileboot-domain/src/main/java/com/agileboot/domain/shop/goods/GoodsApplicationService.java index 63bd019..9ad75a1 100644 --- a/agileboot-domain/src/main/java/com/agileboot/domain/shop/goods/GoodsApplicationService.java +++ b/agileboot-domain/src/main/java/com/agileboot/domain/shop/goods/GoodsApplicationService.java @@ -62,8 +62,8 @@ public class GoodsApplicationService { } - public List getGoodsWithCabinetList() { - return shopGoodsService.getGoodsWithCabinetList(); + public List getGoodsWithCabinetList(Long shopId) { + return shopGoodsService.getGoodsWithCabinetList(shopId); } public ShopGoodsDTO getGoodsInfo(Long goodsId) { diff --git a/agileboot-domain/src/main/java/com/agileboot/domain/shop/goods/db/SearchGoodsWithCabinetDO.java b/agileboot-domain/src/main/java/com/agileboot/domain/shop/goods/db/SearchGoodsWithCabinetDO.java index 996c049..72afb65 100644 --- a/agileboot-domain/src/main/java/com/agileboot/domain/shop/goods/db/SearchGoodsWithCabinetDO.java +++ b/agileboot-domain/src/main/java/com/agileboot/domain/shop/goods/db/SearchGoodsWithCabinetDO.java @@ -28,6 +28,9 @@ public class SearchGoodsWithCabinetDO extends BaseEntity { "WHERE g.deleted = 0 AND sc.deleted = 0 AND cc.deleted = 0 AND cc.goods_id IS NOT NULL ") List getGoodsWithCabinetList(); + @Select("SELECT g.goods_id, g.goods_name, g.category_id, g.price, " + + "g.status, g.cover_img, g.goods_detail, " + + "g.creator_id, g.create_time, g.updater_id, g.update_time, g.remark, g.deleted, " + + "sc.cabinet_id, sc.cabinet_name, sc.shop_id, cc.stock, cc.cell_id " + + "FROM shop_goods g " + + "LEFT JOIN cabinet_cell cc ON g.goods_id = cc.goods_id " + + "LEFT JOIN smart_cabinet sc ON cc.cabinet_id = sc.cabinet_id " + + "WHERE g.deleted = 0 AND sc.deleted = 0 AND sc.shop_id = #{shopId} AND cc.deleted = 0 AND cc.goods_id IS NOT NULL ") + List getGoodsWithCabinetListByShopId(@Param("shopId")Long shopId); + @Select("SELECT g.goods_id, g.goods_name, g.category_id, g.price, " + "g.stock, g.status, g.auto_approval, g.cover_img, SUM(cc.stock) AS total_stock, " + "GROUP_CONCAT(DISTINCT cc.cell_no) AS cell_no_str, " + diff --git a/agileboot-domain/src/main/java/com/agileboot/domain/shop/goods/db/ShopGoodsService.java b/agileboot-domain/src/main/java/com/agileboot/domain/shop/goods/db/ShopGoodsService.java index 9385bc3..8087b17 100644 --- a/agileboot-domain/src/main/java/com/agileboot/domain/shop/goods/db/ShopGoodsService.java +++ b/agileboot-domain/src/main/java/com/agileboot/domain/shop/goods/db/ShopGoodsService.java @@ -19,7 +19,7 @@ public interface ShopGoodsService extends IService { List selectAll(); - List getGoodsWithCabinetList(); + List getGoodsWithCabinetList(Long shopId); SearchGoodsDO getGoodsInfo(Long goodsId); } diff --git a/agileboot-domain/src/main/java/com/agileboot/domain/shop/goods/db/ShopGoodsServiceImpl.java b/agileboot-domain/src/main/java/com/agileboot/domain/shop/goods/db/ShopGoodsServiceImpl.java index 0e47da8..d1c198a 100644 --- a/agileboot-domain/src/main/java/com/agileboot/domain/shop/goods/db/ShopGoodsServiceImpl.java +++ b/agileboot-domain/src/main/java/com/agileboot/domain/shop/goods/db/ShopGoodsServiceImpl.java @@ -4,6 +4,7 @@ import com.agileboot.common.core.page.AbstractPageQuery; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import java.util.List; @@ -15,6 +16,7 @@ import java.util.List; * @author valarchie * @since 2025-03-03 */ +@Slf4j @Service public class ShopGoodsServiceImpl extends ServiceImpl implements ShopGoodsService { @Override @@ -31,8 +33,13 @@ public class ShopGoodsServiceImpl extends ServiceImpl getGoodsWithCabinetList() { - return baseMapper.getGoodsWithCabinetList(); + public List getGoodsWithCabinetList(Long shopId) { + if (shopId == null) { + return baseMapper.getGoodsWithCabinetList(); + } else { + log.info("getGoodsWithCabinetList shopId: {}", shopId); + return baseMapper.getGoodsWithCabinetListByShopId(shopId); + } } @Override