feat(mall): 优化商品查询条件
- 使用 FIND_IN_SET函数替代 like 操作符,提高查询精度 - 修复分类 ID 查询不准确的问题
This commit is contained in:
@@ -110,7 +110,8 @@ public class TzProdServiceImpl extends MPJBaseServiceImpl<TzProdMapper,TzProd> i
|
||||
.eq(TzProd::getStatus, 1)
|
||||
.and(wrapper -> {
|
||||
for (Long id : categoryId) {
|
||||
wrapper.or(w -> w.like(TzProd::getCategoryId, String.valueOf(id)));
|
||||
// 生成 FIND_IN_SET(id,category_id) 的SQL条件
|
||||
wrapper.or().apply("FIND_IN_SET({0}, category_id)", id);
|
||||
}
|
||||
})
|
||||
.orderByDesc(TzProd::getPutawayTime);
|
||||
@@ -181,7 +182,10 @@ public class TzProdServiceImpl extends MPJBaseServiceImpl<TzProdMapper,TzProd> i
|
||||
lqw.like(StringUtils.isNotBlank(bo.getFactoryAddress()), TzProd::getFactoryAddress, bo.getFactoryAddress());
|
||||
lqw.eq(bo.getStatus() != null, TzProd::getStatus, bo.getStatus());
|
||||
lqw.eq(bo.getExamineFlag() != null, TzProd::getExamineFlag, bo.getExamineFlag());
|
||||
lqw.like(bo.getCategoryId() != null, TzProd::getCategoryId, bo.getCategoryId());
|
||||
// lqw.like(bo.getCategoryId() != null, TzProd::getCategoryId, bo.getCategoryId());
|
||||
if(bo.getCategoryId() != null){
|
||||
lqw.or().apply("FIND_IN_SET({0}, t.category_id)", bo.getCategoryId());
|
||||
}
|
||||
lqw.between(params.get("beginTime") != null && params.get("endTime") != null,
|
||||
TzProd::getPutawayTime, params.get("beginTime"), params.get("endTime"));
|
||||
return lqw;
|
||||
|
||||
Reference in New Issue
Block a user