Compare commits

..

5 Commits

21 changed files with 171 additions and 62 deletions

View File

@ -1,5 +1,9 @@
package xyz.zhouxy.plusone.constant; package xyz.zhouxy.plusone.constant;
import java.util.Collection;
import javax.annotation.Nonnull;
import xyz.zhouxy.plusone.commons.util.Enumeration; import xyz.zhouxy.plusone.commons.util.Enumeration;
/** /**
@ -9,24 +13,24 @@ import xyz.zhouxy.plusone.commons.util.Enumeration;
*/ */
public final class EntityStatus extends Enumeration<EntityStatus> { public final class EntityStatus extends Enumeration<EntityStatus> {
private EntityStatus(int value, String name) { private EntityStatus(int id, @Nonnull String name) {
super(value, name); super(id, name);
} }
// 常量 // 常量
public static final EntityStatus AVAILABLE = new EntityStatus(0, "正常"); public static final EntityStatus AVAILABLE = new EntityStatus(0, "正常");
public static final EntityStatus DISABLED = new EntityStatus(1, "禁用"); public static final EntityStatus DISABLED = new EntityStatus(1, "禁用");
private static final EnumerationValuesHolder<EntityStatus> ENUMERATION_VALUES = new EnumerationValuesHolder<>( private static final ValueSet<EntityStatus> VALUE_SET = new ValueSet<>(
AVAILABLE, AVAILABLE, DISABLED);
DISABLED);
public static EntityStatus of(int value) { @Nonnull
return ENUMERATION_VALUES.get(value); public static EntityStatus of(int id) {
return VALUE_SET.get(id);
} }
@Override @Nonnull
public String toString() { public static Collection<EntityStatus> constants() {
return "EntityStatus" + super.toString(); return VALUE_SET.getValues();
} }
} }

View File

@ -1,8 +1,17 @@
package xyz.zhouxy.plusone.oss; package xyz.zhouxy.plusone.oss;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; 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.MyException;
import org.csource.common.NameValuePair; import org.csource.common.NameValuePair;
@ -14,7 +23,10 @@ import org.csource.fastdfs.TrackerServer;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import com.google.common.io.Files;
import lombok.Getter; import lombok.Getter;
import xyz.zhouxy.plusone.exception.SysException;
public class FastDFSUtil { public class FastDFSUtil {
@ -44,7 +56,7 @@ public class FastDFSUtil {
* @throws FastDFSException * @throws FastDFSException
*/ */
public String[] upload(FastDFSFile file) 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]; NameValuePair[] metaList = new NameValuePair[1];
metaList[0] = new NameValuePair("author", file.getAuthor()); metaList[0] = new NameValuePair("author", file.getAuthor());
@ -63,7 +75,7 @@ public class FastDFSUtil {
uploadResults[0], uploadResults[1], System.currentTimeMillis() - startTime); uploadResults[0], uploadResults[1], System.currentTimeMillis() - startTime);
} catch (IOException e) { } 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) { } catch (MyException e) {
throw new FastDFSException(e); throw new FastDFSException(e);
} }
@ -109,18 +121,68 @@ public class FastDFSUtil {
} }
} }
@Getter
public static final class FastDFSFile { public static final class FastDFSFile {
private String name; @Getter
private byte[] content; private final String fileName;
private String ext; private final byte[] content;
private String md5; @Getter
private String author; private final String ext;
@Getter
private final String md5;
@Getter
private final String author;
public FastDFSFile(String name, byte[] content, String ext) { private FastDFSFile(@Nonnull File file, @Nullable String author) throws IOException {
this.name = name; 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.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);
}
} }
} }
} }

View File

