Compare commits
24 Commits
993ba7fa7b
...
main
Author | SHA1 | Date | |
---|---|---|---|
8460b9da29 | |||
19fc97362c | |||
d91f818c96 | |||
0e0d6f1808 | |||
06ffc8d858 | |||
60b4f18e8c | |||
2b282039ad | |||
ea7a8ee6a0 | |||
67313938e1 | |||
27be582bfb | |||
288ce9689f | |||
71edaa60a4 | |||
39cd57e675 | |||
7a44c43402 | |||
55395ed327 | |||
956da350ed | |||
78cdded667 | |||
cc3c4be8de | |||
1e31e1f327 | |||
33d3d86393 | |||
1b551eeb4c | |||
1611bf38e8 | |||
17273b0bc6 | |||
2d02899372 |
@@ -1,10 +1,13 @@
|
||||
package xyz.zhouxy.plusone.exception.handler;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import xyz.zhouxy.plusone.exception.handler.BaseExceptionHandler.ExceptionInfoHolder;
|
||||
import xyz.zhouxy.plusone.commons.exception.handler.AllExceptionHandler;
|
||||
import xyz.zhouxy.plusone.commons.exception.handler.BaseExceptionHandler.ExceptionInfoHolder;
|
||||
|
||||
/**
|
||||
* AllExceptionHandlerConfig
|
||||
@@ -14,7 +17,7 @@ import xyz.zhouxy.plusone.exception.handler.BaseExceptionHandler.ExceptionInfoHo
|
||||
public class AllExceptionHandlerConfig {
|
||||
|
||||
@Bean
|
||||
AllExceptionHandler getAllExceptionHandler(ExceptionInfoHolder exceptionInfoHolder) {
|
||||
AllExceptionHandler getAllExceptionHandler(@Nonnull ExceptionInfoHolder exceptionInfoHolder) {
|
||||
return new AllExceptionHandler(exceptionInfoHolder);
|
||||
}
|
||||
}
|
||||
|
@@ -1,5 +1,7 @@
|
||||
package xyz.zhouxy.plusone.exception.handler;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import org.springframework.context.support.DefaultMessageSourceResolvable;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.core.annotation.Order;
|
||||
@@ -11,7 +13,8 @@ import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import xyz.zhouxy.plusone.commons.util.RestfulResult;
|
||||
import xyz.zhouxy.plusone.commons.exception.handler.BaseExceptionHandler;
|
||||
import xyz.zhouxy.plusone.commons.exception.handler.RestfulResult;
|
||||
|
||||
/**
|
||||
* 默认异常的处理器
|
||||
@@ -40,7 +43,7 @@ import xyz.zhouxy.plusone.commons.util.RestfulResult;
|
||||
@Order(Ordered.LOWEST_PRECEDENCE - 1)
|
||||
@Slf4j
|
||||
public class DefaultExceptionHandler extends BaseExceptionHandler {
|
||||
public DefaultExceptionHandler(ExceptionInfoHolder exceptionInfoHolder) {
|
||||
public DefaultExceptionHandler(@Nonnull ExceptionInfoHolder exceptionInfoHolder) {
|
||||
super(exceptionInfoHolder);
|
||||
set(IllegalArgumentException.class, 4010000, "格式错误", HttpStatus.FORBIDDEN);
|
||||
set(DataAccessException.class, 6030000, "数据库错误", HttpStatus.INTERNAL_SERVER_ERROR, true);
|
||||
|
@@ -8,6 +8,7 @@ import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import xyz.zhouxy.plusone.commons.exception.handler.BaseExceptionHandler;
|
||||
import xyz.zhouxy.plusone.commons.util.RestfulResult;
|
||||
import xyz.zhouxy.plusone.exception.SysException;
|
||||
|
||||
@@ -15,7 +16,7 @@ import xyz.zhouxy.plusone.exception.SysException;
|
||||
@Slf4j
|
||||
public class SysExceptionHandler extends BaseExceptionHandler {
|
||||
|
||||
public SysExceptionHandler(ExceptionInfoHolder exceptionInfoHolder) {
|
||||
public SysExceptionHandler(@Nonnull ExceptionInfoHolder exceptionInfoHolder) {
|
||||
super(exceptionInfoHolder);
|
||||
}
|
||||
|
||||
|
@@ -44,12 +44,12 @@
|
||||
<dependency>
|
||||
<groupId>xyz.zhouxy.plusone</groupId>
|
||||
<artifactId>plusone-validator</artifactId>
|
||||
<version>0.1.2-SNAPSHOT</version>
|
||||
<version>0.1.3-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>xyz.zhouxy.plusone</groupId>
|
||||
<artifactId>plusone-exception-handler</artifactId>
|
||||
<version>0.0.6-SNAPSHOT</version>
|
||||
<version>0.0.9-SNAPSHOT</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
@@ -2,4 +2,8 @@ package xyz.zhouxy.plusone.constant;
|
||||
|
||||
public class ErrorCodeConsts {
|
||||
public static final int DEFAULT_ERROR_CODE = 9999999;
|
||||
|
||||
private ErrorCodeConsts() {
|
||||
throw new IllegalStateException("Utility class");
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,18 @@
|
||||
package xyz.zhouxy.plusone.util;
|
||||
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
public final class RandomUtil {
|
||||
private RandomUtil() {
|
||||
throw new IllegalStateException("Utility class");
|
||||
}
|
||||
|
||||
public static String randomStr(char[] sourceCharacters, int length) {
|
||||
ThreadLocalRandom random = ThreadLocalRandom.current();
|
||||
char[] result = new char[length];
|
||||
for (int i = 0; i < length; i++) {
|
||||
result[i] = sourceCharacters[random.nextInt(sourceCharacters.length)];
|
||||
}
|
||||
return String.valueOf(result);
|
||||
}
|
||||
}
|
@@ -0,0 +1,23 @@
|
||||
package xyz.zhouxy.plusone.util;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Slf4j
|
||||
class RandomUtilTests {
|
||||
|
||||
@Test
|
||||
void testRandom() {
|
||||
String[] s = new String[20];
|
||||
for (int i = 0; i < 20; i++) {
|
||||
s[i] = RandomUtil.randomStr(
|
||||
"0123456789qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM~`!@#$%^&*()_-+={[\\|/:;\"',.<>?]}"
|
||||
.toCharArray(),
|
||||
28);
|
||||
}
|
||||
log.info("{}", Arrays.toString(s));
|
||||
}
|
||||
}
|
@@ -15,11 +15,6 @@
|
||||
<groupId>xyz.zhouxy</groupId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-core</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
|
@@ -1,5 +1,9 @@
|
||||
package xyz.zhouxy.plusone.constant;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import xyz.zhouxy.plusone.commons.util.Enumeration;
|
||||
|
||||
/**
|
||||
@@ -9,24 +13,22 @@ import xyz.zhouxy.plusone.commons.util.Enumeration;
|
||||
*/
|
||||
public final class EntityStatus extends Enumeration<EntityStatus> {
|
||||
|
||||
private EntityStatus(int value, String name) {
|
||||
super(value, name);
|
||||
private EntityStatus(int id, @Nonnull String name) {
|
||||
super(id, name);
|
||||
}
|
||||
|
||||
// 常量
|
||||
public static final EntityStatus AVAILABLE = new EntityStatus(0, "正常");
|
||||
public static final EntityStatus DISABLED = new EntityStatus(1, "禁用");
|
||||
|
||||
private static final EnumerationValuesHolder<EntityStatus> ENUMERATION_VALUES = new EnumerationValuesHolder<>(
|
||||
AVAILABLE,
|
||||
DISABLED);
|
||||
private static final ValueSet<EntityStatus> VALUE_SET = new ValueSet<>(
|
||||
AVAILABLE, DISABLED);
|
||||
|
||||
public static EntityStatus of(int value) {
|
||||
return ENUMERATION_VALUES.get(value);
|
||||
public static EntityStatus of(int id) {
|
||||
return VALUE_SET.get(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "EntityStatus" + super.toString();
|
||||
public static Collection<EntityStatus> constants() {
|
||||
return VALUE_SET.getValues();
|
||||
}
|
||||
}
|
||||
|
@@ -1,6 +1,7 @@
|
||||
package xyz.zhouxy.plusone.domain;
|
||||
|
||||
import cn.hutool.core.lang.UUID;
|
||||
import java.util.UUID;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
@@ -20,7 +21,7 @@ public abstract class DomainEvent {
|
||||
private long happenedAt;
|
||||
|
||||
protected DomainEvent() {
|
||||
this.identifier = UUID.randomUUID().toString(true);
|
||||
this.identifier = UUID.randomUUID().toString();
|
||||
this.happenedAt = System.currentTimeMillis();
|
||||
}
|
||||
}
|
||||
|
@@ -5,7 +5,7 @@ import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import xyz.zhouxy.plusone.constant.ErrorCodeConsts;
|
||||
import xyz.zhouxy.plusone.exception.handler.BaseExceptionHandler.ExceptionInfoHolder;
|
||||
import xyz.zhouxy.plusone.commons.exception.handler.BaseExceptionHandler.ExceptionInfoHolder;
|
||||
|
||||
@Configuration
|
||||
public class PlusoneExceptionHandlerConfig {
|
||||
|
@@ -86,18 +86,18 @@ public abstract class PlusoneJdbcDaoSupport {
|
||||
return update(sql, new MapSqlParameterSource(paramName, value));
|
||||
}
|
||||
|
||||
protected final int batchUpdate(String sql, SqlParameterSource[] batchArgs) {
|
||||
protected final long batchUpdate(String sql, SqlParameterSource[] batchArgs) {
|
||||
int[] i = this.jdbc.batchUpdate(sql, batchArgs);
|
||||
return NumberUtil.sum(i);
|
||||
}
|
||||
|
||||
protected final <T> int batchUpdate(String sql, Stream<T> c,
|
||||
protected final <T> long batchUpdate(String sql, Stream<T> c,
|
||||
@Nonnull Function<T, SqlParameterSource> paramSourceBuilder) {
|
||||
int[] i = this.jdbc.batchUpdate(sql, buildSqlParameterSourceArray(c, paramSourceBuilder));
|
||||
return NumberUtil.sum(i);
|
||||
}
|
||||
|
||||
protected final <T> int batchUpdate(String sql, Collection<T> c,
|
||||
protected final <T> long batchUpdate(String sql, Collection<T> c,
|
||||
@Nonnull Function<T, SqlParameterSource> paramSourceBuilder) {
|
||||
int[] i = this.jdbc.batchUpdate(sql, buildSqlParameterSourceArray(c, paramSourceBuilder));
|
||||
return NumberUtil.sum(i);
|
||||
|
@@ -1,13 +1,15 @@
|
||||
package xyz.zhouxy.plusone.validator;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||
|
||||
import xyz.zhouxy.plusone.exception.handler.BaseExceptionHandler;
|
||||
import xyz.zhouxy.plusone.commons.exception.handler.BaseExceptionHandler;
|
||||
|
||||
@RestControllerAdvice
|
||||
public class InvalidInputExceptionHandler extends BaseExceptionHandler {
|
||||
|
||||
public InvalidInputExceptionHandler(ExceptionInfoHolder exceptionInfoHolder) {
|
||||
public InvalidInputExceptionHandler(@Nonnull ExceptionInfoHolder exceptionInfoHolder) {
|
||||
super(exceptionInfoHolder);
|
||||
set(InvalidInputException.class, InvalidInputException.ERROR_CODE, "无效的用户输入");
|
||||
}
|
||||
|
@@ -1,5 +1,7 @@
|
||||
package xyz.zhouxy.plusone;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -25,6 +27,7 @@ class TestAop {
|
||||
command.setPrincipal("Code108");
|
||||
command.setPassword("2333");
|
||||
command.setRememberMe(false);
|
||||
assertNotNull(service);
|
||||
LoginInfoViewObject loginInfo = service.loginByPassword(command);
|
||||
System.err.println(loginInfo);
|
||||
}
|
||||
|
@@ -6,14 +6,14 @@ import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||
|
||||
import xyz.zhouxy.plusone.exception.handler.BaseExceptionHandler;
|
||||
import xyz.zhouxy.plusone.system.application.exception.AccountLoginException;
|
||||
import xyz.zhouxy.plusone.commons.util.RestfulResult;
|
||||
import xyz.zhouxy.plusone.commons.exception.handler.BaseExceptionHandler;
|
||||
import xyz.zhouxy.plusone.commons.exception.handler.RestfulResult;
|
||||
|
||||
@RestControllerAdvice
|
||||
public class AccountLoginExceptionHandler extends BaseExceptionHandler {
|
||||
|
||||
public AccountLoginExceptionHandler(ExceptionInfoHolder exceptionInfoHolder) {
|
||||
public AccountLoginExceptionHandler(@Nonnull ExceptionInfoHolder exceptionInfoHolder) {
|
||||
super(exceptionInfoHolder);
|
||||
}
|
||||
|
||||
|
@@ -1,5 +1,7 @@
|
||||
package xyz.zhouxy.plusone.system.application.exception.handler;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
@@ -14,8 +16,8 @@ import cn.dev33.satoken.exception.NotSafeException;
|
||||
import cn.dev33.satoken.exception.SaTokenException;
|
||||
import cn.dev33.satoken.exception.SameTokenInvalidException;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import xyz.zhouxy.plusone.exception.handler.BaseExceptionHandler;
|
||||
import xyz.zhouxy.plusone.commons.util.RestfulResult;
|
||||
import xyz.zhouxy.plusone.commons.exception.handler.BaseExceptionHandler;
|
||||
import xyz.zhouxy.plusone.commons.exception.handler.RestfulResult;
|
||||
|
||||
/**
|
||||
* Sa-Token 异常处理器
|
||||
@@ -27,7 +29,7 @@ import xyz.zhouxy.plusone.commons.util.RestfulResult;
|
||||
public class SaTokenExceptionHandler extends BaseExceptionHandler {
|
||||
|
||||
|
||||
public SaTokenExceptionHandler(ExceptionInfoHolder exceptionInfoHolder) {
|
||||
public SaTokenExceptionHandler(@Nonnull ExceptionInfoHolder exceptionInfoHolder) {
|
||||
super(exceptionInfoHolder);
|
||||
set(NotPermissionException.class, 4030103, "会话未能通过权限认证", HttpStatus.FORBIDDEN);
|
||||
set(NotRoleException.class, 4030103, "会话未能通过角色认证", HttpStatus.FORBIDDEN);
|
||||
|
@@ -2,6 +2,8 @@ package xyz.zhouxy.plusone.system.application.query;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import xyz.zhouxy.plusone.commons.util.PageDTO;
|
||||
@@ -23,6 +25,7 @@ public interface AccountQueries {
|
||||
return PageDTO.of(content, total);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
List<AccountOverview> queryAccountOverview(AccountQueryParams queryParams);
|
||||
|
||||
long count(AccountQueryParams queryParams);
|
||||
|
@@ -109,7 +109,7 @@ public class MenuViewObject implements IWithOrderNumber {
|
||||
viewObject.icon = menu.getIcon();
|
||||
viewObject.hidden = menu.isHidden();
|
||||
viewObject.orderNumber = menu.getOrderNumber();
|
||||
viewObject.status = menu.getStatus().getValue();
|
||||
viewObject.status = menu.getStatus().getId();
|
||||
viewObject.remarks = menu.getRemarks();
|
||||
if (viewObject.type == MenuType.MENU_ITEM.ordinal()) {
|
||||
viewObject.component = menu.getComponent();
|
||||
|
@@ -26,8 +26,10 @@ import xyz.zhouxy.plusone.system.application.service.command.UpdateAccountComman
|
||||
import xyz.zhouxy.plusone.system.domain.model.account.Account;
|
||||
import xyz.zhouxy.plusone.system.domain.model.account.AccountInfo;
|
||||
import xyz.zhouxy.plusone.system.domain.model.account.AccountRepository;
|
||||
import xyz.zhouxy.plusone.system.domain.model.account.AccountStatus;
|
||||
import xyz.zhouxy.plusone.system.domain.model.account.Email;
|
||||
import xyz.zhouxy.plusone.system.domain.model.account.MobilePhone;
|
||||
import xyz.zhouxy.plusone.system.domain.model.account.Sex;
|
||||
import xyz.zhouxy.plusone.system.domain.model.account.Username;
|
||||
import xyz.zhouxy.plusone.util.AssertResult;
|
||||
|
||||
@@ -67,12 +69,12 @@ public class AccountManagementService {
|
||||
mobilePhone,
|
||||
command.getPassword(),
|
||||
command.getPasswordConfirmation(),
|
||||
command.getStatus(),
|
||||
AccountStatus.of(command.getStatus()),
|
||||
command.getRoleRefs(),
|
||||
AccountInfo.builder()
|
||||
.nickname(command.getNickname())
|
||||
.avatar(command.getAvatar())
|
||||
.sex(command.getSex())
|
||||
.sex(Sex.of(command.getSex()))
|
||||
.build(),
|
||||
adminAuthLogic.getLoginIdAsLong());
|
||||
accountRepository.save(account);
|
||||
@@ -91,7 +93,7 @@ public class AccountManagementService {
|
||||
Assert.isTrue(Objects.equals(id, command.getId()), "参数错误: id 不匹配");
|
||||
Account account = accountRepository.find(id)
|
||||
.orElseThrow(() -> new DataNotExistException("该账号不存在"));
|
||||
account.setAccountInfo(command.getNickname(), command.getAvatar(), command.getSex());
|
||||
account.setAccountInfo(command.getNickname(), command.getAvatar(), Sex.of(command.getSex()));
|
||||
account.setUpdatedBy(adminAuthLogic.getLoginIdAsLong());
|
||||
accountRepository.save(account);
|
||||
}
|
||||
|
@@ -13,6 +13,7 @@ import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import xyz.zhouxy.plusone.constant.EntityStatus;
|
||||
import xyz.zhouxy.plusone.domain.IWithOrderNumber;
|
||||
import xyz.zhouxy.plusone.exception.DataNotExistException;
|
||||
import xyz.zhouxy.plusone.system.application.exception.UnsupportedMenuTypeException;
|
||||
@@ -66,7 +67,7 @@ public class MenuManagementService {
|
||||
command.getIcon(),
|
||||
command.getHidden(),
|
||||
command.getOrderNumber(),
|
||||
command.getStatus(),
|
||||
EntityStatus.of(command.getStatus()),
|
||||
command.getRemarks());
|
||||
}
|
||||
|
||||
@@ -79,7 +80,7 @@ public class MenuManagementService {
|
||||
command.getIcon(),
|
||||
command.getHidden(),
|
||||
command.getOrderNumber(),
|
||||
command.getStatus(),
|
||||
EntityStatus.of(command.getStatus()),
|
||||
command.getComponent(),
|
||||
command.getResource(),
|
||||
command.getCache(),
|
||||
@@ -107,7 +108,7 @@ public class MenuManagementService {
|
||||
command.getIcon(),
|
||||
command.getHidden(),
|
||||
command.getOrderNumber(),
|
||||
command.getStatus(),
|
||||
EntityStatus.of(command.getStatus()),
|
||||
command.getComponent(),
|
||||
command.getResource(),
|
||||
command.getCache(),
|
||||
|
@@ -10,6 +10,7 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import xyz.zhouxy.plusone.constant.EntityStatus;
|
||||
import xyz.zhouxy.plusone.exception.DataNotExistException;
|
||||
import xyz.zhouxy.plusone.system.application.query.RoleQueries;
|
||||
import xyz.zhouxy.plusone.system.application.query.params.RoleQueryParams;
|
||||
@@ -54,7 +55,7 @@ public class RoleManagementService {
|
||||
Role roleToCreate = Role.newInstance(
|
||||
command.getName(),
|
||||
command.getIdentifier(),
|
||||
command.getStatus(),
|
||||
EntityStatus.of(command.getStatus()),
|
||||
command.getRemarks(),
|
||||
menuRefs,
|
||||
permissionRefs);
|
||||
@@ -67,7 +68,7 @@ public class RoleManagementService {
|
||||
roleToUpdate.update(
|
||||
command.getName(),
|
||||
command.getIdentifier(),
|
||||
command.getStatus(),
|
||||
EntityStatus.of(command.getStatus()),
|
||||
command.getRemarks(),
|
||||
Set.copyOf(_menuRepository.findByIdIn(command.getMenus())),
|
||||
Set.copyOf(_menuRepository.findPermissionsByIdIn(command.getPermissions())));
|
||||
|
@@ -12,8 +12,6 @@ import org.hibernate.validator.constraints.URL;
|
||||
import lombok.Data;
|
||||
import xyz.zhouxy.plusone.commons.constant.RegexConsts;
|
||||
import xyz.zhouxy.plusone.domain.ICommand;
|
||||
import xyz.zhouxy.plusone.system.domain.model.account.AccountStatus;
|
||||
import xyz.zhouxy.plusone.system.domain.model.account.Sex;
|
||||
|
||||
/**
|
||||
* 创建账号命令
|
||||
@@ -41,7 +39,7 @@ public class CreateAccountCommand implements ICommand {
|
||||
String passwordConfirmation;
|
||||
|
||||
@NotNull
|
||||
AccountStatus status;
|
||||
Integer status;
|
||||
|
||||
Set<Long> roleRefs;
|
||||
|
||||
@@ -52,5 +50,5 @@ public class CreateAccountCommand implements ICommand {
|
||||
@URL
|
||||
String avatar;
|
||||
|
||||
Sex sex;
|
||||
Integer sex;
|
||||
}
|
||||
|
@@ -5,7 +5,6 @@ import javax.validation.constraints.NotNull;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import xyz.zhouxy.plusone.constant.EntityStatus;
|
||||
import xyz.zhouxy.plusone.domain.ICommand;
|
||||
import xyz.zhouxy.plusone.system.domain.model.menu.Menu.MenuType;
|
||||
|
||||
@@ -42,7 +41,7 @@ public class CreateMenuCommand implements ICommand {
|
||||
private Integer orderNumber;
|
||||
|
||||
@NotNull
|
||||
private EntityStatus status;
|
||||
private Integer status;
|
||||
|
||||
private String component;
|
||||
|
||||
|
@@ -6,7 +6,6 @@ import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
import lombok.Data;
|
||||
import xyz.zhouxy.plusone.constant.EntityStatus;
|
||||
import xyz.zhouxy.plusone.domain.ICommand;
|
||||
|
||||
/**
|
||||
@@ -23,7 +22,7 @@ public class CreateRoleCommand implements ICommand {
|
||||
String identifier;
|
||||
|
||||
@NotNull
|
||||
EntityStatus status;
|
||||
Integer status;
|
||||
String remarks;
|
||||
|
||||
Set<Long> menus;
|
||||
|
@@ -8,7 +8,6 @@ import org.hibernate.validator.constraints.URL;
|
||||
import lombok.Data;
|
||||
import xyz.zhouxy.plusone.commons.constant.RegexConsts;
|
||||
import xyz.zhouxy.plusone.domain.ICommand;
|
||||
import xyz.zhouxy.plusone.system.domain.model.account.Sex;
|
||||
|
||||
/**
|
||||
* 更新账号信息命令
|
||||
@@ -27,5 +26,5 @@ public class UpdateAccountCommand implements ICommand {
|
||||
@URL
|
||||
String avatar;
|
||||
|
||||
Sex sex;
|
||||
Integer sex;
|
||||
}
|
||||
|
@@ -5,7 +5,6 @@ import javax.validation.constraints.NotNull;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import xyz.zhouxy.plusone.constant.EntityStatus;
|
||||
import xyz.zhouxy.plusone.domain.ICommand;
|
||||
import xyz.zhouxy.plusone.system.domain.model.menu.Menu.MenuType;
|
||||
|
||||
@@ -46,7 +45,7 @@ public class UpdateMenuCommand implements ICommand {
|
||||
private Integer orderNumber;
|
||||
|
||||
@NotNull
|
||||
private EntityStatus status;
|
||||
private Integer status;
|
||||
|
||||
private String component;
|
||||
|
||||
|
@@ -6,7 +6,6 @@ import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
import lombok.Data;
|
||||
import xyz.zhouxy.plusone.constant.EntityStatus;
|
||||
import xyz.zhouxy.plusone.domain.ICommand;
|
||||
|
||||
/**
|
||||
@@ -27,7 +26,7 @@ public class UpdateRoleCommand implements ICommand {
|
||||
String identifier;
|
||||
|
||||
@NotNull
|
||||
EntityStatus status;
|
||||
Integer status;
|
||||
|
||||
@NotBlank
|
||||
String remarks;
|
||||
|
@@ -14,10 +14,6 @@
|
||||
<groupId>xyz.zhouxy</groupId>
|
||||
<artifactId>plusone-basic-common</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-crypto</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
@@ -1,19 +1,26 @@
|
||||
package xyz.zhouxy.plusone.system.util;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import cn.hutool.crypto.digest.DigestUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import xyz.zhouxy.plusone.constant.ErrorCodeConsts;
|
||||
import xyz.zhouxy.plusone.exception.BizException;
|
||||
import xyz.zhouxy.plusone.util.RandomUtil;
|
||||
|
||||
/**
|
||||
* 密码工具类
|
||||
*
|
||||
* @author <a href="https://gitee.com/zhouxy108">ZhouXY</a>
|
||||
*/
|
||||
@Slf4j
|
||||
public final class PasswordUtil {
|
||||
private static final String SALT_BASE_STRING = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ~`!@#$%^&*()_-+={}[]|\\:;\"',.<>?/";
|
||||
private static final char[] SALT_BASE_CHAR_ARRAY = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ~`!@#$%^&*()_-+={}[]|\\:;\"',.<>?/"
|
||||
.toCharArray();
|
||||
|
||||
/**
|
||||
* 将密码和随机盐混合,并进行哈希加密。
|
||||
@@ -29,7 +36,7 @@ public final class PasswordUtil {
|
||||
var passwordWithSalt = salt.substring(0, i)
|
||||
+ password
|
||||
+ salt.substring(1);
|
||||
String sha512Hex = DigestUtil.sha512Hex(passwordWithSalt);
|
||||
String sha512Hex = sha512Hex(passwordWithSalt);
|
||||
if (sha512Hex == null) {
|
||||
throw new BizException(ErrorCodeConsts.DEFAULT_ERROR_CODE, "未知错误:哈希加密失败!");
|
||||
}
|
||||
@@ -42,11 +49,23 @@ public final class PasswordUtil {
|
||||
* @return 生成的随机盐
|
||||
*/
|
||||
public static String generateRandomSalt() {
|
||||
return RandomUtil.randomString(SALT_BASE_STRING, 24);
|
||||
return RandomUtil.randomStr(SALT_BASE_CHAR_ARRAY, 24);
|
||||
}
|
||||
|
||||
private PasswordUtil() {
|
||||
// 不允许实例化
|
||||
throw new IllegalStateException("Utility class");
|
||||
}
|
||||
|
||||
private static String sha512Hex(String data) {
|
||||
try {
|
||||
MessageDigest messageDigest = MessageDigest.getInstance("SHA-512");
|
||||
messageDigest.update(data.getBytes(StandardCharsets.UTF_8));
|
||||
byte[] result = messageDigest.digest();
|
||||
return new BigInteger(1, result).toString(16);
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
log.error("{}", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@@ -1,5 +1,9 @@
|
||||
package xyz.zhouxy.plusone.system.domain.model.account;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import lombok.Getter;
|
||||
import xyz.zhouxy.plusone.commons.util.Enumeration;
|
||||
import xyz.zhouxy.plusone.domain.IValueObject;
|
||||
@@ -12,18 +16,22 @@ import xyz.zhouxy.plusone.domain.IValueObject;
|
||||
@Getter
|
||||
public final class AccountStatus extends Enumeration<AccountStatus> implements IValueObject {
|
||||
|
||||
private AccountStatus(int value, String name) {
|
||||
super(value, name);
|
||||
private AccountStatus(int id, @Nonnull String name) {
|
||||
super(id, name);
|
||||
}
|
||||
|
||||
public static final AccountStatus AVAILABLE = new AccountStatus(0, "账号正常");
|
||||
public static final AccountStatus LOCKED = new AccountStatus(1, "账号被锁定");
|
||||
|
||||
private static final EnumerationValuesHolder<AccountStatus> ENUMERATION_VALUES = new EnumerationValuesHolder<>(
|
||||
private static final ValueSet<AccountStatus> VALUE_SET = new ValueSet<>(
|
||||
AVAILABLE,
|
||||
LOCKED);
|
||||
|
||||
public static AccountStatus of(int value) {
|
||||
return ENUMERATION_VALUES.get(value);
|
||||
public static AccountStatus of(int id) {
|
||||
return VALUE_SET.get(id);
|
||||
}
|
||||
|
||||
public static Collection<AccountStatus> constants() {
|
||||
return VALUE_SET.getValues();
|
||||
}
|
||||
}
|
||||
|
@@ -1,5 +1,7 @@
|
||||
package xyz.zhouxy.plusone.system.domain.model.account;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import xyz.zhouxy.plusone.commons.util.Enumeration;
|
||||
@@ -18,16 +20,17 @@ public final class Sex extends Enumeration<Sex> implements IValueObject {
|
||||
@Nonnull
|
||||
public static final Sex FEMALE = new Sex(2, "女性");
|
||||
|
||||
private Sex(int value, String name) {
|
||||
super(value, name);
|
||||
private Sex(int id, @Nonnull String name) {
|
||||
super(id, name);
|
||||
}
|
||||
|
||||
private static EnumerationValuesHolder<Sex> values = new EnumerationValuesHolder<>(
|
||||
UNSET,
|
||||
MALE,
|
||||
FEMALE);
|
||||
private static final ValueSet<Sex> VALUE_SET = new ValueSet<>(UNSET, MALE, FEMALE);
|
||||
|
||||
public static Sex of(int value) {
|
||||
return values.get(value);
|
||||
return VALUE_SET.get(value);
|
||||
}
|
||||
|
||||
public static Collection<Sex> constants() {
|
||||
return VALUE_SET.getValues();
|
||||
}
|
||||
}
|
||||
|
@@ -206,9 +206,9 @@ public class AccountRepositoryImpl extends JdbcRepositorySupport<Account, Long>
|
||||
.addValue("password", entity.getPassword().value())
|
||||
.addValue("salt", entity.getPassword().getSalt())
|
||||
.addValue("avatar", accountInfo.getAvatar().toString())
|
||||
.addValue("sex", accountInfo.getSex().getValue())
|
||||
.addValue("sex", accountInfo.getSex().getId())
|
||||
.addValue("nickname", getValueOrNull(accountInfo.getNickname()))
|
||||
.addValue("status", entity.getStatus().getValue())
|
||||
.addValue("status", entity.getStatus().getId())
|
||||
.addValue("createdBy", entity.getCreatedBy())
|
||||
.addValue("createTime", now)
|
||||
.addValue("updatedBy", entity.getUpdatedBy())
|
||||
|
@@ -31,7 +31,7 @@ class AccountRoleRefDAO extends PlusoneJdbcDaoSupport {
|
||||
}
|
||||
|
||||
void insertAccountRoleRefs(Long accountId, Set<Long> roleRefs) {
|
||||
int i = batchUpdate(
|
||||
long i = batchUpdate(
|
||||
"INSERT INTO sys_account_role (account_id, role_id) VALUES (:accountId, :roleId)",
|
||||
roleRefs,
|
||||
(Long roleId) -> new MapSqlParameterSource()
|
||||
|
@@ -21,11 +21,11 @@ class DictValueDAO extends PlusoneJdbcDaoSupport {
|
||||
void updateDictValues(Dict entity) {
|
||||
update("DELETE FROM sys_dict_value WHERE dict_type = :dictType",
|
||||
"dictType", entity.getId().orElseThrow());
|
||||
int i = insertDictValues(entity.getId().orElseThrow(), entity);
|
||||
long i = insertDictValues(entity.getId().orElseThrow(), entity);
|
||||
assertResultEquals(i, entity.count());
|
||||
}
|
||||
|
||||
int insertDictValues(Long dictId, Dict entity) {
|
||||
long insertDictValues(Long dictId, Dict entity) {
|
||||
if (Objects.isNull(dictId) || Objects.isNull(entity) || CollectionUtils.isEmpty(entity.getValues())) {
|
||||
return 0;
|
||||
}
|
||||
|
@@ -188,7 +188,7 @@ public class MenuRepositoryImpl extends JdbcRepositorySupport<Menu, Long> implem
|
||||
.addValue("icon", entity.getIcon())
|
||||
.addValue("hidden", entity.isHidden())
|
||||
.addValue("orderNumber", entity.getOrderNumber())
|
||||
.addValue("status", entity.getStatus().getValue())
|
||||
.addValue("status", entity.getStatus().getId())
|
||||
.addValue("remarks", entity.getRemarks())
|
||||
.addValue("component", entity.getComponent())
|
||||
.addValue("cache", entity.getCache())
|
||||
|
@@ -29,7 +29,7 @@ class RoleMenuRefDAO extends PlusoneJdbcDaoSupport {
|
||||
}
|
||||
|
||||
void saveRoleMenuRefs(Long roleId, Role entity) {
|
||||
int i = batchUpdate(
|
||||
long i = batchUpdate(
|
||||
"INSERT INTO sys_role_menu(role_id, menu_id) VALUES (:roleId, :menuId)",
|
||||
entity.getMenus(),
|
||||
menuRef -> new MapSqlParameterSource()
|
||||
|
@@ -30,7 +30,7 @@ class RolePermissionRefDAO extends PlusoneJdbcDaoSupport {
|
||||
}
|
||||
|
||||
void saveRolePermissionRefs(Long roleId, Role entity) {
|
||||
int i = batchUpdate(
|
||||
long i = batchUpdate(
|
||||
"INSERT INTO sys_role_permission(role_id, permission_id) VALUES (:roleId, :permissionId)",
|
||||
entity.getPermissions(),
|
||||
actionRef -> new MapSqlParameterSource()
|
||||
|
@@ -135,7 +135,7 @@ public class RoleRepositoryImpl extends JdbcRepositorySupport<Role, Long> implem
|
||||
.addValue("id", id)
|
||||
.addValue("name", entity.getName())
|
||||
.addValue("identifier", entity.getIdentifier())
|
||||
.addValue("status", entity.getStatus().getValue())
|
||||
.addValue("status", entity.getStatus().getId())
|
||||
.addValue("remarks", entity.getRemarks())
|
||||
.addValue("createTime", now)
|
||||
.addValue("createdBy", loginId)
|
||||
|
@@ -67,6 +67,10 @@
|
||||
</dependencyManagement>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-api</artifactId>
|
||||
|
22
pom.xml
22
pom.xml
@@ -25,15 +25,15 @@
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
|
||||
<spring-boot.version>2.7.9</spring-boot.version>
|
||||
<spring-boot.version>2.7.10</spring-boot.version>
|
||||
<sa-token.version>1.34.0</sa-token.version>
|
||||
<hutool.version>5.8.14</hutool.version>
|
||||
<hutool.version>5.8.16</hutool.version>
|
||||
<mybatis-starter.version>3.0.1</mybatis-starter.version>
|
||||
<mybatis-plus.version>3.5.3.1</mybatis-plus.version>
|
||||
<commons-io.version>2.11.0</commons-io.version>
|
||||
<mica.version>2.7.5</mica.version>
|
||||
<mapstruct.version>1.5.3.Final</mapstruct.version>
|
||||
<guava.version>31.1-jre</guava.version>
|
||||
<guava.version>30.1-jre</guava.version>
|
||||
<commons-lang3.version>3.12.0</commons-lang3.version>
|
||||
<commons-collections4.version>4.4</commons-collections4.version>
|
||||
<commons-math3.version>3.6.1</commons-math3.version>
|
||||
@@ -91,16 +91,7 @@
|
||||
<artifactId>hutool-core</artifactId>
|
||||
<version>${hutool.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-crypto</artifactId>
|
||||
<version>${hutool.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-captcha</artifactId>
|
||||
<version>${hutool.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
@@ -186,11 +177,6 @@
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-classic</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.code.findbugs</groupId>
|
||||
<artifactId>jsr305</artifactId>
|
||||
<version>3.0.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
|
Reference in New Issue
Block a user