|
@@ -12,6 +12,7 @@ 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;
|
|
|
import com.example.xiaoshiweixinback.entity.dto.productCategory.AddCategoryDTO;
|
|
@@ -20,13 +21,11 @@ import com.example.xiaoshiweixinback.entity.dto.productCategory.CategoryIdsDTO;
|
|
|
import com.example.xiaoshiweixinback.entity.dto.productCategory.EditCategoryDTO;
|
|
|
import com.example.xiaoshiweixinback.entity.vo.PersonnelVO;
|
|
|
import com.example.xiaoshiweixinback.entity.vo.ProductCategoryVO;
|
|
|
-import com.example.xiaoshiweixinback.entity.vo.ProductVO;
|
|
|
import com.example.xiaoshiweixinback.entity.vo.productCategory.SelectCategoryLevelVO;
|
|
|
import com.example.xiaoshiweixinback.entity.vo.productCategory.SelectCategoryVO;
|
|
|
import com.example.xiaoshiweixinback.mapper.AssoCategoryFileMapper;
|
|
|
import com.example.xiaoshiweixinback.mapper.ProductCategoryMapper;
|
|
|
import com.example.xiaoshiweixinback.service.common.FileManagerService;
|
|
|
-import io.swagger.v3.oas.models.security.SecurityScheme;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
@@ -37,7 +36,9 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.HashSet;
|
|
|
import java.util.List;
|
|
|
+import java.util.Set;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
@@ -53,6 +54,7 @@ public class ProductCategoryService extends ServiceImpl<ProductCategoryMapper, P
|
|
|
private final PersonService personService;
|
|
|
private final FileManagerService fileManagerService;
|
|
|
private final ProductCategoryMapper productCategoryMapper;
|
|
|
+ private final CacheUtil cacheUtil;
|
|
|
@Autowired
|
|
|
private AssoCategoryFileMapper assoCategoryFileMapper;
|
|
|
|
|
@@ -77,13 +79,7 @@ public class ProductCategoryService extends ServiceImpl<ProductCategoryMapper, P
|
|
|
if (StringUtils.isNotEmpty(name)) {
|
|
|
queryWrapper.like(ProductCategory::getName, name);
|
|
|
}
|
|
|
-
|
|
|
- if (parentId == null) {
|
|
|
- queryWrapper.isNull(ProductCategory::getParentId);
|
|
|
- } else {
|
|
|
- queryWrapper.eq(ProductCategory::getParentId, parentId);
|
|
|
- }
|
|
|
-
|
|
|
+ queryWrapper.eq(ProductCategory::getParentId, parentId);
|
|
|
if (ifConcern != null && ifConcern) {
|
|
|
//获取关注的
|
|
|
List<Integer> ids = assoPersonCategoryService.getChoosedProductCategoryIds();
|
|
@@ -92,6 +88,7 @@ public class ProductCategoryService extends ServiceImpl<ProductCategoryMapper, P
|
|
|
}
|
|
|
queryWrapper.in(ProductCategory::getId, ids);
|
|
|
}
|
|
|
+ queryWrapper.orderByDesc(ProductCategory::getCreateTime);
|
|
|
|
|
|
List<ProductCategory> productCategoryList = new ArrayList<>();
|
|
|
if (size != null && current != null) {
|
|
@@ -142,7 +139,6 @@ public class ProductCategoryService extends ServiceImpl<ProductCategoryMapper, P
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
//装载登录人信息,装载
|
|
@@ -165,7 +161,7 @@ public class ProductCategoryService extends ServiceImpl<ProductCategoryMapper, P
|
|
|
}
|
|
|
}
|
|
|
//装载父类产品类别
|
|
|
- if (productCategory.getParentId() != null) {
|
|
|
+ if (productCategory.getParentId() != 0) {
|
|
|
ProductCategory parentCategory = this.getById(productCategory.getParentId());
|
|
|
SelectCategoryLevelVO levelVO = new SelectCategoryLevelVO();
|
|
|
levelVO.setId(parentCategory.getId());
|
|
@@ -174,8 +170,19 @@ public class ProductCategoryService extends ServiceImpl<ProductCategoryMapper, P
|
|
|
levelVO.setLevel(parentCategory.getLevel());
|
|
|
productCategoryVO.setCategoryLevelVo(levelVO);
|
|
|
}
|
|
|
+ //回显路径
|
|
|
+ if (StringUtils.isNotEmpty(productCategory.getPath())) {
|
|
|
+ String echoPath = this.getEchoPath(productCategory.getPath());
|
|
|
+ productCategoryVO.setEchoPath(echoPath);
|
|
|
+ }
|
|
|
//装载产品图
|
|
|
- productCategoryVO.setFileGuids(guids);
|
|
|
+ List<AssoCategoryFile> files = assoCategoryFileMapper.selectList(new LambdaQueryWrapper<AssoCategoryFile>()
|
|
|
+ .eq(AssoCategoryFile::getProductCategoryId, productCategory.getId()));
|
|
|
+ List<String> fileGuids = new ArrayList<>();
|
|
|
+ if (!CollectionUtils.isEmpty(files)) {
|
|
|
+ fileGuids = files.stream().map(AssoCategoryFile::getFileGuid).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+ productCategoryVO.setFileGuids(fileGuids);
|
|
|
//判断是否有子集
|
|
|
Long count = productCategoryMapper.selectCount(new LambdaQueryWrapper<ProductCategory>()
|
|
|
.eq(ProductCategory::getParentId, productCategory.getId()));
|
|
@@ -195,24 +202,40 @@ public class ProductCategoryService extends ServiceImpl<ProductCategoryMapper, P
|
|
|
*/
|
|
|
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Throwable.class)
|
|
|
public Integer addCategory(AddCategoryDTO categoryDTO) {
|
|
|
- Long count = productCategoryMapper.selectCount(new LambdaQueryWrapper<ProductCategory>()
|
|
|
- .eq(ProductCategory::getName, categoryDTO.getName()));
|
|
|
- if (count > 0) {
|
|
|
- throw new BusinessException(ExceptionEnum.THE_PRODUCT_CATEGORY_NAME_IS_EXIST);
|
|
|
- }
|
|
|
ProductCategory category = new ProductCategory();
|
|
|
- category.setName(categoryDTO.getName());
|
|
|
- category.setDescription(categoryDTO.getDescription());
|
|
|
- category.setSearchCondition(categoryDTO.getSearchCondition());
|
|
|
- if (categoryDTO.getParentId() != null) {
|
|
|
+ if (categoryDTO.getParentId() != null && categoryDTO.getParentId() != 0) {
|
|
|
category.setParentId(categoryDTO.getParentId());
|
|
|
ProductCategory parentCategory = this.getById(categoryDTO.getParentId());
|
|
|
Integer level = parentCategory.getLevel();
|
|
|
+ if (level == null) {
|
|
|
+ parentCategory.setLevel(1);
|
|
|
+ parentCategory.updateById();
|
|
|
+ level = parentCategory.getLevel();
|
|
|
+ }
|
|
|
category.setLevel(level + 1);
|
|
|
- category.setPath(this.getPath(level));
|
|
|
+ if (parentCategory.getParentId() != 0) {
|
|
|
+ category.setPath(this.getPath(parentCategory.getParentId()) + "/" + parentCategory.getId() + "/");
|
|
|
+ } else {
|
|
|
+ category.setPath(parentCategory.getId() + "/");
|
|
|
+ }
|
|
|
} else {
|
|
|
+ category.setParentId(0);
|
|
|
category.setLevel(1);
|
|
|
}
|
|
|
+ Long count = productCategoryMapper.selectCount(new LambdaQueryWrapper<ProductCategory>()
|
|
|
+ .eq(ProductCategory::getName, categoryDTO.getName())
|
|
|
+ .eq(ProductCategory::getLevel, category.getLevel()));
|
|
|
+ if (count > 0) {
|
|
|
+ throw new BusinessException(ExceptionEnum.THE_PRODUCT_CATEGORY_NAME_IS_EXIST);
|
|
|
+ }
|
|
|
+ category.setName(categoryDTO.getName());
|
|
|
+ category.setDescription(categoryDTO.getDescription());
|
|
|
+ category.setSearchCondition(categoryDTO.getSearchCondition());
|
|
|
+ PersonnelVO personnelVO = cacheUtil.getLoginUser(LoginUtils.getToken());
|
|
|
+ if (ToolUtil.isEmpty(personnelVO)) {
|
|
|
+ throw new BusinessException(ExceptionEnum.THE_LOG_INVALID_NEED_LOGIN_AGAIN);
|
|
|
+ }
|
|
|
+ category.setCreateId(personnelVO.getId().toString());
|
|
|
category.insert();
|
|
|
Integer categoryId = category.getId();
|
|
|
if (!CollectionUtils.isEmpty(categoryDTO.getFileGuids())) {
|
|
@@ -234,28 +257,41 @@ public class ProductCategoryService extends ServiceImpl<ProductCategoryMapper, P
|
|
|
*/
|
|
|
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Throwable.class)
|
|
|
public Integer editCategory(EditCategoryDTO categoryDTO) {
|
|
|
- Long count = productCategoryMapper.selectCount(new LambdaQueryWrapper<ProductCategory>()
|
|
|
- .eq(ProductCategory::getName, categoryDTO.getName()));
|
|
|
- if (count > 0) {
|
|
|
- throw new BusinessException(ExceptionEnum.THE_PRODUCT_CATEGORY_NAME_IS_EXIST);
|
|
|
- }
|
|
|
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() != null) {
|
|
|
+ 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();
|
|
|
+ if (level == null) {
|
|
|
+ parentCategory.setLevel(1);
|
|
|
+ parentCategory.updateById();
|
|
|
+ level = parentCategory.getLevel();
|
|
|
+ }
|
|
|
category.setLevel(level + 1);
|
|
|
- category.setPath(this.getPath(level));
|
|
|
+ if (parentCategory.getParentId() != 0) {
|
|
|
+ category.setPath(this.getPath(parentCategory.getParentId()) + "/" + parentCategory.getId() + "/");
|
|
|
+ } else {
|
|
|
+ category.setPath(parentCategory.getId() + "/");
|
|
|
+ }
|
|
|
+ this.getParentPath(category.getId(), category.getPath(), category.getLevel());
|
|
|
+ } else {
|
|
|
+ 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())
|
|
|
+ .eq(ProductCategory::getLevel, category.getLevel())
|
|
|
+ .eq(ProductCategory::getName, categoryDTO.getName()));
|
|
|
+ if (count > 0) {
|
|
|
+ throw new BusinessException(ExceptionEnum.THE_PRODUCT_CATEGORY_NAME_IS_EXIST);
|
|
|
}
|
|
|
category.updateById();
|
|
|
|
|
@@ -290,7 +326,7 @@ public class ProductCategoryService extends ServiceImpl<ProductCategoryMapper, P
|
|
|
BeanUtil.copy(category, categoryVO);
|
|
|
//获取父类产品类别
|
|
|
Integer parentId = category.getParentId();
|
|
|
- if (parentId != null) {
|
|
|
+ if (parentId != 0) {
|
|
|
ProductCategory parentCategory = this.getById(parentId);
|
|
|
SelectCategoryLevelVO levelVO = new SelectCategoryLevelVO();
|
|
|
levelVO.setId(parentCategory.getId());
|
|
@@ -299,6 +335,11 @@ public class ProductCategoryService extends ServiceImpl<ProductCategoryMapper, P
|
|
|
levelVO.setLevel(parentCategory.getLevel());
|
|
|
categoryVO.setCategoryLevelVo(levelVO);
|
|
|
}
|
|
|
+ //回显路径
|
|
|
+ if (StringUtils.isNotEmpty(category.getPath())) {
|
|
|
+ String echoPath = this.getEchoPath(category.getPath());
|
|
|
+ categoryVO.setEchoPath(echoPath);
|
|
|
+ }
|
|
|
//获取guids
|
|
|
List<AssoCategoryFile> assoCategoryFiles = assoCategoryFileMapper.selectList(new LambdaQueryWrapper<AssoCategoryFile>()
|
|
|
.eq(AssoCategoryFile::getProductCategoryId, categoryId));
|
|
@@ -307,6 +348,29 @@ public class ProductCategoryService extends ServiceImpl<ProductCategoryMapper, P
|
|
|
fileGuids = assoCategoryFiles.stream().map(AssoCategoryFile::getFileGuid).collect(Collectors.toList());
|
|
|
}
|
|
|
categoryVO.setFileGuids(fileGuids);
|
|
|
+ //查询文件
|
|
|
+ List<SystemFile> systemFiles = new ArrayList<>();
|
|
|
+ if (fileGuids.size() != 0) {
|
|
|
+ try {
|
|
|
+ String res = fileManagerService.getSystemFileFromFMS(fileGuids);
|
|
|
+ systemFiles = JSONObject.parseArray(res, SystemFile.class);
|
|
|
+ if (systemFiles == null) {
|
|
|
+ systemFiles = new ArrayList<>();
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //装载文件信息
|
|
|
+ List<AssoCategoryFile> assoCategoryFilesTemp = assoCategoryFiles.stream().filter(item -> item.getProductCategoryId().equals(category.getId())).collect(Collectors.toList());
|
|
|
+ if (assoCategoryFilesTemp.size() != 0) {
|
|
|
+ List<String> guidTemp = assoCategoryFilesTemp.stream().map(AssoCategoryFile::getFileGuid).collect(Collectors.toList());
|
|
|
+ if (guidTemp.size() != 0) {
|
|
|
+ List<SystemFile> systemFileTemp = systemFiles.stream().filter(item -> guidTemp.contains(item.getGuid())).collect(Collectors.toList());
|
|
|
+ if (systemFileTemp.size() != 0) {
|
|
|
+ categoryVO.setSystemFileList(systemFileTemp);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
//判断是否有子集
|
|
|
Long count = productCategoryMapper.selectCount(new LambdaQueryWrapper<ProductCategory>()
|
|
|
.eq(ProductCategory::getParentId, categoryId));
|
|
@@ -324,10 +388,12 @@ public class ProductCategoryService extends ServiceImpl<ProductCategoryMapper, P
|
|
|
*/
|
|
|
public boolean deleteCategory(CategoryIdsDTO categoryIdsDTO) {
|
|
|
List<Integer> ids = categoryIdsDTO.getIds();
|
|
|
+ List<Integer> list = new ArrayList<>();
|
|
|
for (Integer id : ids) {
|
|
|
List<Integer> productCategoryIds = this.getProductCategoryIds(id);
|
|
|
- ids.addAll(productCategoryIds);
|
|
|
+ list.addAll(productCategoryIds);
|
|
|
}
|
|
|
+ ids.addAll(list);
|
|
|
List<AssoCategoryFile> assoCategoryFiles = assoCategoryFileMapper.selectList(new LambdaQueryWrapper<AssoCategoryFile>()
|
|
|
.in(AssoCategoryFile::getProductCategoryId, ids));
|
|
|
if (!CollectionUtils.isEmpty(assoCategoryFiles)) {
|
|
@@ -352,23 +418,205 @@ 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 id
|
|
|
+ * @param path
|
|
|
* @param level
|
|
|
+ */
|
|
|
+ public void getParentPath(Integer id, String path, 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);
|
|
|
+ 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(productCategory.getLevel() + 1);
|
|
|
+ productCategory.updateById();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改产品类别低层级变高层级
|
|
|
+ *
|
|
|
+ * @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 level) {
|
|
|
+ public String getPath(Integer parentId) {
|
|
|
String s = "";
|
|
|
- for (int i = 1; i < level; i++) {
|
|
|
- if (i != level - 1) {
|
|
|
- s = s + i + "/";
|
|
|
+ ProductCategory parentCategory = this.getById(parentId);
|
|
|
+ if (ToolUtil.isNotEmpty(parentCategory)) {
|
|
|
+ if (parentCategory.getParentId() != 0) {
|
|
|
+ String pathId = this.getPath(parentCategory.getParentId());
|
|
|
+ s = s + "/" + pathId;
|
|
|
} else {
|
|
|
- s = s + i;
|
|
|
+ s = parentCategory.getId().toString();
|
|
|
}
|
|
|
}
|
|
|
return s;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取回显路径
|
|
|
+ *
|
|
|
+ * @param path
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public String getEchoPath(String path) {
|
|
|
+ String str = "";
|
|
|
+ String[] split = path.split("/");
|
|
|
+ for (int i = 0; i < split.length; i++) {
|
|
|
+ String s = split[i];
|
|
|
+ ProductCategory category = productCategoryMapper.selectById(Integer.valueOf(s));
|
|
|
+ if (i != split.length - 1) {
|
|
|
+ str = str + category.getName() + "/";
|
|
|
+ } else {
|
|
|
+ str = str + category.getName() + "/";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return str;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询产品类别
|
|
|
+ *
|
|
|
+ * @param ids
|
|
|
+ * @param ifContentPath
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public List<ProductCategory> getProductCategory(List<Integer> ids, Boolean ifContentPath) {
|
|
|
+ if (ids == null || ids.size() == 0) {
|
|
|
+ return new ArrayList<>();
|
|
|
+ }
|
|
|
+
|
|
|
+ LambdaQueryWrapper<ProductCategory> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.in(ProductCategory::getId, ids);
|
|
|
+ List<ProductCategory> productCategories = this.list(queryWrapper);
|
|
|
+
|
|
|
+ if (ifContentPath) {
|
|
|
+ List<String> paths = productCategories.stream().map(ProductCategory::getPath).collect(Collectors.toList());
|
|
|
+ List<Integer> trueIds = productCategories.stream().map(ProductCategory::getId).collect(Collectors.toList());
|
|
|
+ Set<Integer> set = new HashSet<>();
|
|
|
+ set.addAll(trueIds);
|
|
|
+ paths.forEach(item -> {
|
|
|
+ if (item != null) {
|
|
|
+ String[] arr = item.split("/");
|
|
|
+ for (int i = 0; i > arr.length; i++) {
|
|
|
+ set.add(Integer.parseInt(arr[i]));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ if (set.size() != 0) {
|
|
|
+ LambdaQueryWrapper<ProductCategory> queryWrapper1 = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper1.in(ProductCategory::getId, ids);
|
|
|
+ productCategories = this.list(queryWrapper1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return productCategories;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public ProductCategory addCategorysByStr(List<String> categorys) {
|
|
|
+
|
|
|
+ if(categorys==null||categorys.size()==0){
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ Integer parentId = 0;
|
|
|
+ ProductCategory last = null;
|
|
|
+ for (int i = 0; i < categorys.size(); i++) {
|
|
|
+ Integer level = i + 1;
|
|
|
+ //根据 层级和名称查询
|
|
|
+ LambdaQueryWrapper<ProductCategory> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.eq(ProductCategory::getName, categorys.get(i))
|
|
|
+ .eq(ProductCategory::getLevel, level)
|
|
|
+ .eq(ProductCategory::getParentId, parentId);
|
|
|
+ ProductCategory productCategory = this.getOne(queryWrapper, false);
|
|
|
+
|
|
|
+ if (productCategory == null) {
|
|
|
+ productCategory = new ProductCategory();
|
|
|
+ productCategory.setLevel(level);
|
|
|
+ productCategory.setName(categorys.get(i));
|
|
|
+
|
|
|
+ if (last != null) {
|
|
|
+ if (last.getPath() != null) {
|
|
|
+ productCategory.setPath(last.getPath() + last.getId() + "/");
|
|
|
+ } else {
|
|
|
+ productCategory.setPath(last.getId() + "/");
|
|
|
+ }
|
|
|
+ productCategory.setParentId(parentId);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ productCategory.setParentId(0);
|
|
|
+ }
|
|
|
+ productCategory.insert();
|
|
|
+
|
|
|
+ }
|
|
|
+ last = productCategory;
|
|
|
+ parentId =last.getId();
|
|
|
+ }
|
|
|
+ return last;
|
|
|
+
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|