From cd3ea7403e8f327647eec5551e2501ffdf3d55f9 Mon Sep 17 00:00:00 2001 From: Menethil Date: Wed, 15 Aug 2018 02:05:30 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=B1=BB=E5=88=AB=E5=95=86?= =?UTF-8?q?=E5=93=81=E6=9F=A5=E8=AF=A2BUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../db/service/LitemallGoodsService.java | 95 ++++++++++++------- 1 file changed, 61 insertions(+), 34 deletions(-) diff --git a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallGoodsService.java b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallGoodsService.java index 9e9f87c5..b774159e 100644 --- a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallGoodsService.java +++ b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallGoodsService.java @@ -18,49 +18,75 @@ public class LitemallGoodsService { @Resource private LitemallGoodsMapper goodsMapper; + Column[] columns = new Column[]{Column.id, Column.name, Column.picUrl, Column.counterPrice, Column.retailPrice}; + + /** + * 获取热卖商品 + * + * @param offset + * @param limit + * @return + */ public List queryByHot(int offset, int limit) { LitemallGoodsExample example = new LitemallGoodsExample(); example.or().andIsHotEqualTo(true).andDeletedEqualTo(false); example.setOrderByClause("add_time desc"); PageHelper.startPage(offset, limit); - return goodsMapper.selectByExample(example); + + return goodsMapper.selectByExampleSelective(example, columns); } + /** + * 获取新品上市 + * + * @param offset + * @param limit + * @return + */ public List queryByNew(int offset, int limit) { LitemallGoodsExample example = new LitemallGoodsExample(); example.or().andIsNewEqualTo(true).andDeletedEqualTo(false); example.setOrderByClause("add_time desc"); PageHelper.startPage(offset, limit); - return goodsMapper.selectByExample(example); + + return goodsMapper.selectByExampleSelective(example, columns); } + /** + * 获取分类下的商品 + * + * @param catList + * @param offset + * @param limit + * @return + */ public List queryByCategory(List catList, int offset, int limit) { LitemallGoodsExample example = new LitemallGoodsExample(); example.or().andCategoryIdIn(catList).andDeletedEqualTo(false); example.setOrderByClause("add_time desc"); PageHelper.startPage(offset, limit); - return goodsMapper.selectByExample(example); + + return goodsMapper.selectByExampleSelective(example, columns); } - public int countByCategory(List catList, int offset, int limit) { - LitemallGoodsExample example = new LitemallGoodsExample(); - example.or().andCategoryIdIn(catList).andDeletedEqualTo(false); - return (int) goodsMapper.countByExample(example); - } + /** + * 获取分类下的商品 + * + * @param catId + * @param offset + * @param limit + * @return + */ public List queryByCategory(Integer catId, int offset, int limit) { LitemallGoodsExample example = new LitemallGoodsExample(); example.or().andCategoryIdEqualTo(catId).andDeletedEqualTo(false); example.setOrderByClause("add_time desc"); PageHelper.startPage(offset, limit); - return goodsMapper.selectByExample(example); + + return goodsMapper.selectByExampleSelective(example, columns); } - public int countByCategory(Integer catId, Integer page, Integer size) { - LitemallGoodsExample example = new LitemallGoodsExample(); - example.or().andCategoryIdEqualTo(catId).andDeletedEqualTo(false); - return (int) goodsMapper.countByExample(example); - } public List querySelective(Integer catId, Integer brandId, String keyword, Boolean isHot, Boolean isNew, Integer offset, Integer limit, String sort, String order) { LitemallGoodsExample example = new LitemallGoodsExample(); @@ -98,7 +124,6 @@ public class LitemallGoodsService { PageHelper.startPage(offset, limit); } - Column[] columns = new Column[]{Column.id, Column.name, Column.picUrl, Column.counterPrice, Column.retailPrice}; return goodsMapper.selectByExampleSelective(example, columns); } @@ -131,25 +156,6 @@ public class LitemallGoodsService { 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 queryByIds(List 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 querySelective(String goodsSn, String name, Integer page, Integer size, String sort, String order) { LitemallGoodsExample example = new LitemallGoodsExample(); LitemallGoodsExample.Criteria criteria = example.createCriteria(); @@ -181,6 +187,24 @@ public class LitemallGoodsService { 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) { goodsMapper.updateByPrimaryKeySelective(goods); } @@ -204,6 +228,9 @@ 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);