Bläddra i källkod

Merge remote-tracking branch 'origin/V0.0.2' into V0.0.2

jingyuanchao 2 år sedan
förälder
incheckning
06349e1362

+ 0 - 9
soc-modules/soc-modules-system/src/main/java/com/xunmei/system/controller/SysDeptController.java

@@ -114,15 +114,6 @@ public class SysDeptController extends BaseController {
         if (dept.getParentId().equals(deptId)) {
             return error("修改机构'" + dept.getName() + "'失败,上级机构不能是自己");
         }
-        //获取选择的父机构数据
-        SysOrg byId = orgService.getById(dept.getParentId());
-        //更新机构对应的path
-        if(ObjectUtil.isEmpty(dept.getShortName())){
-            dept.setShortName(dept.getName());
-        }
-        dept.setPath(byId.getPath()+dept.getId()+"-");
-        dept.setTreeShowPath(byId.getTreeShowPath()+dept.getId()+"-");
-        dept.setTreeShowParentId(byId.getId());
 
         dept.setUpdateBy(SecurityUtils.getUsername());
         dept.setUpdateTime(new Date());

+ 57 - 10
soc-modules/soc-modules-system/src/main/java/com/xunmei/system/service/impl/SysOrgServiceImpl.java

@@ -11,7 +11,6 @@ import com.xunmei.common.core.constant.CacheConstants;
 import com.xunmei.common.core.constant.Constants;
 import com.xunmei.common.core.exception.ServiceException;
 import com.xunmei.common.core.utils.DateUtils;
-import com.xunmei.common.core.utils.StringUtils;
 import com.xunmei.common.core.web.page.TableDataInfo;
 import com.xunmei.common.redis.utils.RedisUtils;
 import com.xunmei.common.security.utils.SecurityUtils;
@@ -295,24 +294,49 @@ public class SysOrgServiceImpl extends ServiceImpl<SysOrgMapper, SysOrg> impleme
     @Override
     @Transactional(rollbackFor = Exception.class)
     public boolean saveOrUpdateOrg(SysOrg org) {
+        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());
+//            if (StringUtils.isEmpty(org.getManagerPhone())) {
+//                org.setManagerPhone(org.getPhone());
+//            }
+            //修改前的原始机构对象
+            final SysOrg originalOrg = getById(org.getId());
+            //仅系统新增的机构可以修改层级,同步到系统的机构不允许修改机构层级
+            if(ObjectUtil.equal(originalOrg.getSource(),0)) {
+                //父级机构发生变化后,修改机构path ,以及下级机构path
+                if(!ObjectUtil.equal(originalOrg.getParentId(),org.getParentId())){
+                    //获取选择的父机构数据
+                    SysOrg parentOrg = getById(org.getParentId());
+                    //更新机构对应的业务path
+                    org.setPath(parentOrg.getPath() + org.getId() + "-");
+                    //更新机构对应的机构树path
+                    org.setTreeShowPath(parentOrg.getTreeShowPath() + org.getId() + "-");
+                    org.setTreeShowParentId(parentOrg.getId());
+
+                    //ToDo 刷新当前机构下所有子机构 path
+                    //final List<SysOrg> childOrgList = getAllChildOrgList(originalOrg.getPath());
+                }
             }
+
             isOk = this.updateById(org);
         } else {
-            SysOrg sysOrg = sysOrgMapper.selectById(org.getParentId());
-            org.setParentGuid(sysOrg.getGuid());
+            SysOrg parentOrg = sysOrgMapper.selectById(org.getParentId());
+            org.setParentGuid(parentOrg.getGuid());
             org.setDeleted(0);
             long id = IdWorker.getId();
             org.setId(id);
-            org.setPath(sysOrg.getPath() + id + "-");
-            org.setTreeShowPath(sysOrg.getPath() + id + "-");
+            org.setPath(parentOrg.getPath() + id + "-");
+            org.setTreeShowPath(parentOrg.getPath() + id + "-");
 
-            if (StringUtils.isEmpty(org.getManagerPhone())) {
-                org.setManagerPhone(org.getPhone());
-            }
+//            if (StringUtils.isEmpty(org.getManagerPhone())) {
+//                org.setManagerPhone(org.getPhone());
+//            }
             isOk = this.save(org);
         }
         /*
@@ -334,6 +358,29 @@ public class SysOrgServiceImpl extends ServiceImpl<SysOrgMapper, SysOrg> impleme
         return rel;
     }
 
+    private List<SysOrg> getAllChildOrgList(String path)
+    {
+        return sysOrgMapper.selectList(new LambdaQueryWrapper<SysOrg>()
+                .likeRight(SysOrg::getPath, path)
+                .eq(SysOrg::getDeleted, 0));
+    }
+
+    private void reSetOrgAllChildOrgPath(SysOrg newOrg,SysOrg originalOrg)
+    {
+        final List<SysOrg> childOrgList = getAllChildOrgList(originalOrg.getPath());
+        if(ObjectUtil.isEmpty(childOrgList))
+        {
+            return;
+        }
+
+    }
+
+    private void reSetOrgPath(SysOrg parentOrg,List<SysOrg> childOrgList)
+    {
+
+    }
+
+
     private static List<SysOrg> handleTree(Map<Long, List<SysOrg>> map, Long parentId) {
         List<SysOrg> orgList = map.get(parentId);
         if (ObjectUtil.isNotEmpty(orgList)) {