|
@@ -2,8 +2,10 @@ package com.qs.mp.web.controller.api.admin;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
import com.qs.mp.admin.domain.Goods;
|
|
|
import com.qs.mp.admin.domain.GoodsCategory;
|
|
|
+import com.qs.mp.admin.domain.vo.GoodsCategoryTreeVO;
|
|
|
import com.qs.mp.admin.service.IGoodsCategoryService;
|
|
|
import com.qs.mp.admin.service.IGoodsService;
|
|
|
import com.qs.mp.common.annotation.Log;
|
|
@@ -14,8 +16,15 @@ import com.qs.mp.common.enums.ErrorCodeEnum;
|
|
|
import com.qs.mp.web.controller.common.BaseApiController;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.Arrays;
|
|
|
import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+import io.swagger.annotations.ApiResponse;
|
|
|
+import io.swagger.annotations.ApiResponses;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
import org.springframework.stereotype.Component;
|
|
@@ -30,7 +39,7 @@ import org.springframework.web.bind.annotation.RestController;
|
|
|
* @create 2022-04-07 23:45:48
|
|
|
* @describe 商品分类管理前端控制器
|
|
|
*/
|
|
|
-@Api("商品分类管理API")
|
|
|
+@Api(tags = "商品分类管理API")
|
|
|
@RestController
|
|
|
@RequestMapping("/api/v1/mp/admin/goods/category/*")
|
|
|
@Component
|
|
@@ -42,6 +51,36 @@ public class GoodsCategoryMgrController extends BaseApiController {
|
|
|
@Autowired
|
|
|
private IGoodsService goodsService;
|
|
|
|
|
|
+ @PostMapping("/listTree")
|
|
|
+ @PreAuthorize("@ss.hasPermi('business:category:list')")
|
|
|
+ @ApiOperation("分类列表树状接口")
|
|
|
+ public TableDataInfo listTree() {
|
|
|
+ startPage();
|
|
|
+
|
|
|
+ // 获取父分类
|
|
|
+ List<GoodsCategory> categoryList = goodsCategoryService.list(
|
|
|
+ new LambdaQueryWrapper<GoodsCategory>()
|
|
|
+ .eq(GoodsCategory::getParentId, 0)
|
|
|
+ .orderByDesc(GoodsCategory::getSort));
|
|
|
+ if (CollectionUtils.isEmpty(categoryList)) {
|
|
|
+ return getErrorDataTable("分类信息不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ List<GoodsCategoryTreeVO> treeList = categoryList.stream().map(goodsCategory -> {
|
|
|
+ GoodsCategoryTreeVO goodsCategoryTreeVO = new GoodsCategoryTreeVO();
|
|
|
+ BeanUtils.copyProperties(goodsCategory, goodsCategoryTreeVO);
|
|
|
+ // 获取子分类
|
|
|
+ List<GoodsCategory> list = goodsCategoryService.list(
|
|
|
+ new LambdaQueryWrapper<GoodsCategory>()
|
|
|
+ .eq(GoodsCategory::getParentId, goodsCategory.getCategoryId())
|
|
|
+ .orderByDesc(GoodsCategory::getSort));
|
|
|
+ goodsCategoryTreeVO.setGoodsCategoryList(list);
|
|
|
+ return goodsCategoryTreeVO;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+
|
|
|
+ return getDataTable(treeList);
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 查询商品分类列表, 支持翻页
|
|
@@ -50,6 +89,10 @@ public class GoodsCategoryMgrController extends BaseApiController {
|
|
|
*/
|
|
|
@PostMapping("/list")
|
|
|
@PreAuthorize("@ss.hasPermi('business:category:list')")
|
|
|
+ @ApiOperation("分类列表接口")
|
|
|
+ @ApiResponses(
|
|
|
+ @ApiResponse(code = 200,message = "查询成功",response = GoodsCategory.class)
|
|
|
+ )
|
|
|
public TableDataInfo list(@RequestBody JSONObject param) {
|
|
|
startPage();
|
|
|
List<GoodsCategory> categoryList = goodsCategoryService.list(
|
|
@@ -105,7 +148,6 @@ public class GoodsCategoryMgrController extends BaseApiController {
|
|
|
return AjaxResult.error("分类名称已存在!");
|
|
|
}
|
|
|
// 2.保存
|
|
|
- goodsCategory.setParentId(0L);
|
|
|
goodsCategoryService.save(goodsCategory);
|
|
|
return AjaxResult.success("保存成功");
|
|
|
}
|