fix(shop-goods): 修复商品查询条件及优化SQL查询字段

1. 在SearchShopGoodsQuery中增加externalGoodsId的非空判断,避免当参数为null时生成无效查询条件
2. 简化ShopGoodsMapper中的SQL查询字段,使用g.*替代具体字段列表,同时保持聚合字段不变
This commit is contained in:
dzq 2025-06-05 17:30:29 +08:00
parent 3b80c87f52
commit aefb4366dc
2 changed files with 3 additions and 3 deletions

View File

@ -84,8 +84,8 @@ public interface ShopGoodsMapper extends BaseMapper<ShopGoodsEntity> {
"WHERE g.deleted = 0 AND g.belong_type = 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, " +
"g.stock, g.status, g.auto_approval, g.cover_img, g.goods_detail, g.usage_instruction, SUM(cc.stock) AS total_stock, " +
@Select("SELECT g.*, " +
"SUM(cc.stock) AS total_stock, " +
"GROUP_CONCAT(DISTINCT cc.cell_no) AS cell_no_str, " +
"GROUP_CONCAT(DISTINCT sc.cabinet_name) AS cabinet_name " +
"FROM shop_goods g " +

View File

@ -32,7 +32,7 @@ public class SearchShopGoodsQuery<T> extends AbstractPageQuery<T> {
.ge(minPrice != null, "g.price", minPrice)
.le(maxPrice != null, "g.price", maxPrice)
.eq(belongType != null, "g.belong_type", belongType)
.eq("g.external_goods_id", externalGoodsId)
.eq(externalGoodsId != null, "g.external_goods_id", externalGoodsId)
.eq("g.deleted", 0)
.groupBy("g.goods_id");