|
|
@@ -1,5 +1,6 @@
|
|
|
package com.gree.mall.manager.logic.goods;
|
|
|
|
|
|
+import cn.hutool.core.collection.CollectionUtil;
|
|
|
import com.gree.mall.manager.bean.admin.AdminUserCom;
|
|
|
import com.gree.mall.manager.bean.goods.GoodsCategoryBean;
|
|
|
import com.gree.mall.manager.commonmapper.CustomGoodsCategoryMapper;
|
|
|
@@ -8,6 +9,7 @@ import com.gree.mall.manager.logic.common.CommonLogic;
|
|
|
import com.gree.mall.manager.plus.entity.*;
|
|
|
import com.gree.mall.manager.plus.service.*;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
@@ -37,6 +39,10 @@ public class GoodsCategoryLogic {
|
|
|
|
|
|
@Autowired
|
|
|
GoodsCategoryItemService goodsCategoryItemService;
|
|
|
+ @Resource
|
|
|
+ GoodsCategoryRelaService goodsCategoryRelaService;
|
|
|
+ @Resource
|
|
|
+ GoodsDocumentsService goodsDocumentsService;
|
|
|
|
|
|
/**
|
|
|
* 分类管理列表
|
|
|
@@ -45,14 +51,14 @@ public class GoodsCategoryLogic {
|
|
|
* @param status
|
|
|
* @return
|
|
|
*/
|
|
|
- public List<GoodsCategoryBean> list(Integer type, Integer level, String name, Boolean status, Boolean platform, HttpServletRequest request) {
|
|
|
+ public List<GoodsCategoryBean> list(Integer type, Integer level, String name, Boolean status, HttpServletRequest request) {
|
|
|
//获取当前登录企业微信id
|
|
|
AdminUserCom adminUser = commonLogic.getAdminUser(request);
|
|
|
List<String> companyWechatIds = adminUser.getCompanyWechatIds();
|
|
|
if (type == null) {
|
|
|
type = 1;
|
|
|
}
|
|
|
- return customGoodsCategoryMapper.list(type, level, status, name, platform, companyWechatIds);
|
|
|
+ return customGoodsCategoryMapper.list(type, level, status, name, companyWechatIds);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -94,30 +100,53 @@ public class GoodsCategoryLogic {
|
|
|
//goodsCategory.setCreateTime(new Date());
|
|
|
goodsCategory.insert();
|
|
|
|
|
|
+ // 文档分类处理
|
|
|
+ if (goodsCategoryBean.getType() == 5 && CollectionUtil.isNotEmpty(goodsCategoryBean.getGoodsCategoryRelaList())) {
|
|
|
+ for (GoodsCategoryRela categoryRela : goodsCategoryBean.getGoodsCategoryRelaList()) {
|
|
|
+ categoryRela.setCategoryId(goodsCategory.getCategoryId());
|
|
|
+ }
|
|
|
+
|
|
|
+ goodsCategoryRelaService.saveBatch(goodsCategoryBean.getGoodsCategoryRelaList());
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 修改分类
|
|
|
*
|
|
|
- * @param goodsCategory
|
|
|
+ * @param goodsCategoryBean
|
|
|
*/
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
- public void update(GoodsCategory goodsCategory) {
|
|
|
- GoodsCategory old = goodsCategoryService.getById(goodsCategory.getCategoryId());
|
|
|
+ public void update(GoodsCategoryBean goodsCategoryBean) {
|
|
|
+ GoodsCategory old = goodsCategoryService.getById(goodsCategoryBean.getCategoryId());
|
|
|
//检查名称不可重复
|
|
|
Integer count = goodsCategoryService.lambdaQuery()
|
|
|
- .ne(GoodsCategory::getCategoryId, goodsCategory.getCategoryId())
|
|
|
+ .ne(GoodsCategory::getCategoryId, goodsCategoryBean.getCategoryId())
|
|
|
.eq(GoodsCategory::getType, old.getType())
|
|
|
- .eq(GoodsCategory::getName, goodsCategory.getName())
|
|
|
+ .eq(GoodsCategory::getName, goodsCategoryBean.getName())
|
|
|
.eq(GoodsCategory::getCompanyWechatId, old.getCompanyWechatId()).count();
|
|
|
if (count > 0) {
|
|
|
- throw new RemoteServiceException("分类名称【" + goodsCategory.getName() + "】已存在");
|
|
|
+ throw new RemoteServiceException("分类名称【" + goodsCategoryBean.getName() + "】已存在");
|
|
|
}
|
|
|
- goodsCategoryService.updateById(goodsCategory);
|
|
|
+ goodsCategoryService.updateById(goodsCategoryBean);
|
|
|
//如果有子集,覆盖子集的一些参数
|
|
|
// goodsCategoryService.lambdaUpdate()
|
|
|
// .set(GoodsCategory::getIsPromotionDiscount,goodsCategory.getIsPromotionDiscount())
|
|
|
// .eq(GoodsCategory::getParentId,goodsCategory.getCategoryId()).update();
|
|
|
+
|
|
|
+ // 文档分类处理
|
|
|
+ if (goodsCategoryBean.getType() == 5) {
|
|
|
+ goodsCategoryRelaService.lambdaUpdate()
|
|
|
+ .eq(GoodsCategoryRela::getCategoryId, goodsCategoryBean.getCategoryId())
|
|
|
+ .remove();
|
|
|
+ if (CollectionUtil.isNotEmpty(goodsCategoryBean.getGoodsCategoryRelaList())) {
|
|
|
+ for (GoodsCategoryRela categoryRela : goodsCategoryBean.getGoodsCategoryRelaList()) {
|
|
|
+ categoryRela.setCategoryId(goodsCategoryBean.getCategoryId());
|
|
|
+ }
|
|
|
+
|
|
|
+ goodsCategoryRelaService.saveBatch(goodsCategoryBean.getGoodsCategoryRelaList());
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -148,6 +177,15 @@ public class GoodsCategoryLogic {
|
|
|
throw new RemoteServiceException("服务分类已被商品规格使用,不可删除");
|
|
|
}
|
|
|
|
|
|
+ final Integer count3 = goodsDocumentsService.lambdaQuery().in(GoodsDocuments::getParentCategoryId, goodsCategoryIds).count();
|
|
|
+ if (count3 > 0) {
|
|
|
+ throw new RemoteServiceException("文档分类已被文件夹使用,不可删除");
|
|
|
+ }
|
|
|
+ final Integer count4 = goodsDocumentsService.lambdaQuery().in(GoodsDocuments::getCategoryId, goodsCategoryIds).count();
|
|
|
+ if (count4 > 0) {
|
|
|
+ throw new RemoteServiceException("文档分类已被文件夹使用,不可删除");
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
// 删除子类别
|
|
|
goodsCategoryService.lambdaUpdate()
|
|
|
@@ -169,8 +207,17 @@ public class GoodsCategoryLogic {
|
|
|
/**
|
|
|
* 分类详情
|
|
|
*/
|
|
|
- public GoodsCategory detail(String goodsCategoryId) {
|
|
|
- return goodsCategoryService.getById(goodsCategoryId);
|
|
|
+ public GoodsCategoryBean detail(String goodsCategoryId) {
|
|
|
+ GoodsCategoryBean bean = new GoodsCategoryBean();
|
|
|
+ final GoodsCategory goodsCategory = goodsCategoryService.getById(goodsCategoryId);
|
|
|
+ BeanUtils.copyProperties(goodsCategory, bean);
|
|
|
+ if (bean.getType() == 5) {
|
|
|
+ final List<GoodsCategoryRela> relaList = goodsCategoryRelaService.lambdaQuery()
|
|
|
+ .eq(GoodsCategoryRela::getCategoryId, bean.getCategoryId())
|
|
|
+ .list();
|
|
|
+ bean.setGoodsCategoryRelaList(relaList);
|
|
|
+ }
|
|
|
+ return bean;
|
|
|
}
|
|
|
|
|
|
}
|