From 19fc97362c24a71f0ec7a482afc50dc797e6cca0 Mon Sep 17 00:00:00 2001 From: ZhouXY108 Date: Sun, 16 Apr 2023 00:06:36 +0800 Subject: [PATCH 1/8] =?UTF-8?q?=E6=9B=B4=E6=94=B9=20Exception=20Handler=20?= =?UTF-8?q?=E7=89=88=E6=9C=AC=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../exception/handler/AllExceptionHandlerConfig.java | 7 +++++-- .../exception/handler/DefaultExceptionHandler.java | 7 +++++-- .../plusone/exception/handler/SysExceptionHandler.java | 3 ++- plusone-basic/plusone-basic-common/pom.xml | 2 +- .../exception/config/PlusoneExceptionHandlerConfig.java | 2 +- .../plusone/validator/InvalidInputExceptionHandler.java | 6 ++++-- .../exception/handler/AccountLoginExceptionHandler.java | 6 +++--- .../exception/handler/SaTokenExceptionHandler.java | 8 +++++--- 8 files changed, 26 insertions(+), 15 deletions(-) diff --git a/plusone-basic/plusone-basic-application/src/main/java/xyz/zhouxy/plusone/exception/handler/AllExceptionHandlerConfig.java b/plusone-basic/plusone-basic-application/src/main/java/xyz/zhouxy/plusone/exception/handler/AllExceptionHandlerConfig.java index fd05fdb..ef86397 100644 --- a/plusone-basic/plusone-basic-application/src/main/java/xyz/zhouxy/plusone/exception/handler/AllExceptionHandlerConfig.java +++ b/plusone-basic/plusone-basic-application/src/main/java/xyz/zhouxy/plusone/exception/handler/AllExceptionHandlerConfig.java @@ -1,10 +1,13 @@ package xyz.zhouxy.plusone.exception.handler; +import javax.annotation.Nonnull; + import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import xyz.zhouxy.plusone.exception.handler.BaseExceptionHandler.ExceptionInfoHolder; +import xyz.zhouxy.plusone.commons.exception.handler.AllExceptionHandler; +import xyz.zhouxy.plusone.commons.exception.handler.BaseExceptionHandler.ExceptionInfoHolder; /** * AllExceptionHandlerConfig @@ -14,7 +17,7 @@ import xyz.zhouxy.plusone.exception.handler.BaseExceptionHandler.ExceptionInfoHo public class AllExceptionHandlerConfig { @Bean - AllExceptionHandler getAllExceptionHandler(ExceptionInfoHolder exceptionInfoHolder) { + AllExceptionHandler getAllExceptionHandler(@Nonnull ExceptionInfoHolder exceptionInfoHolder) { return new AllExceptionHandler(exceptionInfoHolder); } } diff --git a/plusone-basic/plusone-basic-application/src/main/java/xyz/zhouxy/plusone/exception/handler/DefaultExceptionHandler.java b/plusone-basic/plusone-basic-application/src/main/java/xyz/zhouxy/plusone/exception/handler/DefaultExceptionHandler.java index aeb8918..51e4499 100644 --- a/plusone-basic/plusone-basic-application/src/main/java/xyz/zhouxy/plusone/exception/handler/DefaultExceptionHandler.java +++ b/plusone-basic/plusone-basic-application/src/main/java/xyz/zhouxy/plusone/exception/handler/DefaultExceptionHandler.java @@ -1,5 +1,7 @@ package xyz.zhouxy.plusone.exception.handler; +import javax.annotation.Nonnull; + import org.springframework.context.support.DefaultMessageSourceResolvable; import org.springframework.core.Ordered; import org.springframework.core.annotation.Order; @@ -11,7 +13,8 @@ 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.commons.exception.handler.BaseExceptionHandler; +import xyz.zhouxy.plusone.commons.exception.handler.RestfulResult; /** * 默认异常的处理器 @@ -40,7 +43,7 @@ import xyz.zhouxy.plusone.commons.util.RestfulResult; @Order(Ordered.LOWEST_PRECEDENCE - 1) @Slf4j public class DefaultExceptionHandler extends BaseExceptionHandler { - public DefaultExceptionHandler(ExceptionInfoHolder exceptionInfoHolder) { + public DefaultExceptionHandler(@Nonnull ExceptionInfoHolder exceptionInfoHolder) { super(exceptionInfoHolder); set(IllegalArgumentException.class, 4010000, "格式错误", HttpStatus.FORBIDDEN); set(DataAccessException.class, 6030000, "数据库错误", HttpStatus.INTERNAL_SERVER_ERROR, true); diff --git a/plusone-basic/plusone-basic-application/src/main/java/xyz/zhouxy/plusone/exception/handler/SysExceptionHandler.java b/plusone-basic/plusone-basic-application/src/main/java/xyz/zhouxy/plusone/exception/handler/SysExceptionHandler.java index b9ad4f6..9fd763f 100644 --- a/plusone-basic/plusone-basic-application/src/main/java/xyz/zhouxy/plusone/exception/handler/SysExceptionHandler.java +++ b/plusone-basic/plusone-basic-application/src/main/java/xyz/zhouxy/plusone/exception/handler/SysExceptionHandler.java @@ -8,6 +8,7 @@ import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.RestControllerAdvice; import lombok.extern.slf4j.Slf4j; +import xyz.zhouxy.plusone.commons.exception.handler.BaseExceptionHandler; import xyz.zhouxy.plusone.commons.util.RestfulResult; import xyz.zhouxy.plusone.exception.SysException; @@ -15,7 +16,7 @@ import xyz.zhouxy.plusone.exception.SysException; @Slf4j public class SysExceptionHandler extends BaseExceptionHandler { - public SysExceptionHandler(ExceptionInfoHolder exceptionInfoHolder) { + public SysExceptionHandler(@Nonnull ExceptionInfoHolder exceptionInfoHolder) { super(exceptionInfoHolder); } diff --git a/plusone-basic/plusone-basic-common/pom.xml b/plusone-basic/plusone-basic-common/pom.xml index a26bfcb..06a0f90 100644 --- a/plusone-basic/plusone-basic-common/pom.xml +++ b/plusone-basic/plusone-basic-common/pom.xml @@ -49,7 +49,7 @@ xyz.zhouxy.plusone plusone-exception-handler - 0.0.8-SNAPSHOT + 0.0.9-SNAPSHOT diff --git a/plusone-basic/plusone-basic-infrastructure/src/main/java/xyz/zhouxy/plusone/exception/config/PlusoneExceptionHandlerConfig.java b/plusone-basic/plusone-basic-infrastructure/src/main/java/xyz/zhouxy/plusone/exception/config/PlusoneExceptionHandlerConfig.java index fd871aa..ad04f49 100644 --- a/plusone-basic/plusone-basic-infrastructure/src/main/java/xyz/zhouxy/plusone/exception/config/PlusoneExceptionHandlerConfig.java +++ b/plusone-basic/plusone-basic-infrastructure/src/main/java/xyz/zhouxy/plusone/exception/config/PlusoneExceptionHandlerConfig.java @@ -5,7 +5,7 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import xyz.zhouxy.plusone.constant.ErrorCodeConsts; -import xyz.zhouxy.plusone.exception.handler.BaseExceptionHandler.ExceptionInfoHolder; +import xyz.zhouxy.plusone.commons.exception.handler.BaseExceptionHandler.ExceptionInfoHolder; @Configuration public class PlusoneExceptionHandlerConfig { diff --git a/plusone-basic/plusone-basic-infrastructure/src/main/java/xyz/zhouxy/plusone/validator/InvalidInputExceptionHandler.java b/plusone-basic/plusone-basic-infrastructure/src/main/java/xyz/zhouxy/plusone/validator/InvalidInputExceptionHandler.java index 82ebd4e..57c6666 100644 --- a/plusone-basic/plusone-basic-infrastructure/src/main/java/xyz/zhouxy/plusone/validator/InvalidInputExceptionHandler.java +++ b/plusone-basic/plusone-basic-infrastructure/src/main/java/xyz/zhouxy/plusone/validator/InvalidInputExceptionHandler.java @@ -1,13 +1,15 @@ package xyz.zhouxy.plusone.validator; +import javax.annotation.Nonnull; + import org.springframework.web.bind.annotation.RestControllerAdvice; -import xyz.zhouxy.plusone.exception.handler.BaseExceptionHandler; +import xyz.zhouxy.plusone.commons.exception.handler.BaseExceptionHandler; @RestControllerAdvice public class InvalidInputExceptionHandler extends BaseExceptionHandler { - public InvalidInputExceptionHandler(ExceptionInfoHolder exceptionInfoHolder) { + public InvalidInputExceptionHandler(@Nonnull ExceptionInfoHolder exceptionInfoHolder) { super(exceptionInfoHolder); set(InvalidInputException.class, InvalidInputException.ERROR_CODE, "无效的用户输入"); } diff --git a/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/exception/handler/AccountLoginExceptionHandler.java b/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/exception/handler/AccountLoginExceptionHandler.java index bd2a0d5..0351fec 100644 --- a/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/exception/handler/AccountLoginExceptionHandler.java +++ b/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/exception/handler/AccountLoginExceptionHandler.java @@ -6,14 +6,14 @@ import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.ExceptionHandler; 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.commons.util.RestfulResult; +import xyz.zhouxy.plusone.commons.exception.handler.BaseExceptionHandler; +import xyz.zhouxy.plusone.commons.exception.handler.RestfulResult; @RestControllerAdvice public class AccountLoginExceptionHandler extends BaseExceptionHandler { - public AccountLoginExceptionHandler(ExceptionInfoHolder exceptionInfoHolder) { + public AccountLoginExceptionHandler(@Nonnull ExceptionInfoHolder exceptionInfoHolder) { super(exceptionInfoHolder); } diff --git a/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/exception/handler/SaTokenExceptionHandler.java b/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/exception/handler/SaTokenExceptionHandler.java index a6e0808..172d5c1 100644 --- a/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/exception/handler/SaTokenExceptionHandler.java +++ b/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/exception/handler/SaTokenExceptionHandler.java @@ -1,5 +1,7 @@ package xyz.zhouxy.plusone.system.application.exception.handler; +import javax.annotation.Nonnull; + import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.ExceptionHandler; @@ -14,8 +16,8 @@ import cn.dev33.satoken.exception.NotSafeException; 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.commons.util.RestfulResult; +import xyz.zhouxy.plusone.commons.exception.handler.BaseExceptionHandler; +import xyz.zhouxy.plusone.commons.exception.handler.RestfulResult; /** * Sa-Token 异常处理器 @@ -27,7 +29,7 @@ import xyz.zhouxy.plusone.commons.util.RestfulResult; public class SaTokenExceptionHandler extends BaseExceptionHandler { - public SaTokenExceptionHandler(ExceptionInfoHolder exceptionInfoHolder) { + public SaTokenExceptionHandler(@Nonnull ExceptionInfoHolder exceptionInfoHolder) { super(exceptionInfoHolder); set(NotPermissionException.class, 4030103, "会话未能通过权限认证", HttpStatus.FORBIDDEN); set(NotRoleException.class, 4030103, "会话未能通过角色认证", HttpStatus.FORBIDDEN); From 8460b9da2901023ae8cf6aaf881e90864332d2c3 Mon Sep 17 00:00:00 2001 From: ZhouXY108 Date: Sun, 16 Apr 2023 00:08:04 +0800 Subject: [PATCH 2/8] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=83=A8=E5=88=86=20jsr3?= =?UTF-8?q?05=20=E6=B3=A8=E8=A7=A3=E7=9A=84=E4=BD=BF=E7=94=A8=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/xyz/zhouxy/plusone/constant/EntityStatus.java | 2 -- .../plusone/system/application/query/AccountQueries.java | 3 +++ .../plusone/system/domain/model/account/AccountStatus.java | 1 - .../xyz/zhouxy/plusone/system/domain/model/account/Sex.java | 2 -- 4 files changed, 3 insertions(+), 5 deletions(-) diff --git a/plusone-basic/plusone-basic-domain/src/main/java/xyz/zhouxy/plusone/constant/EntityStatus.java b/plusone-basic/plusone-basic-domain/src/main/java/xyz/zhouxy/plusone/constant/EntityStatus.java index 752e31e..d3e887e 100644 --- a/plusone-basic/plusone-basic-domain/src/main/java/xyz/zhouxy/plusone/constant/EntityStatus.java +++ b/plusone-basic/plusone-basic-domain/src/main/java/xyz/zhouxy/plusone/constant/EntityStatus.java @@ -24,12 +24,10 @@ public final class EntityStatus extends Enumeration { private static final ValueSet VALUE_SET = new ValueSet<>( AVAILABLE, DISABLED); - @Nonnull public static EntityStatus of(int id) { return VALUE_SET.get(id); } - @Nonnull public static Collection constants() { return VALUE_SET.getValues(); } diff --git a/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/query/AccountQueries.java b/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/query/AccountQueries.java index e1019e4..fa67800 100644 --- a/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/query/AccountQueries.java +++ b/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/query/AccountQueries.java @@ -2,6 +2,8 @@ package xyz.zhouxy.plusone.system.application.query; import java.util.List; +import javax.annotation.Nonnull; + import org.apache.ibatis.annotations.Mapper; import xyz.zhouxy.plusone.commons.util.PageDTO; @@ -23,6 +25,7 @@ public interface AccountQueries { return PageDTO.of(content, total); } + @Nonnull List queryAccountOverview(AccountQueryParams queryParams); long count(AccountQueryParams queryParams); diff --git a/plusone-system/plusone-system-domain/src/main/java/xyz/zhouxy/plusone/system/domain/model/account/AccountStatus.java b/plusone-system/plusone-system-domain/src/main/java/xyz/zhouxy/plusone/system/domain/model/account/AccountStatus.java index b5e9ba7..540ceab 100644 --- a/plusone-system/plusone-system-domain/src/main/java/xyz/zhouxy/plusone/system/domain/model/account/AccountStatus.java +++ b/plusone-system/plusone-system-domain/src/main/java/xyz/zhouxy/plusone/system/domain/model/account/AccountStatus.java @@ -31,7 +31,6 @@ public final class AccountStatus extends Enumeration implements I return VALUE_SET.get(id); } - @Nonnull public static Collection constants() { return VALUE_SET.getValues(); } diff --git a/plusone-system/plusone-system-domain/src/main/java/xyz/zhouxy/plusone/system/domain/model/account/Sex.java b/plusone-system/plusone-system-domain/src/main/java/xyz/zhouxy/plusone/system/domain/model/account/Sex.java index 2f66038..7a0d646 100644 --- a/plusone-system/plusone-system-domain/src/main/java/xyz/zhouxy/plusone/system/domain/model/account/Sex.java +++ b/plusone-system/plusone-system-domain/src/main/java/xyz/zhouxy/plusone/system/domain/model/account/Sex.java @@ -26,12 +26,10 @@ public final class Sex extends Enumeration implements IValueObject { private static final ValueSet VALUE_SET = new ValueSet<>(UNSET, MALE, FEMALE); - @Nonnull public static Sex of(int value) { return VALUE_SET.get(value); } - @Nonnull public static Collection constants() { return VALUE_SET.getValues(); } From f1d16808c66d91bc04ea97d3679da5d517fdba6d Mon Sep 17 00:00:00 2001 From: ZhouXY108 Date: Tue, 4 Apr 2023 18:53:38 +0800 Subject: [PATCH 3/8] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=B8=B8=E9=87=8F?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/xyz/zhouxy/plusone/constant/ErrorCodeConsts.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plusone-basic/plusone-basic-common/src/main/java/xyz/zhouxy/plusone/constant/ErrorCodeConsts.java b/plusone-basic/plusone-basic-common/src/main/java/xyz/zhouxy/plusone/constant/ErrorCodeConsts.java index 2c38bd4..569a78f 100644 --- a/plusone-basic/plusone-basic-common/src/main/java/xyz/zhouxy/plusone/constant/ErrorCodeConsts.java +++ b/plusone-basic/plusone-basic-common/src/main/java/xyz/zhouxy/plusone/constant/ErrorCodeConsts.java @@ -2,6 +2,8 @@ package xyz.zhouxy.plusone.constant; public class ErrorCodeConsts { public static final int DEFAULT_ERROR_CODE = 9999999; + public static final int DEFAULT_SYS_ERROR_CODE = 5000000; + public static final int DEFAULT_BIZ_ERROR_CODE = 4000000; private ErrorCodeConsts() { throw new IllegalStateException("Utility class"); From f3017e90c0d9378613f4ebeb8dff53e92db2ad0c Mon Sep 17 00:00:00 2001 From: ZhouXY108 Date: Thu, 6 Apr 2023 16:21:54 +0800 Subject: [PATCH 4/8] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=94=99=E5=88=AB?= =?UTF-8?q?=E5=AD=97=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/xyz/zhouxy/plusone/jdbc/common/ResultMapper.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plusone-basic/plusone-basic-infrastructure/src/main/java/xyz/zhouxy/plusone/jdbc/common/ResultMapper.java b/plusone-basic/plusone-basic-infrastructure/src/main/java/xyz/zhouxy/plusone/jdbc/common/ResultMapper.java index 55cf363..6d12efd 100644 --- a/plusone-basic/plusone-basic-infrastructure/src/main/java/xyz/zhouxy/plusone/jdbc/common/ResultMapper.java +++ b/plusone-basic/plusone-basic-infrastructure/src/main/java/xyz/zhouxy/plusone/jdbc/common/ResultMapper.java @@ -8,7 +8,7 @@ import java.sql.SQLException; * *

* 通过在 {@link #map(ResultSet)} 中配置 {@link ResultSet} 到对象的映射, - * 可将 {@link #rowMapper(ResultSet, int)} 的方法应用, + * 可将 {@link #rowMapper(ResultSet, int)} 的方法引用, * 直接当成 {@link org.springframework.jdbc.core.RowMapper} 对象传给 * {@link org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate} * 的查询方法, From 89584d2a48e711922ddb2eb69a61e472aabc5429 Mon Sep 17 00:00:00 2001 From: ZhouXY108 Date: Sat, 15 Apr 2023 13:37:44 +0800 Subject: [PATCH 5/8] =?UTF-8?q?=E9=87=8D=E6=9E=84=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../plusone/system/util/PasswordUtil.java | 29 +++++++++---------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/plusone-system/plusone-system-common/src/main/java/xyz/zhouxy/plusone/system/util/PasswordUtil.java b/plusone-system/plusone-system-common/src/main/java/xyz/zhouxy/plusone/system/util/PasswordUtil.java index 015a5f6..bf34ac9 100644 --- a/plusone-system/plusone-system-common/src/main/java/xyz/zhouxy/plusone/system/util/PasswordUtil.java +++ b/plusone-system/plusone-system-common/src/main/java/xyz/zhouxy/plusone/system/util/PasswordUtil.java @@ -4,10 +4,10 @@ import java.math.BigInteger; import java.nio.charset.StandardCharsets; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; +import java.util.Objects; import javax.annotation.Nonnull; -import lombok.extern.slf4j.Slf4j; import xyz.zhouxy.plusone.constant.ErrorCodeConsts; import xyz.zhouxy.plusone.exception.BizException; import xyz.zhouxy.plusone.util.RandomUtil; @@ -17,7 +17,6 @@ import xyz.zhouxy.plusone.util.RandomUtil; * * @author ZhouXY */ -@Slf4j public final class PasswordUtil { private static final char[] SALT_BASE_CHAR_ARRAY = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ~`!@#$%^&*()_-+={}[]|\\:;\"',.<>?/" .toCharArray(); @@ -36,11 +35,12 @@ public final class PasswordUtil { var passwordWithSalt = salt.substring(0, i) + password + salt.substring(1); - String sha512Hex = sha512Hex(passwordWithSalt); - if (sha512Hex == null) { - throw new BizException(ErrorCodeConsts.DEFAULT_ERROR_CODE, "未知错误:哈希加密失败!"); + + try { + return sha512Hex(passwordWithSalt); + } catch (Exception e) { + throw new BizException(ErrorCodeConsts.DEFAULT_ERROR_CODE, "哈希加密失败!", e); } - return sha512Hex; } /** @@ -57,15 +57,12 @@ public final class PasswordUtil { throw new IllegalStateException("Utility class"); } - private static String sha512Hex(String data) { - try { - MessageDigest messageDigest = MessageDigest.getInstance("SHA-512"); - messageDigest.update(data.getBytes(StandardCharsets.UTF_8)); - byte[] result = messageDigest.digest(); - return new BigInteger(1, result).toString(16); - } catch (NoSuchAlgorithmException e) { - log.error("{}", e); - } - return null; + @Nonnull + private static String sha512Hex(String data) throws NoSuchAlgorithmException { + MessageDigest messageDigest = MessageDigest.getInstance("SHA-512"); + messageDigest.update(data.getBytes(StandardCharsets.UTF_8)); + byte[] result = messageDigest.digest(); + var sha512Hex = new BigInteger(1, result).toString(16); + return Objects.requireNonNull(sha512Hex); } } From 0f145e383e7feb9cf8fc3f9d9c8b2d5ba68b8637 Mon Sep 17 00:00:00 2001 From: ZhouXY108 Date: Sat, 15 Apr 2023 13:38:00 +0800 Subject: [PATCH 6/8] =?UTF-8?q?=E9=87=8D=E6=9E=84=20FastDFSFile=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xyz/zhouxy/plusone/oss/FastDFSUtil.java | 84 ++++++++++++++++--- .../java/xyz/zhouxy/plusone/FastDFSTests.java | 10 +-- 2 files changed, 76 insertions(+), 18 deletions(-) diff --git a/plusone-basic/plusone-basic-infrastructure/src/main/java/xyz/zhouxy/plusone/oss/FastDFSUtil.java b/plusone-basic/plusone-basic-infrastructure/src/main/java/xyz/zhouxy/plusone/oss/FastDFSUtil.java index cbfc351..368f109 100644 --- a/plusone-basic/plusone-basic-infrastructure/src/main/java/xyz/zhouxy/plusone/oss/FastDFSUtil.java +++ b/plusone-basic/plusone-basic-infrastructure/src/main/java/xyz/zhouxy/plusone/oss/FastDFSUtil.java @@ -1,8 +1,17 @@ package xyz.zhouxy.plusone.oss; import java.io.ByteArrayInputStream; +import java.io.File; import java.io.IOException; import java.io.InputStream; +import java.math.BigInteger; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.util.Arrays; +import java.util.Objects; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; import org.csource.common.MyException; import org.csource.common.NameValuePair; @@ -14,7 +23,10 @@ import org.csource.fastdfs.TrackerServer; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.google.common.io.Files; + import lombok.Getter; +import xyz.zhouxy.plusone.exception.SysException; public class FastDFSUtil { @@ -44,7 +56,7 @@ public class FastDFSUtil { * @throws FastDFSException */ public String[] upload(FastDFSFile file) throws FastDFSException { - logger.info("File Name: {}, File Length: {}", file.getName(), file.getContent().length); + logger.info("File Name: {}, File Length: {}", file.getFileName(), file.getContent().length); NameValuePair[] metaList = new NameValuePair[1]; metaList[0] = new NameValuePair("author", file.getAuthor()); @@ -63,7 +75,7 @@ public class FastDFSUtil { uploadResults[0], uploadResults[1], System.currentTimeMillis() - startTime); } catch (IOException e) { - throw new FastDFSException("IO Exception when uploadind the file:" + file.getName(), e); + throw new FastDFSException("IO Exception when uploadind the file:" + file.getFileName(), e); } catch (MyException e) { throw new FastDFSException(e); } @@ -109,18 +121,68 @@ public class FastDFSUtil { } } - @Getter public static final class FastDFSFile { - private String name; - private byte[] content; - private String ext; - private String md5; - private String author; + @Getter + private final String fileName; + private final byte[] content; + @Getter + private final String ext; + @Getter + private final String md5; + @Getter + private final String author; - public FastDFSFile(String name, byte[] content, String ext) { - this.name = name; + private FastDFSFile(@Nonnull File file, @Nullable String author) throws IOException { + this.fileName = file.getName(); + this.content = Files.toByteArray(file); + this.ext = Files.getFileExtension(fileName); + this.md5 = md5Hex(content); + this.author = author; + } + + private FastDFSFile(@Nonnull String fileName, @Nonnull byte[] content, @Nullable String author) { + this.fileName = fileName; this.content = content; - this.ext = ext; + this.ext = Files.getFileExtension(fileName); + this.md5 = md5Hex(content); + this.author = author; + } + + @Nonnull + public static FastDFSFile of(@Nonnull File file) throws IOException { + return new FastDFSFile(file, null); + } + + @Nonnull + public static FastDFSFile of(@Nonnull File file, @Nullable String author) throws IOException { + return new FastDFSFile(file, author); + } + + @Nonnull + public static FastDFSFile of(@Nonnull String fileName, @Nonnull byte[] content) { + return new FastDFSFile(fileName, content, null); + } + + @Nonnull + public static FastDFSFile of(@Nonnull String fileName, @Nonnull byte[] content, @Nullable String author) { + return new FastDFSFile(fileName, content, author); + } + + public byte[] getContent() { + return Arrays.copyOf(content, content.length); + } + + @Nonnull + private static String md5Hex(byte[] data) { + try { + MessageDigest messageDigest = MessageDigest.getInstance("MD5"); + messageDigest.update(data); + byte[] result = messageDigest.digest(); + var sha512Hex = new BigInteger(1, result).toString(16); + return Objects.requireNonNull(sha512Hex); + } catch (NoSuchAlgorithmException e) { + throw new SysException(e); + } } } } diff --git a/plusone-start/src/test/java/xyz/zhouxy/plusone/FastDFSTests.java b/plusone-start/src/test/java/xyz/zhouxy/plusone/FastDFSTests.java index 69efb0d..88d70ce 100644 --- a/plusone-start/src/test/java/xyz/zhouxy/plusone/FastDFSTests.java +++ b/plusone-start/src/test/java/xyz/zhouxy/plusone/FastDFSTests.java @@ -1,12 +1,11 @@ package xyz.zhouxy.plusone; -import java.io.FileInputStream; +import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import javax.annotation.Resource; -import org.apache.commons.io.IOUtils; import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; @@ -24,10 +23,7 @@ class FastDFSTests { @Test void testOSS() throws FileNotFoundException, IOException, FastDFSException { - try (FileInputStream in = new FileInputStream("D:\\ZhouXY\\Desktop\\666.png");) { - byte[] content = IOUtils.toByteArray(in); - String[] upload = fastDFSUtil.upload(new FastDFSFile("666.png", content, "png")); - log.info(String.join("/", upload)); - } + String[] upload = fastDFSUtil.upload(FastDFSFile.of(new File("D:\\ZhouXY\\Desktop\\666.png"))); + log.info(String.join("/", upload)); } } From fe03b6da4d27256c829e70e2360772b265c37bce Mon Sep 17 00:00:00 2001 From: ZhouXY108 Date: Sun, 16 Apr 2023 00:16:11 +0800 Subject: [PATCH 7/8] =?UTF-8?q?=E9=9D=99=E6=80=81=E5=B7=A5=E5=8E=82?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E6=B7=BB=E5=8A=A0=20@StaticFactoryMethod=20?= =?UTF-8?q?=E6=B3=A8=E8=A7=A3=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/xyz/zhouxy/plusone/oss/FastDFSUtil.java | 5 +++++ .../zhouxy/plusone/system/domain/model/account/Account.java | 4 ++++ .../zhouxy/plusone/system/domain/model/account/Email.java | 3 +++ .../plusone/system/domain/model/account/MobilePhone.java | 3 +++ .../zhouxy/plusone/system/domain/model/account/Nickname.java | 3 +++ .../zhouxy/plusone/system/domain/model/account/Password.java | 5 +++++ .../xyz/zhouxy/plusone/system/domain/model/account/Sex.java | 2 ++ .../zhouxy/plusone/system/domain/model/account/Username.java | 2 ++ .../xyz/zhouxy/plusone/system/domain/model/dict/Dict.java | 4 ++++ .../zhouxy/plusone/system/domain/model/dict/DictValue.java | 2 ++ .../plusone/system/domain/model/menu/MenuConstructor.java | 3 +++ .../plusone/system/domain/model/permission/Action.java | 5 ++++- .../plusone/system/domain/model/permission/Permission.java | 2 ++ 13 files changed, 42 insertions(+), 1 deletion(-) diff --git a/plusone-basic/plusone-basic-infrastructure/src/main/java/xyz/zhouxy/plusone/oss/FastDFSUtil.java b/plusone-basic/plusone-basic-infrastructure/src/main/java/xyz/zhouxy/plusone/oss/FastDFSUtil.java index 368f109..09640ca 100644 --- a/plusone-basic/plusone-basic-infrastructure/src/main/java/xyz/zhouxy/plusone/oss/FastDFSUtil.java +++ b/plusone-basic/plusone-basic-infrastructure/src/main/java/xyz/zhouxy/plusone/oss/FastDFSUtil.java @@ -26,6 +26,7 @@ import org.slf4j.LoggerFactory; import com.google.common.io.Files; import lombok.Getter; +import xyz.zhouxy.plusone.commons.annotation.StaticFactoryMethod; import xyz.zhouxy.plusone.exception.SysException; public class FastDFSUtil { @@ -149,21 +150,25 @@ public class FastDFSUtil { } @Nonnull + @StaticFactoryMethod(FastDFSFile.class) public static FastDFSFile of(@Nonnull File file) throws IOException { return new FastDFSFile(file, null); } @Nonnull + @StaticFactoryMethod(FastDFSFile.class) public static FastDFSFile of(@Nonnull File file, @Nullable String author) throws IOException { return new FastDFSFile(file, author); } @Nonnull + @StaticFactoryMethod(FastDFSFile.class) public static FastDFSFile of(@Nonnull String fileName, @Nonnull byte[] content) { return new FastDFSFile(fileName, content, null); } @Nonnull + @StaticFactoryMethod(FastDFSFile.class) public static FastDFSFile of(@Nonnull String fileName, @Nonnull byte[] content, @Nullable String author) { return new FastDFSFile(fileName, content, author); } diff --git a/plusone-system/plusone-system-domain/src/main/java/xyz/zhouxy/plusone/system/domain/model/account/Account.java b/plusone-system/plusone-system-domain/src/main/java/xyz/zhouxy/plusone/system/domain/model/account/Account.java index 3150b64..08e913e 100644 --- a/plusone-system/plusone-system-domain/src/main/java/xyz/zhouxy/plusone/system/domain/model/account/Account.java +++ b/plusone-system/plusone-system-domain/src/main/java/xyz/zhouxy/plusone/system/domain/model/account/Account.java @@ -6,6 +6,7 @@ import java.util.Optional; import java.util.Set; import lombok.ToString; +import xyz.zhouxy.plusone.commons.annotation.StaticFactoryMethod; import xyz.zhouxy.plusone.domain.AggregateRoot; import xyz.zhouxy.plusone.domain.IWithVersion; import xyz.zhouxy.plusone.exception.UserOperationException; @@ -164,6 +165,7 @@ public class Account extends AggregateRoot implements IWithVersion { return newInstance; } + @StaticFactoryMethod(Account.class) public static Account register( Username username, Email email, @@ -193,6 +195,7 @@ public class Account extends AggregateRoot implements IWithVersion { password, status, accountInfo, roleRefs, createdBy, updatedBy, version); } + @StaticFactoryMethod(Account.class) public static Account newInstance( String username, String email, @@ -210,6 +213,7 @@ public class Account extends AggregateRoot implements IWithVersion { return newInstance; } + @StaticFactoryMethod(Account.class) public static Account register( String username, String email, diff --git a/plusone-system/plusone-system-domain/src/main/java/xyz/zhouxy/plusone/system/domain/model/account/Email.java b/plusone-system/plusone-system-domain/src/main/java/xyz/zhouxy/plusone/system/domain/model/account/Email.java index fe12230..680e881 100644 --- a/plusone-system/plusone-system-domain/src/main/java/xyz/zhouxy/plusone/system/domain/model/account/Email.java +++ b/plusone-system/plusone-system-domain/src/main/java/xyz/zhouxy/plusone/system/domain/model/account/Email.java @@ -4,6 +4,7 @@ import java.util.Objects; import java.util.regex.Pattern; import cn.hutool.core.util.DesensitizedUtil; +import xyz.zhouxy.plusone.commons.annotation.StaticFactoryMethod; import xyz.zhouxy.plusone.commons.constant.PatternConsts; /** @@ -26,10 +27,12 @@ public class Email extends Principal { } } + @StaticFactoryMethod(Email.class) public static Email of(String email) { return new Email(email); } + @StaticFactoryMethod(Email.class) public static Email ofNullable(String email) { return Objects.nonNull(email) ? new Email(email) : null; } diff --git a/plusone-system/plusone-system-domain/src/main/java/xyz/zhouxy/plusone/system/domain/model/account/MobilePhone.java b/plusone-system/plusone-system-domain/src/main/java/xyz/zhouxy/plusone/system/domain/model/account/MobilePhone.java index c641536..15a3692 100644 --- a/plusone-system/plusone-system-domain/src/main/java/xyz/zhouxy/plusone/system/domain/model/account/MobilePhone.java +++ b/plusone-system/plusone-system-domain/src/main/java/xyz/zhouxy/plusone/system/domain/model/account/MobilePhone.java @@ -4,6 +4,7 @@ import java.util.Objects; import java.util.regex.Pattern; import cn.hutool.core.util.DesensitizedUtil; +import xyz.zhouxy.plusone.commons.annotation.StaticFactoryMethod; import xyz.zhouxy.plusone.commons.constant.PatternConsts; /** @@ -26,10 +27,12 @@ public class MobilePhone extends Principal { } } + @StaticFactoryMethod(MobilePhone.class) public static MobilePhone of(String mobilePhone) { return new MobilePhone(mobilePhone); } + @StaticFactoryMethod(MobilePhone.class) public static MobilePhone ofNullable(String mobilePhone) { return Objects.nonNull(mobilePhone) ? new MobilePhone(mobilePhone) : null; } diff --git a/plusone-system/plusone-system-domain/src/main/java/xyz/zhouxy/plusone/system/domain/model/account/Nickname.java b/plusone-system/plusone-system-domain/src/main/java/xyz/zhouxy/plusone/system/domain/model/account/Nickname.java index 0d09911..d1964b2 100644 --- a/plusone-system/plusone-system-domain/src/main/java/xyz/zhouxy/plusone/system/domain/model/account/Nickname.java +++ b/plusone-system/plusone-system-domain/src/main/java/xyz/zhouxy/plusone/system/domain/model/account/Nickname.java @@ -3,6 +3,7 @@ package xyz.zhouxy.plusone.system.domain.model.account; import java.util.Objects; import java.util.regex.Pattern; +import xyz.zhouxy.plusone.commons.annotation.StaticFactoryMethod; import xyz.zhouxy.plusone.commons.constant.PatternConsts; import xyz.zhouxy.plusone.domain.ValidatableStringRecord; @@ -26,10 +27,12 @@ public class Nickname extends ValidatableStringRecord { } } + @StaticFactoryMethod(Nickname.class) public static Nickname of(String nickname) { return new Nickname(nickname); } + @StaticFactoryMethod(Nickname.class) public static Nickname ofNullable(String nickname) { return Objects.nonNull(nickname) ? new Nickname(nickname) : null; } diff --git a/plusone-system/plusone-system-domain/src/main/java/xyz/zhouxy/plusone/system/domain/model/account/Password.java b/plusone-system/plusone-system-domain/src/main/java/xyz/zhouxy/plusone/system/domain/model/account/Password.java index d810c58..ba0b109 100644 --- a/plusone-system/plusone-system-domain/src/main/java/xyz/zhouxy/plusone/system/domain/model/account/Password.java +++ b/plusone-system/plusone-system-domain/src/main/java/xyz/zhouxy/plusone/system/domain/model/account/Password.java @@ -7,6 +7,7 @@ import javax.annotation.Nonnull; import org.springframework.util.Assert; +import xyz.zhouxy.plusone.commons.annotation.StaticFactoryMethod; import xyz.zhouxy.plusone.commons.constant.PatternConsts; import xyz.zhouxy.plusone.constant.ErrorCodeConsts; import xyz.zhouxy.plusone.domain.IValueObject; @@ -51,15 +52,18 @@ public class Password implements IValueObject { this.saltVal = salt; } + @StaticFactoryMethod(Password.class) public static Password of(String password, String salt) { return new Password(password, salt); } + @StaticFactoryMethod(Password.class) public static Password newPassword(String newPassword, String passwordConfirmation) { Assert.isTrue(Objects.equals(newPassword, passwordConfirmation), "两次输入的密码不一致"); return newPassword(newPassword); } + @StaticFactoryMethod(Password.class) public static Password newPassword(String newPassword) { return new Password(newPassword); } @@ -80,6 +84,7 @@ public class Password implements IValueObject { return saltVal; } + @StaticFactoryMethod(Nickname.class) public static Password newDefaultPassword() { return newPassword(DEFAULT_PASSWORD); } diff --git a/plusone-system/plusone-system-domain/src/main/java/xyz/zhouxy/plusone/system/domain/model/account/Sex.java b/plusone-system/plusone-system-domain/src/main/java/xyz/zhouxy/plusone/system/domain/model/account/Sex.java index 7a0d646..09735c5 100644 --- a/plusone-system/plusone-system-domain/src/main/java/xyz/zhouxy/plusone/system/domain/model/account/Sex.java +++ b/plusone-system/plusone-system-domain/src/main/java/xyz/zhouxy/plusone/system/domain/model/account/Sex.java @@ -4,6 +4,7 @@ import java.util.Collection; import javax.annotation.Nonnull; +import xyz.zhouxy.plusone.commons.annotation.StaticFactoryMethod; import xyz.zhouxy.plusone.commons.util.Enumeration; import xyz.zhouxy.plusone.domain.IValueObject; @@ -26,6 +27,7 @@ public final class Sex extends Enumeration implements IValueObject { private static final ValueSet VALUE_SET = new ValueSet<>(UNSET, MALE, FEMALE); + @StaticFactoryMethod(Sex.class) public static Sex of(int value) { return VALUE_SET.get(value); } diff --git a/plusone-system/plusone-system-domain/src/main/java/xyz/zhouxy/plusone/system/domain/model/account/Username.java b/plusone-system/plusone-system-domain/src/main/java/xyz/zhouxy/plusone/system/domain/model/account/Username.java index 530144f..92b1420 100644 --- a/plusone-system/plusone-system-domain/src/main/java/xyz/zhouxy/plusone/system/domain/model/account/Username.java +++ b/plusone-system/plusone-system-domain/src/main/java/xyz/zhouxy/plusone/system/domain/model/account/Username.java @@ -2,6 +2,7 @@ package xyz.zhouxy.plusone.system.domain.model.account; import java.util.regex.Pattern; +import xyz.zhouxy.plusone.commons.annotation.StaticFactoryMethod; import xyz.zhouxy.plusone.commons.constant.PatternConsts; /** @@ -24,6 +25,7 @@ public class Username extends Principal { } } + @StaticFactoryMethod(Username.class) public static Username of(String username) { return new Username(username); } diff --git a/plusone-system/plusone-system-domain/src/main/java/xyz/zhouxy/plusone/system/domain/model/dict/Dict.java b/plusone-system/plusone-system-domain/src/main/java/xyz/zhouxy/plusone/system/domain/model/dict/Dict.java index 0e2c184..dc7fa42 100644 --- a/plusone-system/plusone-system-domain/src/main/java/xyz/zhouxy/plusone/system/domain/model/dict/Dict.java +++ b/plusone-system/plusone-system-domain/src/main/java/xyz/zhouxy/plusone/system/domain/model/dict/Dict.java @@ -8,6 +8,7 @@ import java.util.Optional; import java.util.Set; import lombok.ToString; +import xyz.zhouxy.plusone.commons.annotation.StaticFactoryMethod; import xyz.zhouxy.plusone.domain.AggregateRoot; import xyz.zhouxy.plusone.domain.IWithLabel; import xyz.zhouxy.plusone.domain.IWithVersion; @@ -70,12 +71,14 @@ public class Dict extends AggregateRoot implements IWithLabel, IWithVersio this.version = version; } + @StaticFactoryMethod(Dict.class) public static Dict newInstance( String dictType, String dictLabel) { return new Dict(null, dictType, dictLabel, Collections.emptySet(), 0); } + @StaticFactoryMethod(Dict.class) public static Dict newInstance( String dictType, String dictLabel, @@ -83,6 +86,7 @@ public class Dict extends AggregateRoot implements IWithLabel, IWithVersio return new Dict(null, dictType, dictLabel, values, 0); } + @StaticFactoryMethod(Dict.class) public static Dict newInstance( String dictType, String dictLabel, diff --git a/plusone-system/plusone-system-domain/src/main/java/xyz/zhouxy/plusone/system/domain/model/dict/DictValue.java b/plusone-system/plusone-system-domain/src/main/java/xyz/zhouxy/plusone/system/domain/model/dict/DictValue.java index 5e8650a..b7ae79e 100644 --- a/plusone-system/plusone-system-domain/src/main/java/xyz/zhouxy/plusone/system/domain/model/dict/DictValue.java +++ b/plusone-system/plusone-system-domain/src/main/java/xyz/zhouxy/plusone/system/domain/model/dict/DictValue.java @@ -4,6 +4,7 @@ import java.util.Objects; import lombok.Getter; import lombok.ToString; +import xyz.zhouxy.plusone.commons.annotation.StaticFactoryMethod; import xyz.zhouxy.plusone.domain.IValueObject; /** @@ -25,6 +26,7 @@ public class DictValue implements IValueObject { this.label = label; } + @StaticFactoryMethod(DictValue.class) public static DictValue of(int key, String label) { return new DictValue(key, label); } diff --git a/plusone-system/plusone-system-domain/src/main/java/xyz/zhouxy/plusone/system/domain/model/menu/MenuConstructor.java b/plusone-system/plusone-system-domain/src/main/java/xyz/zhouxy/plusone/system/domain/model/menu/MenuConstructor.java index 8902760..165f84f 100644 --- a/plusone-system/plusone-system-domain/src/main/java/xyz/zhouxy/plusone/system/domain/model/menu/MenuConstructor.java +++ b/plusone-system/plusone-system-domain/src/main/java/xyz/zhouxy/plusone/system/domain/model/menu/MenuConstructor.java @@ -2,6 +2,7 @@ package xyz.zhouxy.plusone.system.domain.model.menu; import java.util.List; +import xyz.zhouxy.plusone.commons.annotation.StaticFactoryMethod; import xyz.zhouxy.plusone.constant.EntityStatus; import xyz.zhouxy.plusone.system.domain.model.menu.Menu.MenuType; @@ -16,6 +17,7 @@ public class MenuConstructor { throw new IllegalStateException("Utility class"); } + @StaticFactoryMethod(Menu.class) public static Menu newMenuItem( long parentId, String path, @@ -39,6 +41,7 @@ public class MenuConstructor { remarks, component, cache, resource, actions, 0L); } + @StaticFactoryMethod(Menu.class) public static Menu newMenuList( long parentId, String path, diff --git a/plusone-system/plusone-system-domain/src/main/java/xyz/zhouxy/plusone/system/domain/model/permission/Action.java b/plusone-system/plusone-system-domain/src/main/java/xyz/zhouxy/plusone/system/domain/model/permission/Action.java index 9addc7f..a2903ae 100644 --- a/plusone-system/plusone-system-domain/src/main/java/xyz/zhouxy/plusone/system/domain/model/permission/Action.java +++ b/plusone-system/plusone-system-domain/src/main/java/xyz/zhouxy/plusone/system/domain/model/permission/Action.java @@ -3,6 +3,7 @@ package xyz.zhouxy.plusone.system.domain.model.permission; import java.util.Optional; import lombok.Getter; +import xyz.zhouxy.plusone.commons.annotation.StaticFactoryMethod; import xyz.zhouxy.plusone.domain.Entity; import xyz.zhouxy.plusone.domain.IWithLabel; import xyz.zhouxy.plusone.domain.IWithVersion; @@ -20,7 +21,7 @@ public class Action extends Entity implements IWithLabel, IWithVersion { @Getter String label; @Getter long version; - public Action(Long id, String resource, String identifier, String label, long version) { + private Action(Long id, String resource, String identifier, String label, long version) { this.id = id; this.resource = resource; this.identifier = identifier; @@ -28,10 +29,12 @@ public class Action extends Entity implements IWithLabel, IWithVersion { this.version = version; } + @StaticFactoryMethod(Action.class) static Action newInstance(String resource, String identifier, String label) { return new Action(null, resource, identifier, label, 0L); } + @StaticFactoryMethod(Action.class) static Action existingInstance(Long id, String resource, String action, String label, Long version) { return new Action(id, resource, action, label, version); } diff --git a/plusone-system/plusone-system-domain/src/main/java/xyz/zhouxy/plusone/system/domain/model/permission/Permission.java b/plusone-system/plusone-system-domain/src/main/java/xyz/zhouxy/plusone/system/domain/model/permission/Permission.java index b3bb8cb..892e0bf 100644 --- a/plusone-system/plusone-system-domain/src/main/java/xyz/zhouxy/plusone/system/domain/model/permission/Permission.java +++ b/plusone-system/plusone-system-domain/src/main/java/xyz/zhouxy/plusone/system/domain/model/permission/Permission.java @@ -6,6 +6,7 @@ import java.util.Objects; import java.util.Optional; import lombok.Getter; +import xyz.zhouxy.plusone.commons.annotation.StaticFactoryMethod; import xyz.zhouxy.plusone.domain.AggregateRoot; import xyz.zhouxy.plusone.domain.IWithVersion; @@ -37,6 +38,7 @@ public class Permission extends AggregateRoot implements IWithVersion { // ==================== 实例化 ==================== + @StaticFactoryMethod(Permission.class) public static Permission newInstance(String resource) { return new Permission( null, resource, From 62607dc0a4f8c1278e1c1751843e0716c94a57ba Mon Sep 17 00:00:00 2001 From: ZhouXY108 Date: Sun, 16 Apr 2023 00:54:59 +0800 Subject: [PATCH 8/8] =?UTF-8?q?plusone-exception-handler=20=E7=9A=84?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E8=B0=83=E6=95=B4=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../plusone/exception/handler/DefaultExceptionHandler.java | 2 +- .../exception/handler/AccountLoginExceptionHandler.java | 2 +- .../application/exception/handler/SaTokenExceptionHandler.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/plusone-basic/plusone-basic-application/src/main/java/xyz/zhouxy/plusone/exception/handler/DefaultExceptionHandler.java b/plusone-basic/plusone-basic-application/src/main/java/xyz/zhouxy/plusone/exception/handler/DefaultExceptionHandler.java index 51e4499..6374a97 100644 --- a/plusone-basic/plusone-basic-application/src/main/java/xyz/zhouxy/plusone/exception/handler/DefaultExceptionHandler.java +++ b/plusone-basic/plusone-basic-application/src/main/java/xyz/zhouxy/plusone/exception/handler/DefaultExceptionHandler.java @@ -14,7 +14,7 @@ import org.springframework.web.bind.annotation.RestControllerAdvice; import lombok.extern.slf4j.Slf4j; import xyz.zhouxy.plusone.commons.exception.handler.BaseExceptionHandler; -import xyz.zhouxy.plusone.commons.exception.handler.RestfulResult; +import xyz.zhouxy.plusone.commons.util.RestfulResult; /** * 默认异常的处理器 diff --git a/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/exception/handler/AccountLoginExceptionHandler.java b/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/exception/handler/AccountLoginExceptionHandler.java index 0351fec..4f1895b 100644 --- a/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/exception/handler/AccountLoginExceptionHandler.java +++ b/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/exception/handler/AccountLoginExceptionHandler.java @@ -8,7 +8,7 @@ import org.springframework.web.bind.annotation.RestControllerAdvice; import xyz.zhouxy.plusone.system.application.exception.AccountLoginException; import xyz.zhouxy.plusone.commons.exception.handler.BaseExceptionHandler; -import xyz.zhouxy.plusone.commons.exception.handler.RestfulResult; +import xyz.zhouxy.plusone.commons.util.RestfulResult; @RestControllerAdvice public class AccountLoginExceptionHandler extends BaseExceptionHandler { diff --git a/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/exception/handler/SaTokenExceptionHandler.java b/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/exception/handler/SaTokenExceptionHandler.java index 172d5c1..0db62bc 100644 --- a/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/exception/handler/SaTokenExceptionHandler.java +++ b/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/exception/handler/SaTokenExceptionHandler.java @@ -17,7 +17,7 @@ import cn.dev33.satoken.exception.SaTokenException; import cn.dev33.satoken.exception.SameTokenInvalidException; import lombok.extern.slf4j.Slf4j; import xyz.zhouxy.plusone.commons.exception.handler.BaseExceptionHandler; -import xyz.zhouxy.plusone.commons.exception.handler.RestfulResult; +import xyz.zhouxy.plusone.commons.util.RestfulResult; /** * Sa-Token 异常处理器