From 1cd1efdaf9ee4f137e81f2e391c4722cf67145b1 Mon Sep 17 00:00:00 2001 From: bynt Date: Tue, 28 Dec 2021 11:07:32 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A4=E6=96=AD=E6=98=AF=E5=90=A6=E4=B8=BA?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E5=91=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../constant/DefaultNumberConstants.java | 10 +++++++++ .../modules/system/service/dto/UserDto.java | 2 ++ .../system/service/impl/UserServiceImpl.java | 21 +++++++++++++++---- 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/ad-platform-common/src/main/java/com/baiye/constant/DefaultNumberConstants.java b/ad-platform-common/src/main/java/com/baiye/constant/DefaultNumberConstants.java index efb043d2..e9813d85 100644 --- a/ad-platform-common/src/main/java/com/baiye/constant/DefaultNumberConstants.java +++ b/ad-platform-common/src/main/java/com/baiye/constant/DefaultNumberConstants.java @@ -47,6 +47,16 @@ public class DefaultNumberConstants { */ public static final int SIX_NUMBER = 6; + /** + * 7 + */ + public static final int SEVEN_NUMBER = 7; + + /** + * 8 + */ + public static final int EIGHT_NUMBER = 8; + /** * 9 */ diff --git a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/dto/UserDto.java b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/dto/UserDto.java index 8cd83902..8085733b 100644 --- a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/dto/UserDto.java +++ b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/dto/UserDto.java @@ -62,4 +62,6 @@ public class UserDto extends BaseDTO implements Serializable { private Boolean isAdmin = false; private Date pwdResetTime; + + private Boolean isManager; } diff --git a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/impl/UserServiceImpl.java b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/impl/UserServiceImpl.java index 2b64aa1b..6aab90ef 100644 --- a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/impl/UserServiceImpl.java +++ b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/impl/UserServiceImpl.java @@ -15,12 +15,15 @@ */ package com.baiye.modules.system.service.impl; +import cn.hutool.core.convert.Convert; import com.baiye.config.properties.FileProperties; +import com.baiye.constant.DefaultNumberConstants; import com.baiye.exception.BadRequestException; import com.baiye.exception.EntityExistException; import com.baiye.exception.EntityNotFoundException; import com.baiye.modules.security.service.OnlineUserService; import com.baiye.modules.security.service.UserCacheClean; +import com.baiye.modules.system.domain.Role; import com.baiye.modules.system.domain.User; import com.baiye.modules.system.repository.UserRepository; import com.baiye.modules.system.service.UserService; @@ -123,7 +126,7 @@ public class UserServiceImpl implements UserService { redisUtils.del(CacheKey.ROLE_AUTH + resources.getId()); } // 如果用户被禁用,则清除用户登录信息 - if(!resources.getEnabled()){ + if (!resources.getEnabled()) { onlineUserService.kickOutForUsername(resources.getUsername()); } user.setUsername(resources.getUsername()); @@ -169,12 +172,22 @@ public class UserServiceImpl implements UserService { @Override public UserDto findByName(String userName) { + UserDto convert; User user = userRepository.findByUsername(userName); if (user == null) { throw new EntityNotFoundException(User.class, "name", userName); } else { - return userMapper.toDto(user); + convert = Convert.convert(UserDto.class, user); + Set roles = user.getRoles(); + convert.setIsManager(Boolean.FALSE); + for (Role role : roles) { + // TODO 修改管理员id + if (role.getId() == DefaultNumberConstants.EIGHT_NUMBER) { + convert.setIsManager(Boolean.TRUE); + } + } } + return convert; } @Override @@ -192,8 +205,8 @@ public class UserServiceImpl implements UserService { // 验证文件上传的格式 String image = "gif jpg png jpeg"; String fileType = FileUtil.getExtensionName(multipartFile.getOriginalFilename()); - if(fileType != null && !image.contains(fileType)){ - throw new BadRequestException("文件格式错误!, 仅支持 " + image +" 格式"); + if (fileType != null && !image.contains(fileType)) { + throw new BadRequestException("文件格式错误!, 仅支持 " + image + " 格式"); } User user = userRepository.findByUsername(SecurityUtils.getCurrentUsername()); String oldPath = user.getAvatarPath();