Explorar o código

平台商品类别管理

wwh hai 2 semanas
pai
achega
86833a5a24

+ 4 - 2
baqing-shop/src/main/java/com/ruoyi/web/modules/category/controller/PlatformCategoryController.java

@@ -17,6 +17,7 @@ import org.springframework.web.bind.annotation.RestController;
17 17
 import com.ruoyi.common.annotation.Log;
18 18
 import com.ruoyi.common.core.controller.BaseController;
19 19
 import com.ruoyi.common.core.domain.AjaxResult;
20
+import com.ruoyi.common.core.page.TableDataInfo;
20 21
 import com.ruoyi.common.enums.BusinessType;
21 22
 import com.ruoyi.web.modules.category.domain.BizGoodsCategory;
22 23
 import com.ruoyi.web.modules.category.exception.CategoryBatchDeleteException;
@@ -34,9 +35,10 @@ public class PlatformCategoryController extends BaseController
34 35
 
35 36
     @PreAuthorize("@ss.hasPermi('agri:category:list')")
36 37
     @GetMapping("/list")
37
-    public AjaxResult list(@RequestParam(value = "keyword", required = false) String keyword)
38
+    public TableDataInfo list(@RequestParam(value = "keyword", required = false) String keyword)
38 39
     {
39
-        return success(platformCategoryService.selectPlatformCategoryList(keyword));
40
+        startPage();
41
+        return getDataTable(platformCategoryService.selectPlatformCategoryRowList(keyword));
40 42
     }
41 43
 
42 44
     @PreAuthorize("@ss.hasPermi('agri:category:list')")

+ 11 - 2
baqing-shop/src/main/java/com/ruoyi/web/modules/category/controller/SellerCategoryController.java

@@ -17,6 +17,7 @@ import org.springframework.web.bind.annotation.RestController;
17 17
 import com.ruoyi.common.annotation.Log;
18 18
 import com.ruoyi.common.core.controller.BaseController;
19 19
 import com.ruoyi.common.core.domain.AjaxResult;
20
+import com.ruoyi.common.core.page.TableDataInfo;
20 21
 import com.ruoyi.common.enums.BusinessType;
21 22
 import com.ruoyi.web.modules.category.domain.BizGoodsCategory;
22 23
 import com.ruoyi.web.modules.category.exception.CategoryBatchDeleteException;
@@ -32,11 +33,19 @@ public class SellerCategoryController extends BaseController
32 33
     @Autowired
33 34
     private ICategoryService categoryService;
34 35
 
36
+    @PreAuthorize("@ss.hasPermi('agri:seller:category:list')")
37
+    @GetMapping("/scope")
38
+    public AjaxResult scope()
39
+    {
40
+        return success(categoryService.selectCategoryScope());
41
+    }
42
+
35 43
     @PreAuthorize("@ss.hasPermi('agri:seller:category:list')")
36 44
     @GetMapping("/list")
37
-    public AjaxResult list(@RequestParam(value = "keyword", required = false) String keyword)
45
+    public TableDataInfo list(@RequestParam(value = "keyword", required = false) String keyword)
38 46
     {
39
-        return success(categoryService.selectCategoryList(keyword));
47
+        startPage();
48
+        return getDataTable(categoryService.selectCategoryRowList(keyword));
40 49
     }
41 50
 
42 51
     @PreAuthorize("@ss.hasPermi('agri:seller:category:list')")

+ 5 - 2
baqing-shop/src/main/java/com/ruoyi/web/modules/category/service/ICategoryService.java

@@ -3,7 +3,8 @@ package com.ruoyi.web.modules.category.service;
3 3
 import java.util.List;
4 4
 import com.ruoyi.web.modules.category.domain.BizGoodsCategory;
5 5
 import com.ruoyi.web.modules.category.vo.CategoryLevel2OptionVO;
6
-import com.ruoyi.web.modules.category.vo.CategoryListVO;
6
+import com.ruoyi.web.modules.category.vo.CategoryRowVO;
7
+import com.ruoyi.web.modules.category.vo.CategoryScopeVO;
7 8
 import com.ruoyi.web.modules.category.vo.CategoryTreeResultVO;
8 9
 
9 10
 /**
@@ -11,7 +12,9 @@ import com.ruoyi.web.modules.category.vo.CategoryTreeResultVO;
11 12
  */
12 13
 public interface ICategoryService
