ソースを参照

修改机构 新增刷新子机构Path 字段

zhulu 2 年 前
コミット
df42dd8330

+ 20 - 18
soc-modules/soc-modules-system/src/main/java/com/xunmei/system/service/impl/SysOrgServiceImpl.java

@@ -27,6 +27,7 @@ import org.springframework.transaction.annotation.Transactional;
 import javax.annotation.PostConstruct;
 import java.util.*;
 import java.util.stream.Collectors;
+import java.util.stream.Stream;
 
 /**
  * 【请填写功能名称】Service业务层处理
@@ -297,14 +298,8 @@ public class SysOrgServiceImpl extends ServiceImpl<SysOrgMapper, SysOrg> impleme
         if (ObjectUtil.isEmpty(org.getShortName())) {
             org.setShortName(org.getName());
         }
-//        if (StringUtils.isEmpty(org.getManagerPhone())) {
-//                org.setManagerPhone(org.getPhone());
-//        }
         boolean isOk = false;
         if (org.getId() != null) {
-//            if (StringUtils.isEmpty(org.getManagerPhone())) {
-//                org.setManagerPhone(org.getPhone());
-//            }
             //修改前的原始机构对象
             final SysOrg originalOrg = getById(org.getId());
             //仅系统新增的机构可以修改层级,同步到系统的机构不允许修改机构层级
@@ -320,11 +315,13 @@ public class SysOrgServiceImpl extends ServiceImpl<SysOrgMapper, SysOrg> impleme
                     org.setTreeShowParentId(parentOrg.getId());
 
                     //ToDo 刷新当前机构下所有子机构 path
-                    //final List<SysOrg> childOrgList = getAllChildOrgList(originalOrg.getPath());
+                    List<SysOrg> allChildOrgList= reSetOrgAllChildOrgPath(org,originalOrg);
+                    this.saveOrUpdateBatch(allChildOrgList);
                 }
             }
 
             isOk = this.updateById(org);
+
         } else {
             SysOrg parentOrg = sysOrgMapper.selectById(org.getParentId());
             org.setParentGuid(parentOrg.getGuid());
@@ -333,10 +330,6 @@ public class SysOrgServiceImpl extends ServiceImpl<SysOrgMapper, SysOrg> impleme
             org.setId(id);
             org.setPath(parentOrg.getPath() + id + "-");
             org.setTreeShowPath(parentOrg.getPath() + id + "-");
-
-//            if (StringUtils.isEmpty(org.getManagerPhone())) {
-//                org.setManagerPhone(org.getPhone());
-//            }
             isOk = this.save(org);
         }
         /*
@@ -365,19 +358,28 @@ public class SysOrgServiceImpl extends ServiceImpl<SysOrgMapper, SysOrg> impleme
                 .eq(SysOrg::getDeleted, 0));
     }
 
-    private void reSetOrgAllChildOrgPath(SysOrg newOrg,SysOrg originalOrg)
+    private List<SysOrg> reSetOrgAllChildOrgPath(SysOrg newOrg,SysOrg originalOrg)
     {
-        final List<SysOrg> childOrgList = getAllChildOrgList(originalOrg.getPath());
-        if(ObjectUtil.isEmpty(childOrgList))
+        final List<SysOrg> allChildOrgList = getAllChildOrgList(originalOrg.getPath());
+        if(ObjectUtil.isEmpty(allChildOrgList))
         {
-            return;
+           return allChildOrgList;
         }
-
+        reSetOrgPath(newOrg,allChildOrgList);
+        return allChildOrgList;
     }
 
-    private void reSetOrgPath(SysOrg parentOrg,List<SysOrg> childOrgList)
+    private void reSetOrgPath(SysOrg parentOrg,List<SysOrg> allChildOrgList)
     {
-
+        final List<SysOrg> chillOrgList = allChildOrgList.stream().filter(child -> ObjectUtil.equal(parentOrg.getId(), child.getParentId())).collect(Collectors.toList());
+        if(ObjectUtil.isEmpty(chillOrgList)){
+            return;
+        }
+        chillOrgList.stream().forEach(child->{
+            child.setPath(parentOrg.getPath()+child.getId()+"-");
+            child.setTreeShowPath(parentOrg.getTreeShowPath()+child.getId()+"-");
+            reSetOrgPath(child,allChildOrgList);
+        });
     }