Merge branch 'dev' into main
This commit is contained in:
commit
33d3d86393
@ -33,4 +33,4 @@ indent_size=4
|
||||
indent_size=2
|
||||
|
||||
[*.java]
|
||||
indent_size = 4
|
||||
indent_size=4
|
||||
|
@ -11,7 +11,7 @@ import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import xyz.zhouxy.plusone.util.RestfulResult;
|
||||
import xyz.zhouxy.plusone.commons.util.RestfulResult;
|
||||
|
||||
/**
|
||||
* 默认异常的处理器
|
||||
|
@ -0,0 +1,28 @@
|
||||
package xyz.zhouxy.plusone.exception.handler;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import xyz.zhouxy.plusone.commons.util.RestfulResult;
|
||||
import xyz.zhouxy.plusone.exception.SysException;
|
||||
|
||||
@RestControllerAdvice
|
||||
@Slf4j
|
||||
public class SysExceptionHandler extends BaseExceptionHandler {
|
||||
|
||||
public SysExceptionHandler(ExceptionInfoHolder exceptionInfoHolder) {
|
||||
super(exceptionInfoHolder);
|
||||
}
|
||||
|
||||
@ExceptionHandler({ SysException.class })
|
||||
public ResponseEntity<RestfulResult> handleException(@Nonnull Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
HttpStatus httpStatus = getHttpStatus(e);
|
||||
return new ResponseEntity<>(RestfulResult.error(getErrorCode(e), "系统错误"), httpStatus);
|
||||
}
|
||||
}
|
@ -39,12 +39,12 @@
|
||||
<dependency>
|
||||
<groupId>xyz.zhouxy.plusone</groupId>
|
||||
<artifactId>plusone-commons</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<version>0.1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>xyz.zhouxy.plusone</groupId>
|
||||
<artifactId>plusone-validator</artifactId>
|
||||
<version>0.1.0-SNAPSHOT</version>
|
||||
<version>0.1.2-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>xyz.zhouxy.plusone</groupId>
|
||||
|
@ -0,0 +1,39 @@
|
||||
package xyz.zhouxy.plusone.exception;
|
||||
|
||||
import xyz.zhouxy.plusone.commons.exception.BaseException;
|
||||
|
||||
/**
|
||||
* 业务异常
|
||||
*
|
||||
* @author <a href="https://gitee.com/zhouxy108">ZhouXY</a>
|
||||
*/
|
||||
public class BizException extends BaseException {
|
||||
@java.io.Serial
|
||||
private static final long serialVersionUID = -5524759033245815405L;
|
||||
|
||||
public static final int DEFAULT_ERROR_CODE = 4000000;
|
||||
|
||||
public BizException(int code, String msg) {
|
||||
super(code, msg);
|
||||
}
|
||||
|
||||
public BizException(int code, Throwable cause) {
|
||||
super(code, cause);
|
||||
}
|
||||
|
||||
public BizException(int code, String msg, Throwable cause) {
|
||||
super(code, msg, cause);
|
||||
}
|
||||
|
||||
public BizException(String msg) {
|
||||
super(DEFAULT_ERROR_CODE, msg);
|
||||
}
|
||||
|
||||
public BizException(Throwable cause) {
|
||||
super(DEFAULT_ERROR_CODE, cause);
|
||||
}
|
||||
|
||||
public BizException(String msg, Throwable cause) {
|
||||
super(DEFAULT_ERROR_CODE, msg, cause);
|
||||
}
|
||||
}
|
@ -9,7 +9,7 @@ import org.springframework.web.bind.annotation.ResponseStatus;
|
||||
* @author <a href="https://gitee.com/zhouxy108">ZhouXY</a>
|
||||
*/
|
||||
@ResponseStatus(HttpStatus.NOT_FOUND)
|
||||
public class DataNotExistException extends PlusoneException {
|
||||
public class DataNotExistException extends BizException {
|
||||
|
||||
@java.io.Serial
|
||||
private static final long serialVersionUID = 6536955800679703111L;
|
||||
|
@ -8,13 +8,12 @@ import org.springframework.web.bind.annotation.ResponseStatus;
|
||||
*
|
||||
* <p>
|
||||
* 暂时先这样,后续完善异常体系时可能会更改。
|
||||
* </p>
|
||||
*
|
||||
* @author <a href="https://gitee.com/zhouxy108">ZhouXY</a>
|
||||
* @see xyz.zhouxy.plusone.util.AssertResult
|
||||
*/
|
||||
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
|
||||
public class DataOperationResultException extends PlusoneException {
|
||||
public class DataOperationResultException extends SysException {
|
||||
|
||||
@java.io.Serial
|
||||
private static final long serialVersionUID = -9220765735990318186L;
|
||||
|
@ -0,0 +1,34 @@
|
||||
package xyz.zhouxy.plusone.exception;
|
||||
|
||||
import xyz.zhouxy.plusone.commons.exception.BaseException;
|
||||
|
||||
public class SysException extends BaseException {
|
||||
@java.io.Serial
|
||||
private static final long serialVersionUID = 8821240827443168118L;
|
||||
|
||||
public static final int DEFAULT_ERROR_CODE = 5000000;
|
||||
|
||||
public SysException(int code, String msg) {
|
||||
super(code, msg);
|
||||
}
|
||||
|
||||
public SysException(int code, Throwable cause) {
|
||||
super(code, cause);
|
||||
}
|
||||
|
||||
public SysException(int code, String msg, Throwable cause) {
|
||||
super(code, msg, cause);
|
||||
}
|
||||
|
||||
public SysException(String msg) {
|
||||
super(DEFAULT_ERROR_CODE, msg);
|
||||
}
|
||||
|
||||
public SysException(Throwable cause) {
|
||||
super(DEFAULT_ERROR_CODE, cause);
|
||||
}
|
||||
|
||||
public SysException(String msg, Throwable cause) {
|
||||
super(DEFAULT_ERROR_CODE, msg, cause);
|
||||
}
|
||||
}
|
@ -9,7 +9,7 @@ import org.springframework.web.bind.annotation.ResponseStatus;
|
||||
* @author ZhouXY
|
||||
*/
|
||||
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
||||
public class UserOperationException extends PlusoneException {
|
||||
public class UserOperationException extends BizException {
|
||||
|
||||
@java.io.Serial
|
||||
private static final long serialVersionUID = 4371055414421991940L;
|
||||
|
@ -1,7 +1,6 @@
|
||||
package xyz.zhouxy.plusone.constant;
|
||||
|
||||
import xyz.zhouxy.plusone.util.Enumeration;
|
||||
import xyz.zhouxy.plusone.util.EnumerationValuesHolder;
|
||||
import xyz.zhouxy.plusone.commons.util.Enumeration;
|
||||
|
||||
/**
|
||||
* 实体状态
|
||||
@ -19,7 +18,8 @@ public class EntityStatus extends Enumeration<EntityStatus> {
|
||||
public static final EntityStatus DISABLED = new EntityStatus(1, "禁用");
|
||||
|
||||
private static final EnumerationValuesHolder<EntityStatus> ENUMERATION_VALUES = new EnumerationValuesHolder<>(
|
||||
new EntityStatus[] { AVAILABLE, DISABLED });
|
||||
AVAILABLE,
|
||||
DISABLED);
|
||||
|
||||
public static EntityStatus of(int value) {
|
||||
return ENUMERATION_VALUES.get(value);
|
||||
|
@ -1,36 +0,0 @@
|
||||
package xyz.zhouxy.plusone.util;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class RegexUtil {
|
||||
|
||||
private RegexUtil() {
|
||||
throw new IllegalStateException("Utility class");
|
||||
}
|
||||
|
||||
public static boolean matches(CharSequence input, String regex) {
|
||||
return Pattern.matches(regex, input);
|
||||
}
|
||||
|
||||
public static boolean matchesOr(CharSequence input, String... regexs) {
|
||||
boolean isMatched;
|
||||
for (var regex : regexs) {
|
||||
isMatched = Pattern.matches(regex, input);
|
||||
if (isMatched) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean matchesAnd(CharSequence input, String... regexs) {
|
||||
boolean isMatched;
|
||||
for (var regex : regexs) {
|
||||
isMatched = Pattern.matches(regex, input);
|
||||
if (!isMatched) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
@ -15,8 +15,8 @@ import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
|
||||
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
|
||||
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
|
||||
|
||||
import xyz.zhouxy.plusone.commons.util.NumberUtil;
|
||||
import xyz.zhouxy.plusone.exception.DataOperationResultException;
|
||||
import xyz.zhouxy.plusone.util.NumberUtil;
|
||||
|
||||
public abstract class PlusoneJdbcDaoSupport {
|
||||
protected final NamedParameterJdbcTemplate jdbc;
|
||||
|
@ -12,7 +12,7 @@ import org.springframework.stereotype.Service;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import xyz.zhouxy.plusone.constant.ErrorCodeConsts;
|
||||
import xyz.zhouxy.plusone.exception.PlusoneException;
|
||||
import xyz.zhouxy.plusone.exception.BizException;
|
||||
import xyz.zhouxy.plusone.sms.SmsProperties.SmsCredentialProperties;
|
||||
import xyz.zhouxy.plusone.sms.SmsProperties.SmsHttpProperties;
|
||||
import xyz.zhouxy.plusone.sms.SmsProperties.SmsProxyProperties;
|
||||
@ -69,7 +69,7 @@ public class TencentSmsServiceImpl implements SmsService {
|
||||
|
||||
} catch (TencentCloudSDKException e) {
|
||||
log.error(e.getMessage(), e);
|
||||
throw new PlusoneException(ErrorCodeConsts.DEFAULT_ERROR_CODE, e);
|
||||
throw new BizException(ErrorCodeConsts.DEFAULT_ERROR_CODE, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,11 +1,13 @@
|
||||
package xyz.zhouxy.plusone.validatortest;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import xyz.zhouxy.plusone.constant.RegexConsts;
|
||||
import xyz.zhouxy.plusone.commons.constant.PatternConsts;
|
||||
import xyz.zhouxy.plusone.validator.BaseValidator;
|
||||
|
||||
class BaseValidatorTest {
|
||||
@ -34,11 +36,11 @@ class LoginCommandValidator extends BaseValidator<LoginCommand> {
|
||||
private LoginCommandValidator() {
|
||||
ruleForString(LoginCommand::getAccount)
|
||||
.notNull("邮箱地址不能为空")
|
||||
.matchesOr(new String[] { RegexConsts.EMAIL, RegexConsts.MOBILE_PHONE },
|
||||
.matchesOr(new Pattern[] { PatternConsts.EMAIL, PatternConsts.MOBILE_PHONE },
|
||||
value -> new RuntimeException('"' + value + "\" 不是邮箱地址或手机号"));
|
||||
ruleForString(LoginCommand::getPwd)
|
||||
.notNull("密码不能为空")
|
||||
.notEmpty("密码不能为空")
|
||||
.matches(RegexConsts.PASSWORD, "密码格式错误");
|
||||
.matches(PatternConsts.PASSWORD, "密码格式错误");
|
||||
}
|
||||
}
|
||||
|
@ -5,14 +5,14 @@ import java.io.ObjectStreamClass;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import xyz.zhouxy.plusone.exception.PlusoneException;
|
||||
import xyz.zhouxy.plusone.exception.*;
|
||||
|
||||
@Slf4j
|
||||
class SerialTests {
|
||||
|
||||
@Test
|
||||
void testSerialVersionUID() {
|
||||
var cl = PlusoneException.class;
|
||||
var cl = SysException.class;
|
||||
var c = ObjectStreamClass.lookup(cl);
|
||||
var uid = c.getSerialVersionUID();
|
||||
log.info("\n @java.io.Serial" +
|
||||
|
@ -0,0 +1,29 @@
|
||||
package xyz.zhouxy.plusone.system.application.common.exception;
|
||||
|
||||
import xyz.zhouxy.plusone.exception.BizException;
|
||||
|
||||
/**
|
||||
* 不支持的 Principal 类型出现时抛出的异常
|
||||
*
|
||||
* @author <a href="https://zhouxy.xyz:3000/ZhouXY108">ZhouXY</a>
|
||||
*/
|
||||
public class UnsupportedPrincipalTypeException extends BizException {
|
||||
|
||||
public static final int ERR_CODE = 4040201;
|
||||
|
||||
public UnsupportedPrincipalTypeException() {
|
||||
super(ERR_CODE, "不支持的 PrincipalType");
|
||||
}
|
||||
|
||||
public UnsupportedPrincipalTypeException(String msg) {
|
||||
super(ERR_CODE, msg);
|
||||
}
|
||||
|
||||
public UnsupportedPrincipalTypeException(Throwable cause) {
|
||||
super(ERR_CODE, cause);
|
||||
}
|
||||
|
||||
public UnsupportedPrincipalTypeException(String msg, Throwable cause) {
|
||||
super(ERR_CODE, msg, cause);
|
||||
}
|
||||
}
|
@ -2,11 +2,11 @@ package xyz.zhouxy.plusone.system.application.common.util;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import xyz.zhouxy.plusone.system.application.common.exception.UnsupportedPrincipalTypeException;
|
||||
import xyz.zhouxy.plusone.system.domain.model.account.Email;
|
||||
import xyz.zhouxy.plusone.system.domain.model.account.MobilePhone;
|
||||
import xyz.zhouxy.plusone.system.domain.model.account.Principal;
|
||||
import xyz.zhouxy.plusone.system.domain.model.account.Username;
|
||||
import xyz.zhouxy.plusone.validator.InvalidInputException;
|
||||
|
||||
/**
|
||||
* 根据字面值,判断并生成 {@link Principal} 值对象。
|
||||
@ -16,7 +16,7 @@ import xyz.zhouxy.plusone.validator.InvalidInputException;
|
||||
* @see Username
|
||||
* @see Email
|
||||
* @see MobilePhone
|
||||
* @see InvalidInputException
|
||||
* @see UnsupportedPrincipalTypeException
|
||||
*/
|
||||
public class PrincipalUtil {
|
||||
|
||||
@ -34,7 +34,7 @@ public class PrincipalUtil {
|
||||
return principalType;
|
||||
}
|
||||
}
|
||||
throw InvalidInputException.unsupportedPrincipalTypeException();
|
||||
throw new UnsupportedPrincipalTypeException();
|
||||
}
|
||||
|
||||
public static Principal getPrincipal(@Nullable String principal) {
|
||||
@ -48,7 +48,7 @@ public class PrincipalUtil {
|
||||
if (principalType == PrincipalType.USERNAME) {
|
||||
return Username.of(principal);
|
||||
}
|
||||
throw InvalidInputException.unsupportedPrincipalTypeException();
|
||||
throw new UnsupportedPrincipalTypeException();
|
||||
}
|
||||
|
||||
public static Principal getEmailOrMobilePhone(@Nullable String principal) {
|
||||
@ -59,6 +59,6 @@ public class PrincipalUtil {
|
||||
if (principalType == PrincipalType.MOBILE_PHONE) {
|
||||
return MobilePhone.of(principal);
|
||||
}
|
||||
throw InvalidInputException.unsupportedPrincipalTypeException("输入邮箱地址或手机号");
|
||||
throw new UnsupportedPrincipalTypeException("输入邮箱地址或手机号");
|
||||
}
|
||||
}
|
||||
|
@ -7,10 +7,10 @@ import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import xyz.zhouxy.plusone.commons.util.RestfulResult;
|
||||
import xyz.zhouxy.plusone.system.application.service.AccountContextService;
|
||||
import xyz.zhouxy.plusone.system.application.service.command.ChangePasswordCommand;
|
||||
import xyz.zhouxy.plusone.system.application.service.command.ChangePasswordWithoutLoginCommand;
|
||||
import xyz.zhouxy.plusone.util.RestfulResult;
|
||||
|
||||
/**
|
||||
* 账号查询本身相关信息
|
||||
|
@ -1,7 +1,7 @@
|
||||
package xyz.zhouxy.plusone.system.application.controller;
|
||||
|
||||
import static xyz.zhouxy.plusone.system.constant.AuthLogic.adminAuthLogic;
|
||||
import static xyz.zhouxy.plusone.util.RestfulResult.success;
|
||||
import static xyz.zhouxy.plusone.commons.util.RestfulResult.success;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -16,11 +16,11 @@ import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import xyz.zhouxy.plusone.commons.util.RestfulResult;
|
||||
import xyz.zhouxy.plusone.system.application.query.params.AccountQueryParams;
|
||||
import xyz.zhouxy.plusone.system.application.service.AccountManagementService;
|
||||
import xyz.zhouxy.plusone.system.application.service.command.CreateAccountCommand;
|
||||
import xyz.zhouxy.plusone.system.application.service.command.UpdateAccountCommand;
|
||||
import xyz.zhouxy.plusone.util.RestfulResult;
|
||||
|
||||
/**
|
||||
* 账号管理
|
||||
|
@ -1,6 +1,6 @@
|
||||
package xyz.zhouxy.plusone.system.application.controller;
|
||||
|
||||
import static xyz.zhouxy.plusone.util.RestfulResult.success;
|
||||
import static xyz.zhouxy.plusone.commons.util.RestfulResult.success;
|
||||
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
@ -12,7 +12,7 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
import xyz.zhouxy.plusone.system.application.service.AdminLoginService;
|
||||
import xyz.zhouxy.plusone.system.application.service.command.LoginByOtpCommand;
|
||||
import xyz.zhouxy.plusone.system.application.service.command.LoginByPasswordCommand;
|
||||
import xyz.zhouxy.plusone.util.RestfulResult;
|
||||
import xyz.zhouxy.plusone.commons.util.RestfulResult;
|
||||
|
||||
/**
|
||||
* Admin 账号登录
|
||||
|
@ -1,7 +1,7 @@
|
||||
package xyz.zhouxy.plusone.system.application.controller;
|
||||
|
||||
import static xyz.zhouxy.plusone.system.constant.AuthLogic.adminAuthLogic;
|
||||
import static xyz.zhouxy.plusone.util.RestfulResult.success;
|
||||
import static xyz.zhouxy.plusone.commons.util.RestfulResult.success;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -20,7 +20,7 @@ import xyz.zhouxy.plusone.system.application.query.params.DictQueryParams;
|
||||
import xyz.zhouxy.plusone.system.application.service.DictManagementService;
|
||||
import xyz.zhouxy.plusone.system.application.service.command.CreateDictCommand;
|
||||
import xyz.zhouxy.plusone.system.application.service.command.UpdateDictCommand;
|
||||
import xyz.zhouxy.plusone.util.RestfulResult;
|
||||
import xyz.zhouxy.plusone.commons.util.RestfulResult;
|
||||
|
||||
/**
|
||||
* 数据字典管理
|
||||
|
@ -1,7 +1,7 @@
|
||||
package xyz.zhouxy.plusone.system.application.controller;
|
||||
|
||||
import static xyz.zhouxy.plusone.system.constant.AuthLogic.adminAuthLogic;
|
||||
import static xyz.zhouxy.plusone.util.RestfulResult.success;
|
||||
import static xyz.zhouxy.plusone.commons.util.RestfulResult.success;
|
||||
|
||||
import javax.validation.Valid;
|
||||
|
||||
@ -18,7 +18,7 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
import xyz.zhouxy.plusone.system.application.service.MenuManagementService;
|
||||
import xyz.zhouxy.plusone.system.application.service.command.CreateMenuCommand;
|
||||
import xyz.zhouxy.plusone.system.application.service.command.UpdateMenuCommand;
|
||||
import xyz.zhouxy.plusone.util.RestfulResult;
|
||||
import xyz.zhouxy.plusone.commons.util.RestfulResult;
|
||||
|
||||
/**
|
||||
* 菜单管理
|
||||
|
@ -1,6 +1,6 @@
|
||||
package xyz.zhouxy.plusone.system.application.controller;
|
||||
|
||||
import static xyz.zhouxy.plusone.util.RestfulResult.success;
|
||||
import static xyz.zhouxy.plusone.commons.util.RestfulResult.success;
|
||||
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
@ -11,7 +11,7 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import xyz.zhouxy.plusone.system.application.service.RegisterAccountService;
|
||||
import xyz.zhouxy.plusone.system.application.service.command.RegisterAccountCommand;
|
||||
import xyz.zhouxy.plusone.util.RestfulResult;
|
||||
import xyz.zhouxy.plusone.commons.util.RestfulResult;
|
||||
|
||||
/**
|
||||
* 注册账号服务
|
||||
|
@ -17,7 +17,7 @@ import xyz.zhouxy.plusone.system.application.query.params.RoleQueryParams;
|
||||
import xyz.zhouxy.plusone.system.application.service.RoleManagementService;
|
||||
import xyz.zhouxy.plusone.system.application.service.command.CreateRoleCommand;
|
||||
import xyz.zhouxy.plusone.system.application.service.command.UpdateRoleCommand;
|
||||
import xyz.zhouxy.plusone.util.RestfulResult;
|
||||
import xyz.zhouxy.plusone.commons.util.RestfulResult;
|
||||
|
||||
/**
|
||||
* 角色管理服务
|
||||
|
@ -3,10 +3,10 @@ package xyz.zhouxy.plusone.system.application.exception;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||
|
||||
import xyz.zhouxy.plusone.exception.PlusoneException;
|
||||
import xyz.zhouxy.plusone.exception.BizException;
|
||||
|
||||
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
||||
public class AccountLoginException extends PlusoneException {
|
||||
public class AccountLoginException extends BizException {
|
||||
@java.io.Serial
|
||||
private static final long serialVersionUID = -3040996790739138556L;
|
||||
|
||||
|
@ -3,10 +3,10 @@ package xyz.zhouxy.plusone.system.application.exception;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||
|
||||
import xyz.zhouxy.plusone.exception.PlusoneException;
|
||||
import xyz.zhouxy.plusone.exception.BizException;
|
||||
|
||||
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
||||
public class AccountRegisterException extends PlusoneException {
|
||||
public class AccountRegisterException extends BizException {
|
||||
|
||||
@java.io.Serial
|
||||
private static final long serialVersionUID = 7580245181633370195L;
|
||||
|
@ -8,7 +8,7 @@ import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||
|
||||
import xyz.zhouxy.plusone.exception.handler.BaseExceptionHandler;
|
||||
import xyz.zhouxy.plusone.system.application.exception.AccountLoginException;
|
||||
import xyz.zhouxy.plusone.util.RestfulResult;
|
||||
import xyz.zhouxy.plusone.commons.util.RestfulResult;
|
||||
|
||||
@RestControllerAdvice
|
||||
public class AccountLoginExceptionHandler extends BaseExceptionHandler {
|
||||
|
@ -15,7 +15,7 @@ import cn.dev33.satoken.exception.SaTokenException;
|
||||
import cn.dev33.satoken.exception.SameTokenInvalidException;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import xyz.zhouxy.plusone.exception.handler.BaseExceptionHandler;
|
||||
import xyz.zhouxy.plusone.util.RestfulResult;
|
||||
import xyz.zhouxy.plusone.commons.util.RestfulResult;
|
||||
|
||||
/**
|
||||
* Sa-Token 异常处理器
|
||||
|
@ -4,10 +4,10 @@ import java.util.List;
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import xyz.zhouxy.plusone.commons.util.PageDTO;
|
||||
import xyz.zhouxy.plusone.system.application.query.params.AccountQueryParams;
|
||||
import xyz.zhouxy.plusone.system.application.query.result.AccountDetails;
|
||||
import xyz.zhouxy.plusone.system.application.query.result.AccountOverview;
|
||||
import xyz.zhouxy.plusone.util.PageDTO;
|
||||
|
||||
/**
|
||||
* 账号信息查询器
|
||||
|
@ -5,7 +5,7 @@ import java.time.LocalDate;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import xyz.zhouxy.plusone.util.PagingAndSortingQueryParams;
|
||||
import xyz.zhouxy.plusone.commons.util.PagingAndSortingQueryParams;
|
||||
|
||||
/**
|
||||
* 账号信息查询参数
|
||||
|
@ -4,7 +4,7 @@ import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.Accessors;
|
||||
import xyz.zhouxy.plusone.util.PagingAndSortingQueryParams;
|
||||
import xyz.zhouxy.plusone.commons.util.PagingAndSortingQueryParams;
|
||||
|
||||
/**
|
||||
* 数据字典查询参数
|
||||
|
@ -5,7 +5,7 @@ import java.time.LocalDate;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import xyz.zhouxy.plusone.util.PagingAndSortingQueryParams;
|
||||
import xyz.zhouxy.plusone.commons.util.PagingAndSortingQueryParams;
|
||||
|
||||
/**
|
||||
* 角色信息查询参数
|
||||
|
@ -1,7 +1,6 @@
|
||||
package xyz.zhouxy.plusone.system.application.service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
@ -9,6 +8,7 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import cn.dev33.satoken.stp.StpLogic;
|
||||
import xyz.zhouxy.plusone.system.application.common.exception.UnsupportedPrincipalTypeException;
|
||||
import xyz.zhouxy.plusone.system.application.common.util.PrincipalUtil;
|
||||
import xyz.zhouxy.plusone.system.application.exception.AccountLoginException;
|
||||
import xyz.zhouxy.plusone.system.application.query.AccountQueries;
|
||||
@ -23,7 +23,6 @@ import xyz.zhouxy.plusone.system.domain.model.account.AccountRepository;
|
||||
import xyz.zhouxy.plusone.system.domain.model.account.Email;
|
||||
import xyz.zhouxy.plusone.system.domain.model.account.MobilePhone;
|
||||
import xyz.zhouxy.plusone.system.domain.model.account.Principal;
|
||||
import xyz.zhouxy.plusone.validator.InvalidInputException;
|
||||
|
||||
/**
|
||||
* 账号对当前帐号进行操作
|
||||
@ -91,13 +90,14 @@ public class AccountContextService {
|
||||
public void changePasswordByOtp(ChangePasswordByOtpCommand command) {
|
||||
|
||||
var principal = command.getAccount();
|
||||
Optional<Account> account = switch (command.getPrincipalType()) {
|
||||
case EMAIL -> accountRepository.findByEmail(Email.of(principal));
|
||||
case MOBILE_PHONE -> accountRepository.findByMobilePhone(MobilePhone.of(principal));
|
||||
default -> throw InvalidInputException.unsupportedPrincipalTypeException("输入邮箱地址或手机号");
|
||||
boolean accountExists = switch (command.getPrincipalType()) {
|
||||
case EMAIL -> accountRepository.existsEmail(Email.of(principal));
|
||||
case MOBILE_PHONE -> accountRepository.existsMobilePhone(MobilePhone.of(principal));
|
||||
default -> throw new UnsupportedPrincipalTypeException("输入邮箱地址或手机号");
|
||||
};
|
||||
account.orElseThrow(AccountLoginException::accountNotExistException);
|
||||
|
||||
if (accountExists) {
|
||||
throw AccountLoginException.accountNotExistException();
|
||||
}
|
||||
mailAndSmsVerifyService.checkOtp(principal, command.getOtp());
|
||||
}
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
|
||||
import xyz.zhouxy.plusone.commons.util.PageDTO;
|
||||
import xyz.zhouxy.plusone.exception.DataNotExistException;
|
||||
import xyz.zhouxy.plusone.system.application.exception.AccountRegisterException;
|
||||
import xyz.zhouxy.plusone.system.application.query.AccountQueries;
|
||||
@ -29,7 +30,6 @@ import xyz.zhouxy.plusone.system.domain.model.account.Email;
|
||||
import xyz.zhouxy.plusone.system.domain.model.account.MobilePhone;
|
||||
import xyz.zhouxy.plusone.system.domain.model.account.Username;
|
||||
import xyz.zhouxy.plusone.util.AssertResult;
|
||||
import xyz.zhouxy.plusone.util.PageDTO;
|
||||
|
||||
/**
|
||||
* 账号管理
|
||||
|
@ -6,6 +6,7 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import xyz.zhouxy.plusone.system.application.common.exception.UnsupportedPrincipalTypeException;
|
||||
import xyz.zhouxy.plusone.system.application.common.util.PrincipalType;
|
||||
import xyz.zhouxy.plusone.system.application.common.util.PrincipalUtil;
|
||||
import xyz.zhouxy.plusone.system.application.exception.AccountLoginException;
|
||||
@ -18,7 +19,6 @@ import xyz.zhouxy.plusone.system.domain.model.account.AccountRepository;
|
||||
import xyz.zhouxy.plusone.system.domain.model.account.Email;
|
||||
import xyz.zhouxy.plusone.system.domain.model.account.MobilePhone;
|
||||
import xyz.zhouxy.plusone.system.domain.model.account.Username;
|
||||
import xyz.zhouxy.plusone.validator.InvalidInputException;
|
||||
import xyz.zhouxy.plusone.validator.ValidateDto;
|
||||
|
||||
/**
|
||||
@ -63,7 +63,7 @@ public class AdminLoginService {
|
||||
Account account = (switch (command.getPrincipalType()) {
|
||||
case EMAIL -> accountRepository.findByEmail(Email.of(principal));
|
||||
case MOBILE_PHONE -> accountRepository.findByMobilePhone(MobilePhone.of(principal));
|
||||
default -> throw InvalidInputException.unsupportedPrincipalTypeException("输入邮箱地址或手机号");
|
||||
default -> throw new UnsupportedPrincipalTypeException("输入邮箱地址或手机号");
|
||||
}).orElseThrow(AccountLoginException::accountNotExistException);
|
||||
|
||||
mailAndSmsVerifyService.checkOtp(principal, command.getOtp());
|
||||
|
@ -5,6 +5,7 @@ import java.util.Set;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import xyz.zhouxy.plusone.system.application.common.exception.UnsupportedPrincipalTypeException;
|
||||
import xyz.zhouxy.plusone.system.application.common.util.PrincipalType;
|
||||
import xyz.zhouxy.plusone.system.application.common.util.PrincipalUtil;
|
||||
import xyz.zhouxy.plusone.system.application.exception.AccountRegisterException;
|
||||
@ -18,7 +19,6 @@ import xyz.zhouxy.plusone.system.domain.model.account.MobilePhone;
|
||||
import xyz.zhouxy.plusone.system.domain.model.account.Password;
|
||||
import xyz.zhouxy.plusone.system.domain.model.account.Sex;
|
||||
import xyz.zhouxy.plusone.system.domain.model.account.Username;
|
||||
import xyz.zhouxy.plusone.validator.InvalidInputException;
|
||||
|
||||
/**
|
||||
* 注册账号服务
|
||||
@ -70,7 +70,7 @@ public class RegisterAccountService {
|
||||
throw AccountRegisterException.emailAlreadyExists(mobilePhone.value());
|
||||
}
|
||||
} else {
|
||||
throw InvalidInputException.unsupportedPrincipalTypeException();
|
||||
throw new UnsupportedPrincipalTypeException();
|
||||
}
|
||||
|
||||
verifyService.checkCode(emailOrMobilePhone, command.getCode());
|
||||
@ -93,7 +93,7 @@ public class RegisterAccountService {
|
||||
} else if (principalType == PrincipalType.MOBILE_PHONE) {
|
||||
verifyService.sendCodeToMobilePhone(MobilePhone.of(principal));
|
||||
} else {
|
||||
throw InvalidInputException.unsupportedPrincipalTypeException();
|
||||
throw new UnsupportedPrincipalTypeException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ import java.util.List;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import xyz.zhouxy.plusone.constant.RegexConsts;
|
||||
import xyz.zhouxy.plusone.commons.constant.PatternConsts;
|
||||
import xyz.zhouxy.plusone.system.application.service.command.LoginByOtpCommand;
|
||||
import xyz.zhouxy.plusone.validator.BaseValidator;
|
||||
import xyz.zhouxy.plusone.validator.DtoValidator;
|
||||
@ -16,10 +16,10 @@ public class LoginByOtpCommandValidator extends BaseValidator<LoginByOtpCommand>
|
||||
ruleForString(LoginByOtpCommand::getPrincipal)
|
||||
.notNull("输入邮箱地址或手机号")
|
||||
.notEmpty("输入邮箱地址或手机号")
|
||||
.matchesOr(List.of(RegexConsts.EMAIL, RegexConsts.MOBILE_PHONE), "输入用户名、邮箱地址或手机号");
|
||||
.matchesOr(List.of(PatternConsts.EMAIL, PatternConsts.MOBILE_PHONE), "输入用户名、邮箱地址或手机号");
|
||||
ruleForString(LoginByOtpCommand::getOtp)
|
||||
.notNull("验证码不能为空")
|
||||
.notEmpty("验证码不能为空")
|
||||
.matches(RegexConsts.CAPTCHA, "验证码格式不正确");
|
||||
.matches(PatternConsts.CAPTCHA, "验证码格式不正确");
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,8 @@ package xyz.zhouxy.plusone.system.application.service.command.validator;
|
||||
|
||||
import java.util.List;
|
||||
import org.springframework.stereotype.Component;
|
||||
import xyz.zhouxy.plusone.constant.RegexConsts;
|
||||
|
||||
import xyz.zhouxy.plusone.commons.constant.PatternConsts;
|
||||
import xyz.zhouxy.plusone.system.application.service.command.LoginByPasswordCommand;
|
||||
import xyz.zhouxy.plusone.validator.BaseValidator;
|
||||
import xyz.zhouxy.plusone.validator.DtoValidator;
|
||||
@ -14,11 +15,11 @@ public class LoginByPasswordCommandValidator extends BaseValidator<LoginByPasswo
|
||||
ruleForString(LoginByPasswordCommand::getPrincipal)
|
||||
.notNull("输入用户名、邮箱地址或手机号")
|
||||
.notEmpty("输入用户名、邮箱地址或手机号")
|
||||
.matchesOr(List.of(RegexConsts.USERNAME, RegexConsts.EMAIL, RegexConsts.MOBILE_PHONE),
|
||||
.matchesOr(List.of(PatternConsts.USERNAME, PatternConsts.EMAIL, PatternConsts.MOBILE_PHONE),
|
||||
"输入用户名、邮箱地址或手机号");
|
||||
ruleForString(LoginByPasswordCommand::getPassword)
|
||||
.notNull("密码不能为空")
|
||||
.notEmpty("密码不能为空")
|
||||
.matches(RegexConsts.PASSWORD, "密码格式不正确");
|
||||
.matches(PatternConsts.PASSWORD, "密码格式不正确");
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ import javax.annotation.Nonnull;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import cn.hutool.crypto.digest.DigestUtil;
|
||||
import xyz.zhouxy.plusone.constant.ErrorCodeConsts;
|
||||
import xyz.zhouxy.plusone.exception.PlusoneException;
|
||||
import xyz.zhouxy.plusone.exception.BizException;
|
||||
|
||||
/**
|
||||
* 密码工具类
|
||||
@ -31,7 +31,7 @@ public final class PasswordUtil {
|
||||
+ salt.substring(1);
|
||||
String sha512Hex = DigestUtil.sha512Hex(passwordWithSalt);
|
||||
if (sha512Hex == null) {
|
||||
throw new PlusoneException(ErrorCodeConsts.DEFAULT_ERROR_CODE, "未知错误:哈希加密失败!");
|
||||
throw new BizException(ErrorCodeConsts.DEFAULT_ERROR_CODE, "未知错误:哈希加密失败!");
|
||||
}
|
||||
return sha512Hex;
|
||||
}
|
||||
|
@ -1,9 +1,8 @@
|
||||
package xyz.zhouxy.plusone.system.domain.model.account;
|
||||
|
||||
import lombok.Getter;
|
||||
import xyz.zhouxy.plusone.commons.util.Enumeration;
|
||||
import xyz.zhouxy.plusone.domain.IValueObject;
|
||||
import xyz.zhouxy.plusone.util.Enumeration;
|
||||
import xyz.zhouxy.plusone.util.EnumerationValuesHolder;
|
||||
|
||||
/**
|
||||
* 账号状态
|
||||
@ -21,7 +20,8 @@ public class AccountStatus extends Enumeration<AccountStatus> implements IValueO
|
||||
public static final AccountStatus LOCKED = new AccountStatus(1, "账号被锁定");
|
||||
|
||||
private static final EnumerationValuesHolder<AccountStatus> ENUMERATION_VALUES = new EnumerationValuesHolder<>(
|
||||
new AccountStatus[] { AVAILABLE, LOCKED });
|
||||
AVAILABLE,
|
||||
LOCKED);
|
||||
|
||||
public static AccountStatus of(int value) {
|
||||
return ENUMERATION_VALUES.get(value);
|
||||
|
@ -10,7 +10,7 @@ import org.springframework.util.Assert;
|
||||
import xyz.zhouxy.plusone.constant.ErrorCodeConsts;
|
||||
import xyz.zhouxy.plusone.constant.RegexConsts;
|
||||
import xyz.zhouxy.plusone.domain.IValueObject;
|
||||
import xyz.zhouxy.plusone.exception.PlusoneException;
|
||||
import xyz.zhouxy.plusone.exception.BizException;
|
||||
import xyz.zhouxy.plusone.system.util.PasswordUtil;
|
||||
|
||||
/**
|
||||
@ -37,7 +37,7 @@ public class Password implements IValueObject {
|
||||
}
|
||||
var salt = PasswordUtil.generateRandomSalt();
|
||||
if (salt == null) {
|
||||
throw new PlusoneException(ErrorCodeConsts.DEFAULT_ERROR_CODE, "未知错误:生成随机盐失败");
|
||||
throw new BizException(ErrorCodeConsts.DEFAULT_ERROR_CODE, "未知错误:生成随机盐失败");
|
||||
}
|
||||
this.saltVal = salt;
|
||||
this.passwordVal = PasswordUtil.hashPassword(password, salt);
|
||||
|
@ -1,8 +1,7 @@
|
||||
package xyz.zhouxy.plusone.system.domain.model.account;
|
||||
|
||||
import xyz.zhouxy.plusone.commons.util.Enumeration;
|
||||
import xyz.zhouxy.plusone.domain.IValueObject;
|
||||
import xyz.zhouxy.plusone.util.Enumeration;
|
||||
import xyz.zhouxy.plusone.util.EnumerationValuesHolder;
|
||||
|
||||
/**
|
||||
* 值对象:性别
|
||||
@ -18,11 +17,10 @@ public class Sex extends Enumeration<Sex> implements IValueObject {
|
||||
super(value, name);
|
||||
}
|
||||
|
||||
private static EnumerationValuesHolder<Sex> values = new EnumerationValuesHolder<>(new Sex[] {
|
||||
UNSET,
|
||||
MALE,
|
||||
FEMALE
|
||||
});
|
||||
private static EnumerationValuesHolder<Sex> values = new EnumerationValuesHolder<>(
|
||||
UNSET,
|
||||
MALE,
|
||||
FEMALE);
|
||||
|
||||
public static Sex of(int value) {
|
||||
return values.get(value);
|
||||
|
@ -17,12 +17,12 @@ import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import xyz.zhouxy.plusone.commons.util.EnumUtil;
|
||||
import xyz.zhouxy.plusone.constant.EntityStatus;
|
||||
import xyz.zhouxy.plusone.exception.DataNotExistException;
|
||||
import xyz.zhouxy.plusone.jdbc.JdbcRepositorySupport;
|
||||
import xyz.zhouxy.plusone.system.domain.model.menu.Menu.MenuType;
|
||||
import xyz.zhouxy.plusone.util.AssertResult;
|
||||
import xyz.zhouxy.plusone.util.EnumUtil;
|
||||
|
||||
/**
|
||||
* MenuRepository 实现类
|
||||
|
10
pom.xml
10
pom.xml
@ -1,7 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
@ -28,7 +27,7 @@
|
||||
|
||||
<spring-boot.version>2.7.8</spring-boot.version>
|
||||
<sa-token.version>1.34.0</sa-token.version>
|
||||
<hutool.version>5.8.11</hutool.version>
|
||||
<hutool.version>5.8.12</hutool.version>
|
||||
<mybatis-starter.version>3.0.1</mybatis-starter.version>
|
||||
<mybatis-plus.version>3.5.3.1</mybatis-plus.version>
|
||||
<commons-io.version>2.11.0</commons-io.version>
|
||||
@ -87,11 +86,6 @@
|
||||
<version>${mybatis-plus.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-all</artifactId>
|
||||
<version>${hutool.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-core</artifactId>
|
||||
|
Loading…
x
Reference in New Issue
Block a user