Commit 76591d9e authored by 赵啸非's avatar 赵啸非

修改用户同步接口

parent 3485f2b5
...@@ -343,40 +343,55 @@ public class UserServiceImpl extends AbstractCRUDCacheServiceImpl<UserDao, UserE ...@@ -343,40 +343,55 @@ public class UserServiceImpl extends AbstractCRUDCacheServiceImpl<UserDao, UserE
List<UserEntity> newUserList = userPduList.stream().map(newUser -> { List<UserEntity> newUserList = userPduList.stream().map(newUser -> {
UserEntity userEntity = new UserEntity(); UserEntity userEntity = new UserEntity();
userEntity.initAttrValue(); userEntity.initAttrValue();
BeanUtils.copyProperties(newUser, userEntity, new String[]{"id","lastLoginTime", "lastLoginAddress"}); BeanUtils.copyProperties(newUser, userEntity, new String[]{"id", "lastLoginTime", "lastLoginAddress"});
return userEntity; return userEntity;
}).collect(Collectors.toList()); }).collect(Collectors.toList());
/*
List<UserEntity> oldUserList = this.find(new UserQuery()); List<UserEntity> oldUserList = this.find(new UserQuery());
log.info(" oldUserList size:{}", oldUserList.size()); log.info(" oldUserList size:{}", oldUserList.size());
//用户map 登录名做唯一标识
Map<String, UserEntity> newUserMap = newUserList.stream().collect(Collectors.toMap(x -> x.getLoginName(), y -> y, (o, n) -> n));
Map<String, UserEntity> oldUserMap = oldUserList.stream().collect(Collectors.toMap(x -> x.getLoginName(), y -> y, (o, n) -> n)); Map<String, UserEntity> oldUserMap = oldUserList.stream().collect(Collectors.toMap(x -> x.getLoginName(), y -> y, (o, n) -> n));
Map<String, UserEntity> newUserMap = newUserList.stream().collect(Collectors.toMap(x -> x.getLoginName(), y -> y, (o, n) -> n)); */
List<UserEntity> saveUserList = newUserList.stream().map(item -> { List<UserEntity> saveUpdateUserList = newUserList.parallelStream().map(item -> {
if (!oldUserMap.containsKey(item.getLoginName())) { UserEntity extCache = this.getExtCache(item.getLoginName());
if (ObjectUtils.isEmpty(extCache)) {
item.setCreateUserId(1L); item.setCreateUserId(1L);
item.setCreateUserName("系统管理员"); item.setCreateUserName("系统管理员");
item.setCreateTime(new Date()); item.setCreateTime(new Date());
return item; return item;
} else {
//更新用户列表
item.setId(extCache.getId());
item.setUpdateUserId(1L);
item.setUpdateUserName("系统管理员");
item.setUpdateTime(new Date());
return item;
} }
return null; }).collect(Collectors.toList());
}).filter(f -> f != null).collect(Collectors.toList()); Map<Boolean, List<UserEntity>> saveUpdateCollect = saveUpdateUserList.stream().collect(Collectors.partitioningBy(x -> x.getId() == null));
if (!ObjectUtils.isEmpty(saveUpdateCollect.get(true))) {
//需要新增的用户
if (!ObjectUtils.isEmpty(saveUserList)) { log.info("需要新增用户数量:{}", saveUpdateCollect.get(true).size());
saveUserList.stream().forEach(item->{ saveUpdateCollect.get(true).stream().forEach(item -> {
this.getUserDao().insert(item); this.getUserDao().insert(item);
}); });
}
//userService.save(saveUserList); if (!ObjectUtils.isEmpty(saveUpdateCollect.get(false))) {
//需要新增的用户
log.info("需要更新用户数量:{}", saveUpdateCollect.get(false).size());
saveUpdateCollect.get(false).stream().forEach(item -> {
this.getUserDao().update(item);
});
} }
} }
//查找新增 与更新 //查找新增 与更新
} }
return Rest.ok(); return Rest.ok();
} }
......
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