Merge branch 'dev' of http://zhouxy.xyz:3000/ZhouXY108/plusone-admin into dev
This commit is contained in:
@@ -12,7 +12,7 @@ import xyz.zhouxy.plusone.commons.util.PagingAndSortingQueryParams;
|
||||
*
|
||||
* @author <a href="https://gitee.com/zhouxy108">ZhouXY</a>
|
||||
*/
|
||||
@ToString
|
||||
@ToString(callSuper = true)
|
||||
public class AccountQueryParams extends PagingAndSortingQueryParams {
|
||||
|
||||
public AccountQueryParams() {
|
||||
@@ -29,7 +29,6 @@ public class AccountQueryParams extends PagingAndSortingQueryParams {
|
||||
"update_time");
|
||||
}
|
||||
|
||||
// TODO【添加】 注解参数校验
|
||||
private @Getter @Setter Long id;
|
||||
private @Getter @Setter String username;
|
||||
private @Getter @Setter String email;
|
||||
|
@@ -3,8 +3,11 @@ package xyz.zhouxy.plusone.system.domain.model.account;
|
||||
import java.util.Objects;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import cn.hutool.core.util.DesensitizedUtil;
|
||||
import xyz.zhouxy.plusone.commons.annotation.StaticFactoryMethod;
|
||||
import xyz.zhouxy.plusone.commons.annotation.ValueObject;
|
||||
import xyz.zhouxy.plusone.commons.constant.PatternConsts;
|
||||
|
||||
/**
|
||||
@@ -12,19 +15,13 @@ import xyz.zhouxy.plusone.commons.constant.PatternConsts;
|
||||
*
|
||||
* @author <a href="https://gitee.com/zhouxy108">ZhouXY</a>
|
||||
*/
|
||||
public class Email extends Principal {
|
||||
@ValueObject
|
||||
public final class Email extends Principal {
|
||||
|
||||
public static final Pattern REGEX = PatternConsts.EMAIL;
|
||||
|
||||
private Email(String email) {
|
||||
super(REGEX);
|
||||
if (email == null) {
|
||||
throw new IllegalArgumentException("邮箱地址不能为空");
|
||||
}
|
||||
this.value = email;
|
||||
if (!isValid()) {
|
||||
throw new IllegalArgumentException("邮箱地址格式错误");
|
||||
}
|
||||
super(email, REGEX);
|
||||
}
|
||||
|
||||
@StaticFactoryMethod(Email.class)
|
||||
@@ -33,19 +30,13 @@ public class Email extends Principal {
|
||||
}
|
||||
|
||||
@StaticFactoryMethod(Email.class)
|
||||
@Nullable
|
||||
public static Email ofNullable(String email) {
|
||||
return Objects.nonNull(email) ? new Email(email) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 脱敏后的数据
|
||||
*/
|
||||
public String safeValue() {
|
||||
return DesensitizedUtil.email(this.value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.safeValue();
|
||||
public String safeValue() {
|
||||
return DesensitizedUtil.email(value());
|
||||
}
|
||||
}
|
||||
|
@@ -3,8 +3,11 @@ package xyz.zhouxy.plusone.system.domain.model.account;
|
||||
import java.util.Objects;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import cn.hutool.core.util.DesensitizedUtil;
|
||||
import xyz.zhouxy.plusone.commons.annotation.StaticFactoryMethod;
|
||||
import xyz.zhouxy.plusone.commons.annotation.ValueObject;
|
||||
import xyz.zhouxy.plusone.commons.constant.PatternConsts;
|
||||
|
||||
/**
|
||||
@@ -12,19 +15,13 @@ import xyz.zhouxy.plusone.commons.constant.PatternConsts;
|
||||
*
|
||||
* @author <a href="https://gitee.com/zhouxy108">ZhouXY</a>
|
||||
*/
|
||||
@ValueObject
|
||||
public class MobilePhone extends Principal {
|
||||
|
||||
public static final Pattern REGEX = PatternConsts.MOBILE_PHONE;
|
||||
|
||||
private MobilePhone(String mobilePhone) {
|
||||
super(REGEX);
|
||||
if (mobilePhone == null) {
|
||||
throw new IllegalArgumentException("手机号不能为空");
|
||||
}
|
||||
this.value = mobilePhone;
|
||||
if (!isValid()) {
|
||||
throw new IllegalArgumentException("手机号格式错误");
|
||||
}
|
||||
super(mobilePhone, REGEX);
|
||||
}
|
||||
|
||||
@StaticFactoryMethod(MobilePhone.class)
|
||||
@@ -33,16 +30,13 @@ public class MobilePhone extends Principal {
|
||||
}
|
||||
|
||||
@StaticFactoryMethod(MobilePhone.class)
|
||||
@Nullable
|
||||
public static MobilePhone ofNullable(String mobilePhone) {
|
||||
return Objects.nonNull(mobilePhone) ? new MobilePhone(mobilePhone) : null;
|
||||
}
|
||||
|
||||
public String safeValue() {
|
||||
return DesensitizedUtil.mobilePhone(this.value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.safeValue();
|
||||
public String safeValue() {
|
||||
return DesensitizedUtil.mobilePhone(this.value());
|
||||
}
|
||||
}
|
||||
|
@@ -4,27 +4,22 @@ import java.util.Objects;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import xyz.zhouxy.plusone.commons.annotation.StaticFactoryMethod;
|
||||
import xyz.zhouxy.plusone.commons.annotation.ValueObject;
|
||||
import xyz.zhouxy.plusone.commons.constant.PatternConsts;
|
||||
import xyz.zhouxy.plusone.domain.ValidatableStringRecord;
|
||||
import xyz.zhouxy.plusone.commons.domain.ValidatableStringRecord;
|
||||
|
||||
/**
|
||||
* 值对象:昵称
|
||||
*
|
||||
* @author <a href="https://gitee.com/zhouxy108">ZhouXY</a>
|
||||
*/
|
||||
@ValueObject
|
||||
public class Nickname extends ValidatableStringRecord {
|
||||
|
||||
public static final Pattern REGEX = PatternConsts.NICKNAME;
|
||||
|
||||
private Nickname(String value) {
|
||||
super(REGEX);
|
||||
if (value == null) {
|
||||
throw new IllegalArgumentException("昵称不能为空");
|
||||
}
|
||||
this.value = value;
|
||||
if (!isValid()) {
|
||||
throw new IllegalArgumentException("昵称格式错误");
|
||||
}
|
||||
super(value, REGEX);
|
||||
}
|
||||
|
||||
@StaticFactoryMethod(Nickname.class)
|
||||
|
@@ -2,15 +2,23 @@ package xyz.zhouxy.plusone.system.domain.model.account;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import xyz.zhouxy.plusone.domain.ValidatableStringRecord;
|
||||
import xyz.zhouxy.plusone.commons.domain.ValidatableStringRecord;
|
||||
import xyz.zhouxy.plusone.domain.IValueObject;
|
||||
|
||||
/**
|
||||
* 账号标识符
|
||||
*
|
||||
* @author <a href="https://gitee.com/zhouxy108">ZhouXY</a>
|
||||
*/
|
||||
public abstract class Principal extends ValidatableStringRecord {
|
||||
protected Principal(Pattern format) {
|
||||
super(format);
|
||||
public abstract class Principal extends ValidatableStringRecord implements IValueObject {
|
||||
protected Principal(String principal, Pattern pattern) {
|
||||
super(principal, pattern);
|
||||
}
|
||||
|
||||
protected abstract String safeValue();
|
||||
|
||||
@Override
|
||||
public final String toString() {
|
||||
return this.safeValue();
|
||||
}
|
||||
}
|
||||
|
@@ -3,6 +3,7 @@ package xyz.zhouxy.plusone.system.domain.model.account;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import xyz.zhouxy.plusone.commons.annotation.StaticFactoryMethod;
|
||||
import xyz.zhouxy.plusone.commons.annotation.ValueObject;
|
||||
import xyz.zhouxy.plusone.commons.constant.PatternConsts;
|
||||
|
||||
/**
|
||||
@@ -10,23 +11,23 @@ import xyz.zhouxy.plusone.commons.constant.PatternConsts;
|
||||
*
|
||||
* @author <a href="https://gitee.com/zhouxy108">ZhouXY</a>
|
||||
*/
|
||||
@ValueObject
|
||||
public class Username extends Principal {
|
||||
|
||||
public static final Pattern REGEX = PatternConsts.USERNAME;
|
||||
|
||||
private Username(String username) {
|
||||
super(REGEX);
|
||||
if (username == null) {
|
||||
throw new IllegalArgumentException("用户名不能为空");
|
||||
}
|
||||
this.value = username;
|
||||
if (!isValid()) {
|
||||
throw new IllegalArgumentException("用户名格式错误");
|
||||
}
|
||||
super(username, REGEX);
|
||||
}
|
||||
|
||||
@StaticFactoryMethod(Username.class)
|
||||
public static Username of(String username) {
|
||||
return new Username(username);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String safeValue() {
|
||||
// 不需要脱敏。
|
||||
return value();
|
||||
}
|
||||
}
|
||||
|
@@ -9,6 +9,7 @@ import com.fasterxml.jackson.annotation.JsonValue;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.ToString;
|
||||
import xyz.zhouxy.plusone.commons.exception.IWithIntCode;
|
||||
import xyz.zhouxy.plusone.constant.EntityStatus;
|
||||
import xyz.zhouxy.plusone.domain.AggregateRoot;
|
||||
import xyz.zhouxy.plusone.domain.IWithOrderNumber;
|
||||
@@ -129,12 +130,28 @@ public class Menu extends AggregateRoot<Long> implements IWithOrderNumber, IWith
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public enum MenuType {
|
||||
MENU_LIST, MENU_ITEM;
|
||||
public enum MenuType implements IWithIntCode {
|
||||
MENU_LIST(0), MENU_ITEM(1);
|
||||
|
||||
private final int code;
|
||||
|
||||
private MenuType(int code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
@JsonValue
|
||||
public int value() {
|
||||
return ordinal();
|
||||
@Override
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public static MenuType valueOf(int code) {
|
||||
for (MenuType value : values()) {
|
||||
if (value.code == code) {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
throw new EnumConstantNotPresentException(MenuType.class, Integer.toString(code));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -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<Account, Long>
|
||||
|
||||
@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<String> email = entity.getEmail().map(ValidatableStringRecord::value);
|
||||
final Optional<String> 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<String> avatar = accountInfo.getAvatar().map(Object::toString);
|
||||
final int sex = accountInfo.getSex().getId();
|
||||
final Optional<String> nickname = accountInfo.getNickname().map(ValidatableStringRecord::value);
|
||||
final int status = entity.getStatus().getId();
|
||||
final Optional<Long> createdBy = entity.getCreatedBy();
|
||||
final Optional<Long> 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);
|
||||
}
|
||||
}
|
||||
|
@@ -7,6 +7,7 @@ import java.sql.SQLException;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
@@ -94,13 +95,12 @@ public class DictRepositoryImpl extends JdbcRepositorySupport<Dict, Long> implem
|
||||
|
||||
@Override
|
||||
protected final Dict mapRow(ResultSet rs) throws SQLException {
|
||||
long id = rs.getLong("id");
|
||||
return new Dict(
|
||||
id,
|
||||
rs.getString("dict_type"),
|
||||
rs.getString("dict_label"),
|
||||
this.dictValueDAO.selectDictValuesByDictId(id),
|
||||
rs.getLong("version"));
|
||||
final long id = rs.getLong("id");
|
||||
final String dictType = rs.getString("dict_type");
|
||||
final String dictLabel = rs.getString("dict_label");
|
||||
final Set<DictValue> values = this.dictValueDAO.selectDictValuesByDictId(id);
|
||||
final long version = rs.getLong("version");
|
||||
return new Dict(id, dictType, dictLabel, values, version);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -17,7 +17,6 @@ import org.springframework.stereotype.Repository;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import xyz.zhouxy.plusone.commons.util.EnumUtil;
|
||||
import xyz.zhouxy.plusone.constant.EntityStatus;
|
||||
import xyz.zhouxy.plusone.exception.DataNotExistException;
|
||||
import xyz.zhouxy.plusone.jdbc.JdbcRepositorySupport;
|
||||
@@ -156,7 +155,7 @@ public class MenuRepositoryImpl extends JdbcRepositorySupport<Menu, Long> implem
|
||||
protected final Menu mapRow(ResultSet rs) throws SQLException {
|
||||
long menuId = rs.getLong("id");
|
||||
return new Menu(
|
||||
EnumUtil.valueOf(MenuType.class, rs.getInt("type")),
|
||||
MenuType.valueOf(rs.getInt("type")),
|
||||
menuId,
|
||||
rs.getLong("parent_id"),
|
||||
rs.getString("name"),
|
||||
@@ -181,7 +180,7 @@ public class MenuRepositoryImpl extends JdbcRepositorySupport<Menu, Long> implem
|
||||
return new MapSqlParameterSource()
|
||||
.addValue("id", id)
|
||||
.addValue("parentId", entity.getParentId())
|
||||
.addValue("type", entity.getType().value())
|
||||
.addValue("type", entity.getType().getCode())
|
||||
.addValue("name", entity.getName())
|
||||
.addValue("path", entity.getPath())
|
||||
.addValue("title", entity.getTitle())
|
||||
|
Reference in New Issue
Block a user