|
@@ -2,7 +2,9 @@ package com.example.xiaoshiweixinback.service;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.extension.conditions.update.UpdateChainWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.example.xiaoshiweixinback.business.common.base.Records;
|
|
@@ -10,8 +12,6 @@ import com.example.xiaoshiweixinback.business.common.base.SystemFile;
|
|
|
import com.example.xiaoshiweixinback.business.exception.BusinessException;
|
|
|
import com.example.xiaoshiweixinback.business.exception.ExceptionEnum;
|
|
|
import com.example.xiaoshiweixinback.business.utils.BeanUtil;
|
|
|
-import com.example.xiaoshiweixinback.business.utils.CacheUtil;
|
|
|
-import com.example.xiaoshiweixinback.business.utils.LoginUtils;
|
|
|
import com.example.xiaoshiweixinback.business.utils.ToolUtil;
|
|
|
import com.example.xiaoshiweixinback.domain.*;
|
|
|
import com.example.xiaoshiweixinback.entity.dto.ProductCategoryDTO;
|
|
@@ -206,7 +206,7 @@ public class ProductCategoryService extends ServiceImpl<ProductCategoryMapper, P
|
|
|
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Throwable.class)
|
|
|
public Integer addCategory(AddCategoryDTO categoryDTO) {
|
|
|
ProductCategory category = new ProductCategory();
|
|
|
- if (categoryDTO.getParentId() != 0) {
|
|
|
+ if (categoryDTO.getParentId() != null && categoryDTO.getParentId() != 0) {
|
|
|
category.setParentId(categoryDTO.getParentId());
|
|
|
ProductCategory parentCategory = this.getById(categoryDTO.getParentId());
|
|
|
Integer level = parentCategory.getLevel();
|
|
@@ -257,16 +257,10 @@ public class ProductCategoryService extends ServiceImpl<ProductCategoryMapper, P
|
|
|
public Integer editCategory(EditCategoryDTO categoryDTO) {
|
|
|
Integer categoryId = categoryDTO.getId();
|
|
|
ProductCategory category = this.getById(categoryId);
|
|
|
- if (StringUtils.isNotEmpty(categoryDTO.getName())) {
|
|
|
- category.setName(categoryDTO.getName());
|
|
|
- }
|
|
|
- if (StringUtils.isNotEmpty(categoryDTO.getDescription())) {
|
|
|
- category.setDescription(categoryDTO.getDescription());
|
|
|
- }
|
|
|
- if (StringUtils.isNotEmpty(categoryDTO.getSearchCondition())) {
|
|
|
- category.setSearchCondition(categoryDTO.getSearchCondition());
|
|
|
- }
|
|
|
- if (categoryDTO.getParentId() != 0) {
|
|
|
+ category.setName(categoryDTO.getName());
|
|
|
+ category.setDescription(categoryDTO.getDescription());
|
|
|
+ category.setSearchCondition(categoryDTO.getSearchCondition());
|
|
|
+ if (categoryDTO.getParentId() != null && categoryDTO.getParentId() != 0) {
|
|
|
category.setParentId(categoryDTO.getParentId());
|
|
|
ProductCategory parentCategory = this.getById(categoryDTO.getParentId());
|
|
|
Integer level = parentCategory.getLevel();
|
|
@@ -283,12 +277,12 @@ public class ProductCategoryService extends ServiceImpl<ProductCategoryMapper, P
|
|
|
}
|
|
|
this.getParentPath(category.getId(), category.getPath(),category.getLevel());
|
|
|
} else {
|
|
|
- //todo
|
|
|
-// category.setParentId(0);
|
|
|
-// category.setLevel(category.getLevel() - 1);
|
|
|
-// category.setPath(null);
|
|
|
-
|
|
|
-
|
|
|
+ Integer parentId = category.getParentId();
|
|
|
+ Integer level = category.getLevel();
|
|
|
+ category.setParentId(0);
|
|
|
+ category.setLevel(level - 1);
|
|
|
+ category.setPath(null);
|
|
|
+ this.getChildPath(category.getId(), parentId, level);
|
|
|
}
|
|
|
Long count = productCategoryMapper.selectCount(new LambdaQueryWrapper<ProductCategory>()
|
|
|
.ne(ProductCategory::getId, categoryDTO.getId())
|
|
@@ -422,29 +416,40 @@ public class ProductCategoryService extends ServiceImpl<ProductCategoryMapper, P
|
|
|
return list;
|
|
|
}
|
|
|
|
|
|
+// public void getParentPath(Integer id, String path, Integer level) {
|
|
|
+// List<ProductCategory> categories = productCategoryMapper.selectList(new LambdaQueryWrapper<ProductCategory>()
|
|
|
+// .eq(ProductCategory::getParentId, id));
|
|
|
+// if (ToolUtil.isNotEmpty(categories)) {
|
|
|
+// for (ProductCategory category : categories) {
|
|
|
+// ProductCategory productCategory = productCategoryMapper.selectById(category.getId());
|
|
|
+// String productCategoryPath = productCategory.getPath();
|
|
|
+// if (StringUtils.isNotEmpty(productCategoryPath)) {
|
|
|
+// productCategory.setPath(path + productCategoryPath);
|
|
|
+// } else {
|
|
|
+// productCategory.setPath(path);
|
|
|
+// }
|
|
|
+// productCategory.setLevel(level + 1);
|
|
|
+// productCategory.updateById();
|
|
|
+// //循环
|
|
|
+// this.getParentPath(productCategory.getId(), productCategory.getPath(), productCategory.getLevel());
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+
|
|
|
/**
|
|
|
- * 获取回显路径
|
|
|
- *
|
|
|
- * @param parentId
|
|
|
- * @return
|
|
|
+ * 修改产品类别高层级变低层级
|
|
|
+ * @param id
|
|
|
+ * @param path
|
|
|
+ * @param level
|
|
|
*/
|
|
|
- public String getPath(Integer parentId) {
|
|
|
- String s = "";
|
|
|
- ProductCategory parentCategory = this.getById(parentId);
|
|
|
- if (ToolUtil.isNotEmpty(parentCategory)) {
|
|
|
- if (parentCategory.getParentId() != 0) {
|
|
|
- String pathId = this.getPath(parentCategory.getParentId());
|
|
|
- s = s + "/" + pathId;
|
|
|
- } else {
|
|
|
- s = parentCategory.getId().toString();
|
|
|
- }
|
|
|
- }
|
|
|
- return s;
|
|
|
- }
|
|
|
-
|
|
|
public void getParentPath(Integer id, String path, Integer level) {
|
|
|
- List<ProductCategory> categories = productCategoryMapper.selectList(new LambdaQueryWrapper<ProductCategory>()
|
|
|
- .eq(ProductCategory::getParentId, id));
|
|
|
+ LambdaQueryWrapper<ProductCategory> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ if (level > 2) {
|
|
|
+ wrapper.like(ProductCategory::getPath, "/" + id + "/");
|
|
|
+ } else {
|
|
|
+ wrapper.likeRight(ToolUtil.isNotEmpty(id), ProductCategory::getPath, id + "/");
|
|
|
+ }
|
|
|
+ List<ProductCategory> categories = productCategoryMapper.selectList(wrapper);
|
|
|
if (ToolUtil.isNotEmpty(categories)) {
|
|
|
for (ProductCategory category : categories) {
|
|
|
ProductCategory productCategory = productCategoryMapper.selectById(category.getId());
|
|
@@ -454,32 +459,54 @@ public class ProductCategoryService extends ServiceImpl<ProductCategoryMapper, P
|
|
|
} else {
|
|
|
productCategory.setPath(path);
|
|
|
}
|
|
|
- productCategory.setLevel(level + 1);
|
|
|
+ productCategory.setLevel(productCategory.getLevel() + 1);
|
|
|
productCategory.updateById();
|
|
|
- //循环
|
|
|
- this.getParentPath(productCategory.getId(), productCategory.getPath(), productCategory.getLevel());
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public void getChildPath(Integer id, String path, Integer level) {
|
|
|
- List<ProductCategory> categories = productCategoryMapper.selectList(new LambdaQueryWrapper<ProductCategory>()
|
|
|
- .eq(ProductCategory::getParentId, id));
|
|
|
- if (ToolUtil.isNotEmpty(categories)) {
|
|
|
- for (ProductCategory category : categories) {
|
|
|
- ProductCategory productCategory = productCategoryMapper.selectById(category.getId());
|
|
|
- String productCategoryPath = productCategory.getPath();
|
|
|
- if (StringUtils.isNotEmpty(productCategoryPath)) {
|
|
|
- productCategory.setPath(path + productCategoryPath);
|
|
|
- } else {
|
|
|
- productCategory.setPath(path);
|
|
|
- }
|
|
|
- productCategory.setLevel(level + 1);
|
|
|
- productCategory.updateById();
|
|
|
- //循环
|
|
|
- this.getChildPath(productCategory.getId(), productCategory.getPath(), productCategory.getLevel());
|
|
|
+ /**
|
|
|
+ * 修改产品类别低层级变高层级
|
|
|
+ * @param id
|
|
|
+ * @param parentId
|
|
|
+ * @param level
|
|
|
+ */
|
|
|
+ public void getChildPath(Integer id, Integer parentId, Integer level) {
|
|
|
+ LambdaQueryWrapper<ProductCategory> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ if (level >= 2) {
|
|
|
+ wrapper.like(ProductCategory::getPath, "/" + id + "/");
|
|
|
+ } else {
|
|
|
+ wrapper.likeRight(ToolUtil.isNotEmpty(id), ProductCategory::getPath, id + "/");
|
|
|
+ }
|
|
|
+ List<ProductCategory> categories = productCategoryMapper.selectList(wrapper);
|
|
|
+ for (ProductCategory category : categories) {
|
|
|
+ ProductCategory productCategory = productCategoryMapper.selectById(category.getId());
|
|
|
+ String categoryPath = productCategory.getPath();
|
|
|
+ Integer categoryLevel = productCategory.getLevel();
|
|
|
+ productCategory.setPath(categoryPath.replace(parentId + "/", ""));
|
|
|
+ productCategory.setLevel(categoryLevel - 1);
|
|
|
+ productCategory.updateById();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取路径
|
|
|
+ *
|
|
|
+ * @param parentId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public String getPath(Integer parentId) {
|
|
|
+ String s = "";
|
|
|
+ ProductCategory parentCategory = this.getById(parentId);
|
|
|
+ if (ToolUtil.isNotEmpty(parentCategory)) {
|
|
|
+ if (parentCategory.getParentId() != 0) {
|
|
|
+ String pathId = this.getPath(parentCategory.getParentId());
|
|
|
+ s = s + "/" + pathId;
|
|
|
+ } else {
|
|
|
+ s = parentCategory.getId().toString();
|
|
|
}
|
|
|
}
|
|
|
+ return s;
|
|
|
}
|
|
|
|
|
|
/**
|