按照商品规格进行模糊查询
This commit is contained in:
parent
7643b5d6d8
commit
3fbd432b9c
|
|
@ -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();
|
startPage();
|
||||||
|
|
||||||
List<Goods> list = goodsService.selectGoodsList(goods);
|
List<Goods> list = goodsService.selectGoodsList(goods);
|
||||||
|
|
|
||||||
|
|
@ -123,4 +123,8 @@ public class Goods extends BaseEntity {
|
||||||
private Integer deliveryService;
|
private Integer deliveryService;
|
||||||
|
|
||||||
private Shop shop;
|
private Shop shop;
|
||||||
|
|
||||||
|
private List<Long> goodsIds;
|
||||||
|
|
||||||
|
private String goodsStandard;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -64,4 +64,11 @@ public interface GoodsStandardMapper {
|
||||||
|
|
||||||
int update(GoodsStandard goodsStandard);
|
int update(GoodsStandard goodsStandard);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据规格名称模糊查询商品规格
|
||||||
|
* @param standardName 规格名称(支持模糊查询)
|
||||||
|
* @return 符合条件的商品规格列表
|
||||||
|
*/
|
||||||
|
List<GoodsStandard> selectByStandardNameLike(@Param("standardName") String standardName);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -59,4 +59,11 @@ public interface GoodsStandardService {
|
||||||
|
|
||||||
int update(GoodsStandard goodsStandard);
|
int update(GoodsStandard goodsStandard);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据规格名称模糊查询商品规格
|
||||||
|
* @param standardName 规格名称(支持模糊查询)
|
||||||
|
* @return 符合条件的商品规格列表
|
||||||
|
*/
|
||||||
|
List<GoodsStandard> selectByStandardNameLike(String standardName);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -86,4 +86,9 @@ public class GoodsStandardServiceImpl implements GoodsStandardService {
|
||||||
public int update(GoodsStandard goodsStandard) {
|
public int update(GoodsStandard goodsStandard) {
|
||||||
return goodsStandardMapper.update(goodsStandard);
|
return goodsStandardMapper.update(goodsStandard);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<GoodsStandard> selectByStandardNameLike(String standardName) {
|
||||||
|
return goodsStandardMapper.selectByStandardNameLike(standardName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -185,6 +185,12 @@
|
||||||
<if test="storeService != null">
|
<if test="storeService != null">
|
||||||
AND g.store_service = #{storeService}
|
AND g.store_service = #{storeService}
|
||||||
</if>
|
</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>
|
</where>
|
||||||
/* 默认生成时间排序 */
|
/* 默认生成时间排序 */
|
||||||
order by create_time
|
order by create_time
|
||||||
|
|
|
||||||
|
|
@ -166,4 +166,14 @@
|
||||||
</set>
|
</set>
|
||||||
WHERE goods_standard_id = #{goodsStandardId}
|
WHERE goods_standard_id = #{goodsStandardId}
|
||||||
</update>
|
</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>
|
</mapper>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue