修改领域模型。
This commit is contained in:
parent
5ad6980bf7
commit
0212020dcf
@ -1,5 +1,7 @@
|
||||
package xyz.zhouxy.plusone.domain;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonValue;
|
||||
|
||||
@ -31,4 +33,8 @@ public abstract class ValidatableStringRecord implements IValueObject {
|
||||
public String toString() {
|
||||
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) {
|
||||
this.username = account.getUsername();
|
||||
this.email = account.getEmail();
|
||||
this.mobilePhone = account.getMobilePhone();
|
||||
this.email = account.getEmail().orElse(null);
|
||||
this.mobilePhone = account.getMobilePhone().orElse(null);
|
||||
}
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ public class AccountLocked extends DomainEvent {
|
||||
|
||||
public AccountLocked(Account account) {
|
||||
this.username = account.getUsername();
|
||||
this.email = account.getEmail();
|
||||
this.mobilePhone = account.getMobilePhone();
|
||||
this.email = account.getEmail().orElse(null);
|
||||
this.mobilePhone = account.getMobilePhone().orElse(null);
|
||||
}
|
||||
}
|
||||
|
@ -27,8 +27,8 @@ public class AccountPasswordChanged extends DomainEvent {
|
||||
|
||||
public AccountPasswordChanged(Account account) {
|
||||
this.username = account.getUsername();
|
||||
this.email = account.getEmail();
|
||||
this.mobilePhone = account.getMobilePhone();
|
||||
this.email = account.getEmail().orElse(null);
|
||||
this.mobilePhone = account.getMobilePhone().orElse(null);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -25,6 +25,6 @@ public class EmailChanged extends DomainEvent {
|
||||
|
||||
public EmailChanged(Account account) {
|
||||
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) {
|
||||
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) {
|
||||
this.username = account.getUsername();
|
||||
this.email = account.getEmail();
|
||||
this.mobilePhone = account.getMobilePhone();
|
||||
this.email = account.getEmail().orElse(null);
|
||||
this.mobilePhone = account.getMobilePhone().orElse(null);
|
||||
}
|
||||
}
|
||||
|
@ -5,8 +5,6 @@ import java.util.HashSet;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import xyz.zhouxy.plusone.domain.AggregateRoot;
|
||||
import xyz.zhouxy.plusone.domain.IWithVersion;
|
||||
@ -30,17 +28,17 @@ public class Account extends AggregateRoot<Long> implements IWithVersion {
|
||||
|
||||
// ===================== 字段 ====================
|
||||
private Long id;
|
||||
private @Getter Username username;
|
||||
private @Getter Email email;
|
||||
private @Getter MobilePhone mobilePhone;
|
||||
private Username username;
|
||||
private Email email;
|
||||
private MobilePhone mobilePhone;
|
||||
private Password password;
|
||||
private @Getter AccountStatus status;
|
||||
private @Getter AccountInfo accountInfo;
|
||||
private AccountStatus status;
|
||||
private AccountInfo accountInfo;
|
||||
private Set<Long> roleRefs = new HashSet<>();
|
||||
|
||||
private @Getter Long createdBy;
|
||||
private @Getter @Setter Long updatedBy;
|
||||
private @Getter long version;
|
||||
private Long createdBy;
|
||||
private Long updatedBy;
|
||||
private long version;
|
||||
|
||||
public void setUsername(Username username) {
|
||||
this.username = username;
|
||||
@ -223,11 +221,48 @@ public class Account extends AggregateRoot<Long> implements IWithVersion {
|
||||
return Optional.ofNullable(id);
|
||||
}
|
||||
|
||||
public Set<Long> getRoleIds() {
|
||||
return Set.copyOf(this.roleRefs);
|
||||
public Username getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public Optional<Email> getEmail() {
|
||||
return Optional.ofNullable(email);
|
||||
}
|
||||
|
||||
public Optional<MobilePhone> getMobilePhone() {
|
||||
return Optional.ofNullable(mobilePhone);
|
||||
}
|
||||
|
||||
Password getPassword() {
|
||||
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.URL;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.ToString;
|
||||
@ -13,13 +14,12 @@ import xyz.zhouxy.plusone.domain.IValueObject;
|
||||
*
|
||||
* @author <a href="https://gitee.com/zhouxy108">ZhouXY</a>
|
||||
*/
|
||||
@Getter
|
||||
@ToString
|
||||
public class AccountInfo implements IValueObject {
|
||||
|
||||
private final Nickname nickname;
|
||||
private final URL avatar;
|
||||
private final Sex sex;
|
||||
private final @Getter Sex sex;
|
||||
|
||||
private AccountInfo(Nickname nickname, URL avatar, Sex sex) {
|
||||
this.nickname = nickname;
|
||||
@ -40,4 +40,12 @@ public class AccountInfo implements IValueObject {
|
||||
}
|
||||
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.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import lombok.ToString;
|
||||
import xyz.zhouxy.plusone.domain.AggregateRoot;
|
||||
@ -115,7 +114,7 @@ public class Dict extends AggregateRoot<Long> implements IWithLabel, IWithVersio
|
||||
}
|
||||
|
||||
public Set<DictValue> getValues() {
|
||||
return this.values.values().stream().collect(Collectors.toSet());
|
||||
return Set.copyOf(this.values.values());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -4,7 +4,6 @@ import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Collection;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
@ -15,6 +14,7 @@ import org.springframework.jdbc.core.namedparam.SqlParameterSource;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import static xyz.zhouxy.plusone.domain.ValidatableStringRecord.getValueOrNull;
|
||||
import xyz.zhouxy.plusone.jdbc.JdbcRepositorySupport;
|
||||
|
||||
/**
|
||||
@ -100,7 +100,8 @@ public class AccountRepositoryImpl extends JdbcRepositorySupport<Account, Long>
|
||||
|
||||
@Override
|
||||
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());
|
||||
}
|
||||
|
||||
@ -112,7 +113,8 @@ public class AccountRepositoryImpl extends JdbcRepositorySupport<Account, Long>
|
||||
|
||||
@Override
|
||||
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());
|
||||
}
|
||||
|
||||
@ -198,16 +200,14 @@ public class AccountRepositoryImpl extends JdbcRepositorySupport<Account, Long>
|
||||
AccountInfo accountInfo = entity.getAccountInfo();
|
||||
return new MapSqlParameterSource()
|
||||
.addValue("id", id)
|
||||
.addValue("email", Objects.nonNull(entity.getEmail()) ? entity.getEmail().value() : null)
|
||||
.addValue("mobilePhone",
|
||||
Objects.nonNull(entity.getMobilePhone()) ? entity.getMobilePhone().value() : null)
|
||||
.addValue("email", getValueOrNull(entity.getEmail()))
|
||||
.addValue("mobilePhone", getValueOrNull(entity.getMobilePhone()))
|
||||
.addValue("username", entity.getUsername().value())
|
||||
.addValue("password", entity.getPassword().value())
|
||||
.addValue("salt", entity.getPassword().getSalt())
|
||||
.addValue("avatar", accountInfo.getAvatar().toString())
|
||||
.addValue("sex", accountInfo.getSex().getValue())
|
||||
.addValue("nickname",
|
||||
Objects.nonNull(accountInfo.getNickname()) ? accountInfo.getNickname().value() : null)
|
||||
.addValue("nickname", getValueOrNull(accountInfo.getNickname()))
|
||||
.addValue("status", entity.getStatus().getValue())
|
||||
.addValue("createdBy", entity.getCreatedBy())
|
||||
.addValue("createTime", now)
|
||||
|
Loading…
x
Reference in New Issue
Block a user