|
@@ -78,9 +78,9 @@ public class ProductCategoryService extends ServiceImpl<ProductCategoryMapper, P
|
|
|
queryWrapper.like(ProductCategory::getName, name);
|
|
|
}
|
|
|
|
|
|
- if (parentId == null) {
|
|
|
+ if (parentId == 0) {
|
|
|
queryWrapper.isNull(ProductCategory::getParentId);
|
|
|
- } else {
|
|
|
+ } else if (parentId != 0){
|
|
|
queryWrapper.eq(ProductCategory::getParentId, parentId);
|
|
|
}
|
|
|
|
|
@@ -142,7 +142,6 @@ public class ProductCategoryService extends ServiceImpl<ProductCategoryMapper, P
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
//装载登录人信息,装载
|
|
@@ -174,6 +173,10 @@ public class ProductCategoryService extends ServiceImpl<ProductCategoryMapper, P
|
|
|
levelVO.setLevel(parentCategory.getLevel());
|
|
|
productCategoryVO.setCategoryLevelVo(levelVO);
|
|
|
}
|
|
|
+ //路径
|
|
|
+ Integer level = productCategory.getLevel();
|
|
|
+ String echoPath = this.getEchoPath(level);
|
|
|
+ productCategoryVO.setEchoPath(echoPath);
|
|
|
//装载产品图
|
|
|
productCategoryVO.setFileGuids(guids);
|
|
|
//判断是否有子集
|
|
@@ -208,8 +211,13 @@ public class ProductCategoryService extends ServiceImpl<ProductCategoryMapper, P
|
|
|
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));
|
|
|
+ category.setPath(this.getPath(category.getLevel()));
|
|
|
} else {
|
|
|
category.setLevel(1);
|
|
|
}
|
|
@@ -235,6 +243,7 @@ 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>()
|
|
|
+ .ne(ProductCategory::getId,categoryDTO.getId())
|
|
|
.eq(ProductCategory::getName, categoryDTO.getName()));
|
|
|
if (count > 0) {
|
|
|
throw new BusinessException(ExceptionEnum.THE_PRODUCT_CATEGORY_NAME_IS_EXIST);
|
|
@@ -254,8 +263,13 @@ public class ProductCategoryService extends ServiceImpl<ProductCategoryMapper, P
|
|
|
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));
|
|
|
+ category.setPath(this.getPath(category.getLevel()));
|
|
|
}
|
|
|
category.updateById();
|
|
|
|
|
@@ -299,6 +313,10 @@ public class ProductCategoryService extends ServiceImpl<ProductCategoryMapper, P
|
|
|
levelVO.setLevel(parentCategory.getLevel());
|
|
|
categoryVO.setCategoryLevelVo(levelVO);
|
|
|
}
|
|
|
+ //路径
|
|
|
+ Integer level = category.getLevel();
|
|
|
+ String echoPath = this.getEchoPath(level);
|
|
|
+ categoryVO.setEchoPath(echoPath);
|
|
|
//获取guids
|
|
|
List<AssoCategoryFile> assoCategoryFiles = assoCategoryFileMapper.selectList(new LambdaQueryWrapper<AssoCategoryFile>()
|
|
|
.eq(AssoCategoryFile::getProductCategoryId, categoryId));
|
|
@@ -307,6 +325,19 @@ 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) {
|
|
|
+ }
|
|
|
+ }
|
|
|
+ categoryVO.setSystemFileList(systemFiles);
|
|
|
//判断是否有子集
|
|
|
Long count = productCategoryMapper.selectCount(new LambdaQueryWrapper<ProductCategory>()
|
|
|
.eq(ProductCategory::getParentId, categoryId));
|
|
@@ -324,10 +355,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)) {
|
|
@@ -353,7 +386,7 @@ public class ProductCategoryService extends ServiceImpl<ProductCategoryMapper, P
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 获取路径
|
|
|
+ * 获取回显路径
|
|
|
*
|
|
|
* @param level
|
|
|
* @return
|
|
@@ -361,6 +394,59 @@ public class ProductCategoryService extends ServiceImpl<ProductCategoryMapper, P
|
|
|
public String getPath(Integer level) {
|
|
|
String s = "";
|
|
|
for (int i = 1; i < level; i++) {
|
|
|
+ String str = levelToStr(i);
|
|
|
+ if (i != level - 1) {
|
|
|
+ s = s + str + "/";
|
|
|
+ } else {
|
|
|
+ s = s + str;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return s;
|
|
|
+ }
|
|
|
+
|
|
|
+ public String levelToStr(int i) {
|
|
|
+ String s = "";
|
|
|
+ switch (i) {
|
|
|
+ case 1:
|
|
|
+ s = "一级";
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ s = "二级";
|
|
|
+ break;
|
|
|
+ case 3:
|
|
|
+ s = "三级";
|
|
|
+ break;
|
|
|
+ case 4:
|
|
|
+ s = "四级";
|
|
|
+ break;
|
|
|
+ case 5:
|
|
|
+ s = "五级";
|
|
|
+ break;
|
|
|
+ case 6:
|
|
|
+ s = "六级";
|
|
|
+ break;
|
|
|
+ case 7:
|
|
|
+ s = "七级";
|
|
|
+ break;
|
|
|
+ case 8:
|
|
|
+ s = "八级";
|
|
|
+ break;
|
|
|
+ case 9:
|
|
|
+ s = "九级";
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ return s;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取回显路径
|
|
|
+ *
|
|
|
+ * @param level
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public String getEchoPath(Integer level) {
|
|
|
+ String s = "";
|
|
|
+ for (int i = 1; i < level; i++) {
|
|
|
if (i != level - 1) {
|
|
|
s = s + i + "/";
|
|
|
} else {
|