@ -1,12 +1,11 @@
package xyz.zhouxy.plusone; package xyz.zhouxy.plusone;
import java.io.FileInputStream; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import javax.annotation.Resource; import javax.annotation.Resource;
import org.apache.commons.io.IOUtils;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
@ -24,10 +23,7 @@ class FastDFSTests {
@Test @Test
void testOSS() throws FileNotFoundException, IOException, FastDFSException { void testOSS() throws FileNotFoundException, IOException, FastDFSException {
try (FileInputStream in = new FileInputStream("D:\\ZhouXY\\Desktop\\666.png");) { String[] upload = fastDFSUtil.upload(FastDFSFile.of(new File("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)); log.info(String.join("/", upload));
} }
}
} }

View File

@ -109,7 +109,7 @@ public class MenuViewObject implements IWithOrderNumber {
viewObject.icon = menu.getIcon(); viewObject.icon = menu.getIcon();
viewObject.hidden = menu.isHidden(); viewObject.hidden = menu.isHidden();
viewObject.orderNumber = menu.getOrderNumber(); viewObject.orderNumber = menu.getOrderNumber();
viewObject.status = menu.getStatus().getValue(); viewObject.status = menu.getStatus().getId();
viewObject.remarks = menu.getRemarks(); viewObject.remarks = menu.getRemarks();
if (viewObject.type == MenuType.MENU_ITEM.ordinal()) { if (viewObject.type == MenuType.MENU_ITEM.ordinal()) {
viewObject.component = menu.getComponent(); viewObject.component = menu.getComponent();

View File

@ -4,10 +4,10 @@ import java.math.BigInteger;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.security.MessageDigest; import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.util.Objects;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import lombok.extern.slf4j.Slf4j;
import xyz.zhouxy.plusone.constant.ErrorCodeConsts; import xyz.zhouxy.plusone.constant.ErrorCodeConsts;
import xyz.zhouxy.plusone.exception.BizException; import xyz.zhouxy.plusone.exception.BizException;
import xyz.zhouxy.plusone.util.RandomUtil; import xyz.zhouxy.plusone.util.RandomUtil;
@ -17,7 +17,6 @@ import xyz.zhouxy.plusone.util.RandomUtil;
* *
* @author <a href="https://gitee.com/zhouxy108">ZhouXY</a> * @author <a href="https://gitee.com/zhouxy108">ZhouXY</a>
*/ */
@Slf4j
public final class PasswordUtil { public final class PasswordUtil {
private static final char[] SALT_BASE_CHAR_ARRAY = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ~`!@#$%^&*()_-+={}[]|\\:;\"',.<>?/" private static final char[] SALT_BASE_CHAR_ARRAY = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ~`!@#$%^&*()_-+={}[]|\\:;\"',.<>?/"
.toCharArray(); .toCharArray();
@ -36,11 +35,12 @@ public final class PasswordUtil {
var passwordWithSalt = salt.substring(0, i) var passwordWithSalt = salt.substring(0, i)
+ password + password
+ salt.substring(1); + salt.substring(1);
String sha512Hex = sha512Hex(passwordWithSalt);
if (sha512Hex == null) { try {
throw new BizException(ErrorCodeConsts.DEFAULT_ERROR_CODE, "未知错误:哈希加密失败!"); 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"); throw new IllegalStateException("Utility class");
} }
private static String sha512Hex(String data) { @Nonnull
try { private static String sha512Hex(String data) throws NoSuchAlgorithmException {
MessageDigest messageDigest = MessageDigest.getInstance("SHA-512"); MessageDigest messageDigest = MessageDigest.getInstance("SHA-512");
messageDigest.update(data.getBytes(StandardCharsets.UTF_8)); messageDigest.update(data.getBytes(StandardCharsets.UTF_8));
byte[] result = messageDigest.digest(); byte[] result = messageDigest.digest();
return new BigInteger(1, result).toString(16); var sha512Hex = new BigInteger(1, result).toString(16);
} catch (NoSuchAlgorithmException e) { return Objects.requireNonNull(sha512Hex);
log.error("{}", e);
}
return null;
} }
} }

View File

@ -6,6 +6,7 @@ import java.util.Optional;
import java.util.Set; import java.util.Set;
import lombok.ToString; import lombok.ToString;
import xyz.zhouxy.plusone.commons.annotation.StaticFactoryMethod;
import xyz.zhouxy.plusone.domain.AggregateRoot; import xyz.zhouxy.plusone.domain.AggregateRoot;
import xyz.zhouxy.plusone.domain.IWithVersion; import xyz.zhouxy.plusone.domain.IWithVersion;
import xyz.zhouxy.plusone.exception.UserOperationException; import xyz.zhouxy.plusone.exception.UserOperationException;
@ -164,6 +165,7 @@ public class Account extends AggregateRoot<Long> implements IWithVersion {
return newInstance; return newInstance;
} }
@StaticFactoryMethod(Account.class)
public static Account register( public static Account register(
Username username, Username username,
Email email, Email email,
@ -193,6 +195,7 @@ public class Account extends AggregateRoot<Long> implements IWithVersion {
password, status, accountInfo, roleRefs, createdBy, updatedBy, version); password, status, accountInfo, roleRefs, createdBy, updatedBy, version);
} }
@StaticFactoryMethod(Account.class)
public static Account newInstance( public static Account newInstance(
String username, String username,
String email, String email,
@ -210,6 +213,7 @@ public class Account extends AggregateRoot<Long> implements IWithVersion {
return newInstance; return newInstance;
} }
@StaticFactoryMethod(Account.class)
public static Account register( public static Account register(
String username, String username,
String email, String email,

View File

@ -1,5 +1,9 @@
package xyz.zhouxy.plusone.system.domain.model.account; package xyz.zhouxy.plusone.system.domain.model.account;
import java.util.Collection;
import javax.annotation.Nonnull;
import lombok.Getter; import lombok.Getter;
import xyz.zhouxy.plusone.commons.util.Enumeration; import xyz.zhouxy.plusone.commons.util.Enumeration;
import xyz.zhouxy.plusone.domain.IValueObject; import xyz.zhouxy.plusone.domain.IValueObject;
@ -12,18 +16,23 @@ import xyz.zhouxy.plusone.domain.IValueObject;
@Getter @Getter
public final class AccountStatus extends Enumeration<AccountStatus> implements IValueObject { public final class AccountStatus extends Enumeration<AccountStatus> implements IValueObject {
private AccountStatus(int value, String name) { private AccountStatus(int id, @Nonnull String name) {
super(value, name); super(id, name);
} }
public static final AccountStatus AVAILABLE = new AccountStatus(0, "账号正常"); public static final AccountStatus AVAILABLE = new AccountStatus(0, "账号正常");
public static final AccountStatus LOCKED = new AccountStatus(1, "账号被锁定"); public static final AccountStatus LOCKED = new AccountStatus(1, "账号被锁定");
private static final EnumerationValuesHolder<AccountStatus> ENUMERATION_VALUES = new EnumerationValuesHolder<>( private static final ValueSet<AccountStatus> VALUE_SET = new ValueSet<>(
AVAILABLE, AVAILABLE,
LOCKED); LOCKED);
public static AccountStatus of(int value) { public static AccountStatus of(int id) {
return ENUMERATION_VALUES.get(value); return VALUE_SET.get(id);
}
@Nonnull
public static Collection<AccountStatus> constants() {
return VALUE_SET.getValues();
} }
} }

View File

@ -4,6 +4,7 @@ import java.util.Objects;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import cn.hutool.core.util.DesensitizedUtil; import cn.hutool.core.util.DesensitizedUtil;
import xyz.zhouxy.plusone.commons.annotation.StaticFactoryMethod;
import xyz.zhouxy.plusone.commons.constant.PatternConsts; 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) { public static Email of(String email) {
return new Email(email); return new Email(email);
} }
@StaticFactoryMethod(Email.class)
public static Email ofNullable(String email) { public static Email ofNullable(String email) {
return Objects.nonNull(email) ? new Email(email) : null; return Objects.nonNull(email) ? new Email(email) : null;
} }

View File

@ -4,6 +4,7 @@ import java.util.Objects;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import cn.hutool.core.util.DesensitizedUtil; import cn.hutool.core.util.DesensitizedUtil;
import xyz.zhouxy.plusone.commons.annotation.StaticFactoryMethod;
import xyz.zhouxy.plusone.commons.constant.PatternConsts; 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) { public static MobilePhone of(String mobilePhone) {
return new MobilePhone(mobilePhone); return new MobilePhone(mobilePhone);
} }
@StaticFactoryMethod(MobilePhone.class)
public static MobilePhone ofNullable(String mobilePhone) { public static MobilePhone ofNullable(String mobilePhone) {
return Objects.nonNull(mobilePhone) ? new MobilePhone(mobilePhone) : null; return Objects.nonNull(mobilePhone) ? new MobilePhone(mobilePhone) : null;
} }

View File

@ -3,6 +3,7 @@ package xyz.zhouxy.plusone.system.domain.model.account;
import java.util.Objects; import java.util.Objects;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import xyz.zhouxy.plusone.commons.annotation.StaticFactoryMethod;
import xyz.zhouxy.plusone.commons.constant.PatternConsts; import xyz.zhouxy.plusone.commons.constant.PatternConsts;
import xyz.zhouxy.plusone.domain.ValidatableStringRecord; import xyz.zhouxy.plusone.domain.ValidatableStringRecord;
@ -26,10 +27,12 @@ public class Nickname extends ValidatableStringRecord {
} }
} }
@StaticFactoryMethod(Nickname.class)
public static Nickname of(String nickname) { public static Nickname of(String nickname) {
return new Nickname(nickname); return new Nickname(nickname);
} }
@StaticFactoryMethod(Nickname.class)
public static Nickname ofNullable(String nickname) { public static Nickname ofNullable(String nickname) {
return Objects.nonNull(nickname) ? new Nickname(nickname) : null; return Objects.nonNull(nickname) ? new Nickname(nickname) : null;
} }

View File

@ -7,6 +7,7 @@ import javax.annotation.Nonnull;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import xyz.zhouxy.plusone.commons.annotation.StaticFactoryMethod;
import xyz.zhouxy.plusone.commons.constant.PatternConsts; import xyz.zhouxy.plusone.commons.constant.PatternConsts;
import xyz.zhouxy.plusone.constant.ErrorCodeConsts; import xyz.zhouxy.plusone.constant.ErrorCodeConsts;
import xyz.zhouxy.plusone.domain.IValueObject; import xyz.zhouxy.plusone.domain.IValueObject;
@ -51,15 +52,18 @@ public class Password implements IValueObject {
this.saltVal = salt; this.saltVal = salt;
} }
@StaticFactoryMethod(Password.class)
public static Password of(String password, String salt) { public static Password of(String password, String salt) {
return new Password(password, salt); return new Password(password, salt);
} }
@StaticFactoryMethod(Password.class)
public static Password newPassword(String newPassword, String passwordConfirmation) { public static Password newPassword(String newPassword, String passwordConfirmation) {
Assert.isTrue(Objects.equals(newPassword, passwordConfirmation), "两次输入的密码不一致"); Assert.isTrue(Objects.equals(newPassword, passwordConfirmation), "两次输入的密码不一致");
return newPassword(newPassword); return newPassword(newPassword);
} }
@StaticFactoryMethod(Password.class)
public static Password newPassword(String newPassword) { public static Password newPassword(String newPassword) {
return new Password(newPassword); return new Password(newPassword);
} }
@ -80,6 +84,7 @@ public class Password implements IValueObject {
return saltVal; return saltVal;
} }
@StaticFactoryMethod(Nickname.class)
public static Password newDefaultPassword() { public static Password newDefaultPassword() {
return newPassword(DEFAULT_PASSWORD); return newPassword(DEFAULT_PASSWORD);
} }

