ソースを参照

优化首页Json数据

Menethil 7 年 前
コミット
149c7d2096

+ 15 - 6
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<LitemallBrand> query(int offset, int limit) {
         LitemallBrandExample example = new LitemallBrandExample();
@@ -22,10 +24,17 @@ public class LitemallBrandService {
         return brandMapper.selectByExample(example);
     }
 
+    public List<LitemallBrand> 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) {

+ 19 - 2
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);
+    }
+
 
     /**
      * 获取所有在售物品总数

+ 11 - 9
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<LitemallTopic> 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<LitemallTopic> 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<LitemallTopic> 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) {

+ 24 - 24
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<LitemallBrand> brandList = brandService.query(page, size);
+        List<LitemallBrand> 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<String, Object> data = new HashMap<String, Object>();
-        data.put("brand",entity);
+        data.put("brand", entity);
         return ResponseUtil.ok(data);
     }
 }

+ 11 - 0
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<UserVo> joiners = new ArrayList<>();
         joiners.add(creator);

+ 2 - 2
litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxHomeController.java

@@ -89,7 +89,7 @@ public class WxHomeController {
         List<LitemallGoods> hotGoods = goodsService.queryByHot(0, SystemConfig.getHotLimit());
         data.put("hotGoodsList", hotGoods);
 
-        List<LitemallBrand> brandList = brandService.query(0, SystemConfig.getBrandLimit());
+        List<LitemallBrand> brandList = brandService.queryVO(0, SystemConfig.getBrandLimit());
         data.put("brandList", brandList);
 
         List<LitemallTopic> topicList = topicService.queryList(0, SystemConfig.getTopicLimit());
@@ -100,7 +100,7 @@ public class WxHomeController {
         List<LitemallGoods> grouponGoods = new ArrayList<>();
         List<Map<String, Object>> grouponList = new ArrayList<>();
         for (LitemallGrouponRules rule : grouponRules) {
-            LitemallGoods goods = goodsService.findById(rule.getGoodsId());
+            LitemallGoods goods = goodsService.findByIdVO(rule.getGoodsId());
             if (goods == null)
                 continue;