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 2f66038..c8e87e0 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; @@ -27,6 +28,7 @@ public final class Sex extends Enumeration implements IValueObject { private static final ValueSet VALUE_SET = new ValueSet<>(UNSET, MALE, FEMALE); @Nonnull + @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,