View File

@ -1,7 +1,10 @@
package xyz.zhouxy.plusone.system.domain.model.account; package xyz.zhouxy.plusone.system.domain.model.account;
import java.util.Collection;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import xyz.zhouxy.plusone.commons.annotation.StaticFactoryMethod;
import xyz.zhouxy.plusone.commons.util.Enumeration; import xyz.zhouxy.plusone.commons.util.Enumeration;
import xyz.zhouxy.plusone.domain.IValueObject; import xyz.zhouxy.plusone.domain.IValueObject;
@ -18,16 +21,20 @@ public final class Sex extends Enumeration<Sex> implements IValueObject {
@Nonnull @Nonnull
public static final Sex FEMALE = new Sex(2, "女性"); public static final Sex FEMALE = new Sex(2, "女性");
private Sex(int value, String name) { private Sex(int id, @Nonnull String name) {
super(value, name); super(id, name);
} }
private static EnumerationValuesHolder<Sex> values = new EnumerationValuesHolder<>( private static final ValueSet<Sex> VALUE_SET = new ValueSet<>(UNSET, MALE, FEMALE);
UNSET,
MALE,
FEMALE);
@Nonnull
@StaticFactoryMethod(Sex.class)
public static Sex of(int value) { public static Sex of(int value) {
return values.get(value); return VALUE_SET.get(value);
}
@Nonnull
public static Collection<Sex> constants() {
return VALUE_SET.getValues();
} }
} }

