Commit 69da706f555df8329c63584f3134f520d0d04a8c
1 parent
eb246a2d
🐞 fix: 修复导入用户的 username 为空时会异常问题
Showing
1 changed file
with
16 additions
and
6 deletions
yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/user/AdminUserServiceImpl.java
| @@ -36,6 +36,7 @@ import com.mzt.logapi.service.impl.DiffParseFunction; | @@ -36,6 +36,7 @@ import com.mzt.logapi.service.impl.DiffParseFunction; | ||
| 36 | import com.mzt.logapi.starter.annotation.LogRecord; | 36 | import com.mzt.logapi.starter.annotation.LogRecord; |
| 37 | import jakarta.annotation.Resource; | 37 | import jakarta.annotation.Resource; |
| 38 | import jakarta.validation.ConstraintViolationException; | 38 | import jakarta.validation.ConstraintViolationException; |
| 39 | +import java.util.concurrent.atomic.AtomicInteger; | ||
| 39 | import lombok.extern.slf4j.Slf4j; | 40 | import lombok.extern.slf4j.Slf4j; |
| 40 | import org.springframework.context.annotation.Lazy; | 41 | import org.springframework.context.annotation.Lazy; |
| 41 | import org.springframework.security.crypto.password.PasswordEncoder; | 42 | import org.springframework.security.crypto.password.PasswordEncoder; |
| @@ -284,11 +285,16 @@ public class AdminUserServiceImpl implements AdminUserService { | @@ -284,11 +285,16 @@ public class AdminUserServiceImpl implements AdminUserService { | ||
| 284 | @Override | 285 | @Override |
| 285 | public PageResult<AdminUserDO> getUserPage(UserPageReqVO reqVO) { | 286 | public PageResult<AdminUserDO> getUserPage(UserPageReqVO reqVO) { |
| 286 | // 如果有角色编号,查询角色对应的用户编号 | 287 | // 如果有角色编号,查询角色对应的用户编号 |
| 287 | - Set<Long> userIds = reqVO.getRoleId() != null ? | ||
| 288 | - permissionService.getUserRoleIdListByRoleId(singleton(reqVO.getRoleId())) : null; | ||
| 289 | - if (userIds != null && userIds.isEmpty()) { | ||
| 290 | - return PageResult.empty(); | 288 | + Set<Long> userIds; |
| 289 | + if (reqVO.getRoleId() != null) { | ||
| 290 | + userIds = permissionService.getUserRoleIdListByRoleId(singleton(reqVO.getRoleId())); | ||
| 291 | + if (CollUtil.isEmpty(userIds)) { | ||
| 292 | + return PageResult.empty(); | ||
| 293 | + } | ||
| 294 | + } else { | ||
| 295 | + userIds = null; | ||
| 291 | } | 296 | } |
| 297 | + | ||
| 292 | // 分页查询 | 298 | // 分页查询 |
| 293 | return userMapper.selectPage(reqVO, getDeptCondition(reqVO.getDeptId()), userIds); | 299 | return userMapper.selectPage(reqVO, getDeptCondition(reqVO.getDeptId()), userIds); |
| 294 | } | 300 | } |
| @@ -484,12 +490,16 @@ public class AdminUserServiceImpl implements AdminUserService { | @@ -484,12 +490,16 @@ public class AdminUserServiceImpl implements AdminUserService { | ||
| 484 | // 2. 遍历,逐个创建 or 更新 | 490 | // 2. 遍历,逐个创建 or 更新 |
| 485 | UserImportRespVO respVO = UserImportRespVO.builder().createUsernames(new ArrayList<>()) | 491 | UserImportRespVO respVO = UserImportRespVO.builder().createUsernames(new ArrayList<>()) |
| 486 | .updateUsernames(new ArrayList<>()).failureUsernames(new LinkedHashMap<>()).build(); | 492 | .updateUsernames(new ArrayList<>()).failureUsernames(new LinkedHashMap<>()).build(); |
| 493 | + AtomicInteger index = new AtomicInteger(1); | ||
| 487 | importUsers.forEach(importUser -> { | 494 | importUsers.forEach(importUser -> { |
| 495 | + int currentIndex = index.getAndIncrement(); | ||
| 488 | // 2.1.1 校验字段是否符合要求 | 496 | // 2.1.1 校验字段是否符合要求 |
| 489 | try { | 497 | try { |
| 490 | ValidationUtils.validate(BeanUtils.toBean(importUser, UserSaveReqVO.class).setPassword(initPassword)); | 498 | ValidationUtils.validate(BeanUtils.toBean(importUser, UserSaveReqVO.class).setPassword(initPassword)); |
| 491 | - } catch (ConstraintViolationException ex){ | ||
| 492 | - respVO.getFailureUsernames().put(importUser.getUsername(), ex.getMessage()); | 499 | + } catch (ConstraintViolationException ex) { |
| 500 | + String key = importUser.getUsername(); | ||
| 501 | + if (StrUtil.isBlank(key)) key = "第" + currentIndex + "行"; | ||
| 502 | + respVO.getFailureUsernames().put(key, ex.getMessage()); | ||
| 493 | return; | 503 | return; |
| 494 | } | 504 | } |
| 495 | // 2.1.2 校验,判断是否有不符合的原因 | 505 | // 2.1.2 校验,判断是否有不符合的原因 |