mirror of
				https://github.com/continew-org/continew-admin.git
				synced 2025-10-31 22:57:17 +08:00 
			
		
		
		
	优化:优化校验器相关方法名
This commit is contained in:
		| @@ -186,7 +186,7 @@ public class MailUtils { | |||||||
|      */ |      */ | ||||||
|     public static void send(Collection<String> tos, Collection<String> ccs, Collection<String> bccs, String subject, |     public static void send(Collection<String> tos, Collection<String> ccs, Collection<String> bccs, String subject, | ||||||
|         String content, boolean isHtml, File... files) throws MessagingException { |         String content, boolean isHtml, File... files) throws MessagingException { | ||||||
|         CheckUtils.exIfCondition(() -> CollUtil.isEmpty(tos), "请至少指定一名收件人"); |         CheckUtils.throwIf(() -> CollUtil.isEmpty(tos), "请至少指定一名收件人"); | ||||||
|         MimeMessage mimeMessage = MAIL_SENDER.createMimeMessage(); |         MimeMessage mimeMessage = MAIL_SENDER.createMimeMessage(); | ||||||
|         MimeMessageHelper messageHelper = |         MimeMessageHelper messageHelper = | ||||||
|             new MimeMessageHelper(mimeMessage, true, StandardCharsets.UTF_8.displayName()); |             new MimeMessageHelper(mimeMessage, true, StandardCharsets.UTF_8.displayName()); | ||||||
|   | |||||||
| @@ -57,7 +57,7 @@ public class SecureUtils { | |||||||
|      */ |      */ | ||||||
|     public static String decryptByRsaPrivateKey(String data) { |     public static String decryptByRsaPrivateKey(String data) { | ||||||
|         String privateKey = RsaProperties.PRIVATE_KEY; |         String privateKey = RsaProperties.PRIVATE_KEY; | ||||||
|         ValidationUtils.exIfBlank(privateKey, "请配置 RSA 私钥"); |         ValidationUtils.throwIfBlank(privateKey, "请配置 RSA 私钥"); | ||||||
|         return decryptByRsaPrivateKey(data, privateKey); |         return decryptByRsaPrivateKey(data, privateKey); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -43,8 +43,8 @@ public class CheckUtils extends Validator { | |||||||
|      * @param message |      * @param message | ||||||
|      *            错误信息 |      *            错误信息 | ||||||
|      */ |      */ | ||||||
|     public static void exIfBlank(CharSequence str, String message) { |     public static void throwIfBlank(CharSequence str, String message) { | ||||||
|         exIfBlank(str, message, EXCEPTION_TYPE); |         throwIfBlank(str, message, EXCEPTION_TYPE); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
| @@ -55,8 +55,8 @@ public class CheckUtils extends Validator { | |||||||
|      * @param message |      * @param message | ||||||
|      *            错误信息 |      *            错误信息 | ||||||
|      */ |      */ | ||||||
|     public static void exIfNotBlank(CharSequence str, String message) { |     public static void throwIfNotBlank(CharSequence str, String message) { | ||||||
|         exIfNotBlank(str, message, EXCEPTION_TYPE); |         throwIfNotBlank(str, message, EXCEPTION_TYPE); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
| @@ -69,8 +69,8 @@ public class CheckUtils extends Validator { | |||||||
|      * @param message |      * @param message | ||||||
|      *            错误信息 |      *            错误信息 | ||||||
|      */ |      */ | ||||||
|     public static void exIfEqual(Object obj1, Object obj2, String message) { |     public static void throwIfEqual(Object obj1, Object obj2, String message) { | ||||||
|         exIfEqual(obj1, obj2, message, EXCEPTION_TYPE); |         throwIfEqual(obj1, obj2, message, EXCEPTION_TYPE); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
| @@ -83,8 +83,8 @@ public class CheckUtils extends Validator { | |||||||
|      * @param message |      * @param message | ||||||
|      *            错误信息 |      *            错误信息 | ||||||
|      */ |      */ | ||||||
|     public static void exIfNotEqual(Object obj1, Object obj2, String message) { |     public static void throwIfNotEqual(Object obj1, Object obj2, String message) { | ||||||
|         exIfNotEqual(obj1, obj2, message, EXCEPTION_TYPE); |         throwIfNotEqual(obj1, obj2, message, EXCEPTION_TYPE); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
| @@ -97,8 +97,8 @@ public class CheckUtils extends Validator { | |||||||
|      * @param message |      * @param message | ||||||
|      *            错误信息 |      *            错误信息 | ||||||
|      */ |      */ | ||||||
|     public static void exIfEqualIgnoreCase(CharSequence str1, CharSequence str2, String message) { |     public static void throwIfEqualIgnoreCase(CharSequence str1, CharSequence str2, String message) { | ||||||
|         exIfEqualIgnoreCase(str1, str2, message, EXCEPTION_TYPE); |         throwIfEqualIgnoreCase(str1, str2, message, EXCEPTION_TYPE); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
| @@ -111,8 +111,8 @@ public class CheckUtils extends Validator { | |||||||
|      * @param message |      * @param message | ||||||
|      *            错误信息 |      *            错误信息 | ||||||
|      */ |      */ | ||||||
|     public static void exIfNotEqualIgnoreCase(CharSequence str1, CharSequence str2, String message) { |     public static void throwIfNotEqualIgnoreCase(CharSequence str1, CharSequence str2, String message) { | ||||||
|         exIfNotEqualIgnoreCase(str1, str2, message, EXCEPTION_TYPE); |         throwIfNotEqualIgnoreCase(str1, str2, message, EXCEPTION_TYPE); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
| @@ -123,8 +123,8 @@ public class CheckUtils extends Validator { | |||||||
|      * @param message |      * @param message | ||||||
|      *            错误信息 |      *            错误信息 | ||||||
|      */ |      */ | ||||||
|     public static void exIfNull(Object obj, String message) { |     public static void throwIfNull(Object obj, String message) { | ||||||
|         exIfNull(obj, message, EXCEPTION_TYPE); |         throwIfNull(obj, message, EXCEPTION_TYPE); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
| @@ -135,8 +135,8 @@ public class CheckUtils extends Validator { | |||||||
|      * @param message |      * @param message | ||||||
|      *            错误信息 |      *            错误信息 | ||||||
|      */ |      */ | ||||||
|     public static void exIfNotNull(Object obj, String message) { |     public static void throwIfNotNull(Object obj, String message) { | ||||||
|         exIfNotNull(obj, message, EXCEPTION_TYPE); |         throwIfNotNull(obj, message, EXCEPTION_TYPE); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
| @@ -147,7 +147,7 @@ public class CheckUtils extends Validator { | |||||||
|      * @param message |      * @param message | ||||||
|      *            错误信息 |      *            错误信息 | ||||||
|      */ |      */ | ||||||
|     public static void exIfCondition(java.util.function.BooleanSupplier conditionSupplier, String message) { |     public static void throwIf(java.util.function.BooleanSupplier conditionSupplier, String message) { | ||||||
|         exIfCondition(conditionSupplier, message, EXCEPTION_TYPE); |         throwIf(conditionSupplier, message, EXCEPTION_TYPE); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -43,8 +43,8 @@ public class ValidationUtils extends Validator { | |||||||
|      * @param message |      * @param message | ||||||
|      *            错误信息 |      *            错误信息 | ||||||
|      */ |      */ | ||||||
|     public static void exIfBlank(CharSequence str, String message) { |     public static void throwIfBlank(CharSequence str, String message) { | ||||||
|         exIfBlank(str, message, EXCEPTION_TYPE); |         throwIfBlank(str, message, EXCEPTION_TYPE); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
| @@ -55,8 +55,8 @@ public class ValidationUtils extends Validator { | |||||||
|      * @param message |      * @param message | ||||||
|      *            错误信息 |      *            错误信息 | ||||||
|      */ |      */ | ||||||
|     public static void exIfNotBlank(CharSequence str, String message) { |     public static void throwIfNotBlank(CharSequence str, String message) { | ||||||
|         exIfNotBlank(str, message, EXCEPTION_TYPE); |         throwIfNotBlank(str, message, EXCEPTION_TYPE); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
| @@ -69,8 +69,8 @@ public class ValidationUtils extends Validator { | |||||||
|      * @param message |      * @param message | ||||||
|      *            错误信息 |      *            错误信息 | ||||||
|      */ |      */ | ||||||
|     public static void exIfEqual(Object obj1, Object obj2, String message) { |     public static void throwIfEqual(Object obj1, Object obj2, String message) { | ||||||
|         exIfEqual(obj1, obj2, message, EXCEPTION_TYPE); |         throwIfEqual(obj1, obj2, message, EXCEPTION_TYPE); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
| @@ -83,8 +83,8 @@ public class ValidationUtils extends Validator { | |||||||
|      * @param message |      * @param message | ||||||
|      *            错误信息 |      *            错误信息 | ||||||
|      */ |      */ | ||||||
|     public static void exIfNotEqual(Object obj1, Object obj2, String message) { |     public static void throwIfNotEqual(Object obj1, Object obj2, String message) { | ||||||
|         exIfNotEqual(obj1, obj2, message, EXCEPTION_TYPE); |         throwIfNotEqual(obj1, obj2, message, EXCEPTION_TYPE); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
| @@ -97,8 +97,8 @@ public class ValidationUtils extends Validator { | |||||||
|      * @param message |      * @param message | ||||||
|      *            错误信息 |      *            错误信息 | ||||||
|      */ |      */ | ||||||
|     public static void exIfEqualIgnoreCase(CharSequence str1, CharSequence str2, String message) { |     public static void throwIfEqualIgnoreCase(CharSequence str1, CharSequence str2, String message) { | ||||||
|         exIfEqualIgnoreCase(str1, str2, message, EXCEPTION_TYPE); |         throwIfEqualIgnoreCase(str1, str2, message, EXCEPTION_TYPE); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
| @@ -111,8 +111,8 @@ public class ValidationUtils extends Validator { | |||||||
|      * @param message |      * @param message | ||||||
|      *            错误信息 |      *            错误信息 | ||||||
|      */ |      */ | ||||||
|     public static void exIfNotEqualIgnoreCase(CharSequence str1, CharSequence str2, String message) { |     public static void throwIfNotEqualIgnoreCase(CharSequence str1, CharSequence str2, String message) { | ||||||
|         exIfNotEqualIgnoreCase(str1, str2, message, EXCEPTION_TYPE); |         throwIfNotEqualIgnoreCase(str1, str2, message, EXCEPTION_TYPE); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
| @@ -123,8 +123,8 @@ public class ValidationUtils extends Validator { | |||||||
|      * @param message |      * @param message | ||||||
|      *            错误信息 |      *            错误信息 | ||||||
|      */ |      */ | ||||||
|     public static void exIfNull(Object obj, String message) { |     public static void throwIfNull(Object obj, String message) { | ||||||
|         exIfNull(obj, message, EXCEPTION_TYPE); |         throwIfNull(obj, message, EXCEPTION_TYPE); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
| @@ -135,8 +135,8 @@ public class ValidationUtils extends Validator { | |||||||
|      * @param message |      * @param message | ||||||
|      *            错误信息 |      *            错误信息 | ||||||
|      */ |      */ | ||||||
|     public static void exIfNotNull(Object obj, String message) { |     public static void throwIfNotNull(Object obj, String message) { | ||||||
|         exIfNotNull(obj, message, EXCEPTION_TYPE); |         throwIfNotNull(obj, message, EXCEPTION_TYPE); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
| @@ -147,7 +147,7 @@ public class ValidationUtils extends Validator { | |||||||
|      * @param message |      * @param message | ||||||
|      *            错误信息 |      *            错误信息 | ||||||
|      */ |      */ | ||||||
|     public static void exIfCondition(java.util.function.BooleanSupplier conditionSupplier, String message) { |     public static void throwIf(java.util.function.BooleanSupplier conditionSupplier, String message) { | ||||||
|         exIfCondition(conditionSupplier, message, EXCEPTION_TYPE); |         throwIf(conditionSupplier, message, EXCEPTION_TYPE); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -44,8 +44,9 @@ public class Validator { | |||||||
|      * @param exceptionType |      * @param exceptionType | ||||||
|      *            异常类型 |      *            异常类型 | ||||||
|      */ |      */ | ||||||
|     protected static void exIfBlank(CharSequence str, String message, Class<? extends RuntimeException> exceptionType) { |     protected static void throwIfBlank(CharSequence str, String message, | ||||||
|         exIfCondition(() -> StrUtil.isBlank(str), message, exceptionType); |         Class<? extends RuntimeException> exceptionType) { | ||||||
|  |         throwIf(() -> StrUtil.isBlank(str), message, exceptionType); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
| @@ -58,9 +59,9 @@ public class Validator { | |||||||
|      * @param exceptionType |      * @param exceptionType | ||||||
|      *            异常类型 |      *            异常类型 | ||||||
|      */ |      */ | ||||||
|     protected static void exIfNotBlank(CharSequence str, String message, |     protected static void throwIfNotBlank(CharSequence str, String message, | ||||||
|         Class<? extends RuntimeException> exceptionType) { |         Class<? extends RuntimeException> exceptionType) { | ||||||
|         exIfCondition(() -> StrUtil.isNotBlank(str), message, exceptionType); |         throwIf(() -> StrUtil.isNotBlank(str), message, exceptionType); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
| @@ -75,9 +76,9 @@ public class Validator { | |||||||
|      * @param exceptionType |      * @param exceptionType | ||||||
|      *            异常类型 |      *            异常类型 | ||||||
|      */ |      */ | ||||||
|     protected static void exIfEqual(Object obj1, Object obj2, String message, |     protected static void throwIfEqual(Object obj1, Object obj2, String message, | ||||||
|         Class<? extends RuntimeException> exceptionType) { |         Class<? extends RuntimeException> exceptionType) { | ||||||
|         exIfCondition(() -> ObjectUtil.equal(obj1, obj2), message, exceptionType); |         throwIf(() -> ObjectUtil.equal(obj1, obj2), message, exceptionType); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
| @@ -92,9 +93,9 @@ public class Validator { | |||||||
|      * @param exceptionType |      * @param exceptionType | ||||||
|      *            异常类型 |      *            异常类型 | ||||||
|      */ |      */ | ||||||
|     protected static void exIfNotEqual(Object obj1, Object obj2, String message, |     protected static void throwIfNotEqual(Object obj1, Object obj2, String message, | ||||||
|         Class<? extends RuntimeException> exceptionType) { |         Class<? extends RuntimeException> exceptionType) { | ||||||
|         exIfCondition(() -> ObjectUtil.notEqual(obj1, obj2), message, exceptionType); |         throwIf(() -> ObjectUtil.notEqual(obj1, obj2), message, exceptionType); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
| @@ -109,9 +110,9 @@ public class Validator { | |||||||
|      * @param exceptionType |      * @param exceptionType | ||||||
|      *            异常类型 |      *            异常类型 | ||||||
|      */ |      */ | ||||||
|     protected static void exIfEqualIgnoreCase(CharSequence str1, CharSequence str2, String message, |     protected static void throwIfEqualIgnoreCase(CharSequence str1, CharSequence str2, String message, | ||||||
|         Class<? extends RuntimeException> exceptionType) { |         Class<? extends RuntimeException> exceptionType) { | ||||||
|         exIfCondition(() -> StrUtil.equalsIgnoreCase(str1, str2), message, exceptionType); |         throwIf(() -> StrUtil.equalsIgnoreCase(str1, str2), message, exceptionType); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
| @@ -126,9 +127,9 @@ public class Validator { | |||||||
|      * @param exceptionType |      * @param exceptionType | ||||||
|      *            异常类型 |      *            异常类型 | ||||||
|      */ |      */ | ||||||
|     protected static void exIfNotEqualIgnoreCase(CharSequence str1, CharSequence str2, String message, |     protected static void throwIfNotEqualIgnoreCase(CharSequence str1, CharSequence str2, String message, | ||||||
|         Class<? extends RuntimeException> exceptionType) { |         Class<? extends RuntimeException> exceptionType) { | ||||||
|         exIfCondition(() -> !StrUtil.equalsIgnoreCase(str1, str2), message, exceptionType); |         throwIf(() -> !StrUtil.equalsIgnoreCase(str1, str2), message, exceptionType); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
| @@ -141,8 +142,8 @@ public class Validator { | |||||||
|      * @param exceptionType |      * @param exceptionType | ||||||
|      *            异常类型 |      *            异常类型 | ||||||
|      */ |      */ | ||||||
|     protected static void exIfNull(Object obj, String message, Class<? extends RuntimeException> exceptionType) { |     protected static void throwIfNull(Object obj, String message, Class<? extends RuntimeException> exceptionType) { | ||||||
|         exIfCondition(() -> obj == null, message, exceptionType); |         throwIf(() -> obj == null, message, exceptionType); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
| @@ -155,8 +156,8 @@ public class Validator { | |||||||
|      * @param exceptionType |      * @param exceptionType | ||||||
|      *            异常类型 |      *            异常类型 | ||||||
|      */ |      */ | ||||||
|     protected static void exIfNotNull(Object obj, String message, Class<? extends RuntimeException> exceptionType) { |     protected static void throwIfNotNull(Object obj, String message, Class<? extends RuntimeException> exceptionType) { | ||||||
|         exIfCondition(() -> obj != null, message, exceptionType); |         throwIf(() -> obj != null, message, exceptionType); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
| @@ -169,7 +170,7 @@ public class Validator { | |||||||
|      * @param exceptionType |      * @param exceptionType | ||||||
|      *            异常类型 |      *            异常类型 | ||||||
|      */ |      */ | ||||||
|     protected static void exIfCondition(java.util.function.BooleanSupplier conditionSupplier, String message, |     protected static void throwIf(java.util.function.BooleanSupplier conditionSupplier, String message, | ||||||
|         Class<? extends RuntimeException> exceptionType) { |         Class<? extends RuntimeException> exceptionType) { | ||||||
|         if (conditionSupplier != null && conditionSupplier.getAsBoolean()) { |         if (conditionSupplier != null && conditionSupplier.getAsBoolean()) { | ||||||
|             log.error(message); |             log.error(message); | ||||||
|   | |||||||
| @@ -135,7 +135,7 @@ public class LogServiceImpl implements LogService { | |||||||
|     @Override |     @Override | ||||||
|     public SystemLogDetailVO detail(Long logId) { |     public SystemLogDetailVO detail(Long logId) { | ||||||
|         SysLog sysLog = logMapper.selectById(logId); |         SysLog sysLog = logMapper.selectById(logId); | ||||||
|         ValidationUtils.exIfNull(sysLog, String.format("ID为 [%s] 的日志已不存在", logId)); |         ValidationUtils.throwIfNull(sysLog, String.format("ID为 [%s] 的日志已不存在", logId)); | ||||||
|  |  | ||||||
|         SystemLogDetailVO detailVO = BeanUtil.copyProperties(sysLog, SystemLogDetailVO.class); |         SystemLogDetailVO detailVO = BeanUtil.copyProperties(sysLog, SystemLogDetailVO.class); | ||||||
|         this.fill(detailVO); |         this.fill(detailVO); | ||||||
|   | |||||||
| @@ -50,11 +50,11 @@ public class LoginServiceImpl implements LoginService { | |||||||
|         SysUser sysUser = userService.getByUsername(username); |         SysUser sysUser = userService.getByUsername(username); | ||||||
|  |  | ||||||
|         // 校验 |         // 校验 | ||||||
|         ValidationUtils.exIfNull(sysUser, "用户名或密码错误"); |         ValidationUtils.throwIfNull(sysUser, "用户名或密码错误"); | ||||||
|         Long userId = sysUser.getUserId(); |         Long userId = sysUser.getUserId(); | ||||||
|         ValidationUtils.exIfNotEqual(SecureUtils.md5Salt(password, userId.toString()), sysUser.getPassword(), |         ValidationUtils.throwIfNotEqual(SecureUtils.md5Salt(password, userId.toString()), sysUser.getPassword(), | ||||||
|             "用户名或密码错误"); |             "用户名或密码错误"); | ||||||
|         ValidationUtils.exIfEqual(DisEnableStatusEnum.DISABLE, sysUser.getStatus(), "此账号已被禁用,如有疑问,请联系管理员"); |         ValidationUtils.throwIfEqual(DisEnableStatusEnum.DISABLE, sysUser.getStatus(), "此账号已被禁用,如有疑问,请联系管理员"); | ||||||
|  |  | ||||||
|         // 登录 |         // 登录 | ||||||
|         LoginUser loginUser = BeanUtil.copyProperties(sysUser, LoginUser.class); |         LoginUser loginUser = BeanUtil.copyProperties(sysUser, LoginUser.class); | ||||||
|   | |||||||
| @@ -67,7 +67,7 @@ public class UserServiceImpl implements UserService { | |||||||
|         // 上传新头像 |         // 上传新头像 | ||||||
|         String avatarPath = localStorageProperties.getPath().getAvatar(); |         String avatarPath = localStorageProperties.getPath().getAvatar(); | ||||||
|         File newAvatarFile = FileUtils.upload(avatarFile, avatarPath, false); |         File newAvatarFile = FileUtils.upload(avatarFile, avatarPath, false); | ||||||
|         CheckUtils.exIfNull(newAvatarFile, "上传头像失败"); |         CheckUtils.throwIfNull(newAvatarFile, "上传头像失败"); | ||||||
|         assert newAvatarFile != null; |         assert newAvatarFile != null; | ||||||
|  |  | ||||||
|         // 更新用户头像 |         // 更新用户头像 | ||||||
| @@ -104,7 +104,7 @@ public class UserServiceImpl implements UserService { | |||||||
|     @Transactional(rollbackFor = Exception.class) |     @Transactional(rollbackFor = Exception.class) | ||||||
|     public void updatePassword(String oldPassword, String newPassword, Long userId) { |     public void updatePassword(String oldPassword, String newPassword, Long userId) { | ||||||
|         SysUser sysUser = this.getById(userId); |         SysUser sysUser = this.getById(userId); | ||||||
|         ValidationUtils.exIfNotEqual(SecureUtils.md5Salt(oldPassword, userId.toString()), sysUser.getPassword(), |         ValidationUtils.throwIfNotEqual(SecureUtils.md5Salt(oldPassword, userId.toString()), sysUser.getPassword(), | ||||||
|             "当前密码错误"); |             "当前密码错误"); | ||||||
|  |  | ||||||
|         // 更新密码和密码重置时间 |         // 更新密码和密码重置时间 | ||||||
| @@ -125,11 +125,11 @@ public class UserServiceImpl implements UserService { | |||||||
|     public void updateEmail(String newEmail, String currentPassword, Long userId) { |     public void updateEmail(String newEmail, String currentPassword, Long userId) { | ||||||
|         // 校验 |         // 校验 | ||||||
|         SysUser sysUser = this.getById(userId); |         SysUser sysUser = this.getById(userId); | ||||||
|         ValidationUtils.exIfNotEqual(SecureUtils.md5Salt(currentPassword, userId.toString()), sysUser.getPassword(), |         ValidationUtils.throwIfNotEqual(SecureUtils.md5Salt(currentPassword, userId.toString()), sysUser.getPassword(), | ||||||
|             "当前密码错误"); |             "当前密码错误"); | ||||||
|         Long count = userMapper.selectCount(Wrappers.<SysUser>lambdaQuery().eq(SysUser::getEmail, newEmail)); |         Long count = userMapper.selectCount(Wrappers.<SysUser>lambdaQuery().eq(SysUser::getEmail, newEmail)); | ||||||
|         ValidationUtils.exIfCondition(() -> count > 0, "邮箱已绑定其他账号,请更换其他邮箱"); |         ValidationUtils.throwIf(() -> count > 0, "邮箱已绑定其他账号,请更换其他邮箱"); | ||||||
|         ValidationUtils.exIfEqual(newEmail, sysUser.getEmail(), "新邮箱不能与当前邮箱相同"); |         ValidationUtils.throwIfEqual(newEmail, sysUser.getEmail(), "新邮箱不能与当前邮箱相同"); | ||||||
|  |  | ||||||
|         // 更新邮箱 |         // 更新邮箱 | ||||||
|         userMapper.update(null, |         userMapper.update(null, | ||||||
| @@ -143,9 +143,9 @@ public class UserServiceImpl implements UserService { | |||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|     public SysUser getById(Long userId) { |     public SysUser getById(Long userId) { | ||||||
|         ValidationUtils.exIfNull(userId, "用户不存在"); |         ValidationUtils.throwIfNull(userId, "用户不存在"); | ||||||
|         SysUser sysUser = userMapper.selectById(userId); |         SysUser sysUser = userMapper.selectById(userId); | ||||||
|         ValidationUtils.exIfNull(sysUser, String.format("ID为 [%s] 的用户已不存在", userId)); |         ValidationUtils.throwIfNull(sysUser, String.format("ID为 [%s] 的用户已不存在", userId)); | ||||||
|         return sysUser; |         return sysUser; | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -67,14 +67,14 @@ public class LoginController { | |||||||
|         // 校验验证码 |         // 校验验证码 | ||||||
|         String captchaKey = RedisUtils.formatKey(CacheConstants.CAPTCHA_CACHE_KEY, loginRequest.getUuid()); |         String captchaKey = RedisUtils.formatKey(CacheConstants.CAPTCHA_CACHE_KEY, loginRequest.getUuid()); | ||||||
|         String captcha = RedisUtils.getCacheObject(captchaKey); |         String captcha = RedisUtils.getCacheObject(captchaKey); | ||||||
|         ValidationUtils.exIfBlank(captcha, "验证码已失效"); |         ValidationUtils.throwIfBlank(captcha, "验证码已失效"); | ||||||
|         RedisUtils.deleteCacheObject(captchaKey); |         RedisUtils.deleteCacheObject(captchaKey); | ||||||
|         ValidationUtils.exIfNotEqualIgnoreCase(loginRequest.getCaptcha(), captcha, "验证码错误"); |         ValidationUtils.throwIfNotEqualIgnoreCase(loginRequest.getCaptcha(), captcha, "验证码错误"); | ||||||
|  |  | ||||||
|         // 用户登录 |         // 用户登录 | ||||||
|         String rawPassword = |         String rawPassword = | ||||||
|             ExceptionUtils.exToNull(() -> SecureUtils.decryptByRsaPrivateKey(loginRequest.getPassword())); |             ExceptionUtils.exToNull(() -> SecureUtils.decryptByRsaPrivateKey(loginRequest.getPassword())); | ||||||
|         ValidationUtils.exIfBlank(rawPassword, "密码解密失败"); |         ValidationUtils.throwIfBlank(rawPassword, "密码解密失败"); | ||||||
|         String token = loginService.login(loginRequest.getUsername(), rawPassword); |         String token = loginService.login(loginRequest.getUsername(), rawPassword); | ||||||
|         return R.ok(new LoginVO().setToken(token)); |         return R.ok(new LoginVO().setToken(token)); | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -94,7 +94,7 @@ public class CaptchaController { | |||||||
|         String captchaCacheKey = CacheConstants.CAPTCHA_CACHE_KEY; |         String captchaCacheKey = CacheConstants.CAPTCHA_CACHE_KEY; | ||||||
|         String limitCaptchaKey = RedisUtils.formatKey(limitCacheKey, captchaCacheKey, email); |         String limitCaptchaKey = RedisUtils.formatKey(limitCacheKey, captchaCacheKey, email); | ||||||
|         long limitTimeInMillisecond = RedisUtils.getTimeToLive(limitCaptchaKey); |         long limitTimeInMillisecond = RedisUtils.getTimeToLive(limitCaptchaKey); | ||||||
|         ValidationUtils.exIfCondition(() -> limitTimeInMillisecond > 0, |         ValidationUtils.throwIf(() -> limitTimeInMillisecond > 0, | ||||||
|             String.format("发送邮箱验证码过于频繁,请您 %ds 后再试", limitTimeInMillisecond / 1000)); |             String.format("发送邮箱验证码过于频繁,请您 %ds 后再试", limitTimeInMillisecond / 1000)); | ||||||
|  |  | ||||||
|         // 生成验证码 |         // 生成验证码 | ||||||
|   | |||||||
| @@ -70,13 +70,13 @@ public class UserCenterController { | |||||||
|     @PostMapping("/avatar") |     @PostMapping("/avatar") | ||||||
|     public R<AvatarVO> uploadAvatar(@NotNull(message = "头像不能为空") MultipartFile avatarFile) { |     public R<AvatarVO> uploadAvatar(@NotNull(message = "头像不能为空") MultipartFile avatarFile) { | ||||||
|         // 校验 |         // 校验 | ||||||
|         ValidationUtils.exIfCondition(avatarFile::isEmpty, "头像不能为空"); |         ValidationUtils.throwIf(avatarFile::isEmpty, "头像不能为空"); | ||||||
|         Long avatarMaxSizeInMb = localStorageProperties.getAvatarMaxSizeInMb(); |         Long avatarMaxSizeInMb = localStorageProperties.getAvatarMaxSizeInMb(); | ||||||
|         ValidationUtils.exIfCondition(() -> avatarFile.getSize() > avatarMaxSizeInMb * 1024 * 1024, |         ValidationUtils.throwIf(() -> avatarFile.getSize() > avatarMaxSizeInMb * 1024 * 1024, | ||||||
|             String.format("请上传小于 %s MB 的图片", avatarMaxSizeInMb)); |             String.format("请上传小于 %s MB 的图片", avatarMaxSizeInMb)); | ||||||
|         String avatarImageType = FileNameUtil.extName(avatarFile.getOriginalFilename()); |         String avatarImageType = FileNameUtil.extName(avatarFile.getOriginalFilename()); | ||||||
|         String[] avatarSupportImgTypes = FileConstants.AVATAR_SUPPORTED_IMG_TYPES; |         String[] avatarSupportImgTypes = FileConstants.AVATAR_SUPPORTED_IMG_TYPES; | ||||||
|         ValidationUtils.exIfCondition(() -> !StrUtil.equalsAnyIgnoreCase(avatarImageType, avatarSupportImgTypes), |         ValidationUtils.throwIf(() -> !StrUtil.equalsAnyIgnoreCase(avatarImageType, avatarSupportImgTypes), | ||||||
|             String.format("头像仅支持 %s 格式的图片", String.join(",", avatarSupportImgTypes))); |             String.format("头像仅支持 %s 格式的图片", String.join(",", avatarSupportImgTypes))); | ||||||
|  |  | ||||||
|         // 上传头像 |         // 上传头像 | ||||||
| @@ -100,15 +100,15 @@ public class UserCenterController { | |||||||
|         // 解密 |         // 解密 | ||||||
|         String rawOldPassword = |         String rawOldPassword = | ||||||
|             ExceptionUtils.exToNull(() -> SecureUtils.decryptByRsaPrivateKey(updatePasswordRequest.getOldPassword())); |             ExceptionUtils.exToNull(() -> SecureUtils.decryptByRsaPrivateKey(updatePasswordRequest.getOldPassword())); | ||||||
|         ValidationUtils.exIfBlank(rawOldPassword, "当前密码解密失败"); |         ValidationUtils.throwIfBlank(rawOldPassword, "当前密码解密失败"); | ||||||
|         String rawNewPassword = |         String rawNewPassword = | ||||||
|             ExceptionUtils.exToNull(() -> SecureUtils.decryptByRsaPrivateKey(updatePasswordRequest.getNewPassword())); |             ExceptionUtils.exToNull(() -> SecureUtils.decryptByRsaPrivateKey(updatePasswordRequest.getNewPassword())); | ||||||
|         ValidationUtils.exIfBlank(rawNewPassword, "新密码解密失败"); |         ValidationUtils.throwIfBlank(rawNewPassword, "新密码解密失败"); | ||||||
|  |  | ||||||
|         // 校验 |         // 校验 | ||||||
|         ValidationUtils.exIfCondition(() -> !ReUtil.isMatch(RegExpConstants.PASSWORD, rawNewPassword), |         ValidationUtils.throwIf(() -> !ReUtil.isMatch(RegExpConstants.PASSWORD, rawNewPassword), | ||||||
|             "密码长度 6 到 32 位,同时包含数字和字母"); |             "密码长度 6 到 32 位,同时包含数字和字母"); | ||||||
|         ValidationUtils.exIfEqual(rawNewPassword, rawOldPassword, "新密码不能与当前密码相同"); |         ValidationUtils.throwIfEqual(rawNewPassword, rawOldPassword, "新密码不能与当前密码相同"); | ||||||
|  |  | ||||||
|         // 修改密码 |         // 修改密码 | ||||||
|         userService.updatePassword(rawOldPassword, rawNewPassword, LoginHelper.getUserId()); |         userService.updatePassword(rawOldPassword, rawNewPassword, LoginHelper.getUserId()); | ||||||
| @@ -121,13 +121,13 @@ public class UserCenterController { | |||||||
|         // 解密 |         // 解密 | ||||||
|         String rawCurrentPassword = |         String rawCurrentPassword = | ||||||
|             ExceptionUtils.exToNull(() -> SecureUtils.decryptByRsaPrivateKey(updateEmailRequest.getCurrentPassword())); |             ExceptionUtils.exToNull(() -> SecureUtils.decryptByRsaPrivateKey(updateEmailRequest.getCurrentPassword())); | ||||||
|         ValidationUtils.exIfBlank(rawCurrentPassword, "当前密码解密失败"); |         ValidationUtils.throwIfBlank(rawCurrentPassword, "当前密码解密失败"); | ||||||
|  |  | ||||||
|         // 校验 |         // 校验 | ||||||
|         String captchaKey = RedisUtils.formatKey(CacheConstants.CAPTCHA_CACHE_KEY, updateEmailRequest.getNewEmail()); |         String captchaKey = RedisUtils.formatKey(CacheConstants.CAPTCHA_CACHE_KEY, updateEmailRequest.getNewEmail()); | ||||||
|         String captcha = RedisUtils.getCacheObject(captchaKey); |         String captcha = RedisUtils.getCacheObject(captchaKey); | ||||||
|         ValidationUtils.exIfBlank(captcha, "验证码已失效"); |         ValidationUtils.throwIfBlank(captcha, "验证码已失效"); | ||||||
|         ValidationUtils.exIfNotEqualIgnoreCase(updateEmailRequest.getCaptcha(), captcha, "验证码错误"); |         ValidationUtils.throwIfNotEqualIgnoreCase(updateEmailRequest.getCaptcha(), captcha, "验证码错误"); | ||||||
|         RedisUtils.deleteCacheObject(captchaKey); |         RedisUtils.deleteCacheObject(captchaKey); | ||||||
|  |  | ||||||
|         // 修改邮箱 |         // 修改邮箱 | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user