From 8fcdccc8c04781fd5bcaa6321da5217a46bada13 Mon Sep 17 00:00:00 2001 From: lihongjie0209 Date: Wed, 13 Nov 2024 20:44:56 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=94=A8=E6=88=B7=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E7=A1=AE=E4=BF=9D=E8=A6=81=E6=9C=89=E4=B8=80?= =?UTF-8?q?=E4=B8=AA=E7=AE=A1=E7=90=86=E5=91=98=E8=B4=A6=E6=88=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../coal/user/service/UserService.java | 34 ++++++++++++++++--- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/src/main/java/cn/lihongjie/coal/user/service/UserService.java b/src/main/java/cn/lihongjie/coal/user/service/UserService.java index 96febce7..71696586 100644 --- a/src/main/java/cn/lihongjie/coal/user/service/UserService.java +++ b/src/main/java/cn/lihongjie/coal/user/service/UserService.java @@ -81,8 +81,7 @@ public class UserService extends BaseService { @Autowired PasswordDictService passwordDictService; private Pbkdf2PasswordEncoder passwordEncoder; - @Autowired - UserService that; + @Autowired UserService that; @PostConstruct public void init() { @@ -193,14 +192,41 @@ public class UserService extends BaseService { UserEntity user = this.repository.get(request.getId()); this.mapper.updateEntity(user, request); this.repository.save(user); + String organizationId = user.getOrganizationId(); + + assertAdmin(organizationId); + clearUserCache(request.getId()); return getById(user.getId()); } + private void assertAdmin(String organizationId) { + long adminCnt = + this.repository.count( + new Specification() { + @Override + public Predicate toPredicate( + Root root, + CriteriaQuery query, + CriteriaBuilder criteriaBuilder) { + return criteriaBuilder.and( + criteriaBuilder.equal( + root.get("organizationId"), organizationId), + criteriaBuilder.equal(root.get("orgAdmin"), true)); + } + }); + + if (adminCnt == 0) { + throw new BizException("组织必须有一个管理员"); + } + } + public void delete(IdRequest request) { this.repository.deleteAllById(request.getIds()); request.getIds().forEach(this::clearUserCache); + + this.assertAdmin(Ctx.currentUser().getOrganizationId()); } public UserDto getById(String id) { @@ -541,7 +567,7 @@ public class UserService extends BaseService { stopWatch.start("contains"); boolean contains = ids.contains(resourceId); stopWatch.stop(); -// log.info(stopWatch.prettyPrint()); + // log.info(stopWatch.prettyPrint()); return contains; } @@ -549,7 +575,5 @@ public class UserService extends BaseService { Try.run(() -> cacheManager.getCache(Constants.CACHE_USER_RESOURCES).clear()); Try.run(() -> cacheManager.getCache(Constants.CACHE_USER_PERMISSIONS).clear()); Try.run(() -> cacheManager.getCache(Constants.CACHE_USER_RESOURCE_IDS).clear()); - - } }