feat(商城): 添加商城分类接口

master
wayn 4 years ago
parent 1582986de1
commit 3d8c558d1e

@ -0,0 +1,22 @@
package com.wayn.common.core.domain.vo;
import lombok.Data;
/**
*
*/
@Data
public class VanTreeSelectVo {
private Long id;
private String text;
private String icon;
public VanTreeSelectVo() {
}
public VanTreeSelectVo(Long id, String text, String icon) {
this.id = id;
this.text = text;
this.icon = icon;
}
}

@ -2,6 +2,7 @@ package com.wayn.common.core.service.shop;
import com.baomidou.mybatisplus.extension.service.IService;
import com.wayn.common.core.domain.shop.Category;
import com.wayn.common.core.domain.vo.VanTreeSelectVo;
import java.util.List;
@ -21,4 +22,8 @@ public interface ICategoryService extends IService<Category> {
* @return
*/
List<Category> list(Category category);
List<VanTreeSelectVo> selectL1Category();
List<VanTreeSelectVo> selectCategoryByPid(Long id);
}

@ -1,12 +1,15 @@
package com.wayn.common.core.service.shop.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wayn.common.core.domain.shop.Category;
import com.wayn.common.core.domain.vo.VanTreeSelectVo;
import com.wayn.common.core.mapper.shop.CategoryMapper;
import com.wayn.common.core.service.shop.ICategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
/**
@ -28,4 +31,31 @@ public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category> i
public List<Category> list(Category category) {
return categoryMapper.selectCategoryList(category);
}
@Override
public List<VanTreeSelectVo> selectL1Category() {
List<Category> categoryList = list(new QueryWrapper<Category>().eq("level", "L1").orderByAsc("sort_order"));
List<VanTreeSelectVo> vanTreeSelectVos = new ArrayList<>();
categoryList.forEach(category -> {
VanTreeSelectVo vanTreeSelectVo = new VanTreeSelectVo();
vanTreeSelectVo.setId(category.getId());
vanTreeSelectVo.setText(category.getName());
vanTreeSelectVos.add(vanTreeSelectVo);
});
return vanTreeSelectVos;
}
@Override
public List<VanTreeSelectVo> selectCategoryByPid(Long id) {
List<Category> categoryList = list(new QueryWrapper<Category>().eq("pid", id).orderByAsc("sort_order"));
List<VanTreeSelectVo> vanTreeSelectVos = new ArrayList<>();
categoryList.forEach(category -> {
VanTreeSelectVo vanTreeSelectVo = new VanTreeSelectVo();
vanTreeSelectVo.setId(category.getId());
vanTreeSelectVo.setIcon(category.getIconUrl());
vanTreeSelectVo.setText(category.getName());
vanTreeSelectVos.add(vanTreeSelectVo);
});
return vanTreeSelectVos;
}
}

@ -0,0 +1,41 @@
package com.wayn.mobile.api.controller;
import com.wayn.common.core.domain.shop.Category;
import com.wayn.common.core.domain.vo.VanTreeSelectVo;
import com.wayn.common.core.service.shop.ICategoryService;
import com.wayn.common.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.Objects;
@RestController
@RequestMapping("category")
public class CategoryController {
@Autowired
private ICategoryService iCategoryService;
@GetMapping("index")
public R index(@RequestParam(required = false) Long id) {
R success = R.success();
List<VanTreeSelectVo> categoryList = iCategoryService.selectL1Category();
Category currentCategory;
List<VanTreeSelectVo> subCategoryList;
if (Objects.isNull(id) && categoryList.size() > 0) {
currentCategory = iCategoryService.getById(categoryList.get(0).getId());
subCategoryList = iCategoryService.selectCategoryByPid(currentCategory.getId());
} else {
currentCategory = iCategoryService.getById(id);
subCategoryList = iCategoryService.selectCategoryByPid(id);
}
success.add("categoryList", categoryList);
success.add("currentCategory", currentCategory);
success.add("subCategoryList", subCategoryList);
return success;
}
}

@ -19,7 +19,7 @@ public class HomeController extends BaseController {
private HomeService homeService;
@PostMapping("index")
public R getHomeIndex() {
public R index() {
return homeService.getHomeIndexData();
}

@ -1,13 +0,0 @@
package com.wayn.mobile.api.controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class TestController {
@GetMapping("test")
public String test() {
return "hello world!";
}
}
Loading…
Cancel
Save