Commit 04c3e418 authored by huyuchen's avatar huyuchen

huyc 部门根节点数值修改

parent b4adaeac
...@@ -61,8 +61,6 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl ...@@ -61,8 +61,6 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
private final SysDeptRelationService sysDeptRelationService; private final SysDeptRelationService sysDeptRelationService;
private final SysUserService sysUserService;
private final LdapUtil ldapUtil; private final LdapUtil ldapUtil;
private final SysDeptMapper sysDeptMapper; private final SysDeptMapper sysDeptMapper;
......
...@@ -80,14 +80,10 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl ...@@ -80,14 +80,10 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
private final SysUserRoleMapper sysUserRoleMapper; private final SysUserRoleMapper sysUserRoleMapper;
private final SysUserPostMapper sysUserPostMapper;
private final LdapUtil ldapUtil; private final LdapUtil ldapUtil;
private final SysUserMapper sysUserMapper; private final SysUserMapper sysUserMapper;
private final SysDeptService sysDeptService;
/** /**
* 保存用户信息 * 保存用户信息
* @param userDto DTO 对象 * @param userDto DTO 对象
...@@ -432,7 +428,68 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl ...@@ -432,7 +428,68 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
sysUserMapper.batchInsertUser(insertList); sysUserMapper.batchInsertUser(insertList);
} }
} }
sysDeptService.updateDeptByLdap(); List<SearchResultEntry> entryList = ldapUtil.getAllPersonNamesWithTraditionalWay();
//获取ldap所有的dn
List<String> entryDnList = entryList.stream().map(SearchResultEntry::getDN).collect(Collectors.toList());
//获取本地dept表中所有的dn
List<String> dnList = sysDeptMapper.selectDnList();
List<String> delList = dnList.stream().filter(p-> !entryDnList.contains(p)).collect(Collectors.toList());
//删除ldap中不存在的dn的数据
if (delList.size() >0) {
sysDeptMapper.delete(Wrappers.<SysDept>query().lambda().in(SysDept::getDeptDn, delList));
}
List<Map<String,Object>> updUserList = new ArrayList<>();
for (SearchResultEntry entry : entryList) {
String dn = entry.getDN();
String userId = "";
if (dn.contains("uid")) {
userId = dn.substring(4, dn.indexOf(",", 1));
dn = dn.substring(dn.indexOf(",", 1) + 1);
}
List<String> saveDnList = Arrays.asList(dn.split(",")).stream().filter(e -> (e.contains("ou=") && !e.equals("ou=wanxin"))).collect(Collectors.toList());
String deptName = saveDnList.get(0).replace("ou=", "");
int size = saveDnList.size();
if (size == 1) {
SysDept sysDept = sysDeptMapper.selectOne(Wrappers.<SysDept>query().lambda().eq(SysDept::getDeptDn, dn));
if (null == sysDept) {
SysDept insertSysDept = new SysDept();
insertSysDept.setName(deptName);
insertSysDept.setParentId(0L);
insertSysDept.setDeptDn(dn);
sysDeptMapper.insert(insertSysDept);
} else {
sysDept.setName(deptName);
sysDeptMapper.updateById(sysDept);
}
} else if (size >= 2) {
SysDept sysDept = sysDeptMapper.selectOne(Wrappers.<SysDept>query().lambda().eq(SysDept::getDeptDn, dn.substring(dn.indexOf("ou=", 2), dn.length())));
if (null != sysDept) {
SysDept sysDeptCount = sysDeptMapper.selectOne(Wrappers.<SysDept>query().lambda().eq(SysDept::getDeptDn, dn));
if (null == sysDeptCount) {
if (StringUtils.isEmpty(userId)) {
SysDept insertSysDept = new SysDept();
insertSysDept.setName(deptName);
insertSysDept.setParentId(sysDept.getDeptId());
insertSysDept.setDeptDn(dn);
sysDeptMapper.insert(insertSysDept);
}
} else {
if (!StringUtils.isEmpty(userId)) {
Map<String,Object> map = new HashMap<>();
map.put("userId",userId);
map.put("deptId",sysDeptCount.getDeptId());
updUserList.add(map);
}else {
sysDeptCount.setName(deptName);
sysDeptCount.setParentId(sysDept.getDeptId());
sysDeptMapper.updateById(sysDeptCount);
}
}
}
}
}
//更新用户信息
sysUserMapper.updateUser(updUserList);
}catch (Exception e) { }catch (Exception e) {
log.info("用户部门信息同步异常:" + e.getMessage()); log.info("用户部门信息同步异常:" + e.getMessage());
return R.failed("用户部门信息同步异常!"); return R.failed("用户部门信息同步异常!");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment