|
@@ -12,21 +12,19 @@ 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;
|
|
|
import com.example.xiaoshiweixinback.entity.dto.productCategory.CategoryIdDTO;
|
|
|
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;
|
|
@@ -173,12 +171,19 @@ 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);
|
|
|
+ //回显路径
|
|
|
+ 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()));
|
|
@@ -198,15 +203,7 @@ 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) {
|
|
|
category.setParentId(categoryDTO.getParentId());
|
|
|
ProductCategory parentCategory = this.getById(categoryDTO.getParentId());
|
|
@@ -217,10 +214,23 @@ public class ProductCategoryService extends ServiceImpl<ProductCategoryMapper, P
|
|
|
level = parentCategory.getLevel();
|
|
|
}
|
|
|
category.setLevel(level + 1);
|
|
|
- category.setPath(this.getPath(category.getLevel()));
|
|
|
+ if (parentCategory.getParentId() != null) {
|
|
|
+ category.setPath(this.getPath(parentCategory.getParentId()) + "/" + parentCategory.getId() + "/");
|
|
|
+ } else {
|
|
|
+ category.setPath(parentCategory.getId() + "/");
|
|
|
+ }
|
|
|
} else {
|
|
|
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());
|
|
|
category.insert();
|
|
|
Integer categoryId = category.getId();
|
|
|
if (!CollectionUtils.isEmpty(categoryDTO.getFileGuids())) {
|
|
@@ -242,12 +252,6 @@ 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);
|
|
|
- }
|
|
|
Integer categoryId = categoryDTO.getId();
|
|
|
ProductCategory category = this.getById(categoryId);
|
|
|
if (StringUtils.isNotEmpty(categoryDTO.getName())) {
|
|
@@ -269,7 +273,18 @@ public class ProductCategoryService extends ServiceImpl<ProductCategoryMapper, P
|
|
|
level = parentCategory.getLevel();
|
|
|
}
|
|
|
category.setLevel(level + 1);
|
|
|
- category.setPath(this.getPath(category.getLevel()));
|
|
|
+ if (parentCategory.getParentId() != null) {
|
|
|
+ category.setPath(this.getPath(parentCategory.getParentId()) + "/" + parentCategory.getId() + "/");
|
|
|
+ } else {
|
|
|
+ category.setPath(parentCategory.getId() + "/");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ 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();
|
|
|
|
|
@@ -313,10 +328,11 @@ 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);
|
|
|
+ //回显路径
|
|
|
+ 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));
|
|
@@ -337,7 +353,18 @@ public class ProductCategoryService extends ServiceImpl<ProductCategoryMapper, P
|
|
|
} catch (Exception e) {
|
|
|
}
|
|
|
}
|
|
|
- categoryVO.setSystemFileList(systemFiles);
|
|
|
+ //装载文件信息
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+// categoryVO.setSystemFileList(systemFiles);
|
|
|
//判断是否有子集
|
|
|
Long count = productCategoryMapper.selectCount(new LambdaQueryWrapper<ProductCategory>()
|
|
|
.eq(ProductCategory::getParentId, categoryId));
|
|
@@ -388,52 +415,34 @@ public class ProductCategoryService extends ServiceImpl<ProductCategoryMapper, P
|
|
|
/**
|
|
|
* 获取回显路径
|
|
|
*
|
|
|
- * @param level
|
|
|
+ * @param parentId
|
|
|
* @return
|
|
|
*/
|
|
|
- public String getPath(Integer level) {
|
|
|
+ public String getPath(Integer parentId) {
|
|
|
String s = "";
|
|
|
- for (int i = 1; i < level; i++) {
|
|
|
- String str = levelToStr(i);
|
|
|
- if (i != level - 1) {
|
|
|
- s = s + str + "/";
|
|
|
+ ProductCategory parentCategory = this.getById(parentId);
|
|
|
+ if (ToolUtil.isNotEmpty(parentCategory)) {
|
|
|
+ if (parentCategory.getParentId() != null) {
|
|
|
+ String pathId = this.getPath(parentCategory.getParentId());
|
|
|
+ s = s + "/" + pathId;
|
|
|
} else {
|
|
|
- s = s + str;
|
|
|
+ s = parentCategory.getId().toString();
|
|
|
}
|
|
|
}
|
|
|
return s;
|
|
|
}
|
|
|
|
|
|
- public String levelToStr(int i) {
|
|
|
+ public String getChildPath(Integer id) {
|
|
|
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;
|
|
|
+ List<ProductCategory> categories = productCategoryMapper.selectList(new LambdaQueryWrapper<ProductCategory>()
|
|
|
+ .eq(ProductCategory::getParentId, id));
|
|
|
+ if (ToolUtil.isNotEmpty(categories)) {
|
|
|
+// if (parentCategory.getParentId() != null) {
|
|
|
+// String pathId = this.getPath(parentCategory.getParentId());
|
|
|
+// s = s + "/" + pathId;
|
|
|
+// } else {
|
|
|
+// s = parentCategory.getId().toString();
|
|
|
+// }
|
|
|
}
|
|
|
return s;
|
|
|
}
|
|
@@ -441,19 +450,22 @@ public class ProductCategoryService extends ServiceImpl<ProductCategoryMapper, P
|
|
|
/**
|
|
|
* 获取回显路径
|
|
|
*
|
|
|
- * @param level
|
|
|
+ * @param path
|
|
|
* @return
|
|
|
*/
|
|
|
- public String getEchoPath(Integer level) {
|
|
|
- String s = "";
|
|
|
- for (int i = 1; i < level; i++) {
|
|
|
- if (i != level - 1) {
|
|
|
- s = s + i + "/";
|
|
|
+ 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 {
|
|
|
- s = s + i;
|
|
|
+ str = str + category.getName() + "/";
|
|
|
}
|
|
|
}
|
|
|
- return s;
|
|
|
+ return str;
|
|
|
}
|
|
|
}
|
|
|
|