QueryWrapper全部升级LambdaQueryWrapper

This commit is contained in:
LIONCITYS\lioncity
2020-10-16 14:56:06 +08:00
parent 4c89f55a05
commit c14422a985
3 changed files with 18 additions and 20 deletions

View File

@ -6,7 +6,7 @@ import co.yixiang.modules.monitor.domain.Visits;
import co.yixiang.modules.monitor.service.VisitsService; import co.yixiang.modules.monitor.service.VisitsService;
import co.yixiang.modules.monitor.service.mapper.VisitsMapper; import co.yixiang.modules.monitor.service.mapper.VisitsMapper;
import co.yixiang.utils.StringUtils; import co.yixiang.utils.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Propagation;

View File

@ -230,50 +230,49 @@ public class YxStoreProductServiceImpl extends BaseServiceImpl<StoreProductMappe
@Override @Override
public List<YxStoreProductQueryVo> getGoodsList(YxStoreProductQueryParam productQueryParam) { public List<YxStoreProductQueryVo> getGoodsList(YxStoreProductQueryParam productQueryParam) {
QueryWrapper<YxStoreProduct> wrapper = new QueryWrapper<>(); LambdaQueryWrapper<YxStoreProduct> wrapper = new LambdaQueryWrapper<>();
wrapper.lambda().eq(YxStoreProduct::getIsShow, CommonEnum.SHOW_STATUS_1.getValue()); wrapper.eq(YxStoreProduct::getIsShow, CommonEnum.SHOW_STATUS_1.getValue());
//多字段模糊查询分类搜索 //多字段模糊查询分类搜索
if (StrUtil.isNotBlank(productQueryParam.getSid()) && if (StrUtil.isNotBlank(productQueryParam.getSid()) &&
!ShopConstants.YSHOP_ZERO.equals(productQueryParam.getSid())) { !ShopConstants.YSHOP_ZERO.equals(productQueryParam.getSid())) {
wrapper.lambda().eq(YxStoreProduct::getCateId, productQueryParam.getSid()); wrapper.eq(YxStoreProduct::getCateId, productQueryParam.getSid());
} }
//关键字搜索 //关键字搜索
if (StrUtil.isNotEmpty(productQueryParam.getKeyword())) { if (StrUtil.isNotEmpty(productQueryParam.getKeyword())) {
String blurry = "storeName,storeInfo,keyword";
String[] blurrys = blurry.split(",");
wrapper.and(wrapper1 -> { wrapper.and(wrapper1 -> {
for (int i=0;i< blurrys.length;i++) {
String column = humpToUnderline(blurrys[i]);
wrapper1.or(); wrapper1.or();
wrapper1.like(column, productQueryParam.getKeyword()); wrapper1.like(YxStoreProduct::getStoreName, productQueryParam.getKeyword());
} wrapper1.or();
wrapper1.like(YxStoreProduct::getStoreInfo, productQueryParam.getKeyword());
wrapper1.or();
wrapper1.like(YxStoreProduct::getKeyword, productQueryParam.getKeyword());
}); });
} }
//新品搜索 //新品搜索
if (StrUtil.isNotBlank(productQueryParam.getNews()) && if (StrUtil.isNotBlank(productQueryParam.getNews()) &&
!ShopConstants.YSHOP_ZERO.equals(productQueryParam.getNews())) { !ShopConstants.YSHOP_ZERO.equals(productQueryParam.getNews())) {
wrapper.lambda().eq(YxStoreProduct::getIsNew, ShopCommonEnum.IS_NEW_1.getValue()); wrapper.eq(YxStoreProduct::getIsNew, ShopCommonEnum.IS_NEW_1.getValue());
} }
//销量排序 //销量排序
if (SortEnum.DESC.getValue().equals(productQueryParam.getSalesOrder())) { if (SortEnum.DESC.getValue().equals(productQueryParam.getSalesOrder())) {
wrapper.lambda().orderByDesc(YxStoreProduct::getSales); wrapper.orderByDesc(YxStoreProduct::getSales);
} else if (SortEnum.ASC.getValue().equals(productQueryParam.getSalesOrder())) { } else if (SortEnum.ASC.getValue().equals(productQueryParam.getSalesOrder())) {
wrapper.lambda().orderByAsc(YxStoreProduct::getSales); wrapper.orderByAsc(YxStoreProduct::getSales);
} }
//价格排序 //价格排序
if (SortEnum.DESC.getValue().equals(productQueryParam.getPriceOrder())) { if (SortEnum.DESC.getValue().equals(productQueryParam.getPriceOrder())) {
wrapper.lambda().orderByDesc(YxStoreProduct::getPrice); wrapper.orderByDesc(YxStoreProduct::getPrice);
} else if (SortEnum.ASC.getValue().equals(productQueryParam.getPriceOrder())) { } else if (SortEnum.ASC.getValue().equals(productQueryParam.getPriceOrder())) {
wrapper.lambda().orderByAsc(YxStoreProduct::getPrice); wrapper.orderByAsc(YxStoreProduct::getPrice);
} }
wrapper.lambda().orderByDesc(YxStoreProduct::getSort); wrapper.orderByDesc(YxStoreProduct::getSort);
//无其他排序条件时,防止因为商品排序导致商品重复 //无其他排序条件时,防止因为商品排序导致商品重复
if (StringUtils.isNullOrEmpty(productQueryParam.getPriceOrder()) && StringUtils.isNullOrEmpty(productQueryParam.getSalesOrder())) { if (StringUtils.isNullOrEmpty(productQueryParam.getPriceOrder()) && StringUtils.isNullOrEmpty(productQueryParam.getSalesOrder())) {
wrapper.lambda().orderByDesc(YxStoreProduct::getId); wrapper.orderByDesc(YxStoreProduct::getId);
} }
Page<YxStoreProduct> pageModel = new Page<>(productQueryParam.getPage(), Page<YxStoreProduct> pageModel = new Page<>(productQueryParam.getPage(),
productQueryParam.getLimit()); productQueryParam.getLimit());

View File

@ -268,8 +268,7 @@ public class YxWechatLiveServiceImpl extends BaseServiceImpl<YxWechatLiveMapper,
public List<YxWechatLiveDto> getList(int page, int limit, int order) { public List<YxWechatLiveDto> getList(int page, int limit, int order) {
//todo 添加状态判断 //todo 添加状态判断
LambdaQueryWrapper<YxWechatLive> wrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<YxWechatLive> wrapper = new LambdaQueryWrapper<>();
wrapper wrapper.orderByDesc(YxWechatLive::getStartTime);
.orderByDesc(YxWechatLive::getStartTime);
Page<YxWechatLive> pageModel = new Page<>(page, limit); Page<YxWechatLive> pageModel = new Page<>(page, limit);