From fe03b6da4d27256c829e70e2360772b265c37bce Mon Sep 17 00:00:00 2001 From: ZhouXY108 Date: Sun, 16 Apr 2023 00:16:11 +0800 Subject: [PATCH] =?UTF-8?q?=E9=9D=99=E6=80=81=E5=B7=A5=E5=8E=82=E6=96=B9?= =?UTF-8?q?=E6=B3=95=E6=B7=BB=E5=8A=A0=20@StaticFactoryMethod=20=E6=B3=A8?= =?UTF-8?q?=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,