Commit 08445f52b3d6cae29d780122ee5f00f38546db4e
Committed by
Gitee
!1487 fix: 修复导入用户的 username 为空时会异常问题
Merge pull request !1487 from 半栈幼儿员/hotfix/user
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 | 36 | import com.mzt.logapi.starter.annotation.LogRecord; |
| 37 | 37 | import jakarta.annotation.Resource; |
| 38 | 38 | import jakarta.validation.ConstraintViolationException; |
| 39 | +import java.util.concurrent.atomic.AtomicInteger; | |
| 39 | 40 | import lombok.extern.slf4j.Slf4j; |
| 40 | 41 | import org.springframework.context.annotation.Lazy; |
| 41 | 42 | import org.springframework.security.crypto.password.PasswordEncoder; |
| ... | ... | @@ -284,11 +285,16 @@ public class AdminUserServiceImpl implements AdminUserService { |
| 284 | 285 | @Override |
| 285 | 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 | 299 | return userMapper.selectPage(reqVO, getDeptCondition(reqVO.getDeptId()), userIds); |
| 294 | 300 | } |
| ... | ... | @@ -484,12 +490,16 @@ public class AdminUserServiceImpl implements AdminUserService { |
| 484 | 490 | // 2. 遍历,逐个创建 or 更新 |
| 485 | 491 | UserImportRespVO respVO = UserImportRespVO.builder().createUsernames(new ArrayList<>()) |
| 486 | 492 | .updateUsernames(new ArrayList<>()).failureUsernames(new LinkedHashMap<>()).build(); |
| 493 | + AtomicInteger index = new AtomicInteger(1); | |
| 487 | 494 | importUsers.forEach(importUser -> { |
| 495 | + int currentIndex = index.getAndIncrement(); | |
| 488 | 496 | // 2.1.1 校验字段是否符合要求 |
| 489 | 497 | try { |
| 490 | 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 | 503 | return; |
| 494 | 504 | } |
| 495 | 505 | // 2.1.2 校验,判断是否有不符合的原因 | ... | ... |