Ver código fonte

add productcategory

zero 1 ano atrás
pai
commit
0e9b197248

+ 14 - 0
src/main/java/com/example/xiaoshiweixinback/business/exception/ExceptionEnum.java

@@ -21,6 +21,20 @@ public enum ExceptionEnum {
     THE_PARAMETER_EXCEPTION("20001", "参数异常,请传入数据"),
     THE_GET_INFORMATION_TOKEN_INVALID("20002", "获取用信息token失效"),
     THE_FAIL_TO_DELETE("20003", "删除失败"),
+
+    //业务异常
+    THE_PRODUCT_CATEGORY_NAME_IS_EXIST("608", "产品类别名称已存在"),
+
+
+
+
+
+
+
+
+
+
+
     SYSTEM_ERROR("999999", "系统异常");
 
     private String code;// 异常代码

+ 67 - 0
src/main/java/com/example/xiaoshiweixinback/business/utils/CollectionKit.java

@@ -5,6 +5,7 @@ import cn.hutool.core.collection.BoundedPriorityQueue;
 import java.lang.reflect.Array;
 import java.util.*;
 import java.util.Map.Entry;
+import java.util.stream.Collectors;
 
 /**
  * 集合相关工具类,包括数组
@@ -797,4 +798,70 @@ public class CollectionKit {
 		}
 		return obj.toString();
 	}
+
+	/**
+	 * 交集
+	 * @param list1
+	 * @param list2
+	 * @return
+	 */
+	public List<String> intersection(List<String> list1, List<String> list2) {
+		return list1.stream().filter(item -> list2.contains(item)).collect(Collectors.toList());
+	}
+
+	/**
+	 * 去重交集
+	 * @param list1
+	 * @param list2
+	 * @return
+	 */
+	public List<String> intersectionDistinct(List<String> list1, List<String> list2) {
+		return list1.stream().filter(item -> list2.contains(item)).distinct().collect(Collectors.toList());
+	}
+
+	/**
+	 * 差集 (list1 - list2)
+	 * @param list1
+	 * @param list2
+	 * @return
+	 */
+	public List<String> reduce1(List<String> list1, List<String> list2) {
+		return list1.stream().filter(item -> !list2.contains(item)).collect(Collectors.toList());
+	}
+
+	/**
+	 * 差集 (list2 - list1)
+	 * @param list1
+	 * @param list2
+	 * @return
+	 */
+	public List<String> reduce2(List<String> list1, List<String> list2) {
+		return list2.stream().filter(item -> !list1.contains(item)).collect(Collectors.toList());
+	}
+
+	/**
+	 * 并集 listAll
+	 * @param list1
+	 * @param list2
+	 * @return
+	 */
+	public List<String> listAll(List<String> list1, List<String> list2) {
+		List<String> listAll = new ArrayList<>();
+		listAll.addAll(list1);
+		listAll.addAll(list2);
+		return listAll;
+	}
+
+	/**
+	 * 去重并集
+	 * @param list1
+	 * @param list2
+	 * @return
+	 */
+	public List<String> listAllDistinct(List<String> list1, List<String> list2) {
+		List<String> listAll = new ArrayList<>();
+		listAll.addAll(list1);
+		listAll.addAll(list2);
+		return listAll.stream().distinct().collect(Collectors.toList());
+	}
 }

+ 45 - 2
src/main/java/com/example/xiaoshiweixinback/controller/ProductCategoryController.java

@@ -8,9 +8,15 @@ import com.example.xiaoshiweixinback.checkLogin.checkLogin;
 import com.example.xiaoshiweixinback.domain.AssoCategoryFile;
 import com.example.xiaoshiweixinback.entity.dto.ConcernCategoryDTO;
 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.productCategory.SelectCategoryVO;
 import com.example.xiaoshiweixinback.service.AssoPersonCategoryService;
 import com.example.xiaoshiweixinback.service.ProductCategoryService;
 import io.swagger.v3.oas.annotations.Operation;
