Commit 7912a54ebd0d8057b948384a6dbec4d4bc122196
1 parent
b7380019
【修复】没有数据权限时,添加/修改用户的唯一手机、账号等字段的校验不正确
Showing
1 changed file
with
9 additions
and
3 deletions
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/user/AdminUserServiceImpl.java
| ... | ... | @@ -8,6 +8,7 @@ import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 8 | 8 | import cn.iocoder.yudao.framework.common.exception.ServiceException; |
| 9 | 9 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 10 | 10 | import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; |
| 11 | +import cn.iocoder.yudao.framework.datapermission.core.annotation.DataPermission; | |
| 11 | 12 | import cn.iocoder.yudao.module.infra.api.file.FileApi; |
| 12 | 13 | import cn.iocoder.yudao.module.system.controller.admin.user.vo.profile.UserProfileUpdatePasswordReqVO; |
| 13 | 14 | import cn.iocoder.yudao.module.system.controller.admin.user.vo.profile.UserProfileUpdateReqVO; |
| ... | ... | @@ -72,6 +73,10 @@ public class AdminUserServiceImpl implements AdminUserService { |
| 72 | 73 | @Resource |
| 73 | 74 | private FileApi fileApi; |
| 74 | 75 | |
| 76 | + @Resource | |
| 77 | + @Lazy // 循环依赖(自己依赖自己),避免报错 | |
| 78 | + private AdminUserServiceImpl self; | |
| 79 | + | |
| 75 | 80 | @Override |
| 76 | 81 | @Transactional(rollbackFor = Exception.class) |
| 77 | 82 | public Long createUser(UserCreateReqVO reqVO) { |
| ... | ... | @@ -83,7 +88,7 @@ public class AdminUserServiceImpl implements AdminUserService { |
| 83 | 88 | } |
| 84 | 89 | }); |
| 85 | 90 | // 校验正确性 |
| 86 | - checkCreateOrUpdate(null, reqVO.getUsername(), reqVO.getMobile(), reqVO.getEmail(), | |
| 91 | + self.checkCreateOrUpdate(null, reqVO.getUsername(), reqVO.getMobile(), reqVO.getEmail(), | |
| 87 | 92 | reqVO.getDeptId(), reqVO.getPostIds()); |
| 88 | 93 | // 插入用户 |
| 89 | 94 | AdminUserDO user = UserConvert.INSTANCE.convert(reqVO); |
| ... | ... | @@ -102,7 +107,7 @@ public class AdminUserServiceImpl implements AdminUserService { |
| 102 | 107 | @Transactional(rollbackFor = Exception.class) |
| 103 | 108 | public void updateUser(UserUpdateReqVO reqVO) { |
| 104 | 109 | // 校验正确性 |
| 105 | - checkCreateOrUpdate(reqVO.getId(), reqVO.getUsername(), reqVO.getMobile(), reqVO.getEmail(), | |
| 110 | + self.checkCreateOrUpdate(reqVO.getId(), reqVO.getUsername(), reqVO.getMobile(), reqVO.getEmail(), | |
| 106 | 111 | reqVO.getDeptId(), reqVO.getPostIds()); |
| 107 | 112 | // 更新用户 |
| 108 | 113 | AdminUserDO updateObj = UserConvert.INSTANCE.convert(reqVO); |
| ... | ... | @@ -299,7 +304,8 @@ public class AdminUserServiceImpl implements AdminUserService { |
| 299 | 304 | return deptIds; |
| 300 | 305 | } |
| 301 | 306 | |
| 302 | - private void checkCreateOrUpdate(Long id, String username, String mobile, String email, | |
| 307 | + @DataPermission(enable = false) // 关闭数据权限,避免因为没有数据权限,查询不到数据,进而导致唯一校验不正确 | |
| 308 | + public void checkCreateOrUpdate(Long id, String username, String mobile, String email, | |
| 303 | 309 | Long deptId, Set<Long> postIds) { |
| 304 | 310 | // 校验用户存在 |
| 305 | 311 | checkUserExists(id); | ... | ... |