修改领域模型。
This commit is contained in:
parent
5ad6980bf7
commit
0212020dcf
@ -1,5 +1,7 @@
|
|||||||
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;
|
||||||
|
|
||||||
@ -31,4 +33,8 @@ 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();
|
this.email = account.getEmail().orElse(null);
|
||||||
this.mobilePhone = account.getMobilePhone();
|
this.mobilePhone = account.getMobilePhone().orElse(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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();
|
this.email = account.getEmail().orElse(null);
|
||||||
this.mobilePhone = account.getMobilePhone();
|
this.mobilePhone = account.getMobilePhone().orElse(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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();
|
this.email = account.getEmail().orElse(null);
|
||||||
this.mobilePhone = account.getMobilePhone();
|
this.mobilePhone = account.getMobilePhone().orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -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();
|
this.email = account.getEmail().orElse(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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();
|
this.mobilePhone = account.getMobilePhone().orElse(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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();
|
this.email = account.getEmail().orElse(null);
|
||||||
this.mobilePhone = account.getMobilePhone();
|
this.mobilePhone = account.getMobilePhone().orElse(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,8 +5,6 @@ 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;
|
||||||
@ -30,17 +28,17 @@ public class Account extends AggregateRoot<Long> implements IWithVersion {
|
|||||||
|
|
||||||
// ===================== 字段 ====================
|
// ===================== 字段 ====================
|
||||||
private Long id;
|
private Long id;
|
||||||
private @Getter Username username;
|
private Username username;
|
||||||
private @Getter Email email;
|
private Email email;
|
||||||
private @Getter MobilePhone mobilePhone;
|
private MobilePhone mobilePhone;
|
||||||
private Password password;
|
private Password password;
|
||||||
private @Getter AccountStatus status;
|
private AccountStatus status;
|
||||||
private @Getter AccountInfo accountInfo;
|
private AccountInfo accountInfo;
|
||||||
private Set<Long> roleRefs = new HashSet<>();
|
private Set<Long> roleRefs = new HashSet<>();
|
||||||
|
|
||||||
private @Getter Long createdBy;
|
private Long createdBy;
|
||||||
private @Getter @Setter Long updatedBy;
|
private Long updatedBy;
|
||||||
private @Getter long version;
|
private long version;
|
||||||
|
|
||||||
public void setUsername(Username username) {
|
public void setUsername(Username username) {
|
||||||
this.username = username;
|
this.username = username;
|
||||||
@ -223,11 +221,48 @@ public class Account extends AggregateRoot<Long> implements IWithVersion {
|
|||||||
return Optional.ofNullable(id);
|
return Optional.ofNullable(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<Long> getRoleIds() {
|
public Username getUsername() {
|
||||||
return Set.copyOf(this.roleRefs);
|
return username;
|
||||||
|
}
|
||||||
|
|
||||||
|
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,6 +3,7 @@ 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;
|
||||||
@ -13,13 +14,12 @@ 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 Sex sex;
|
private final @Getter 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,4 +40,12 @@ 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,7 +6,6 @@ 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;
|
||||||
@ -115,7 +114,7 @@ public class Dict extends AggregateRoot<Long> implements IWithLabel, IWithVersio
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Set<DictValue> getValues() {
|
public Set<DictValue> getValues() {
|
||||||
return this.values.values().stream().collect(Collectors.toSet());
|
return Set.copyOf(this.values.values());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -4,7 +4,6 @@ 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;
|
||||||
@ -15,6 +14,7 @@ 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,7 +100,8 @@ public class AccountRepositoryImpl extends JdbcRepositorySupport<Account, Long>
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean existsUsername(Username username) {
|
public boolean existsUsername(Username username) {
|
||||||
return queryExists("SELECT EXISTS (SELECT 1 FROM sys_account WHERE username = :username AND deleted = 0 LIMIT 1)",
|
return queryExists(
|
||||||
|
"SELECT EXISTS (SELECT 1 FROM sys_account WHERE username = :username AND deleted = 0 LIMIT 1)",
|
||||||
"username", username.value());
|
"username", username.value());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -112,7 +113,8 @@ public class AccountRepositoryImpl extends JdbcRepositorySupport<Account, Long>
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean existsMobilePhone(MobilePhone mobilePhone) {
|
public boolean existsMobilePhone(MobilePhone mobilePhone) {
|
||||||
return queryExists("SELECT EXISTS (SELECT 1 FROM sys_account WHERE mobile_phone = :mobile_phone AND deleted = 0 LIMIT 1)",
|
return queryExists(
|
||||||
|
"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());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -198,16 +200,14 @@ 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", Objects.nonNull(entity.getEmail()) ? entity.getEmail().value() : null)
|
.addValue("email", getValueOrNull(entity.getEmail()))
|
||||||
.addValue("mobilePhone",
|
.addValue("mobilePhone", getValueOrNull(entity.getMobilePhone()))
|
||||||
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",
|
.addValue("nickname", getValueOrNull(accountInfo.getNickname()))
|
||||||
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