ソースを参照

Merge branch 'V0.0.2' of http://10.87.10.227:4000/jzyd_yyds/soc into V0.0.2

jiawuxian 2 年 前
コミット
26f569a03b

+ 15 - 0
soc-api/soc-api-system/src/main/java/com/xunmei/system/api/Eto/SysOrgTreeRequestDto.java

@@ -0,0 +1,15 @@
+package com.xunmei.system.api.Eto;
+
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+
+@Data
+public class SysOrgTreeRequestDto {
+
+    private Long orgId;
+
+    private Boolean includeSub=false;
+}

+ 2 - 0
soc-api/soc-api-system/src/main/java/com/xunmei/system/api/vo/SysOrgVO.java

@@ -23,6 +23,8 @@ import java.util.stream.Collectors;
 public class SysOrgVO {
     @JsonSerialize(using = ToStringSerializer.class)
     private Long id;
+
+    private String code;
     private String name;
     private String path;
     @JsonSerialize(using = ToStringSerializer.class)

+ 2 - 1
soc-common/soc-common-core/src/main/java/com/xunmei/common/core/domain/drill/vo/CoreDrillDictionaryPageVo.java

@@ -19,7 +19,8 @@ public class CoreDrillDictionaryPageVo {
     @JsonSerialize(using = ToStringSerializer.class)
     private Long id;
 
-    private Long orgId;
+    @ApiModelProperty(value = "参考演练创建机构")
+    private String orgId;
 
     @ApiModelProperty(value = "机构名称")
     private String orgName;

+ 1 - 1
soc-modules/soc-modules-core/src/main/java/com/xunmei/core/drill/controller/CoreDrillDictionaryController.java

@@ -47,7 +47,7 @@ public class CoreDrillDictionaryController extends BaseController {
      * 获取预案演练库详细信息
      */
     @ApiOperation(value = "获取CoreDrillDictionary详细信息")
-    @RequiresPermissions("core:drillDictionary:query")
+    @RequiresPermissions("core:drillDictionary:edit")
     @GetMapping(value = "/{id}")
     public AjaxResult getInfo(@PathVariable("id") Long id) {
         return success(coreDrillDictionaryService.selectCoreDrillDictionaryById(id));

+ 10 - 0
soc-modules/soc-modules-sync/src/main/java/com/xunmei/sync/config/ThirdPartySystemConfig.java

@@ -21,6 +21,16 @@ public class ThirdPartySystemConfig {
      * 同步机构时自建机构的名称
      */
     private String fjnxSyncOrgCustomOrgName;
+
+    /**
+     * 同步机构时自建顶级机构的名称
+     */
+    private String fjnxSyncOrgCustomRootOrgName;
+    /**
+     * 同步机构时自建顶级机构的名称
+     */
+    private String fjnxSyncOrgCustomRootOrgCode;
+
     /**
      * 同步用户默认密码
      */

+ 14 - 4
soc-modules/soc-modules-sync/src/main/java/com/xunmei/sync/domain/FjnxOrgBusinessRelation.java

@@ -34,15 +34,25 @@ public class FjnxOrgBusinessRelation implements Serializable {
     @TableField("org_code")
     private String orgCode;
 
-//    @ApiModelProperty(value = "业务父级Id")
-//    @TableField("business_parent_id")
-//    @JsonSerialize(using = ToStringSerializer.class)
-//    private Long businessParentId;
+    @ApiModelProperty(value = "同步配置表自定义机构类型 1:省联社 2:办事处 3: 地区行社")
+    @TableField("org_type")
+    private Integer orgType;
 
     @ApiModelProperty(value = "业务父级机构编码")
     @TableField("business_parent_code")
     private String businessParentCode;
 
+
+    @ApiModelProperty(value = "机构树上显示父级机构编码")
+    @TableField("tree_show_parent_code")
+    private String treeShowParentCode;
+
+    @ApiModelProperty(value = "办事处对应的地区行社机构")
+    @TableField("dqhs_org_code")
+    private String DqhsOrgCode;
+
+
+
 //    @ApiModelProperty(value = "机构层级")
 //    @TableField("org_level")
 //    private Integer orgLevel;

+ 240 - 44
soc-modules/soc-modules-sync/src/main/java/com/xunmei/sync/service/impl/FJNXSyncServiceImpl.java

@@ -25,15 +25,12 @@ import com.xunmei.system.api.domain.SysOrg;
 import com.xunmei.system.api.domain.SysUser;
 import io.netty.util.internal.StringUtil;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.collections4.CollectionUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
-import javax.annotation.Resource;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-import java.util.Optional;
+import java.util.*;
 import java.util.stream.Collectors;
 
 /**
@@ -79,7 +76,6 @@ public class FJNXSyncServiceImpl implements IFJNXSyncService {
             return "未获取到用户信息数据";
         }
 
-
         // 将同步到的用户数据线保存下来
         List<FjnxUser> fjnxUserList = FjnxXmlUsersDtoConvertToFjnxUsers(fjnxXmlUserDto.getUserVos());
         ifjnxUserService.saveOrUpdateBatch(fjnxUserList);
@@ -100,22 +96,30 @@ public class FJNXSyncServiceImpl implements IFJNXSyncService {
         }
         List<SysOrg> existOrgList = existAllOrgResult.getData();
 
+        // 获取到机构同步时 保留的同步机构原始数据
         List<FjnxOrg> existFjnxOrgList = ifjnxOrgService.list();
 
-        //将FJNXUser 转换为SysUser 并保存
+        //获取配置表中配置的 数据拿到办事处和地区行社的机构编码 以及映射关系
+        List<FjnxOrgBusinessRelation> specialOrgList = fjnxOrgBusinessRelationMapper.selectList(Wrappers.emptyWrapper());
+
+
+        //系统中不存在同步用户时 将FJNXUser 转换为SysUser 并保存
         if (ObjectUtil.isEmpty(existUserList)) {
-            final R<Boolean> booleanR = remoteUserService.batchSaveSyncUser(FjnxUsersConvertToUsers(fjnxXmlUserDto.getUserVos(), existOrgList, existFjnxOrgList), SecurityConstants.INNER);
+            final R<Boolean> booleanR = remoteUserService.batchSaveSyncUser(FjnxUsersConvertToUsers(fjnxXmlUserDto.getUserVos(), existOrgList, existFjnxOrgList,specialOrgList), SecurityConstants.INNER);
             if (booleanR != null && booleanR.getCode() != 200) {
                 log.error("调用远程服务接口remoteUserService.batchSaveSyncOrg 失败:{}", booleanR.getMsg());
                 return "remoteUserService.batchSaveSyncUser 调用失败:" + booleanR.getMsg();
             }
             return null;
         }
+
+        // 系统中存在已同步的用户时
         List<SysUser> addList = new ArrayList<>();
         List<SysUser> updateList = new ArrayList<>();
         List<SysUser> deleteList = new ArrayList<>();
         List<String> fjnxUserCodeList = new ArrayList<>();
 
+
         fjnxXmlUserDto.getUserVos().forEach(fjnxUser -> {
             String orgCode = fjnxUser.getDepCode();
             if (!StringUtil.isNullOrEmpty(orgCode) && !StringUtil.isNullOrEmpty(fjnxUser.getUserId())) {
@@ -123,13 +127,9 @@ public class FJNXSyncServiceImpl implements IFJNXSyncService {
 
                 Optional<SysOrg> optionalOrg = existOrgList.stream().filter(x -> orgCode.equals(x.getCode())).findFirst();
 
-                SysOrg userBusinessSysOrg = getUserBusinessFjnxOrg(existFjnxOrgList, existOrgList, fjnxUser);
-                if (optionalOrg.isPresent() && ObjectUtil.isNotEmpty(userBusinessSysOrg)) {
-//                    final Optional<SysOrg> businessSysOrgOptional = existOrgList.stream().filter(x -> userBusinessFjnxOrg.getOrgCode().equals(x.getCode())).findFirst();
-//                    if(!businessSysOrgOptional.isPresent())
-//                    {
-//                        return;
-//                    }
+                // 获取用户的业务机构信息
+                SysOrg userBusinessSysOrg = getUserBusinessFjnxOrg(existFjnxOrgList, existOrgList, fjnxUser,specialOrgList);
+                if (optionalOrg.isPresent()) {
                     Optional<SysUser> optionalUser = existUserList.stream().filter(x -> fjnxUser.getUserId().equals(x.getCode())).findFirst();
                     if (optionalUser.isPresent()) {
                         updateList.add(FjnxUserConvertToUser(fjnxUser, optionalUser.get(), optionalOrg.get(), userBusinessSysOrg));
@@ -140,9 +140,12 @@ public class FJNXSyncServiceImpl implements IFJNXSyncService {
                     log.error("同步人员【{}】所属机构编码【{}】在当前数据库中未找到,{}", fjnxUser.getUserId() + fjnxUser.getUserName(), fjnxUser.getDepCode(), fjnxUser);
                 }
             }
+            else{
+                log.error("同步人员【{}】没有机构编码或者用户id,机构编码【{}】,用户id【{}】,{}", fjnxUser.getUserName(), fjnxUser.getDepCode(),fjnxUser.getUserId(), fjnxUser);
+            }
         });
 
-        // 人员在本系统中存在 但是在统一运营门户中不存在
+        // 已同步的人员在本系统中存在 但是在统一运营门户中不存在,标记为删除
         deleteList = existUserList.stream().filter(entity -> !fjnxUserCodeList.contains(entity.getCode()) && entity.getSource() == 1).collect(Collectors.toList());
         deleteList.forEach(x -> x.setDeleted(1));
         existUserList.addAll(addList);
@@ -170,7 +173,7 @@ public class FJNXSyncServiceImpl implements IFJNXSyncService {
             return "未获取到机构信息数据";
         }
 
-        List<FjnxOrg> fjnxOrgList = ConvertXmlOrgDtoToOrgJinx(fjnxXmlOrgDto.getOrgVos());
+        List<FjnxOrg> fjnxOrgList = ConvertXmlOrgDtoToOrgFjnx(fjnxXmlOrgDto.getOrgVos());
         ifjnxOrgService.saveOrUpdateBatch(fjnxOrgList);
 
         R<List<SysOrg>> existAllOrgResult = remoteOrgService.getAllOrg(SecurityConstants.INNER);
@@ -606,12 +609,15 @@ public class FJNXSyncServiceImpl implements IFJNXSyncService {
         org.setShortName(getOrgShortName(fjnxOrgDto));
         org.setCode(fjnxOrgDto.getOrgCode());
         org.setGuid(fjnxOrgDto.getOrgCode());
+        if(fjnxOrgDto.getShortName().endsWith("办事处"))
+        {
+            String a="";
+        }
         org.setParentGuid(fjnxOrgDto.getBusinessParentCode());
         org.setTreeParentCode(fjnxOrgDto.getTreeShowParentCode());
         org.setPhone(fjnxOrgDto.getOrgPhone());
         org.setAddress(fjnxOrgDto.getOrgAddress());
-        //我们系统自己可以调整顺序, 不覆盖sort的值
-//        org.setSort(ConvertOrgOrderValue(fjnxOrgDto.getOrgOrder()));
+        org.setSort(ConvertOrgOrderValue(fjnxOrgDto.getOrgOrder()));
         org.setUpdateTime(fjnxOrgDto.getUpdateTime());
         org.setRemark(fjnxOrgDto.getRemark());
         //org.setLevel(fjnxOrgDto.getOrgPath().split("/").length);
@@ -686,11 +692,14 @@ public class FJNXSyncServiceImpl implements IFJNXSyncService {
         org.setCode(fjnxOrg.getOrgCode());
         org.setGuid(fjnxOrg.getOrgCode());
         org.setParentGuid(fjnxOrg.getBusinessParentCode());
+        if(fjnxOrg.getShortName().equals("泉州办事处"))
+        {
+            String a="";
+        }
         org.setTreeParentCode(fjnxOrg.getTreeShowParentCode());
         org.setPhone(fjnxOrg.getOrgPhone());
         org.setAddress(fjnxOrg.getOrgAddress());
-        //我们系统自己可以调整顺序, 不覆盖sort的值
-//        org.setSort(ConvertOrgOrderValue(fjnxOrg.getOrgOrder()));
+        org.setSort(ConvertOrgOrderValue(fjnxOrg.getOrgOrder()));
         org.setUpdateTime(fjnxOrg.getUpdateTime());
         org.setRemark(fjnxOrg.getRemark());
 //        org.setLevel(fjnxOrg.getOrgPath().split("/").length);
@@ -746,16 +755,24 @@ public class FJNXSyncServiceImpl implements IFJNXSyncService {
     }
 
 
-    private List<SysUser> FjnxUsersConvertToUsers(List<FJNXUserDto> fjnxUserDtoList, List<SysOrg> orgList, List<FjnxOrg> fjnxOrgList) {
+    /**
+     *
+     * @param fjnxUserDtoList 同步获取到的用户信息
+     * @param orgList 系统中的机构信息
+     * @param fjnxOrgList 福建nx的机构信息
+     * @param specialOrgList 配置表中配置的 特殊机构信息,地区行社、办事处、以及他们的对应关系
+     * @return
+     */
+    private List<SysUser> FjnxUsersConvertToUsers(List<FJNXUserDto> fjnxUserDtoList, List<SysOrg> orgList, List<FjnxOrg> fjnxOrgList,List<FjnxOrgBusinessRelation> specialOrgList) {
         List<SysUser> result = new ArrayList<>();
         if (ObjectUtil.isNotEmpty(fjnxUserDtoList)) {
-            fjnxUserDtoList.forEach(x -> {
-                SysOrg userBusinessSysOrg = getUserBusinessFjnxOrg(fjnxOrgList, orgList, x);
-                Optional<SysOrg> optionalOrg = orgList.stream().filter(org -> org.getCode().equals(x.getDepCode())).findFirst();
+            fjnxUserDtoList.forEach(fjnxUserDto -> {
+                SysOrg userBusinessSysOrg = getUserBusinessFjnxOrg(fjnxOrgList, orgList,fjnxUserDto, specialOrgList);
+                Optional<SysOrg> optionalOrg = orgList.stream().filter(org -> org.getCode().equals(fjnxUserDto.getDepCode())).findFirst();
                 if (optionalOrg.isPresent() && ObjectUtil.isNotEmpty(userBusinessSysOrg)) {
-                    result.add(FjnxUserConvertToUser(x, null,optionalOrg.get(), userBusinessSysOrg));
+                    result.add(FjnxUserConvertToUser(fjnxUserDto, null,optionalOrg.get(), userBusinessSysOrg));
                 } else {
-                    log.error("同步人员【{}】所属机构编码【{}】在当前数据库中未找到,{}", x.getUserId() + x.getUserName(), x.getDepCode(), x);
+                    log.error("同步人员【{}】所属机构编码【{}】在当前数据库中未找到,{}", fjnxUserDto.getUserId() + fjnxUserDto.getUserName(), fjnxUserDto.getDepCode(), fjnxUserDto);
                 }
             });
         }
@@ -796,9 +813,16 @@ public class FJNXSyncServiceImpl implements IFJNXSyncService {
         user.setJobNumber(fjnxUserDto.getTeller());
         user.setApproveStatus(1L);
         user.setUpdateTime(fjnxUserDto.getUpdateTime());
-        user.setOrgId(businessOrg.getId());
-        user.setOrgName(businessOrg.getName());
-        user.setOrgPath(businessOrg.getPath());
+        if(ObjectUtil.isNotEmpty(businessOrg)){
+            user.setOrgId(businessOrg.getId());
+            user.setOrgName(businessOrg.getShortName());
+            user.setOrgPath(businessOrg.getPath());
+        }
+        else {
+            user.setOrgId(org.getId());
+            user.setOrgName(org.getShortName());
+            user.setOrgPath(org.getPath());
+        }
         //0 禁用 1 启用已改密码 2 启用未改密码
         user.setIsLock(fjnxUserDto.getUserStatus());
         user.setSource(1);
@@ -818,26 +842,163 @@ public class FJNXSyncServiceImpl implements IFJNXSyncService {
      *
      * @return
      */
-    private SysOrg getUserBusinessFjnxOrg(List<FjnxOrg> fjnxOrgList, List<SysOrg> existOrgList, FJNXUserDto fjnxUserDto) {
+    private SysOrg getUserBusinessFjnxOrg(List<FjnxOrg> fjnxOrgList, List<SysOrg> existOrgList, FJNXUserDto fjnxUserDto,List<FjnxOrgBusinessRelation> specialOrgList) {
         final Optional<FjnxOrg> fjnxOrgOptional = fjnxOrgList.stream().filter(x -> x.getOrgCode().equals(fjnxUserDto.getDepCode())).findFirst();
         if (fjnxOrgOptional.isPresent()) {
-            if ("0001".equals(fjnxOrgOptional.get().getOrgType())) {
-                final Optional<FjnxOrg> corporCodeOptional = fjnxOrgList.stream().filter(x -> x.getOrgCode().equals(fjnxUserDto.getCorporCode())).findFirst();
-                if (corporCodeOptional.isPresent()) {
-                    return getSysOrgByFjnxOrg(existOrgList, corporCodeOptional.get());
+
+            final Integer syncUserOrgLevel = getSyncUserOrgLevel(fjnxOrgOptional.get().getOrgPath(), specialOrgList);
+
+            //省联社下级机关部门下的人,迁移到顶级机构下
+//            if(ObjectUtil.equal(syncUserOrgLevel,1))
+//            {
+//                final Optional<SysOrg> topOrg = existOrgList.stream().filter(x -> x.getParentId().equals(-1L)).findFirst();
+//                if(topOrg.isPresent())
+//                {
+//                    return topOrg.get();
+//                }
+//                return null;
+//            }
+
+            //办事处机构下,人员迁移到地区行社下
+            if(ObjectUtil.equal(syncUserOrgLevel,2))
+            {
+//                final String dqhsOrgCode = getUserOwnerBscOrgMapperDqhsOrgCode(fjnxOrgOptional.get().getOrgPath(), specialOrgList);
+                final String dqhsOrgCode = getUserOwnerBscOrgCode(fjnxOrgOptional.get().getOrgPath(), specialOrgList);
+                if(StringUtil.isNullOrEmpty(dqhsOrgCode))
+                {
+                    return getSysOrgByOrgCode(existOrgList,dqhsOrgCode);
+                }
+                return null;
+            }
+
+            //地区行社处机构下,部门下的人迁移到法人机构下
+            if(ObjectUtil.equal(syncUserOrgLevel,3))
+            {
+                if ("0001".equals(fjnxOrgOptional.get().getOrgType())) {
+                    // 获取法人机构
+                    final Optional<FjnxOrg> corporCodeOptional = fjnxOrgList.stream().filter(x -> x.getOrgCode().equals(fjnxUserDto.getCorporCode())).findFirst();
+                    if (corporCodeOptional.isPresent()) {
+                        return getSysOrgByFjnxOrg(existOrgList, corporCodeOptional.get());
+                    } else {
+                        log.error("同步人员【{}】所属法人机构编码【{}】在当前sync_fjnx_org中未找到对应法人机构,{}", fjnxUserDto.getUserId() + fjnxUserDto.getUserName(), fjnxUserDto.getCorporCode(), fjnxUserDto);
+                    }
                 } else {
-                    log.error("同步人员【{}】所属法人机构编码【{}】在当前fjnx_org中未找到对应法人机构,{}", fjnxUserDto.getUserId() + fjnxUserDto.getUserName(), fjnxUserDto.getCorporCode(), fjnxUserDto);
+                    return getSysOrgByFjnxOrg(existOrgList, fjnxOrgOptional.get());
                 }
-            } else {
-                return getSysOrgByFjnxOrg(existOrgList, fjnxOrgOptional.get());
-//               return fjnxOrgOptional.get();
             }
         } else {
-            log.error("同步人员【{}】所属机构编码【{}】在当前fjnx_org中未找到对应机构,{}", fjnxUserDto.getUserId() + fjnxUserDto.getUserName(), fjnxUserDto.getDepCode(), fjnxUserDto);
+            log.error("同步人员【{}】所属机构编码【{}】在当前sync_fjnx_org中未找到对应机构,{}", fjnxUserDto.getUserId() + fjnxUserDto.getUserName(), fjnxUserDto.getDepCode(), fjnxUserDto);
+        }
+        return null;
+    }
+
+    /**
+     * 获取法人机构
+     * @return
+     */
+//    private SysOrg getcorporOrg(){
+//
+//    }
+
+    /**
+     * 根据用户所属机构找到用户机构位置 1:省联社下级机关部门下 2:办事处机构下 3:地区行社机构下, null 代表没找到对应机构
+     * @return
+     */
+    private Integer getSyncUserOrgLevel(String userOrgPath,List<FjnxOrgBusinessRelation> specialOrgList)
+    {
+            final boolean userOrgLevelLowerOfBSC = isUserOrgLevelLowerOfBSC(userOrgPath, specialOrgList);
+            if(userOrgLevelLowerOfBSC){
+                return 2;
+            }
+            final boolean userOrgLevelLowerOfDQHS = isUserOrgLevelLowerOfDQHS(userOrgPath, specialOrgList);
+            if(userOrgLevelLowerOfDQHS)
+            {
+                return 3;
+            }
+            return 1;
+    }
+
+
+    /**
+     * 用户所在机构层级是否低于办事处
+      * @param userOrgPath 用户所在机构path
+     * @param specialOrgList 同步配置表中配置的各类型数据, 类型为2的为办事处
+     * @return
+     */
+    private boolean isUserOrgLevelLowerOfBSC(String userOrgPath,List<FjnxOrgBusinessRelation> specialOrgList){
+        final List<String> bacOrgCodeList = specialOrgList.stream().filter(x -> x.getOrgType().equals(2)).map(FjnxOrgBusinessRelation::getOrgCode).collect(Collectors.toList());
+        final List<String> orgCodeList = orgPathConvertToOrgCodeList(userOrgPath);
+        final int length = CollectionUtils.intersection(orgCodeList, bacOrgCodeList).toArray().length;
+        if(length>0)
+        {
+            return true;
+        }
+
+        return false;
+    }
+
+    /**
+     * 获取用户机构所在的办事处机构对应的地址行社编码
+     * @param userOrgPath
+     * @param specialOrgList
+     * @return
+     */
+    private String getUserOwnerBscOrgMapperDqhsOrgCode(String userOrgPath,List<FjnxOrgBusinessRelation> specialOrgList){
+        final List<String> bacOrgCodeList = specialOrgList.stream().filter(x -> x.getOrgType().equals(2)).map(FjnxOrgBusinessRelation::getOrgCode).collect(Collectors.toList());
+        final List<String> orgCodeList = orgPathConvertToOrgCodeList(userOrgPath);
+        final Optional<Object> first = Arrays.stream(CollectionUtils.intersection(orgCodeList, bacOrgCodeList).toArray()).findFirst();
+        if(first.isPresent())
+        {
+            final Optional<FjnxOrgBusinessRelation> basOrgMapperDqhsOrg = specialOrgList.stream().filter(x -> x.getOrgType().equals(2) && x.getOrgCode().equals(first.get().toString())).findFirst();
+            if(basOrgMapperDqhsOrg.isPresent())
+            {
+                return basOrgMapperDqhsOrg.get().getDqhsOrgCode();
+            }
         }
         return null;
     }
 
+    private String getUserOwnerBscOrgCode(String userOrgPath,List<FjnxOrgBusinessRelation> specialOrgList){
+        final List<String> bacOrgCodeList = specialOrgList.stream().filter(x -> x.getOrgType().equals(2)).map(FjnxOrgBusinessRelation::getOrgCode).collect(Collectors.toList());
+        final List<String> orgCodeList = orgPathConvertToOrgCodeList(userOrgPath);
+        final Optional<Object> first = Arrays.stream(CollectionUtils.intersection(orgCodeList, bacOrgCodeList).toArray()).findFirst();
+        if(first.isPresent())
+        {
+          return first.get().toString();
+        }
+        return null;
+    }
+
+    /**
+     * 用户所在机构层级是否低于地区行社
+     * @param userOrgPath 用户所在机构path
+     * @param specialOrgList 同步配置表中配置的各类型数据, 类型为3的为地区行社
+     * @return
+     */
+    private boolean isUserOrgLevelLowerOfDQHS(String userOrgPath,List<FjnxOrgBusinessRelation> specialOrgList){
+        final List<String> dqhsOrgCodeList = specialOrgList.stream().filter(x -> x.getOrgType().equals(3)).map(FjnxOrgBusinessRelation::getOrgCode).collect(Collectors.toList());
+        final List<String> orgCodeList = orgPathConvertToOrgCodeList(userOrgPath);
+        final int length = CollectionUtils.intersection(orgCodeList, dqhsOrgCodeList).toArray().length;
+        if(length>0)
+        {
+            return true;
+        }
+        return false;
+    }
+
+    private List<String> orgPathConvertToOrgCodeList(String userOrgPath){
+        if(StringUtil.isNullOrEmpty(userOrgPath))
+        {
+            return new ArrayList<>();
+        }
+        return Arrays.asList( userOrgPath.split("/"));
+    }
+
+
+
+
+
+    // 根据FjnxOrg 对象查询到系统对应的机构对象
     private SysOrg getSysOrgByFjnxOrg(List<SysOrg> existOrgList, FjnxOrg fjnxOrg) {
         final Optional<SysOrg> businessSysOrgOptional = existOrgList.stream().filter(x -> fjnxOrg.getOrgCode().equals(x.getCode())).findFirst();
         if (businessSysOrgOptional.isPresent()) {
@@ -847,15 +1008,28 @@ public class FJNXSyncServiceImpl implements IFJNXSyncService {
         return null;
     }
 
+    private SysOrg getSysOrgByOrgCode(List<SysOrg> existOrgList, String orgCode) {
+        final Optional<SysOrg> businessSysOrgOptional = existOrgList.stream().filter(x -> orgCode.equals(x.getCode())).findFirst();
+        if (businessSysOrgOptional.isPresent()) {
+            return businessSysOrgOptional.get();
+        }
+
+        return null;
+    }
+
+
+
     /**
      * 将从fjnx统一门户获取到的原始机构数据转换为
      * @param list 从fjnx获取的原始机构数据
      * @return
      */
-    private List<FjnxOrg> ConvertXmlOrgDtoToOrgJinx(List<FJNXOrgDto> list) {
+    private List<FjnxOrg> ConvertXmlOrgDtoToOrgFjnx(List<FJNXOrgDto> list) {
         if (ObjectUtil.isEmpty(list)) {
             return new ArrayList<>();
         }
+        //新增自定顶级机构“福建农信社”
+        list.add(createCustomRootOrg());
         List<FjnxOrgBusinessRelation> fjnxOrgBusinessRelationList = fjnxOrgBusinessRelationMapper.selectList(Wrappers.emptyWrapper());
         final ArrayList<FjnxOrg> resultList = new ArrayList<>();
         Date syncDateTime = new Date();
@@ -864,6 +1038,10 @@ public class FJNXSyncServiceImpl implements IFJNXSyncService {
                 log.error("没有机构编码,机构名称:{}", item.getOrgName());
                 return;
             }
+            if(ObjectUtil.equal(item.getShortName(),"省联社"))
+            {
+                item.setShortName("省联社职能部门");
+            }
 
             FjnxOrg tempOrg = new FjnxOrg();
             BeanUtils.copyBeanProp(tempOrg, item);
@@ -871,15 +1049,22 @@ public class FJNXSyncServiceImpl implements IFJNXSyncService {
             tempOrg.setLastSyncTime(syncDateTime);
             tempOrg.setBusinessParentCode(tempOrg.getOrgParent());
             tempOrg.setTreeShowParentCode(tempOrg.getOrgParent());
+            if(item.getOrgCode().equals("M33000000"))
+            {
+                String a="M33000000";
+            }
 
             Optional<FjnxOrgBusinessRelation> first = fjnxOrgBusinessRelationList.stream().filter(b -> b.getOrgCode().equals(item.getOrgCode())).findFirst();
             if (first.isPresent()) {
-                if (list.stream().anyMatch(y -> y.getOrgCode().equals(first.get().getBusinessParentCode()))) {
+                if (!StringUtil.isNullOrEmpty(first.get().getBusinessParentCode()) &&  list.stream().anyMatch(y -> y.getOrgCode().equals(first.get().getBusinessParentCode()))) {
                     tempOrg.setBusinessParentCode(first.get().getBusinessParentCode());
-                    tempOrg.setTreeShowParentCode(item.getOrgParent());
                 } else {
                     log.error("设置fjnx业务父级机构失败,机构名称:{},机构编码:{},业务父级机构编码:{}", item.getOrgName(), first.get().getOrgCode(), first.get().getBusinessParentCode());
-                    return;
+                }
+                if (!StringUtil.isNullOrEmpty(first.get().getTreeShowParentCode()) &&  list.stream().anyMatch(y -> y.getOrgCode().equals(first.get().getTreeShowParentCode()))) {
+                    tempOrg.setTreeShowParentCode(first.get().getTreeShowParentCode());
+                } else {
+                    log.error("设置fjnx机构树显示父级机构失败,机构名称:{},机构编码:{},机构树显示父级机构编码:{}", item.getOrgName(), first.get().getOrgCode(), first.get().getBusinessParentCode());
                 }
             }
             resultList.add(tempOrg);
@@ -1036,4 +1221,15 @@ public class FJNXSyncServiceImpl implements IFJNXSyncService {
         return customOrg;
     }
 
+    private FJNXOrgDto createCustomRootOrg() {
+        FJNXOrgDto customOrg = new FJNXOrgDto();
+        customOrg.setOrgName(thirdPartySystemConfig.getFjnxSyncOrgCustomRootOrgName());
+        customOrg.setShortName(thirdPartySystemConfig.getFjnxSyncOrgCustomRootOrgName());
+        customOrg.setOrgCode(thirdPartySystemConfig.getFjnxSyncOrgCustomRootOrgCode());
+        customOrg.setCorporCode(thirdPartySystemConfig.getFjnxSyncOrgCustomRootOrgCode());
+        customOrg.setOrgPath("/" + customOrg.getOrgCode());
+        customOrg.setUsableFlag(1);
+        return customOrg;
+    }
+
 }

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

@@ -14,6 +14,7 @@ import com.xunmei.common.security.annotation.InnerAuth;
 import com.xunmei.common.security.annotation.RequiresPermissions;
 import com.xunmei.common.security.utils.SecurityUtils;
 import com.xunmei.system.api.Eto.OrgListByTypesConditionEto;
+import com.xunmei.system.api.Eto.SysOrgTreeRequestDto;
 import com.xunmei.system.api.domain.SysDept;
 import com.xunmei.system.api.domain.SysOrg;
 import com.xunmei.system.api.domain.SysUser;
@@ -155,6 +156,24 @@ public class SysDeptController extends BaseController {
         return success(deptService.selectHangsheTreeList());
     }
 
+    @PostMapping("/deptTree/business")
+    public AjaxResult businessDeptTree(@RequestBody String excludeOrgCode) {
+        if(StringUtils.isEmpty(excludeOrgCode))
+        {
+            excludeOrgCode="900000000";
+        }
+        return success(deptService.selectBusinessTreeList(excludeOrgCode));
+    }
+
+    /**
+     * 获取指定机构的所有下级以及直接上级树
+     */
+    @PostMapping("/deptTree/whole")
+    public AjaxResult wholePathTree(@RequestBody SysOrgTreeRequestDto request) {
+        return success(deptService.orgWholePathTree(request));
+    }
+
+
     /**
      * 获取缓存的行社及行社上级机构
      */

+ 5 - 0
soc-modules/soc-modules-system/src/main/java/com/xunmei/system/service/ISysDeptService.java

@@ -1,6 +1,7 @@
 package com.xunmei.system.service;
 
 import com.baomidou.mybatisplus.extension.service.IService;
+import com.xunmei.system.api.Eto.SysOrgTreeRequestDto;
 import com.xunmei.system.api.domain.SysDept;
 import com.xunmei.system.api.domain.SysOrg;
 import com.xunmei.system.api.vo.SysOrgVO;
@@ -37,6 +38,8 @@ public interface ISysDeptService extends IService<SysDept> {
      */
     List<SysOrgVO> selectHangsheTreeList();
 
+    List<SysOrgVO> selectBusinessTreeList(String excludeOrgCode);
+
     /**
      * 获取缓存的行社及行社上级机构
      * @param path
@@ -59,6 +62,8 @@ public interface ISysDeptService extends IService<SysDept> {
      */
     List<SysDept> selectDeptTreeList(SysDept dept);
 
+    List<SysOrgVO> orgWholePathTree(SysOrgTreeRequestDto request);
+
     /**
      * 构建前端所需要树结构
      *

+ 104 - 2
soc-modules/soc-modules-system/src/main/java/com/xunmei/system/service/impl/SysDeptServiceImpl.java

@@ -16,10 +16,12 @@ import com.xunmei.common.core.utils.StringUtils;
 import com.xunmei.common.datascope.annotation.DataScope;
 import com.xunmei.common.redis.utils.RedisUtils;
 import com.xunmei.common.security.utils.SecurityUtils;
+import com.xunmei.system.api.Eto.SysOrgTreeRequestDto;
 import com.xunmei.system.api.domain.SysDept;
 import com.xunmei.system.api.domain.SysOrg;
 import com.xunmei.system.api.domain.SysRole;
 import com.xunmei.system.api.domain.SysUser;
+import com.xunmei.system.api.model.LoginUser;
 import com.xunmei.system.api.vo.SysOrgVO;
 import com.xunmei.system.domain.vo.TreeSelect;
 import com.xunmei.system.mapper.SysDeptMapper;
@@ -146,6 +148,42 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
         return generateTree(hangshelist, sysOrg);
     }
 
+    @Override
+    public List<SysOrgVO> selectBusinessTreeList(String excludeOrgCode) {
+        SysOrg sysOrg = null;
+        SysOrgVO excludeOrg = null;
+        sysOrg = getLoginUserOrg();
+        List<SysOrgVO> cacheList = getOrgCache();
+        List<SysOrgVO> orgs = new ArrayList<>();
+        if(StringUtils.isNotEmpty(excludeOrgCode)){
+            final Optional<SysOrgVO> first = cacheList.stream().filter(x -> ObjectUtil.equal(x.getCode(), excludeOrgCode)).findFirst();
+            if(first.isPresent())
+            {
+                excludeOrg=first.get();
+            }
+        }
+
+        for (SysOrgVO org : cacheList) {
+            String path = org.getPath();
+            if (StringUtils.isEmpty(path) || !path.startsWith(sysOrg.getPath())) {
+                continue;
+            }
+            String treeShowPath = org.getTreeShowPath();
+            if (ObjectUtil.isNotEmpty(excludeOrg) && treeShowPath.startsWith(excludeOrg.getTreeShowPath())) {
+                continue;
+            }
+
+            if (StringUtils.isEmpty(org.getShortName())) {
+                org.setShortName(org.getName());
+            }
+            if (org.getSort() == null) {
+                org.setSort(100000);
+            }
+            orgs.add(org);
+        }
+        return generateTree(orgs, sysOrg);
+    }
+
     /**
      * 获取缓存的行社及行社上级机构
      *
@@ -200,6 +238,69 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
         return orgVOS;
     }
 
+    @Override
+    public List<SysOrgVO> orgWholePathTree(SysOrgTreeRequestDto request) {
+        SysOrgVO sysOrg = null;
+        Long orgId = null;
+        LoginUser loginUser=SecurityUtils.getLoginUser();
+        if(ObjectUtil.isEmpty(request) || ObjectUtil.isEmpty(request.getOrgId()))
+        {
+            orgId = loginUser.getOrgId();
+        }
+        else {
+            orgId =request.getOrgId();
+        }
+
+        List<SysOrgVO> cacheList = getOrgCache();
+        if(ObjectUtil.isNotEmpty(orgId)){
+            Long finalOrgId = orgId;
+            final Optional<SysOrgVO> first = cacheList.stream().filter(x -> ObjectUtil.equal(x.getId(), finalOrgId)).findFirst();
+            if(first.isPresent())
+            {
+                sysOrg=first.get();
+            }
+        }
+        if(ObjectUtil.isEmpty(sysOrg))
+        {
+            return new ArrayList<>();
+        }
+
+        final List<SysOrgVO> orgList = getWholePathTreeOrgFromCache(sysOrg, cacheList,request.getIncludeSub());
+
+        return generateTree(orgList,null);
+    }
+
+    /**
+     * 根据业务机构path 获取指定机构的所有下级以及所有直接上级机构
+     * @param orgVO
+     * @param cacheList
+     * @return
+     */
+    public List<SysOrgVO> getWholePathTreeOrgFromCache(SysOrgVO orgVO,List<SysOrgVO> cacheList,Boolean includeSub) {
+        List<SysOrgVO> selfAndAllChildOrglist =null;
+        if(includeSub)
+        {
+            selfAndAllChildOrglist=cacheList.stream().filter(c ->ObjectUtil.isNotEmpty(c.getPath()) && c.getPath().startsWith(orgVO.getPath())).collect(Collectors.toList());
+        }
+        else {
+            selfAndAllChildOrglist=cacheList.stream().filter(c ->ObjectUtil.equal(orgVO.getId(),c.getId())).collect(Collectors.toList());
+        }
+
+        Set<Long> parentIds = new HashSet<>();
+            Arrays.stream(orgVO.getPath().split("-")).map(p -> Long.parseLong(p))
+                    .collect(Collectors.toList())
+                    .forEach(id -> {
+                        if (!ObjectUtil.equal(orgVO.getId(),id)) {
+                            parentIds.add(id);
+                        }
+                    });
+        selfAndAllChildOrglist.addAll(cacheList.stream()
+                .filter(o -> parentIds.contains(o.getId()))
+                .collect(Collectors.toList()));
+
+        return selfAndAllChildOrglist;
+    }
+
     private SysOrg getLoginUserOrg() {
         Long userId = SecurityUtils.getUserId();
         SysOrg sysOrg = orgMapper.selectSysOrgByUserId(userId);
@@ -223,11 +324,12 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
 
     private List<SysOrgVO> generateTree(List<SysOrgVO> orgs, SysOrg sysOrg) {
         Long parentId = Constants.TOP_ORG_PARENT_ID;
-        if (ObjectUtil.notEqual(Constants.TOP_ORG_PARENT_ID, sysOrg.getParentId())) {
+        if (ObjectUtil.isNotEmpty(sysOrg) && ObjectUtil.notEqual(Constants.TOP_ORG_PARENT_ID, sysOrg.getParentId())) {
             parentId = sysOrg.getParentId();
         }
 
-        final List<Long> parentIds = orgs.stream().filter(x -> !orgs.stream().anyMatch(y -> x.getTreeShowParentId().equals(y.getParentId()))).map(SysOrgVO::getTreeShowParentId).collect(Collectors.toList());
+        // 顶级机构存在多个的情况
+        final List<Long> parentIds = orgs.stream().filter(x -> !orgs.stream().anyMatch(y -> x.getTreeShowParentId().equals(y.getId()))).map(SysOrgVO::getTreeShowParentId).collect(Collectors.toList());
         if (parentIds.size() == 0) {
             parentIds.add(parentId);
         }

+ 1 - 0
soc-modules/soc-modules-system/src/main/resources/mapper/system/SysOrgMapper.xml

@@ -624,6 +624,7 @@
         SELECT id,
                `name`,
                if(short_name is null,`name` ,short_name) as short_name,
+               code,
                path,
                parent_id,
                type,