|
@@ -8,15 +8,19 @@
|
|
|
*/
|
|
|
package com.yomahub.liteflow.spring;
|
|
|
|
|
|
+import cn.hutool.core.collection.CollStreamUtil;
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import com.yomahub.liteflow.annotation.util.AnnoUtil;
|
|
|
import com.yomahub.liteflow.aop.ICmpAroundAspect;
|
|
|
import com.yomahub.liteflow.core.NodeComponent;
|
|
|
import com.yomahub.liteflow.property.LiteflowConfig;
|
|
|
-import com.yomahub.liteflow.script.annotation.ScriptBean;
|
|
|
import com.yomahub.liteflow.script.ScriptBeanManager;
|
|
|
+import com.yomahub.liteflow.script.annotation.ScriptBean;
|
|
|
+import com.yomahub.liteflow.script.annotation.ScriptMethod;
|
|
|
import com.yomahub.liteflow.script.proxy.ScriptBeanProxy;
|
|
|
+import com.yomahub.liteflow.script.proxy.ScriptMethodProxy;
|
|
|
import com.yomahub.liteflow.util.LOGOPrinter;
|
|
|
import com.yomahub.liteflow.util.LiteFlowProxyUtil;
|
|
|
import org.slf4j.Logger;
|
|
@@ -24,12 +28,16 @@ import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.BeansException;
|
|
|
import org.springframework.beans.factory.config.BeanPostProcessor;
|
|
|
|
|
|
+import java.lang.reflect.Method;
|
|
|
+import java.util.Arrays;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* 组件扫描类,只要是NodeComponent的实现类,都可以被这个扫描器扫到
|
|
|
+ *
|
|
|
* @author Bryan.Zhang
|
|
|
*/
|
|
|
public class ComponentScanner implements BeanPostProcessor {
|
|
@@ -48,7 +56,7 @@ public class ComponentScanner implements BeanPostProcessor {
|
|
|
|
|
|
public ComponentScanner(LiteflowConfig liteflowConfig) {
|
|
|
this.liteflowConfig = liteflowConfig;
|
|
|
- if(liteflowConfig.getPrintBanner()){
|
|
|
+ if (liteflowConfig.getPrintBanner()) {
|
|
|
// 打印liteflow的LOGO
|
|
|
LOGOPrinter.print();
|
|
|
}
|
|
@@ -66,7 +74,7 @@ public class ComponentScanner implements BeanPostProcessor {
|
|
|
|
|
|
//判断是不是声明式组件
|
|
|
//如果是,就缓存到类属性的map中
|
|
|
- if (LiteFlowProxyUtil.isDeclareCmp(bean.getClass())){
|
|
|
+ if (LiteFlowProxyUtil.isDeclareCmp(bean.getClass())) {
|
|
|
LOG.info("proxy component[{}] has been found", beanName);
|
|
|
List<NodeComponent> nodeComponents = LiteFlowProxyUtil.proxy2NodeComponent(bean, beanName);
|
|
|
nodeComponents.forEach(
|
|
@@ -77,7 +85,7 @@ public class ComponentScanner implements BeanPostProcessor {
|
|
|
}
|
|
|
);
|
|
|
// 只有注解支持单bean多Node,所以一个直接返回
|
|
|
- if (nodeComponents.size() == 1){
|
|
|
+ if (nodeComponents.size() == 1) {
|
|
|
return nodeComponents.get(0);
|
|
|
}
|
|
|
return bean;
|
|
@@ -98,11 +106,38 @@ public class ComponentScanner implements BeanPostProcessor {
|
|
|
return cmpAroundAspect;
|
|
|
}
|
|
|
|
|
|
- //扫描@ScriptBean修饰的类
|
|
|
+ // 扫描@ScriptBean修饰的类
|
|
|
ScriptBean scriptBean = AnnoUtil.getAnnotation(clazz, ScriptBean.class);
|
|
|
- if (ObjectUtil.isNotNull(scriptBean)){
|
|
|
+ if (ObjectUtil.isNotNull(scriptBean)) {
|
|
|
ScriptBeanProxy proxy = new ScriptBeanProxy(bean, clazz, scriptBean);
|
|
|
ScriptBeanManager.addScriptBean(scriptBean.value(), proxy.getProxyScriptBean());
|
|
|
+ return bean;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 扫描@ScriptMethod修饰的类
|
|
|
+ List<Method> scriptMethods = Arrays.stream(clazz.getMethods())
|
|
|
+ .filter(method -> {
|
|
|
+ ScriptMethod scriptMethod = AnnoUtil.getAnnotation(method, ScriptMethod.class);
|
|
|
+ return ObjectUtil.isNotNull(scriptMethod) && StrUtil.isNotEmpty(scriptMethod.value());
|
|
|
+ })
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ if (CollUtil.isNotEmpty(scriptMethods)) {
|
|
|
+ Map<String, List<Method>> scriptMethodsGroupByValue = CollStreamUtil.groupBy(scriptMethods, method -> {
|
|
|
+ ScriptMethod scriptMethod = AnnoUtil.getAnnotation(method, ScriptMethod.class);
|
|
|
+ return scriptMethod.value();
|
|
|
+ }, Collectors.toList());
|
|
|
+
|
|
|
+
|
|
|
+ for (Map.Entry<String, List<Method>> entry : scriptMethodsGroupByValue.entrySet()) {
|
|
|
+ String key = entry.getKey();
|
|
|
+ List<Method> methods = entry.getValue();
|
|
|
+ ScriptMethodProxy proxy = new ScriptMethodProxy(bean, clazz, methods);
|
|
|
+
|
|
|
+ ScriptBeanManager.addScriptBean(key, proxy.getProxyScriptMethod());
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ return bean;
|
|
|
}
|
|
|
|
|
|
return bean;
|