按照商品规格进行模糊查询

This commit is contained in:
cb 2025-07-07 15:12:25 +08:00
parent 7643b5d6d8
commit 3fbd432b9c
7 changed files with 65 additions and 0 deletions

View File

@ -216,6 +216,32 @@ public class GoodsController extends BaseController {
}
}
// 通过商品规格名称模糊查询
if (StringUtils.isNotEmpty(goods.getGoodsStandard())) {
logger.info("通过商品规格查询:{}", goods.getGoodsStandard());
List<GoodsStandard> matchedStandards = goodsStandardService.selectByStandardNameLike(goods.getGoodsStandard());
if (CollectionUtils.isNotEmpty(matchedStandards)) {
// 获取所有符合规格条件的商品ID
List<Long> goodsIds = matchedStandards.stream()
.map(GoodsStandard::getGoodsId)
.distinct()
.collect(Collectors.toList());
logger.info("通过规格查询到的商品ID列表{}", goodsIds);
// 设置商品ID筛选条件与现有的类目筛选条件组合使用
if (goods.getGoodsIds() == null) {
goods.setGoodsIds(goodsIds);
} else {
// 如果已有商品ID筛选条件取交集
goods.getGoodsIds().retainAll(goodsIds);
}
} else {
logger.info("未找到符合规格条件的商品,设置空结果");
// 如果没找到符合条件的规格设置一个不存在的商品ID
goods.setGoodsIds(Arrays.asList(-1L));
}
}
startPage();
List<Goods> list = goodsService.selectGoodsList(goods);

View File

@ -123,4 +123,8 @@ public class Goods extends BaseEntity {
private Integer deliveryService;
private Shop shop;
private List<Long> goodsIds;
private String goodsStandard;
}

View File

@ -64,4 +64,11 @@ public interface GoodsStandardMapper {
int update(GoodsStandard goodsStandard);
/**
* 根据规格名称模糊查询商品规格
* @param standardName 规格名称支持模糊查询
* @return 符合条件的商品规格列表
*/
List<GoodsStandard> selectByStandardNameLike(@Param("standardName") String standardName);
}

View File

@ -59,4 +59,11 @@ public interface GoodsStandardService {
int update(GoodsStandard goodsStandard);
/**
* 根据规格名称模糊查询商品规格
* @param standardName 规格名称支持模糊查询
* @return 符合条件的商品规格列表
*/
List<GoodsStandard> selectByStandardNameLike(String standardName);
}

View File

@ -86,4 +86,9 @@ public class GoodsStandardServiceImpl implements GoodsStandardService {
public int update(GoodsStandard goodsStandard) {
return goodsStandardMapper.update(goodsStandard);
}
@Override
public List<GoodsStandard> selectByStandardNameLike(String standardName) {
return goodsStandardMapper.selectByStandardNameLike(standardName);
}
}

View File

@ -185,6 +185,12 @@
<if test="storeService != null">
AND g.store_service = #{storeService}
</if>
<if test="goodsIds != null and goodsIds.size > 0">
AND g.goods_id in
<foreach collection="goodsIds" item="goodsIdItem" open="(" separator="," close=")">
#{goodsIdItem}
</foreach>
</if>
</where>
/* 默认生成时间排序 */
order by create_time

View File

@ -166,4 +166,14 @@
</set>
WHERE goods_standard_id = #{goodsStandardId}
</update>
<!-- 根据规格名称模糊查询商品规格 -->
<select id="selectByStandardNameLike" resultMap="GoodsStandardResult">
<include refid="selectGoodsStandard"/>
<where>
<if test="standardName != null and standardName != ''">
AND goods_standard_name LIKE CONCAT('%', #{standardName}, '%')
</if>
</where>
</select>
</mapper>