From 8433c3ad71bfa3c52739d990035d3922ee91074a Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sat, 31 Dec 2022 17:31:14 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E4=BF=AE=E5=A4=8D=E3=80=91=E6=B2=A1?= =?UTF-8?q?=E6=9C=89=E6=95=B0=E6=8D=AE=E6=9D=83=E9=99=90=E6=97=B6=EF=BC=8C?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0/=E4=BF=AE=E6=94=B9=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E7=9A=84=E5=94=AF=E4=B8=80=E6=89=8B=E6=9C=BA=E3=80=81=E8=B4=A6?= =?UTF-8?q?=E5=8F=B7=E7=AD=89=E5=AD=97=E6=AE=B5=E7=9A=84=E6=A0=A1=E9=AA=8C?= =?UTF-8?q?=E4=B8=8D=E6=AD=A3=E7=A1=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/service/user/AdminUserServiceImpl.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/user/AdminUserServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/user/AdminUserServiceImpl.java index d54b8fd25..a8937f520 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/user/AdminUserServiceImpl.java +++ b/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; import cn.iocoder.yudao.framework.common.exception.ServiceException; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; +import cn.iocoder.yudao.framework.datapermission.core.annotation.DataPermission; import cn.iocoder.yudao.module.infra.api.file.FileApi; import cn.iocoder.yudao.module.system.controller.admin.user.vo.profile.UserProfileUpdatePasswordReqVO; import cn.iocoder.yudao.module.system.controller.admin.user.vo.profile.UserProfileUpdateReqVO; @@ -72,6 +73,10 @@ public class AdminUserServiceImpl implements AdminUserService { @Resource private FileApi fileApi; + @Resource + @Lazy // 循环依赖(自己依赖自己),避免报错 + private AdminUserServiceImpl self; + @Override @Transactional(rollbackFor = Exception.class) public Long createUser(UserCreateReqVO reqVO) { @@ -83,7 +88,7 @@ public class AdminUserServiceImpl implements AdminUserService { } }); // 校验正确性 - checkCreateOrUpdate(null, reqVO.getUsername(), reqVO.getMobile(), reqVO.getEmail(), + self.checkCreateOrUpdate(null, reqVO.getUsername(), reqVO.getMobile(), reqVO.getEmail(), reqVO.getDeptId(), reqVO.getPostIds()); // 插入用户 AdminUserDO user = UserConvert.INSTANCE.convert(reqVO); @@ -102,7 +107,7 @@ public class AdminUserServiceImpl implements AdminUserService { @Transactional(rollbackFor = Exception.class) public void updateUser(UserUpdateReqVO reqVO) { // 校验正确性 - checkCreateOrUpdate(reqVO.getId(), reqVO.getUsername(), reqVO.getMobile(), reqVO.getEmail(), + self.checkCreateOrUpdate(reqVO.getId(), reqVO.getUsername(), reqVO.getMobile(), reqVO.getEmail(), reqVO.getDeptId(), reqVO.getPostIds()); // 更新用户 AdminUserDO updateObj = UserConvert.INSTANCE.convert(reqVO); @@ -299,7 +304,8 @@ public class AdminUserServiceImpl implements AdminUserService { return deptIds; } - private void checkCreateOrUpdate(Long id, String username, String mobile, String email, + @DataPermission(enable = false) // 关闭数据权限,避免因为没有数据权限,查询不到数据,进而导致唯一校验不正确 + public void checkCreateOrUpdate(Long id, String username, String mobile, String email, Long deptId, Set postIds) { // 校验用户存在 checkUserExists(id);