feat(shop): 添加根据店铺ID获取商品列表的功能

在ShopGoodsService接口及其实现类中,新增了根据shopId过滤商品列表的功能。同时,更新了ShopController以支持通过shopId参数获取商品列表。这一改动是为了支持不同店铺展示其专属商品的需求。
This commit is contained in:
dzq 2025-05-09 15:26:06 +08:00
parent fa900ef3f5
commit 931bbd1a4b
6 changed files with 34 additions and 11 deletions

View File

@ -39,7 +39,8 @@ public class ShopController {
private final CategoryApplicationService categoryApplicationService; private final CategoryApplicationService categoryApplicationService;
@GetMapping("/goods") @GetMapping("/goods")
public ResponseDTO<ShopGoodsResponse> getShopGoodsInfo() { public ResponseDTO<ShopGoodsResponse> getShopGoodsInfo(@RequestParam(required = false) Long shopId) {
log.info("getShopGoodsInfo shopId: {}", shopId);
/*// 获取商品列表 /*// 获取商品列表
List<ShopGoodsEntity> goodsList = goodsApplicationService.getGoodsAll(); List<ShopGoodsEntity> goodsList = goodsApplicationService.getGoodsAll();
goodsList.forEach(goods -> { goodsList.forEach(goods -> {
@ -52,7 +53,7 @@ public class ShopController {
List<ShopCategoryDTO> categoryList = categoryApplicationService.getCategoryAll();*/ List<ShopCategoryDTO> categoryList = categoryApplicationService.getCategoryAll();*/
// 客户端显示商品列表按柜机格口 // 客户端显示商品列表按柜机格口
List<SearchGoodsWithCabinetDO> goodsWithCabinetList = goodsApplicationService.getGoodsWithCabinetList(); List<SearchGoodsWithCabinetDO> goodsWithCabinetList = goodsApplicationService.getGoodsWithCabinetList(shopId);
goodsWithCabinetList.forEach(goodsWithCabinet -> { goodsWithCabinetList.forEach(goodsWithCabinet -> {
goodsWithCabinet.setCategoryId(goodsWithCabinet.getCabinetId()); goodsWithCabinet.setCategoryId(goodsWithCabinet.getCabinetId());
}); });
@ -75,12 +76,10 @@ public class ShopController {
*/ */
@GetMapping("/wechatAuth") @GetMapping("/wechatAuth")
public RedirectView wechatAuthRedirect(HttpServletRequest request) { public RedirectView wechatAuthRedirect(HttpServletRequest request) {
/*java.util.StringJoiner joiner = new java.util.StringJoiner("&"); String shopId = request.getParameter("shopId");
request.getParameterMap().forEach((key, values) -> { request.getParameterMap().forEach((key, values) -> {
joiner.add(key + "=" + String.join(",", values));
log.info("wechatAuth key: {} value: {}", key, values[0]); log.info("wechatAuth key: {} value: {}", key, values[0]);
}); });
log.info("wechatAuth 参数:{}", joiner.toString());*/
// 从请求参数中提取包含token的参数名参数名本身可能包含"token=" // 从请求参数中提取包含token的参数名参数名本身可能包含"token="
String token = request.getParameterMap().keySet().stream() String token = request.getParameterMap().keySet().stream()
@ -99,10 +98,14 @@ public class ShopController {
state = "state"; state = "state";
} }
String redirect_uri = "http%3A%2F%2Fwxshop.ab98.cn%2Fshop";
if (StringUtils.isNotBlank(shopId)) {
redirect_uri += "%3FshopId%3D" + shopId;
}
// 构造微信网页授权URL // 构造微信网页授权URL
String authUrl = "https://open.weixin.qq.com/connect/oauth2/authorize" String authUrl = "https://open.weixin.qq.com/connect/oauth2/authorize"
+ "?appid=" + WeixinConstants.appid + "?appid=" + WeixinConstants.appid
+ "&redirect_uri=http%3A%2F%2Fwxshop.ab98.cn%2Fshop" + "&redirect_uri=" + redirect_uri
+ "&response_type=code" + "&response_type=code"
+ "&scope=snsapi_base" + "&scope=snsapi_base"
+ "&state=" + state + "&state=" + state

View File

@ -62,8 +62,8 @@ public class GoodsApplicationService {
} }
public List<SearchGoodsWithCabinetDO> getGoodsWithCabinetList() { public List<SearchGoodsWithCabinetDO> getGoodsWithCabinetList(Long shopId) {
return shopGoodsService.getGoodsWithCabinetList(); return shopGoodsService.getGoodsWithCabinetList(shopId);
} }
public ShopGoodsDTO getGoodsInfo(Long goodsId) { public ShopGoodsDTO getGoodsInfo(Long goodsId) {

View File

@ -28,6 +28,9 @@ public class SearchGoodsWithCabinetDO extends BaseEntity<SearchGoodsWithCabinetD
@TableField("sc.cabinet_name") @TableField("sc.cabinet_name")
private String cabinetName; private String cabinetName;
@TableField("sc.shop_id")
private Long shopId;
@TableField("cc.cell_id") @TableField("cc.cell_id")
private Long cellId; private Long cellId;
} }

View File

@ -72,6 +72,16 @@ public interface ShopGoodsMapper extends BaseMapper<ShopGoodsEntity> {
"WHERE g.deleted = 0 AND sc.deleted = 0 AND cc.deleted = 0 AND cc.goods_id IS NOT NULL ") "WHERE g.deleted = 0 AND sc.deleted = 0 AND cc.deleted = 0 AND cc.goods_id IS NOT NULL ")
List<SearchGoodsWithCabinetDO> getGoodsWithCabinetList(); List<SearchGoodsWithCabinetDO> 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<SearchGoodsWithCabinetDO> getGoodsWithCabinetListByShopId(@Param("shopId")Long shopId);
@Select("SELECT g.goods_id, g.goods_name, g.category_id, g.price, " + @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, " + "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, " + "GROUP_CONCAT(DISTINCT cc.cell_no) AS cell_no_str, " +

View File

@ -19,7 +19,7 @@ public interface ShopGoodsService extends IService<ShopGoodsEntity> {
List<ShopGoodsEntity> selectAll(); List<ShopGoodsEntity> selectAll();
List<SearchGoodsWithCabinetDO> getGoodsWithCabinetList(); List<SearchGoodsWithCabinetDO> getGoodsWithCabinetList(Long shopId);
SearchGoodsDO getGoodsInfo(Long goodsId); SearchGoodsDO getGoodsInfo(Long goodsId);
} }

View File

@ -4,6 +4,7 @@ import com.agileboot.common.core.page.AbstractPageQuery;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.List; import java.util.List;
@ -15,6 +16,7 @@ import java.util.List;
* @author valarchie * @author valarchie
* @since 2025-03-03 * @since 2025-03-03
*/ */
@Slf4j
@Service @Service
public class ShopGoodsServiceImpl extends ServiceImpl<ShopGoodsMapper, ShopGoodsEntity> implements ShopGoodsService { public class ShopGoodsServiceImpl extends ServiceImpl<ShopGoodsMapper, ShopGoodsEntity> implements ShopGoodsService {
@Override @Override
@ -31,8 +33,13 @@ public class ShopGoodsServiceImpl extends ServiceImpl<ShopGoodsMapper, ShopGoods
} }
@Override @Override
public List<SearchGoodsWithCabinetDO> getGoodsWithCabinetList() { public List<SearchGoodsWithCabinetDO> getGoodsWithCabinetList(Long shopId) {
if (shopId == null) {
return baseMapper.getGoodsWithCabinetList(); return baseMapper.getGoodsWithCabinetList();
} else {
log.info("getGoodsWithCabinetList shopId: {}", shopId);
return baseMapper.getGoodsWithCabinetListByShopId(shopId);
}
} }
@Override @Override