Jelajahi Sumber

公有、私有wbs树节点排序相关

liuyc 3 tahun lalu
induk
melakukan
4892af9c8b

+ 7 - 2
blade-service/blade-manager/src/main/java/org/springblade/manager/service/impl/WbsTreePrivateServiceImpl.java

@@ -29,6 +29,7 @@ import org.springframework.transaction.annotation.Transactional;
 import java.util.ArrayList;
 import java.util.Comparator;
 import java.util.List;
+import java.util.Optional;
 import java.util.stream.Collectors;
 
 /**
@@ -89,8 +90,12 @@ public class WbsTreePrivateServiceImpl extends BaseServiceImpl<WbsTreePrivateMap
                 return true;
             }).collect(Collectors.toList());
             //获取最大Sort
-            Integer sortMax = collect.stream().max(Comparator.comparingInt(WbsTreePrivate::getSort)).get().getSort();
-            wbsTreePrivate.setSort(sortMax + 1);
+            Optional<WbsTreePrivate> max = collect.stream().max(Comparator.comparingInt(WbsTreePrivate::getSort));
+            Integer sort = 0;
+            if (max.isPresent()) {
+                sort = max.get().getSort();
+            }
+            wbsTreePrivate.setSort(sort + 1);
 
             //新增
             int row = baseMapper.insert(wbsTreePrivate);

+ 6 - 2
blade-service/blade-manager/src/main/java/org/springblade/manager/service/impl/WbsTreeServiceImpl.java

@@ -133,8 +133,12 @@ public class WbsTreeServiceImpl extends BaseServiceImpl<WbsTreeMapper, WbsTree>
                 return true;
             }).collect(Collectors.toList());
             //获取最大Sort
-            Integer sortMax = collect.stream().max(Comparator.comparingInt(WbsTree::getSort)).get().getSort();
-            wbsTree.setSort(sortMax + 1);
+            Optional<WbsTree> max = collect.stream().max(Comparator.comparingInt(WbsTree::getSort));
+            Integer sort = 0;
+            if (max.isPresent()) {
+                sort = max.get().getSort();
+            }
+            wbsTree.setSort(sort + 1);
         }
         return saveOrUpdate(wbsTree);
     }