Explorar o código

同步-单表同步-公式同步修改逻辑 调整回去

LHB hai 1 mes
pai
achega
429f5082ee

+ 24 - 25
blade-service/blade-manager/src/main/java/org/springblade/manager/service/impl/WbsSynchronousEViSaServiceImpl.java

@@ -14,7 +14,10 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
-import java.util.*;
+import java.util.Comparator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
 import java.util.stream.Collectors;
 
 /**
@@ -52,7 +55,9 @@ public class WbsSynchronousEViSaServiceImpl {
         List<Long> ids = collect.stream().map(WbsTreePrivate::getPKeyId).collect(Collectors.toList());
         List<Long> parentIds = collect.stream().map(WbsTreePrivate::getParentId).collect(Collectors.toList());
         //节点公式同步
-        saveFormula(Long.valueOf(wbsTreePrivate.getProjectId()), wbsTreePrivate.getParentId(), parentIds);
+        for (Long parentId : parentIds) {
+            saveFormula(Long.valueOf(wbsTreePrivate.getProjectId()), wbsTreePrivate.getParentId(), parentId);
+        }
 
         wbsTreePrivateMapper.update(null, Wrappers.<WbsTreePrivate>lambdaUpdate()
                 .set(WbsTreePrivate::getHtmlUrl, wbsTreePrivate.getHtmlUrl())
@@ -223,37 +228,31 @@ public class WbsSynchronousEViSaServiceImpl {
      * 同项目下不同节点 不同的节点公式
      * @param projectId 项目id
      * @param tempParentId 源节点父级id
-     * @param parentIds 节点父级id
+     * @param parentId 节点父级id
      */
-    public void saveFormula(Long projectId, Long tempParentId, List<Long> parentIds) {
+    public void saveFormula(Long projectId, Long tempParentId, Long parentId) {
 
         List<ElementFormulaMapping> tempElementFormulaMappings = elementFormulaMappingService.list(Wrappers.<ElementFormulaMapping>lambdaQuery()
                 .eq(ElementFormulaMapping::getProjectId, projectId)
                 .in(ElementFormulaMapping::getNodeId, tempParentId));
         List<ElementFormulaMapping> elementFormulaMappings = elementFormulaMappingService.list(Wrappers.<ElementFormulaMapping>lambdaQuery()
                 .eq(ElementFormulaMapping::getProjectId, projectId)
-                .in(ElementFormulaMapping::getNodeId, parentIds));
-        Map<Long, List<ElementFormulaMapping>> collect = elementFormulaMappings.stream().collect(Collectors.groupingBy(ElementFormulaMapping::getNodeId));
-
-        Set<Long> longs = collect.keySet();
-
-        List<ElementFormulaMapping> collect2 = new ArrayList<>();
-
-        for (Long parentId : longs) {
-            List<ElementFormulaMapping> list = collect.get(parentId);
-            List<Long> collect3 = list.stream().map(ElementFormulaMapping::getElementId).collect(Collectors.toList());
-            //当前节点不存在的元素公式
-            List<ElementFormulaMapping> collect1 = tempElementFormulaMappings.stream().filter(f -> !collect3.contains(f.getElementId())).collect(Collectors.toList());
-            collect1.forEach(f -> {
-                f.setId(SnowFlakeUtil.getId());
-                f.setProjectId(projectId);
-                f.setNodeId(parentId);
-                f.setCreateTime(DateTime.now());
-            });
-            collect2.addAll(collect1);
-        }
+                .in(ElementFormulaMapping::getNodeId, parentId));
+        List<Long> collect = elementFormulaMappings.stream().map(ElementFormulaMapping::getElementId).collect(Collectors.toList());
+
+        //当前节点不存在的元素公式
+        List<ElementFormulaMapping> collect1 = tempElementFormulaMappings.stream().filter(f -> !collect.contains(f.getElementId())).collect(Collectors.toList());
+
+
+        collect1.forEach(f -> {
+            f.setId(SnowFlakeUtil.getId());
+            f.setProjectId(projectId);
+            f.setNodeId(parentId);
+            f.setCreateTime(DateTime.now());
+        });
+
         //复制新增模板节点的公式
-        elementFormulaMappingService.saveBatch(collect2);
+        elementFormulaMappingService.saveBatch(collect1);
 
     }
 }