商品管理检索功能完成,测试通过

develop
ddyd 1 week ago
parent 44e68e4986
commit 6ebf3e0e62

@ -37,7 +37,7 @@ public class SkuInfoController {
@RequestMapping("/list")
//@RequiresPermissions("product:skuinfo:list")
public R list(@RequestParam Map<String, Object> params){
PageUtils page = skuInfoService.queryPage(params);
PageUtils page = skuInfoService.queryPageByCondition(params);
return R.ok().put("page", page);
}

@ -18,5 +18,7 @@ public interface SkuInfoService extends IService<SkuInfoEntity> {
PageUtils queryPage(Map<String, Object> params);
void saveSkuInfo(SkuInfoEntity skuInfoEntity);
PageUtils queryPageByCondition(Map<String, Object> params);
}

@ -1,6 +1,9 @@
package com.bookstore.bookmall.product.service.impl;
import com.mysql.cj.util.StringUtils;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
@ -31,4 +34,58 @@ public class SkuInfoServiceImpl extends ServiceImpl<SkuInfoDao, SkuInfoEntity> i
this.baseMapper.insert(skuInfoEntity);
}
@Override
public PageUtils queryPageByCondition(Map<String, Object> params) {
QueryWrapper<SkuInfoEntity> QueryWrapper = new QueryWrapper<>();
//key: "华为",
//brandId: 9,
//catelogId: 225
//min
//max
String key = (String) params.get("key");
if (!StringUtils.isNullOrEmpty(key)) {
QueryWrapper.and((w)->{
w.eq("sku_id",key).or().like("sku_name", key);
});
}
String brandId = (String) params.get("brandId");
if (!StringUtils.isNullOrEmpty(brandId) && !"0".equals(brandId)) {
QueryWrapper.eq("brand_id", brandId);
}
String catelogId = (String) params.get("catalogId");
if (!StringUtils.isNullOrEmpty(catelogId) && !"0".equals(catelogId)) {
QueryWrapper.eq("catalog_id", catelogId);
}
String min = (String) params.get("min");
if (!StringUtils.isNullOrEmpty(min)) {
QueryWrapper.ge("price", min);
}
String max = (String) params.get("max");
if (!StringUtils.isNullOrEmpty(max)) {
try {
BigDecimal bigDecimal = new BigDecimal(max);
if (bigDecimal.compareTo(new BigDecimal(0)) == 1) {
QueryWrapper.le("price", max);
}
}catch (Exception e){
}
}
IPage<SkuInfoEntity> page = this.page(
new Query<SkuInfoEntity>().getPage(params),
QueryWrapper
);
return new PageUtils(page);
}
}
Loading…
Cancel
Save