From 149c7d2096fe0a99ea83d32675d29b0b49dc2067 Mon Sep 17 00:00:00 2001 From: Menethil Date: Wed, 15 Aug 2018 03:09:46 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=A6=96=E9=A1=B5Json?= =?UTF-8?q?=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../db/service/LitemallBrandService.java | 21 +++++--- .../db/service/LitemallGoodsService.java | 21 +++++++- .../db/service/LitemallTopicService.java | 20 ++++---- .../litemall/wx/web/WxBrandController.java | 48 +++++++++---------- .../litemall/wx/web/WxGrouponController.java | 11 +++++ .../litemall/wx/web/WxHomeController.java | 4 +- 6 files changed, 82 insertions(+), 43 deletions(-) diff --git a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallBrandService.java b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallBrandService.java index 7d18ba2b..67eab9ff 100644 --- a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallBrandService.java +++ b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallBrandService.java @@ -3,6 +3,7 @@ package org.linlinjava.litemall.db.service; import com.github.pagehelper.PageHelper; import org.linlinjava.litemall.db.domain.LitemallBrandExample; import org.linlinjava.litemall.db.dao.LitemallBrandMapper; +import org.linlinjava.litemall.db.domain.LitemallBrand.Column; import org.linlinjava.litemall.db.domain.LitemallBrand; import org.springframework.stereotype.Service; import org.springframework.util.StringUtils; @@ -14,6 +15,7 @@ import java.util.List; public class LitemallBrandService { @Resource private LitemallBrandMapper brandMapper; + private Column[] columns = new Column[]{Column.id, Column.name, Column.desc, Column.picUrl, Column.floorPrice}; public List query(int offset, int limit) { LitemallBrandExample example = new LitemallBrandExample(); @@ -22,10 +24,17 @@ public class LitemallBrandService { return brandMapper.selectByExample(example); } + public List queryVO(int offset, int limit) { + LitemallBrandExample example = new LitemallBrandExample(); + example.or().andDeletedEqualTo(false); + PageHelper.startPage(offset, limit); + return brandMapper.selectByExampleSelective(example, columns); + } + public int queryTotalCount() { LitemallBrandExample example = new LitemallBrandExample(); example.or().andDeletedEqualTo(false); - return (int)brandMapper.countByExample(example); + return (int) brandMapper.countByExample(example); } public LitemallBrand findById(Integer id) { @@ -36,10 +45,10 @@ public class LitemallBrandService { LitemallBrandExample example = new LitemallBrandExample(); LitemallBrandExample.Criteria criteria = example.createCriteria(); - if(!StringUtils.isEmpty(id)){ + if (!StringUtils.isEmpty(id)) { criteria.andIdEqualTo(Integer.valueOf(id)); } - if(!StringUtils.isEmpty(name)){ + if (!StringUtils.isEmpty(name)) { criteria.andNameLike("%" + name + "%"); } criteria.andDeletedEqualTo(false); @@ -56,15 +65,15 @@ public class LitemallBrandService { LitemallBrandExample example = new LitemallBrandExample(); LitemallBrandExample.Criteria criteria = example.createCriteria(); - if(!StringUtils.isEmpty(id)){ + if (!StringUtils.isEmpty(id)) { criteria.andIdEqualTo(Integer.valueOf(id)); } - if(!StringUtils.isEmpty(name)){ + if (!StringUtils.isEmpty(name)) { criteria.andNameLike("%" + name + "%"); } criteria.andDeletedEqualTo(false); - return (int)brandMapper.countByExample(example); + return (int) brandMapper.countByExample(example); } public void updateById(LitemallBrand brand) { 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 b774159e..7f080b8e 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 @@ -11,14 +11,13 @@ import org.springframework.util.StringUtils; import javax.annotation.Resource; import java.util.ArrayList; import java.util.List; -import java.util.Random; @Service public class LitemallGoodsService { @Resource private LitemallGoodsMapper goodsMapper; - Column[] columns = new Column[]{Column.id, Column.name, Column.picUrl, Column.counterPrice, Column.retailPrice}; + Column[] columns = new Column[]{Column.id, Column.name, Column.brief, Column.picUrl, Column.counterPrice, Column.retailPrice}; /** * 获取热卖商品 @@ -187,12 +186,30 @@ public class LitemallGoodsService { return (int) goodsMapper.countByExample(example); } + /** + * 获取某个商品信息,包含完整信息 + * + * @param id + * @return + */ public LitemallGoods findById(Integer id) { LitemallGoodsExample example = new LitemallGoodsExample(); example.or().andIdEqualTo(id).andDeletedEqualTo(false); return goodsMapper.selectOneByExampleWithBLOBs(example); } + /** + * 获取某个商品信息,仅展示相关内容 + * + * @param id + * @return + */ + public LitemallGoods findByIdVO(Integer id) { + LitemallGoodsExample example = new LitemallGoodsExample(); + example.or().andIdEqualTo(id).andDeletedEqualTo(false); + return goodsMapper.selectOneByExampleSelective(example, columns); + } + /** * 获取所有在售物品总数 diff --git a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallTopicService.java b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallTopicService.java index c296ff5c..b5b03e58 100644 --- a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallTopicService.java +++ b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallTopicService.java @@ -3,6 +3,7 @@ package org.linlinjava.litemall.db.service; import com.github.pagehelper.PageHelper; import org.linlinjava.litemall.db.dao.LitemallTopicMapper; import org.linlinjava.litemall.db.domain.LitemallTopic; +import org.linlinjava.litemall.db.domain.LitemallTopic.Column; import org.linlinjava.litemall.db.domain.LitemallTopicExample; import org.springframework.stereotype.Service; import org.springframework.util.StringUtils; @@ -14,18 +15,19 @@ import java.util.List; public class LitemallTopicService { @Resource private LitemallTopicMapper topicMapper; + private Column[] columns = new Column[]{Column.id, Column.title, Column.subtitle, Column.picUrl, Column.readCount}; public List queryList(int offset, int limit) { LitemallTopicExample example = new LitemallTopicExample(); example.or().andDeletedEqualTo(false); PageHelper.startPage(offset, limit); - return topicMapper.selectByExampleWithBLOBs(example); + return topicMapper.selectByExampleSelective(example, columns); } public int queryTotal() { LitemallTopicExample example = new LitemallTopicExample(); example.or().andDeletedEqualTo(false); - return (int)topicMapper.countByExample(example); + return (int) topicMapper.countByExample(example); } public LitemallTopic findById(Integer id) { @@ -38,7 +40,7 @@ public class LitemallTopicService { LitemallTopicExample example = new LitemallTopicExample(); example.or().andIdEqualTo(id).andDeletedEqualTo(false); List topics = topicMapper.selectByExample(example); - if(topics.size() == 0){ + if (topics.size() == 0) { return queryList(offset, limit); } LitemallTopic topic = topics.get(0); @@ -47,7 +49,7 @@ public class LitemallTopicService { example.or().andIdNotEqualTo(topic.getId()).andDeletedEqualTo(false); PageHelper.startPage(offset, limit); List relateds = topicMapper.selectByExampleWithBLOBs(example); - if(relateds.size() != 0){ + if (relateds.size() != 0) { return relateds; } @@ -58,10 +60,10 @@ public class LitemallTopicService { LitemallTopicExample example = new LitemallTopicExample(); LitemallTopicExample.Criteria criteria = example.createCriteria(); - if(!StringUtils.isEmpty(title)){ + if (!StringUtils.isEmpty(title)) { criteria.andTitleLike("%" + title + "%"); } - if(!StringUtils.isEmpty(subtitle)){ + if (!StringUtils.isEmpty(subtitle)) { criteria.andSubtitleLike("%" + subtitle + "%"); } criteria.andDeletedEqualTo(false); @@ -78,15 +80,15 @@ public class LitemallTopicService { LitemallTopicExample example = new LitemallTopicExample(); LitemallTopicExample.Criteria criteria = example.createCriteria(); - if(!StringUtils.isEmpty(title)){ + if (!StringUtils.isEmpty(title)) { criteria.andTitleLike("%" + title + "%"); } - if(!StringUtils.isEmpty(subtitle)){ + if (!StringUtils.isEmpty(subtitle)) { criteria.andSubtitleLike("%" + subtitle + "%"); } criteria.andDeletedEqualTo(false); - return (int)topicMapper.countByExample(example); + return (int) topicMapper.countByExample(example); } public void updateById(LitemallTopic topic) { diff --git a/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxBrandController.java b/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxBrandController.java index e0bb7c6a..9abc03f9 100644 --- a/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxBrandController.java +++ b/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxBrandController.java @@ -32,23 +32,23 @@ public class WxBrandController { * @param page 分页页数 * @param size 分页大小 * @return 品牌列表 - * 成功则 - * { - * errno: 0, - * errmsg: '成功', - * data: - * { - * brandList: xxx, - * totalPages: xxx - * } - * } - * 失败则 { errno: XXX, errmsg: XXX } + * 成功则 + * { + * errno: 0, + * errmsg: '成功', + * data: + * { + * brandList: xxx, + * totalPages: xxx + * } + * } + * 失败则 { errno: XXX, errmsg: XXX } */ @GetMapping("list") public Object list(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer size) { - List brandList = brandService.query(page, size); + List brandList = brandService.queryVO(page, size); int total = brandService.queryTotalCount(); int totalPages = (int) Math.ceil((double) total / size); @@ -63,26 +63,26 @@ public class WxBrandController { * * @param id 品牌ID * @return 品牌详情 - * 成功则 - * { - * errno: 0, - * errmsg: '成功', - * data: - * { - * brand: xxx - * } - * } - * 失败则 { errno: XXX, errmsg: XXX } + * 成功则 + * { + * errno: 0, + * errmsg: '成功', + * data: + * { + * brand: xxx + * } + * } + * 失败则 { errno: XXX, errmsg: XXX } */ @GetMapping("detail") public Object detail(@NotNull Integer id) { LitemallBrand entity = brandService.findById(id); - if(entity == null){ + if (entity == null) { return ResponseUtil.badArgumentValue(); } Map data = new HashMap(); - data.put("brand",entity); + data.put("brand", entity); return ResponseUtil.ok(data); } } \ No newline at end of file diff --git a/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxGrouponController.java b/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxGrouponController.java index ad2f8c85..46fa4c32 100644 --- a/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxGrouponController.java +++ b/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxGrouponController.java @@ -1,5 +1,7 @@ package org.linlinjava.litemall.wx.web; +import org.linlinjava.litemall.core.express.ExpressService; +import org.linlinjava.litemall.core.express.dao.ExpressInfo; import org.linlinjava.litemall.core.util.ResponseUtil; import org.linlinjava.litemall.db.domain.*; import org.linlinjava.litemall.db.service.*; @@ -36,6 +38,8 @@ public class WxGrouponController { private LitemallOrderGoodsService orderGoodsService; @Autowired private LitemallUserService userService; + @Autowired + private ExpressService expressService; @GetMapping("detail") public Object detail(@LoginUser Integer userId, @NotNull Integer grouponId) { @@ -95,6 +99,13 @@ public class WxGrouponController { result.put("orderInfo", orderVo); result.put("orderGoods", orderGoodsVoList); + // 订单状态为已发货且物流信息不为空 + //"YTO", "800669400640887922" + if (order.getOrderStatus().equals(OrderUtil.STATUS_SHIP)) { + ExpressInfo ei = expressService.getExpressInfo(order.getShipChannel(), order.getShipSn()); + result.put("expressInfo", ei); + } + UserVo creator = userService.findUserVoById(groupon.getCreatorUserId()); List joiners = new ArrayList<>(); joiners.add(creator); diff --git a/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxHomeController.java b/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxHomeController.java index 30577e48..583bbdfb 100644 --- a/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxHomeController.java +++ b/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxHomeController.java @@ -89,7 +89,7 @@ public class WxHomeController { List hotGoods = goodsService.queryByHot(0, SystemConfig.getHotLimit()); data.put("hotGoodsList", hotGoods); - List brandList = brandService.query(0, SystemConfig.getBrandLimit()); + List brandList = brandService.queryVO(0, SystemConfig.getBrandLimit()); data.put("brandList", brandList); List topicList = topicService.queryList(0, SystemConfig.getTopicLimit()); @@ -100,7 +100,7 @@ public class WxHomeController { List grouponGoods = new ArrayList<>(); List> grouponList = new ArrayList<>(); for (LitemallGrouponRules rule : grouponRules) { - LitemallGoods goods = goodsService.findById(rule.getGoodsId()); + LitemallGoods goods = goodsService.findByIdVO(rule.getGoodsId()); if (goods == null) continue;