Commit 21573bfd authored by Junling Bu's avatar Junling Bu
Browse files

fix[litemall-db]: 查询商品服务时,过滤非在售的商品。

parent 3921561e
......@@ -28,8 +28,8 @@ public class LitemallGoodsService {
*/
public List<LitemallGoods> queryByHot(int offset, int limit) {
LitemallGoodsExample example = new LitemallGoodsExample();
example.or().andIsHotEqualTo(true).andDeletedEqualTo(false);
example.setOrderByClause("add_time desc");
example.or().andIsHotEqualTo(true).andIsOnSaleEqualTo(true).andDeletedEqualTo(false);
example.setOrderByClause("add_time desc");
PageHelper.startPage(offset, limit);
return goodsMapper.selectByExampleSelective(example, columns);
......@@ -44,8 +44,8 @@ public class LitemallGoodsService {
*/
public List<LitemallGoods> queryByNew(int offset, int limit) {
LitemallGoodsExample example = new LitemallGoodsExample();
example.or().andIsNewEqualTo(true).andDeletedEqualTo(false);
example.setOrderByClause("add_time desc");
example.or().andIsNewEqualTo(true).andIsOnSaleEqualTo(true).andDeletedEqualTo(false);
example.setOrderByClause("add_time desc");
PageHelper.startPage(offset, limit);
return goodsMapper.selectByExampleSelective(example, columns);
......@@ -61,7 +61,7 @@ public class LitemallGoodsService {
*/
public List<LitemallGoods> queryByCategory(List<Integer> catList, int offset, int limit) {
LitemallGoodsExample example = new LitemallGoodsExample();
example.or().andCategoryIdIn(catList).andDeletedEqualTo(false);
example.or().andCategoryIdIn(catList).andIsOnSaleEqualTo(true).andDeletedEqualTo(false);
example.setOrderByClause("add_time desc");
PageHelper.startPage(offset, limit);
......@@ -79,8 +79,8 @@ public class LitemallGoodsService {
*/
public List<LitemallGoods> queryByCategory(Integer catId, int offset, int limit) {
LitemallGoodsExample example = new LitemallGoodsExample();
example.or().andCategoryIdEqualTo(catId).andDeletedEqualTo(false);
example.setOrderByClause("add_time desc");
example.or().andCategoryIdEqualTo(catId).andIsOnSaleEqualTo(true).andDeletedEqualTo(false);
example.setOrderByClause("add_time desc");
PageHelper.startPage(offset, limit);
return goodsMapper.selectByExampleSelective(example, columns);
......@@ -112,6 +112,8 @@ public class LitemallGoodsService {
criteria1.andKeywordsLike("%" + keywords + "%");
criteria2.andNameLike("%" + keywords + "%");
}
criteria1.andIsOnSaleEqualTo(true);
criteria2.andIsOnSaleEqualTo(true);
criteria1.andDeletedEqualTo(false);
criteria2.andDeletedEqualTo(false);
......@@ -151,6 +153,10 @@ public class LitemallGoodsService {
criteria1.andKeywordsLike("%" + keywords + "%");
criteria2.andNameLike("%" + keywords + "%");
}
criteria1.andIsOnSaleEqualTo(true);
criteria2.andIsOnSaleEqualTo(true);
criteria1.andDeletedEqualTo(false);
criteria2.andDeletedEqualTo(false);
return (int) goodsMapper.countByExample(example);
}
......@@ -165,7 +171,7 @@ public class LitemallGoodsService {
if (!StringUtils.isEmpty(name)) {
criteria.andNameLike("%" + name + "%");
}
criteria.andDeletedEqualTo(false);
criteria.andIsOnSaleEqualTo(true).andDeletedEqualTo(false);
PageHelper.startPage(page, size);
return goodsMapper.selectByExampleWithBLOBs(example);
......@@ -181,7 +187,7 @@ public class LitemallGoodsService {
if (!StringUtils.isEmpty(name)) {
criteria.andNameLike("%" + name + "%");
}
criteria.andDeletedEqualTo(false);
criteria.andIsOnSaleEqualTo(true).andDeletedEqualTo(false);
return (int) goodsMapper.countByExample(example);
}
......@@ -194,7 +200,7 @@ public class LitemallGoodsService {
*/
public LitemallGoods findById(Integer id) {
LitemallGoodsExample example = new LitemallGoodsExample();
example.or().andIdEqualTo(id).andDeletedEqualTo(false);
example.or().andIdEqualTo(id).andIsOnSaleEqualTo(true).andDeletedEqualTo(false);
return goodsMapper.selectOneByExampleWithBLOBs(example);
}
......@@ -206,7 +212,7 @@ public class LitemallGoodsService {
*/
public LitemallGoods findByIdVO(Integer id) {
LitemallGoodsExample example = new LitemallGoodsExample();
example.or().andIdEqualTo(id).andDeletedEqualTo(false);
example.or().andIdEqualTo(id).andIsOnSaleEqualTo(true).andDeletedEqualTo(false);
return goodsMapper.selectOneByExampleSelective(example, columns);
}
......@@ -234,6 +240,11 @@ public class LitemallGoodsService {
goodsMapper.insertSelective(goods);
}
/**
* 获取所有物品总数,包括在售的和下架的,但是不包括已删除的商品
*
* @return
*/
public int count() {
LitemallGoodsExample example = new LitemallGoodsExample();
example.or().andDeletedEqualTo(false);
......@@ -245,9 +256,6 @@ public class LitemallGoodsService {
LitemallGoodsExample.Criteria criteria1 = example.or();
LitemallGoodsExample.Criteria criteria2 = example.or();
criteria1.andDeletedEqualTo(false);
criteria2.andDeletedEqualTo(false);
if (!StringUtils.isEmpty(brandId)) {
criteria1.andBrandIdEqualTo(brandId);
criteria2.andBrandIdEqualTo(brandId);
......@@ -264,6 +272,10 @@ public class LitemallGoodsService {
criteria1.andKeywordsLike("%" + keywords + "%");
criteria2.andNameLike("%" + keywords + "%");
}
criteria1.andIsOnSaleEqualTo(true);
criteria2.andIsOnSaleEqualTo(true);
criteria1.andDeletedEqualTo(false);
criteria2.andDeletedEqualTo(false);
List<LitemallGoods> goodsList = goodsMapper.selectByExampleSelective(example, Column.categoryId);
List<Integer> cats = new ArrayList<Integer>();
......@@ -275,7 +287,7 @@ public class LitemallGoodsService {
public boolean checkExistByName(String name) {
LitemallGoodsExample example = new LitemallGoodsExample();
example.or().andNameEqualTo(name).andDeletedEqualTo(false);
example.or().andNameEqualTo(name).andIsOnSaleEqualTo(true).andDeletedEqualTo(false);
return goodsMapper.countByExample(example) != 0;
}
}
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