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; + } + }