diff --git a/plusone-basic/plusone-basic-common/pom.xml b/plusone-basic/plusone-basic-common/pom.xml
index b476f10..3a1d54e 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.6-SNAPSHOT
+ 0.0.7-SNAPSHOT
diff --git a/plusone-basic/plusone-basic-common/src/main/java/xyz/zhouxy/plusone/util/RandomUtil.java b/plusone-basic/plusone-basic-common/src/main/java/xyz/zhouxy/plusone/util/RandomUtil.java
new file mode 100644
index 0000000..df9253d
--- /dev/null
+++ b/plusone-basic/plusone-basic-common/src/main/java/xyz/zhouxy/plusone/util/RandomUtil.java
@@ -0,0 +1,18 @@
+package xyz.zhouxy.plusone.util;
+
+import java.util.concurrent.ThreadLocalRandom;
+
+public final class RandomUtil {
+ private RandomUtil() {
+ throw new IllegalStateException("Utility class");
+ }
+
+ public static String randomStr(char[] sourceCharacters, int length) {
+ ThreadLocalRandom random = ThreadLocalRandom.current();
+ char[] result = new char[length];
+ for (int i = 0; i < length; i++) {
+ result[i] = sourceCharacters[random.nextInt(sourceCharacters.length)];
+ }
+ return String.valueOf(result);
+ }
+}
diff --git a/plusone-basic/plusone-basic-common/src/test/java/xyz/zhouxy/plusone/util/RandomUtilTests.java b/plusone-basic/plusone-basic-common/src/test/java/xyz/zhouxy/plusone/util/RandomUtilTests.java
new file mode 100644
index 0000000..ad3399b
--- /dev/null
+++ b/plusone-basic/plusone-basic-common/src/test/java/xyz/zhouxy/plusone/util/RandomUtilTests.java
@@ -0,0 +1,23 @@
+package xyz.zhouxy.plusone.util;
+
+import java.util.Arrays;
+
+import org.junit.jupiter.api.Test;
+
+import lombok.extern.slf4j.Slf4j;
+
+@Slf4j
+class RandomUtilTests {
+
+ @Test
+ void testRandom() {
+ String[] s = new String[20];
+ for (int i = 0; i < 20; i++) {
+ s[i] = RandomUtil.randomStr(
+ "0123456789qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM~`!@#$%^&*()_-+={[\\|/:;\"',.<>?]}"
+ .toCharArray(),
+ 28);
+ }
+ log.info("{}", Arrays.toString(s));
+ }
+}
diff --git a/plusone-basic/plusone-basic-domain/pom.xml b/plusone-basic/plusone-basic-domain/pom.xml
index ca01461..107fd4d 100644
--- a/plusone-basic/plusone-basic-domain/pom.xml
+++ b/plusone-basic/plusone-basic-domain/pom.xml
@@ -15,11 +15,6 @@
xyz.zhouxy
-
- cn.hutool
- hutool-core
-
-
org.projectlombok
lombok
@@ -28,12 +23,10 @@
com.fasterxml.jackson.core
jackson-core
- 2.13.4
com.fasterxml.jackson.core
jackson-annotations
- 2.13.4
-
+
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 77c9e19..d8d3501 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
@@ -7,7 +7,7 @@ import xyz.zhouxy.plusone.commons.util.Enumeration;
*
* @author ZhouXY
*/
-public class EntityStatus extends Enumeration {
+public final class EntityStatus extends Enumeration {
private EntityStatus(int value, String name) {
super(value, name);
diff --git a/plusone-basic/plusone-basic-domain/src/main/java/xyz/zhouxy/plusone/constant/RegexConsts.java b/plusone-basic/plusone-basic-domain/src/main/java/xyz/zhouxy/plusone/constant/RegexConsts.java
deleted file mode 100644
index a34c436..0000000
--- a/plusone-basic/plusone-basic-domain/src/main/java/xyz/zhouxy/plusone/constant/RegexConsts.java
+++ /dev/null
@@ -1,27 +0,0 @@
-package xyz.zhouxy.plusone.constant;
-
-/**
- * 正则表达式常量
- *
- * @author ZhouXY
- */
-public final class RegexConsts {
-
- public static final String DATE = "^\\d{4}-\\d{2}-\\d{2}";
-
- public static final String PASSWORD = "^(?=.*\\d)(?=.*[a-z])(?=.*[A-Z])[\\w\\\\!#$%&'*\\+\\-/=?^`{|}~@\\(\\)\\[\\]\",\\.;':><]{8,32}$";
-
- public static final String CAPTCHA = "^[0-9A-Za-z]{4,6}$";
-
- public static final String EMAIL = "^\\w+([-+.]\\w+)*@[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(\\.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})*(\\.(?![0-9]+$)[a-zA-Z0-9][-0-9A-Za-z]{0,62})$";
-
- public static final String MOBILE_PHONE = "^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\\d{8}$";
-
- public static final String USERNAME = "^[\\da-zA-Z_.@\\\\]{4,36}$";
-
- public static final String NICKNAME = "^[\\da-zA-Z_.@\\\\]{4,36}$";
-
- private RegexConsts() {
- throw new IllegalStateException("Utility class");
- }
-}
diff --git a/plusone-basic/plusone-basic-domain/src/main/java/xyz/zhouxy/plusone/domain/DomainEvent.java b/plusone-basic/plusone-basic-domain/src/main/java/xyz/zhouxy/plusone/domain/DomainEvent.java
index 34acdda..3cbb914 100644
--- a/plusone-basic/plusone-basic-domain/src/main/java/xyz/zhouxy/plusone/domain/DomainEvent.java
+++ b/plusone-basic/plusone-basic-domain/src/main/java/xyz/zhouxy/plusone/domain/DomainEvent.java
@@ -1,6 +1,7 @@
package xyz.zhouxy.plusone.domain;
-import cn.hutool.core.lang.UUID;
+import java.util.UUID;
+
import lombok.Getter;
/**
@@ -20,7 +21,7 @@ public abstract class DomainEvent {
private long happenedAt;
protected DomainEvent() {
- this.identifier = UUID.randomUUID().toString(true);
+ this.identifier = UUID.randomUUID().toString();
this.happenedAt = System.currentTimeMillis();
}
}
diff --git a/plusone-basic/plusone-basic-domain/src/main/java/xyz/zhouxy/plusone/domain/ValidatableStringRecord.java b/plusone-basic/plusone-basic-domain/src/main/java/xyz/zhouxy/plusone/domain/ValidatableStringRecord.java
index a44c675..0a03e65 100644
--- a/plusone-basic/plusone-basic-domain/src/main/java/xyz/zhouxy/plusone/domain/ValidatableStringRecord.java
+++ b/plusone-basic/plusone-basic-domain/src/main/java/xyz/zhouxy/plusone/domain/ValidatableStringRecord.java
@@ -1,6 +1,7 @@
package xyz.zhouxy.plusone.domain;
import java.util.Optional;
+import java.util.regex.Pattern;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonValue;
@@ -13,15 +14,15 @@ import com.fasterxml.jackson.annotation.JsonValue;
public abstract class ValidatableStringRecord implements IValueObject {
protected String value;
- protected final String format;
+ protected final Pattern format;
- protected ValidatableStringRecord(String format) {
+ protected ValidatableStringRecord(Pattern format) {
this.format = format;
}
@JsonIgnore
protected boolean isValid() {
- return value.matches(format);
+ return format.matcher(value).matches();
}
@JsonValue
@@ -35,6 +36,6 @@ public abstract class ValidatableStringRecord implements IValueObject {
}
public static String getValueOrNull(Optional extends ValidatableStringRecord> s) {
- return s.map(ValidatableStringRecord::value).orElse(null);
+ return s.isPresent() ? s.get().value() : null;
}
}
diff --git a/plusone-basic/plusone-basic-infrastructure/src/main/java/xyz/zhouxy/plusone/jdbc/PlusoneJdbcDaoSupport.java b/plusone-basic/plusone-basic-infrastructure/src/main/java/xyz/zhouxy/plusone/jdbc/PlusoneJdbcDaoSupport.java
index ff90f2f..c190e7d 100644
--- a/plusone-basic/plusone-basic-infrastructure/src/main/java/xyz/zhouxy/plusone/jdbc/PlusoneJdbcDaoSupport.java
+++ b/plusone-basic/plusone-basic-infrastructure/src/main/java/xyz/zhouxy/plusone/jdbc/PlusoneJdbcDaoSupport.java
@@ -14,6 +14,7 @@ import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
+import org.springframework.util.CollectionUtils;
import xyz.zhouxy.plusone.commons.util.NumberUtil;
import xyz.zhouxy.plusone.exception.DataOperationResultException;
@@ -68,13 +69,13 @@ public abstract class PlusoneJdbcDaoSupport {
return queryForStream(sql, new MapSqlParameterSource(paramName, value), elementType);
}
- protected final boolean queryExists(String sql, SqlParameterSource parameterSource) {
- Boolean isExists = this.jdbc.queryForObject(sql, parameterSource, Boolean.TYPE);
- return Boolean.TRUE.equals(isExists);
+ protected final boolean queryForBool(String sql, SqlParameterSource parameterSource) {
+ Boolean result = this.jdbc.queryForObject(sql, parameterSource, Boolean.TYPE);
+ return Boolean.TRUE.equals(result);
}
- protected final boolean queryExists(String sql, String paramName, Object value) {
- return queryExists(sql, new MapSqlParameterSource(paramName, value));
+ protected final boolean queryForBool(String sql, String paramName, Object value) {
+ return queryForBool(sql, new MapSqlParameterSource(paramName, value));
}
protected final int update(String sql, SqlParameterSource parameterSource) {
@@ -85,18 +86,18 @@ public abstract class PlusoneJdbcDaoSupport {
return update(sql, new MapSqlParameterSource(paramName, value));
}
- protected final int batchUpdate(String sql, SqlParameterSource[] batchArgs) {
+ protected final long batchUpdate(String sql, SqlParameterSource[] batchArgs) {
int[] i = this.jdbc.batchUpdate(sql, batchArgs);
return NumberUtil.sum(i);
}
- protected final int batchUpdate(String sql, Stream c,
+ protected final long batchUpdate(String sql, Stream c,
@Nonnull Function paramSourceBuilder) {
int[] i = this.jdbc.batchUpdate(sql, buildSqlParameterSourceArray(c, paramSourceBuilder));
return NumberUtil.sum(i);
}
- protected final int batchUpdate(String sql, Collection c,
+ protected final long batchUpdate(String sql, Collection c,
@Nonnull Function paramSourceBuilder) {
int[] i = this.jdbc.batchUpdate(sql, buildSqlParameterSourceArray(c, paramSourceBuilder));
return NumberUtil.sum(i);
@@ -156,7 +157,7 @@ public abstract class PlusoneJdbcDaoSupport {
protected static final SqlParameterSource[] buildSqlParameterSourceArray(
Collection c,
@Nonnull Function paramSourceBuilder) {
- if (c == null || c.isEmpty()) {
+ if (CollectionUtils.isEmpty(c)) {
return new SqlParameterSource[] {};
}
return buildSqlParameterSourceArray(c.stream(), paramSourceBuilder);
diff --git a/plusone-basic/plusone-basic-infrastructure/src/main/java/xyz/zhouxy/plusone/oss/FastDFSException.java b/plusone-basic/plusone-basic-infrastructure/src/main/java/xyz/zhouxy/plusone/oss/FastDFSException.java
index a34cd35..88f4c13 100644
--- a/plusone-basic/plusone-basic-infrastructure/src/main/java/xyz/zhouxy/plusone/oss/FastDFSException.java
+++ b/plusone-basic/plusone-basic-infrastructure/src/main/java/xyz/zhouxy/plusone/oss/FastDFSException.java
@@ -6,6 +6,7 @@ package xyz.zhouxy.plusone.oss;
* @author ZhouXY
*/
public class FastDFSException extends Exception {
+ private static final long serialVersionUID = 7871031982887742468L;
public FastDFSException() {
}
diff --git a/plusone-basic/pom.xml b/plusone-basic/pom.xml
index 6072631..26d7e80 100644
--- a/plusone-basic/pom.xml
+++ b/plusone-basic/pom.xml
@@ -7,9 +7,7 @@
1.0.0-SNAPSHOT
- xyz.zhouxy
plusone-basic
- 1.0.0-SNAPSHOT
pom
diff --git a/plusone-start/pom.xml b/plusone-start/pom.xml
index 56478b1..99950e8 100644
--- a/plusone-start/pom.xml
+++ b/plusone-start/pom.xml
@@ -7,10 +7,7 @@
1.0.0-SNAPSHOT
- xyz.zhouxy
plusone-start
- 1.0.0-SNAPSHOT
-
plusone-start
参考 DDD 落地的脚手架
diff --git a/plusone-start/src/test/java/xyz/zhouxy/plusone/TestAop.java b/plusone-start/src/test/java/xyz/zhouxy/plusone/TestAop.java
index 12a2322..73df511 100644
--- a/plusone-start/src/test/java/xyz/zhouxy/plusone/TestAop.java
+++ b/plusone-start/src/test/java/xyz/zhouxy/plusone/TestAop.java
@@ -1,5 +1,7 @@
package xyz.zhouxy.plusone;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
import javax.annotation.Resource;
import org.junit.jupiter.api.Test;
@@ -25,6 +27,7 @@ class TestAop {
command.setPrincipal("Code108");
command.setPassword("2333");
command.setRememberMe(false);
+ assertNotNull(service);
LoginInfoViewObject loginInfo = service.loginByPassword(command);
System.err.println(loginInfo);
}
diff --git a/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/common/exception/UnsupportedPrincipalTypeException.java b/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/common/exception/UnsupportedPrincipalTypeException.java
index de90bae..a71d443 100644
--- a/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/common/exception/UnsupportedPrincipalTypeException.java
+++ b/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/common/exception/UnsupportedPrincipalTypeException.java
@@ -9,10 +9,13 @@ import xyz.zhouxy.plusone.exception.BizException;
*/
public class UnsupportedPrincipalTypeException extends BizException {
+ private static final long serialVersionUID = 5207757290868470762L;
+
public static final int ERR_CODE = 4040201;
+ private static final String DEFAULT_ERROR_MSG = "不支持的 PrincipalType";
public UnsupportedPrincipalTypeException() {
- super(ERR_CODE, "不支持的 PrincipalType");
+ super(ERR_CODE, DEFAULT_ERROR_MSG);
}
public UnsupportedPrincipalTypeException(String msg) {
diff --git a/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/common/util/PrincipalType.java b/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/common/util/PrincipalType.java
index 14022c7..5db3ded 100644
--- a/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/common/util/PrincipalType.java
+++ b/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/common/util/PrincipalType.java
@@ -1,18 +1,20 @@
package xyz.zhouxy.plusone.system.application.common.util;
+import java.util.regex.Pattern;
+
import lombok.Getter;
-import xyz.zhouxy.plusone.constant.RegexConsts;
+import xyz.zhouxy.plusone.commons.constant.PatternConsts;
public enum PrincipalType {
- EMAIL(RegexConsts.EMAIL),
- MOBILE_PHONE(RegexConsts.MOBILE_PHONE),
- USERNAME(RegexConsts.USERNAME)
+ EMAIL(PatternConsts.EMAIL),
+ MOBILE_PHONE(PatternConsts.MOBILE_PHONE),
+ USERNAME(PatternConsts.USERNAME)
;
@Getter
- private final String regex;
+ private final Pattern regex;
- PrincipalType(String regex) {
+ PrincipalType(Pattern regex) {
this.regex = regex;
}
}
diff --git a/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/common/util/PrincipalUtil.java b/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/common/util/PrincipalUtil.java
index 96d3715..fef5125 100644
--- a/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/common/util/PrincipalUtil.java
+++ b/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/common/util/PrincipalUtil.java
@@ -30,7 +30,7 @@ public class PrincipalUtil {
}
PrincipalType[] principalTypes = PrincipalType.values();
for (var principalType : principalTypes) {
- if (principal.matches(principalType.getRegex())) {
+ if (principalType.getRegex().matcher(principal).matches()) {
return principalType;
}
}
diff --git a/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/service/AccountManagementService.java b/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/service/AccountManagementService.java
index 0eab48b..d53a1ba 100644
--- a/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/service/AccountManagementService.java
+++ b/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/service/AccountManagementService.java
@@ -26,8 +26,10 @@ import xyz.zhouxy.plusone.system.application.service.command.UpdateAccountComman
import xyz.zhouxy.plusone.system.domain.model.account.Account;
import xyz.zhouxy.plusone.system.domain.model.account.AccountInfo;
import xyz.zhouxy.plusone.system.domain.model.account.AccountRepository;
+import xyz.zhouxy.plusone.system.domain.model.account.AccountStatus;
import xyz.zhouxy.plusone.system.domain.model.account.Email;
import xyz.zhouxy.plusone.system.domain.model.account.MobilePhone;
+import xyz.zhouxy.plusone.system.domain.model.account.Sex;
import xyz.zhouxy.plusone.system.domain.model.account.Username;
import xyz.zhouxy.plusone.util.AssertResult;
@@ -67,9 +69,13 @@ public class AccountManagementService {
mobilePhone,
command.getPassword(),
command.getPasswordConfirmation(),
- command.getStatus(),
+ AccountStatus.of(command.getStatus()),
command.getRoleRefs(),
- AccountInfo.of(command.getNickname(), command.getAvatar(), command.getSex()),
+ AccountInfo.builder()
+ .nickname(command.getNickname())
+ .avatar(command.getAvatar())
+ .sex(Sex.of(command.getSex()))
+ .build(),
adminAuthLogic.getLoginIdAsLong());
accountRepository.save(account);
}
@@ -87,7 +93,7 @@ public class AccountManagementService {
Assert.isTrue(Objects.equals(id, command.getId()), "参数错误: id 不匹配");
Account account = accountRepository.find(id)
.orElseThrow(() -> new DataNotExistException("该账号不存在"));
- account.setAccountInfo(command.getNickname(), command.getAvatar(), command.getSex());
+ account.setAccountInfo(command.getNickname(), command.getAvatar(), Sex.of(command.getSex()));
account.setUpdatedBy(adminAuthLogic.getLoginIdAsLong());
accountRepository.save(account);
}
diff --git a/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/service/MenuManagementService.java b/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/service/MenuManagementService.java
index f7e5368..b8b07d4 100644
--- a/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/service/MenuManagementService.java
+++ b/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/service/MenuManagementService.java
@@ -13,6 +13,7 @@ import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;
+import xyz.zhouxy.plusone.constant.EntityStatus;
import xyz.zhouxy.plusone.domain.IWithOrderNumber;
import xyz.zhouxy.plusone.exception.DataNotExistException;
import xyz.zhouxy.plusone.system.application.exception.UnsupportedMenuTypeException;
@@ -66,7 +67,7 @@ public class MenuManagementService {
command.getIcon(),
command.getHidden(),
command.getOrderNumber(),
- command.getStatus(),
+ EntityStatus.of(command.getStatus()),
command.getRemarks());
}
@@ -79,7 +80,7 @@ public class MenuManagementService {
command.getIcon(),
command.getHidden(),
command.getOrderNumber(),
- command.getStatus(),
+ EntityStatus.of(command.getStatus()),
command.getComponent(),
command.getResource(),
command.getCache(),
@@ -107,7 +108,7 @@ public class MenuManagementService {
command.getIcon(),
command.getHidden(),
command.getOrderNumber(),
- command.getStatus(),
+ EntityStatus.of(command.getStatus()),
command.getComponent(),
command.getResource(),
command.getCache(),
diff --git a/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/service/RegisterAccountService.java b/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/service/RegisterAccountService.java
index cfc3116..c81a49c 100644
--- a/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/service/RegisterAccountService.java
+++ b/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/service/RegisterAccountService.java
@@ -17,7 +17,6 @@ import xyz.zhouxy.plusone.system.domain.model.account.AccountStatus;
import xyz.zhouxy.plusone.system.domain.model.account.Email;
import xyz.zhouxy.plusone.system.domain.model.account.MobilePhone;
import xyz.zhouxy.plusone.system.domain.model.account.Password;
-import xyz.zhouxy.plusone.system.domain.model.account.Sex;
import xyz.zhouxy.plusone.system.domain.model.account.Username;
/**
@@ -82,7 +81,9 @@ public class RegisterAccountService {
Password.newPassword(command.getPassword(), command.getReenteredPassword()),
AccountStatus.AVAILABLE,
Set.of(DEFAULT_ROLE_ID),
- AccountInfo.of(command.getNickname(), null, Sex.UNSET));
+ AccountInfo.builder()
+ .nickname(command.getNickname())
+ .build());
accountRepository.save(accountToSave);
}
diff --git a/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/service/RoleManagementService.java b/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/service/RoleManagementService.java
index 9d88826..75fb2c9 100644
--- a/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/service/RoleManagementService.java
+++ b/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/service/RoleManagementService.java
@@ -10,6 +10,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
+import xyz.zhouxy.plusone.constant.EntityStatus;
import xyz.zhouxy.plusone.exception.DataNotExistException;
import xyz.zhouxy.plusone.system.application.query.RoleQueries;
import xyz.zhouxy.plusone.system.application.query.params.RoleQueryParams;
@@ -54,7 +55,7 @@ public class RoleManagementService {
Role roleToCreate = Role.newInstance(
command.getName(),
command.getIdentifier(),
- command.getStatus(),
+ EntityStatus.of(command.getStatus()),
command.getRemarks(),
menuRefs,
permissionRefs);
@@ -67,7 +68,7 @@ public class RoleManagementService {
roleToUpdate.update(
command.getName(),
command.getIdentifier(),
- command.getStatus(),
+ EntityStatus.of(command.getStatus()),
command.getRemarks(),
Set.copyOf(_menuRepository.findByIdIn(command.getMenus())),
Set.copyOf(_menuRepository.findPermissionsByIdIn(command.getPermissions())));
diff --git a/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/service/command/CreateAccountCommand.java b/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/service/command/CreateAccountCommand.java
index c2b09d6..51c07cf 100644
--- a/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/service/command/CreateAccountCommand.java
+++ b/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/service/command/CreateAccountCommand.java
@@ -10,10 +10,8 @@ import javax.validation.constraints.Pattern;
import org.hibernate.validator.constraints.URL;
import lombok.Data;
-import xyz.zhouxy.plusone.constant.RegexConsts;
+import xyz.zhouxy.plusone.commons.constant.RegexConsts;
import xyz.zhouxy.plusone.domain.ICommand;
-import xyz.zhouxy.plusone.system.domain.model.account.AccountStatus;
-import xyz.zhouxy.plusone.system.domain.model.account.Sex;
/**
* 创建账号命令
@@ -41,7 +39,7 @@ public class CreateAccountCommand implements ICommand {
String passwordConfirmation;
@NotNull
- AccountStatus status;
+ Integer status;
Set roleRefs;
@@ -52,5 +50,5 @@ public class CreateAccountCommand implements ICommand {
@URL
String avatar;
- Sex sex;
+ Integer sex;
}
diff --git a/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/service/command/CreateMenuCommand.java b/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/service/command/CreateMenuCommand.java
index d319517..eeb469a 100644
--- a/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/service/command/CreateMenuCommand.java
+++ b/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/service/command/CreateMenuCommand.java
@@ -5,7 +5,6 @@ import javax.validation.constraints.NotNull;
import lombok.Getter;
import lombok.Setter;
-import xyz.zhouxy.plusone.constant.EntityStatus;
import xyz.zhouxy.plusone.domain.ICommand;
import xyz.zhouxy.plusone.system.domain.model.menu.Menu.MenuType;
@@ -42,7 +41,7 @@ public class CreateMenuCommand implements ICommand {
private Integer orderNumber;
@NotNull
- private EntityStatus status;
+ private Integer status;
private String component;
diff --git a/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/service/command/CreateRoleCommand.java b/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/service/command/CreateRoleCommand.java
index b0fd176..b9408b8 100644
--- a/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/service/command/CreateRoleCommand.java
+++ b/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/service/command/CreateRoleCommand.java
@@ -6,7 +6,6 @@ import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import lombok.Data;
-import xyz.zhouxy.plusone.constant.EntityStatus;
import xyz.zhouxy.plusone.domain.ICommand;
/**
@@ -23,7 +22,7 @@ public class CreateRoleCommand implements ICommand {
String identifier;
@NotNull
- EntityStatus status;
+ Integer status;
String remarks;
Set menus;
diff --git a/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/service/command/RegisterAccountCommand.java b/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/service/command/RegisterAccountCommand.java
index 266016b..0a4409a 100644
--- a/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/service/command/RegisterAccountCommand.java
+++ b/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/service/command/RegisterAccountCommand.java
@@ -4,7 +4,7 @@ import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Pattern;
import lombok.Data;
-import xyz.zhouxy.plusone.constant.RegexConsts;
+import xyz.zhouxy.plusone.commons.constant.RegexConsts;
import xyz.zhouxy.plusone.domain.ICommand;
/**
diff --git a/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/service/command/UpdateAccountCommand.java b/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/service/command/UpdateAccountCommand.java
index e45750c..1e5ae31 100644
--- a/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/service/command/UpdateAccountCommand.java
+++ b/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/service/command/UpdateAccountCommand.java
@@ -6,9 +6,8 @@ import javax.validation.constraints.Pattern;
import org.hibernate.validator.constraints.URL;
import lombok.Data;
-import xyz.zhouxy.plusone.constant.RegexConsts;
+import xyz.zhouxy.plusone.commons.constant.RegexConsts;
import xyz.zhouxy.plusone.domain.ICommand;
-import xyz.zhouxy.plusone.system.domain.model.account.Sex;
/**
* 更新账号信息命令
@@ -27,5 +26,5 @@ public class UpdateAccountCommand implements ICommand {
@URL
String avatar;
- Sex sex;
+ Integer sex;
}
diff --git a/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/service/command/UpdateMenuCommand.java b/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/service/command/UpdateMenuCommand.java
index 2055d75..04d1d23 100644
--- a/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/service/command/UpdateMenuCommand.java
+++ b/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/service/command/UpdateMenuCommand.java
@@ -5,7 +5,6 @@ import javax.validation.constraints.NotNull;
import lombok.Getter;
import lombok.Setter;
-import xyz.zhouxy.plusone.constant.EntityStatus;
import xyz.zhouxy.plusone.domain.ICommand;
import xyz.zhouxy.plusone.system.domain.model.menu.Menu.MenuType;
@@ -46,7 +45,7 @@ public class UpdateMenuCommand implements ICommand {
private Integer orderNumber;
@NotNull
- private EntityStatus status;
+ private Integer status;
private String component;
diff --git a/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/service/command/UpdateRoleCommand.java b/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/service/command/UpdateRoleCommand.java
index 1f267d0..4a59be9 100644
--- a/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/service/command/UpdateRoleCommand.java
+++ b/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/service/command/UpdateRoleCommand.java
@@ -6,7 +6,6 @@ import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import lombok.Data;
-import xyz.zhouxy.plusone.constant.EntityStatus;
import xyz.zhouxy.plusone.domain.ICommand;
/**
@@ -27,7 +26,7 @@ public class UpdateRoleCommand implements ICommand {
String identifier;
@NotNull
- EntityStatus status;
+ Integer status;
@NotBlank
String remarks;
diff --git a/plusone-system/plusone-system-common/pom.xml b/plusone-system/plusone-system-common/pom.xml
index e95bfee..f749873 100644
--- a/plusone-system/plusone-system-common/pom.xml
+++ b/plusone-system/plusone-system-common/pom.xml
@@ -14,10 +14,6 @@
xyz.zhouxy
plusone-basic-common
-
- cn.hutool
- hutool-crypto
-
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 e377ca7..015a5f6 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
@@ -1,19 +1,26 @@
package xyz.zhouxy.plusone.system.util;
+import java.math.BigInteger;
+import java.nio.charset.StandardCharsets;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+
import javax.annotation.Nonnull;
-import cn.hutool.core.util.RandomUtil;
-import cn.hutool.crypto.digest.DigestUtil;
+import lombok.extern.slf4j.Slf4j;
import xyz.zhouxy.plusone.constant.ErrorCodeConsts;
import xyz.zhouxy.plusone.exception.BizException;
+import xyz.zhouxy.plusone.util.RandomUtil;
/**
* 密码工具类
*
* @author ZhouXY
*/
+@Slf4j
public final class PasswordUtil {
- private static final String SALT_BASE_STRING = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ~`!@#$%^&*()_-+={}[]|\\:;\"',.<>?/";
+ private static final char[] SALT_BASE_CHAR_ARRAY = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ~`!@#$%^&*()_-+={}[]|\\:;\"',.<>?/"
+ .toCharArray();
/**
* 将密码和随机盐混合,并进行哈希加密。
@@ -29,7 +36,7 @@ public final class PasswordUtil {
var passwordWithSalt = salt.substring(0, i)
+ password
+ salt.substring(1);
- String sha512Hex = DigestUtil.sha512Hex(passwordWithSalt);
+ String sha512Hex = sha512Hex(passwordWithSalt);
if (sha512Hex == null) {
throw new BizException(ErrorCodeConsts.DEFAULT_ERROR_CODE, "未知错误:哈希加密失败!");
}
@@ -42,11 +49,23 @@ public final class PasswordUtil {
* @return 生成的随机盐
*/
public static String generateRandomSalt() {
- return RandomUtil.randomString(SALT_BASE_STRING, 24);
+ return RandomUtil.randomStr(SALT_BASE_CHAR_ARRAY, 24);
}
private 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;
+ }
}
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 895eda3..3150b64 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
@@ -93,11 +93,19 @@ public class Account extends AggregateRoot implements IWithVersion {
}
public void setAccountInfo(Nickname nickname, URL avatar, Sex sex) {
- this.accountInfo = AccountInfo.of(nickname, avatar, sex);
+ this.accountInfo = AccountInfo.builder()
+ .nickname(nickname)
+ .avatar(avatar)
+ .sex(sex)
+ .build();
}
public void setAccountInfo(String nickname, String avatar, Sex sex) {
- this.accountInfo = AccountInfo.of(nickname, avatar, sex);
+ this.accountInfo = AccountInfo.builder()
+ .nickname(nickname)
+ .avatar(avatar)
+ .sex(sex)
+ .build();
}
/**
diff --git a/plusone-system/plusone-system-domain/src/main/java/xyz/zhouxy/plusone/system/domain/model/account/AccountInfo.java b/plusone-system/plusone-system-domain/src/main/java/xyz/zhouxy/plusone/system/domain/model/account/AccountInfo.java
index 6b9aa87..7e750d0 100644
--- a/plusone-system/plusone-system-domain/src/main/java/xyz/zhouxy/plusone/system/domain/model/account/AccountInfo.java
+++ b/plusone-system/plusone-system-domain/src/main/java/xyz/zhouxy/plusone/system/domain/model/account/AccountInfo.java
@@ -5,7 +5,9 @@ import java.net.URL;
import java.util.Objects;
import java.util.Optional;
-import lombok.Getter;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
import lombok.ToString;
import xyz.zhouxy.plusone.domain.IValueObject;
@@ -17,30 +19,19 @@ import xyz.zhouxy.plusone.domain.IValueObject;
@ToString
public class AccountInfo implements IValueObject {
+ @Nullable
private final Nickname nickname;
+ @Nullable
private final URL avatar;
- private final @Getter Sex sex;
+ @Nonnull
+ private final Sex sex;
- private AccountInfo(Nickname nickname, URL avatar, Sex sex) {
+ private AccountInfo(@Nullable Nickname nickname, @Nullable URL avatar, @Nullable Sex sex) {
this.nickname = nickname;
this.avatar = avatar;
this.sex = Objects.nonNull(sex) ? sex : Sex.UNSET;
}
- public static AccountInfo of(Nickname nickname, URL avatar, Sex sex) {
- return new AccountInfo(nickname, avatar, sex);
- }
-
- public static AccountInfo of(String nickname, String avatar, Sex sex) {
- URL avatarURL;
- try {
- avatarURL = Objects.nonNull(avatar) ? new URL(avatar) : null;
- } catch (MalformedURLException e) {
- throw new IllegalArgumentException(e);
- }
- return new AccountInfo(Nickname.ofNullable(nickname), avatarURL, sex);
- }
-
public Optional getNickname() {
return Optional.ofNullable(nickname);
}
@@ -48,4 +39,54 @@ public class AccountInfo implements IValueObject {
public Optional getAvatar() {
return Optional.ofNullable(avatar);
}
+
+ @Nonnull
+ public Sex getSex() {
+ return this.sex;
+ }
+
+ // Builder
+
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ public static class Builder {
+ private Nickname nickname;
+ private URL avatar;
+ private Sex sex;
+
+ public Builder nickname(@Nullable Nickname nickname) {
+ this.nickname = nickname;
+ return this;
+ }
+
+ public Builder nickname(@Nullable String nickname) {
+ return nickname(Nickname.ofNullable(nickname));
+ }
+
+ public Builder avatar(@Nullable URL avatar) {
+ this.avatar = avatar;
+ return this;
+ }
+
+ public Builder avatar(@Nullable String avatar) {
+ URL avatarURL;
+ try {
+ avatarURL = Objects.nonNull(avatar) ? new URL(avatar) : null;
+ } catch (MalformedURLException e) {
+ throw new IllegalArgumentException(e);
+ }
+ return avatar(avatarURL);
+ }
+
+ public Builder sex(@Nullable Sex sex) {
+ this.sex = sex;
+ return this;
+ }
+
+ public AccountInfo build() {
+ return new AccountInfo(this.nickname, this.avatar, this.sex);
+ }
+ }
}
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 4ee846d..f49ad82 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
@@ -10,7 +10,7 @@ import xyz.zhouxy.plusone.domain.IValueObject;
* @author ZhouXY
*/
@Getter
-public class AccountStatus extends Enumeration implements IValueObject {
+public final class AccountStatus extends Enumeration implements IValueObject {
private AccountStatus(int value, String name) {
super(value, name);
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 f09d3b7..fe12230 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
@@ -1,9 +1,10 @@
package xyz.zhouxy.plusone.system.domain.model.account;
import java.util.Objects;
+import java.util.regex.Pattern;
import cn.hutool.core.util.DesensitizedUtil;
-import xyz.zhouxy.plusone.constant.RegexConsts;
+import xyz.zhouxy.plusone.commons.constant.PatternConsts;
/**
* 值对象:电子邮箱地址
@@ -12,7 +13,7 @@ import xyz.zhouxy.plusone.constant.RegexConsts;
*/
public class Email extends Principal {
- public static final String REGEX = RegexConsts.EMAIL;
+ public static final Pattern REGEX = PatternConsts.EMAIL;
private Email(String email) {
super(REGEX);
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 ebf5b2e..c641536 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
@@ -1,9 +1,10 @@
package xyz.zhouxy.plusone.system.domain.model.account;
import java.util.Objects;
+import java.util.regex.Pattern;
import cn.hutool.core.util.DesensitizedUtil;
-import xyz.zhouxy.plusone.constant.RegexConsts;
+import xyz.zhouxy.plusone.commons.constant.PatternConsts;
/**
* 值对象:手机号码
@@ -12,7 +13,7 @@ import xyz.zhouxy.plusone.constant.RegexConsts;
*/
public class MobilePhone extends Principal {
- public static final String REGEX = RegexConsts.MOBILE_PHONE;
+ public static final Pattern REGEX = PatternConsts.MOBILE_PHONE;
private MobilePhone(String mobilePhone) {
super(REGEX);
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 7fcd33a..0d09911 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
@@ -1,8 +1,9 @@
package xyz.zhouxy.plusone.system.domain.model.account;
import java.util.Objects;
+import java.util.regex.Pattern;
-import xyz.zhouxy.plusone.constant.RegexConsts;
+import xyz.zhouxy.plusone.commons.constant.PatternConsts;
import xyz.zhouxy.plusone.domain.ValidatableStringRecord;
/**
@@ -12,7 +13,7 @@ import xyz.zhouxy.plusone.domain.ValidatableStringRecord;
*/
public class Nickname extends ValidatableStringRecord {
- public static final String REGEX = RegexConsts.NICKNAME;
+ public static final Pattern REGEX = PatternConsts.NICKNAME;
private Nickname(String value) {
super(REGEX);
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 2e1b7bd..d810c58 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,8 +7,8 @@ import javax.annotation.Nonnull;
import org.springframework.util.Assert;
+import xyz.zhouxy.plusone.commons.constant.PatternConsts;
import xyz.zhouxy.plusone.constant.ErrorCodeConsts;
-import xyz.zhouxy.plusone.constant.RegexConsts;
import xyz.zhouxy.plusone.domain.IValueObject;
import xyz.zhouxy.plusone.exception.BizException;
import xyz.zhouxy.plusone.system.util.PasswordUtil;
@@ -20,7 +20,7 @@ import xyz.zhouxy.plusone.system.util.PasswordUtil;
*/
public class Password implements IValueObject {
- private static final Pattern PATTERN = Pattern.compile(RegexConsts.PASSWORD);
+ private static final Pattern PATTERN = PatternConsts.PASSWORD;
private static final String DEFAULT_PASSWORD = "A1b2C3d4";
@Nonnull
diff --git a/plusone-system/plusone-system-domain/src/main/java/xyz/zhouxy/plusone/system/domain/model/account/Principal.java b/plusone-system/plusone-system-domain/src/main/java/xyz/zhouxy/plusone/system/domain/model/account/Principal.java
index b622630..c4a4701 100644
--- a/plusone-system/plusone-system-domain/src/main/java/xyz/zhouxy/plusone/system/domain/model/account/Principal.java
+++ b/plusone-system/plusone-system-domain/src/main/java/xyz/zhouxy/plusone/system/domain/model/account/Principal.java
@@ -1,5 +1,7 @@
package xyz.zhouxy.plusone.system.domain.model.account;
+import java.util.regex.Pattern;
+
import xyz.zhouxy.plusone.domain.ValidatableStringRecord;
/**
@@ -8,7 +10,7 @@ import xyz.zhouxy.plusone.domain.ValidatableStringRecord;
* @author ZhouXY
*/
public abstract class Principal extends ValidatableStringRecord {
- protected Principal(String format) {
+ protected Principal(Pattern format) {
super(format);
}
}
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 3b80c87..2430bbc 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
@@ -1,5 +1,7 @@
package xyz.zhouxy.plusone.system.domain.model.account;
+import javax.annotation.Nonnull;
+
import xyz.zhouxy.plusone.commons.util.Enumeration;
import xyz.zhouxy.plusone.domain.IValueObject;
@@ -8,9 +10,12 @@ import xyz.zhouxy.plusone.domain.IValueObject;
*
* @author ZhouXY
*/
-public class Sex extends Enumeration implements IValueObject {
+public final class Sex extends Enumeration implements IValueObject {
+ @Nonnull
public static final Sex UNSET = new Sex(0, "未设置");
+ @Nonnull
public static final Sex MALE = new Sex(1, "男性");
+ @Nonnull
public static final Sex FEMALE = new Sex(2, "女性");
private Sex(int value, String name) {
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 94eab93..530144f 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
@@ -1,6 +1,8 @@
package xyz.zhouxy.plusone.system.domain.model.account;
-import xyz.zhouxy.plusone.constant.RegexConsts;
+import java.util.regex.Pattern;
+
+import xyz.zhouxy.plusone.commons.constant.PatternConsts;
/**
* 值对象:用户名
@@ -9,7 +11,7 @@ import xyz.zhouxy.plusone.constant.RegexConsts;
*/
public class Username extends Principal {
- public static final String REGEX = RegexConsts.USERNAME;
+ public static final Pattern REGEX = PatternConsts.USERNAME;
private Username(String username) {
super(REGEX);
diff --git a/plusone-system/plusone-system-infrastructure/src/main/java/xyz/zhouxy/plusone/system/domain/model/account/AccountRepositoryImpl.java b/plusone-system/plusone-system-infrastructure/src/main/java/xyz/zhouxy/plusone/system/domain/model/account/AccountRepositoryImpl.java
index c466dc0..32ec762 100644
--- a/plusone-system/plusone-system-infrastructure/src/main/java/xyz/zhouxy/plusone/system/domain/model/account/AccountRepositoryImpl.java
+++ b/plusone-system/plusone-system-infrastructure/src/main/java/xyz/zhouxy/plusone/system/domain/model/account/AccountRepositoryImpl.java
@@ -94,26 +94,26 @@ public class AccountRepositoryImpl extends JdbcRepositorySupport
@Override
public boolean exists(Long id) {
- return queryExists("SELECT EXISTS (SELECT 1 FROM sys_account WHERE id = :id AND deleted = 0 LIMIT 1)",
+ return queryForBool("SELECT EXISTS (SELECT 1 FROM sys_account WHERE id = :id AND deleted = 0 LIMIT 1)",
"id", id);
}
@Override
public boolean existsUsername(Username username) {
- return queryExists(
+ return queryForBool(
"SELECT EXISTS (SELECT 1 FROM sys_account WHERE username = :username AND deleted = 0 LIMIT 1)",
"username", username.value());
}
@Override
public boolean existsEmail(Email email) {
- return queryExists("SELECT EXISTS (SELECT 1 FROM sys_account WHERE email = :email AND deleted = 0 LIMIT 1)",
+ return queryForBool("SELECT EXISTS (SELECT 1 FROM sys_account WHERE email = :email AND deleted = 0 LIMIT 1)",
"email", email.value());
}
@Override
public boolean existsMobilePhone(MobilePhone mobilePhone) {
- return queryExists(
+ return queryForBool(
"SELECT EXISTS (SELECT 1 FROM sys_account WHERE mobile_phone = :mobile_phone AND deleted = 0 LIMIT 1)",
"mobile_phone", mobilePhone.value());
}
@@ -176,10 +176,6 @@ public class AccountRepositoryImpl extends JdbcRepositorySupport
@Override
protected final Account mapRow(ResultSet rs) throws SQLException {
long accountId = rs.getLong("id");
- AccountInfo accountInfo = AccountInfo.of(
- rs.getString("nickname"),
- rs.getString("avatar"),
- Sex.of(rs.getInt("sex")));
return new Account(
accountId,
rs.getString("username"),
@@ -187,7 +183,11 @@ public class AccountRepositoryImpl extends JdbcRepositorySupport
rs.getString("mobile_phone"),
Password.of(rs.getString("password"), rs.getString("salt")),
AccountStatus.of(rs.getInt("status")),
- accountInfo,
+ AccountInfo.builder()
+ .nickname(rs.getString("nickname"))
+ .avatar(rs.getString("avatar"))
+ .sex(Sex.of(rs.getInt("sex")))
+ .build(),
this.accountRoleDAO.selectRoleIdsByAccountId(accountId),
rs.getLong("created_by"),
rs.getLong("updated_by"),
diff --git a/plusone-system/plusone-system-infrastructure/src/main/java/xyz/zhouxy/plusone/system/domain/model/account/AccountRoleRefDAO.java b/plusone-system/plusone-system-infrastructure/src/main/java/xyz/zhouxy/plusone/system/domain/model/account/AccountRoleRefDAO.java
index 3e28167..f9aea5c 100644
--- a/plusone-system/plusone-system-infrastructure/src/main/java/xyz/zhouxy/plusone/system/domain/model/account/AccountRoleRefDAO.java
+++ b/plusone-system/plusone-system-infrastructure/src/main/java/xyz/zhouxy/plusone/system/domain/model/account/AccountRoleRefDAO.java
@@ -31,7 +31,7 @@ class AccountRoleRefDAO extends PlusoneJdbcDaoSupport {
}
void insertAccountRoleRefs(Long accountId, Set roleRefs) {
- int i = batchUpdate(
+ long i = batchUpdate(
"INSERT INTO sys_account_role (account_id, role_id) VALUES (:accountId, :roleId)",
roleRefs,
(Long roleId) -> new MapSqlParameterSource()
diff --git a/plusone-system/plusone-system-infrastructure/src/main/java/xyz/zhouxy/plusone/system/domain/model/dict/DictRepositoryImpl.java b/plusone-system/plusone-system-infrastructure/src/main/java/xyz/zhouxy/plusone/system/domain/model/dict/DictRepositoryImpl.java
index 2bd38ee..482b039 100644
--- a/plusone-system/plusone-system-infrastructure/src/main/java/xyz/zhouxy/plusone/system/domain/model/dict/DictRepositoryImpl.java
+++ b/plusone-system/plusone-system-infrastructure/src/main/java/xyz/zhouxy/plusone/system/domain/model/dict/DictRepositoryImpl.java
@@ -83,7 +83,7 @@ public class DictRepositoryImpl extends JdbcRepositorySupport implem
@Override
public boolean exists(Long id) {
- return queryExists("SELECT EXISTS (SELECT 1 FROM sys_dict_type WHERE id = :id AND deleted = 0 LIMIT 1)",
+ return queryForBool("SELECT EXISTS (SELECT 1 FROM sys_dict_type WHERE id = :id AND deleted = 0 LIMIT 1)",
new MapSqlParameterSource("id", id));
}
diff --git a/plusone-system/plusone-system-infrastructure/src/main/java/xyz/zhouxy/plusone/system/domain/model/dict/DictValueDAO.java b/plusone-system/plusone-system-infrastructure/src/main/java/xyz/zhouxy/plusone/system/domain/model/dict/DictValueDAO.java
index 19133c3..f1d981b 100644
--- a/plusone-system/plusone-system-infrastructure/src/main/java/xyz/zhouxy/plusone/system/domain/model/dict/DictValueDAO.java
+++ b/plusone-system/plusone-system-infrastructure/src/main/java/xyz/zhouxy/plusone/system/domain/model/dict/DictValueDAO.java
@@ -21,11 +21,11 @@ class DictValueDAO extends PlusoneJdbcDaoSupport {
void updateDictValues(Dict entity) {
update("DELETE FROM sys_dict_value WHERE dict_type = :dictType",
"dictType", entity.getId().orElseThrow());
- int i = insertDictValues(entity.getId().orElseThrow(), entity);
+ long i = insertDictValues(entity.getId().orElseThrow(), entity);
assertResultEquals(i, entity.count());
}
- int insertDictValues(Long dictId, Dict entity) {
+ long insertDictValues(Long dictId, Dict entity) {
if (Objects.isNull(dictId) || Objects.isNull(entity) || CollectionUtils.isEmpty(entity.getValues())) {
return 0;
}
diff --git a/plusone-system/plusone-system-infrastructure/src/main/java/xyz/zhouxy/plusone/system/domain/model/menu/ActionDAO.java b/plusone-system/plusone-system-infrastructure/src/main/java/xyz/zhouxy/plusone/system/domain/model/menu/ActionDAO.java
index 34a8e89..07bb570 100644
--- a/plusone-system/plusone-system-infrastructure/src/main/java/xyz/zhouxy/plusone/system/domain/model/menu/ActionDAO.java
+++ b/plusone-system/plusone-system-infrastructure/src/main/java/xyz/zhouxy/plusone/system/domain/model/menu/ActionDAO.java
@@ -8,7 +8,6 @@ import java.time.LocalDateTime;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
-import java.util.Objects;
import java.util.stream.Collectors;
import javax.annotation.Nonnull;
@@ -16,6 +15,7 @@ import javax.annotation.Nonnull;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
+import org.springframework.util.CollectionUtils;
import cn.hutool.core.util.IdUtil;
import xyz.zhouxy.plusone.jdbc.JdbcEntityDaoSupport;
@@ -80,7 +80,7 @@ class ActionDAO extends JdbcEntityDaoSupport {
}
Collection selectActionsByIdIn(Collection actionIds) {
- if (Objects.isNull(actionIds) || actionIds.isEmpty()) {
+ if (CollectionUtils.isEmpty(actionIds)) {
return Collections.emptyList();
}
return queryForList("""
diff --git a/plusone-system/plusone-system-infrastructure/src/main/java/xyz/zhouxy/plusone/system/domain/model/menu/MenuRepositoryImpl.java b/plusone-system/plusone-system-infrastructure/src/main/java/xyz/zhouxy/plusone/system/domain/model/menu/MenuRepositoryImpl.java
index f083e0a..93b9e97 100644
--- a/plusone-system/plusone-system-infrastructure/src/main/java/xyz/zhouxy/plusone/system/domain/model/menu/MenuRepositoryImpl.java
+++ b/plusone-system/plusone-system-infrastructure/src/main/java/xyz/zhouxy/plusone/system/domain/model/menu/MenuRepositoryImpl.java
@@ -7,7 +7,6 @@ import java.sql.SQLException;
import java.time.LocalDateTime;
import java.util.Collection;
import java.util.Collections;
-import java.util.Objects;
import java.util.Optional;
import javax.annotation.Nonnull;
@@ -15,6 +14,7 @@ import javax.annotation.Nonnull;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.stereotype.Repository;
+import org.springframework.util.CollectionUtils;
import cn.hutool.core.util.IdUtil;
import xyz.zhouxy.plusone.commons.util.EnumUtil;
@@ -115,13 +115,13 @@ public class MenuRepositoryImpl extends JdbcRepositorySupport