|
|
@@ -18,6 +18,7 @@ import com.ruoyi.web.modules.category.facade.IGoodsFacade;
|
|
18
|
18
|
import com.ruoyi.web.modules.category.facade.IShopFacade;
|
|
19
|
19
|
import com.ruoyi.web.modules.category.mapper.BizGoodsCategoryMapper;
|
|
20
|
20
|
import com.ruoyi.web.modules.category.service.ICategoryService;
|
|
|
21
|
+import com.ruoyi.web.modules.category.service.IPlatformCategoryService;
|
|
21
|
22
|
import com.ruoyi.web.modules.category.support.SellerShopContext;
|
|
22
|
23
|
import com.ruoyi.web.modules.category.vo.CategoryLevel2OptionVO;
|
|
23
|
24
|
import com.ruoyi.web.modules.category.vo.CategoryListVO;
|
|
|
@@ -26,10 +27,10 @@ import com.ruoyi.web.modules.category.vo.CategoryTreeResultVO;
|
|
26
|
27
|
import com.ruoyi.web.modules.category.vo.CategoryTreeVO;
|
|
27
|
28
|
|
|
28
|
29
|
/**
|
|
29
|
|
- * 商品分类业务实现
|
|
|
30
|
+ * 商品分类业务实现(商家端 shop_id 非空;平台端 shop_id 为 NULL)
|
|
30
|
31
|
*/
|
|
31
|
32
|
@Service
|
|
32
|
|
-public class CategoryServiceImpl implements ICategoryService
|
|
|
33
|
+public class CategoryServiceImpl implements ICategoryService, IPlatformCategoryService
|
|
33
|
34
|
{
|
|
34
|
35
|
@Autowired
|
|
35
|
36
|
private BizGoodsCategoryMapper categoryMapper;
|
|
|
@@ -43,41 +44,125 @@ public class CategoryServiceImpl implements ICategoryService
|
|
43
|
44
|
@Override
|
|
44
|
45
|
public CategoryListVO selectCategoryList(String keyword)
|
|
45
|
46
|
{
|
|
46
|
|
- Long shopId = requireShopId();
|
|
47
|
|
- List<BizGoodsCategory> list = queryList(shopId, keyword);
|
|
|
47
|
+ return doSelectCategoryList(requireShopId(), keyword);
|
|
|
48
|
+ }
|
|
|
49
|
+
|
|
|
50
|
+ @Override
|
|
|
51
|
+ public CategoryTreeResultVO selectCategoryTree(String keyword)
|
|
|
52
|
+ {
|
|
|
53
|
+ return doSelectCategoryTree(requireShopId(), keyword);
|
|
|
54
|
+ }
|
|
|
55
|
+
|
|
|
56
|
+ @Override
|
|
|
57
|
+ public List<BizGoodsCategory> selectLevel1Options()
|
|
|
58
|
+ {
|
|
|
59
|
+ return doSelectLevel1Options(requireShopId());
|
|
|
60
|
+ }
|
|
|
61
|
+
|
|
|
62
|
+ @Override
|
|
|
63
|
+ public List<CategoryLevel2OptionVO> selectLevel2Options()
|
|
|
64
|
+ {
|
|
|
65
|
+ return doSelectLevel2Options(requireShopId());
|
|
|
66
|
+ }
|
|
|
67
|
+
|
|
|
68
|
+ @Override
|
|
|
69
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
70
|
+ public int insertCategory(BizGoodsCategory category)
|
|
|
71
|
+ {
|
|
|
72
|
+ return doInsertCategory(requireShopId(), category);
|
|
|
73
|
+ }
|
|
|
74
|
+
|
|
|
75
|
+ @Override
|
|
|
76
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
77
|
+ public int updateCategory(BizGoodsCategory category)
|
|
|
78
|
+ {
|
|
|
79
|
+ return doUpdateCategory(requireShopId(), category);
|
|
|
80
|
+ }
|
|
|
81
|
+
|
|
|
82
|
+ @Override
|
|
|
83
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
84
|
+ public void deleteCategoryByIds(Long[] categoryIds, String operator)
|
|
|
85
|
+ {
|
|
|
86
|
+ doDeleteCategoryByIds(requireShopId(), categoryIds, operator);
|
|
|
87
|
+ }
|
|
|
88
|
+
|
|
|
89
|
+ @Override
|
|
|
90
|
+ public CategoryListVO selectPlatformCategoryList(String keyword)
|
|
|
91
|
+ {
|
|
|
92
|
+ return doSelectCategoryList(null, keyword);
|
|
|
93
|
+ }
|
|
|
94
|
+
|
|
|
95
|
+ @Override
|
|
|
96
|
+ public CategoryTreeResultVO selectPlatformCategoryTree(String keyword)
|
|
|
97
|
+ {
|
|
|
98
|
+ return doSelectCategoryTree(null, keyword);
|
|
|
99
|
+ }
|
|
|
100
|
+
|
|
|
101
|
+ @Override
|
|
|
102
|
+ public List<BizGoodsCategory> selectPlatformLevel1Options()
|
|
|
103
|
+ {
|
|
|
104
|
+ return doSelectLevel1Options(null);
|
|
|
105
|
+ }
|
|
|
106
|
+
|
|
|
107
|
+ @Override
|
|
|
108
|
+ public List<CategoryLevel2OptionVO> selectPlatformLevel2Options()
|
|
|
109
|
+ {
|
|
|
110
|
+ return doSelectLevel2Options(null);
|
|
|
111
|
+ }
|
|
|
112
|
+
|
|
|
113
|
+ @Override
|
|
|
114
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
115
|
+ public int insertPlatformCategory(BizGoodsCategory category)
|
|
|
116
|
+ {
|
|
|
117
|
+ return doInsertCategory(null, category);
|
|
|
118
|
+ }
|
|
|
119
|
+
|
|
|
120
|
+ @Override
|
|
|
121
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
122
|
+ public int updatePlatformCategory(BizGoodsCategory category)
|
|
|
123
|
+ {
|
|
|
124
|
+ return doUpdateCategory(null, category);
|
|
|
125
|
+ }
|
|
|
126
|
+
|
|
|
127
|
+ @Override
|
|
|
128
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
129
|
+ public void deletePlatformCategoryByIds(Long[] categoryIds, String operator)
|
|
|
130
|
+ {
|
|
|
131
|
+ doDeleteCategoryByIds(null, categoryIds, operator);
|
|
|
132
|
+ }
|
|
|
133
|
+
|
|
|
134
|
+ private CategoryListVO doSelectCategoryList(Long shopId, String keyword)
|
|
|
135
|
+ {
|
|
|
136
|
+ assertScopeMaintable(shopId);
|
|
48
|
137
|
CategoryListVO vo = new CategoryListVO();
|
|
49
|
138
|
vo.setShopId(shopId);
|
|
50
|
|
- vo.setShopName(shopFacade.getShopName(shopId));
|
|
51
|
|
- vo.setRows(buildFlatRows(list));
|
|
|
139
|
+ vo.setShopName(resolveScopeName(shopId));
|
|
|
140
|
+ vo.setRows(buildFlatRows(queryList(shopId, keyword)));
|
|
52
|
141
|
return vo;
|
|
53
|
142
|
}
|
|
54
|
143
|
|
|
55
|
|
- @Override
|
|
56
|
|
- public CategoryTreeResultVO selectCategoryTree(String keyword)
|
|
|
144
|
+ private CategoryTreeResultVO doSelectCategoryTree(Long shopId, String keyword)
|
|
57
|
145
|
{
|
|
58
|
|
- Long shopId = requireShopId();
|
|
59
|
|
- List<BizGoodsCategory> list = queryList(shopId, keyword);
|
|
|
146
|
+ assertScopeMaintable(shopId);
|
|
60
|
147
|
CategoryTreeResultVO result = new CategoryTreeResultVO();
|
|
61
|
148
|
result.setShopId(shopId);
|
|
62
|
|
- result.setShopName(shopFacade.getShopName(shopId));
|
|
63
|
|
- result.setTree(buildTree(list));
|
|
|
149
|
+ result.setShopName(resolveScopeName(shopId));
|
|
|
150
|
+ result.setTree(buildTree(queryList(shopId, keyword)));
|
|
64
|
151
|
return result;
|
|
65
|
152
|
}
|
|
66
|
153
|
|
|
67
|
|
- @Override
|
|
68
|
|
- public List<BizGoodsCategory> selectLevel1Options()
|
|
|
154
|
+ private List<BizGoodsCategory> doSelectLevel1Options(Long shopId)
|
|
69
|
155
|
{
|
|
70
|
|
- Long shopId = requireShopId();
|
|
|
156
|
+ assertScopeMaintable(shopId);
|
|
71
|
157
|
BizGoodsCategory query = new BizGoodsCategory();
|
|
72
|
158
|
query.setShopId(shopId);
|
|
73
|
159
|
query.setCategoryLevel(CategoryConstants.LEVEL_ONE);
|
|
74
|
160
|
return categoryMapper.selectList(query);
|
|
75
|
161
|
}
|
|
76
|
162
|
|
|
77
|
|
- @Override
|
|
78
|
|
- public List<CategoryLevel2OptionVO> selectLevel2Options()
|
|
|
163
|
+ private List<CategoryLevel2OptionVO> doSelectLevel2Options(Long shopId)
|
|
79
|
164
|
{
|
|
80
|
|
- Long shopId = requireShopId();
|
|
|
165
|
+ assertScopeMaintable(shopId);
|
|
81
|
166
|
BizGoodsCategory query = new BizGoodsCategory();
|
|
82
|
167
|
query.setShopId(shopId);
|
|
83
|
168
|
List<BizGoodsCategory> all = categoryMapper.selectList(query);
|
|
|
@@ -98,14 +183,11 @@ public class CategoryServiceImpl implements ICategoryService
|
|
98
|
183
|
return options;
|
|
99
|
184
|
}
|
|
100
|
185
|
|
|
101
|
|
- @Override
|
|
102
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
103
|
|
- public int insertCategory(BizGoodsCategory category)
|
|
|
186
|
+ private int doInsertCategory(Long shopId, BizGoodsCategory category)
|
|
104
|
187
|
{
|
|
105
|
|
- Long shopId = requireShopId();
|
|
106
|
|
- shopFacade.assertShopMaintable(shopId);
|
|
|
188
|
+ assertScopeMaintable(shopId);
|
|
107
|
189
|
validateFields(category);
|
|
108
|
|
- normalizeLevelOnSave(category, shopId, true);
|
|
|
190
|
+ normalizeLevelOnSave(category, shopId);
|
|
109
|
191
|
if (categoryMapper.countByName(shopId, category.getParentId(), category.getCategoryName(), null) > 0)
|
|
110
|
192
|
{
|
|
111
|
193
|
throw new ServiceException("同级分类名称已存在");
|
|
|
@@ -115,12 +197,9 @@ public class CategoryServiceImpl implements ICategoryService
|
|
115
|
197
|
return categoryMapper.insert(category);
|
|
116
|
198
|
}
|
|
117
|
199
|
|
|
118
|
|
- @Override
|
|
119
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
120
|
|
- public int updateCategory(BizGoodsCategory category)
|
|
|
200
|
+ private int doUpdateCategory(Long shopId, BizGoodsCategory category)
|
|
121
|
201
|
{
|
|
122
|
|
- Long shopId = requireShopId();
|
|
123
|
|
- shopFacade.assertShopMaintable(shopId);
|
|
|
202
|
+ assertScopeMaintable(shopId);
|
|
124
|
203
|
if (category.getCategoryId() == null)
|
|
125
|
204
|
{
|
|
126
|
205
|
throw new ServiceException("分类ID不能为空");
|
|
|
@@ -150,12 +229,9 @@ public class CategoryServiceImpl implements ICategoryService
|
|
150
|
229
|
return categoryMapper.update(category);
|
|
151
|
230
|
}
|
|
152
|
231
|
|
|
153
|
|
- @Override
|
|
154
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
155
|
|
- public void deleteCategoryByIds(Long[] categoryIds, String operator)
|
|
|
232
|
+ private void doDeleteCategoryByIds(Long shopId, Long[] categoryIds, String operator)
|
|
156
|
233
|
{
|
|
157
|
|
- Long shopId = requireShopId();
|
|
158
|
|
- shopFacade.assertShopMaintable(shopId);
|
|
|
234
|
+ assertScopeMaintable(shopId);
|
|
159
|
235
|
if (categoryIds == null || categoryIds.length == 0)
|
|
160
|
236
|
{
|
|
161
|
237
|
throw new ServiceException("请选择要删除的分类");
|
|
|
@@ -178,8 +254,7 @@ public class CategoryServiceImpl implements ICategoryService
|
|
178
|
254
|
{
|
|
179
|
255
|
throw new CategoryBatchDeleteException("部分分类不满足删除条件,整批操作已取消", reasons);
|
|
180
|
256
|
}
|
|
181
|
|
- List<Long> idList = new ArrayList<>(targetIds);
|
|
182
|
|
- categoryMapper.logicDeleteByIds(idList, shopId, operator);
|
|
|
257
|
+ categoryMapper.logicDeleteByIds(new ArrayList<>(targetIds), shopId, operator);
|
|
183
|
258
|
}
|
|
184
|
259
|
|
|
185
|
260
|
private Long requireShopId()
|
|
|
@@ -189,10 +264,26 @@ public class CategoryServiceImpl implements ICategoryService
|
|
189
|
264
|
{
|
|
190
|
265
|
throw new ServiceException("请先选择当前店铺");
|
|
191
|
266
|
}
|
|
192
|
|
- shopFacade.assertShopMaintable(shopId);
|
|
193
|
267
|
return shopId;
|
|
194
|
268
|
}
|
|
195
|
269
|
|
|
|
270
|
+ private void assertScopeMaintable(Long shopId)
|
|
|
271
|
+ {
|
|
|
272
|
+ if (shopId != null)
|
|
|
273
|
+ {
|
|
|
274
|
+ shopFacade.assertShopMaintable(shopId);
|
|
|
275
|
+ }
|
|
|
276
|
+ }
|
|
|
277
|
+
|
|
|
278
|
+ private String resolveScopeName(Long shopId)
|
|
|
279
|
+ {
|
|
|
280
|
+ if (shopId == null)
|
|
|
281
|
+ {
|
|
|
282
|
+ return CategoryConstants.PLATFORM_SCOPE_NAME;
|
|
|
283
|
+ }
|
|
|
284
|
+ return shopFacade.getShopName(shopId);
|
|
|
285
|
+ }
|
|
|
286
|
+
|
|
196
|
287
|
private List<BizGoodsCategory> queryList(Long shopId, String keyword)
|
|
197
|
288
|
{
|
|
198
|
289
|
BizGoodsCategory query = new BizGoodsCategory();
|
|
|
@@ -281,7 +372,7 @@ public class CategoryServiceImpl implements ICategoryService
|
|
281
|
372
|
{
|
|
282
|
373
|
throw new ServiceException("请上传分类图片");
|
|
283
|
374
|
}
|
|
284
|
|
- if (category.getSortNo() == null || category.getSortNo() < 0)
|
|
|
375
|
+ if (category.getSortNo() < 0)
|
|
285
|
376
|
{
|
|
286
|
377
|
throw new ServiceException("排序须为非负整数");
|
|
287
|
378
|
}
|
|
|
@@ -297,7 +388,7 @@ public class CategoryServiceImpl implements ICategoryService
|
|
297
|
388
|
}
|
|
298
|
389
|
}
|
|
299
|
390
|
|
|
300
|
|
- private void normalizeLevelOnSave(BizGoodsCategory category, Long shopId, boolean insert)
|
|
|
391
|
+ private void normalizeLevelOnSave(BizGoodsCategory category, Long shopId)
|
|
301
|
392
|
{
|
|
302
|
393
|
if (CategoryConstants.LEVEL_ONE.equals(category.getCategoryLevel()))
|
|
303
|
394
|
{
|
|
|
@@ -343,8 +434,7 @@ public class CategoryServiceImpl implements ICategoryService
|
|
343
|
434
|
}
|
|
344
|
435
|
if (CategoryConstants.LEVEL_ONE.equals(cat.getCategoryLevel()))
|
|
345
|
436
|
{
|
|
346
|
|
- List<Long> children = categoryMapper.selectChildIds(shopId, id);
|
|
347
|
|
- result.addAll(children);
|
|
|
437
|
+ result.addAll(categoryMapper.selectChildIds(shopId, id));
|
|
348
|
438
|
result.add(id);
|
|
349
|
439
|
}
|
|
350
|
440
|
else
|