浏览代码

fixed productcategory

zero 1 年之前
父节点
当前提交
eacb55a6ec

+ 2 - 1
src/main/java/com/example/xiaoshiweixinback/domain/ProductCategory.java

@@ -60,6 +60,7 @@ public class ProductCategory extends BaseEntity<ProductCategory> {
     /**
      * 
      */
-    private DateTime createTime;
+    @TableField(value = "create_time")
+    private Date createTime;
 
 }

+ 3 - 4
src/main/java/com/example/xiaoshiweixinback/entity/vo/ProductCategoryVO.java

@@ -1,12 +1,9 @@
 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;
 
 import java.util.Date;
 import java.util.List;
@@ -23,12 +20,14 @@ public class ProductCategoryVO {
     private String searchCondition;
 
     private String path;
+    //回显路径
+    private String echoPath;
 
     private Integer level;  //层级
 
     private String createName;
 
-    private DateTime createTime;
+    private Date createTime;
 
     private String createId;
 

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

@@ -1,5 +1,7 @@
 package com.example.xiaoshiweixinback.entity.vo.productCategory;
 
+import com.example.xiaoshiweixinback.business.common.base.SystemFile;
+import io.swagger.v3.oas.annotations.media.Schema;
 import lombok.Data;
 import org.joda.time.DateTime;
 
@@ -20,6 +22,8 @@ public class SelectCategoryVO {
     private String searchCondition;   //关键词/检索条件
 
     private String path;   //路径
+    //回显路径
+    private String echoPath;
 
     private Integer level;  //层级
 
@@ -32,4 +36,7 @@ public class SelectCategoryVO {
     private SelectCategoryLevelVO categoryLevelVo;  //父类类别信息
 
     private Boolean ifChild = false;  //是否有子集
+
+    @Schema(description = "文件信息")
+    private List<SystemFile> systemFileList;
 }

+ 93 - 7
src/main/java/com/example/xiaoshiweixinback/service/ProductCategoryService.java

@@ -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 {