Compare commits
62 Commits
6f4503684f
...
feature/ad
Author | SHA1 | Date | |
---|---|---|---|
975c7db41e | |||
782e641a51 | |||
0e0d6f1808 | |||
06ffc8d858 | |||
86a14380bf | |||
7195d69468 | |||
60b4f18e8c | |||
2b282039ad | |||
67313938e1 | |||
27be582bfb | |||
288ce9689f | |||
71edaa60a4 | |||
39cd57e675 | |||
7a44c43402 | |||
55395ed327 | |||
956da350ed | |||
78cdded667 | |||
cc3c4be8de | |||
1e31e1f327 | |||
de884f8197 | |||
993ba7fa7b | |||
8ae0faa04d | |||
920971c640 | |||
5f1cb36235 | |||
b4bccfe663 | |||
dc09022919 | |||
f0b6014e77 | |||
19557734ed | |||
ff54aca271 | |||
5d9e6ae5b3 | |||
5c3b31bb18 | |||
a0b16afde2 | |||
9293ba6817 | |||
92dbc613d2 | |||
5b80f70373 | |||
cf068566a1 | |||
0212020dcf | |||
699ba2394d | |||
5ad6980bf7 | |||
bac7a007e6 | |||
02d918d0a4 | |||
f70e9575ea | |||
cbc2711540 | |||
960a4d4ef3 | |||
1dbd00ccef | |||
44f2067f20 | |||
cc44c3ddbd | |||
2de86dcc4a | |||
7c522cae1d | |||
117390c5ae | |||
cec72ba7f9 | |||
d01db60309 | |||
151a33cad4 | |||
6d7517f778 | |||
c73c722b87 | |||
2c967a4c0d | |||
90da53bf2b | |||
7462b47655 | |||
46a72e63c0 | |||
ad8a6da44d | |||
d398800ce4 | |||
71438901a0 |
@@ -33,4 +33,4 @@ indent_size=4
|
|||||||
indent_size=2
|
indent_size=2
|
||||||
|
|
||||||
[*.java]
|
[*.java]
|
||||||
indent_size = 4
|
indent_size=4
|
||||||
|
5
.gitignore
vendored
5
.gitignore
vendored
@@ -32,3 +32,8 @@ build/
|
|||||||
|
|
||||||
### VS Code ###
|
### VS Code ###
|
||||||
.vscode/
|
.vscode/
|
||||||
|
log/
|
||||||
|
|
||||||
|
### bak ###
|
||||||
|
*.bak
|
||||||
|
*-secret.yaml
|
||||||
|
@@ -1,17 +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.exception.handler.BaseExceptionHandler.ExceptionInfoHolder;
|
|
||||||
|
|
||||||
@Configuration
|
|
||||||
public class PlusoneExceptionHandlerConfig {
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
@ConditionalOnMissingBean
|
|
||||||
ExceptionInfoHolder exceptionInfoHolder() {
|
|
||||||
return new ExceptionInfoHolder();
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,10 +1,25 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022-2023 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
package xyz.zhouxy.plusone.exception.handler;
|
package xyz.zhouxy.plusone.exception.handler;
|
||||||
|
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
import xyz.zhouxy.plusone.constant.ErrorCodeConsts;
|
|
||||||
import xyz.zhouxy.plusone.exception.handler.BaseExceptionHandler.ExceptionInfoHolder;
|
import xyz.zhouxy.plusone.exception.handler.BaseExceptionHandler.ExceptionInfoHolder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -16,6 +31,6 @@ public class AllExceptionHandlerConfig {
|
|||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
AllExceptionHandler getAllExceptionHandler(ExceptionInfoHolder exceptionInfoHolder) {
|
AllExceptionHandler getAllExceptionHandler(ExceptionInfoHolder exceptionInfoHolder) {
|
||||||
return new AllExceptionHandler(ErrorCodeConsts.DEFAULT_ERROR_CODE, exceptionInfoHolder);
|
return new AllExceptionHandler(exceptionInfoHolder);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,3 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022-2023 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
package xyz.zhouxy.plusone.exception.handler;
|
package xyz.zhouxy.plusone.exception.handler;
|
||||||
|
|
||||||
import org.springframework.context.support.DefaultMessageSourceResolvable;
|
import org.springframework.context.support.DefaultMessageSourceResolvable;
|
||||||
@@ -11,8 +27,7 @@ import org.springframework.web.bind.annotation.ExceptionHandler;
|
|||||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import xyz.zhouxy.plusone.constant.ErrorCodeConsts;
|
import xyz.zhouxy.plusone.commons.util.RestfulResult;
|
||||||
import xyz.zhouxy.plusone.util.RestfulResult;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 默认异常的处理器
|
* 默认异常的处理器
|
||||||
@@ -41,14 +56,13 @@ import xyz.zhouxy.plusone.util.RestfulResult;
|
|||||||
@Order(Ordered.LOWEST_PRECEDENCE - 1)
|
@Order(Ordered.LOWEST_PRECEDENCE - 1)
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class DefaultExceptionHandler extends BaseExceptionHandler {
|
public class DefaultExceptionHandler extends BaseExceptionHandler {
|
||||||
|
|
||||||
public DefaultExceptionHandler(ExceptionInfoHolder exceptionInfoHolder) {
|
public DefaultExceptionHandler(ExceptionInfoHolder exceptionInfoHolder) {
|
||||||
super(ErrorCodeConsts.DEFAULT_ERROR_CODE, exceptionInfoHolder);
|
super(exceptionInfoHolder);
|
||||||
set(IllegalArgumentException.class, 4010000, "格式错误", HttpStatus.FORBIDDEN);
|
set(IllegalArgumentException.class, 4010000, "格式错误", HttpStatus.FORBIDDEN);
|
||||||
set(DataAccessException.class, 6030000, "数据库错误", HttpStatus.INTERNAL_SERVER_ERROR, true);
|
set(DataAccessException.class, 6030000, "数据库错误", HttpStatus.INTERNAL_SERVER_ERROR, true);
|
||||||
set(MethodArgumentNotValidException.class,
|
set(MethodArgumentNotValidException.class,
|
||||||
4040401,
|
4040401,
|
||||||
e -> ((MethodArgumentNotValidException) e).getAllErrors()
|
e -> e.getAllErrors()
|
||||||
.stream()
|
.stream()
|
||||||
.map(DefaultMessageSourceResolvable::getDefaultMessage)
|
.map(DefaultMessageSourceResolvable::getDefaultMessage)
|
||||||
.toList()
|
.toList()
|
||||||
|
@@ -0,0 +1,44 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022-2023 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package xyz.zhouxy.plusone.exception.handler;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
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.exception.SysException;
|
||||||
|
|
||||||
|
@RestControllerAdvice
|
||||||
|
@Slf4j
|
||||||
|
public class SysExceptionHandler extends BaseExceptionHandler {
|
||||||
|
|
||||||
|
public SysExceptionHandler(ExceptionInfoHolder exceptionInfoHolder) {
|
||||||
|
super(exceptionInfoHolder);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ExceptionHandler({ SysException.class })
|
||||||
|
public ResponseEntity<RestfulResult> handleException(@Nonnull Exception e) {
|
||||||
|
log.error(e.getMessage(), e);
|
||||||
|
HttpStatus httpStatus = getHttpStatus(e);
|
||||||
|
return new ResponseEntity<>(RestfulResult.error(getErrorCode(e), "系统错误"), httpStatus);
|
||||||
|
}
|
||||||
|
}
|
@@ -1,5 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<parent>
|
<parent>
|
||||||
<artifactId>plusone-basic</artifactId>
|
<artifactId>plusone-basic</artifactId>
|
||||||
@@ -31,20 +31,25 @@
|
|||||||
<artifactId>spring-webmvc</artifactId>
|
<artifactId>spring-webmvc</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>commons-io</groupId>
|
||||||
|
<artifactId>commons-io</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>xyz.zhouxy.plusone</groupId>
|
<groupId>xyz.zhouxy.plusone</groupId>
|
||||||
<artifactId>plusone-commons</artifactId>
|
<artifactId>plusone-commons</artifactId>
|
||||||
<version>0.0.1-SNAPSHOT</version>
|
<version>0.1.0-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>xyz.zhouxy.plusone</groupId>
|
<groupId>xyz.zhouxy.plusone</groupId>
|
||||||
<artifactId>plusone-validator</artifactId>
|
<artifactId>plusone-validator</artifactId>
|
||||||
<version>0.0.1-SNAPSHOT</version>
|
<version>0.1.3-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>xyz.zhouxy.plusone</groupId>
|
<groupId>xyz.zhouxy.plusone</groupId>
|
||||||
<artifactId>plusone-exception-handler</artifactId>
|
<artifactId>plusone-exception-handler</artifactId>
|
||||||
<version>0.0.4-SNAPSHOT</version>
|
<version>0.0.8-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
@@ -1,5 +1,25 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022-2023 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
package xyz.zhouxy.plusone.constant;
|
package xyz.zhouxy.plusone.constant;
|
||||||
|
|
||||||
public class ErrorCodeConsts {
|
public class ErrorCodeConsts {
|
||||||
public static final int DEFAULT_ERROR_CODE = 9999999;
|
public static final int DEFAULT_ERROR_CODE = 9999999;
|
||||||
|
|
||||||
|
private ErrorCodeConsts() {
|
||||||
|
throw new IllegalStateException("Utility class");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,55 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022-2023 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package xyz.zhouxy.plusone.exception;
|
||||||
|
|
||||||
|
import xyz.zhouxy.plusone.commons.exception.BaseException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 业务异常
|
||||||
|
*
|
||||||
|
* @author <a href="https://gitee.com/zhouxy108">ZhouXY</a>
|
||||||
|
*/
|
||||||
|
public class BizException extends BaseException {
|
||||||
|
@java.io.Serial
|
||||||
|
private static final long serialVersionUID = -5524759033245815405L;
|
||||||
|
|
||||||
|
public static final int DEFAULT_ERROR_CODE = 4000000;
|
||||||
|
|
||||||
|
public BizException(int code, String msg) {
|
||||||
|
super(code, msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public BizException(int code, Throwable cause) {
|
||||||
|
super(code, cause);
|
||||||
|
}
|
||||||
|
|
||||||
|
public BizException(int code, String msg, Throwable cause) {
|
||||||
|
super(code, msg, cause);
|
||||||
|
}
|
||||||
|
|
||||||
|
public BizException(String msg) {
|
||||||
|
super(DEFAULT_ERROR_CODE, msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public BizException(Throwable cause) {
|
||||||
|
super(DEFAULT_ERROR_CODE, cause);
|
||||||
|
}
|
||||||
|
|
||||||
|
public BizException(String msg, Throwable cause) {
|
||||||
|
super(DEFAULT_ERROR_CODE, msg, cause);
|
||||||
|
}
|
||||||
|
}
|
@@ -1,3 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022-2023 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
package xyz.zhouxy.plusone.exception;
|
package xyz.zhouxy.plusone.exception;
|
||||||
|
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
@@ -6,15 +22,10 @@ import org.springframework.web.bind.annotation.ResponseStatus;
|
|||||||
/**
|
/**
|
||||||
* 需要时,当查询数据不存在时抛出的异常
|
* 需要时,当查询数据不存在时抛出的异常
|
||||||
*
|
*
|
||||||
* <p>
|
|
||||||
* 暂时先这样,后续完善异常体系时可能会更改。
|
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* @author <a href="https://gitee.com/zhouxy108">ZhouXY</a>
|
* @author <a href="https://gitee.com/zhouxy108">ZhouXY</a>
|
||||||
* @see xyz.zhouxy.plusone.util.AssertResult
|
|
||||||
*/
|
*/
|
||||||
@ResponseStatus(HttpStatus.NOT_FOUND)
|
@ResponseStatus(HttpStatus.NOT_FOUND)
|
||||||
public class DataNotExistException extends PlusoneException {
|
public class DataNotExistException extends BizException {
|
||||||
|
|
||||||
@java.io.Serial
|
@java.io.Serial
|
||||||
private static final long serialVersionUID = 6536955800679703111L;
|
private static final long serialVersionUID = 6536955800679703111L;
|
||||||
|
@@ -1,31 +0,0 @@
|
|||||||
package xyz.zhouxy.plusone.exception;
|
|
||||||
|
|
||||||
import org.springframework.http.HttpStatus;
|
|
||||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 需要时,当数据操作的行数不符合预期时抛出的异常
|
|
||||||
*
|
|
||||||
* <p>
|
|
||||||
* 暂时先这样,后续完善异常体系时可能会更改。
|
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* @author <a href="https://gitee.com/zhouxy108">ZhouXY</a>
|
|
||||||
* @see xyz.zhouxy.plusone.util.AssertResult
|
|
||||||
*/
|
|
||||||
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
|
|
||||||
public class DataOperationNumberException extends PlusoneException {
|
|
||||||
|
|
||||||
@java.io.Serial
|
|
||||||
private static final long serialVersionUID = -9220765735990318186L;
|
|
||||||
|
|
||||||
public static final int ERROR_CODE = 4110200;
|
|
||||||
|
|
||||||
public DataOperationNumberException() {
|
|
||||||
super(ERROR_CODE, "数据操作的行数不符合预期");
|
|
||||||
}
|
|
||||||
|
|
||||||
public DataOperationNumberException(String message) {
|
|
||||||
super(ERROR_CODE, message);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -0,0 +1,46 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022-2023 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package xyz.zhouxy.plusone.exception;
|
||||||
|
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 需要时,当数据操作的结果不符合预期时抛出的异常
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* 暂时先这样,后续完善异常体系时可能会更改。
|
||||||
|
*
|
||||||
|
* @author <a href="https://gitee.com/zhouxy108">ZhouXY</a>
|
||||||
|
* @see xyz.zhouxy.plusone.util.AssertResult
|
||||||
|
*/
|
||||||
|
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
|
||||||
|
public class DataOperationResultException extends SysException {
|
||||||
|
|
||||||
|
@java.io.Serial
|
||||||
|
private static final long serialVersionUID = -9220765735990318186L;
|
||||||
|
|
||||||
|
public static final int ERROR_CODE = 4110200;
|
||||||
|
|
||||||
|
public DataOperationResultException() {
|
||||||
|
super(ERROR_CODE, "数据操作结果不符合预期");
|
||||||
|
}
|
||||||
|
|
||||||
|
public DataOperationResultException(String message) {
|
||||||
|
super(ERROR_CODE, message);
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,50 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022-2023 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package xyz.zhouxy.plusone.exception;
|
||||||
|
|
||||||
|
import xyz.zhouxy.plusone.commons.exception.BaseException;
|
||||||
|
|
||||||
|
public class SysException extends BaseException {
|
||||||
|
@java.io.Serial
|
||||||
|
private static final long serialVersionUID = 8821240827443168118L;
|
||||||
|
|
||||||
|
public static final int DEFAULT_ERROR_CODE = 5000000;
|
||||||
|
|
||||||
|
public SysException(int code, String msg) {
|
||||||
|
super(code, msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SysException(int code, Throwable cause) {
|
||||||
|
super(code, cause);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SysException(int code, String msg, Throwable cause) {
|
||||||
|
super(code, msg, cause);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SysException(String msg) {
|
||||||
|
super(DEFAULT_ERROR_CODE, msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SysException(Throwable cause) {
|
||||||
|
super(DEFAULT_ERROR_CODE, cause);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SysException(String msg, Throwable cause) {
|
||||||
|
super(DEFAULT_ERROR_CODE, msg, cause);
|
||||||
|
}
|
||||||
|
}
|
@@ -1,3 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022-2023 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
package xyz.zhouxy.plusone.exception;
|
package xyz.zhouxy.plusone.exception;
|
||||||
|
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
@@ -9,7 +25,7 @@ import org.springframework.web.bind.annotation.ResponseStatus;
|
|||||||
* @author ZhouXY
|
* @author ZhouXY
|
||||||
*/
|
*/
|
||||||
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
||||||
public class UserOperationException extends PlusoneException {
|
public class UserOperationException extends BizException {
|
||||||
|
|
||||||
@java.io.Serial
|
@java.io.Serial
|
||||||
private static final long serialVersionUID = 4371055414421991940L;
|
private static final long serialVersionUID = 4371055414421991940L;
|
||||||
|
@@ -1,10 +1,26 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022-2023 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
package xyz.zhouxy.plusone.util;
|
package xyz.zhouxy.plusone.util;
|
||||||
|
|
||||||
|
|
||||||
import xyz.zhouxy.plusone.exception.DataNotExistException;
|
import xyz.zhouxy.plusone.exception.DataNotExistException;
|
||||||
import xyz.zhouxy.plusone.exception.DataOperationNumberException;
|
import xyz.zhouxy.plusone.exception.DataOperationResultException;
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 对数据库执行结果进行判断
|
* 对数据库执行结果进行判断
|
||||||
@@ -17,51 +33,34 @@ public final class AssertResult {
|
|||||||
throw new IllegalStateException("Utility class");
|
throw new IllegalStateException("Utility class");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void update(boolean expression) {
|
public static <E extends Throwable> void isTrue(boolean condition, Supplier<E> e) throws E {
|
||||||
if (!expression) {
|
if (!condition) {
|
||||||
throw new DataOperationNumberException();
|
throw e.get();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void update(boolean expression, String message) {
|
public static <T> void equals(T result, T expectedValue) {
|
||||||
if (!expression) {
|
isTrue(Objects.equals(result, expectedValue), DataOperationResultException::new);
|
||||||
throw new DataOperationNumberException(message);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void update(Object i, int expectedValue) {
|
public static <T> void equals(T result, T expectedValue, String msgTemplate, Object... args) {
|
||||||
if (!Objects.equals(i, expectedValue)) {
|
isTrue(!Objects.equals(result, expectedValue),
|
||||||
throw new DataOperationNumberException();
|
() -> new DataOperationResultException(String.format(msgTemplate, args)));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void update(Object i, int expectedValue, String format) {
|
public static void updateOneRow(int i) {
|
||||||
if (!Objects.equals(i, expectedValue)) {
|
equals(i, 1);
|
||||||
throw new DataOperationNumberException(String.format(format, i));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void exist(boolean expression) {
|
public static void updateOneRow(int i, String format, Object... args) {
|
||||||
if (!expression) {
|
equals(i, 1, format, args);
|
||||||
throw new DataNotExistException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void exist(boolean expression, String message) {
|
|
||||||
if (!expression) {
|
|
||||||
throw new DataNotExistException(message);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void nonNull(Object obj) {
|
public static void nonNull(Object obj) {
|
||||||
if (Objects.isNull(obj)) {
|
isTrue(Objects.nonNull(obj), DataNotExistException::new);
|
||||||
throw new DataNotExistException();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void nonNull(Object obj, String message) {
|
public static void nonNull(Object obj, String message) {
|
||||||
if (Objects.isNull(obj)) {
|
isTrue(Objects.nonNull(obj), () -> new DataNotExistException(message));
|
||||||
throw new DataNotExistException(message);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,3 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022-2023 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
package xyz.zhouxy.plusone.util;
|
package xyz.zhouxy.plusone.util;
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
@@ -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>
|
<groupId>xyz.zhouxy</groupId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>cn.hutool</groupId>
|
|
||||||
<artifactId>hutool-core</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.projectlombok</groupId>
|
<groupId>org.projectlombok</groupId>
|
||||||
<artifactId>lombok</artifactId>
|
<artifactId>lombok</artifactId>
|
||||||
@@ -28,12 +23,10 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.fasterxml.jackson.core</groupId>
|
<groupId>com.fasterxml.jackson.core</groupId>
|
||||||
<artifactId>jackson-core</artifactId>
|
<artifactId>jackson-core</artifactId>
|
||||||
<version>2.13.4</version>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.fasterxml.jackson.core</groupId>
|
<groupId>com.fasterxml.jackson.core</groupId>
|
||||||
<artifactId>jackson-annotations</artifactId>
|
<artifactId>jackson-annotations</artifactId>
|
||||||
<version>2.13.4</version>
|
</dependency>
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
@@ -1,32 +1,52 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022-2023 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
package xyz.zhouxy.plusone.constant;
|
package xyz.zhouxy.plusone.constant;
|
||||||
|
|
||||||
import xyz.zhouxy.plusone.util.Enumeration;
|
import java.util.Collection;
|
||||||
import xyz.zhouxy.plusone.util.EnumerationValuesHolder;
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
|
import xyz.zhouxy.plusone.commons.util.Enumeration;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 实体状态
|
* 实体状态
|
||||||
*
|
*
|
||||||
* @author <a href="https://gitee.com/zhouxy108">ZhouXY</a>
|
* @author <a href="https://gitee.com/zhouxy108">ZhouXY</a>
|
||||||
*/
|
*/
|
||||||
public class EntityStatus extends Enumeration<EntityStatus> {
|
public final class EntityStatus extends Enumeration<EntityStatus> {
|
||||||
|
|
||||||
private EntityStatus(int value, String name) {
|
private EntityStatus(int id, @Nonnull String name) {
|
||||||
super(value, name);
|
super(id, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 常量
|
// 常量
|
||||||
public static final EntityStatus AVAILABLE = new EntityStatus(0, "正常");
|
public static final EntityStatus AVAILABLE = new EntityStatus(0, "正常");
|
||||||
public static final EntityStatus DISABLED = new EntityStatus(1, "禁用");
|
public static final EntityStatus DISABLED = new EntityStatus(1, "禁用");
|
||||||
|
|
||||||
private static final EnumerationValuesHolder<EntityStatus> ENUMERATION_VALUES = new EnumerationValuesHolder<>(
|
private static final ValueSet<EntityStatus> VALUE_SET = new ValueSet<>(
|
||||||
new EntityStatus[] { AVAILABLE, DISABLED });
|
AVAILABLE, DISABLED);
|
||||||
|
|
||||||
public static EntityStatus of(int value) {
|
@Nonnull
|
||||||
return ENUMERATION_VALUES.get(value);
|
public static EntityStatus of(int id) {
|
||||||
|
return VALUE_SET.get(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Nonnull
|
||||||
public String toString() {
|
public static Collection<EntityStatus> constants() {
|
||||||
return "EntityStatus" + super.toString();
|
return VALUE_SET.getValues();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,27 +0,0 @@
|
|||||||
package xyz.zhouxy.plusone.constant;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 正则表达式常量
|
|
||||||
*
|
|
||||||
* @author <a href="https://gitee.com/zhouxy108">ZhouXY</a>
|
|
||||||
*/
|
|
||||||
public final class RegexConsts {
|
|
||||||
|
|
||||||
public static final String DATE = "^\\d{4}-\\d{2}-\\d{2}";
|
|
||||||
|
|
||||||
public static final String PASSWORD = "^(?=.*\\d)(?=.*[a-z])(?=.*[A-Z])[\\w\\\\!#$%&'*\\+\\-/=?^`{|}~@\\(\\)\\[\\]\",\\.;':><]{8,32}$";
|
|
||||||
|
|
||||||
public static final String CAPTCHA = "^[0-9A-Za-z]{4,6}$";
|
|
||||||
|
|
||||||
public static final String EMAIL = "^\\w+([-+.]\\w+)*@[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(\\.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})*(\\.(?![0-9]+$)[a-zA-Z0-9][-0-9A-Za-z]{0,62})$";
|
|
||||||
|
|
||||||
public static final String MOBILE_PHONE = "^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\\d{8}$";
|
|
||||||
|
|
||||||
public static final String USERNAME = "^[\\da-zA-Z_.@\\\\]{4,36}$";
|
|
||||||
|
|
||||||
public static final String NICKNAME = "^[\\da-zA-Z_.@\\\\]{4,36}$";
|
|
||||||
|
|
||||||
private RegexConsts() {
|
|
||||||
throw new IllegalStateException("Utility class");
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,3 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022-2023 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
package xyz.zhouxy.plusone.domain;
|
package xyz.zhouxy.plusone.domain;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
@@ -1,6 +1,23 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022-2023 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
package xyz.zhouxy.plusone.domain;
|
package xyz.zhouxy.plusone.domain;
|
||||||
|
|
||||||
import cn.hutool.core.lang.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -20,7 +37,7 @@ public abstract class DomainEvent {
|
|||||||
private long happenedAt;
|
private long happenedAt;
|
||||||
|
|
||||||
protected DomainEvent() {
|
protected DomainEvent() {
|
||||||
this.identifier = UUID.randomUUID().toString(true);
|
this.identifier = UUID.randomUUID().toString();
|
||||||
this.happenedAt = System.currentTimeMillis();
|
this.happenedAt = System.currentTimeMillis();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,3 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022-2023 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
package xyz.zhouxy.plusone.domain;
|
package xyz.zhouxy.plusone.domain;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
@@ -1,3 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022-2023 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
package xyz.zhouxy.plusone.domain;
|
package xyz.zhouxy.plusone.domain;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -1,3 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022-2023 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
package xyz.zhouxy.plusone.domain;
|
package xyz.zhouxy.plusone.domain;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -1,3 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022-2023 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
package xyz.zhouxy.plusone.domain;
|
package xyz.zhouxy.plusone.domain;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -1,6 +1,23 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022-2023 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
package xyz.zhouxy.plusone.domain;
|
package xyz.zhouxy.plusone.domain;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Repository 基础接口
|
* Repository 基础接口
|
||||||
@@ -10,7 +27,7 @@ import java.io.Serializable;
|
|||||||
*/
|
*/
|
||||||
public interface IRepository<T extends AggregateRoot<ID>, ID extends Serializable> {
|
public interface IRepository<T extends AggregateRoot<ID>, ID extends Serializable> {
|
||||||
|
|
||||||
T find(ID id);
|
Optional<T> find(ID id);
|
||||||
|
|
||||||
T save(T entity);
|
T save(T entity);
|
||||||
|
|
||||||
|
@@ -1,3 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022-2023 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
package xyz.zhouxy.plusone.domain;
|
package xyz.zhouxy.plusone.domain;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -1,3 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022-2023 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
package xyz.zhouxy.plusone.domain;
|
package xyz.zhouxy.plusone.domain;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -1,3 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022-2023 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
package xyz.zhouxy.plusone.domain;
|
package xyz.zhouxy.plusone.domain;
|
||||||
|
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
|
@@ -1,3 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022-2023 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
package xyz.zhouxy.plusone.domain;
|
package xyz.zhouxy.plusone.domain;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -1,5 +1,24 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022-2023 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
package xyz.zhouxy.plusone.domain;
|
package xyz.zhouxy.plusone.domain;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
import com.fasterxml.jackson.annotation.JsonValue;
|
import com.fasterxml.jackson.annotation.JsonValue;
|
||||||
|
|
||||||
@@ -11,15 +30,15 @@ import com.fasterxml.jackson.annotation.JsonValue;
|
|||||||
public abstract class ValidatableStringRecord implements IValueObject {
|
public abstract class ValidatableStringRecord implements IValueObject {
|
||||||
|
|
||||||
protected String value;
|
protected String value;
|
||||||
protected final String format;
|
protected final Pattern format;
|
||||||
|
|
||||||
protected ValidatableStringRecord(String format) {
|
protected ValidatableStringRecord(Pattern format) {
|
||||||
this.format = format;
|
this.format = format;
|
||||||
}
|
}
|
||||||
|
|
||||||
@JsonIgnore
|
@JsonIgnore
|
||||||
protected boolean isValid() {
|
protected boolean isValid() {
|
||||||
return value.matches(format);
|
return format.matcher(value).matches();
|
||||||
}
|
}
|
||||||
|
|
||||||
@JsonValue
|
@JsonValue
|
||||||
@@ -31,4 +50,8 @@ public abstract class ValidatableStringRecord implements IValueObject {
|
|||||||
public String toString() {
|
public String toString() {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String getValueOrNull(Optional<? extends ValidatableStringRecord> s) {
|
||||||
|
return s.isPresent() ? s.get().value() : null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,36 +0,0 @@
|
|||||||
package xyz.zhouxy.plusone.util;
|
|
||||||
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
public class RegexUtil {
|
|
||||||
|
|
||||||
private RegexUtil() {
|
|
||||||
throw new IllegalStateException("Utility class");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean matches(CharSequence input, String regex) {
|
|
||||||
return Pattern.matches(regex, input);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean matchesOr(CharSequence input, String... regexs) {
|
|
||||||
boolean isMatched;
|
|
||||||
for (var regex : regexs) {
|
|
||||||
isMatched = Pattern.matches(regex, input);
|
|
||||||
if (isMatched) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean matchesAnd(CharSequence input, String... regexs) {
|
|
||||||
boolean isMatched;
|
|
||||||
for (var regex : regexs) {
|
|
||||||
isMatched = Pattern.matches(regex, input);
|
|
||||||
if (!isMatched) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,5 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>xyz.zhouxy</groupId>
|
<groupId>xyz.zhouxy</groupId>
|
||||||
@@ -84,6 +86,11 @@
|
|||||||
<groupId>com.tencentcloudapi</groupId>
|
<groupId>com.tencentcloudapi</groupId>
|
||||||
<artifactId>tencentcloud-sdk-java-sms</artifactId>
|
<artifactId>tencentcloud-sdk-java-sms</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.csource</groupId>
|
||||||
|
<artifactId>fastdfs-client-java</artifactId>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
@@ -1,3 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022-2023 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
package xyz.zhouxy.plusone.config;
|
package xyz.zhouxy.plusone.config;
|
||||||
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
@@ -0,0 +1,34 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022-2023 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
@@ -1,3 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022-2023 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
package xyz.zhouxy.plusone.infrastructure.pojo;
|
package xyz.zhouxy.plusone.infrastructure.pojo;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
@@ -1,3 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022-2023 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
package xyz.zhouxy.plusone.jdbc;
|
package xyz.zhouxy.plusone.jdbc;
|
||||||
|
|
||||||
import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource;
|
import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource;
|
||||||
|
@@ -1,3 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022-2023 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
package xyz.zhouxy.plusone.jdbc;
|
package xyz.zhouxy.plusone.jdbc;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@@ -1,63 +1,80 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022-2023 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
package xyz.zhouxy.plusone.jdbc;
|
package xyz.zhouxy.plusone.jdbc;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
import org.springframework.jdbc.core.ResultSetExtractor;
|
import org.springframework.jdbc.core.ResultSetExtractor;
|
||||||
import org.springframework.jdbc.core.RowMapper;
|
import org.springframework.jdbc.core.RowMapper;
|
||||||
|
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
|
||||||
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
|
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
|
||||||
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
|
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
|
||||||
|
|
||||||
import xyz.zhouxy.plusone.domain.Entity;
|
import xyz.zhouxy.plusone.domain.Entity;
|
||||||
|
|
||||||
public abstract class JdbcEntityDaoSupport<T extends Entity<ID>, ID extends Serializable> {
|
public abstract class JdbcEntityDaoSupport<T extends Entity<ID>, ID extends Serializable>
|
||||||
protected final NamedParameterJdbcTemplate jdbc;
|
extends PlusoneJdbcDaoSupport {
|
||||||
|
|
||||||
protected RowMapper<T> rowMapper;
|
protected RowMapper<T> rowMapper;
|
||||||
protected ResultSetExtractor<T> resultSetExtractor;
|
protected ResultSetExtractor<Optional<T>> resultSetExtractor;
|
||||||
|
|
||||||
protected JdbcEntityDaoSupport(@Nonnull NamedParameterJdbcTemplate namedParameterJdbcTemplate) {
|
protected JdbcEntityDaoSupport(@Nonnull NamedParameterJdbcTemplate namedParameterJdbcTemplate) {
|
||||||
this.jdbc = namedParameterJdbcTemplate;
|
super(namedParameterJdbcTemplate);
|
||||||
this.rowMapper = (ResultSet rs, int rowNum) -> mapRow(rs);
|
this.rowMapper = (ResultSet rs, int rowNum) -> mapRow(rs);
|
||||||
this.resultSetExtractor = (ResultSet rs) -> rs.next() ? mapRow(rs) : null;
|
this.resultSetExtractor = (ResultSet rs) -> rs.next() ? Optional.of(mapRow(rs)) : Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected final T queryForObject(String sql) {
|
protected final Optional<T> queryForObject(String sql) {
|
||||||
return this.jdbc.query(sql, this.resultSetExtractor);
|
return queryForObject(sql, this.resultSetExtractor);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected final T queryForObject(String sql, SqlParameterSource paramSource) {
|
protected final Optional<T> queryForObject(String sql, SqlParameterSource paramSource) {
|
||||||
return this.jdbc.query(sql, paramSource, this.resultSetExtractor);
|
return queryForObject(sql, paramSource, this.resultSetExtractor);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected final Optional<T> queryForObject(String sql, String paramName, Object value) {
|
||||||
|
return queryForObject(sql, new MapSqlParameterSource(paramName, value), this.resultSetExtractor);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected final List<T> queryForList(String sql) {
|
protected final List<T> queryForList(String sql) {
|
||||||
return this.jdbc.query(sql, this.rowMapper);
|
return queryForList(sql, this.rowMapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected final List<T> queryForList(String sql, SqlParameterSource parameterSource) {
|
protected final List<T> queryForList(String sql, SqlParameterSource parameterSource) {
|
||||||
return this.jdbc.query(sql, parameterSource, this.rowMapper);
|
return queryForList(sql, parameterSource, this.rowMapper);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected final List<T> queryForList(String sql, String paramName, Object value) {
|
||||||
|
return queryForList(sql, new MapSqlParameterSource(paramName, value), this.rowMapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected final Stream<T> queryForStream(String sql, SqlParameterSource parameterSource) {
|
protected final Stream<T> queryForStream(String sql, SqlParameterSource parameterSource) {
|
||||||
return this.jdbc.queryForStream(sql, parameterSource, this.rowMapper);
|
return queryForStream(sql, parameterSource, this.rowMapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected final <E> Stream<E> queryForStream(String sql, SqlParameterSource parameterSource, Class<E> elementType) {
|
protected final Stream<T> queryForStream(String sql, String paramName, Object value) {
|
||||||
return this.jdbc.queryForList(sql, parameterSource, elementType).stream();
|
return queryForStream(sql, new MapSqlParameterSource(paramName, value), this.rowMapper);
|
||||||
}
|
|
||||||
|
|
||||||
protected final boolean queryExists(String sql, SqlParameterSource parameterSource) {
|
|
||||||
Boolean isExists = this.jdbc.query(sql, parameterSource, ResultSet::next);
|
|
||||||
return Boolean.TRUE.equals(isExists);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected final int update(String sql, SqlParameterSource parameterSource) {
|
|
||||||
return this.jdbc.update(sql, parameterSource);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract T mapRow(ResultSet rs) throws SQLException;
|
protected abstract T mapRow(ResultSet rs) throws SQLException;
|
||||||
@@ -66,7 +83,7 @@ public abstract class JdbcEntityDaoSupport<T extends Entity<ID>, ID extends Seri
|
|||||||
this.rowMapper = rowMapper;
|
this.rowMapper = rowMapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void setResultSetExtractor(@Nonnull ResultSetExtractor<T> resultSetExtractor) {
|
protected void setResultSetExtractor(@Nonnull ResultSetExtractor<Optional<T>> resultSetExtractor) {
|
||||||
this.resultSetExtractor = resultSetExtractor;
|
this.resultSetExtractor = resultSetExtractor;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,5 +1,22 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022-2023 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
package xyz.zhouxy.plusone.jdbc;
|
package xyz.zhouxy.plusone.jdbc;
|
||||||
|
|
||||||
|
import org.springframework.context.ApplicationContext;
|
||||||
import org.springframework.jdbc.core.JdbcTemplate;
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
|
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
|
||||||
|
|
||||||
@@ -16,15 +33,17 @@ import xyz.zhouxy.plusone.spring.SpringContextHolder;
|
|||||||
*/
|
*/
|
||||||
public final class JdbcFactory {
|
public final class JdbcFactory {
|
||||||
|
|
||||||
|
private static final ApplicationContext CONTEXT = SpringContextHolder.getContext();
|
||||||
|
|
||||||
private JdbcFactory() {
|
private JdbcFactory() {
|
||||||
throw new IllegalStateException("Utility class");
|
throw new IllegalStateException("Utility class");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static JdbcTemplate getJdbcTemplate() {
|
public static JdbcTemplate getJdbcTemplate() {
|
||||||
return SpringContextHolder.getContext().getBean(JdbcTemplate.class);
|
return CONTEXT.getBean(JdbcTemplate.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static NamedParameterJdbcTemplate getNamedParameterJdbcTemplate() {
|
public static NamedParameterJdbcTemplate getNamedParameterJdbcTemplate() {
|
||||||
return SpringContextHolder.getContext().getBean(NamedParameterJdbcTemplate.class);
|
return CONTEXT.getBean(NamedParameterJdbcTemplate.class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,6 +1,23 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022-2023 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
package xyz.zhouxy.plusone.jdbc;
|
package xyz.zhouxy.plusone.jdbc;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
@@ -20,7 +37,7 @@ public abstract class JdbcRepositorySupport<T extends AggregateRoot<ID>, ID exte
|
|||||||
|
|
||||||
protected abstract void doDelete(@Nonnull T entity);
|
protected abstract void doDelete(@Nonnull T entity);
|
||||||
|
|
||||||
protected abstract T doFindById(@Nonnull ID id);
|
protected abstract Optional<T> doFindById(@Nonnull ID id);
|
||||||
|
|
||||||
protected abstract T doInsert(@Nonnull T entity);
|
protected abstract T doInsert(@Nonnull T entity);
|
||||||
|
|
||||||
@@ -35,7 +52,7 @@ public abstract class JdbcRepositorySupport<T extends AggregateRoot<ID>, ID exte
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final T find(ID id) {
|
public final Optional<T> find(ID id) {
|
||||||
if (id == null) {
|
if (id == null) {
|
||||||
throw new IllegalArgumentException("Id cannot be null.");
|
throw new IllegalArgumentException("Id cannot be null.");
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,189 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022-2023 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package xyz.zhouxy.plusone.jdbc;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.function.Function;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
|
import org.springframework.jdbc.core.ResultSetExtractor;
|
||||||
|
import org.springframework.jdbc.core.RowMapper;
|
||||||
|
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
|
||||||
|
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
|
||||||
|
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
|
||||||
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
|
import xyz.zhouxy.plusone.commons.util.NumberUtil;
|
||||||
|
import xyz.zhouxy.plusone.exception.DataOperationResultException;
|
||||||
|
|
||||||
|
public abstract class PlusoneJdbcDaoSupport {
|
||||||
|
protected final NamedParameterJdbcTemplate jdbc;
|
||||||
|
|
||||||
|
protected PlusoneJdbcDaoSupport(@Nonnull NamedParameterJdbcTemplate namedParameterJdbcTemplate) {
|
||||||
|
this.jdbc = namedParameterJdbcTemplate;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected final <T> T queryForObject(String sql, ResultSetExtractor<T> resultSetExtractor) {
|
||||||
|
return this.jdbc.query(sql, resultSetExtractor);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected final <T> T queryForObject(String sql, SqlParameterSource paramSource,
|
||||||
|
ResultSetExtractor<T> resultSetExtractor) {
|
||||||
|
return this.jdbc.query(sql, paramSource, resultSetExtractor);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected final <T> T queryForObject(String sql, String paramName, Object value,
|
||||||
|
ResultSetExtractor<T> resultSetExtractor) {
|
||||||
|
return this.jdbc.query(sql, new MapSqlParameterSource(paramName, value), resultSetExtractor);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected final <T> List<T> queryForList(String sql, RowMapper<T> rowMapper) {
|
||||||
|
return this.jdbc.query(sql, rowMapper);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected final <T> List<T> queryForList(String sql, SqlParameterSource parameterSource, RowMapper<T> rowMapper) {
|
||||||
|
return this.jdbc.query(sql, parameterSource, rowMapper);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected final <T> List<T> queryForList(String sql, String paramName, Object value, RowMapper<T> rowMapper) {
|
||||||
|
return this.jdbc.query(sql, new MapSqlParameterSource(paramName, value), rowMapper);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected final <T> Stream<T> queryForStream(String sql, SqlParameterSource parameterSource,
|
||||||
|
RowMapper<T> rowMapper) {
|
||||||
|
return this.jdbc.queryForStream(sql, parameterSource, rowMapper);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected final <T> Stream<T> queryForStream(String sql, String paramName, Object value, RowMapper<T> rowMapper) {
|
||||||
|
return this.jdbc.queryForStream(sql, new MapSqlParameterSource(paramName, value), rowMapper);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected final <T> Stream<T> queryForStream(String sql, SqlParameterSource parameterSource, Class<T> elementType) {
|
||||||
|
return this.jdbc.queryForList(sql, parameterSource, elementType).stream();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected final <T> Stream<T> queryForStream(String sql, String paramName, Object value, Class<T> elementType) {
|
||||||
|
return queryForStream(sql, new MapSqlParameterSource(paramName, value), elementType);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected final boolean queryForBool(String sql, SqlParameterSource parameterSource) {
|
||||||
|
Boolean result = this.jdbc.queryForObject(sql, parameterSource, Boolean.TYPE);
|
||||||
|
return Boolean.TRUE.equals(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected final boolean queryForBool(String sql, String paramName, Object value) {
|
||||||
|
return queryForBool(sql, new MapSqlParameterSource(paramName, value));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected final int update(String sql, SqlParameterSource parameterSource) {
|
||||||
|
return this.jdbc.update(sql, parameterSource);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected final int update(String sql, String paramName, Object value) {
|
||||||
|
return update(sql, new MapSqlParameterSource(paramName, value));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected final long batchUpdate(String sql, SqlParameterSource[] batchArgs) {
|
||||||
|
int[] i = this.jdbc.batchUpdate(sql, batchArgs);
|
||||||
|
return NumberUtil.sum(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
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> 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static final <T> void assertResultEquals(T result, T expectedValue) {
|
||||||
|
if (!Objects.equals(result, expectedValue)) {
|
||||||
|
throw new DataOperationResultException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static final <T> void assertResultEquals(T result, T expectedValue, Function<T, String> errMsg) {
|
||||||
|
if (!Objects.equals(result, expectedValue)) {
|
||||||
|
throw new DataOperationResultException(errMsg.apply(result));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static final <T> void assertResultEquals(T result, T expectedValue, String msgTemplate, Object... args) {
|
||||||
|
if (!Objects.equals(result, expectedValue)) {
|
||||||
|
throw new DataOperationResultException(String.format(msgTemplate, args));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static final <T, E extends Throwable> void assertResultEqualsOrThrow(T result, T expectedValue,
|
||||||
|
Function<T, E> e) throws E {
|
||||||
|
if (!Objects.equals(result, expectedValue)) {
|
||||||
|
throw e.apply(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static final void assertUpdateOneRow(int result) {
|
||||||
|
assertResultEquals(result, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static final void assertUpdateOneRow(int result, Function<Integer, String> errMsg) {
|
||||||
|
assertResultEquals(result, 1, errMsg);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static final void assertUpdateOneRow(int result, String msgTemplate, Object... args) {
|
||||||
|
assertResultEquals(result, 1, msgTemplate, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static final <E extends Throwable> void assertUpdateOneRowOrThrow(int result, Function<Integer, E> e)
|
||||||
|
throws E {
|
||||||
|
assertResultEqualsOrThrow(result, 1, e);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static final <T> SqlParameterSource[] buildSqlParameterSourceArray(
|
||||||
|
T[] c,
|
||||||
|
@Nonnull Function<T, SqlParameterSource> paramSourceBuilder) {
|
||||||
|
if (c == null || c.length == 0) {
|
||||||
|
return new SqlParameterSource[] {};
|
||||||
|
}
|
||||||
|
return buildSqlParameterSourceArray(Arrays.stream(c), paramSourceBuilder);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static final <T> SqlParameterSource[] buildSqlParameterSourceArray(
|
||||||
|
Collection<T> c,
|
||||||
|
@Nonnull Function<T, SqlParameterSource> paramSourceBuilder) {
|
||||||
|
if (CollectionUtils.isEmpty(c)) {
|
||||||
|
return new SqlParameterSource[] {};
|
||||||
|
}
|
||||||
|
return buildSqlParameterSourceArray(c.stream(), paramSourceBuilder);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static final <T> SqlParameterSource[] buildSqlParameterSourceArray(
|
||||||
|
Stream<T> stream,
|
||||||
|
@Nonnull Function<T, SqlParameterSource> paramSourceBuilder) {
|
||||||
|
Objects.requireNonNull(stream);
|
||||||
|
Objects.requireNonNull(paramSourceBuilder);
|
||||||
|
return stream.map(paramSourceBuilder).toArray(SqlParameterSource[]::new);
|
||||||
|
}
|
||||||
|
}
|
@@ -1,3 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022-2023 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
package xyz.zhouxy.plusone.jdbc.common;
|
package xyz.zhouxy.plusone.jdbc.common;
|
||||||
|
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
|
@@ -1,3 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022-2023 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
package xyz.zhouxy.plusone.jdbc.common;
|
package xyz.zhouxy.plusone.jdbc.common;
|
||||||
|
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
|
@@ -1,3 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022-2023 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
package xyz.zhouxy.plusone.jdbc.converter;
|
package xyz.zhouxy.plusone.jdbc.converter;
|
||||||
|
|
||||||
import org.springframework.core.convert.converter.Converter;
|
import org.springframework.core.convert.converter.Converter;
|
||||||
|
@@ -1,3 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022-2023 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
package xyz.zhouxy.plusone.jdbc.converter;
|
package xyz.zhouxy.plusone.jdbc.converter;
|
||||||
|
|
||||||
import org.springframework.core.convert.converter.Converter;
|
import org.springframework.core.convert.converter.Converter;
|
||||||
|
@@ -1,3 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022-2023 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
package xyz.zhouxy.plusone.mail;
|
package xyz.zhouxy.plusone.mail;
|
||||||
|
|
||||||
import org.springframework.mail.SimpleMailMessage;
|
import org.springframework.mail.SimpleMailMessage;
|
||||||
|
@@ -1,3 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022-2023 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
package xyz.zhouxy.plusone.mail;
|
package xyz.zhouxy.plusone.mail;
|
||||||
|
|
||||||
import javax.mail.MessagingException;
|
import javax.mail.MessagingException;
|
||||||
|
@@ -1,6 +1,21 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022-2023 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
package xyz.zhouxy.plusone.mail;
|
package xyz.zhouxy.plusone.mail;
|
||||||
|
|
||||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
@@ -15,11 +30,10 @@ import org.springframework.mail.javamail.JavaMailSender;
|
|||||||
@Configuration
|
@Configuration
|
||||||
@EnableConfigurationProperties(PlusoneMailProperties.class)
|
@EnableConfigurationProperties(PlusoneMailProperties.class)
|
||||||
@ConditionalOnClass(MailService.class)
|
@ConditionalOnClass(MailService.class)
|
||||||
@EnableAutoConfiguration
|
|
||||||
public class PlusoneMailAutoConfiguration {
|
public class PlusoneMailAutoConfiguration {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public MailService mailService(JavaMailSender mailSender, PlusoneMailProperties mailProperties) {
|
MailService mailService(JavaMailSender mailSender, PlusoneMailProperties mailProperties) {
|
||||||
MailMessageFactory mailMessageFactory = new MailMessageFactory(mailProperties);
|
MailMessageFactory mailMessageFactory = new MailMessageFactory(mailProperties);
|
||||||
return new SimpleMailService(mailSender, mailMessageFactory);
|
return new SimpleMailService(mailSender, mailMessageFactory);
|
||||||
}
|
}
|
||||||
|
@@ -1,3 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022-2023 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
package xyz.zhouxy.plusone.mail;
|
package xyz.zhouxy.plusone.mail;
|
||||||
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
@@ -1,3 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022-2023 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
package xyz.zhouxy.plusone.mail;
|
package xyz.zhouxy.plusone.mail;
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
@@ -1,3 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022-2023 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
package xyz.zhouxy.plusone.mybatis;
|
package xyz.zhouxy.plusone.mybatis;
|
||||||
|
|
||||||
import org.apache.ibatis.session.SqlSessionFactory;
|
import org.apache.ibatis.session.SqlSessionFactory;
|
||||||
|
@@ -1,3 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022-2023 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
package xyz.zhouxy.plusone.mybatis;
|
package xyz.zhouxy.plusone.mybatis;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
|
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
|
||||||
|
@@ -0,0 +1,108 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022-2023 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package xyz.zhouxy.plusone.oss;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.InetSocketAddress;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
import org.csource.common.MyException;
|
||||||
|
import org.csource.fastdfs.ClientGlobal;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||||
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.util.CollectionUtils;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
|
import xyz.zhouxy.plusone.oss.FastDFSProperties.ConnectionPool;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@EnableConfigurationProperties(FastDFSProperties.class)
|
||||||
|
@ConditionalOnClass(FastDFSUtil.class)
|
||||||
|
public class FastDFSAutoConfig {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@SuppressWarnings("all")
|
||||||
|
FastDFSUtil fastDFSUtil(FastDFSProperties props) throws IOException, FastDFSException {
|
||||||
|
|
||||||
|
List<String> trackerServerStrList = props.getTrackerServers();
|
||||||
|
if (CollectionUtils.isEmpty(trackerServerStrList)) {
|
||||||
|
throw new FastDFSException(
|
||||||
|
String.format("configure item %s is required - ", ClientGlobal.PROP_KEY_TRACKER_SERVERS));
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
InetSocketAddress[] trackerServers = trackerServerStrList.stream()
|
||||||
|
.map(trackerServer -> {
|
||||||
|
String[] hostPort = trackerServer.trim().split(":");
|
||||||
|
String host = hostPort[0].trim();
|
||||||
|
int port = Integer.parseInt(hostPort[1].trim());
|
||||||
|
return new InetSocketAddress(host, port);
|
||||||
|
})
|
||||||
|
.toArray(InetSocketAddress[]::new);
|
||||||
|
ClientGlobal.initByTrackers(trackerServers);
|
||||||
|
|
||||||
|
var connectTimeoutInSecondsConf = props.getConnectTimeoutInSeconds();
|
||||||
|
if (connectTimeoutInSecondsConf != null) {
|
||||||
|
ClientGlobal.setG_connect_timeout(connectTimeoutInSecondsConf * 1000);
|
||||||
|
}
|
||||||
|
var networkTimeoutInSecondsConf = props.getNetworkTimeoutInSeconds();
|
||||||
|
if (networkTimeoutInSecondsConf != null) {
|
||||||
|
ClientGlobal.setG_network_timeout(networkTimeoutInSecondsConf * 1000);
|
||||||
|
}
|
||||||
|
var charsetConf = props.getCharset();
|
||||||
|
if (StringUtils.hasText(charsetConf)) {
|
||||||
|
ClientGlobal.setG_charset(charsetConf);
|
||||||
|
}
|
||||||
|
var httpAntiStealTokenConf = props.getHttpAntiStealToken();
|
||||||
|
if (httpAntiStealTokenConf != null) {
|
||||||
|
ClientGlobal.setG_anti_steal_token(httpAntiStealTokenConf);
|
||||||
|
}
|
||||||
|
var httpSecretKeyConf = props.getHttpSecretKey();
|
||||||
|
if (StringUtils.hasText(httpSecretKeyConf)) {
|
||||||
|
ClientGlobal.setG_secret_key(httpSecretKeyConf);
|
||||||
|
}
|
||||||
|
var httpTrackerHttpPortConf = props.getHttpTrackerHttpPort();
|
||||||
|
if (httpTrackerHttpPortConf != null) {
|
||||||
|
ClientGlobal.setG_tracker_http_port(httpTrackerHttpPortConf);
|
||||||
|
}
|
||||||
|
|
||||||
|
ConnectionPool connectionPool = props.getConnectionPool();
|
||||||
|
var poolEnabled = Objects.nonNull(connectionPool)
|
||||||
|
&& Boolean.TRUE.equals(connectionPool.getEnabled());
|
||||||
|
|
||||||
|
if (poolEnabled) {
|
||||||
|
var poolMaxCountPerEntry = connectionPool.getMaxCountPerEntry();
|
||||||
|
if (poolMaxCountPerEntry != null) {
|
||||||
|
ClientGlobal.g_connection_pool_max_count_per_entry = poolMaxCountPerEntry;
|
||||||
|
}
|
||||||
|
var poolMaxIdleTime = connectionPool.getMaxIdleTime();
|
||||||
|
if (poolMaxIdleTime != null) {
|
||||||
|
ClientGlobal.g_connection_pool_max_idle_time = poolMaxIdleTime * 1000;
|
||||||
|
}
|
||||||
|
var poolMaxWaitTimeInMS = connectionPool.getMaxWaitTimeInMs();
|
||||||
|
if (poolMaxWaitTimeInMS != null) {
|
||||||
|
ClientGlobal.g_connection_pool_max_wait_time_in_ms = poolMaxWaitTimeInMS;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new FastDFSUtil();
|
||||||
|
} catch (MyException e) {
|
||||||
|
throw new FastDFSException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022-2023 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package xyz.zhouxy.plusone.oss;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 封装 FastDFS 的 {@link org.csource.common.MyException}
|
||||||
|
*
|
||||||
|
* @author <a href="https://gitee.com/zhouxy108">ZhouXY</a>
|
||||||
|
*/
|
||||||
|
public class FastDFSException extends Exception {
|
||||||
|
private static final long serialVersionUID = 7871031982887742468L;
|
||||||
|
|
||||||
|
public FastDFSException() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public FastDFSException(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public FastDFSException(Throwable cause) {
|
||||||
|
super(cause);
|
||||||
|
}
|
||||||
|
|
||||||
|
public FastDFSException(String message, Throwable cause) {
|
||||||
|
super(message, cause);
|
||||||
|
}
|
||||||
|
|
||||||
|
public FastDFSException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
|
||||||
|
super(message, cause, enableSuppression, writableStackTrace);
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,137 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022-2023 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package xyz.zhouxy.plusone.oss;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
|
||||||
|
@ConfigurationProperties("fastdfs")
|
||||||
|
public class FastDFSProperties {
|
||||||
|
private Integer connectTimeoutInSeconds;
|
||||||
|
private Integer networkTimeoutInSeconds;
|
||||||
|
private String charset;
|
||||||
|
private Boolean httpAntiStealToken;
|
||||||
|
private String httpSecretKey;
|
||||||
|
private Integer httpTrackerHttpPort;
|
||||||
|
private List<String> trackerServers;
|
||||||
|
|
||||||
|
private ConnectionPool connectionPool;
|
||||||
|
|
||||||
|
public Integer getConnectTimeoutInSeconds() {
|
||||||
|
return connectTimeoutInSeconds;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setConnectTimeoutInSeconds(Integer connectTimeoutInSeconds) {
|
||||||
|
this.connectTimeoutInSeconds = connectTimeoutInSeconds;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getNetworkTimeoutInSeconds() {
|
||||||
|
return networkTimeoutInSeconds;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNetworkTimeoutInSeconds(Integer networkTimeoutInSeconds) {
|
||||||
|
this.networkTimeoutInSeconds = networkTimeoutInSeconds;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCharset() {
|
||||||
|
return charset;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCharset(String charset) {
|
||||||
|
this.charset = charset;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean getHttpAntiStealToken() {
|
||||||
|
return httpAntiStealToken;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHttpAntiStealToken(Boolean httpAntiStealToken) {
|
||||||
|
this.httpAntiStealToken = httpAntiStealToken;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getHttpSecretKey() {
|
||||||
|
return httpSecretKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHttpSecretKey(String httpSecretKey) {
|
||||||
|
this.httpSecretKey = httpSecretKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getHttpTrackerHttpPort() {
|
||||||
|
return httpTrackerHttpPort;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHttpTrackerHttpPort(Integer httpTrackerHttpPort) {
|
||||||
|
this.httpTrackerHttpPort = httpTrackerHttpPort;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getTrackerServers() {
|
||||||
|
return trackerServers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTrackerServers(List<String> trackerServers) {
|
||||||
|
this.trackerServers = trackerServers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConnectionPool getConnectionPool() {
|
||||||
|
return connectionPool;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setConnectionPool(ConnectionPool connectionPool) {
|
||||||
|
this.connectionPool = connectionPool;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class ConnectionPool {
|
||||||
|
private Boolean enabled;
|
||||||
|
private Integer maxCountPerEntry;
|
||||||
|
private Integer maxIdleTime;
|
||||||
|
private Integer maxWaitTimeInMs;
|
||||||
|
|
||||||
|
public Boolean getEnabled() {
|
||||||
|
return enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEnabled(Boolean enabled) {
|
||||||
|
this.enabled = enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getMaxCountPerEntry() {
|
||||||
|
return maxCountPerEntry;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMaxCountPerEntry(Integer maxCountPerEntry) {
|
||||||
|
this.maxCountPerEntry = maxCountPerEntry;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getMaxIdleTime() {
|
||||||
|
return maxIdleTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMaxIdleTime(Integer maxIdleTime) {
|
||||||
|
this.maxIdleTime = maxIdleTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getMaxWaitTimeInMs() {
|
||||||
|
return maxWaitTimeInMs;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMaxWaitTimeInMs(Integer maxWaitTimeInMs) {
|
||||||
|
this.maxWaitTimeInMs = maxWaitTimeInMs;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,142 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022-2023 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package xyz.zhouxy.plusone.oss;
|
||||||
|
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
|
||||||
|
import org.csource.common.MyException;
|
||||||
|
import org.csource.common.NameValuePair;
|
||||||
|
import org.csource.fastdfs.FileInfo;
|
||||||
|
import org.csource.fastdfs.StorageClient;
|
||||||
|
import org.csource.fastdfs.StorageServer;
|
||||||
|
import org.csource.fastdfs.TrackerClient;
|
||||||
|
import org.csource.fastdfs.TrackerServer;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
public class FastDFSUtil {
|
||||||
|
|
||||||
|
private final TrackerServer trackerServer;
|
||||||
|
private final StorageServer storageServer;
|
||||||
|
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(FastDFSUtil.class);
|
||||||
|
|
||||||
|
FastDFSUtil() throws IOException, MyException {
|
||||||
|
TrackerClient trackerClient = new TrackerClient();
|
||||||
|
this.trackerServer = trackerClient.getTrackerServer();
|
||||||
|
this.storageServer = trackerClient.getStoreStorage(trackerServer);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 上传文件到 Fast DFS,失败将抛异常
|
||||||
|
*
|
||||||
|
* @param file 文件信息
|
||||||
|
* @return 2 elements string array if success:<br>
|
||||||
|
* <ul>
|
||||||
|
* <li>results[0]: the group name to store the file</li>
|
||||||
|
* </ul>
|
||||||
|
* <ul>
|
||||||
|
* <li>results[1]: the new created filename</li>
|
||||||
|
* </ul>
|
||||||
|
* return null if fail
|
||||||
|
* @throws FastDFSException
|
||||||
|
*/
|
||||||
|
public String[] upload(FastDFSFile file) throws FastDFSException {
|
||||||
|
logger.info("File Name: {}, File Length: {}", file.getName(), file.getContent().length);
|
||||||
|
|
||||||
|
NameValuePair[] metaList = new NameValuePair[1];
|
||||||
|
metaList[0] = new NameValuePair("author", file.getAuthor());
|
||||||
|
|
||||||
|
long startTime = System.currentTimeMillis();
|
||||||
|
StorageClient storageClient = null;
|
||||||
|
String[] uploadResults = null;
|
||||||
|
try {
|
||||||
|
storageClient = new StorageClient(this.trackerServer, this.storageServer);
|
||||||
|
uploadResults = storageClient.upload_file(file.getContent(), file.getExt(), metaList);
|
||||||
|
|
||||||
|
if (uploadResults == null) {
|
||||||
|
throw new FastDFSException("upload file fail, error code: " + storageClient.getErrorCode());
|
||||||
|
}
|
||||||
|
logger.info("Upload file successfully!!! group_name: {}, remoteFileName: {}, time used: {} ms",
|
||||||
|
uploadResults[0], uploadResults[1], System.currentTimeMillis() - startTime);
|
||||||
|
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new FastDFSException("IO Exception when uploadind the file:" + file.getName(), e);
|
||||||
|
} catch (MyException e) {
|
||||||
|
throw new FastDFSException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
return uploadResults;
|
||||||
|
}
|
||||||
|
|
||||||
|
public FileInfo getFile(String groupName, String remoteFileName) throws FastDFSException {
|
||||||
|
try {
|
||||||
|
StorageClient storageClient = new StorageClient(this.trackerServer, this.storageServer);
|
||||||
|
return storageClient.get_file_info(groupName, remoteFileName);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new FastDFSException("IO Exception: Get File from Fast DFS failed", e);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new FastDFSException("Non IO Exception: Get File from Fast DFS failed", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public InputStream downFile(String groupName, String remoteFileName) throws FastDFSException {
|
||||||
|
try {
|
||||||
|
StorageClient storageClient = new StorageClient(this.trackerServer, this.storageServer);
|
||||||
|
byte[] fileByte = storageClient.download_file(groupName, remoteFileName);
|
||||||
|
InputStream ins = new ByteArrayInputStream(fileByte);
|
||||||
|
return ins;
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new FastDFSException("IO Exception: Get File from Fast DFS failed", e);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new FastDFSException("Non IO Exception: Get File from Fast DFS failed", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deleteFile(String groupName, String remoteFileName) throws FastDFSException {
|
||||||
|
StorageClient storageClient = new StorageClient(this.trackerServer, this.storageServer);
|
||||||
|
try {
|
||||||
|
int i = storageClient.delete_file(groupName, remoteFileName);
|
||||||
|
if (i == 0) {
|
||||||
|
logger.info("Delete file SUCCESSFULLY!!!");
|
||||||
|
} else {
|
||||||
|
throw new FastDFSException("Delete file failed, error code is: " + i);
|
||||||
|
}
|
||||||
|
} catch (IOException | MyException e) {
|
||||||
|
throw new FastDFSException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
public static final class FastDFSFile {
|
||||||
|
private String name;
|
||||||
|
private byte[] content;
|
||||||
|
private String ext;
|
||||||
|
private String md5;
|
||||||
|
private String author;
|
||||||
|
|
||||||
|
public FastDFSFile(String name, byte[] content, String ext) {
|
||||||
|
this.name = name;
|
||||||
|
this.content = content;
|
||||||
|
this.ext = ext;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -1,3 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022-2023 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
package xyz.zhouxy.plusone.redis;
|
package xyz.zhouxy.plusone.redis;
|
||||||
|
|
||||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||||
|
@@ -1,3 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022-2023 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
package xyz.zhouxy.plusone.redis;
|
package xyz.zhouxy.plusone.redis;
|
||||||
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
@@ -1,3 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022-2023 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
package xyz.zhouxy.plusone.sms;
|
package xyz.zhouxy.plusone.sms;
|
||||||
|
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||||
@@ -11,17 +27,12 @@ import org.springframework.context.annotation.Configuration;
|
|||||||
* @author <a href="https://gitee.com/zhouxy108">ZhouXY</a>
|
* @author <a href="https://gitee.com/zhouxy108">ZhouXY</a>
|
||||||
*/
|
*/
|
||||||
@Configuration
|
@Configuration
|
||||||
@EnableConfigurationProperties(value = {
|
@EnableConfigurationProperties(SmsProperties.class)
|
||||||
SmsProperties.class,
|
|
||||||
SmsCredentialProperties.class,
|
|
||||||
SmsClientProperties.class,
|
|
||||||
SmsHttpProperties.class,
|
|
||||||
SmsProxyProperties.class})
|
|
||||||
@ConditionalOnClass(SmsService.class)
|
@ConditionalOnClass(SmsService.class)
|
||||||
public class PlusoneSmsAutoConfiguration {
|
public class PlusoneSmsAutoConfiguration {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public SmsService smsService(SmsProperties smsProperties) {
|
SmsService smsService(SmsProperties smsProperties) {
|
||||||
return new TencentSmsServiceImpl(smsProperties);
|
return new TencentSmsServiceImpl(smsProperties);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,17 +1,30 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022-2023 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
package xyz.zhouxy.plusone.sms;
|
package xyz.zhouxy.plusone.sms;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SMS 相关参数
|
* SMS 相关参数
|
||||||
*
|
*
|
||||||
* @author <a href="https://gitee.com/zhouxy108">ZhouXY</a>
|
* @author <a href="https://gitee.com/zhouxy108">ZhouXY</a>
|
||||||
*/
|
*/
|
||||||
@Data
|
|
||||||
@ConfigurationProperties("plusone.sms")
|
@ConfigurationProperties("plusone.sms")
|
||||||
public class SmsProperties {
|
public class SmsProperties {
|
||||||
private String region;
|
private String region;
|
||||||
@@ -19,33 +32,138 @@ public class SmsProperties {
|
|||||||
private SmsClientProperties client;
|
private SmsClientProperties client;
|
||||||
private String appId;
|
private String appId;
|
||||||
private Map<String, String> templates;
|
private Map<String, String> templates;
|
||||||
}
|
|
||||||
|
|
||||||
@Data
|
public String getRegion() {
|
||||||
@ConfigurationProperties("plusone.sms.credential")
|
return region;
|
||||||
class SmsCredentialProperties {
|
}
|
||||||
private String secretId;
|
|
||||||
private String secretKey;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Data
|
public void setRegion(String region) {
|
||||||
@ConfigurationProperties("plusone.sms.client")
|
this.region = region;
|
||||||
class SmsClientProperties {
|
}
|
||||||
private String signMethod;
|
|
||||||
private SmsHttpProperties http;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Data
|
public SmsCredentialProperties getCredential() {
|
||||||
@ConfigurationProperties("plusone.sms.client.http")
|
return credential;
|
||||||
class SmsHttpProperties {
|
}
|
||||||
private SmsProxyProperties proxy;
|
|
||||||
private String reqMethod;
|
public void setCredential(SmsCredentialProperties credential) {
|
||||||
private Integer connTimeout;
|
this.credential = credential;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public SmsClientProperties getClient() {
|
||||||
|
return client;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setClient(SmsClientProperties client) {
|
||||||
|
this.client = client;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAppId() {
|
||||||
|
return appId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAppId(String appId) {
|
||||||
|
this.appId = appId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, String> getTemplates() {
|
||||||
|
return templates;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTemplates(Map<String, String> templates) {
|
||||||
|
this.templates = templates;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class SmsCredentialProperties {
|
||||||
|
private String secretId;
|
||||||
|
private String secretKey;
|
||||||
|
|
||||||
|
public String getSecretId() {
|
||||||
|
return secretId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSecretId(String secretId) {
|
||||||
|
this.secretId = secretId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSecretKey() {
|
||||||
|
return secretKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSecretKey(String secretKey) {
|
||||||
|
this.secretKey = secretKey;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class SmsClientProperties {
|
||||||
|
private String signMethod;
|
||||||
|
private SmsHttpProperties http;
|
||||||
|
|
||||||
|
public String getSignMethod() {
|
||||||
|
return signMethod;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSignMethod(String signMethod) {
|
||||||
|
this.signMethod = signMethod;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SmsHttpProperties getHttp() {
|
||||||
|
return http;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHttp(SmsHttpProperties http) {
|
||||||
|
this.http = http;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class SmsHttpProperties {
|
||||||
|
private SmsProxyProperties proxy;
|
||||||
|
private String reqMethod;
|
||||||
|
private Integer connTimeout;
|
||||||
|
|
||||||
|
public SmsProxyProperties getProxy() {
|
||||||
|
return proxy;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProxy(SmsProxyProperties proxy) {
|
||||||
|
this.proxy = proxy;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getReqMethod() {
|
||||||
|
return reqMethod;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setReqMethod(String reqMethod) {
|
||||||
|
this.reqMethod = reqMethod;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getConnTimeout() {
|
||||||
|
return connTimeout;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setConnTimeout(Integer connTimeout) {
|
||||||
|
this.connTimeout = connTimeout;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class SmsProxyProperties {
|
||||||
|
private String host;
|
||||||
|
private Integer port;
|
||||||
|
|
||||||
|
public String getHost() {
|
||||||
|
return host;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHost(String host) {
|
||||||
|
this.host = host;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getPort() {
|
||||||
|
return port;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPort(Integer port) {
|
||||||
|
this.port = port;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Data
|
|
||||||
@ConfigurationProperties("plusone.sms.client.http.proxy")
|
|
||||||
class SmsProxyProperties {
|
|
||||||
private String host;
|
|
||||||
private Integer port;
|
|
||||||
}
|
}
|
||||||
|
@@ -1,3 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022-2023 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
package xyz.zhouxy.plusone.sms;
|
package xyz.zhouxy.plusone.sms;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -1,3 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022-2023 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
package xyz.zhouxy.plusone.sms;
|
package xyz.zhouxy.plusone.sms;
|
||||||
|
|
||||||
import com.tencentcloudapi.common.Credential;
|
import com.tencentcloudapi.common.Credential;
|
||||||
@@ -12,7 +28,10 @@ import org.springframework.stereotype.Service;
|
|||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import xyz.zhouxy.plusone.constant.ErrorCodeConsts;
|
import xyz.zhouxy.plusone.constant.ErrorCodeConsts;
|
||||||
import xyz.zhouxy.plusone.exception.PlusoneException;
|
import xyz.zhouxy.plusone.exception.BizException;
|
||||||
|
import xyz.zhouxy.plusone.sms.SmsProperties.SmsCredentialProperties;
|
||||||
|
import xyz.zhouxy.plusone.sms.SmsProperties.SmsHttpProperties;
|
||||||
|
import xyz.zhouxy.plusone.sms.SmsProperties.SmsProxyProperties;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 使用腾讯 SMS 服务
|
* 使用腾讯 SMS 服务
|
||||||
@@ -66,7 +85,7 @@ public class TencentSmsServiceImpl implements SmsService {
|
|||||||
|
|
||||||
} catch (TencentCloudSDKException e) {
|
} catch (TencentCloudSDKException e) {
|
||||||
log.error(e.getMessage(), e);
|
log.error(e.getMessage(), e);
|
||||||
throw new PlusoneException(ErrorCodeConsts.DEFAULT_ERROR_CODE, e);
|
throw new BizException(ErrorCodeConsts.DEFAULT_ERROR_CODE, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,3 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022-2023 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
package xyz.zhouxy.plusone.spring;
|
package xyz.zhouxy.plusone.spring;
|
||||||
|
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
|
@@ -1,34 +0,0 @@
|
|||||||
package xyz.zhouxy.plusone.sql;
|
|
||||||
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
import org.apache.ibatis.jdbc.AbstractSQL;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 扩展 MyBatis 中的 SQL 语句构造器
|
|
||||||
*
|
|
||||||
* @author <a href="https://gitee.com/zhouxy108">ZhouXY</a>
|
|
||||||
*/
|
|
||||||
public class SQL extends AbstractSQL<SQL> {
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,3 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022-2023 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
package xyz.zhouxy.plusone.validator;
|
package xyz.zhouxy.plusone.validator;
|
||||||
|
|
||||||
import java.lang.annotation.ElementType;
|
import java.lang.annotation.ElementType;
|
||||||
|
@@ -0,0 +1,30 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022-2023 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package xyz.zhouxy.plusone.validator;
|
||||||
|
|
||||||
|
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||||
|
|
||||||
|
import xyz.zhouxy.plusone.exception.handler.BaseExceptionHandler;
|
||||||
|
|
||||||
|
@RestControllerAdvice
|
||||||
|
public class InvalidInputExceptionHandler extends BaseExceptionHandler {
|
||||||
|
|
||||||
|
public InvalidInputExceptionHandler(ExceptionInfoHolder exceptionInfoHolder) {
|
||||||
|
super(exceptionInfoHolder);
|
||||||
|
set(InvalidInputException.class, InvalidInputException.ERROR_CODE, "无效的用户输入");
|
||||||
|
}
|
||||||
|
}
|
@@ -1,3 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022-2023 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
package xyz.zhouxy.plusone.validator;
|
package xyz.zhouxy.plusone.validator;
|
||||||
|
|
||||||
import java.lang.annotation.ElementType;
|
import java.lang.annotation.ElementType;
|
||||||
|
@@ -1,3 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022-2023 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
package xyz.zhouxy.plusone.web.config;
|
package xyz.zhouxy.plusone.web.config;
|
||||||
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
@@ -1,3 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022-2023 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
package xyz.zhouxy.plusone.web.config;
|
package xyz.zhouxy.plusone.web.config;
|
||||||
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
@@ -0,0 +1,4 @@
|
|||||||
|
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
||||||
|
xyz.zhouxy.plusone.sms.PlusoneSmsAutoConfiguration,\
|
||||||
|
xyz.zhouxy.plusone.mail.PlusoneMailAutoConfiguration,\
|
||||||
|
xyz.zhouxy.plusone.oss.FastDFSAutoConfig
|
@@ -1,43 +0,0 @@
|
|||||||
package xyz.zhouxy.plusone.validatortest;
|
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
import xyz.zhouxy.plusone.constant.RegexConsts;
|
|
||||||
import xyz.zhouxy.plusone.validator.validator2.BaseValidator2;
|
|
||||||
|
|
||||||
class BaseValidator2Test {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void testValid() {
|
|
||||||
LoginCommand loginCommand = new LoginCommand("13169053215@qq.com", "A1qZ6c-cQ78=^(", false);
|
|
||||||
LoginCommandValidator.INSTANCE.validate(loginCommand);
|
|
||||||
System.err.println(loginCommand);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Data
|
|
||||||
@NoArgsConstructor
|
|
||||||
@AllArgsConstructor
|
|
||||||
class LoginCommand {
|
|
||||||
private String account;
|
|
||||||
private String pwd;
|
|
||||||
private boolean rememberMe;
|
|
||||||
}
|
|
||||||
|
|
||||||
class LoginCommandValidator extends BaseValidator2<LoginCommand> {
|
|
||||||
|
|
||||||
public static final LoginCommandValidator INSTANCE = new LoginCommandValidator();
|
|
||||||
|
|
||||||
private LoginCommandValidator() {
|
|
||||||
ruleFor(LoginCommand::getAccount)
|
|
||||||
.notNull("邮箱地址不能为空")
|
|
||||||
.matchesOr(new String[] { RegexConsts.EMAIL, RegexConsts.MOBILE_PHONE }, value -> new RuntimeException('"' + value + "\" 不是邮箱地址或手机号"));
|
|
||||||
ruleFor(LoginCommand::getPwd)
|
|
||||||
.notNull("密码不能为空")
|
|
||||||
.notEmpty("密码不能为空")
|
|
||||||
.matches(RegexConsts.PASSWORD, "密码格式错误");
|
|
||||||
}
|
|
||||||
}
|
|
@@ -0,0 +1,62 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022-2023 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package xyz.zhouxy.plusone.validatortest;
|
||||||
|
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import xyz.zhouxy.plusone.commons.constant.PatternConsts;
|
||||||
|
import xyz.zhouxy.plusone.validator.BaseValidator;
|
||||||
|
|
||||||
|
class BaseValidatorTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testValid() {
|
||||||
|
LoginCommand loginCommand = new LoginCommand("13169053215@qq.com", "A1qZ6c-cQ78=^(", false);
|
||||||
|
LoginCommandValidator.INSTANCE.validate(loginCommand);
|
||||||
|
System.err.println(loginCommand);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
class LoginCommand {
|
||||||
|
private String account;
|
||||||
|
private String pwd;
|
||||||
|
private boolean rememberMe;
|
||||||
|
}
|
||||||
|
|
||||||
|
class LoginCommandValidator extends BaseValidator<LoginCommand> {
|
||||||
|
|
||||||
|
public static final LoginCommandValidator INSTANCE = new LoginCommandValidator();
|
||||||
|
|
||||||
|
private LoginCommandValidator() {
|
||||||
|
ruleForString(LoginCommand::getAccount)
|
||||||
|
.notNull("邮箱地址不能为空")
|
||||||
|
.matchesOr(new Pattern[] { PatternConsts.EMAIL, PatternConsts.MOBILE_PHONE },
|
||||||
|
value -> new RuntimeException('"' + value + "\" 不是邮箱地址或手机号"));
|
||||||
|
ruleForString(LoginCommand::getPwd)
|
||||||
|
.notNull("密码不能为空")
|
||||||
|
.notEmpty("密码不能为空")
|
||||||
|
.matches(PatternConsts.PASSWORD, "密码格式错误");
|
||||||
|
}
|
||||||
|
}
|
@@ -7,9 +7,7 @@
|
|||||||
<version>1.0.0-SNAPSHOT</version>
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<groupId>xyz.zhouxy</groupId>
|
|
||||||
<artifactId>plusone-basic</artifactId>
|
<artifactId>plusone-basic</artifactId>
|
||||||
<version>1.0.0-SNAPSHOT</version>
|
|
||||||
|
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
|
|
||||||
|
@@ -7,18 +7,11 @@
|
|||||||
<version>1.0.0-SNAPSHOT</version>
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<groupId>xyz.zhouxy</groupId>
|
|
||||||
<artifactId>plusone-start</artifactId>
|
<artifactId>plusone-start</artifactId>
|
||||||
<version>1.0.0-SNAPSHOT</version>
|
|
||||||
|
|
||||||
<name>plusone-start</name>
|
<name>plusone-start</name>
|
||||||
|
|
||||||
<description>参考 DDD 落地的脚手架</description>
|
<description>参考 DDD 落地的脚手架</description>
|
||||||
|
|
||||||
<properties>
|
|
||||||
<spring-boot.version>2.7.6</spring-boot.version>
|
|
||||||
</properties>
|
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
|
@@ -1,3 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022-2023 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
package xyz.zhouxy.plusone;
|
package xyz.zhouxy.plusone;
|
||||||
|
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
|
@@ -1,12 +0,0 @@
|
|||||||
package xyz.zhouxy.plusone;
|
|
||||||
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
@RestController
|
|
||||||
public class TestController {
|
|
||||||
@RequestMapping("/test")
|
|
||||||
public String test() throws Exception {
|
|
||||||
throw new Exception();
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,34 +1,32 @@
|
|||||||
{
|
{"properties": [
|
||||||
"properties": [
|
{
|
||||||
{
|
"name": "plusone.application.name",
|
||||||
"name": "plusone.application.name",
|
"type": "java.lang.String",
|
||||||
"type": "java.lang.String",
|
"description": "A description for 'plusone.application.name'"
|
||||||
"description": "A description for 'plusone.application.name'"
|
},
|
||||||
},
|
{
|
||||||
{
|
"name": "plusone.server.port",
|
||||||
"name": "plusone.server.port",
|
"type": "java.lang.Integer",
|
||||||
"type": "java.lang.Integer",
|
"description": "A description for 'plusone.server.port'"
|
||||||
"description": "A description for 'plusone.server.port'"
|
},
|
||||||
},
|
{
|
||||||
{
|
"name": "plusone.debug",
|
||||||
"name": "plusone.debug",
|
"type": "java.lang.Boolean",
|
||||||
"type": "java.lang.Boolean",
|
"description": "A description for 'plusone.debug'"
|
||||||
"description": "A description for 'plusone.debug'"
|
},
|
||||||
},
|
{
|
||||||
{
|
"name": "plusone.mail.host",
|
||||||
"name": "plusone.mail.host",
|
"type": "java.lang.String",
|
||||||
"type": "java.lang.String",
|
"description": "A description for 'plusone.mail.host'"
|
||||||
"description": "A description for 'plusone.mail.host'"
|
},
|
||||||
},
|
{
|
||||||
{
|
"name": "plusone.mail.password",
|
||||||
"name": "plusone.mail.password",
|
"type": "java.lang.String",
|
||||||
"type": "java.lang.String",
|
"description": "A description for 'plusone.mail.password'"
|
||||||
"description": "A description for 'plusone.mail.password'"
|
},
|
||||||
},
|
{
|
||||||
{
|
"name": "plusone.exception.handle-all-exception",
|
||||||
"name": "plusone.exception.handle-all-exception",
|
"type": "java.lang.Boolean",
|
||||||
"type": "java.lang.Boolean",
|
"description": "A description for 'plusone.exception.handle-all-exception'"
|
||||||
"description": "A description for 'plusone.exception.handle-all-exception'"
|
}
|
||||||
}
|
]}
|
||||||
]
|
|
||||||
}
|
|
||||||
|
78
plusone-start/src/main/resources/application-public.yaml
Normal file
78
plusone-start/src/main/resources/application-public.yaml
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
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
|
||||||
|
|
||||||
|
fastdfs:
|
||||||
|
connect_timeout_in_seconds: 5
|
||||||
|
network_timeout_in_seconds: 30
|
||||||
|
charset: UTF-8
|
||||||
|
http_anti_steal_token: false
|
||||||
|
http_secret_key: FastDFS1234567890
|
||||||
|
http_tracker_http_port: 80
|
||||||
|
tracker_servers: 10.0.11.201:22122,10.0.11.202:22122,10.0.11.203:22122
|
||||||
|
connection_pool:
|
||||||
|
enabled: true
|
||||||
|
max_count_per_entry: 500
|
||||||
|
max_idle_time: 3600
|
||||||
|
max_wait_time_in_ms: 1000
|
@@ -1,79 +1,16 @@
|
|||||||
|
spring:
|
||||||
|
profiles:
|
||||||
|
active: public
|
||||||
|
|
||||||
plusone:
|
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:
|
mail:
|
||||||
host: smtp.163.com
|
|
||||||
#设置邮件发送者
|
|
||||||
from: example@163.com
|
|
||||||
password: XXXXXXXXXXXXXXXX
|
|
||||||
subject:
|
subject:
|
||||||
code: Plusone
|
'[code]': Plusone
|
||||||
template:
|
template:
|
||||||
code: 【Plusone】验证码:%s,10分钟内有效,请勿泄露。
|
'[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:
|
logging:
|
||||||
file:
|
|
||||||
name: ${user.home}/logs/${plusone.application.name}.log
|
|
||||||
level:
|
level:
|
||||||
root: INFO
|
root: info
|
||||||
xyz.zhouxy.plusone: DEBUG
|
'[xyz.zhouxy.plusone]': debug
|
||||||
org.springframework.jdbc.core: DEBUG
|
|
||||||
xyz.zhouxy.plusone.system.application.query: DEBUG
|
|
||||||
|
@@ -10,23 +10,23 @@
|
|||||||
</encoder>
|
</encoder>
|
||||||
</appender>
|
</appender>
|
||||||
|
|
||||||
<!-- <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||||
<encoder>
|
<encoder>
|
||||||
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %5level ${PID:- } - [%15.15t] %-50.50logger : %msg%n</pattern>
|
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %5level ${PID:- } - [%15.15t] %-50.50logger : %msg%n</pattern>
|
||||||
<charset>utf-8</charset>
|
<charset>utf-8</charset>
|
||||||
</encoder>
|
</encoder>
|
||||||
<file>log/output.log</file>
|
<file>log/plusone.log</file>
|
||||||
<rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
|
<rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
|
||||||
<fileNamePattern>log/output.log.%i</fileNamePattern>
|
<fileNamePattern>log/plusone.log.%i</fileNamePattern>
|
||||||
</rollingPolicy>
|
</rollingPolicy>
|
||||||
<triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
|
<triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
|
||||||
<MaxFileSize>20MB</MaxFileSize>
|
<MaxFileSize>20MB</MaxFileSize>
|
||||||
</triggeringPolicy>
|
</triggeringPolicy>
|
||||||
</appender> -->
|
</appender>
|
||||||
|
|
||||||
<root level="INFO">
|
<root level="INFO">
|
||||||
<appender-ref ref="CONSOLE" />
|
<appender-ref ref="CONSOLE" />
|
||||||
<!-- <appender-ref ref="FILE" /> -->
|
<appender-ref ref="FILE" />
|
||||||
</root>
|
</root>
|
||||||
|
|
||||||
</configuration>
|
</configuration>
|
||||||
|
@@ -0,0 +1,49 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022-2023 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package xyz.zhouxy.plusone;
|
||||||
|
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
import org.apache.commons.io.IOUtils;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import xyz.zhouxy.plusone.oss.FastDFSException;
|
||||||
|
import xyz.zhouxy.plusone.oss.FastDFSUtil;
|
||||||
|
import xyz.zhouxy.plusone.oss.FastDFSUtil.FastDFSFile;
|
||||||
|
|
||||||
|
@SpringBootTest(classes = PlusoneApplication.class)
|
||||||
|
@Slf4j
|
||||||
|
class FastDFSTests {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
FastDFSUtil fastDFSUtil;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testOSS() throws FileNotFoundException, IOException, FastDFSException {
|
||||||
|
try (FileInputStream in = new FileInputStream("D:\\ZhouXY\\Desktop\\666.png");) {
|
||||||
|
byte[] content = IOUtils.toByteArray(in);
|
||||||
|
String[] upload = fastDFSUtil.upload(new FastDFSFile("666.png", content, "png"));
|
||||||
|
log.info(String.join("/", upload));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -1,3 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022-2023 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
package xyz.zhouxy.plusone;
|
package xyz.zhouxy.plusone;
|
||||||
|
|
||||||
import java.io.ObjectStreamClass;
|
import java.io.ObjectStreamClass;
|
||||||
@@ -5,14 +21,14 @@ import java.io.ObjectStreamClass;
|
|||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import xyz.zhouxy.plusone.exception.PlusoneException;
|
import xyz.zhouxy.plusone.exception.*;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
class SerialTests {
|
class SerialTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testSerialVersionUID() {
|
void testSerialVersionUID() {
|
||||||
var cl = PlusoneException.class;
|
var cl = SysException.class;
|
||||||
var c = ObjectStreamClass.lookup(cl);
|
var c = ObjectStreamClass.lookup(cl);
|
||||||
var uid = c.getSerialVersionUID();
|
var uid = c.getSerialVersionUID();
|
||||||
log.info("\n @java.io.Serial" +
|
log.info("\n @java.io.Serial" +
|
||||||
|
@@ -1,5 +1,23 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022-2023 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
package xyz.zhouxy.plusone;
|
package xyz.zhouxy.plusone;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
@@ -25,6 +43,7 @@ class TestAop {
|
|||||||
command.setPrincipal("Code108");
|
command.setPrincipal("Code108");
|
||||||
command.setPassword("2333");
|
command.setPassword("2333");
|
||||||
command.setRememberMe(false);
|
command.setRememberMe(false);
|
||||||
|
assertNotNull(service);
|
||||||
LoginInfoViewObject loginInfo = service.loginByPassword(command);
|
LoginInfoViewObject loginInfo = service.loginByPassword(command);
|
||||||
System.err.println(loginInfo);
|
System.err.println(loginInfo);
|
||||||
}
|
}
|
||||||
|
16
plusone-start/src/test/resources/application.yaml
Normal file
16
plusone-start/src/test/resources/application.yaml
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
spring:
|
||||||
|
profiles:
|
||||||
|
active: secret
|
||||||
|
|
||||||
|
plusone:
|
||||||
|
# 邮件发送相关参数
|
||||||
|
mail:
|
||||||
|
subject:
|
||||||
|
'[code]': Plusone
|
||||||
|
template:
|
||||||
|
'[code]': 【Plusone】验证码:%s,10分钟内有效,请勿泄露。
|
||||||
|
# 日志配置
|
||||||
|
logging:
|
||||||
|
level:
|
||||||
|
root: info
|
||||||
|
'[xyz.zhouxy.plusone]': debug
|
@@ -0,0 +1,48 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022-2023 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package xyz.zhouxy.plusone.system.application.common.exception;
|
||||||
|
|
||||||
|
import xyz.zhouxy.plusone.exception.BizException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 不支持的 Principal 类型出现时抛出的异常
|
||||||
|
*
|
||||||
|
* @author <a href="https://zhouxy.xyz:3000/ZhouXY108">ZhouXY</a>
|
||||||
|
*/
|
||||||
|
public class UnsupportedPrincipalTypeException extends BizException {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 5207757290868470762L;
|
||||||
|
|
||||||
|
public static final int ERR_CODE = 4040201;
|
||||||
|
private static final String DEFAULT_ERROR_MSG = "不支持的 PrincipalType";
|
||||||
|
|
||||||
|
public UnsupportedPrincipalTypeException() {
|
||||||
|
super(ERR_CODE, DEFAULT_ERROR_MSG);
|
||||||
|
}
|
||||||
|
|
||||||
|
public UnsupportedPrincipalTypeException(String msg) {
|
||||||
|
super(ERR_CODE, msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public UnsupportedPrincipalTypeException(Throwable cause) {
|
||||||
|
super(ERR_CODE, cause);
|
||||||
|
}
|
||||||
|
|
||||||
|
public UnsupportedPrincipalTypeException(String msg, Throwable cause) {
|
||||||
|
super(ERR_CODE, msg, cause);
|
||||||
|
}
|
||||||
|
}
|
@@ -1,3 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022-2023 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
package xyz.zhouxy.plusone.system.application.common.util;
|
package xyz.zhouxy.plusone.system.application.common.util;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@@ -1,18 +1,36 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022-2023 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
package xyz.zhouxy.plusone.system.application.common.util;
|
package xyz.zhouxy.plusone.system.application.common.util;
|
||||||
|
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import xyz.zhouxy.plusone.constant.RegexConsts;
|
import xyz.zhouxy.plusone.commons.constant.PatternConsts;
|
||||||
|
|
||||||
public enum PrincipalType {
|
public enum PrincipalType {
|
||||||
EMAIL(RegexConsts.EMAIL),
|
EMAIL(PatternConsts.EMAIL),
|
||||||
MOBILE_PHONE(RegexConsts.MOBILE_PHONE),
|
MOBILE_PHONE(PatternConsts.MOBILE_PHONE),
|
||||||
USERNAME(RegexConsts.USERNAME)
|
USERNAME(PatternConsts.USERNAME)
|
||||||
;
|
;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private final String regex;
|
private final Pattern regex;
|
||||||
|
|
||||||
PrincipalType(String regex) {
|
PrincipalType(Pattern regex) {
|
||||||
this.regex = regex;
|
this.regex = regex;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,12 +1,28 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022-2023 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
package xyz.zhouxy.plusone.system.application.common.util;
|
package xyz.zhouxy.plusone.system.application.common.util;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
import xyz.zhouxy.plusone.system.application.common.exception.UnsupportedPrincipalTypeException;
|
||||||
import xyz.zhouxy.plusone.system.domain.model.account.Email;
|
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.MobilePhone;
|
||||||
import xyz.zhouxy.plusone.system.domain.model.account.Principal;
|
import xyz.zhouxy.plusone.system.domain.model.account.Principal;
|
||||||
import xyz.zhouxy.plusone.system.domain.model.account.Username;
|
import xyz.zhouxy.plusone.system.domain.model.account.Username;
|
||||||
import xyz.zhouxy.plusone.validator.InvalidInputException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据字面值,判断并生成 {@link Principal} 值对象。
|
* 根据字面值,判断并生成 {@link Principal} 值对象。
|
||||||
@@ -16,7 +32,7 @@ import xyz.zhouxy.plusone.validator.InvalidInputException;
|
|||||||
* @see Username
|
* @see Username
|
||||||
* @see Email
|
* @see Email
|
||||||
* @see MobilePhone
|
* @see MobilePhone
|
||||||
* @see InvalidInputException
|
* @see UnsupportedPrincipalTypeException
|
||||||
*/
|
*/
|
||||||
public class PrincipalUtil {
|
public class PrincipalUtil {
|
||||||
|
|
||||||
@@ -30,11 +46,11 @@ public class PrincipalUtil {
|
|||||||
}
|
}
|
||||||
PrincipalType[] principalTypes = PrincipalType.values();
|
PrincipalType[] principalTypes = PrincipalType.values();
|
||||||
for (var principalType : principalTypes) {
|
for (var principalType : principalTypes) {
|
||||||
if (principal.matches(principalType.getRegex())) {
|
if (principalType.getRegex().matcher(principal).matches()) {
|
||||||
return principalType;
|
return principalType;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw InvalidInputException.unsupportedPrincipalTypeException();
|
throw new UnsupportedPrincipalTypeException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Principal getPrincipal(@Nullable String principal) {
|
public static Principal getPrincipal(@Nullable String principal) {
|
||||||
@@ -48,7 +64,7 @@ public class PrincipalUtil {
|
|||||||
if (principalType == PrincipalType.USERNAME) {
|
if (principalType == PrincipalType.USERNAME) {
|
||||||
return Username.of(principal);
|
return Username.of(principal);
|
||||||
}
|
}
|
||||||
throw InvalidInputException.unsupportedPrincipalTypeException();
|
throw new UnsupportedPrincipalTypeException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Principal getEmailOrMobilePhone(@Nullable String principal) {
|
public static Principal getEmailOrMobilePhone(@Nullable String principal) {
|
||||||
@@ -59,6 +75,6 @@ public class PrincipalUtil {
|
|||||||
if (principalType == PrincipalType.MOBILE_PHONE) {
|
if (principalType == PrincipalType.MOBILE_PHONE) {
|
||||||
return MobilePhone.of(principal);
|
return MobilePhone.of(principal);
|
||||||
}
|
}
|
||||||
throw InvalidInputException.unsupportedPrincipalTypeException("输入邮箱地址或手机号");
|
throw new UnsupportedPrincipalTypeException("输入邮箱地址或手机号");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,3 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022-2023 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
package xyz.zhouxy.plusone.system.application.controller;
|
package xyz.zhouxy.plusone.system.application.controller;
|
||||||
|
|
||||||
import static xyz.zhouxy.plusone.system.constant.AuthLogic.adminAuthLogic;
|
import static xyz.zhouxy.plusone.system.constant.AuthLogic.adminAuthLogic;
|
||||||
@@ -7,10 +23,10 @@ import org.springframework.web.bind.annotation.PostMapping;
|
|||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import xyz.zhouxy.plusone.commons.util.RestfulResult;
|
||||||
import xyz.zhouxy.plusone.system.application.service.AccountContextService;
|
import xyz.zhouxy.plusone.system.application.service.AccountContextService;
|
||||||
import xyz.zhouxy.plusone.system.application.service.command.ChangePasswordCommand;
|
import xyz.zhouxy.plusone.system.application.service.command.ChangePasswordCommand;
|
||||||
import xyz.zhouxy.plusone.system.application.service.command.ChangePasswordWithoutLoginCommand;
|
import xyz.zhouxy.plusone.system.application.service.command.ChangePasswordWithoutLoginCommand;
|
||||||
import xyz.zhouxy.plusone.util.RestfulResult;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 账号查询本身相关信息
|
* 账号查询本身相关信息
|
||||||
@@ -34,6 +50,12 @@ public class AccountContextController {
|
|||||||
return RestfulResult.success("查询成功", result);
|
return RestfulResult.success("查询成功", result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("logout")
|
||||||
|
public RestfulResult logout() {
|
||||||
|
service.logout();
|
||||||
|
return RestfulResult.success("注销成功");
|
||||||
|
}
|
||||||
|
|
||||||
@GetMapping("menus")
|
@GetMapping("menus")
|
||||||
public RestfulResult getMenuTree() {
|
public RestfulResult getMenuTree() {
|
||||||
adminAuthLogic.checkLogin();
|
adminAuthLogic.checkLogin();
|
||||||
|
@@ -1,7 +1,23 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022-2023 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
package xyz.zhouxy.plusone.system.application.controller;
|
package xyz.zhouxy.plusone.system.application.controller;
|
||||||
|
|
||||||
import static xyz.zhouxy.plusone.system.constant.AuthLogic.adminAuthLogic;
|
import static xyz.zhouxy.plusone.system.constant.AuthLogic.adminAuthLogic;
|
||||||
import static xyz.zhouxy.plusone.util.RestfulResult.success;
|
import static xyz.zhouxy.plusone.commons.util.RestfulResult.success;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -16,12 +32,11 @@ import org.springframework.web.bind.annotation.RequestBody;
|
|||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import xyz.zhouxy.plusone.commons.util.RestfulResult;
|
||||||
import xyz.zhouxy.plusone.system.application.query.params.AccountQueryParams;
|
import xyz.zhouxy.plusone.system.application.query.params.AccountQueryParams;
|
||||||
import xyz.zhouxy.plusone.system.application.service.AccountManagementService;
|
import xyz.zhouxy.plusone.system.application.service.AccountManagementService;
|
||||||
import xyz.zhouxy.plusone.system.application.service.command.CreateAccountCommand;
|
import xyz.zhouxy.plusone.system.application.service.command.CreateAccountCommand;
|
||||||
import xyz.zhouxy.plusone.system.application.service.command.UpdateAccountCommand;
|
import xyz.zhouxy.plusone.system.application.service.command.UpdateAccountCommand;
|
||||||
import xyz.zhouxy.plusone.util.AssertResult;
|
|
||||||
import xyz.zhouxy.plusone.util.RestfulResult;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 账号管理
|
* 账号管理
|
||||||
@@ -77,7 +92,6 @@ public class AccountManagementController {
|
|||||||
adminAuthLogic.checkLogin();
|
adminAuthLogic.checkLogin();
|
||||||
adminAuthLogic.checkPermission("sys-account-details");
|
adminAuthLogic.checkPermission("sys-account-details");
|
||||||
var accountDetails = service.queryAccountDetails(accountId);
|
var accountDetails = service.queryAccountDetails(accountId);
|
||||||
AssertResult.nonNull(accountDetails);
|
|
||||||
return success("查询成功", accountDetails);
|
return success("查询成功", accountDetails);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,6 +1,22 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022-2023 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
package xyz.zhouxy.plusone.system.application.controller;
|
package xyz.zhouxy.plusone.system.application.controller;
|
||||||
|
|
||||||
import static xyz.zhouxy.plusone.util.RestfulResult.success;
|
import static xyz.zhouxy.plusone.commons.util.RestfulResult.success;
|
||||||
|
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
@@ -12,7 +28,7 @@ import org.springframework.web.bind.annotation.RestController;
|
|||||||
import xyz.zhouxy.plusone.system.application.service.AdminLoginService;
|
import xyz.zhouxy.plusone.system.application.service.AdminLoginService;
|
||||||
import xyz.zhouxy.plusone.system.application.service.command.LoginByOtpCommand;
|
import xyz.zhouxy.plusone.system.application.service.command.LoginByOtpCommand;
|
||||||
import xyz.zhouxy.plusone.system.application.service.command.LoginByPasswordCommand;
|
import xyz.zhouxy.plusone.system.application.service.command.LoginByPasswordCommand;
|
||||||
import xyz.zhouxy.plusone.util.RestfulResult;
|
import xyz.zhouxy.plusone.commons.util.RestfulResult;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Admin 账号登录
|
* Admin 账号登录
|
||||||
|
@@ -1,30 +0,0 @@
|
|||||||
package xyz.zhouxy.plusone.system.application.controller;
|
|
||||||
|
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
import xyz.zhouxy.plusone.system.application.service.AdminLogoutService;
|
|
||||||
import xyz.zhouxy.plusone.util.RestfulResult;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Admin 账号登出
|
|
||||||
*
|
|
||||||
* @author <a href="https://gitee.com/zhouxy108">ZhouXY</a>
|
|
||||||
*/
|
|
||||||
@RestController
|
|
||||||
@RequestMapping("logout")
|
|
||||||
public class AdminLogoutController {
|
|
||||||
|
|
||||||
private final AdminLogoutService service;
|
|
||||||
|
|
||||||
public AdminLogoutController(AdminLogoutService service) {
|
|
||||||
this.service = service;
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping
|
|
||||||
public RestfulResult execute() {
|
|
||||||
service.execute();
|
|
||||||
return RestfulResult.success("注销成功");
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,7 +1,23 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022-2023 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
package xyz.zhouxy.plusone.system.application.controller;
|
package xyz.zhouxy.plusone.system.application.controller;
|
||||||
|
|
||||||
import static xyz.zhouxy.plusone.system.constant.AuthLogic.adminAuthLogic;
|
import static xyz.zhouxy.plusone.system.constant.AuthLogic.adminAuthLogic;
|
||||||
import static xyz.zhouxy.plusone.util.RestfulResult.success;
|
import static xyz.zhouxy.plusone.commons.util.RestfulResult.success;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -20,7 +36,7 @@ import xyz.zhouxy.plusone.system.application.query.params.DictQueryParams;
|
|||||||
import xyz.zhouxy.plusone.system.application.service.DictManagementService;
|
import xyz.zhouxy.plusone.system.application.service.DictManagementService;
|
||||||
import xyz.zhouxy.plusone.system.application.service.command.CreateDictCommand;
|
import xyz.zhouxy.plusone.system.application.service.command.CreateDictCommand;
|
||||||
import xyz.zhouxy.plusone.system.application.service.command.UpdateDictCommand;
|
import xyz.zhouxy.plusone.system.application.service.command.UpdateDictCommand;
|
||||||
import xyz.zhouxy.plusone.util.RestfulResult;
|
import xyz.zhouxy.plusone.commons.util.RestfulResult;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 数据字典管理
|
* 数据字典管理
|
||||||
|
@@ -1,7 +1,23 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022-2023 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
package xyz.zhouxy.plusone.system.application.controller;
|
package xyz.zhouxy.plusone.system.application.controller;
|
||||||
|
|
||||||
import static xyz.zhouxy.plusone.system.constant.AuthLogic.adminAuthLogic;
|
import static xyz.zhouxy.plusone.system.constant.AuthLogic.adminAuthLogic;
|
||||||
import static xyz.zhouxy.plusone.util.RestfulResult.success;
|
import static xyz.zhouxy.plusone.commons.util.RestfulResult.success;
|
||||||
|
|
||||||
import javax.validation.Valid;
|
import javax.validation.Valid;
|
||||||
|
|
||||||
@@ -18,7 +34,7 @@ import org.springframework.web.bind.annotation.RestController;
|
|||||||
import xyz.zhouxy.plusone.system.application.service.MenuManagementService;
|
import xyz.zhouxy.plusone.system.application.service.MenuManagementService;
|
||||||
import xyz.zhouxy.plusone.system.application.service.command.CreateMenuCommand;
|
import xyz.zhouxy.plusone.system.application.service.command.CreateMenuCommand;
|
||||||
import xyz.zhouxy.plusone.system.application.service.command.UpdateMenuCommand;
|
import xyz.zhouxy.plusone.system.application.service.command.UpdateMenuCommand;
|
||||||
import xyz.zhouxy.plusone.util.RestfulResult;
|
import xyz.zhouxy.plusone.commons.util.RestfulResult;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 菜单管理
|
* 菜单管理
|
||||||
|
@@ -1,6 +1,22 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022-2023 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
package xyz.zhouxy.plusone.system.application.controller;
|
package xyz.zhouxy.plusone.system.application.controller;
|
||||||
|
|
||||||
import static xyz.zhouxy.plusone.util.RestfulResult.success;
|
import static xyz.zhouxy.plusone.commons.util.RestfulResult.success;
|
||||||
|
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
@@ -11,7 +27,7 @@ import org.springframework.web.bind.annotation.RestController;
|
|||||||
|
|
||||||
import xyz.zhouxy.plusone.system.application.service.RegisterAccountService;
|
import xyz.zhouxy.plusone.system.application.service.RegisterAccountService;
|
||||||
import xyz.zhouxy.plusone.system.application.service.command.RegisterAccountCommand;
|
import xyz.zhouxy.plusone.system.application.service.command.RegisterAccountCommand;
|
||||||
import xyz.zhouxy.plusone.util.RestfulResult;
|
import xyz.zhouxy.plusone.commons.util.RestfulResult;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 注册账号服务
|
* 注册账号服务
|
||||||
|
@@ -1,3 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022-2023 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
package xyz.zhouxy.plusone.system.application.controller;
|
package xyz.zhouxy.plusone.system.application.controller;
|
||||||
|
|
||||||
import javax.validation.Valid;
|
import javax.validation.Valid;
|
||||||
@@ -17,7 +33,7 @@ import xyz.zhouxy.plusone.system.application.query.params.RoleQueryParams;
|
|||||||
import xyz.zhouxy.plusone.system.application.service.RoleManagementService;
|
import xyz.zhouxy.plusone.system.application.service.RoleManagementService;
|
||||||
import xyz.zhouxy.plusone.system.application.service.command.CreateRoleCommand;
|
import xyz.zhouxy.plusone.system.application.service.command.CreateRoleCommand;
|
||||||
import xyz.zhouxy.plusone.system.application.service.command.UpdateRoleCommand;
|
import xyz.zhouxy.plusone.system.application.service.command.UpdateRoleCommand;
|
||||||
import xyz.zhouxy.plusone.util.RestfulResult;
|
import xyz.zhouxy.plusone.commons.util.RestfulResult;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 角色管理服务
|
* 角色管理服务
|
||||||
|
@@ -1,12 +1,28 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022-2023 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
package xyz.zhouxy.plusone.system.application.exception;
|
package xyz.zhouxy.plusone.system.application.exception;
|
||||||
|
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||||
|
|
||||||
import xyz.zhouxy.plusone.exception.PlusoneException;
|
import xyz.zhouxy.plusone.exception.BizException;
|
||||||
|
|
||||||
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
||||||
public class AccountLoginException extends PlusoneException {
|
public class AccountLoginException extends BizException {
|
||||||
@java.io.Serial
|
@java.io.Serial
|
||||||
private static final long serialVersionUID = -3040996790739138556L;
|
private static final long serialVersionUID = -3040996790739138556L;
|
||||||
|
|
||||||
@@ -21,18 +37,34 @@ public class AccountLoginException extends PlusoneException {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static AccountLoginException accountNotExistException() {
|
public static AccountLoginException accountNotExistException() {
|
||||||
return new AccountLoginException(4030101, "用户账户不存在");
|
return accountNotExistException("用户账户不存在");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static AccountLoginException accountNotExistException(String msg) {
|
||||||
|
return new AccountLoginException(4030101, msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static AccountLoginException otpErrorException() {
|
public static AccountLoginException otpErrorException() {
|
||||||
return new AccountLoginException(4030501, "验证码错误");
|
return otpErrorException("验证码错误");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static AccountLoginException otpErrorException(String msg) {
|
||||||
|
return new AccountLoginException(4030501, msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static AccountLoginException otpNotExistsException() {
|
public static AccountLoginException otpNotExistsException() {
|
||||||
return new AccountLoginException(4030502, "验证码不存在或已过期");
|
return otpNotExistsException("验证码不存在或已过期");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static AccountLoginException otpNotExistsException(String msg) {
|
||||||
|
return new AccountLoginException(4030502, msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static AccountLoginException passwordErrorException() {
|
public static AccountLoginException passwordErrorException() {
|
||||||
return new AccountLoginException(4030200, "用户密码错误");
|
return passwordErrorException("用户密码错误");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static AccountLoginException passwordErrorException(String msg) {
|
||||||
|
return new AccountLoginException(4030200, msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user