Browse Source

优化组织架构

zhou-hao 7 years ago
parent
commit
9ef3d6448d

+ 5 - 0
hsweb-system/hsweb-system-organizational/hsweb-system-organizational-authorization/src/main/java/org/hswebframework/web/organizational/authorization/PersonnelAuthorization.java

@@ -81,6 +81,11 @@ public interface PersonnelAuthorization extends Serializable {
      */
      */
     Set<TreeNode<String>> getDepartmentIds();
     Set<TreeNode<String>> getDepartmentIds();
 
 
+    /**
+     * 获取人员的所有职位信息
+     *
+     * @return 职位信息
+     */
     Set<Position> getPositions();
     Set<Position> getPositions();
 
 
     default Optional<Position> getPosition(String id) {
     default Optional<Position> getPosition(String id) {

+ 23 - 11
hsweb-system/hsweb-system-organizational/hsweb-system-organizational-service/hsweb-system-organizational-service-simple/src/main/java/org/hswebframework/web/service/organizational/simple/SimplePersonService.java

@@ -297,23 +297,34 @@ public class SimplePersonService extends GenericEntityService<PersonEntity, Stri
         //获取所有职位,并得到根职位(树结构)
         //获取所有职位,并得到根职位(树结构)
         List<PositionEntity> positionEntities = getAllChildrenAndReturnRootNode(positionDao, positionIds, PositionEntity::setChildren, rootPosList -> {
         List<PositionEntity> positionEntities = getAllChildrenAndReturnRootNode(positionDao, positionIds, PositionEntity::setChildren, rootPosList -> {
             //根据职位获取部门
             //根据职位获取部门
-            Set<String> departmentIds = rootPosList.stream().map(PositionEntity::getDepartmentId).collect(Collectors.toSet());
-            rootPosList.forEach(positionEntity -> positionCache.put(positionEntity.getId(), positionEntity));
+            Set<String> departmentIds = rootPosList.stream()
+                    .peek(positionEntity -> positionCache.put(positionEntity.getId(), positionEntity))
+                    .map(PositionEntity::getDepartmentId)
+                    .collect(Collectors.toSet());
+//            rootPosList.forEach(positionEntity -> positionCache.put(positionEntity.getId(), positionEntity));
             if (!CollectionUtils.isEmpty(departmentIds)) {
             if (!CollectionUtils.isEmpty(departmentIds)) {
                 List<DepartmentEntity> departmentEntities = getAllChildrenAndReturnRootNode(departmentDao, departmentIds, DepartmentEntity::setChildren, rootDepList -> {
                 List<DepartmentEntity> departmentEntities = getAllChildrenAndReturnRootNode(departmentDao, departmentIds, DepartmentEntity::setChildren, rootDepList -> {
-                    rootDepList.forEach(departmentEntity -> departmentCache.put(departmentEntity.getId(), departmentEntity));
+                    //rootDepList.forEach(departmentEntity -> departmentCache.put(departmentEntity.getId(), departmentEntity));
                     //根据部门获取机构
                     //根据部门获取机构
-                    Set<String> orgIds = rootDepList.stream().map(DepartmentEntity::getOrgId).collect(Collectors.toSet());
+                    Set<String> orgIds = rootDepList.stream()
+                            .peek(departmentEntity -> departmentCache.put(departmentEntity.getId(), departmentEntity))
+                            .map(DepartmentEntity::getOrgId)
+                            .collect(Collectors.toSet());
+
                     if (!CollectionUtils.isEmpty(orgIds)) {
                     if (!CollectionUtils.isEmpty(orgIds)) {
                         List<OrganizationalEntity> orgEntities = getAllChildrenAndReturnRootNode(organizationalDao, orgIds, OrganizationalEntity::setChildren, rootOrgList -> {
                         List<OrganizationalEntity> orgEntities = getAllChildrenAndReturnRootNode(organizationalDao, orgIds, OrganizationalEntity::setChildren, rootOrgList -> {
-                            rootOrgList.forEach(org -> orgCache.put(org.getId(), org));
+//                            rootOrgList.forEach(org -> orgCache.put(org.getId(), org));
                             //根据机构获取行政区域
                             //根据机构获取行政区域
-                            Set<String> districtIds = rootOrgList.stream().map(OrganizationalEntity::getDistrictId).filter(Objects::nonNull).collect(Collectors.toSet());
+                            Set<String> districtIds = rootOrgList.stream()
+                                    .peek(org -> orgCache.put(org.getId(), org))
+                                    .map(OrganizationalEntity::getDistrictId)
+                                    .filter(Objects::nonNull)
+                                    .collect(Collectors.toSet());
                             if (!CollectionUtils.isEmpty(districtIds)) {
                             if (!CollectionUtils.isEmpty(districtIds)) {
                                 List<DistrictEntity> districtEntities =
                                 List<DistrictEntity> districtEntities =
-                                        getAllChildrenAndReturnRootNode(districtDao, districtIds, DistrictEntity::setChildren, rootDistrictList -> {
-                                            rootDistrictList.forEach(dist -> districtCache.put(dist.getId(), dist));
-                                        });
+                                        getAllChildrenAndReturnRootNode(districtDao, districtIds, DistrictEntity::setChildren,
+                                                rootDistrictList -> rootDistrictList.forEach(dist -> districtCache.put(dist.getId(), dist)));
+
                                 authorization.setDistrictIds(transformationTreeNode(null, districtEntities));
                                 authorization.setDistrictIds(transformationTreeNode(null, districtEntities));
                             }
                             }
                         });
                         });
@@ -365,7 +376,8 @@ public class SimplePersonService extends GenericEntityService<PersonEntity, Stri
                             .department(department)
                             .department(department)
                             .code("")
                             .code("")
                             .build();
                             .build();
-                }).filter(Objects::nonNull)
+                })
+                .filter(Objects::nonNull)
                 .collect(Collectors.toSet());
                 .collect(Collectors.toSet());
         authorization.setPositions(positions);
         authorization.setPositions(positions);
         //获取关系
         //获取关系
@@ -404,7 +416,7 @@ public class SimplePersonService extends GenericEntityService<PersonEntity, Stri
                                                                                             Set<String> rootIds,
                                                                                             Set<String> rootIds,
                                                                                             BiConsumer<T, List<T>> childAccepter,
                                                                                             BiConsumer<T, List<T>> childAccepter,
                                                                                             Consumer<List<T>> rootConsumer) {
                                                                                             Consumer<List<T>> rootConsumer) {
-        if (rootIds.isEmpty()) {
+        if (CollectionUtils.isEmpty(rootIds)) {
             return Collections.emptyList();
             return Collections.emptyList();
         }
         }
         //获取根节点
         //获取根节点