diff --git a/.gitignore b/.gitignore index eb3eb56..d0334d0 100644 --- a/.gitignore +++ b/.gitignore @@ -32,6 +32,8 @@ build/ ### VS Code ### .vscode/ +log/ ### bak ### *.bak +*-secret.yaml diff --git a/plusone-basic/plusone-basic-application/src/main/java/xyz/zhouxy/plusone/exception/config/PlusoneExceptionHandlerConfig.java b/plusone-basic/plusone-basic-application/src/main/java/xyz/zhouxy/plusone/exception/config/PlusoneExceptionHandlerConfig.java deleted file mode 100644 index fd871aa..0000000 --- a/plusone-basic/plusone-basic-application/src/main/java/xyz/zhouxy/plusone/exception/config/PlusoneExceptionHandlerConfig.java +++ /dev/null @@ -1,18 +0,0 @@ -package xyz.zhouxy.plusone.exception.config; - -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -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; - -@Configuration -public class PlusoneExceptionHandlerConfig { - - @Bean - @ConditionalOnMissingBean - ExceptionInfoHolder exceptionInfoHolder() { - return new ExceptionInfoHolder(ErrorCodeConsts.DEFAULT_ERROR_CODE); - } -} diff --git a/plusone-basic/plusone-basic-application/src/main/java/xyz/zhouxy/plusone/exception/handler/AllExceptionHandlerConfig.java b/plusone-basic/plusone-basic-application/src/main/java/xyz/zhouxy/plusone/exception/handler/AllExceptionHandlerConfig.java index fd05fdb..b74d637 100644 --- a/plusone-basic/plusone-basic-application/src/main/java/xyz/zhouxy/plusone/exception/handler/AllExceptionHandlerConfig.java +++ b/plusone-basic/plusone-basic-application/src/main/java/xyz/zhouxy/plusone/exception/handler/AllExceptionHandlerConfig.java @@ -4,8 +4,6 @@ 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; - /** * AllExceptionHandlerConfig */ @@ -14,7 +12,7 @@ import xyz.zhouxy.plusone.exception.handler.BaseExceptionHandler.ExceptionInfoHo public class AllExceptionHandlerConfig { @Bean - AllExceptionHandler getAllExceptionHandler(ExceptionInfoHolder exceptionInfoHolder) { - return new AllExceptionHandler(exceptionInfoHolder); + AllExceptionHandler getAllExceptionHandler() { + return new AllExceptionHandler(ExceptionInfoHolderFactory.newDefaultExceptionInfoHolder()); } } diff --git a/plusone-basic/plusone-basic-application/src/main/java/xyz/zhouxy/plusone/exception/handler/DefaultExceptionHandler.java b/plusone-basic/plusone-basic-application/src/main/java/xyz/zhouxy/plusone/exception/handler/DefaultExceptionHandler.java index af53870..a63630e 100644 --- a/plusone-basic/plusone-basic-application/src/main/java/xyz/zhouxy/plusone/exception/handler/DefaultExceptionHandler.java +++ b/plusone-basic/plusone-basic-application/src/main/java/xyz/zhouxy/plusone/exception/handler/DefaultExceptionHandler.java @@ -41,13 +41,13 @@ import xyz.zhouxy.plusone.util.RestfulResult; @Slf4j public class DefaultExceptionHandler extends BaseExceptionHandler { - public DefaultExceptionHandler(ExceptionInfoHolder exceptionInfoHolder) { - super(exceptionInfoHolder); + public DefaultExceptionHandler() { + super(ExceptionInfoHolderFactory.newDefaultExceptionInfoHolder()); set(IllegalArgumentException.class, 4010000, "格式错误", HttpStatus.FORBIDDEN); set(DataAccessException.class, 6030000, "数据库错误", HttpStatus.INTERNAL_SERVER_ERROR, true); set(MethodArgumentNotValidException.class, 4040401, - e -> ((MethodArgumentNotValidException) e).getAllErrors() + e -> e.getAllErrors() .stream() .map(DefaultMessageSourceResolvable::getDefaultMessage) .toList() diff --git a/plusone-basic/plusone-basic-common/pom.xml b/plusone-basic/plusone-basic-common/pom.xml index 14aa305..6fdebe7 100644 --- a/plusone-basic/plusone-basic-common/pom.xml +++ b/plusone-basic/plusone-basic-common/pom.xml @@ -1,5 +1,5 @@ - + 4.0.0 plusone-basic @@ -39,12 +39,12 @@ xyz.zhouxy.plusone plusone-validator - 0.0.1-SNAPSHOT + 0.1.0-SNAPSHOT xyz.zhouxy.plusone plusone-exception-handler - 0.0.5-SNAPSHOT + 0.0.6-SNAPSHOT diff --git a/plusone-basic/plusone-basic-infrastructure/src/main/java/xyz/zhouxy/plusone/exception/handler/ExceptionInfoHolderFactory.java b/plusone-basic/plusone-basic-infrastructure/src/main/java/xyz/zhouxy/plusone/exception/handler/ExceptionInfoHolderFactory.java new file mode 100644 index 0000000..bf5837d --- /dev/null +++ b/plusone-basic/plusone-basic-infrastructure/src/main/java/xyz/zhouxy/plusone/exception/handler/ExceptionInfoHolderFactory.java @@ -0,0 +1,15 @@ +package xyz.zhouxy.plusone.exception.handler; + +import xyz.zhouxy.plusone.constant.ErrorCodeConsts; +import xyz.zhouxy.plusone.exception.handler.BaseExceptionHandler.ExceptionInfoHolder; + +public class ExceptionInfoHolderFactory { + + private ExceptionInfoHolderFactory() { + throw new IllegalStateException("Utility class"); + } + + public static ExceptionInfoHolder newDefaultExceptionInfoHolder() { + return new ExceptionInfoHolder(ErrorCodeConsts.DEFAULT_ERROR_CODE); + } +} diff --git a/plusone-basic/plusone-basic-infrastructure/src/main/java/xyz/zhouxy/plusone/sql/SQL.java b/plusone-basic/plusone-basic-infrastructure/src/main/java/xyz/zhouxy/plusone/sql/SQL.java deleted file mode 100644 index df2867c..0000000 --- a/plusone-basic/plusone-basic-infrastructure/src/main/java/xyz/zhouxy/plusone/sql/SQL.java +++ /dev/null @@ -1,34 +0,0 @@ -package xyz.zhouxy.plusone.sql; - -import java.util.Objects; - -import org.apache.ibatis.jdbc.AbstractSQL; - -/** - * 扩展 MyBatis 中的 SQL 语句构造器 - * - * @author ZhouXY - */ -public class SQL extends AbstractSQL { - - public SQL SET_IF(boolean condition, String sets) { - return condition ? SET(sets) : getSelf(); - } - - public SQL SET_IF_NOT_NULL(Object param, String sets) { - return Objects.nonNull(param) ? SET(sets) : getSelf(); - } - - public SQL WHERE_IF(boolean condition, String sqlCondition) { - return condition ? WHERE(sqlCondition) : getSelf(); - } - - public SQL WHERE_IF_NOT_NULL(Object param, String sqlCondition) { - return Objects.nonNull(param) ? WHERE(sqlCondition) : getSelf(); - } - - @Override - public SQL getSelf() { - return this; - } -} diff --git a/plusone-basic/plusone-basic-infrastructure/src/main/java/xyz/zhouxy/plusone/validator/InvalidInputExceptionHandler.java b/plusone-basic/plusone-basic-infrastructure/src/main/java/xyz/zhouxy/plusone/validator/InvalidInputExceptionHandler.java index f987fec..b8eef0f 100644 --- a/plusone-basic/plusone-basic-infrastructure/src/main/java/xyz/zhouxy/plusone/validator/InvalidInputExceptionHandler.java +++ b/plusone-basic/plusone-basic-infrastructure/src/main/java/xyz/zhouxy/plusone/validator/InvalidInputExceptionHandler.java @@ -2,14 +2,14 @@ package xyz.zhouxy.plusone.validator; import org.springframework.web.bind.annotation.RestControllerAdvice; -import xyz.zhouxy.plusone.constant.ErrorCodeConsts; import xyz.zhouxy.plusone.exception.handler.BaseExceptionHandler; +import xyz.zhouxy.plusone.exception.handler.ExceptionInfoHolderFactory; @RestControllerAdvice public class InvalidInputExceptionHandler extends BaseExceptionHandler { protected InvalidInputExceptionHandler() { - super(new ExceptionInfoHolder(ErrorCodeConsts.DEFAULT_ERROR_CODE)); + super(ExceptionInfoHolderFactory.newDefaultExceptionInfoHolder()); set(InvalidInputException.class, InvalidInputException.ERROR_CODE, "无效的用户输入"); } } diff --git a/plusone-basic/plusone-basic-infrastructure/src/test/java/xyz/zhouxy/plusone/validatortest/BaseValidator2Test.java b/plusone-basic/plusone-basic-infrastructure/src/test/java/xyz/zhouxy/plusone/validatortest/BaseValidator2Test.java index e908fe1..954e9ab 100644 --- a/plusone-basic/plusone-basic-infrastructure/src/test/java/xyz/zhouxy/plusone/validatortest/BaseValidator2Test.java +++ b/plusone-basic/plusone-basic-infrastructure/src/test/java/xyz/zhouxy/plusone/validatortest/BaseValidator2Test.java @@ -6,7 +6,7 @@ import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; import xyz.zhouxy.plusone.constant.RegexConsts; -import xyz.zhouxy.plusone.validator.validator2.BaseValidator2; +import xyz.zhouxy.plusone.validator.BaseValidator; class BaseValidator2Test { @@ -27,15 +27,16 @@ class LoginCommand { private boolean rememberMe; } -class LoginCommandValidator extends BaseValidator2 { +class LoginCommandValidator extends BaseValidator { public static final LoginCommandValidator INSTANCE = new LoginCommandValidator(); private LoginCommandValidator() { - ruleFor(LoginCommand::getAccount) + ruleForString(LoginCommand::getAccount) .notNull("邮箱地址不能为空") - .matchesOr(new String[] { RegexConsts.EMAIL, RegexConsts.MOBILE_PHONE }, value -> new RuntimeException('"' + value + "\" 不是邮箱地址或手机号")); - ruleFor(LoginCommand::getPwd) + .matchesOr(new String[] { RegexConsts.EMAIL, RegexConsts.MOBILE_PHONE }, + value -> new RuntimeException('"' + value + "\" 不是邮箱地址或手机号")); + ruleForString(LoginCommand::getPwd) .notNull("密码不能为空") .notEmpty("密码不能为空") .matches(RegexConsts.PASSWORD, "密码格式错误"); diff --git a/plusone-start/pom.xml b/plusone-start/pom.xml index e5bdcb4..56478b1 100644 --- a/plusone-start/pom.xml +++ b/plusone-start/pom.xml @@ -15,10 +15,6 @@ 参考 DDD 落地的脚手架 - - 2.7.6 - - diff --git a/plusone-start/src/main/resources/application-public.yaml b/plusone-start/src/main/resources/application-public.yaml new file mode 100644 index 0000000..a6a5b1e --- /dev/null +++ b/plusone-start/src/main/resources/application-public.yaml @@ -0,0 +1,69 @@ +spring: + # redis配置 + redis: + # Redis数据库索引(默认为0) + database: 1 + # Redis服务器地址 + host: 127.0.0.1 + # Redis服务器连接端口 + port: 6379 + # Redis服务器连接密码(默认为空) + # password: + # 连接超时时间 + timeout: 10s + lettuce: + pool: + # 连接池最大连接数 + max-active: 200 + # 连接池最大阻塞等待时间(使用负值表示没有限制) + max-wait: -1ms + # 连接池中的最大空闲连接 + max-idle: 10 + # 连接池中的最小空闲连接 + min-idle: 0 + # 数据库 + datasource: + url: jdbc:postgresql://localhost:5432/plusone + username: plusone + password: XXXXXXXXXXXXXXXX + +plusone: + application: + name: plusone + server: + port: 8108 + debug: true + # 短信发送相关参数 + sms: + region: ap-guangzhou + credential: + secret-id: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX + secret-key: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX + client: + # SDK 默认用 TC3-HMAC-SHA256 进行签名,非必要请不要修改这个字段 + sign-method: HmacSHA256 + http: + # proxy: + # host: xxx + # port: xxx + req-method: POST + conn-timeout: 60 + app-id: 1111111111 + templates: + code: 0000000 + + # 邮件发送相关参数 + mail: + host: smtp.163.com + #设置邮件发送者 + from: example@163.com + password: XXXXXXXXXXXXXXXX + + # 异常拦截机制是否拦截所有异常 + exception: + handle-all-exception: false + +# 日志配置 +logging: + level: + root: debug diff --git a/plusone-start/src/main/resources/application.yaml b/plusone-start/src/main/resources/application.yaml index 80c6303..4a48e74 100644 --- a/plusone-start/src/main/resources/application.yaml +++ b/plusone-start/src/main/resources/application.yaml @@ -1,79 +1,11 @@ +spring: + profiles: + active: public + plusone: - application: - name: plusone - server: - port: 8108 - debug: true - - # 短信发送相关参数 - sms: - region: ap-guangzhou - credential: - secret-id: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX - secret-key: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX - client: - # SDK 默认用 TC3-HMAC-SHA256 进行签名,非必要请不要修改这个字段 - sign-method: HmacSHA256 - http: - # proxy: - # host: xxx - # port: xxx - req-method: POST - conn-timeout: 60 - app-id: 1111111111 - templates: - code: 0000000 - # 邮件发送相关参数 mail: - host: smtp.163.com - #设置邮件发送者 - from: example@163.com - password: XXXXXXXXXXXXXXXX subject: code: Plusone template: code: 【Plusone】验证码:%s,10分钟内有效,请勿泄露。 - - # 异常拦截机制是否拦截所有异常 - exception: - handle-all-exception: false - -spring: - # redis配置 - redis: - # Redis数据库索引(默认为0) - database: 1 - # Redis服务器地址 - host: 127.0.0.1 - # Redis服务器连接端口 - port: 6379 - # Redis服务器连接密码(默认为空) - # password: - # 连接超时时间 - timeout: 10s - lettuce: - pool: - # 连接池最大连接数 - max-active: 200 - # 连接池最大阻塞等待时间(使用负值表示没有限制) - max-wait: -1ms - # 连接池中的最大空闲连接 - max-idle: 10 - # 连接池中的最小空闲连接 - min-idle: 0 - # 数据库 - datasource: - url: jdbc:postgresql://localhost:5432/plusone - username: plusone - password: XXXXXXXXXXXXXXXX - -# 日志配置 -logging: - file: - name: ${user.home}/logs/${plusone.application.name}.log - level: - root: INFO - xyz.zhouxy.plusone: DEBUG - org.springframework.jdbc.core: DEBUG - xyz.zhouxy.plusone.system.application.query: DEBUG diff --git a/plusone-start/src/main/resources/logback.xml b/plusone-start/src/main/resources/logback.xml index de3d0d4..dd9c22e 100644 --- a/plusone-start/src/main/resources/logback.xml +++ b/plusone-start/src/main/resources/logback.xml @@ -10,23 +10,23 @@ - + - + diff --git a/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/exception/handler/AccountLoginExceptionHandler.java b/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/exception/handler/AccountLoginExceptionHandler.java new file mode 100644 index 0000000..e742c38 --- /dev/null +++ b/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/exception/handler/AccountLoginExceptionHandler.java @@ -0,0 +1,25 @@ +package xyz.zhouxy.plusone.system.application.exception.handler; + +import javax.annotation.Nonnull; + +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.exception.handler.ExceptionInfoHolderFactory; +import xyz.zhouxy.plusone.system.application.exception.AccountLoginException; +import xyz.zhouxy.plusone.util.RestfulResult; + +@RestControllerAdvice +public class AccountLoginExceptionHandler extends BaseExceptionHandler { + + protected AccountLoginExceptionHandler() { + super(ExceptionInfoHolderFactory.newDefaultExceptionInfoHolder()); + } + + @ExceptionHandler({ AccountLoginException.class }) + public ResponseEntity handleException(@Nonnull Exception e) { + return buildExceptionResponse(e); + } +} diff --git a/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/exception/handler/SaTokenExceptionHandler.java b/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/exception/handler/SaTokenExceptionHandler.java index e216e16..f41f4eb 100644 --- a/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/exception/handler/SaTokenExceptionHandler.java +++ b/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/exception/handler/SaTokenExceptionHandler.java @@ -15,6 +15,7 @@ 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.exception.handler.ExceptionInfoHolderFactory; import xyz.zhouxy.plusone.util.RestfulResult; /** @@ -26,8 +27,8 @@ import xyz.zhouxy.plusone.util.RestfulResult; @Slf4j public class SaTokenExceptionHandler extends BaseExceptionHandler { - public SaTokenExceptionHandler(ExceptionInfoHolder exceptionInfoHolder) { - super(exceptionInfoHolder); + public SaTokenExceptionHandler() { + super(ExceptionInfoHolderFactory.newDefaultExceptionInfoHolder()); set(NotPermissionException.class, 4030103, "会话未能通过权限认证", HttpStatus.FORBIDDEN); set(NotRoleException.class, 4030103, "会话未能通过角色认证", HttpStatus.FORBIDDEN); set(DisableServiceException.class, 4030202, "账号指定服务已被封禁", HttpStatus.FORBIDDEN); @@ -36,7 +37,7 @@ public class SaTokenExceptionHandler extends BaseExceptionHandler { set(NotSafeException.class, 4020300, "会话未能通过二级认证", HttpStatus.UNAUTHORIZED); set(NotLoginException.class, 4020400, - e -> switch (((NotLoginException) e).getType()) { + e -> switch (e.getType()) { case NotLoginException.NOT_TOKEN -> "未提供 Token"; case NotLoginException.INVALID_TOKEN -> "Token 无效"; case NotLoginException.TOKEN_TIMEOUT -> "Token 已过期"; diff --git a/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/query/DictQueries.java b/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/query/DictQueries.java index bb7a4c7..c1ad02d 100644 --- a/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/query/DictQueries.java +++ b/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/query/DictQueries.java @@ -2,12 +2,12 @@ package xyz.zhouxy.plusone.system.application.query; import java.util.List; +import org.apache.ibatis.jdbc.SQL; import org.springframework.jdbc.core.BeanPropertyRowMapper; import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource; import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; import org.springframework.stereotype.Component; -import xyz.zhouxy.plusone.sql.SQL; import xyz.zhouxy.plusone.system.application.query.params.DictQueryParams; import xyz.zhouxy.plusone.system.application.query.result.DictOverview; @@ -26,14 +26,21 @@ public class DictQueries { } public List queryDictOverviewList(DictQueryParams queryParams) { - String sql = new SQL() - .SELECT("id", "dict_type", "dict_label", - "created_by", "create_time", "updated_by", "update_time", "count") - .FROM("view_sys_dict_overview") - .WHERE_IF(queryParams.getDictType() != null, "dict_type LIKE '%:dictType%'") - .WHERE_IF(queryParams.getDictLabel() != null, "dict_label LIKE '%:dictLabel%'") - .toString(); + String sql = new SQL() { + { + SELECT("id", "dict_type", "dict_label", + "created_by", "create_time", "updated_by", "update_time", "count"); + FROM("view_sys_dict_overview"); + if (queryParams.getDictType() != null) { + WHERE("dict_type LIKE '%:dictType%'"); + } + if (queryParams.getDictLabel() != null) { + WHERE("dict_label LIKE '%:dictLabel%'"); + } + } + }.toString(); return this.jdbcTemplate - .query(sql, new BeanPropertySqlParameterSource(queryParams), new BeanPropertyRowMapper<>(DictOverview.class)); + .query(sql, new BeanPropertySqlParameterSource(queryParams), + new BeanPropertyRowMapper<>(DictOverview.class)); } } diff --git a/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/query/RoleQueries.java b/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/query/RoleQueries.java index e1feef8..ce7f0e6 100644 --- a/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/query/RoleQueries.java +++ b/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/query/RoleQueries.java @@ -7,7 +7,7 @@ import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource; import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; import org.springframework.stereotype.Repository; -import xyz.zhouxy.plusone.sql.SQL; +import org.apache.ibatis.jdbc.SQL; import xyz.zhouxy.plusone.system.application.query.params.RoleQueryParams; import xyz.zhouxy.plusone.system.application.query.result.RoleOverview; @@ -35,30 +35,47 @@ public class RoleQueries { * @return 查询结果 */ public List query(RoleQueryParams params) { - String b = new SQL() - .SELECT("id") - .FROM("sys_role") - .WHERE_IF_NOT_NULL(params.getId(), "id = :id") - .WHERE_IF_NOT_NULL(params.getName(), "name = :name") - .WHERE_IF_NOT_NULL(params.getIdentifier(), "identifier = :identifier") - .WHERE_IF_NOT_NULL(params.getStatus(), "status = :status") - .WHERE_IF_NOT_NULL(params.getCreateTimeStart(), "create_time >= :createTimeStart") - .WHERE_IF_NOT_NULL(params.getCreateTimeEnd(), "create_time < :createTimeEnd") - .WHERE_IF_NOT_NULL(params.getUpdateTimeStart(), "update_time >= :updateTimeStart") - .WHERE_IF_NOT_NULL(params.getUpdateTimeEnd(), "update_time < :updateTimeEnd") - .LIMIT(params.getSize()) - .OFFSET(params.getOffset()) - .toString(); - var sql = """ - SELECT a.id AS id, a.name AS name, a.identifier AS identifier, a.status AS status - FROM sys_role AS a, ( - """ + b + """ - ) AS b - WHERE a.id = b.id - """; + var sql = new SQL() { + { + SELECT("a.id AS id", "a.name AS name", "a.identifier AS identifier", "a.status AS status"); + FROM("sys_role AS a", "(" + + new SQL() { + { + SELECT("id"); + FROM("sys_role"); + if (null != params.getId()) { + WHERE("id = :id"); + } + if (null != params.getName()) { + WHERE("name = :name"); + } + if (null != params.getIdentifier()) { + WHERE("identifier = :identifier"); + } + if (null != params.getStatus()) { + WHERE("status = :status"); + } + if (null != params.getCreateTimeStart()) { + WHERE("create_time >= :createTimeStart"); + } + if (null != params.getCreateTimeEnd()) { + WHERE("create_time < :createTimeEnd"); + } + if (null != params.getUpdateTimeStart()) { + WHERE("update_time >= :updateTimeStart"); + } + if (null != params.getUpdateTimeEnd()) { + WHERE("update_time < :updateTimeEnd"); + } + LIMIT(params.getSize()); + OFFSET(params.getOffset()); + } + }.toString() + ") AS b"); + WHERE("a.id = b.id"); + } + }.toString(); return this.jdbcTemplate .query(sql, new BeanPropertySqlParameterSource(params), new BeanPropertyRowMapper<>(RoleOverview.class)); } - } diff --git a/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/service/RegisterAccountService.java b/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/service/RegisterAccountService.java index e05c4b8..0a5678f 100644 --- a/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/service/RegisterAccountService.java +++ b/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/service/RegisterAccountService.java @@ -16,6 +16,7 @@ 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.Password; +import xyz.zhouxy.plusone.system.domain.model.account.Sex; import xyz.zhouxy.plusone.system.domain.model.account.Username; import xyz.zhouxy.plusone.validator.InvalidInputException; @@ -78,10 +79,10 @@ public class RegisterAccountService { Username.of(username), email, mobilePhone, - Password.newPassword(command.getPassword(), command.getPasswordConfirmation()), + Password.newPassword(command.getPassword(), command.getReenteredPassword()), AccountStatus.AVAILABLE, Set.of(DEFAULT_ROLE_ID), - AccountInfo.of(command.getNickname(), command.getAvatar(), command.getSex())); + AccountInfo.of(command.getNickname(), null, Sex.UNSET)); accountRepository.save(accountToSave); } diff --git a/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/service/command/RegisterAccountCommand.java b/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/service/command/RegisterAccountCommand.java index 7d76d2b..266016b 100644 --- a/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/service/command/RegisterAccountCommand.java +++ b/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/service/command/RegisterAccountCommand.java @@ -3,12 +3,9 @@ package xyz.zhouxy.plusone.system.application.service.command; import javax.validation.constraints.NotBlank; import javax.validation.constraints.Pattern; -import org.hibernate.validator.constraints.URL; - import lombok.Data; import xyz.zhouxy.plusone.constant.RegexConsts; import xyz.zhouxy.plusone.domain.ICommand; -import xyz.zhouxy.plusone.system.domain.model.account.Sex; /** * 注册账号命令 @@ -32,14 +29,8 @@ public class RegisterAccountCommand implements ICommand { @NotBlank @Pattern(regexp = RegexConsts.PASSWORD) String password; - String passwordConfirmation; + String reenteredPassword; @Pattern(regexp = RegexConsts.NICKNAME) String nickname; - - @NotBlank - @URL - String avatar; - - Sex sex; } diff --git a/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/service/command/validator/LoginByOtpCommandValidator.java b/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/service/command/validator/LoginByOtpCommandValidator.java index 01d3eaa..170b08b 100644 --- a/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/service/command/validator/LoginByOtpCommandValidator.java +++ b/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/service/command/validator/LoginByOtpCommandValidator.java @@ -1,13 +1,11 @@ package xyz.zhouxy.plusone.system.application.service.command.validator; -import java.util.regex.Pattern; +import java.util.List; import org.springframework.stereotype.Component; -import org.springframework.util.StringUtils; import xyz.zhouxy.plusone.constant.RegexConsts; import xyz.zhouxy.plusone.system.application.service.command.LoginByOtpCommand; -import xyz.zhouxy.plusone.util.RegexUtil; import xyz.zhouxy.plusone.validator.BaseValidator; import xyz.zhouxy.plusone.validator.DtoValidator; @@ -15,15 +13,13 @@ import xyz.zhouxy.plusone.validator.DtoValidator; @DtoValidator(LoginByOtpCommand.class) public class LoginByOtpCommandValidator extends BaseValidator { public LoginByOtpCommandValidator() { - withRule(loginCommand -> { - String principal = loginCommand.getPrincipal(); - return StringUtils.hasText(principal) - && - RegexUtil.matchesOr(principal, RegexConsts.EMAIL, RegexConsts.MOBILE_PHONE); - }, "输入邮箱地址或手机号"); - withRule(loginCommand -> { - String otp = loginCommand.getOtp(); - return StringUtils.hasText(otp) && Pattern.matches(RegexConsts.CAPTCHA, otp); - }, "验证码不符合要求"); + ruleForString(LoginByOtpCommand::getPrincipal) + .notNull("输入邮箱地址或手机号") + .notEmpty("输入邮箱地址或手机号") + .matchesOr(List.of(RegexConsts.EMAIL, RegexConsts.MOBILE_PHONE), "输入用户名、邮箱地址或手机号"); + ruleForString(LoginByOtpCommand::getOtp) + .notNull("验证码不能为空") + .notEmpty("验证码不能为空") + .matches(RegexConsts.CAPTCHA, "验证码格式不正确"); } } diff --git a/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/service/command/validator/LoginByPasswordCommandValidator.java b/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/service/command/validator/LoginByPasswordCommandValidator.java index 9aad770..a7b42c9 100644 --- a/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/service/command/validator/LoginByPasswordCommandValidator.java +++ b/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/service/command/validator/LoginByPasswordCommandValidator.java @@ -1,13 +1,9 @@ package xyz.zhouxy.plusone.system.application.service.command.validator; -import java.util.regex.Pattern; - +import java.util.List; import org.springframework.stereotype.Component; -import org.springframework.util.StringUtils; - import xyz.zhouxy.plusone.constant.RegexConsts; import xyz.zhouxy.plusone.system.application.service.command.LoginByPasswordCommand; -import xyz.zhouxy.plusone.util.RegexUtil; import xyz.zhouxy.plusone.validator.BaseValidator; import xyz.zhouxy.plusone.validator.DtoValidator; @@ -15,17 +11,14 @@ import xyz.zhouxy.plusone.validator.DtoValidator; @DtoValidator(LoginByPasswordCommand.class) public class LoginByPasswordCommandValidator extends BaseValidator { public LoginByPasswordCommandValidator() { - withRule(loginCommand -> { - String principal = loginCommand.getPrincipal(); - return StringUtils.hasText(principal) - && - RegexUtil.matchesOr(principal, RegexConsts.USERNAME, RegexConsts.EMAIL, RegexConsts.MOBILE_PHONE, principal); - }, "输入用户名、邮箱地址或手机号"); - withRule(loginCommand -> { - String password = loginCommand.getPassword(); - return StringUtils.hasText(password) - && - Pattern.matches(RegexConsts.PASSWORD, password); - }, "密码格式不正确"); + ruleForString(LoginByPasswordCommand::getPrincipal) + .notNull("输入用户名、邮箱地址或手机号") + .notEmpty("输入用户名、邮箱地址或手机号") + .matchesOr(List.of(RegexConsts.USERNAME, RegexConsts.EMAIL, RegexConsts.MOBILE_PHONE), + "输入用户名、邮箱地址或手机号"); + ruleForString(LoginByPasswordCommand::getPassword) + .notNull("密码不能为空") + .notEmpty("密码不能为空") + .matches(RegexConsts.PASSWORD, "密码格式不正确"); } } diff --git a/pom.xml b/pom.xml index f2702f3..2deac8d 100644 --- a/pom.xml +++ b/pom.xml @@ -1,6 +1,7 @@ - + 4.0.0 @@ -25,21 +26,23 @@ 17 17 - 2.7.6 - 1.32.0 - 5.8.9 - 2.2.2 - 3.5.2 + 2.7.8 + 1.34.0 + 5.8.11 + 3.0.1 + 3.5.3.1 2.11.0 2.7.5 1.5.3.Final - 30.1-jre + 31.1-jre 3.12.0 4.4 3.6.1 2.11.1 - 1.12.0 - 3.1.622 + 3.1.681 + 1.29-SNAPSHOT + 3.0.0 + 4.10.0 1.0.0-SNAPSHOT 1.0.0-SNAPSHOT @@ -126,12 +129,6 @@ ${mica.version} - - com.squareup.okio - okio - ${okio.version} - - com.google.guava guava @@ -169,6 +166,24 @@ commons-pool2 ${commons-pool2.version} + + + org.csource + fastdfs-client-java + ${fastdfs.version} + + + + com.squareup.okhttp3 + okhttp + ${okhttp.version} + + + com.squareup.okio + okio + ${okio.version} + +