From 01e91d252ced5f3ebbe281fa654f9ff322af5a08 Mon Sep 17 00:00:00 2001 From: Ziin Date: Thu, 17 Jul 2025 16:50:22 +0800 Subject: [PATCH] =?UTF-8?q?1.=E6=8A=BD=E7=A6=BB=20getUserByName=20?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E8=BF=9B=E8=A1=8C=E5=A4=8D=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/UserController.java | 65 +++++++------------ 1 file changed, 23 insertions(+), 42 deletions(-) diff --git a/src/main/java/com/yupi/springbootinit/controller/UserController.java b/src/main/java/com/yupi/springbootinit/controller/UserController.java index 3aff4af..089aa3a 100644 --- a/src/main/java/com/yupi/springbootinit/controller/UserController.java +++ b/src/main/java/com/yupi/springbootinit/controller/UserController.java @@ -34,20 +34,7 @@ public class UserController { // 用户登陆接口 @PostMapping("doLogin") public BaseResponse doLogin(@RequestBody SystemUsersDTO usersDTO) { - SystemUsers user = usersService.getUserByUserName(usersDTO.getUsername(),usersDTO.getTenantId()); - if (user == null) { - throw new BusinessException(ErrorCode.USERNAME_OR_PASSWORD_ERROR); - } - if (!usersService.isPasswordMatch(usersDTO.getPassword(), user.getPassword())) { - throw new BusinessException(ErrorCode.USERNAME_OR_PASSWORD_ERROR); - } - - if (CommonStatusEnum.isDisable(Integer.valueOf(user.getStatus()))) { - throw new BusinessException(ErrorCode.USER_DISABLE); - } - if (usersService.isExpired(usersDTO.getTenantId())){ - throw new BusinessException(ErrorCode.PACKAGE_EXPIRED); - } + SystemUsers user = getUserByName(usersDTO); if (!usersService.checkCrawlRole(user.getId())){ throw new BusinessException(ErrorCode.LOGIN_NOW_ALLOWED); } @@ -63,23 +50,11 @@ public class UserController { return ResultUtils.success(systemUsersVO); } + // 用户登陆接口 @PostMapping("bigbrother-doLogin") public BaseResponse bigBrotherDoLogin(@RequestBody SystemUsersDTO usersDTO) { - SystemUsers user = usersService.getUserByUserName(usersDTO.getUsername(),usersDTO.getTenantId()); - if (user == null) { - throw new BusinessException(ErrorCode.USERNAME_OR_PASSWORD_ERROR); - } - if (!usersService.isPasswordMatch(usersDTO.getPassword(), user.getPassword())) { - throw new BusinessException(ErrorCode.USERNAME_OR_PASSWORD_ERROR); - } - - if (CommonStatusEnum.isDisable(Integer.valueOf(user.getStatus()))) { - throw new BusinessException(ErrorCode.USER_DISABLE); - } - if (usersService.isExpired(usersDTO.getTenantId())){ - throw new BusinessException(ErrorCode.PACKAGE_EXPIRED); - } + SystemUsers user = getUserByName(usersDTO); if (!usersService.checkbigBrotherlRole(user.getId())){ throw new BusinessException(ErrorCode.LOGIN_NOW_ALLOWED); } @@ -98,20 +73,7 @@ public class UserController { // 用户登陆接口 @PostMapping("aiChat-doLogin") public BaseResponse aiChatDoLogin(@RequestBody SystemUsersDTO usersDTO) { - SystemUsers user = usersService.getUserByUserName(usersDTO.getUsername(),usersDTO.getTenantId()); - if (user == null) { - throw new BusinessException(ErrorCode.USERNAME_OR_PASSWORD_ERROR); - } - if (!usersService.isPasswordMatch(usersDTO.getPassword(), user.getPassword())) { - throw new BusinessException(ErrorCode.USERNAME_OR_PASSWORD_ERROR); - } - - if (CommonStatusEnum.isDisable(Integer.valueOf(user.getStatus()))) { - throw new BusinessException(ErrorCode.USER_DISABLE); - } - if (usersService.isExpired(usersDTO.getTenantId())){ - throw new BusinessException(ErrorCode.PACKAGE_EXPIRED); - } + SystemUsers user = getUserByName(usersDTO); if (!usersService.checkAiCHatLoginRole(user.getId())){ throw new BusinessException(ErrorCode.LOGIN_NOW_ALLOWED); } @@ -126,4 +88,23 @@ public class UserController { systemUsersVO.setTokenValue(StpUtil.getTokenValue()); return ResultUtils.success(systemUsersVO); } + + private SystemUsers getUserByName(@RequestBody SystemUsersDTO usersDTO) { + SystemUsers user = usersService.getUserByUserName(usersDTO.getUsername(),usersDTO.getTenantId()); + if (user == null) { + throw new BusinessException(ErrorCode.USERNAME_OR_PASSWORD_ERROR); + } + if (!usersService.isPasswordMatch(usersDTO.getPassword(), user.getPassword())) { + throw new BusinessException(ErrorCode.USERNAME_OR_PASSWORD_ERROR); + } + + if (CommonStatusEnum.isDisable(Integer.valueOf(user.getStatus()))) { + throw new BusinessException(ErrorCode.USER_DISABLE); + } + if (usersService.isExpired(usersDTO.getTenantId())){ + throw new BusinessException(ErrorCode.PACKAGE_EXPIRED); + } + return user; + } + }