Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
schbrain-parent
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Incidents
Environments
Packages & Registries
Packages & Registries
Package Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
framework
schbrain-parent
Commits
e495c854
Commit
e495c854
authored
Jun 24, 2023
by
liaozan
🏀
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish
parent
0b7013c0
Changes
29
Hide whitespace changes
Inline
Side-by-side
Showing
29 changed files
with
230 additions
and
302 deletions
+230
-302
commons/common-util/src/main/java/com/schbrain/common/util/support/excel/listener/ExcelReadListenerBase.java
...on/util/support/excel/listener/ExcelReadListenerBase.java
+5
-5
commons/common-util/src/main/java/com/schbrain/common/util/support/excel/listener/HierarchicalDataReadListener.java
.../support/excel/listener/HierarchicalDataReadListener.java
+4
-4
commons/common/src/main/java/com/schbrain/common/util/ValidateUtils.java
...src/main/java/com/schbrain/common/util/ValidateUtils.java
+48
-0
commons/web-common/src/main/java/com/schbrain/common/web/ExceptionHandingConfiguration.java
...om/schbrain/common/web/ExceptionHandingConfiguration.java
+9
-8
commons/web-common/src/main/java/com/schbrain/common/web/ServletComponentConfiguration.java
...om/schbrain/common/web/ServletComponentConfiguration.java
+4
-2
commons/web-common/src/main/java/com/schbrain/common/web/WebCommonAutoConfiguration.java
...a/com/schbrain/common/web/WebCommonAutoConfiguration.java
+4
-4
commons/web-common/src/main/java/com/schbrain/common/web/exception/DefaultGlobalExceptionResolver.java
.../common/web/exception/DefaultGlobalExceptionResolver.java
+4
-5
commons/web-common/src/main/java/com/schbrain/common/web/exception/ExceptionHandingWebMvcConfigurer.java
...ommon/web/exception/ExceptionHandingWebMvcConfigurer.java
+1
-1
commons/web-common/src/main/java/com/schbrain/common/web/log/RequestLoggingFilter.java
...ava/com/schbrain/common/web/log/RequestLoggingFilter.java
+1
-11
commons/web-common/src/main/java/com/schbrain/common/web/result/ResponseBodyHandler.java
...a/com/schbrain/common/web/result/ResponseBodyHandler.java
+4
-16
commons/web-common/src/main/java/com/schbrain/common/web/servlet/TraceIdInitializeServletListener.java
.../common/web/servlet/TraceIdInitializeServletListener.java
+6
-6
commons/web-common/src/main/java/com/schbrain/common/web/support/BaseHandlerInterceptor.java
...m/schbrain/common/web/support/BaseHandlerInterceptor.java
+4
-4
commons/web-common/src/main/java/com/schbrain/common/web/support/authentication/AbstractAuthenticator.java
...mon/web/support/authentication/AbstractAuthenticator.java
+4
-4
commons/web-common/src/main/java/com/schbrain/common/web/support/authentication/AuthenticationInterceptor.java
...web/support/authentication/AuthenticationInterceptor.java
+4
-4
commons/web-common/src/main/java/com/schbrain/common/web/support/authentication/Authenticator.java
...rain/common/web/support/authentication/Authenticator.java
+1
-1
pom.xml
pom.xml
+2
-2
starters/apollo-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/apollo/ConfigurablePropertiesLoader.java
...rk/autoconfigure/apollo/ConfigurablePropertiesLoader.java
+1
-1
starters/cache-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/cache/CacheAutoConfiguration.java
...framework/autoconfigure/cache/CacheAutoConfiguration.java
+4
-5
starters/cache-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/cache/CacheUtils.java
...om/schbrain/framework/autoconfigure/cache/CacheUtils.java
+14
-14
starters/cache-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/cache/provider/CacheProvider.java
...framework/autoconfigure/cache/provider/CacheProvider.java
+16
-19
starters/cache-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/cache/provider/CacheProviderDelegate.java
...k/autoconfigure/cache/provider/CacheProviderDelegate.java
+33
-48
starters/cache-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/cache/provider/redis/RedisCacheProvider.java
...utoconfigure/cache/provider/redis/RedisCacheProvider.java
+39
-41
starters/logger-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/logger/listener/LoggerConfigLoadedEventListener.java
...gure/logger/listener/LoggerConfigLoadedEventListener.java
+5
-2
starters/mybatis-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/mybatis/datasource/extractor/DataSourcePropertiesExtractorSupport.java
...ource/extractor/DataSourcePropertiesExtractorSupport.java
+2
-2
starters/mybatis-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/mybatis/datasource/extractor/DruidDataSourcePropertiesExtractor.java
...asource/extractor/DruidDataSourcePropertiesExtractor.java
+1
-1
starters/mybatis-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/mybatis/datasource/extractor/HikariDataSourcePropertiesExtractor.java
...source/extractor/HikariDataSourcePropertiesExtractor.java
+1
-1
starters/xxl-job-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/xxl/SchbrainXxlJobExecutor.java
...n/framework/autoconfigure/xxl/SchbrainXxlJobExecutor.java
+0
-83
starters/xxl-job-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/xxl/XxlJobAutoConfiguration.java
.../framework/autoconfigure/xxl/XxlJobAutoConfiguration.java
+4
-3
support/schbrain-base-dao/src/main/java/com/schbrain/framework/dao/BaseDao.java
...dao/src/main/java/com/schbrain/framework/dao/BaseDao.java
+5
-5
No files found.
commons/common-util/src/main/java/com/schbrain/common/util/support/excel/listener/ExcelReadListenerBase.java
View file @
e495c854
...
...
@@ -37,6 +37,11 @@ public class ExcelReadListenerBase<T> extends AnalysisEventListener<T> {
this
.
headers
=
headMap
;
}
@Override
public
void
onException
(
Exception
exception
,
AnalysisContext
context
)
{
throw
new
ExcelException
(
exception
.
getMessage
(),
exception
);
}
@Override
public
void
invoke
(
T
data
,
AnalysisContext
context
)
{
boolean
validated
=
validate
(
data
,
context
);
...
...
@@ -48,11 +53,6 @@ public class ExcelReadListenerBase<T> extends AnalysisEventListener<T> {
this
.
dataList
.
add
(
data
);
}
@Override
public
void
onException
(
Exception
exception
,
AnalysisContext
context
)
{
throw
new
ExcelException
(
exception
.
getMessage
(),
exception
);
}
@Override
public
void
doAfterAllAnalysed
(
AnalysisContext
context
)
{
}
...
...
commons/common-util/src/main/java/com/schbrain/common/util/support/excel/listener/HierarchicalDataReadListener.java
View file @
e495c854
...
...
@@ -36,10 +36,6 @@ public class HierarchicalDataReadListener extends ExcelReadListenerBase<Map<Inte
});
}
public
List
<
ImportedRecord
>
getImportedRecords
()
{
return
importedRecords
;
}
@Override
protected
boolean
validate
(
Map
<
Integer
,
String
>
data
,
AnalysisContext
context
)
{
Integer
rowIndex
=
context
.
readRowHolder
().
getRowIndex
();
...
...
@@ -54,6 +50,10 @@ public class HierarchicalDataReadListener extends ExcelReadListenerBase<Map<Inte
return
true
;
}
public
List
<
ImportedRecord
>
getImportedRecords
()
{
return
importedRecords
;
}
protected
void
buildImportedRow
(
Integer
rowIndex
,
Integer
columnIndex
,
String
text
)
{
ImportedRecord
importedRecord
=
new
ImportedRecord
();
importedRecord
.
setText
(
text
);
...
...
commons/common/src/main/java/com/schbrain/common/util/ValidateUtils.java
View file @
e495c854
...
...
@@ -15,6 +15,10 @@ public class ValidateUtils {
private
ValidateUtils
()
{
}
public
static
void
isTrue
(
boolean
expression
)
{
isTrue
(
expression
,
"操作有误"
);
}
public
static
void
isTrue
(
boolean
expression
,
String
message
)
{
isTrue
(
expression
,
()
->
new
ParamInvalidException
(
message
));
}
...
...
@@ -25,6 +29,10 @@ public class ValidateUtils {
}
}
public
static
void
isFalse
(
boolean
expression
)
{
isFalse
(
expression
,
"操作有误"
);
}
public
static
void
isFalse
(
boolean
expression
,
String
message
)
{
isFalse
(
expression
,
()
->
new
ParamInvalidException
(
message
));
}
...
...
@@ -35,6 +43,10 @@ public class ValidateUtils {
}
}
public
static
void
notNull
(
Object
object
)
{
notNull
(
object
,
"The validated object is null"
);
}
public
static
void
notNull
(
Object
object
,
String
message
)
{
notNull
(
object
,
()
->
new
ParamInvalidException
(
message
));
}
...
...
@@ -45,6 +57,10 @@ public class ValidateUtils {
}
}
public
static
void
isNull
(
Object
object
)
{
isNull
(
object
,
"The validated object is not null"
);
}
public
static
void
isNull
(
Object
object
,
String
message
)
{
isNull
(
object
,
()
->
new
ParamInvalidException
(
message
));
}
...
...
@@ -55,6 +71,10 @@ public class ValidateUtils {
}
}
public
static
void
notEmpty
(
String
value
)
{
notEmpty
(
value
,
"The validated string is empty"
);
}
public
static
void
notEmpty
(
String
value
,
String
message
)
{
notEmpty
(
value
,
()
->
new
ParamInvalidException
(
message
));
}
...
...
@@ -65,6 +85,10 @@ public class ValidateUtils {
}
}
public
static
void
isEmpty
(
String
value
)
{
isEmpty
(
value
,
"The validated string is not empty"
);
}
public
static
void
isEmpty
(
String
value
,
String
message
)
{
isEmpty
(
value
,
()
->
new
ParamInvalidException
(
message
));
}
...
...
@@ -75,6 +99,10 @@ public class ValidateUtils {
}
}
public
static
void
notEmpty
(
Object
[]
array
)
{
notEmpty
(
array
,
"The validated array is empty"
);
}
public
static
void
notEmpty
(
Object
[]
array
,
String
message
)
{
notEmpty
(
array
,
()
->
new
ParamInvalidException
(
message
));
}
...
...
@@ -85,6 +113,10 @@ public class ValidateUtils {
}
}
public
static
void
isEmpty
(
Object
[]
array
)
{
isEmpty
(
array
,
"The validated array is not empty"
);
}
public
static
void
isEmpty
(
Object
[]
array
,
String
message
)
{
isEmpty
(
array
,
()
->
new
ParamInvalidException
(
message
));
}
...
...
@@ -95,6 +127,10 @@ public class ValidateUtils {
}
}
public
static
void
notEmpty
(
Collection
<?>
collection
)
{
notEmpty
(
collection
,
"The validated collection is empty"
);
}
public
static
void
notEmpty
(
Collection
<?>
collection
,
String
message
)
{
notEmpty
(
collection
,
()
->
new
ParamInvalidException
(
message
));
}
...
...
@@ -105,6 +141,10 @@ public class ValidateUtils {
}
}
public
static
void
isEmpty
(
Collection
<?>
collection
)
{
isEmpty
(
collection
,
"The validated collection is not empty"
);
}
public
static
void
isEmpty
(
Collection
<?>
collection
,
String
message
)
{
isEmpty
(
collection
,
()
->
new
ParamInvalidException
(
message
));
}
...
...
@@ -115,6 +155,10 @@ public class ValidateUtils {
}
}
public
static
void
notEmpty
(
Map
<?,
?>
map
)
{
notEmpty
(
map
,
"The validated map is empty"
);
}
public
static
void
notEmpty
(
Map
<?,
?>
map
,
String
message
)
{
notEmpty
(
map
,
()
->
new
ParamInvalidException
(
message
));
}
...
...
@@ -125,6 +169,10 @@ public class ValidateUtils {
}
}
public
static
void
isEmpty
(
Map
<?,
?>
map
)
{
isEmpty
(
map
,
"The validated map is not empty"
);
}
public
static
void
isEmpty
(
Map
<?,
?>
map
,
String
message
)
{
isEmpty
(
map
,
()
->
new
ParamInvalidException
(
message
));
}
...
...
commons/web-common/src/main/java/com/schbrain/common/web/ExceptionHandingConfiguration.java
View file @
e495c854
...
...
@@ -3,8 +3,8 @@ package com.schbrain.common.web;
import
com.schbrain.common.web.exception.*
;
import
com.schbrain.common.web.properties.WebProperties
;
import
org.springframework.beans.factory.ObjectProvider
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnBean
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
...
...
@@ -15,24 +15,25 @@ import java.util.stream.Collectors;
* @since 2023-05-08
*/
@Configuration
(
proxyBeanMethods
=
false
)
@ConditionalOnProperty
(
value
=
"schbrain.web.enable-global-exception-handler"
,
havingValue
=
"true"
,
matchIfMissing
=
true
)
public
class
ExceptionHandingConfiguration
{
@Bean
public
GlobalExceptionHandler
defaultGlobalExceptionHandler
(
ObjectProvider
<
ExceptionTranslator
>
exceptionTranslators
)
{
return
new
GlobalExceptionHandler
(
exceptionTranslators
.
orderedStream
().
collect
(
Collectors
.
toList
()));
@ConditionalOnMissingBean
public
ExceptionTranslator
defaultExceptionTranslator
()
{
return
new
DefaultExceptionTranslator
();
}
@Bean
@ConditionalOnMissingBean
public
ExceptionHandingWebMvcConfigurer
defaultExceptionHandingWebMvcConfigurer
(
WebProperties
webProperties
,
GlobalExceptionHandler
exceptionHandler
)
{
return
new
ExceptionHandingWebMvcConfigurer
(
webProperties
,
exceptionHandler
);
public
GlobalExceptionHandler
defaultGlobalExceptionHandler
(
ObjectProvider
<
ExceptionTranslator
>
exceptionTranslators
)
{
return
new
GlobalExceptionHandler
(
exceptionTranslators
.
orderedStream
().
collect
(
Collectors
.
toList
())
);
}
@Bean
@ConditionalOnMissingBean
@ConditionalOnBean
(
GlobalExceptionHandler
.
class
)
public
ExceptionTranslator
defaultExceptionTranslator
()
{
return
new
DefaultExceptionTranslator
();
public
ExceptionHandingWebMvcConfigurer
defaultExceptionHandingWebMvcConfigurer
(
WebProperties
webProperties
,
GlobalExceptionHandler
exceptionHandler
)
{
return
new
ExceptionHandingWebMvcConfigurer
(
webProperties
,
exceptionHandler
);
}
}
\ No newline at end of file
commons/web-common/src/main/java/com/schbrain/common/web/ServletComponentConfiguration.java
View file @
e495c854
...
...
@@ -4,6 +4,7 @@ import com.schbrain.common.web.log.RequestLoggingFilter;
import
com.schbrain.common.web.properties.WebProperties
;
import
com.schbrain.common.web.servlet.CharacterEncodingServletContextInitializer
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
;
import
org.springframework.boot.web.servlet.filter.OrderedRequestContextFilter
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
...
...
@@ -32,8 +33,9 @@ public class ServletComponentConfiguration {
@Bean
@ConditionalOnMissingBean
public
RequestLoggingFilter
requestLoggingFilter
(
WebProperties
properties
)
{
return
new
RequestLoggingFilter
(
properties
);
@ConditionalOnProperty
(
value
=
"schbrain.web.enable-request-logging"
,
havingValue
=
"true"
,
matchIfMissing
=
true
)
public
RequestLoggingFilter
requestLoggingFilter
()
{
return
new
RequestLoggingFilter
();
}
}
\ No newline at end of file
commons/web-common/src/main/java/com/schbrain/common/web/WebCommonAutoConfiguration.java
View file @
e495c854
...
...
@@ -9,8 +9,7 @@ import org.springframework.beans.factory.BeanFactory;
import
org.springframework.beans.factory.ObjectProvider
;
import
org.springframework.boot.autoconfigure.AutoConfiguration
;
import
org.springframework.boot.autoconfigure.AutoConfigurationPackages
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication
;
import
org.springframework.boot.autoconfigure.condition.*
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type
;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.boot.web.client.RestTemplateBuilder
;
...
...
@@ -48,9 +47,10 @@ public class WebCommonAutoConfiguration {
@Bean
@ConditionalOnMissingBean
public
ResponseBodyHandler
defaultResponseBodyHandler
(
WebProperties
properties
,
BeanFactory
beanFactory
)
{
@ConditionalOnProperty
(
value
=
"schbrain.web.wrap-response"
,
havingValue
=
"true"
,
matchIfMissing
=
true
)
public
ResponseBodyHandler
defaultResponseBodyHandler
(
BeanFactory
beanFactory
)
{
List
<
String
>
basePackages
=
AutoConfigurationPackages
.
get
(
beanFactory
);
return
new
ResponseBodyHandler
(
properties
,
basePackages
);
return
new
ResponseBodyHandler
(
basePackages
);
}
@Bean
...
...
commons/web-common/src/main/java/com/schbrain/common/web/exception/DefaultGlobalExceptionResolver.java
View file @
e495c854
package
com.schbrain.common.web.exception
;
import
com.schbrain.common.web.annotation.ResponseWrapOption
;
import
com.schbrain.common.web.properties.WebProperties
;
import
com.schbrain.common.web.utils.HandlerMethodAnnotationUtils
;
import
lombok.EqualsAndHashCode
;
import
lombok.extern.slf4j.Slf4j
;
...
...
@@ -29,7 +28,7 @@ import java.util.concurrent.ConcurrentHashMap;
@EqualsAndHashCode
(
callSuper
=
true
)
public
class
DefaultGlobalExceptionResolver
extends
AbstractHandlerMethodExceptionResolver
{
private
final
WebProperties
webProperties
;
private
final
boolean
wrapResponse
;
private
final
GlobalExceptionHandler
exceptionHandler
;
...
...
@@ -41,8 +40,8 @@ public class DefaultGlobalExceptionResolver extends AbstractHandlerMethodExcepti
private
final
Map
<
Class
<?>,
ExceptionHandlerMethodResolver
>
exceptionHandlerMethodResolvers
=
new
ConcurrentHashMap
<>(
64
);
public
DefaultGlobalExceptionResolver
(
ExceptionHandlerExceptionResolver
handlerMethodResolver
,
WebProperties
webProperties
,
GlobalExceptionHandler
exceptionHandler
)
{
this
.
w
ebProperties
=
webProperties
;
public
DefaultGlobalExceptionResolver
(
ExceptionHandlerExceptionResolver
handlerMethodResolver
,
boolean
wrapResponse
,
GlobalExceptionHandler
exceptionHandler
)
{
this
.
w
rapResponse
=
wrapResponse
;
this
.
exceptionHandler
=
exceptionHandler
;
this
.
handlerMethodResolver
=
new
ExceptionHandlerMethodResolver
(
exceptionHandler
.
getClass
());
this
.
argumentResolverComposite
=
handlerMethodResolver
.
getArgumentResolvers
();
...
...
@@ -52,7 +51,7 @@ public class DefaultGlobalExceptionResolver extends AbstractHandlerMethodExcepti
@Override
protected
boolean
shouldApplyTo
(
HttpServletRequest
request
,
@Nullable
Object
handler
)
{
if
(!
w
ebProperties
.
isWrapResponse
()
)
{
if
(!
w
rapResponse
)
{
return
false
;
}
...
...
commons/web-common/src/main/java/com/schbrain/common/web/exception/ExceptionHandingWebMvcConfigurer.java
View file @
e495c854
...
...
@@ -49,7 +49,7 @@ public class ExceptionHandingWebMvcConfigurer implements WebMvcConfigurer {
}
protected
HandlerExceptionResolver
createExceptionResolver
(
ExceptionHandlerExceptionResolver
adviceExceptionResolver
)
{
return
new
DefaultGlobalExceptionResolver
(
adviceExceptionResolver
,
webProperties
,
globalExceptionHandler
);
return
new
DefaultGlobalExceptionResolver
(
adviceExceptionResolver
,
webProperties
.
isWrapResponse
()
,
globalExceptionHandler
);
}
}
\ No newline at end of file
commons/web-common/src/main/java/com/schbrain/common/web/log/RequestLoggingFilter.java
View file @
e495c854
...
...
@@ -2,7 +2,6 @@ package com.schbrain.common.web.log;
import
cn.hutool.core.text.CharPool
;
import
cn.hutool.core.util.ArrayUtil
;
import
com.schbrain.common.web.properties.WebProperties
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.boot.web.servlet.filter.OrderedFilter
;
import
org.springframework.core.Ordered
;
...
...
@@ -27,15 +26,9 @@ import static com.schbrain.common.web.utils.ContentCachingServletUtils.wrapReque
@Slf4j
public
class
RequestLoggingFilter
extends
OncePerRequestFilter
implements
OrderedFilter
{
private
final
WebProperties
webProperties
;
public
RequestLoggingFilter
(
WebProperties
webProperties
)
{
this
.
webProperties
=
webProperties
;
}
@Override
public
int
getOrder
()
{
return
Ordered
.
HIGHEST_PRECEDENCE
;
return
Ordered
.
HIGHEST_PRECEDENCE
+
10
;
}
@Override
...
...
@@ -57,9 +50,6 @@ public class RequestLoggingFilter extends OncePerRequestFilter implements Ordere
}
protected
boolean
shouldSkip
(
HttpServletRequest
request
)
{
if
(!
webProperties
.
isEnableRequestLogging
())
{
return
true
;
}
return
CorsUtils
.
isPreFlightRequest
(
request
);
}
...
...
commons/web-common/src/main/java/com/schbrain/common/web/result/ResponseBodyHandler.java
View file @
e495c854
package
com.schbrain.common.web.result
;
import
com.schbrain.common.web.annotation.ResponseWrapOption
;
import
com.schbrain.common.web.properties.WebProperties
;
import
org.springframework.core.MethodParameter
;
import
org.springframework.http.MediaType
;
import
org.springframework.http.converter.HttpMessageConverter
;
...
...
@@ -22,34 +21,23 @@ import java.util.concurrent.ConcurrentHashMap;
@RestControllerAdvice
public
class
ResponseBodyHandler
implements
ResponseBodyAdvice
<
Object
>
{
private
final
WebProperties
webProperties
;
private
final
List
<
String
>
basePackages
;
private
final
Map
<
Method
,
Boolean
>
methodCache
;
private
final
Map
<
Method
,
Boolean
>
methodCache
=
new
ConcurrentHashMap
<>()
;
public
ResponseBodyHandler
(
WebProperties
webProperties
,
List
<
String
>
basePackages
)
{
this
.
webProperties
=
webProperties
;
public
ResponseBodyHandler
(
List
<
String
>
basePackages
)
{
this
.
basePackages
=
basePackages
;
this
.
methodCache
=
new
ConcurrentHashMap
<>();
}
@Override
public
boolean
supports
(
MethodParameter
returnType
,
Class
<?
extends
HttpMessageConverter
<?>>
converterType
)
{
if
(!
webProperties
.
isWrapResponse
())
{
return
false
;
}
return
methodCache
.
computeIfAbsent
(
returnType
.
getMethod
(),
this
::
shouldApply
);
}
@Override
public
Object
beforeBodyWrite
(
Object
body
,
MethodParameter
returnType
,
MediaType
selectedContentType
,
Class
<?
extends
HttpMessageConverter
<?>>
selectedConverterType
,
public
Object
beforeBodyWrite
(
Object
body
,
MethodParameter
returnType
,
MediaType
selectedContentType
,
Class
<?
extends
HttpMessageConverter
<?>>
selectedConverterType
,
ServerHttpRequest
request
,
ServerHttpResponse
response
)
{
return
beforeBodyWrite
(
body
);
}
protected
Object
beforeBodyWrite
(
Object
body
)
{
if
(
body
instanceof
ResponseDTO
)
{
return
body
;
}
...
...
commons/web-common/src/main/java/com/schbrain/common/web/servlet/TraceIdInitializeServletListener.java
View file @
e495c854
...
...
@@ -11,16 +11,16 @@ import javax.servlet.ServletRequestListener;
*/
public
class
TraceIdInitializeServletListener
implements
ServletRequestListener
{
@Override
public
void
requestInitialized
(
ServletRequestEvent
event
)
{
// Make sure the traceId is initialized
TraceIdUtils
.
get
();
}
@Override
public
void
requestDestroyed
(
ServletRequestEvent
event
)
{
// Make sure the traceId can be cleared
TraceIdUtils
.
clear
();
}
@Override
public
void
requestInitialized
(
ServletRequestEvent
event
)
{
// Make sure the traceId is initialized
TraceIdUtils
.
get
();
}
}
\ No newline at end of file
commons/web-common/src/main/java/com/schbrain/common/web/support/BaseHandlerInterceptor.java
View file @
e495c854
...
...
@@ -46,19 +46,19 @@ public class BaseHandlerInterceptor implements AsyncHandlerInterceptor {
}
}
protected
boolean
preHandle
(
HttpServletRequest
request
,
HttpServletResponse
response
,
HandlerMethod
handler
)
throws
Exception
{
protected
boolean
preHandle
(
HttpServletRequest
request
,
HttpServletResponse
response
,
HandlerMethod
handler
Method
)
throws
Exception
{
return
true
;
}
protected
void
postHandle
(
HttpServletRequest
request
,
HttpServletResponse
response
,
HandlerMethod
handler
,
ModelAndView
modelAndView
)
throws
Exception
{
protected
void
postHandle
(
HttpServletRequest
request
,
HttpServletResponse
response
,
HandlerMethod
handler
Method
,
ModelAndView
modelAndView
)
throws
Exception
{
}
protected
void
afterCompletion
(
HttpServletRequest
request
,
HttpServletResponse
response
,
HandlerMethod
handler
,
Exception
ex
)
throws
Exception
{
protected
void
afterCompletion
(
HttpServletRequest
request
,
HttpServletResponse
response
,
HandlerMethod
handler
Method
,
Exception
ex
)
throws
Exception
{
}
protected
void
afterConcurrentHandlingStarted
(
HttpServletRequest
request
,
HttpServletResponse
response
,
HandlerMethod
handlerMethod
)
{
protected
void
afterConcurrentHandlingStarted
(
HttpServletRequest
request
,
HttpServletResponse
response
,
HandlerMethod
handlerMethod
)
throws
Exception
{
}
...
...
commons/web-common/src/main/java/com/schbrain/common/web/support/authentication/AbstractAuthenticator.java
View file @
e495c854
...
...
@@ -34,8 +34,8 @@ public abstract class AbstractAuthenticator implements Authenticator {
}
@Override
public
boolean
validate
(
HttpServletRequest
request
,
HttpServletResponse
response
,
HandlerMethod
handler
)
{
boolean
ignore
=
HandlerMethodAnnotationUtils
.
hasAnnotation
(
handler
,
IgnoreLogin
.
class
);
public
boolean
validate
(
HttpServletRequest
request
,
HttpServletResponse
response
,
HandlerMethod
handler
Method
)
{
boolean
ignore
=
HandlerMethodAnnotationUtils
.
hasAnnotation
(
handler
Method
,
IgnoreLogin
.
class
);
if
(
ignore
)
{
return
true
;
}
...
...
@@ -43,10 +43,10 @@ public abstract class AbstractAuthenticator implements Authenticator {
if
(
StringUtils
.
isBlank
(
authentication
))
{
return
false
;
}
return
doValidate
(
authentication
,
request
,
response
,
handler
);
return
doValidate
(
authentication
,
request
,
response
,
handler
Method
);
}
protected
abstract
boolean
doValidate
(
String
authentication
,
HttpServletRequest
request
,
HttpServletResponse
response
,
HandlerMethod
handler
);
protected
abstract
boolean
doValidate
(
String
authentication
,
HttpServletRequest
request
,
HttpServletResponse
response
,
HandlerMethod
handler
Method
);
@Nullable
protected
String
getAuthentication
(
HttpServletRequest
request
)
{
...
...
commons/web-common/src/main/java/com/schbrain/common/web/support/authentication/AuthenticationInterceptor.java
View file @
e495c854
...
...
@@ -38,8 +38,8 @@ public class AuthenticationInterceptor extends BaseHandlerInterceptor implements
}
@Override
protected
boolean
preHandle
(
HttpServletRequest
request
,
HttpServletResponse
response
,
HandlerMethod
handler
)
{
boolean
validated
=
authenticator
.
validate
(
request
,
response
,
handler
);
protected
boolean
preHandle
(
HttpServletRequest
request
,
HttpServletResponse
response
,
HandlerMethod
handler
Method
)
{
boolean
validated
=
authenticator
.
validate
(
request
,
response
,
handler
Method
);
if
(
validated
)
{
return
true
;
}
...
...
@@ -48,8 +48,8 @@ public class AuthenticationInterceptor extends BaseHandlerInterceptor implements
}
@Override
protected
void
afterCompletion
(
HttpServletRequest
request
,
HttpServletResponse
response
,
HandlerMethod
handler
,
Exception
ex
)
{
authenticator
.
afterCompletion
(
request
,
response
,
handler
,
ex
);
protected
void
afterCompletion
(
HttpServletRequest
request
,
HttpServletResponse
response
,
HandlerMethod
handler
Method
,
Exception
ex
)
{
authenticator
.
afterCompletion
(
request
,
response
,
handler
Method
,
ex
);
}
protected
void
writeResult
(
HttpServletResponse
response
,
ResponseDTO
<?>
result
)
{
...
...
commons/web-common/src/main/java/com/schbrain/common/web/support/authentication/Authenticator.java
View file @
e495c854
...
...
@@ -19,6 +19,6 @@ public interface Authenticator {
/**
* 请求完成后的回调
*/
void
afterCompletion
(
HttpServletRequest
request
,
HttpServletResponse
response
,
HandlerMethod
handler
,
Exception
exception
);
void
afterCompletion
(
HttpServletRequest
request
,
HttpServletResponse
response
,
HandlerMethod
handler
Method
,
Exception
exception
);
}
\ No newline at end of file
pom.xml
View file @
e495c854
...
...
@@ -79,7 +79,7 @@
<guava.version>
32.0.1-jre
</guava.version>
<hutool.version>
5.8.20
</hutool.version>
<jsr305.version>
3.0.2
</jsr305.version>
<logstash-logback-encoder.version>
7.
4
</logstash-logback-encoder.version>
<logstash-logback-encoder.version>
7.
3
</logstash-logback-encoder.version>
<mybatis.version>
3.5.13
</mybatis.version>
<mybatis.starter.version>
2.3.0
</mybatis.starter.version>
<mybatis-plus.version>
3.5.3.1
</mybatis-plus.version>
...
...
@@ -785,4 +785,4 @@
</profile>
</profiles>
</project>
</project>
\ No newline at end of file
starters/apollo-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/apollo/ConfigurablePropertiesLoader.java
View file @
e495c854
...
...
@@ -54,7 +54,7 @@ class ConfigurablePropertiesLoader {
ApolloProperties
apolloProperties
=
ApolloProperties
.
get
(
environment
);
// MUST NOT use CachedCompositePropertySource
// MUST NOT use CachedCompositePropertySource
, because propertyNames will be cached when property loading
CompositePropertySource
compositePropertySource
=
new
CompositePropertySource
(
PROPERTIES_PROPERTY_SOURCE
);
if
(
apolloProperties
.
isRemoteFirst
())
{
environment
.
getPropertySources
().
addFirst
(
compositePropertySource
);
...
...
starters/cache-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/cache/CacheAutoConfiguration.java
View file @
e495c854
...
...
@@ -10,7 +10,6 @@ import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Import
;
import
org.springframework.core.env.Environment
;
/**
* AutoConfiguration for schbrain cache
...
...
@@ -25,10 +24,10 @@ public class CacheAutoConfiguration {
@Bean
@ConditionalOnBean
(
CacheProvider
.
class
)
public
CacheProvider
cacheProvider
(
CacheProvider
cacheProvider
,
CacheProperties
cacheProperties
,
Environment
environment
)
{
CacheProvider
Delegate
delegate
=
new
CacheProviderDelegate
(
cacheProperties
,
cacheProvider
,
environment
);
CacheUtils
.
setCacheProvider
(
delegate
);
return
delegate
;
public
CacheProvider
cacheProvider
(
CacheProvider
cacheProvider
,
CacheProperties
cacheProperties
)
{
CacheProvider
provider
=
new
CacheProviderDelegate
(
cacheProperties
,
cacheProvider
);
CacheUtils
.
setCacheProvider
(
provider
);
return
provider
;
}
}
\ No newline at end of file
starters/cache-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/cache/CacheUtils.java
View file @
e495c854
...
...
@@ -46,6 +46,20 @@ public class CacheUtils {
return
getCacheProvider
().
getExpire
(
cacheKey
);
}
/**
* 模糊搜索 key, 默认采用 scan 实现
*/
public
static
Set
<
String
>
keys
(
String
pattern
)
{
return
keys
(
pattern
,
Long
.
MAX_VALUE
);
}
/**
* 模糊搜索 key, 默认采用 scan 实现
*/
public
static
Set
<
String
>
keys
(
String
pattern
,
long
limit
)
{
return
getCacheProvider
().
keys
(
pattern
,
limit
);
}
/**
* 获取缓存数据
*/
...
...
@@ -161,18 +175,4 @@ public class CacheUtils {
getCacheProvider
().
del
(
cacheKeys
);
}
/**
* 模糊搜索 key, 默认采用 scan 实现
*/
public
static
Set
<
String
>
keys
(
String
pattern
)
{
return
keys
(
pattern
,
Long
.
MAX_VALUE
);
}
/**
* 模糊搜索 key, 默认采用 scan 实现
*/
public
static
Set
<
String
>
keys
(
String
pattern
,
long
limit
)
{
return
getCacheProvider
().
keys
(
pattern
,
limit
);
}
}
\ No newline at end of file
starters/cache-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/cache/provider/CacheProvider.java
View file @
e495c854
package
com.schbrain.framework.autoconfigure.cache.provider
;
import
java.time.Duration
;
import
java.util.Collection
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
import
java.util.*
;
/**
* @author zhuyf
...
...
@@ -12,6 +9,11 @@ import java.util.Set;
**/
public
interface
CacheProvider
{
/**
* 查询key是否过期
*/
boolean
isExpired
(
String
cacheKey
);
/**
* 指定缓存失效时间
*/
...
...
@@ -27,30 +29,20 @@ public interface CacheProvider {
*/
boolean
hasKey
(
String
cacheKey
);
/**
* 删除缓存
*/
void
del
(
List
<
String
>
cacheKeys
);
/**
* 模糊搜索 key, 默认采用 scan 实现
*/
Set
<
String
>
keys
(
String
pattern
,
long
limit
);
/**
*
缓存获取
*
删除缓存
*/
<
T
>
T
get
(
String
cacheKey
,
Class
<
T
>
valueType
);
void
del
(
List
<
String
>
cacheKeys
);
/**
* 缓存获取
*/
<
T
>
Map
<
String
,
T
>
multiGet
(
Collection
<
String
>
cacheKeys
,
Class
<
T
>
valueType
,
boolean
discardIfValueIsNull
);
/**
* list 缓存获取
*/
<
T
>
List
<
T
>
getList
(
String
cacheKey
,
Class
<
T
>
valueType
);
<
T
>
T
get
(
String
cacheKey
,
Class
<
T
>
valueType
);
/**
* 缓存放入并设置时间
...
...
@@ -63,8 +55,13 @@ public interface CacheProvider {
<
T
>
void
multiSet
(
Map
<
String
,
T
>
data
,
Duration
expiration
);
/**
*
查询key是否过期
*
缓存获取
*/
boolean
isExpired
(
String
cacheKey
);
<
T
>
Map
<
String
,
T
>
multiGet
(
Collection
<
String
>
cacheKeys
,
Class
<
T
>
valueType
,
boolean
discardIfValueIsNull
);
/**
* list 缓存获取
*/
<
T
>
List
<
T
>
getList
(
String
cacheKey
,
Class
<
T
>
valueType
);
}
\ No newline at end of file
starters/cache-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/cache/provider/CacheProviderDelegate.java
View file @
e495c854
...
...
@@ -8,7 +8,6 @@ import com.schbrain.framework.autoconfigure.cache.properties.CacheProperties;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.apache.commons.collections4.MapUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.core.env.Environment
;
import
java.time.Duration
;
import
java.util.*
;
...
...
@@ -24,12 +23,12 @@ public class CacheProviderDelegate implements CacheProvider {
private
final
CacheProvider
cacheProvider
;
public
CacheProviderDelegate
(
CacheProperties
properties
,
CacheProvider
cacheProvider
,
Environment
environment
)
{
public
CacheProviderDelegate
(
CacheProperties
properties
,
CacheProvider
cacheProvider
)
{
this
.
cacheProvider
=
cacheProvider
;
if
(
properties
.
isAppendPrefix
())
{
String
prefix
=
properties
.
getPrefix
();
if
(
StringUtils
.
isBlank
(
prefix
))
{
prefix
=
ApplicationName
.
get
(
environment
);
prefix
=
ApplicationName
.
get
();
}
this
.
prefixWithDelimiter
=
prefix
+
properties
.
getDelimiter
();
}
else
{
...
...
@@ -37,6 +36,11 @@ public class CacheProviderDelegate implements CacheProvider {
}
}
@Override
public
boolean
isExpired
(
String
cacheKey
)
{
return
getCacheProvider
().
isExpired
(
withKeyPrefix
(
cacheKey
));
}
@Override
public
void
expire
(
String
cacheKey
,
Duration
expiration
)
{
checkDuration
(
expiration
);
...
...
@@ -53,15 +57,6 @@ public class CacheProviderDelegate implements CacheProvider {
return
getCacheProvider
().
hasKey
(
withKeyPrefix
(
cacheKey
));
}
@Override
public
void
del
(
List
<
String
>
cacheKeys
)
{
if
(
CollectionUtils
.
isEmpty
(
cacheKeys
))
{
return
;
}
List
<
String
>
keysWithPrefix
=
StreamUtils
.
toList
(
cacheKeys
,
this
::
withKeyPrefix
);
getCacheProvider
().
del
(
keysWithPrefix
);
}
@Override
public
Set
<
String
>
keys
(
String
pattern
,
long
limit
)
{
Set
<
String
>
keys
=
getCacheProvider
().
keys
(
withKeyPrefix
(
pattern
),
limit
);
...
...
@@ -69,46 +64,17 @@ public class CacheProviderDelegate implements CacheProvider {
}
@Override
public
<
T
>
T
get
(
String
cacheKey
,
Class
<
T
>
valueType
)
{
return
getCacheProvider
().
get
(
withKeyPrefix
(
cacheKey
),
valueType
);
}
@Override
public
<
T
>
Map
<
String
,
T
>
multiGet
(
Collection
<
String
>
cacheKeys
,
Class
<
T
>
valueType
,
boolean
discardIfValueIsNull
)
{
public
void
del
(
List
<
String
>
cacheKeys
)
{
if
(
CollectionUtils
.
isEmpty
(
cacheKeys
))
{
return
Collections
.
emptyMap
()
;
return
;
}
List
<
String
>
keysWithPrefix
=
StreamUtils
.
toList
(
cacheKeys
,
this
::
withKeyPrefix
);
Map
<
String
,
T
>
cachedDate
=
getCacheProvider
().
multiGet
(
keysWithPrefix
,
valueType
,
discardIfValueIsNull
);
Map
<
String
,
T
>
result
=
Maps
.
newHashMapWithExpectedSize
(
keysWithPrefix
.
size
());
// 这里不能用 Stream toMap, toMap 不允许 value 是 null
if
(
MapUtils
.
isEmpty
(
cachedDate
))
{
if
(
discardIfValueIsNull
)
{
result
=
Collections
.
emptyMap
();
}
else
{
for
(
String
cacheKey
:
keysWithPrefix
)
{
result
.
put
(
removeKeyPrefix
(
cacheKey
),
null
);
}
}
return
result
;
}
else
{
if
(
discardIfValueIsNull
)
{
// 值为 null 的key 在实现类获取时已经被丢弃,直接遍历 put 即可
for
(
Entry
<
String
,
T
>
cacheEntry
:
cachedDate
.
entrySet
())
{
result
.
put
(
removeKeyPrefix
(
cacheEntry
.
getKey
()),
cacheEntry
.
getValue
());
}
}
else
{
for
(
String
cacheKey
:
keysWithPrefix
)
{
result
.
put
(
removeKeyPrefix
(
cacheKey
),
cachedDate
.
get
(
cacheKey
));
}
}
}
return
result
;
getCacheProvider
().
del
(
keysWithPrefix
);
}
@Override
public
<
T
>
List
<
T
>
getLis
t
(
String
cacheKey
,
Class
<
T
>
valueType
)
{
return
getCacheProvider
().
get
List
(
withKeyPrefix
(
cacheKey
),
valueType
);
public
<
T
>
T
ge
t
(
String
cacheKey
,
Class
<
T
>
valueType
)
{
return
getCacheProvider
().
get
(
withKeyPrefix
(
cacheKey
),
valueType
);
}
@Override
...
...
@@ -131,8 +97,27 @@ public class CacheProviderDelegate implements CacheProvider {
}
@Override
public
boolean
isExpired
(
String
cacheKey
)
{
return
getCacheProvider
().
isExpired
(
withKeyPrefix
(
cacheKey
));
public
<
T
>
Map
<
String
,
T
>
multiGet
(
Collection
<
String
>
cacheKeys
,
Class
<
T
>
valueType
,
boolean
discardIfValueIsNull
)
{
if
(
CollectionUtils
.
isEmpty
(
cacheKeys
))
{
return
Collections
.
emptyMap
();
}
List
<
String
>
keysWithPrefix
=
StreamUtils
.
toList
(
cacheKeys
,
this
::
withKeyPrefix
);
Map
<
String
,
T
>
dataWithPrefixedKey
=
getCacheProvider
().
multiGet
(
keysWithPrefix
,
valueType
,
discardIfValueIsNull
);
if
(
MapUtils
.
isEmpty
(
dataWithPrefixedKey
))
{
return
Collections
.
emptyMap
();
}
else
{
Map
<
String
,
T
>
result
=
Maps
.
newHashMapWithExpectedSize
(
dataWithPrefixedKey
.
size
());
// 这里不能用 Stream toMap, toMap 不允许 value 是 null
for
(
Entry
<
String
,
T
>
cacheEntry
:
dataWithPrefixedKey
.
entrySet
())
{
result
.
put
(
removeKeyPrefix
(
cacheEntry
.
getKey
()),
cacheEntry
.
getValue
());
}
return
result
;
}
}
@Override
public
<
T
>
List
<
T
>
getList
(
String
cacheKey
,
Class
<
T
>
valueType
)
{
return
getCacheProvider
().
getList
(
withKeyPrefix
(
cacheKey
),
valueType
);
}
public
CacheProvider
getCacheProvider
()
{
...
...
starters/cache-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/cache/provider/redis/RedisCacheProvider.java
View file @
e495c854
...
...
@@ -7,10 +7,7 @@ import com.schbrain.framework.autoconfigure.cache.exception.CacheException;
import
com.schbrain.framework.autoconfigure.cache.provider.CacheProvider
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.data.redis.core.Cursor
;
import
org.springframework.data.redis.core.RedisCallback
;
import
org.springframework.data.redis.core.ScanOptions
;
import
org.springframework.data.redis.core.StringRedisTemplate
;
import
org.springframework.data.redis.core.*
;
import
org.springframework.data.redis.serializer.RedisSerializer
;
import
org.springframework.util.CollectionUtils
;
...
...
@@ -34,6 +31,14 @@ public class RedisCacheProvider implements CacheProvider {
this
.
redisTemplate
=
redisTemplate
;
}
/**
* 查询key是否过期
*/
@Override
public
boolean
isExpired
(
String
cacheKey
)
{
return
!
hasKey
(
cacheKey
);
}
/**
* 指定缓存失效时间
*/
...
...
@@ -62,17 +67,6 @@ public class RedisCacheProvider implements CacheProvider {
return
Boolean
.
TRUE
.
equals
(
redisTemplate
.
hasKey
(
cacheKey
));
}
/**
* 删除缓存
*/
@Override
public
void
del
(
List
<
String
>
cacheKeys
)
{
if
(
CollectionUtils
.
isEmpty
(
cacheKeys
))
{
return
;
}
redisTemplate
.
delete
(
cacheKeys
);
}
/**
* 模糊搜索 key
*/
...
...
@@ -92,35 +86,22 @@ public class RedisCacheProvider implements CacheProvider {
}
/**
*
缓存获取
*
删除缓存
*/
@Override
public
<
T
>
T
get
(
String
cacheKey
,
Class
<
T
>
type
)
{
return
JacksonUtils
.
getObjectFromJson
(
getValueFromRedis
(
cacheKey
),
type
);
}
@Override
public
<
T
>
Map
<
String
,
T
>
multiGet
(
Collection
<
String
>
cacheKeys
,
Class
<
T
>
type
,
boolean
discardIfValueIsNull
)
{
Map
<
String
,
T
>
result
=
Maps
.
newHashMapWithExpectedSize
(
cacheKeys
.
size
());
Iterables
.
partition
(
cacheKeys
,
DEFAULT_BATCH_SIZE
).
forEach
(
subKeys
->
{
List
<
String
>
valueList
=
Objects
.
requireNonNull
(
redisTemplate
.
opsForValue
().
multiGet
(
subKeys
));
for
(
int
i
=
0
;
i
<
subKeys
.
size
();
i
++)
{
T
rawValue
=
JacksonUtils
.
getObjectFromJson
(
valueList
.
get
(
i
),
type
);
if
(
discardIfValueIsNull
&&
rawValue
==
null
)
{
continue
;
}
result
.
put
(
subKeys
.
get
(
i
),
rawValue
);
}
});
return
result
;
public
void
del
(
List
<
String
>
cacheKeys
)
{
if
(
CollectionUtils
.
isEmpty
(
cacheKeys
))
{
return
;
}
redisTemplate
.
delete
(
cacheKeys
);
}
/**
*
list
缓存获取
* 缓存获取
*/
@Override
public
<
T
>
List
<
T
>
getLis
t
(
String
cacheKey
,
Class
<
T
>
type
)
{
return
JacksonUtils
.
get
Lis
tFromJson
(
getValueFromRedis
(
cacheKey
),
type
);
public
<
T
>
T
ge
t
(
String
cacheKey
,
Class
<
T
>
type
)
{
return
JacksonUtils
.
get
Objec
tFromJson
(
getValueFromRedis
(
cacheKey
),
type
);
}
/**
...
...
@@ -140,19 +121,36 @@ public class RedisCacheProvider implements CacheProvider {
byteMap
.
put
(
key
.
getBytes
(
StandardCharsets
.
UTF_8
),
JacksonUtils
.
writeObjectAsBytes
(
data
.
get
(
key
)));
}
connection
.
mSet
(
byteMap
);
long
expirationMillis
=
expiration
.
toMillis
();
for
(
byte
[]
rawKey
:
byteMap
.
keySet
())
{
connection
.
pExpire
(
rawKey
,
expiration
.
toMillis
()
);
connection
.
pExpire
(
rawKey
,
expiration
Millis
);
}
return
null
;
}));
}
@Override
public
<
T
>
Map
<
String
,
T
>
multiGet
(
Collection
<
String
>
cacheKeys
,
Class
<
T
>
type
,
boolean
discardIfValueIsNull
)
{
Map
<
String
,
T
>
result
=
Maps
.
newHashMapWithExpectedSize
(
cacheKeys
.
size
());
Iterables
.
partition
(
cacheKeys
,
DEFAULT_BATCH_SIZE
).
forEach
(
subKeys
->
{
List
<
String
>
valueList
=
Objects
.
requireNonNull
(
redisTemplate
.
opsForValue
().
multiGet
(
subKeys
));
for
(
int
i
=
0
;
i
<
subKeys
.
size
();
i
++)
{
T
rawValue
=
JacksonUtils
.
getObjectFromJson
(
valueList
.
get
(
i
),
type
);
if
(
discardIfValueIsNull
&&
rawValue
==
null
)
{
continue
;
}
result
.
put
(
subKeys
.
get
(
i
),
rawValue
);
}
});
return
result
;
}
/**
*
查询key是否过期
*
list 缓存获取
*/
@Override
public
boolean
isExpired
(
String
cacheKey
)
{
return
!
hasKey
(
cacheKey
);
public
<
T
>
List
<
T
>
getList
(
String
cacheKey
,
Class
<
T
>
type
)
{
return
JacksonUtils
.
getListFromJson
(
getValueFromRedis
(
cacheKey
),
type
);
}
private
String
getValueFromRedis
(
String
cacheKey
)
{
...
...
starters/logger-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/logger/listener/LoggerConfigLoadedEventListener.java
View file @
e495c854
...
...
@@ -12,6 +12,9 @@ import com.schbrain.framework.autoconfigure.apollo.event.ConfigLoadedEvent;
import
com.schbrain.framework.autoconfigure.apollo.event.listener.GenericConfigLoadedEventListener
;
import
com.schbrain.framework.autoconfigure.logger.LoggerConfigurationInitializer
;
import
com.schbrain.framework.autoconfigure.logger.properties.LoggerProperties
;
import
org.springframework.boot.context.logging.LoggingApplicationListener
;
import
org.springframework.boot.logging.LogFile
;
import
org.springframework.boot.logging.LoggingSystem
;
import
org.springframework.core.env.ConfigurableEnvironment
;
import
org.springframework.util.StringUtils
;
...
...
@@ -48,9 +51,9 @@ public class LoggerConfigLoadedEventListener extends GenericConfigLoadedEventLis
}
/**
* Add {@link
org.springframework.boot.context.logging.
LoggingApplicationListener#CONFIG_PROPERTY} property to SystemProperty
* Add {@link LoggingApplicationListener#CONFIG_PROPERTY} property to SystemProperty
*
* @see
org.springframework.boot.context.logging.LoggingApplicationListener#initializeSystem(ConfigurableEnvironment, org.springframework.boot.logging.LoggingSystem, org.springframework.boot.logging.
LogFile)
* @see
LoggingApplicationListener#initializeSystem(ConfigurableEnvironment, LoggingSystem,
LogFile)
*/
@SuppressWarnings
(
"JavadocReference"
)
private
void
configLoggingFileLocation
(
ConfigurableEnvironment
environment
,
String
logConfigNamespace
)
{
...
...
starters/mybatis-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/mybatis/datasource/extractor/DataSourcePropertiesExtractorSupport.java
View file @
e495c854
...
...
@@ -19,13 +19,13 @@ public abstract class DataSourcePropertiesExtractorSupport implements DataSource
return
TypeUtils
.
isAssignable
(
supportedType
,
dataSource
.
getClass
());
}
public
abstract
Class
<?
extends
DataSource
>
getSupportedType
();
@Override
public
Properties
extract
(
DataSource
dataSource
,
Map
<
String
,
String
>
properties
)
throws
SQLException
{
return
extract
(
dataSource
);
}
protected
abstract
Class
<?
extends
DataSource
>
getSupportedType
();
protected
abstract
Properties
extract
(
DataSource
dataSource
)
throws
SQLException
;
}
\ No newline at end of file
starters/mybatis-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/mybatis/datasource/extractor/DruidDataSourcePropertiesExtractor.java
View file @
e495c854
...
...
@@ -17,7 +17,7 @@ import java.util.Properties;
public
class
DruidDataSourcePropertiesExtractor
extends
DataSourcePropertiesExtractorSupport
{
@Override
p
ublic
Class
<
DruidDataSource
>
getSupportedType
()
{
p
rotected
Class
<
DruidDataSource
>
getSupportedType
()
{
return
DruidDataSource
.
class
;
}
...
...
starters/mybatis-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/mybatis/datasource/extractor/HikariDataSourcePropertiesExtractor.java
View file @
e495c854
...
...
@@ -15,7 +15,7 @@ import java.util.Properties;
public
class
HikariDataSourcePropertiesExtractor
extends
DataSourcePropertiesExtractorSupport
{
@Override
p
ublic
Class
<?
extends
DataSource
>
getSupportedType
()
{
p
rotected
Class
<?
extends
DataSource
>
getSupportedType
()
{
return
HikariDataSource
.
class
;
}
...
...
starters/xxl-job-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/xxl/SchbrainXxlJobExecutor.java
deleted
100644 → 0
View file @
0b7013c0
package
com.schbrain.framework.autoconfigure.xxl
;
import
com.xxl.job.core.executor.impl.XxlJobSpringExecutor
;
import
com.xxl.job.core.thread.*
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.DisposableBean
;
import
org.springframework.beans.factory.InitializingBean
;
import
org.springframework.util.ReflectionUtils
;
import
java.lang.reflect.Field
;
/**
* @author liaozan
* @since 2022/4/18
*/
@Slf4j
public
class
SchbrainXxlJobExecutor
extends
XxlJobSpringExecutor
implements
InitializingBean
,
DisposableBean
{
private
Field
executorRegistryThreadStopField
;
private
Field
jobLogFileCleanThreadStopField
;
private
Field
triggerCallbackThreadStopField
;
private
volatile
boolean
started
=
false
;
public
SchbrainXxlJobExecutor
()
{
try
{
this
.
executorRegistryThreadStopField
=
ExecutorRegistryThread
.
class
.
getDeclaredField
(
"toStop"
);
ReflectionUtils
.
makeAccessible
(
executorRegistryThreadStopField
);
}
catch
(
Exception
e
)
{
this
.
executorRegistryThreadStopField
=
null
;
}
try
{
this
.
triggerCallbackThreadStopField
=
TriggerCallbackThread
.
class
.
getDeclaredField
(
"toStop"
);
ReflectionUtils
.
makeAccessible
(
triggerCallbackThreadStopField
);
}
catch
(
Exception
e
)
{
this
.
triggerCallbackThreadStopField
=
null
;
}
try
{
this
.
jobLogFileCleanThreadStopField
=
JobLogFileCleanThread
.
class
.
getDeclaredField
(
"toStop"
);
ReflectionUtils
.
makeAccessible
(
jobLogFileCleanThreadStopField
);
}
catch
(
Exception
e
)
{
this
.
jobLogFileCleanThreadStopField
=
null
;
}
}
@Override
public
void
start
()
throws
Exception
{
afterPropertiesSet
();
}
@Override
public
void
afterPropertiesSet
()
throws
Exception
{
if
(
started
)
{
return
;
}
super
.
start
();
started
=
true
;
log
.
info
(
"Xxl-job started"
);
}
@Override
public
void
destroy
()
{
if
(!
started
)
{
return
;
}
super
.
destroy
();
resetThreadsStatus
();
started
=
false
;
log
.
info
(
"Xxl-job destroyed"
);
}
/**
* Reset xxl-job related thread to make it support restartable
*/
private
void
resetThreadsStatus
()
{
ReflectionUtils
.
setField
(
executorRegistryThreadStopField
,
ExecutorRegistryThread
.
getInstance
(),
false
);
ReflectionUtils
.
setField
(
triggerCallbackThreadStopField
,
TriggerCallbackThread
.
getInstance
(),
false
);
ReflectionUtils
.
setField
(
jobLogFileCleanThreadStopField
,
JobLogFileCleanThread
.
getInstance
(),
false
);
}
}
\ No newline at end of file
starters/xxl-job-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/xxl/XxlJobAutoConfiguration.java
View file @
e495c854
...
...
@@ -5,6 +5,7 @@ import com.schbrain.framework.autoconfigure.logger.properties.LoggerProperties;
import
com.schbrain.framework.autoconfigure.xxl.condition.XxlJobShouldAvailableCondition
;
import
com.schbrain.framework.autoconfigure.xxl.properties.XxlJobProperties
;
import
com.xxl.job.core.executor.XxlJobExecutor
;
import
com.xxl.job.core.executor.impl.XxlJobSpringExecutor
;
import
org.springframework.boot.autoconfigure.AutoConfiguration
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
...
...
@@ -22,10 +23,10 @@ import java.nio.file.Paths;
@EnableConfigurationProperties
(
XxlJobProperties
.
class
)
public
class
XxlJobAutoConfiguration
{
@Bean
@Bean
(
initMethod
=
"start"
,
destroyMethod
=
"destroy"
)
@ConditionalOnMissingBean
(
XxlJobExecutor
.
class
)
public
SchbrainXxlJobExecutor
schbrainX
xlJobSpringExecutor
(
XxlJobProperties
xxlJobProperties
,
LoggerProperties
loggingProperties
)
{
SchbrainXxlJobExecutor
executor
=
new
SchbrainXxlJob
Executor
();
public
XxlJobSpringExecutor
x
xlJobSpringExecutor
(
XxlJobProperties
xxlJobProperties
,
LoggerProperties
loggingProperties
)
{
XxlJobSpringExecutor
executor
=
new
XxlJobSpring
Executor
();
executor
.
setAdminAddresses
(
xxlJobProperties
.
getAdminAddresses
());
executor
.
setIp
(
xxlJobProperties
.
getIp
());
executor
.
setPort
(
xxlJobProperties
.
getPort
());
...
...
support/schbrain-base-dao/src/main/java/com/schbrain/framework/dao/BaseDao.java
View file @
e495c854
...
...
@@ -26,7 +26,7 @@ public interface BaseDao<T> {
* 批量插入领域对象
*
* @param objList 待插入领域对象列表
* @param fields
插入时指定的领域对象属性列表,如果为空表示对象的所有属性
* @param fields 插入时指定的领域对象属性列表,如果为空表示对象的所有属性
* @return 影响行数
*/
Integer
addList
(
List
<
T
>
objList
,
String
...
fields
);
...
...
@@ -50,11 +50,11 @@ public interface BaseDao<T> {
/**
* 分页获取列表
*
* @param pageNum
当前页码
* @param pageSize
当前页记录数
* @param whereClause
<tt>where</tt>关键词后的条件语句
* @param pageNum 当前页码
* @param pageSize 当前页记录数
* @param whereClause <tt>where</tt>关键词后的条件语句
* @param orderByClause <tt>order by</tt>关键词后的排序语句,注意:语句中不支持参数
* @param objs
<tt>where</tt>关键词后的条件语句中参数对应的值
* @param objs <tt>where</tt>关键词后的条件语句中参数对应的值
* @return <tt>page</tt>对象,包含记录及分页信息
*/
Page
<
T
>
pageByCondition
(
int
pageNum
,
int
pageSize
,
String
whereClause
,
String
orderByClause
,
Object
...
objs
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment