Compare commits
No commits in common. "cf068566a12203130c7b9aad703ff01e4c77f731" and "699ba2394d9f4f7130406951d8226740610223d2" have entirely different histories.
cf068566a1
...
699ba2394d
@ -1,7 +1,5 @@
|
|||||||
package xyz.zhouxy.plusone.domain;
|
package xyz.zhouxy.plusone.domain;
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
import com.fasterxml.jackson.annotation.JsonValue;
|
import com.fasterxml.jackson.annotation.JsonValue;
|
||||||
|
|
||||||
@ -33,8 +31,4 @@ public abstract class ValidatableStringRecord implements IValueObject {
|
|||||||
public String toString() {
|
public String toString() {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getValueOrNull(Optional<? extends ValidatableStringRecord> s) {
|
|
||||||
return s.map(ValidatableStringRecord::value).orElse(null);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,7 @@ public class AccountCreated extends DomainEvent {
|
|||||||
|
|
||||||
public AccountCreated(Account account) {
|
public AccountCreated(Account account) {
|
||||||
this.username = account.getUsername();
|
this.username = account.getUsername();
|
||||||
this.email = account.getEmail().orElse(null);
|
this.email = account.getEmail();
|
||||||
this.mobilePhone = account.getMobilePhone().orElse(null);
|
this.mobilePhone = account.getMobilePhone();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,7 @@ public class AccountLocked extends DomainEvent {
|
|||||||
|
|
||||||
public AccountLocked(Account account) {
|
public AccountLocked(Account account) {
|
||||||
this.username = account.getUsername();
|
this.username = account.getUsername();
|
||||||
this.email = account.getEmail().orElse(null);
|
this.email = account.getEmail();
|
||||||
this.mobilePhone = account.getMobilePhone().orElse(null);
|
this.mobilePhone = account.getMobilePhone();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,8 +27,8 @@ public class AccountPasswordChanged extends DomainEvent {
|
|||||||
|
|
||||||
public AccountPasswordChanged(Account account) {
|
public AccountPasswordChanged(Account account) {
|
||||||
this.username = account.getUsername();
|
this.username = account.getUsername();
|
||||||
this.email = account.getEmail().orElse(null);
|
this.email = account.getEmail();
|
||||||
this.mobilePhone = account.getMobilePhone().orElse(null);
|
this.mobilePhone = account.getMobilePhone();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,6 @@ public class EmailChanged extends DomainEvent {
|
|||||||
|
|
||||||
public EmailChanged(Account account) {
|
public EmailChanged(Account account) {
|
||||||
this.username = account.getUsername();
|
this.username = account.getUsername();
|
||||||
this.email = account.getEmail().orElse(null);
|
this.email = account.getEmail();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,6 @@ public class MobilePhoneChanged extends DomainEvent {
|
|||||||
|
|
||||||
public MobilePhoneChanged(Account account) {
|
public MobilePhoneChanged(Account account) {
|
||||||
this.username = account.getUsername();
|
this.username = account.getUsername();
|
||||||
this.mobilePhone = account.getMobilePhone().orElse(null);
|
this.mobilePhone = account.getMobilePhone();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,7 @@ public class UsernameChanged extends DomainEvent {
|
|||||||
|
|
||||||
public UsernameChanged(Account account) {
|
public UsernameChanged(Account account) {
|
||||||
this.username = account.getUsername();
|
this.username = account.getUsername();
|
||||||
this.email = account.getEmail().orElse(null);
|
this.email = account.getEmail();
|
||||||
this.mobilePhone = account.getMobilePhone().orElse(null);
|
this.mobilePhone = account.getMobilePhone();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,8 @@ import java.util.HashSet;
|
|||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
import lombok.ToString;
|
import lombok.ToString;
|
||||||
import xyz.zhouxy.plusone.domain.AggregateRoot;
|
import xyz.zhouxy.plusone.domain.AggregateRoot;
|
||||||
import xyz.zhouxy.plusone.domain.IWithVersion;
|
import xyz.zhouxy.plusone.domain.IWithVersion;
|
||||||
@ -28,17 +30,17 @@ public class Account extends AggregateRoot<Long> implements IWithVersion {
|
|||||||
|
|
||||||
// ===================== 字段 ====================
|
// ===================== 字段 ====================
|
||||||
private Long id;
|
private Long id;
|
||||||
private Username username;
|
private @Getter Username username;
|
||||||
private Email email;
|
private @Getter Email email;
|
||||||
private MobilePhone mobilePhone;
|
private @Getter MobilePhone mobilePhone;
|
||||||
private Password password;
|
private Password password;
|
||||||
private AccountStatus status;
|
private @Getter AccountStatus status;
|
||||||
private AccountInfo accountInfo;
|
private @Getter AccountInfo accountInfo;
|
||||||
private Set<Long> roleRefs = new HashSet<>();
|
private Set<Long> roleRefs = new HashSet<>();
|
||||||
|
|
||||||
private Long createdBy;
|
private @Getter Long createdBy;
|
||||||
private Long updatedBy;
|
private @Getter @Setter Long updatedBy;
|
||||||
private long version;
|
private @Getter long version;
|
||||||
|
|
||||||
public void setUsername(Username username) {
|
public void setUsername(Username username) {
|
||||||
this.username = username;
|
this.username = username;
|
||||||
@ -221,48 +223,11 @@ public class Account extends AggregateRoot<Long> implements IWithVersion {
|
|||||||
return Optional.ofNullable(id);
|
return Optional.ofNullable(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Username getUsername() {
|
public Set<Long> getRoleIds() {
|
||||||
return username;
|
return Set.copyOf(this.roleRefs);
|
||||||
}
|
|
||||||
|
|
||||||
public Optional<Email> getEmail() {
|
|
||||||
return Optional.ofNullable(email);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Optional<MobilePhone> getMobilePhone() {
|
|
||||||
return Optional.ofNullable(mobilePhone);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Password getPassword() {
|
Password getPassword() {
|
||||||
return password;
|
return password;
|
||||||
}
|
}
|
||||||
|
|
||||||
public AccountStatus getStatus() {
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
public AccountInfo getAccountInfo() {
|
|
||||||
return accountInfo;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Set<Long> getRoleIds() {
|
|
||||||
return Set.copyOf(roleRefs);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Optional<Long> getCreatedBy() {
|
|
||||||
return Optional.ofNullable(createdBy);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Optional<Long> getUpdatedBy() {
|
|
||||||
return Optional.ofNullable(updatedBy);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUpdatedBy(long updatedBy) {
|
|
||||||
this.updatedBy = updatedBy;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public long getVersion() {
|
|
||||||
return this.version;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,6 @@ package xyz.zhouxy.plusone.system.domain.model.account;
|
|||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.ToString;
|
import lombok.ToString;
|
||||||
@ -14,12 +13,13 @@ import xyz.zhouxy.plusone.domain.IValueObject;
|
|||||||
*
|
*
|
||||||
* @author <a href="https://gitee.com/zhouxy108">ZhouXY</a>
|
* @author <a href="https://gitee.com/zhouxy108">ZhouXY</a>
|
||||||
*/
|
*/
|
||||||
|
@Getter
|
||||||
@ToString
|
@ToString
|
||||||
public class AccountInfo implements IValueObject {
|
public class AccountInfo implements IValueObject {
|
||||||
|
|
||||||
private final Nickname nickname;
|
private final Nickname nickname;
|
||||||
private final URL avatar;
|
private final URL avatar;
|
||||||
private final @Getter Sex sex;
|
private final Sex sex;
|
||||||
|
|
||||||
private AccountInfo(Nickname nickname, URL avatar, Sex sex) {
|
private AccountInfo(Nickname nickname, URL avatar, Sex sex) {
|
||||||
this.nickname = nickname;
|
this.nickname = nickname;
|
||||||
@ -40,12 +40,4 @@ public class AccountInfo implements IValueObject {
|
|||||||
}
|
}
|
||||||
return new AccountInfo(Nickname.ofNullable(nickname), avatarURL, sex);
|
return new AccountInfo(Nickname.ofNullable(nickname), avatarURL, sex);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Optional<Nickname> getNickname() {
|
|
||||||
return Optional.ofNullable(nickname);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Optional<URL> getAvatar() {
|
|
||||||
return Optional.ofNullable(avatar);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ import java.util.HashSet;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import lombok.ToString;
|
import lombok.ToString;
|
||||||
import xyz.zhouxy.plusone.domain.AggregateRoot;
|
import xyz.zhouxy.plusone.domain.AggregateRoot;
|
||||||
@ -114,7 +115,7 @@ public class Dict extends AggregateRoot<Long> implements IWithLabel, IWithVersio
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Set<DictValue> getValues() {
|
public Set<DictValue> getValues() {
|
||||||
return Set.copyOf(this.values.values());
|
return this.values.values().stream().collect(Collectors.toSet());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -4,6 +4,7 @@ import java.sql.ResultSet;
|
|||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
@ -14,7 +15,6 @@ import org.springframework.jdbc.core.namedparam.SqlParameterSource;
|
|||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
import cn.hutool.core.util.IdUtil;
|
import cn.hutool.core.util.IdUtil;
|
||||||
import static xyz.zhouxy.plusone.domain.ValidatableStringRecord.getValueOrNull;
|
|
||||||
import xyz.zhouxy.plusone.jdbc.JdbcRepositorySupport;
|
import xyz.zhouxy.plusone.jdbc.JdbcRepositorySupport;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -100,8 +100,7 @@ public class AccountRepositoryImpl extends JdbcRepositorySupport<Account, Long>
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean existsUsername(Username username) {
|
public boolean existsUsername(Username username) {
|
||||||
return queryExists(
|
return queryExists("SELECT EXISTS (SELECT 1 FROM sys_account WHERE username = :username AND deleted = 0 LIMIT 1)",
|
||||||
"SELECT EXISTS (SELECT 1 FROM sys_account WHERE username = :username AND deleted = 0 LIMIT 1)",
|
|
||||||
"username", username.value());
|
"username", username.value());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -113,8 +112,7 @@ public class AccountRepositoryImpl extends JdbcRepositorySupport<Account, Long>
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean existsMobilePhone(MobilePhone mobilePhone) {
|
public boolean existsMobilePhone(MobilePhone mobilePhone) {
|
||||||
return queryExists(
|
return queryExists("SELECT EXISTS (SELECT 1 FROM sys_account WHERE mobile_phone = :mobile_phone AND deleted = 0 LIMIT 1)",
|
||||||
"SELECT EXISTS (SELECT 1 FROM sys_account WHERE mobile_phone = :mobile_phone AND deleted = 0 LIMIT 1)",
|
|
||||||
"mobile_phone", mobilePhone.value());
|
"mobile_phone", mobilePhone.value());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -200,14 +198,16 @@ public class AccountRepositoryImpl extends JdbcRepositorySupport<Account, Long>
|
|||||||
AccountInfo accountInfo = entity.getAccountInfo();
|
AccountInfo accountInfo = entity.getAccountInfo();
|
||||||
return new MapSqlParameterSource()
|
return new MapSqlParameterSource()
|
||||||
.addValue("id", id)
|
.addValue("id", id)
|
||||||
.addValue("email", getValueOrNull(entity.getEmail()))
|
.addValue("email", Objects.nonNull(entity.getEmail()) ? entity.getEmail().value() : null)
|
||||||
.addValue("mobilePhone", getValueOrNull(entity.getMobilePhone()))
|
.addValue("mobilePhone",
|
||||||
|
Objects.nonNull(entity.getMobilePhone()) ? entity.getMobilePhone().value() : null)
|
||||||
.addValue("username", entity.getUsername().value())
|
.addValue("username", entity.getUsername().value())
|
||||||
.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().getValue())
|
||||||
.addValue("nickname", getValueOrNull(accountInfo.getNickname()))
|
.addValue("nickname",
|
||||||
|
Objects.nonNull(accountInfo.getNickname()) ? accountInfo.getNickname().value() : null)
|
||||||
.addValue("status", entity.getStatus().getValue())
|
.addValue("status", entity.getStatus().getValue())
|
||||||
.addValue("createdBy", entity.getCreatedBy())
|
.addValue("createdBy", entity.getCreatedBy())
|
||||||
.addValue("createTime", now)
|
.addValue("createTime", now)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user