Kaynağa Gözat

流程配置

24282 2 yıl önce
ebeveyn
işleme
2663dad8a9

+ 7 - 5
hx-flow/src/main/java/com/fjhx/flow/config/FlowInitializingBean.java → hx-flow/src/main/java/com/fjhx/flow/config/FlowBeanPostProcessor.java

@@ -7,20 +7,22 @@ import org.springframework.beans.BeansException;
 import org.springframework.beans.factory.config.BeanPostProcessor;
 import org.springframework.context.annotation.Configuration;
 
+import javax.annotation.Nonnull;
+
 /**
  * 利用spring后置处理器注册流程代理对象
  */
 @Slf4j
 @Configuration
-public class FlowInitializingBean implements BeanPostProcessor {
+public class FlowBeanPostProcessor implements BeanPostProcessor {
 
     @Override
-    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
+    public Object postProcessAfterInitialization(@Nonnull Object bean, @Nonnull String beanName) throws BeansException {
 
         if (bean instanceof FlowDelegate) {
-            FlowDelegate flowDelegate = (FlowDelegate) bean;
-            FlowBean.addBean(flowDelegate.getFlowKey(), beanName);
-            log.info("流程:{} 注册成功", flowDelegate.getFlowKey());
+            String flowKey = ((FlowDelegate) bean).getFlowKey();
+            FlowBean.addBean(flowKey, beanName);
+            log.info("流程Key:{} spring委托对象注册成功", flowKey);
         }
 
         return BeanPostProcessor.super.postProcessAfterInitialization(bean, beanName);

+ 8 - 10
hx-flow/src/main/java/com/fjhx/flow/core/FlowBean.java

@@ -11,7 +11,7 @@ public class FlowBean {
     /**
      * 流程定义map
      */
-    protected static final Map<String, String> map = new HashMap<>();
+    private static final Map<String, String> map = new HashMap<>();
 
     /**
      * 添加流程bean
@@ -20,6 +20,9 @@ public class FlowBean {
      * @param beanName springBean名称
      */
     public static void addBean(String flowKey, String beanName) {
+        if (map.get(flowKey) != null) {
+            throw new RuntimeException("流程key:" + flowKey + " spring委托对象重复注册");
+        }
         map.put(flowKey, beanName);
     }
 
@@ -31,17 +34,12 @@ public class FlowBean {
      */
     public static FlowDelegate getBean(String flowKey) {
 
-        String beanBane = map.get(flowKey);
-        if (beanBane == null) {
-            throw new ServiceException("没有把流程 " + flowKey + " 注册到spring中");
-        }
-
-        FlowDelegate bean = SpringUtil.getBean(beanBane);
-        if (bean == null) {
-            throw new ServiceException("没有把流程 " + flowKey + " 注册到spring中");
+        String beanName = map.get(flowKey);
+        if (beanName == null) {
+            throw new ServiceException("没有把流程Key:" + flowKey + " 委托对象注册到spring中");
         }
 
-        return bean;
+        return SpringUtil.getBean(beanName);
     }
 
 }

+ 6 - 0
hx-flow/src/main/java/com/fjhx/flow/core/FlowThreadLocalUtil.java

@@ -29,6 +29,9 @@ public class FlowThreadLocalUtil {
     public static JSONObject getCurrentData() {
         return getData().getCurrentData();
     }
+    public static <T> T getCurrentData(Class<T> cls) {
+        return getData().getCurrentData().toJavaObject(cls);
+    }
     public static void setCurrentData(JSONObject currentData) {
         getData().setCurrentData(currentData);
     }
@@ -37,6 +40,9 @@ public class FlowThreadLocalUtil {
     public static JSONObject getStartData() {
         return getData().getStartData();
     }
+    public static <T> T getStartData(Class<T> cls) {
+        return getData().getStartData().toJavaObject(cls);
+    }
     public static void setStartData(JSONObject startData) {
         getData().setStartData(startData);
     }