View File

@ -2,6 +2,7 @@ package xyz.zhouxy.plusone.system.domain.model.account;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import xyz.zhouxy.plusone.commons.annotation.StaticFactoryMethod;
import xyz.zhouxy.plusone.commons.constant.PatternConsts; 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) { public static Username of(String username) {
return new Username(username); return new Username(username);
} }

View File

@ -8,6 +8,7 @@ import java.util.Optional;
import java.util.Set; import java.util.Set;
import lombok.ToString; import lombok.ToString;
import xyz.zhouxy.plusone.commons.annotation.StaticFactoryMethod;
import xyz.zhouxy.plusone.domain.AggregateRoot; import xyz.zhouxy.plusone.domain.AggregateRoot;
import xyz.zhouxy.plusone.domain.IWithLabel; import xyz.zhouxy.plusone.domain.IWithLabel;
import xyz.zhouxy.plusone.domain.IWithVersion; import xyz.zhouxy.plusone.domain.IWithVersion;
@ -70,12 +71,14 @@ public class Dict extends AggregateRoot<Long> implements IWithLabel, IWithVersio
this.version = version; this.version = version;
} }
@StaticFactoryMethod(Dict.class)
public static Dict newInstance( public static Dict newInstance(
String dictType, String dictType,
String dictLabel) { String dictLabel) {
return new Dict(null, dictType, dictLabel, Collections.emptySet(), 0); return new Dict(null, dictType, dictLabel, Collections.emptySet(), 0);
} }
@StaticFactoryMethod(Dict.class)
public static Dict newInstance( public static Dict newInstance(
String dictType, String dictType,
String dictLabel, String dictLabel,
@ -83,6 +86,7 @@ public class Dict extends AggregateRoot<Long> implements IWithLabel, IWithVersio
return new Dict(null, dictType, dictLabel, values, 0); return new Dict(null, dictType, dictLabel, values, 0);
} }
@StaticFactoryMethod(Dict.class)
public static Dict newInstance( public static Dict newInstance(
String dictType, String dictType,
String dictLabel, String dictLabel,

View File

@ -4,6 +4,7 @@ import java.util.Objects;
import lombok.Getter; import lombok.Getter;
import lombok.ToString; import lombok.ToString;
import xyz.zhouxy.plusone.commons.annotation.StaticFactoryMethod;
import xyz.zhouxy.plusone.domain.IValueObject; import xyz.zhouxy.plusone.domain.IValueObject;
/** /**
@ -25,6 +26,7 @@ public class DictValue implements IValueObject {
this.label = label; this.label = label;
} }
@StaticFactoryMethod(DictValue.class)
public static DictValue of(int key, String label) { public static DictValue of(int key, String label) {
return new DictValue(key, label); return new DictValue(key, label);
} }

View File

@ -2,6 +2,7 @@ package xyz.zhouxy.plusone.system.domain.model.menu;
import java.util.List; import java.util.List;
import xyz.zhouxy.plusone.commons.annotation.StaticFactoryMethod;
import xyz.zhouxy.plusone.constant.EntityStatus; import xyz.zhouxy.plusone.constant.EntityStatus;
import xyz.zhouxy.plusone.system.domain.model.menu.Menu.MenuType; import xyz.zhouxy.plusone.system.domain.model.menu.Menu.MenuType;
@ -16,6 +17,7 @@ public class MenuConstructor {
throw new IllegalStateException("Utility class"); throw new IllegalStateException("Utility class");
} }
@StaticFactoryMethod(Menu.class)
public static Menu newMenuItem( public static Menu newMenuItem(
long parentId, long parentId,
String path, String path,
@ -39,6 +41,7 @@ public class MenuConstructor {
remarks, component, cache, resource, actions, 0L); remarks, component, cache, resource, actions, 0L);
} }
@StaticFactoryMethod(Menu.class)
public static Menu newMenuList( public static Menu newMenuList(
long parentId, long parentId,
String path, String path,

View File

@ -3,6 +3,7 @@ package xyz.zhouxy.plusone.system.domain.model.permission;
import java.util.Optional; import java.util.Optional;
import lombok.Getter; import lombok.Getter;
import xyz.zhouxy.plusone.commons.annotation.StaticFactoryMethod;
import xyz.zhouxy.plusone.domain.Entity; import xyz.zhouxy.plusone.domain.Entity;
import xyz.zhouxy.plusone.domain.IWithLabel; import xyz.zhouxy.plusone.domain.IWithLabel;
import xyz.zhouxy.plusone.domain.IWithVersion; import xyz.zhouxy.plusone.domain.IWithVersion;
@ -20,7 +21,7 @@ public class Action extends Entity<Long> implements IWithLabel, IWithVersion {
@Getter String label; @Getter String label;
@Getter long version; @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.id = id;
this.resource = resource; this.resource = resource;
this.identifier = identifier; this.identifier = identifier;
@ -28,10 +29,12 @@ public class Action extends Entity<Long> implements IWithLabel, IWithVersion {
this.version = version; this.version = version;
} }
@StaticFactoryMethod(Action.class)
static Action newInstance(String resource, String identifier, String label) { static Action newInstance(String resource, String identifier, String label) {
return new Action(null, resource, identifier, label, 0L); return new Action(null, resource, identifier, label, 0L);
} }
@StaticFactoryMethod(Action.class)
static Action existingInstance(Long id, String resource, String action, String label, Long version) { static Action existingInstance(Long id, String resource, String action, String label, Long version) {
return new Action(id, resource, action, label, version); return new Action(id, resource, action, label, version);
} }

View File

@ -6,6 +6,7 @@ import java.util.Objects;
import java.util.Optional; import java.util.Optional;
import lombok.Getter; import lombok.Getter;
import xyz.zhouxy.plusone.commons.annotation.StaticFactoryMethod;
import xyz.zhouxy.plusone.domain.AggregateRoot; import xyz.zhouxy.plusone.domain.AggregateRoot;
import xyz.zhouxy.plusone.domain.IWithVersion; import xyz.zhouxy.plusone.domain.IWithVersion;
@ -37,6 +38,7 @@ public class Permission extends AggregateRoot<Long> implements IWithVersion {
// ==================== 实例化 ==================== // ==================== 实例化 ====================
@StaticFactoryMethod(Permission.class)
public static Permission newInstance(String resource) { public static Permission newInstance(String resource) {
return new Permission( return new Permission(
null, resource, null, resource,

View File

@ -206,9 +206,9 @@ public class AccountRepositoryImpl extends JdbcRepositorySupport<Account, Long>
.addValue("password", entity.getPassword().value()) .addValue("password", entity.getPassword().value())
.addValue("salt", entity.getPassword().getSalt()) .addValue("salt", entity.getPassword().getSalt())
.addValue("avatar", accountInfo.getAvatar().toString()) .addValue("avatar", accountInfo.getAvatar().toString())
.addValue("sex", accountInfo.getSex().getValue()) .addValue("sex", accountInfo.getSex().getId())
.addValue("nickname", getValueOrNull(accountInfo.getNickname())) .addValue("nickname", getValueOrNull(accountInfo.getNickname()))
.addValue("status", entity.getStatus().getValue()) .addValue("status", entity.getStatus().getId())
.addValue("createdBy", entity.getCreatedBy()) .addValue("createdBy", entity.getCreatedBy())
.addValue("createTime", now) .addValue("createTime", now)
.addValue("updatedBy", entity.getUpdatedBy()) .addValue("updatedBy", entity.getUpdatedBy())

View File

@ -188,7 +188,7 @@ public class MenuRepositoryImpl extends JdbcRepositorySupport<Menu, Long> implem
.addValue("icon", entity.getIcon()) .addValue("icon", entity.getIcon())
.addValue("hidden", entity.isHidden()) .addValue("hidden", entity.isHidden())
.addValue("orderNumber", entity.getOrderNumber()) .addValue("orderNumber", entity.getOrderNumber())
.addValue("status", entity.getStatus().getValue()) .addValue("status", entity.getStatus().getId())
.addValue("remarks", entity.getRemarks()) .addValue("remarks", entity.getRemarks())
.addValue("component", entity.getComponent()) .addValue("component", entity.getComponent())
.addValue("cache", entity.getCache()) .addValue("cache", entity.getCache())

View File

@ -135,7 +135,7 @@ public class RoleRepositoryImpl extends JdbcRepositorySupport<Role, Long> implem
.addValue("id", id) .addValue("id", id)
.addValue("name", entity.getName()) .addValue("name", entity.getName())
.addValue("identifier", entity.getIdentifier()) .addValue("identifier", entity.getIdentifier())
.addValue("status", entity.getStatus().getValue()) .addValue("status", entity.getStatus().getId())
.addValue("remarks", entity.getRemarks()) .addValue("remarks", entity.getRemarks())
.addValue("createTime", now) .addValue("createTime", now)
.addValue("createdBy", loginId) .addValue("createdBy", loginId)