文章目录
- spu
- SpuInfoController.java
- SpuInfoServiceImpl.java
- sku
- SkuInfoController.java
- SkuInfoServiceImpl.java
没有做分类检索功能
spu
SpuInfoController.java
/**
* 列表
*/
@RequestMapping("/list")
//@RequiresPermissions("product:spuinfo:list")
public R list(@RequestParam Map<String, Object> params){
PageUtils page = spuInfoService.queryPageByCondition(params);
return R.ok().put("page", page);
}
SpuInfoServiceImpl.java
/**
* spu的条件查询
* @param params
* @return
*/
@Override
public PageUtils queryPageByCondition(Map<String, Object> params) {
QueryWrapper<SpuInfoEntity> wrapper = new QueryWrapper<>();
//是否携带key
String key = (String) params.get("key");
if (!StringUtils.isEmpty(key)) {
wrapper.and(w->{
w.eq("id", key).or().like("spu_name", key);
});
}
//是否携带分类id,品牌id
String brandId = (String) params.get("brandId");
if (!StringUtils.isEmpty(brandId) && !"0".equalsIgnoreCase(brandId)) {
wrapper.eq("brand_id", brandId);
}
String categoryId = (String) params.get("categoryId");
if (!StringUtils.isEmpty(categoryId) && !"0".equalsIgnoreCase(categoryId)) {
wrapper.eq("category_id", categoryId);
}
//是否携带status
String status = (String) params.get("status");
if (!StringUtils.isEmpty(status)) {
wrapper.eq("public_status", status);
}
IPage<SpuInfoEntity> page = this.page(new Query<SpuInfoEntity>().getPage(params), wrapper);
return new PageUtils(page);
}
sku
SkuInfoController.java
/**
* 列表
*/
@RequestMapping("/list")
//@RequiresPermissions("product:skuinfo:list")
public R list(@RequestParam Map<String, Object> params){
PageUtils page = skuInfoService.queryPageByCondition(params);
return R.ok().put("page", page);
}
SkuInfoServiceImpl.java
/**
* sku的条件查询
* @param params
* @return
*/
@Override
public PageUtils queryPageByCondition(Map<String, Object> params) {
QueryWrapper<SkuInfoEntity> wrapper = new QueryWrapper<>();
//是否携带 key
String key = (String) params.get("key");
if (!StringUtils.isEmpty(key)) {
//wrapper.eq("id", key).or().like("sku_name", key);
wrapper.and(w->{
w.eq("id", key).or().like("sku_name", key);
});
}
String categoryId = (String) params.get("categoryId");
if (!StringUtils.isEmpty(categoryId) && !"0".equalsIgnoreCase(categoryId)){
wrapper.eq("category_id",categoryId);
}
String brandId = (String) params.get("brandId");
if (!StringUtils.isEmpty(brandId) && !"0".equalsIgnoreCase(brandId)){
wrapper.eq("brand_id",brandId);
}
//是否携带 价格区间
String min = (String) params.get("min");
if (!StringUtils.isEmpty(min)) {
wrapper.ge("price", min);
}
String max = (String) params.get("max");
if (!StringUtils.isEmpty(max) && !"0".equalsIgnoreCase(max)) {
wrapper.le("price", max);
}
IPage<SkuInfoEntity> page = this.page(new Query<SkuInfoEntity>().getPage(params), wrapper);
return new PageUtils(page);
}