3
3
import io .github .lvyahui8 .spring .aggregate .config .RuntimeSettings ;
4
4
import io .github .lvyahui8 .spring .aggregate .facade .DataBeanAggregateQueryFacade ;
5
5
import io .github .lvyahui8 .spring .aggregate .facade .impl .DataBeanAggregateQueryFacadeImpl ;
6
+ import io .github .lvyahui8 .spring .aggregate .interceptor .AggregateQueryInterceptor ;
6
7
import io .github .lvyahui8 .spring .aggregate .interceptor .AggregateQueryInterceptorChain ;
7
8
import io .github .lvyahui8 .spring .aggregate .interceptor .impl .AggregateQueryInterceptorChainImpl ;
8
9
import io .github .lvyahui8 .spring .aggregate .model .DataProvideDefinition ;
24
25
import org .springframework .context .ApplicationContextAware ;
25
26
import org .springframework .context .annotation .Bean ;
26
27
import org .springframework .context .annotation .Configuration ;
28
+ import org .springframework .core .Ordered ;
27
29
import org .springframework .core .annotation .AnnotationUtils ;
30
+ import org .springframework .core .annotation .Order ;
28
31
import org .springframework .scheduling .concurrent .CustomizableThreadFactory ;
29
32
import org .springframework .util .Assert ;
30
33
import org .springframework .util .StringUtils ;
31
34
32
35
import java .lang .reflect .Method ;
33
36
import java .lang .reflect .Modifier ;
34
- import java .util .Set ;
37
+ import java .util .* ;
35
38
import java .util .concurrent .ExecutorService ;
36
39
import java .util .concurrent .LinkedBlockingDeque ;
37
40
import java .util .concurrent .ThreadPoolExecutor ;
@@ -104,7 +107,7 @@ public DataBeanAggregateQueryService dataBeanAggregateQueryService (
104
107
* @return
105
108
*/
106
109
@ Bean (name = "aggregateExecutorService" )
107
- @ ConditionalOnMissingBean (name = "aggregateExecutorService" )
110
+ @ ConditionalOnMissingBean (name = "aggregateExecutorService" , value = ExecutorService . class )
108
111
public ExecutorService aggregateExecutorService () {
109
112
return new ThreadPoolExecutor (
110
113
properties .getThreadNumber (),
@@ -129,6 +132,24 @@ public DataProviderRepository dataProviderRepository() {
129
132
@ Bean (name = "aggregateQueryInterceptorChain" )
130
133
@ ConditionalOnMissingBean (AggregateQueryInterceptorChain .class )
131
134
public AggregateQueryInterceptorChain aggregateQueryInterceptorChain () {
132
- return new AggregateQueryInterceptorChainImpl ();
135
+ Map <String , AggregateQueryInterceptor > interceptorMap = applicationContext .getBeansOfType (AggregateQueryInterceptor .class );
136
+ AggregateQueryInterceptorChainImpl interceptorChain = new AggregateQueryInterceptorChainImpl ();
137
+ if (interceptorMap != null && ! interceptorMap .isEmpty ()) {
138
+ List <AggregateQueryInterceptor > interceptors = new ArrayList <>(interceptorMap .values ());
139
+ interceptors .sort (new Comparator <AggregateQueryInterceptor >() {
140
+ @ Override
141
+ public int compare (AggregateQueryInterceptor o1 , AggregateQueryInterceptor o2 ) {
142
+ Order order1 = o1 .getClass ().getAnnotation (Order .class );
143
+ Order order2 = o2 .getClass ().getAnnotation (Order .class );
144
+ int oi1 = order1 == null ? Ordered .LOWEST_PRECEDENCE : order1 .value ();
145
+ int oi2 = order2 == null ? Ordered .LOWEST_PRECEDENCE : order2 .value ();
146
+ return oi1 - oi2 ;
147
+ }
148
+ });
149
+ for (AggregateQueryInterceptor interceptor : interceptors ) {
150
+ interceptorChain .addInterceptor (interceptor );
151
+ }
152
+ }
153
+ return interceptorChain ;
133
154
}
134
155
}
0 commit comments