+import jakarta.validation.Valid;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 
@@ -30,13 +36,51 @@ public class ProductCategoryController {
     private final ProductCategoryService productCategoryService;
     private final AssoPersonCategoryService assoPersonCategoryService;
 
-    @Operation(summary = "查询产品类别")
+    @Operation(summary = "查询产品类别列表")
     @PostMapping("/queryCategory")
     public Response queryProductCategory(@RequestBody ProductCategoryDTO productCategoryDTO) {
         Records records = productCategoryService.queryProductCategory(productCategoryDTO);
         return Response.success(records);
     }
 
+    @Operation(summary = "添加产品类别")
+    @PostMapping("/addCategory")
+    public Response addCategory(@RequestBody @Valid AddCategoryDTO categoryDTO) {
+        Integer categoryId = null;
+        try {
+            categoryId = productCategoryService.addCategory(categoryDTO);
+        } catch (Exception e) {
+            return Response.error(e.getMessage());
+        }
+        return Response.success(categoryId);
+    }
+
+    @Operation(summary = "编辑产品类别")
+    @PostMapping("/editCategory")
+    public Response editCategory(@RequestBody EditCategoryDTO categoryDTO) {
+        Integer categoryId = null;
+        try {
+            categoryId = productCategoryService.editCategory(categoryDTO);
+        } catch (Exception e) {
+            return Response.error(e.getMessage());
+        }
+        return Response.success(categoryId);
+    }
+
+    @Operation(summary = "查询产品类别详情")
+    @PostMapping("/selectCategoryDetail")
+    public Response selectCategoryDetail(@RequestBody CategoryIdDTO categoryIdDTO) {
+        SelectCategoryVO categoryVO = productCategoryService.selectCategoryDetail(categoryIdDTO);
+        return Response.success(categoryVO);
+    }
+
+    @Operation(summary = "删除产品类别")
+    @PostMapping("/deleteCategory")
+    public Response deleteCategory(@RequestBody CategoryIdsDTO categoryIdsDTO) {
+        boolean b = productCategoryService.deleteCategory(categoryIdsDTO);
+        return Response.success(b);
+    }
+
     @Operation(summary = "查询关注的产品类别")
     @PostMapping("/queryConcernedCategory")
     public Response queryConcernedCategory(@RequestBody ProductCategoryDTO productCategoryDTO) {
@@ -45,7 +89,6 @@ public class ProductCategoryController {
         return Response.success(records);
     }
 
-
     @checkLogin
     @Operation(summary = "关注产品类别")
     @PostMapping("/concernCategory")

+ 5 - 0
src/main/java/com/example/xiaoshiweixinback/entity/dto/ProductCategoryDTO.java

@@ -4,9 +4,14 @@ import lombok.Data;
 
 @Data
 public class ProductCategoryDTO {
+
     private String name;
+
     private Long current;
+
     private Long size;
+
     private Integer parentId;
+
     private Boolean ifConcern;
 }

+ 28 - 0
src/main/java/com/example/xiaoshiweixinback/entity/dto/productCategory/AddCategoryDTO.java

@@ -0,0 +1,28 @@
+package com.example.xiaoshiweixinback.entity.dto.productCategory;
+
+import jakarta.validation.constraints.NotBlank;
+import lombok.Data;
+
+import java.util.List;
+
+@Data
+public class AddCategoryDTO {
+
+    //类别描述
+    @NotBlank
+    private String description;
+
+    //产品类别名称
+    @NotBlank
+    private String name;
+
+    //上级产品类别
+    private Integer parentId;
+
+    //关键词/检索条件
+    @NotBlank
+    private String searchCondition;
+
+    //图s
+    private List<String> fileGuids;
+}

+ 9 - 0
src/main/java/com/example/xiaoshiweixinback/entity/dto/productCategory/CategoryIdDTO.java

@@ -0,0 +1,9 @@
+package com.example.xiaoshiweixinback.entity.dto.productCategory;
+
+import lombok.Data;
+
+@Data
+public class CategoryIdDTO {
+
+    private Integer id;
+}

+ 12 - 0
src/main/java/com/example/xiaoshiweixinback/entity/dto/productCategory/CategoryIdsDTO.java

@@ -0,0 +1,12 @@
+package com.example.xiaoshiweixinback.entity.dto.productCategory;
+
+import lombok.Data;
+
+import java.util.List;
+
+@Data
+public class CategoryIdsDTO {
+
+    private List<Integer> ids;
+
+}

+ 27 - 0
src/main/java/com/example/xiaoshiweixinback/entity/dto/productCategory/EditCategoryDTO.java

@@ -0,0 +1,27 @@
+package com.example.xiaoshiweixinback.entity.dto.productCategory;
+
+import jakarta.validation.constraints.NotBlank;
+import lombok.Data;
+
+import java.util.List;
+
+@Data
+public class EditCategoryDTO {
+
+    private Integer id;
+
+    //类别描述
+    private String description;
+
+    //产品类别名称
+    private String name;
+
+    //上级产品类别
+    private Integer parentId;
+
+    //关键词/检索条件
+    private String searchCondition;
+
+    //图s
+    private List<String> fileGuids;
+}

+ 10 - 23
src/main/java/com/example/xiaoshiweixinback/entity/vo/ProductCategoryVO.java

@@ -3,6 +3,7 @@ package com.example.xiaoshiweixinback.entity.vo;
 import com.baomidou.mybatisplus.annotation.IdType;
 import com.baomidou.mybatisplus.annotation.TableId;
 import com.example.xiaoshiweixinback.business.common.base.SystemFile;
+import com.example.xiaoshiweixinback.entity.vo.productCategory.SelectCategoryLevelVO;
 import io.swagger.v3.oas.annotations.media.Schema;
 import lombok.Data;
 import org.joda.time.DateTime;
@@ -13,44 +14,30 @@ import java.util.List;
 @Data
 public class ProductCategoryVO {
 
-    /**
-     * ID
-     */
-    @TableId(type = IdType.AUTO)
     private Integer id;
 
-    /**
-     *
-     */
     private String description;
 
-    /**
-     *
-     */
     private String name;
 
-
-    /**
-     * 检索条件
-     */
     private String searchCondition;
 
-    /**
-     *
-     */
     private String path;
 
+    private Integer level;  //层级
 
-    /**
-     *
-     */
     private String createName;
 
-    /**
-     *
-     */
     private DateTime createTime;
+
     private String createId;
+
+    private List<String> fileGuids; //图s
+
+    private SelectCategoryLevelVO categoryLevelVo;  //父类类别信息
+
+    private Boolean ifChild = false;
+
     @Schema(description = "文件信息")
     private List<SystemFile> systemFileList;
 }

+ 15 - 0
src/main/java/com/example/xiaoshiweixinback/entity/vo/productCategory/SelectCategoryLevelVO.java

@@ -0,0 +1,15 @@
+package com.example.xiaoshiweixinback.entity.vo.productCategory;
+
+import lombok.Data;
+
+@Data
+public class SelectCategoryLevelVO {
+
+    private Integer id;
+
+    private String name;   //类别名称
+
+    private Integer level;  //层级
+
+    private String path;   //路径
+}

+ 35 - 0
src/main/java/com/example/xiaoshiweixinback/entity/vo/productCategory/SelectCategoryVO.java

@@ -0,0 +1,35 @@
+package com.example.xiaoshiweixinback.entity.vo.productCategory;
+
+import lombok.Data;
+import org.joda.time.DateTime;
+
+import java.util.Date;
+import java.util.List;
+
+@Data
+public class SelectCategoryVO {
+
+    private Integer id;
+
+    private String description;   //描述
+
+    private String name;   //类别名称
+
+    private Integer parentId;  //父级类别id
+
+    private String searchCondition;   //关键词/检索条件
+
+    private String path;   //路径
+
+    private Integer level;  //层级
+
+    private String createId;  //创建者id
+
+    private DateTime createTime;  //创建时间
+
+    private List<String> fileGuids; //图s
+
+    private SelectCategoryLevelVO categoryLevelVo;  //父类类别信息
+
+    private Boolean ifChild = false;  //是否有子集
+}

+ 225 - 6
src/main/java/com/example/xiaoshiweixinback/service/ProductCategoryService.java

@@ -7,19 +7,34 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.example.xiaoshiweixinback.business.common.base.Records;
 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.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;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Propagation;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.util.CollectionUtils;
 
 import java.util.ArrayList;
 import java.util.List;
@@ -37,6 +52,9 @@ public class ProductCategoryService extends ServiceImpl<ProductCategoryMapper, P
     private final AssoCategoryFileService assoCategoryFileService;
     private final PersonService personService;
     private final FileManagerService fileManagerService;
+    private final ProductCategoryMapper productCategoryMapper;
+    @Autowired
+    private AssoCategoryFileMapper assoCategoryFileMapper;
 
     /**
      * 查询产品类别
@@ -46,33 +64,35 @@ public class ProductCategoryService extends ServiceImpl<ProductCategoryMapper, P
      */
     public Records queryProductCategory(ProductCategoryDTO productCategoryDTO) {
         Boolean ifConcern = productCategoryDTO.getIfConcern();
-        Records records = new Records();
         Long size = productCategoryDTO.getSize();
         Long current = productCategoryDTO.getCurrent();
         String name = productCategoryDTO.getName();
         Integer parentId = productCategoryDTO.getParentId();
+        Records records = new Records();
         records.setCurrent(current);
         records.setSize(size);
 
 
         LambdaQueryWrapper<ProductCategory> queryWrapper = new LambdaQueryWrapper<>();
-        if (name != null && !name.trim().equals("")) {
+        if (StringUtils.isNotEmpty(name)) {
             queryWrapper.like(ProductCategory::getName, name);
         }
+
         if (parentId == null) {
             queryWrapper.isNull(ProductCategory::getParentId);
         } else {
             queryWrapper.eq(ProductCategory::getParentId, parentId);
         }
+
         if (ifConcern != null && ifConcern) {
             //获取关注的
             List<Integer> ids = assoPersonCategoryService.getChoosedProductCategoryIds();
-            if(ids.size()==0){
+            if (ids.size() == 0) {
                 ids.add(0);
             }
             queryWrapper.in(ProductCategory::getId, ids);
-
         }
+
         List<ProductCategory> productCategoryList = new ArrayList<>();
         if (size != null && current != null) {
             IPage<ProductCategory> productCategoryIPage = this.page(new Page<>(current, size), queryWrapper);
@@ -104,7 +124,6 @@ public class ProductCategoryService extends ServiceImpl<ProductCategoryMapper, P
             queryWrapper.in(AssoCategoryFile::getProductCategoryId, ids);
             assoCategoryFiles = assoCategoryFileService.list(queryWrapper);
             guids = assoCategoryFiles.stream().map(AssoCategoryFile::getFileGuid).collect(Collectors.toList());
-
         }
 
         //查询创建人名称
@@ -130,7 +149,7 @@ public class ProductCategoryService extends ServiceImpl<ProductCategoryMapper, P
         for (ProductCategory productCategory : productCategorys) {
             ProductCategoryVO productCategoryVO = new ProductCategoryVO();
             BeanUtils.copyProperties(productCategory, productCategoryVO);
-            Person personnel = personList.stream().filter(item -> item.getUuid().toString().equals(productCategoryVO.getCreateId())).findFirst().orElse(null);
+            Person personnel = personList.stream().filter(item -> item.getUuid().equals(productCategoryVO.getCreateId())).findFirst().orElse(null);
             if (personnel != null) {
                 productCategoryVO.setCreateName(personnel.getName());
             }
@@ -145,11 +164,211 @@ public class ProductCategoryService extends ServiceImpl<ProductCategoryMapper, P
                     }
                 }
             }
+            //装载父类产品类别
+            if (productCategory.getParentId() != null) {
+                ProductCategory parentCategory = this.getById(productCategory.getParentId());
+                SelectCategoryLevelVO levelVO = new SelectCategoryLevelVO();
+                levelVO.setId(parentCategory.getId());
+                levelVO.setName(parentCategory.getName());
+                levelVO.setPath(parentCategory.getPath());
+                levelVO.setLevel(parentCategory.getLevel());
+                productCategoryVO.setCategoryLevelVo(levelVO);
+            }
+            //装载产品图
+            productCategoryVO.setFileGuids(guids);
+            //判断是否有子集
+            Long count = productCategoryMapper.selectCount(new LambdaQueryWrapper<ProductCategory>()
+                    .eq(ProductCategory::getParentId, productCategory.getId()));
+            if (count > 0) {
+                productCategoryVO.setIfChild(true);
+            }
             productCategoryVOS.add(productCategoryVO);
         }
         return productCategoryVOS;
     }
 
+    /**
+     * 添加产品类别
+     *
+     * @param categoryDTO
+     * @return
+     */
+    @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());
+            Integer level = parentCategory.getLevel();
+            category.setLevel(level + 1);
+            category.setPath(this.getPath(level));
+        } else {
+            category.setLevel(1);
+        }
+        category.insert();
+        Integer categoryId = category.getId();
+        if (!CollectionUtils.isEmpty(categoryDTO.getFileGuids())) {
+            for (String fileGuid : categoryDTO.getFileGuids()) {
+                AssoCategoryFile categoryFile = new AssoCategoryFile();
+                categoryFile.setProductCategoryId(categoryId);
+                categoryFile.setFileGuid(fileGuid);
+                categoryFile.insert();
+            }
+        }
+        return categoryId;
+    }
+
+    /**
+     * 编辑产品类别
+     *
+     * @param categoryDTO
+     * @return
+     */
+    @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.setParentId(categoryDTO.getParentId());
+            ProductCategory parentCategory = this.getById(categoryDTO.getParentId());
+            Integer level = parentCategory.getLevel();
+            category.setLevel(level + 1);
+            category.setPath(this.getPath(level));
+        }
+        category.updateById();
+
+        if (!CollectionUtils.isEmpty(categoryDTO.getFileGuids())) {
+            List<AssoCategoryFile> assoCategoryFiles = assoCategoryFileMapper.selectList(new LambdaQueryWrapper<AssoCategoryFile>()
+                    .eq(AssoCategoryFile::getProductCategoryId, categoryId));
+            if (!CollectionUtils.isEmpty(assoCategoryFiles)) {
+                List<Integer> categoryIds = assoCategoryFiles.stream().map(AssoCategoryFile::getId).collect(Collectors.toList());
+                assoCategoryFileMapper.deleteBatchIds(categoryIds);
+            }
+
+            for (String fileGuid : categoryDTO.getFileGuids()) {
+                AssoCategoryFile categoryFile = new AssoCategoryFile();
+                categoryFile.setProductCategoryId(categoryId);
+                categoryFile.setFileGuid(fileGuid);
+                categoryFile.insert();
+            }
+        }
+        return categoryId;
+    }
+
+    /**
+     * 查询产品类别详情
+     *
+     * @param categoryIdDTO
+     * @return
+     */
+    public SelectCategoryVO selectCategoryDetail(CategoryIdDTO categoryIdDTO) {
+        Integer categoryId = categoryIdDTO.getId();
+        SelectCategoryVO categoryVO = new SelectCategoryVO();
+        ProductCategory category = productCategoryMapper.selectById(categoryId);
+        BeanUtil.copy(category, categoryVO);
+        //获取父类产品类别
+        Integer parentId = category.getParentId();
+        if (parentId != null) {
+            ProductCategory parentCategory = this.getById(parentId);
+            SelectCategoryLevelVO levelVO = new SelectCategoryLevelVO();
+            levelVO.setId(parentCategory.getId());
+            levelVO.setName(parentCategory.getName());
+            levelVO.setPath(parentCategory.getPath());
+            levelVO.setLevel(parentCategory.getLevel());
+            categoryVO.setCategoryLevelVo(levelVO);
+        }
+        //获取guids
+        List<AssoCategoryFile> assoCategoryFiles = assoCategoryFileMapper.selectList(new LambdaQueryWrapper<AssoCategoryFile>()
+                .eq(AssoCategoryFile::getProductCategoryId, categoryId));
+        List<String> fileGuids = new ArrayList<>();
+        if (!CollectionUtils.isEmpty(assoCategoryFiles)) {
+            fileGuids = assoCategoryFiles.stream().map(AssoCategoryFile::getFileGuid).collect(Collectors.toList());
+        }
+        categoryVO.setFileGuids(fileGuids);
+        //判断是否有子集
+        Long count = productCategoryMapper.selectCount(new LambdaQueryWrapper<ProductCategory>()
+                .eq(ProductCategory::getParentId, categoryId));
+        if (count > 0) {
+            categoryVO.setIfChild(true);
+        }
+        return categoryVO;
+    }
+
+    /**
+     * 删除产品类别
+     *
+     * @param categoryIdsDTO
+     * @return
+     */
+    public boolean deleteCategory(CategoryIdsDTO categoryIdsDTO) {
+        List<Integer> ids = categoryIdsDTO.getIds();
+        for (Integer id : ids) {
+            List<Integer> productCategoryIds = this.getProductCategoryIds(id);
+            ids.addAll(productCategoryIds);
+        }
+        List<AssoCategoryFile> assoCategoryFiles = assoCategoryFileMapper.selectList(new LambdaQueryWrapper<AssoCategoryFile>()
+                .in(AssoCategoryFile::getProductCategoryId, ids));
+        if (!CollectionUtils.isEmpty(assoCategoryFiles)) {
+            List<Integer> fileIds = assoCategoryFiles.stream().map(AssoCategoryFile::getId).collect(Collectors.toList());
+            assoCategoryFileMapper.deleteBatchIds(fileIds);
+        }
+        return this.removeBatchByIds(ids);
+    }
+
+    public List<Integer> getProductCategoryIds(Integer id) {
+        List<Integer> list = new ArrayList<>();
+        List<ProductCategory> categories = productCategoryMapper.selectList(new LambdaQueryWrapper<ProductCategory>()
+                .eq(ProductCategory::getParentId, id));
+        if (!CollectionUtils.isEmpty(categories)) {
+            List<Integer> ids = categories.stream().map(ProductCategory::getId).collect(Collectors.toList());
+            list.addAll(ids);
+            for (ProductCategory category : categories) {
+                List<Integer> categoryIds = this.getProductCategoryIds(category.getId());
+                list.addAll(categoryIds);
+            }
+        }
+        return list;
+    }
+
+    /**
+     * 获取路径
+     *
+     * @param level
+     * @return
+     */
+    public String getPath(Integer level) {
+        String s = "";
+        for (int i = 1; i < level; i++) {
+            if (i != level - 1) {
+                s = s + i + "/";
+            } else {
+                s = s + i;
+            }
+        }
+        return s;
+    }
 }