13 14
 {
14
-    CategoryListVO selectCategoryList(String keyword);
15
+    CategoryScopeVO selectCategoryScope();
16
+
17
+    List<CategoryRowVO> selectCategoryRowList(String keyword);
15 18
 
16 19
     CategoryTreeResultVO selectCategoryTree(String keyword);
17 20
 

+ 3 - 2
baqing-shop/src/main/java/com/ruoyi/web/modules/category/service/IPlatformCategoryService.java

@@ -3,7 +3,8 @@ package com.ruoyi.web.modules.category.service;
3 3
 import java.util.List;
4 4
 import com.ruoyi.web.modules.category.domain.BizGoodsCategory;
5 5
 import com.ruoyi.web.modules.category.vo.CategoryLevel2OptionVO;
6
-import com.ruoyi.web.modules.category.vo.CategoryListVO;
6
+import com.ruoyi.web.modules.category.vo.CategoryRowVO;
7
+import com.ruoyi.web.modules.category.vo.CategoryScopeVO;
7 8
 import com.ruoyi.web.modules.category.vo.CategoryTreeResultVO;
8 9
 
9 10
 /**
@@ -11,7 +12,7 @@ import com.ruoyi.web.modules.category.vo.CategoryTreeResultVO;
11 12
  */
12 13
 public interface IPlatformCategoryService
13 14
 {
14
-    CategoryListVO selectPlatformCategoryList(String keyword);
15
+    List<CategoryRowVO> selectPlatformCategoryRowList(String keyword);
15 16
 
16 17
     CategoryTreeResultVO selectPlatformCategoryTree(String keyword);
17 18
 

+ 19 - 8
baqing-shop/src/main/java/com/ruoyi/web/modules/category/service/impl/CategoryServiceImpl.java

@@ -21,8 +21,8 @@ import com.ruoyi.web.modules.category.service.ICategoryService;
21 21
 import com.ruoyi.web.modules.category.service.IPlatformCategoryService;
22 22
 import com.ruoyi.web.modules.category.support.SellerShopContext;
23 23
 import com.ruoyi.web.modules.category.vo.CategoryLevel2OptionVO;
24
-import com.ruoyi.web.modules.category.vo.CategoryListVO;
25 24
 import com.ruoyi.web.modules.category.vo.CategoryRowVO;
25
+import com.ruoyi.web.modules.category.vo.CategoryScopeVO;
26 26
 import com.ruoyi.web.modules.category.vo.CategoryTreeResultVO;
27 27
 import com.ruoyi.web.modules.category.vo.CategoryTreeVO;
28 28
 
@@ -42,9 +42,15 @@ public class CategoryServiceImpl implements ICategoryService, IPlatformCategoryS
42 42
     private IShopFacade shopFacade;
43 43
 
44 44
     @Override
45
-    public CategoryListVO selectCategoryList(String keyword)
45
+    public CategoryScopeVO selectCategoryScope()
46 46
     {
47
-        return doSelectCategoryList(requireShopId(), keyword);
47
+        return doSelectScope(requireShopId());
48
+    }
49
+
50
+    @Override
51
+    public List<CategoryRowVO> selectCategoryRowList(String keyword)
52
+    {
53
+        return doSelectCategoryRowList(requireShopId(), keyword);
48 54
     }
49 55
 
50 56
     @Override
@@ -87,9 +93,9 @@ public class CategoryServiceImpl implements ICategoryService, IPlatformCategoryS
87 93
     }
88 94
 
89 95
     @Override
90
-    public CategoryListVO selectPlatformCategoryList(String keyword)
96
+    public List<CategoryRowVO> selectPlatformCategoryRowList(String keyword)
91 97
     {
92
-        return doSelectCategoryList(null, keyword);
98
+        return doSelectCategoryRowList(null, keyword);
93 99
     }
94 100
 
95 101
     @Override
@@ -131,16 +137,21 @@ public class CategoryServiceImpl implements ICategoryService, IPlatformCategoryS
131 137
         doDeleteCategoryByIds(null, categoryIds, operator);
132 138
     }
133 139
 
134
-    private CategoryListVO doSelectCategoryList(Long shopId, String keyword)
140
+    private CategoryScopeVO doSelectScope(Long shopId)
135 141
     {
136 142
         assertScopeMaintable(shopId);
137
-        CategoryListVO vo = new CategoryListVO();
143
+        CategoryScopeVO vo = new CategoryScopeVO();
138 144
         vo.setShopId(shopId);
139 145
         vo.setShopName(resolveScopeName(shopId));
140
-        vo.setRows(buildFlatRows(queryList(shopId, keyword)));
141 146
         return vo;
142 147
     }
143 148
 
149
+    private List<CategoryRowVO> doSelectCategoryRowList(Long shopId, String keyword)
150
+    {
151
+        assertScopeMaintable(shopId);
152
+        return buildFlatRows(queryList(shopId, keyword));
153
+    }
154
+
144 155
     private CategoryTreeResultVO doSelectCategoryTree(Long shopId, String keyword)
