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,6 +8,7 @@ import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | ||
| 8 | import cn.iocoder.yudao.framework.common.exception.ServiceException; | 8 | import cn.iocoder.yudao.framework.common.exception.ServiceException; |
| 9 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 9 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 10 | import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; | 10 | import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; |
| 11 | +import cn.iocoder.yudao.framework.datapermission.core.annotation.DataPermission; | ||
| 11 | import cn.iocoder.yudao.module.infra.api.file.FileApi; | 12 | import cn.iocoder.yudao.module.infra.api.file.FileApi; |
| 12 | import cn.iocoder.yudao.module.system.controller.admin.user.vo.profile.UserProfileUpdatePasswordReqVO; | 13 | import cn.iocoder.yudao.module.system.controller.admin.user.vo.profile.UserProfileUpdatePasswordReqVO; |
| 13 | import cn.iocoder.yudao.module.system.controller.admin.user.vo.profile.UserProfileUpdateReqVO; | 14 | import cn.iocoder.yudao.module.system.controller.admin.user.vo.profile.UserProfileUpdateReqVO; |
| @@ -72,6 +73,10 @@ public class AdminUserServiceImpl implements AdminUserService { | @@ -72,6 +73,10 @@ public class AdminUserServiceImpl implements AdminUserService { | ||
| 72 | @Resource | 73 | @Resource |
| 73 | private FileApi fileApi; | 74 | private FileApi fileApi; |
| 74 | 75 | ||
| 76 | + @Resource | ||
| 77 | + @Lazy // 循环依赖(自己依赖自己),避免报错 | ||
| 78 | + private AdminUserServiceImpl self; | ||
| 79 | + | ||
| 75 | @Override | 80 | @Override |
| 76 | @Transactional(rollbackFor = Exception.class) | 81 | @Transactional(rollbackFor = Exception.class) |
| 77 | public Long createUser(UserCreateReqVO reqVO) { | 82 | public Long createUser(UserCreateReqVO reqVO) { |
| @@ -83,7 +88,7 @@ public class AdminUserServiceImpl implements AdminUserService { | @@ -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 | reqVO.getDeptId(), reqVO.getPostIds()); | 92 | reqVO.getDeptId(), reqVO.getPostIds()); |
| 88 | // 插入用户 | 93 | // 插入用户 |
| 89 | AdminUserDO user = UserConvert.INSTANCE.convert(reqVO); | 94 | AdminUserDO user = UserConvert.INSTANCE.convert(reqVO); |
| @@ -102,7 +107,7 @@ public class AdminUserServiceImpl implements AdminUserService { | @@ -102,7 +107,7 @@ public class AdminUserServiceImpl implements AdminUserService { | ||
| 102 | @Transactional(rollbackFor = Exception.class) | 107 | @Transactional(rollbackFor = Exception.class) |
| 103 | public void updateUser(UserUpdateReqVO reqVO) { | 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 | reqVO.getDeptId(), reqVO.getPostIds()); | 111 | reqVO.getDeptId(), reqVO.getPostIds()); |
| 107 | // 更新用户 | 112 | // 更新用户 |
| 108 | AdminUserDO updateObj = UserConvert.INSTANCE.convert(reqVO); | 113 | AdminUserDO updateObj = UserConvert.INSTANCE.convert(reqVO); |
| @@ -299,7 +304,8 @@ public class AdminUserServiceImpl implements AdminUserService { | @@ -299,7 +304,8 @@ public class AdminUserServiceImpl implements AdminUserService { | ||
| 299 | return deptIds; | 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 | Long deptId, Set<Long> postIds) { | 309 | Long deptId, Set<Long> postIds) { |
| 304 | // 校验用户存在 | 310 | // 校验用户存在 |
| 305 | checkUserExists(id); | 311 | checkUserExists(id); |