33import io .github .lvyahui8 .spring .aggregate .config .RuntimeSettings ;
44import io .github .lvyahui8 .spring .aggregate .facade .DataBeanAggregateQueryFacade ;
55import io .github .lvyahui8 .spring .aggregate .facade .impl .DataBeanAggregateQueryFacadeImpl ;
6+ import io .github .lvyahui8 .spring .aggregate .interceptor .AggregateQueryInterceptor ;
67import io .github .lvyahui8 .spring .aggregate .interceptor .AggregateQueryInterceptorChain ;
78import io .github .lvyahui8 .spring .aggregate .interceptor .impl .AggregateQueryInterceptorChainImpl ;
89import io .github .lvyahui8 .spring .aggregate .model .DataProvideDefinition ;
2425import org .springframework .context .ApplicationContextAware ;
2526import org .springframework .context .annotation .Bean ;
2627import org .springframework .context .annotation .Configuration ;
28+ import org .springframework .core .Ordered ;
2729import org .springframework .core .annotation .AnnotationUtils ;
30+ import org .springframework .core .annotation .Order ;
2831import org .springframework .scheduling .concurrent .CustomizableThreadFactory ;
2932import org .springframework .util .Assert ;
3033import org .springframework .util .StringUtils ;
3134
3235import java .lang .reflect .Method ;
3336import java .lang .reflect .Modifier ;
34- import java .util .Set ;
37+ import java .util .* ;
3538import java .util .concurrent .ExecutorService ;
3639import java .util .concurrent .LinkedBlockingDeque ;
3740import java .util .concurrent .ThreadPoolExecutor ;
@@ -104,7 +107,7 @@ public DataBeanAggregateQueryService dataBeanAggregateQueryService (
104107 * @return
105108 */
106109 @ Bean (name = "aggregateExecutorService" )
107- @ ConditionalOnMissingBean (name = "aggregateExecutorService" )
110+ @ ConditionalOnMissingBean (name = "aggregateExecutorService" , value = ExecutorService . class )
108111 public ExecutorService aggregateExecutorService () {
109112 return new ThreadPoolExecutor (
110113 properties .getThreadNumber (),
@@ -129,6 +132,24 @@ public DataProviderRepository dataProviderRepository() {
129132 @ Bean (name = "aggregateQueryInterceptorChain" )
130133 @ ConditionalOnMissingBean (AggregateQueryInterceptorChain .class )
131134 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 ;
133154 }
134155}
0 commit comments