浏览代码

同步-单表同步-节点公式同步

LHB 1 月之前
父节点
当前提交
66f293624d

+ 41 - 2
blade-service/blade-manager/src/main/java/org/springblade/manager/service/impl/WbsSynchronousEViSaServiceImpl.java

@@ -51,13 +51,20 @@ public class WbsSynchronousEViSaServiceImpl {
     }
 
     @Transactional(rollbackFor = Exception.class)
-    public void updateSyncPrivateForm(WbsTreePrivate wbsTreePrivate, List<Long> collect, Long id,String errorMsg) {
+    public void updateSyncPrivateForm(WbsTreePrivate wbsTreePrivate, List<WbsTreePrivate> collect, Long id,String errorMsg) {
+        List<Long> ids = collect.stream().map(WbsTreePrivate::getPKeyId).collect(Collectors.toList());
+        List<Long> parentIds = collect.stream().map(WbsTreePrivate::getParentId).collect(Collectors.toList());
+        //节点公式同步
+        for (Long parentId : parentIds) {
+            saveFormula(Long.valueOf(wbsTreePrivate.getProjectId()), wbsTreePrivate.getParentId(), parentId);
+        }
+
         wbsTreePrivateMapper.update(null, Wrappers.<WbsTreePrivate>lambdaUpdate()
                 .set(WbsTreePrivate::getHtmlUrl, wbsTreePrivate.getHtmlUrl())
                 .set(wbsTreePrivate.getExcelId()!=null,WbsTreePrivate::getIsLinkTable, 2)
                 .set(WbsTreePrivate::getExcelId, wbsTreePrivate.getExcelId())
                 .set(WbsTreePrivate::getInitTableId, wbsTreePrivate.getInitTableId())
-                .in(WbsTreePrivate::getPKeyId, collect)
+                .in(WbsTreePrivate::getPKeyId, ids)
         );
         synchronousRecordMapper.update(null, Wrappers.<WbsTreeSynchronousRecord>lambdaUpdate()
                 .set(WbsTreeSynchronousRecord::getStatus, 2)
@@ -216,4 +223,36 @@ public class WbsSynchronousEViSaServiceImpl {
         elementFormulaMappingService.saveBatch(elementFormulaMappings);
 
     }
+
+    /**
+     * 同项目下不同节点 不同的节点公式
+     * @param projectId 项目id
+     * @param tempParentId 源节点父级id
+     * @param parentId 节点父级id
+     */
+    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, 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(collect1);
+
+    }
 }

+ 3 - 3
blade-service/blade-manager/src/main/java/org/springblade/manager/service/impl/WbsSynchronousServiceImpl.java

@@ -152,7 +152,7 @@ public class WbsSynchronousServiceImpl {
             collect.addAll(collect1);
         }
         //清表不同的数据
-        List<WbsTreePrivate> noExcelIdEq = wbsTreePrivates.stream().filter(f -> !Objects.equals(f.getExcelId(), wbsTreePrivate.getExcelId())).collect(Collectors.toList());
+        List<WbsTreePrivate> noExcelIdEq = wbsTreePrivates.stream().filter(f -> f.getExcelId()!=null && !Objects.equals(f.getExcelId(), wbsTreePrivate.getExcelId())).collect(Collectors.toList());
         StringBuilder sb = new StringBuilder();
         if (CollectionUtil.isNotEmpty(noExcelIdEq)) {
             for (WbsTreePrivate treePrivate : noExcelIdEq) {
@@ -163,9 +163,9 @@ public class WbsSynchronousServiceImpl {
             }
 //            throw new ServiceException("清表绑定错误:" + sb);
         }
-        List<Long> ids = collect.stream().map(WbsTreePrivate::getPKeyId).collect(Collectors.toList());
+
         //修改数据
-        wbsSynchronousEViSaService.updateSyncPrivateForm(wbsTreePrivate, ids, wbsTreeSynchronousRecord.getId(),sb.toString());
+        wbsSynchronousEViSaService.updateSyncPrivateForm(wbsTreePrivate, collect, wbsTreeSynchronousRecord.getId(),sb.toString());
     }
 
     /**