Commit ba507599 authored by Menethil's avatar Menethil
Browse files

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

parent e73f061a
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"'
} }
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 { ...@@ -22,24 +22,24 @@ public class WxCatalogController {
/** /**
* 分类栏目 * 分类栏目
* *
* @param id 分类类目ID * @param id 分类类目ID
* 如果分类类目ID是空,则选择第一个分类类目。 * 如果分类类目ID是空,则选择第一个分类类目。
* 需要注意,这里分类类目是一级类目 * 需要注意,这里分类类目是一级类目
* @param page 分页页数 * @param page 分页页数
* @param size 分页大小 * @param size 分页大小
* @return 分类栏目 * @return 分类栏目
* 成功则 * 成功则
* { * {
* errno: 0, * errno: 0,
* errmsg: '成功', * errmsg: '成功',
* data: * data:
* { * {
* categoryList: xxx, * categoryList: xxx,
* currentCategory: xxx, * currentCategory: xxx,
* currentSubCategory: xxx * currentSubCategory: xxx
* } * }
* } * }
* 失败则 { errno: XXX, errmsg: 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 { ...@@ -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);
} }
...@@ -71,26 +70,61 @@ public class WxCatalogController { ...@@ -71,26 +70,61 @@ public class WxCatalogController {
return ResponseUtil.ok(data); return ResponseUtil.ok(data);
} }
/**
* 一次性获取全部分类数据
*
* @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, * errno: 0,
* errmsg: '成功', * errmsg: '成功',
* data: * data:
* { * {
* currentCategory: xxx, * currentCategory: xxx,
* currentSubCategory: xxx * currentSubCategory: xxx
* } * }
* } * }
* 失败则 { errno: XXX, errmsg: 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();
} }
......
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