145 156
     {
146 157
         assertScopeMaintable(shopId);

+ 31 - 0
baqing-shop/src/main/java/com/ruoyi/web/modules/category/vo/CategoryScopeVO.java

@@ -0,0 +1,31 @@
1
+package com.ruoyi.web.modules.category.vo;
2
+
3
+/**
4
+ * 分类数据范围(店铺/平台)
5
+ */
6
+public class CategoryScopeVO
7
+{
8
+    private Long shopId;
9
+
10
+    private String shopName;
11
+
12
+    public Long getShopId()
13
+    {
14
+        return shopId;
15
+    }
16
+
17
+    public void setShopId(Long shopId)
18
+    {
19
+        this.shopId = shopId;
20
+    }
21
+
22
+    public String getShopName()
23
+    {
24
+        return shopName;
25
+    }
26
+
27
+    public void setShopName(String shopName)
28
+    {
29
+        this.shopName = shopName;
30
+    }
31
+}

+ 15 - 0
baqing-shop/src/test/java/com/ruoyi/web/modules/category/controller/PlatformCategoryControllerTest.java

@@ -25,6 +25,7 @@ import com.ruoyi.web.modules.category.constant.CategoryConstants;
25 25
 import com.ruoyi.web.modules.category.domain.BizGoodsCategory;
26 26
 import com.ruoyi.web.modules.category.exception.CategoryBatchDeleteException;
27 27
 import com.ruoyi.web.modules.category.service.IPlatformCategoryService;
28
+import com.ruoyi.web.modules.category.vo.CategoryRowVO;
28 29
 import com.ruoyi.web.modules.category.vo.CategoryTreeResultVO;
29 30
 import com.ruoyi.web.modules.category.vo.CategoryTreeVO;
30 31
 
@@ -52,6 +53,20 @@ class PlatformCategoryControllerTest
52 53
         lenient().doReturn("admin").when(controller).getUsername();
53 54
     }
54 55
 
56
+    @Test
57
+    void list_returns200() throws Exception
58
+    {
59
+        CategoryRowVO row = new CategoryRowVO();
60
+        row.setCategoryId(1L);
61
+        row.setCategoryName("肥料");
62
+        when(platformCategoryService.selectPlatformCategoryRowList(null)).thenReturn(Collections.singletonList(row));
63
+
64
+        mockMvc.perform(get("/agri/category/list"))
65
+                .andExpect(status().isOk())
66
+                .andExpect(jsonPath("$.code").value(200))
67
+                .andExpect(jsonPath("$.rows[0].categoryName").value("肥料"));
68
+    }
69
+
55 70
     @Test
56 71
     void tree_returns200() throws Exception
57 72
     {

+ 2 - 8
baqing-shop/src/test/java/com/ruoyi/web/modules/category/controller/SellerCategoryControllerTest.java

@@ -27,7 +27,6 @@ import com.ruoyi.web.modules.category.domain.BizGoodsCategory;
27 27
 import com.ruoyi.web.modules.category.exception.CategoryBatchDeleteException;
28 28
 import com.ruoyi.web.modules.category.service.ICategoryService;
29 29
 import com.ruoyi.web.modules.category.support.SellerShopContext;
30
-import com.ruoyi.web.modules.category.vo.CategoryListVO;
31 30
 import com.ruoyi.web.modules.category.vo.CategoryRowVO;
32 31
 
33 32
 /**
@@ -64,20 +63,15 @@ class SellerCategoryControllerTest
64 63
     @Test
65 64
     void list_returns200() throws Exception
66 65
     {
67
-        CategoryListVO vo = new CategoryListVO();
68
-        vo.setShopId(1L);
69
-        vo.setShopName("测试店");
70 66
         CategoryRowVO row = new CategoryRowVO();
71 67
         row.setCategoryId(1L);
72 68
         row.setCategoryName("肥料");
73
-        vo.setRows(Collections.singletonList(row));
74
-        when(categoryService.selectCategoryList(null)).thenReturn(vo);
69
+        when(categoryService.selectCategoryRowList(null)).thenReturn(Collections.singletonList(row));
75 70
 
76 71
         mockMvc.perform(get("/agri/seller/category/list"))
77 72
                 .andExpect(status().isOk())
78 73
                 .andExpect(jsonPath("$.code").value(200))
79
-                .andExpect(jsonPath("$.data.shopId").value(1))
80
-                .andExpect(jsonPath("$.data.rows[0].categoryName").value("肥料"));
74
+                .andExpect(jsonPath("$.rows[0].categoryName").value("肥料"));
81 75
     }
82 76
 
83 77
     @Test