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 161284d..deb8264 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 @@ -14,7 +14,8 @@ 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.commons.domain.ValidatableStringRecord; +import xyz.zhouxy.plusone.commons.util.OptionalUtil; import xyz.zhouxy.plusone.jdbc.JdbcRepositorySupport; /** @@ -196,23 +197,35 @@ public class AccountRepositoryImpl extends JdbcRepositorySupport @Override protected final SqlParameterSource generateParamSource(Long id, @Nonnull Account entity) { - LocalDateTime now = LocalDateTime.now(); - AccountInfo accountInfo = entity.getAccountInfo(); + final LocalDateTime now = LocalDateTime.now(); + final AccountInfo accountInfo = entity.getAccountInfo(); + final Optional email = entity.getEmail().map(ValidatableStringRecord::value); + final Optional mobilePhone = entity.getMobilePhone().map(ValidatableStringRecord::value); + final String username = entity.getUsername().value(); + final String password = entity.getPassword().value(); + final String salt = entity.getPassword().getSalt(); + final Optional avatar = accountInfo.getAvatar().map(Object::toString); + final int sex = accountInfo.getSex().getId(); + final Optional nickname = accountInfo.getNickname().map(ValidatableStringRecord::value); + final int status = entity.getStatus().getId(); + final Optional createdBy = entity.getCreatedBy(); + final Optional updatedBy = entity.getUpdatedBy(); + final long version = entity.getVersion(); return new MapSqlParameterSource() .addValue("id", id) - .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().getId()) - .addValue("nickname", getValueOrNull(accountInfo.getNickname())) - .addValue("status", entity.getStatus().getId()) - .addValue("createdBy", entity.getCreatedBy()) + .addValue("email", OptionalUtil.orElseNull(email)) + .addValue("mobilePhone", OptionalUtil.orElseNull(mobilePhone)) + .addValue("username", username) + .addValue("password", password) + .addValue("salt", salt) + .addValue("avatar", OptionalUtil.orElseNull(avatar)) + .addValue("sex", sex) + .addValue("nickname", OptionalUtil.orElseNull(nickname)) + .addValue("status", status) + .addValue("createdBy", OptionalUtil.orElseNull(createdBy)) .addValue("createTime", now) - .addValue("updatedBy", entity.getUpdatedBy()) + .addValue("updatedBy", OptionalUtil.orElseNull(updatedBy)) .addValue("updateTime", now) - .addValue("version", entity.getVersion()); + .addValue("version", version); } }