Commit 94ca8525 authored by fangxinjiang's avatar fangxinjiang

统一用户中心用户状态同步,同步清理缓存信息-fxj

parent d61a237c
...@@ -518,8 +518,10 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl ...@@ -518,8 +518,10 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
public R<Boolean> updateByLdap() { public R<Boolean> updateByLdap() {
try { try {
List<PersonVo> list = ldapUtil.getAllPersons(); List<PersonVo> list = ldapUtil.getAllPersons();
List<PersonVo> updateList = new ArrayList<>();
List<SysUser> listUser = null;
if (null != list) { if (null != list) {
List<SysUser> listUser = this.list(Wrappers.<SysUser>query().lambda() listUser = this.list(Wrappers.<SysUser>query().lambda()
.eq(SysUser::getType, CommonConstants.ZERO_STRING) .eq(SysUser::getType, CommonConstants.ZERO_STRING)
.eq(SysUser::getSystemFlag, CommonConstants.ONE_STRING) .eq(SysUser::getSystemFlag, CommonConstants.ONE_STRING)
.eq(SysUser::getDelFlag, CommonConstants.STATUS_NORMAL)); .eq(SysUser::getDelFlag, CommonConstants.STATUS_NORMAL));
...@@ -536,7 +538,6 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl ...@@ -536,7 +538,6 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
this.update(settleUpdate); this.update(settleUpdate);
} }
List<PersonVo> updateList = new ArrayList<>();
List<PersonVo> insertList = new ArrayList<>(); List<PersonVo> insertList = new ArrayList<>();
for (PersonVo personVo : list) { for (PersonVo personVo : list) {
if (list1.stream().anyMatch(e -> e.equals(personVo.getUid()))) { if (list1.stream().anyMatch(e -> e.equals(personVo.getUid()))) {
...@@ -585,11 +586,13 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl ...@@ -585,11 +586,13 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
} }
List<SearchResultEntry> entryList = ldapUtil.getAllPersonNamesWithTraditionalWay(); List<SearchResultEntry> entryList = ldapUtil.getAllPersonNamesWithTraditionalWay();
List<Map<String,Object>> updUserList = new ArrayList<>(); List<Map<String,Object>> updUserList = new ArrayList<>();
List<String> userIdOnlines = new ArrayList<>();
for (SearchResultEntry entry : entryList) { for (SearchResultEntry entry : entryList) {
String dn = entry.getDN(); String dn = entry.getDN();
String userId = ""; String userId = "";
if (dn.contains("uid")) { if (dn.contains("uid")) {
userId = dn.substring(4, dn.indexOf(",", 1)); userId = dn.substring(4, dn.indexOf(",", 1));
userIdOnlines.add(userId);
dn = dn.substring(dn.indexOf(",", 1) + 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()); List<String> saveDnList = Arrays.asList(dn.split(",")).stream().filter(e -> (e.contains("ou=") && !e.equals("ou=wanxin"))).collect(Collectors.toList());
...@@ -665,6 +668,55 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl ...@@ -665,6 +668,55 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
if (!updUserList.isEmpty()) { if (!updUserList.isEmpty()) {
baseMapper.updateUser(updUserList); baseMapper.updateUser(updUserList);
} }
// 对比 updateList 和 updUserList 的 userId 如果 updateList 中存在 但是updUserList 中不存在 则更新成非在用
List<String> updateListStr = updateList.stream().map(e -> e.getUid()).collect(Collectors.toList());
List<String> updateUserList = updateListStr.stream().filter(e -> !userIdOnlines.stream().anyMatch(f -> f.equals(e))).collect(Collectors.toList());
if (!userIdOnlines.isEmpty()){
LambdaUpdateWrapper<SysUser> wrapper = new LambdaUpdateWrapper();
wrapper.in(SysUser::getUsername, userIdOnlines);
wrapper.set(SysUser::getLockFlag, CommonConstants.ZERO_STRING);
this.update(wrapper);
}
if (!updateUserList.isEmpty()) {
LambdaUpdateWrapper<SysUser> wrapper = new LambdaUpdateWrapper();
wrapper.in(SysUser::getUsername, updateUserList);
wrapper.set(SysUser::getLockFlag, CommonConstants.NINE_STRING);
this.update(wrapper);
}
// 刷新用户缓存
Map<String, String> existMap = listUser.stream().collect(Collectors.toMap(SysUser::getUsername,SysUser::getLockFlag));
List<String> refreshList = new ArrayList<>();
if (Common.isNotNull(existMap)){
//找出启用锁定的数据
if (!userIdOnlines.isEmpty()){
for (String userName : userIdOnlines){
if (existMap.containsKey(userName)){
if (!CommonConstants.ZERO_STRING.equals(existMap.get(userName))){
refreshList.add(userName);
}
}
}
}
//找出锁定启用的数据
if (!updateUserList.isEmpty()){
for (String userName : updateUserList){
if (existMap.containsKey(userName)){
if (!CommonConstants.NINE_STRING.equals(existMap.get(userName))){
refreshList.add(userName);
}
}
}
}
// 清理缓存
if (!refreshList.isEmpty()){
for (String userName : refreshList){
redisUtil.remove(CacheConstants.USER_DETAILS +"::"+ userName);
}
}
}
}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