Example #1
0
  private void freshOrgData(String synctime) {
    Map<String, AccountOrg> orgMap = new HashMap<String, AccountOrg>();
    Map<String, AccountDept> deptMap = new HashMap<String, AccountDept>();

    List<LdapOrg> search = ldapDataExtracterService.searchOrgs(synctime);
    // Ldap Bean转Entity
    for (LdapOrg ldapOrg : search) {
      AccountOrg accountOrg = convertldapOrgToEntity(ldapOrg);
      if (accountOrg != null) {
        orgMap.put(accountOrg.getOrgcode(), accountOrg);
      }

      AccountDept accountDept = convertldapOrgToDeptEntity(ldapOrg);
      if (accountDept != null) {
        deptMap.put(accountDept.getPkdept(), accountDept);
      }
    }

    if (!orgMap.isEmpty() && orgMap.size() > 0) {
      List<AccountOrg> insertList = new ArrayList<AccountOrg>();
      for (Entry<String, AccountOrg> entry : orgMap.entrySet()) {
        AccountOrg accountOrg = orgRepository.findByOrgcode(entry.getKey());
        if (accountOrg != null) {
          entry.getValue().setId(accountOrg.getId());
          ;
          orgRepository.saveAndFlush(entry.getValue());
          log.info("-- freshOrgData update accountOrg : {}", entry.getValue());
        } else {
          insertList.add(entry.getValue());
        }
      }
      insertList = orgRepository.save(insertList);
      log.info(
          "-- freshOrgData save accountOrg list : {} ",
          insertList == null ? null : insertList.size());
    }

    if (!deptMap.isEmpty() && deptMap.size() > 0) {
      List<AccountDept> insertList = new ArrayList<AccountDept>();
      for (Entry<String, AccountDept> entry : deptMap.entrySet()) {
        AccountDept accountDept = deptRepository.findByPkdept(entry.getKey());
        if (accountDept != null) {
          entry.getValue().setId(accountDept.getId());
          deptRepository.saveAndFlush(entry.getValue());
          log.info("-- freshDeptData update accountDept : {}", entry.getValue());
        } else {
          insertList.add(entry.getValue());
        }
      }
      // 批量执行插入
      insertList = deptRepository.save(insertList);
      log.info(
          "-- freshDeptData save accountDept list : {} ",
          insertList == null ? null : insertList.size());
    }
  }
Example #2
0
 @Override
 public OrgDTO findByOrgcode(String txNo, String orgcode) throws ParamInvalidException {
   if (log.isInfoEnabled()) {
     log.info(" -- finyOrgByCode txNo:{}  orgcode: {} ", txNo, orgcode);
   }
   AccountOrg accountOrg = orgRepository.findByOrgcode(orgcode);
   OrgDTO dto = AccountOrg.convertToDTO(accountOrg);
   return dto;
 }
Example #3
0
 @Override
 public OrgDTO findByPkOrg(String txNo, String pkorg) throws ParamInvalidException {
   if (log.isInfoEnabled()) {
     log.info(" -- finyOrgByCode txNo:{}  pkorg: {} ", txNo, pkorg);
   }
   AccountOrg accountOrg = this.orgRepository.findByPkorg(pkorg);
   OrgDTO dto = AccountOrg.convertToDTO(accountOrg);
   return dto;
 }
Example #4
0
  @Override
  public List<OrgDTO> queryAllOrg() {
    List<AccountOrg> list = orgRepository.findAll();
    List<OrgDTO> result = new ArrayList<OrgDTO>();
    for (AccountOrg org : list) {
      OrgDTO dto = AccountOrg.convertToDTO(org);
      if (dto != null) result.add(dto);
    }

    if (log.isInfoEnabled()) {
      log.info(" -- queryAllOrg result : {}", result == null ? null : result.size());
    }
    return result;
  }
Example #5
0
 private AccountOrg convertldapOrgToEntity(LdapOrg ldapOrg) {
   // 含有部门编码则不是组织
   if (StringUtils.isNotEmpty(ldapOrg.getDeptcode())) {
     return null;
   }
   AccountOrg accountOrg = new AccountOrg();
   accountOrg.setFatherorg(ldapOrg.getFatherorg());
   accountOrg.setOrgcode(ldapOrg.getOrgcode());
   accountOrg.setOrgname(ldapOrg.getOrgname());
   accountOrg.setPkfatherorg(ldapOrg.getPkfatherorg());
   accountOrg.setPkorg(ldapOrg.getPkorg());
   return accountOrg;
 }