优化用户导入功能,支持批量岗位关联
优化了用户导入服务,新增了在创建或更新用户时批量设置岗位关联的能力。现在会在用户导入时,将用户岗位信息批量插入到`user_post`关联表中,提升了效率并减少了数据库操作的次数。
This commit is contained in:
parent
5117cf4115
commit
3c21758abb
@ -593,6 +593,8 @@ public class AdminUserServiceImpl implements AdminUserService {
|
||||
throw exception(USER_IMPORT_LIST_IS_EMPTY);
|
||||
}
|
||||
UserImportRespVO respVO = UserImportRespVO.builder().createUsernames(new ArrayList<>()).updateUsernames(new ArrayList<>()).failureUsernames(new LinkedHashMap<>()).build();
|
||||
|
||||
List<UserPostDO> userPostDOS = new ArrayList<>();
|
||||
importUsers.forEach(importUser -> {
|
||||
//校验,判断是否有不符合的原因
|
||||
try {
|
||||
@ -635,6 +637,10 @@ public class AdminUserServiceImpl implements AdminUserService {
|
||||
if (existUser == null) {
|
||||
userMapper.insert(updateUser.setPassword(encodePassword(userInitPassword))); // 设置默认密码
|
||||
|
||||
// 设置 user_post关联表
|
||||
userPostDOS.addAll(convertList(updateUser.getPostIds(),
|
||||
postId -> new UserPostDO().setUserId(updateUser.getId()).setPostId(postId)));
|
||||
|
||||
respVO.getCreateUsernames().add(importUser.getNickname());
|
||||
return;
|
||||
}
|
||||
@ -648,8 +654,15 @@ public class AdminUserServiceImpl implements AdminUserService {
|
||||
|
||||
updateUser.setId(existUser.getId());
|
||||
userMapper.updateById(updateUser);
|
||||
// 更新用户岗位关联表
|
||||
updateUserPost(new UserSaveReqVO().setId(existUser.getId()), new AdminUserDO().setPostIds(updateUser.getPostIds()));
|
||||
respVO.getUpdateUsernames().add(importUser.getNickname());
|
||||
});
|
||||
|
||||
// 插入user_post
|
||||
if (CollectionUtil.isNotEmpty(userPostDOS)) {
|
||||
userPostMapper.insertBatch(userPostDOS);
|
||||
}
|
||||
return respVO;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user