Browse Source

增加一次性获取全部分类数据接口

Menethil 7 years ago
parent
commit
ba507599d2

+ 1 - 1
litemall-admin/config/dep.env.js

@@ -1,5 +1,5 @@
 module.exports = {
 module.exports = {
 	NODE_ENV: '"production"',
 	NODE_ENV: '"production"',
 	ENV_CONFIG: '"dep"',
 	ENV_CONFIG: '"dep"',
-    BASE_API: '"http://122.152.206.172:8083/admin"'
+    BASE_API: '"https://www.menethil.com.cn/admin"'
 }
 }

+ 65 - 31
litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxCatalogController.java

@@ -1,8 +1,8 @@
 package org.linlinjava.litemall.wx.web;
 package org.linlinjava.litemall.wx.web;
 
 
+import org.linlinjava.litemall.core.util.ResponseUtil;
 import org.linlinjava.litemall.db.domain.LitemallCategory;
 import org.linlinjava.litemall.db.domain.LitemallCategory;
 import org.linlinjava.litemall.db.service.LitemallCategoryService;
 import org.linlinjava.litemall.db.service.LitemallCategoryService;
-import org.linlinjava.litemall.core.util.ResponseUtil;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
@@ -22,24 +22,24 @@ public class WxCatalogController {
     /**
     /**
      * 分类栏目
      * 分类栏目
      *
      *
-     * @param id 分类类目ID
-     *    如果分类类目ID是空,则选择第一个分类类目。
-     *    需要注意,这里分类类目是一级类目
+     * @param id   分类类目ID
+     *             如果分类类目ID是空,则选择第一个分类类目。
+     *             需要注意,这里分类类目是一级类目
      * @param page 分页页数
      * @param page 分页页数
      * @param size 分页大小
      * @param size 分页大小
      * @return 分类栏目
      * @return 分类栏目
-     *   成功则
-     *  {
-     *      errno: 0,
-     *      errmsg: '成功',
-     *      data:
-     *          {
-     *              categoryList: xxx,
-     *              currentCategory: xxx,
-     *              currentSubCategory: xxx
-     *          }
-     *  }
-     *   失败则 { errno: XXX, errmsg: XXX }
+     * 成功则
+     * {
+     * errno: 0,
+     * errmsg: '成功',
+     * data:
+     * {
+     * categoryList: xxx,
+     * currentCategory: xxx,
+     * currentSubCategory: xxx
+     * }
+     * }
+     * 失败则 { errno: XXX, errmsg: XXX }
      */
      */
     @GetMapping("index")
     @GetMapping("index")
     public Object index(Integer id,
     public Object index(Integer id,
@@ -51,10 +51,9 @@ public class WxCatalogController {
 
 
         // 当前一级分类目录
         // 当前一级分类目录
         LitemallCategory currentCategory = null;
         LitemallCategory currentCategory = null;
-        if(id != null){
+        if (id != null) {
             currentCategory = categoryService.findById(id);
             currentCategory = categoryService.findById(id);
-        }
-        else{
+        } else {
             currentCategory = l1CatList.get(0);
             currentCategory = l1CatList.get(0);
         }
         }
 
 
@@ -72,25 +71,60 @@ public class WxCatalogController {
     }
     }
 
 
     /**
     /**
+     * 一次性获取全部分类数据
+     *
+     * @return
+     */
+    @GetMapping("all")
+    public Object queryAll() {
+        // 所有一级分类目录
+        List<LitemallCategory> l1CatList = categoryService.queryL1();
+
+        //所有子分类列表
+        Map<Integer, List<LitemallCategory>> allList = new HashMap<>();
+        List<LitemallCategory> sub;
+        for (LitemallCategory category : l1CatList) {
+            sub = categoryService.queryByPid(category.getId());
+            allList.put(category.getId(), sub);
+        }
+
+        // 当前一级分类目录
+        LitemallCategory currentCategory = l1CatList.get(0);
+
+        // 当前一级分类目录对应的二级分类目录
+        List<LitemallCategory> currentSubCategory = null;
+        if (null != currentCategory) {
+            currentSubCategory = categoryService.queryByPid(currentCategory.getId());
+        }
+
+        Map<String, Object> data = new HashMap();
+        data.put("categoryList", l1CatList);
+        data.put("allList", allList);
+        data.put("currentCategory", currentCategory);
+        data.put("currentSubCategory", currentSubCategory);
+        return ResponseUtil.ok(data);
+    }
+
+    /**
      * 当前分类栏目
      * 当前分类栏目
      *
      *
      * @param id 分类类目ID
      * @param id 分类类目ID
      * @return 当前分类栏目
      * @return 当前分类栏目
-     *   成功则
-     *  {
-     *      errno: 0,
-     *      errmsg: '成功',
-     *      data:
-     *          {
-     *              currentCategory: xxx,
-     *              currentSubCategory: xxx
-     *          }
-     *  }
-     *   失败则 { errno: XXX, errmsg: XXX }
+     * 成功则
+     * {
+     * errno: 0,
+     * errmsg: '成功',
+     * data:
+     * {
+     * currentCategory: xxx,
+     * currentSubCategory: xxx
+     * }
+     * }
+     * 失败则 { errno: XXX, errmsg: XXX }
      */
      */
     @GetMapping("current")
     @GetMapping("current")
     public Object current(Integer id) {
     public Object current(Integer id) {
-        if(id == null){
+        if (id == null) {
             return ResponseUtil.badArgument();
             return ResponseUtil.badArgument();
         }
         }