Commit cd3ea740 authored by Menethil's avatar Menethil
Browse files

修复类别商品查询BUG

parent 78127aed
...@@ -18,50 +18,76 @@ public class LitemallGoodsService { ...@@ -18,50 +18,76 @@ public class LitemallGoodsService {
@Resource @Resource
private LitemallGoodsMapper goodsMapper; private LitemallGoodsMapper goodsMapper;
Column[] columns = new Column[]{Column.id, Column.name, Column.picUrl, Column.counterPrice, Column.retailPrice};
/**
* 获取热卖商品
*
* @param offset
* @param limit
* @return
*/
public List<LitemallGoods> queryByHot(int offset, int limit) { public List<LitemallGoods> queryByHot(int offset, int limit) {
LitemallGoodsExample example = new LitemallGoodsExample(); LitemallGoodsExample example = new LitemallGoodsExample();
example.or().andIsHotEqualTo(true).andDeletedEqualTo(false); example.or().andIsHotEqualTo(true).andDeletedEqualTo(false);
example.setOrderByClause("add_time desc"); example.setOrderByClause("add_time desc");
PageHelper.startPage(offset, limit); PageHelper.startPage(offset, limit);
return goodsMapper.selectByExample(example);
return goodsMapper.selectByExampleSelective(example, columns);
} }
/**
* 获取新品上市
*
* @param offset
* @param limit
* @return
*/
public List<LitemallGoods> queryByNew(int offset, int limit) { public List<LitemallGoods> queryByNew(int offset, int limit) {
LitemallGoodsExample example = new LitemallGoodsExample(); LitemallGoodsExample example = new LitemallGoodsExample();
example.or().andIsNewEqualTo(true).andDeletedEqualTo(false); example.or().andIsNewEqualTo(true).andDeletedEqualTo(false);
example.setOrderByClause("add_time desc"); example.setOrderByClause("add_time desc");
PageHelper.startPage(offset, limit); PageHelper.startPage(offset, limit);
return goodsMapper.selectByExample(example);
return goodsMapper.selectByExampleSelective(example, columns);
} }
/**
* 获取分类下的商品
*
* @param catList
* @param offset
* @param limit
* @return
*/
public List<LitemallGoods> queryByCategory(List<Integer> catList, int offset, int limit) { public List<LitemallGoods> queryByCategory(List<Integer> catList, int offset, int limit) {
LitemallGoodsExample example = new LitemallGoodsExample(); LitemallGoodsExample example = new LitemallGoodsExample();
example.or().andCategoryIdIn(catList).andDeletedEqualTo(false); example.or().andCategoryIdIn(catList).andDeletedEqualTo(false);
example.setOrderByClause("add_time desc"); example.setOrderByClause("add_time desc");
PageHelper.startPage(offset, limit); PageHelper.startPage(offset, limit);
return goodsMapper.selectByExample(example);
}
public int countByCategory(List<Integer> catList, int offset, int limit) { return goodsMapper.selectByExampleSelective(example, columns);
LitemallGoodsExample example = new LitemallGoodsExample();
example.or().andCategoryIdIn(catList).andDeletedEqualTo(false);
return (int) goodsMapper.countByExample(example);
} }
/**
* 获取分类下的商品
*
* @param catId
* @param offset
* @param limit
* @return
*/
public List<LitemallGoods> queryByCategory(Integer catId, int offset, int limit) { public List<LitemallGoods> queryByCategory(Integer catId, int offset, int limit) {
LitemallGoodsExample example = new LitemallGoodsExample(); LitemallGoodsExample example = new LitemallGoodsExample();
example.or().andCategoryIdEqualTo(catId).andDeletedEqualTo(false); example.or().andCategoryIdEqualTo(catId).andDeletedEqualTo(false);
example.setOrderByClause("add_time desc"); example.setOrderByClause("add_time desc");
PageHelper.startPage(offset, limit); PageHelper.startPage(offset, limit);
return goodsMapper.selectByExample(example);
}
public int countByCategory(Integer catId, Integer page, Integer size) { return goodsMapper.selectByExampleSelective(example, columns);
LitemallGoodsExample example = new LitemallGoodsExample();
example.or().andCategoryIdEqualTo(catId).andDeletedEqualTo(false);
return (int) goodsMapper.countByExample(example);
} }
public List<LitemallGoods> querySelective(Integer catId, Integer brandId, String keyword, Boolean isHot, Boolean isNew, Integer offset, Integer limit, String sort, String order) { public List<LitemallGoods> querySelective(Integer catId, Integer brandId, String keyword, Boolean isHot, Boolean isNew, Integer offset, Integer limit, String sort, String order) {
LitemallGoodsExample example = new LitemallGoodsExample(); LitemallGoodsExample example = new LitemallGoodsExample();
LitemallGoodsExample.Criteria criteria1 = example.or(); LitemallGoodsExample.Criteria criteria1 = example.or();
...@@ -98,7 +124,6 @@ public class LitemallGoodsService { ...@@ -98,7 +124,6 @@ public class LitemallGoodsService {
PageHelper.startPage(offset, limit); PageHelper.startPage(offset, limit);
} }
Column[] columns = new Column[]{Column.id, Column.name, Column.picUrl, Column.counterPrice, Column.retailPrice};
return goodsMapper.selectByExampleSelective(example, columns); return goodsMapper.selectByExampleSelective(example, columns);
} }
...@@ -131,25 +156,6 @@ public class LitemallGoodsService { ...@@ -131,25 +156,6 @@ public class LitemallGoodsService {
return (int) goodsMapper.countByExample(example); return (int) goodsMapper.countByExample(example);
} }
public LitemallGoods findById(Integer id) {
LitemallGoodsExample example = new LitemallGoodsExample();
example.or().andIdEqualTo(id).andDeletedEqualTo(false);
return goodsMapper.selectOneByExampleWithBLOBs(example);
}
public List<LitemallGoods> queryByIds(List<Integer> relatedGoodsIds) {
LitemallGoodsExample example = new LitemallGoodsExample();
example.or().andIdIn(relatedGoodsIds).andDeletedEqualTo(false);
return goodsMapper.selectByExampleWithBLOBs(example);
}
public Integer queryOnSale() {
LitemallGoodsExample example = new LitemallGoodsExample();
example.or().andIsOnSaleEqualTo(true).andDeletedEqualTo(false);
return (int) goodsMapper.countByExample(example);
}
public List<LitemallGoods> querySelective(String goodsSn, String name, Integer page, Integer size, String sort, String order) { public List<LitemallGoods> querySelective(String goodsSn, String name, Integer page, Integer size, String sort, String order) {
LitemallGoodsExample example = new LitemallGoodsExample(); LitemallGoodsExample example = new LitemallGoodsExample();
LitemallGoodsExample.Criteria criteria = example.createCriteria(); LitemallGoodsExample.Criteria criteria = example.createCriteria();
...@@ -181,6 +187,24 @@ public class LitemallGoodsService { ...@@ -181,6 +187,24 @@ public class LitemallGoodsService {
return (int) goodsMapper.countByExample(example); return (int) goodsMapper.countByExample(example);
} }
public LitemallGoods findById(Integer id) {
LitemallGoodsExample example = new LitemallGoodsExample();
example.or().andIdEqualTo(id).andDeletedEqualTo(false);
return goodsMapper.selectOneByExampleWithBLOBs(example);
}
/**
* 获取所有在售物品总数
*
* @return
*/
public Integer queryOnSale() {
LitemallGoodsExample example = new LitemallGoodsExample();
example.or().andIsOnSaleEqualTo(true).andDeletedEqualTo(false);
return (int) goodsMapper.countByExample(example);
}
public void updateById(LitemallGoods goods) { public void updateById(LitemallGoods goods) {
goodsMapper.updateByPrimaryKeySelective(goods); goodsMapper.updateByPrimaryKeySelective(goods);
} }
...@@ -204,6 +228,9 @@ public class LitemallGoodsService { ...@@ -204,6 +228,9 @@ public class LitemallGoodsService {
LitemallGoodsExample.Criteria criteria1 = example.or(); LitemallGoodsExample.Criteria criteria1 = example.or();
LitemallGoodsExample.Criteria criteria2 = example.or(); LitemallGoodsExample.Criteria criteria2 = example.or();
criteria1.andDeletedEqualTo(false);
criteria2.andDeletedEqualTo(false);
if (!StringUtils.isEmpty(brandId)) { if (!StringUtils.isEmpty(brandId)) {
criteria1.andBrandIdEqualTo(brandId); criteria1.andBrandIdEqualTo(brandId);
criteria2.andBrandIdEqualTo(brandId); criteria2.andBrandIdEqualTo(brandId);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment