Browse Source

中心服务业务处理流程,抒写完成,待测试阶段。

wuxw7 8 years ago
parent
commit
fbe3ee1eee
19 changed files with 653 additions and 17 deletions
  1. 1 1
      CenterService/doc/centerService.docx
  2. 5 4
      CenterService/src/main/java/com/java110/center/CenterServiceApplication.java
  3. 47 4
      CenterService/src/main/java/com/java110/center/smo/impl/CenterServiceSMOImpl.java
  4. 22 0
      java110-bean/src/main/java/com/java110/entity/center/DataFlow.java
  5. 1 0
      java110-common/src/main/java/com/java110/common/constant/StatusConstant.java
  6. 2 1
      java110-common/src/main/java/com/java110/common/factory/DataFlowFactory.java
  7. 14 0
      java110-common/src/main/java/com/java110/common/util/Assert.java
  8. 1 5
      java110-common/src/main/java/com/java110/common/util/ResponseTemplateUtil.java
  9. 4 2
      java110-common/src/main/java/com/java110/common/util/WebServiceAxisClient.java
  10. 7 0
      java110-config/src/main/resources/config/center_event.properties
  11. 34 0
      java110-event/src/main/java/com/java110/event/center/DataFlowEvent.java
  12. 207 0
      java110-event/src/main/java/com/java110/event/center/DataFlowEventPublishing.java
  13. 12 0
      java110-event/src/main/java/com/java110/event/center/DataFlowListener.java
  14. 48 0
      java110-event/src/main/java/com/java110/event/center/DataFlowListenerOrderComparator.java
  15. 154 0
      java110-event/src/main/java/com/java110/event/center/init/CenterServiceStartInit.java
  16. 21 0
      java110-event/src/main/java/com/java110/event/center/merchant/event/DataFlowMerchantEvent.java
  17. 26 0
      java110-event/src/main/java/com/java110/event/center/merchant/listener/DataFlowMerchantListener.java
  18. 21 0
      java110-event/src/main/java/com/java110/event/center/user/event/DataFlowCustEvent.java
  19. 26 0
      java110-event/src/main/java/com/java110/event/center/user/listener/DataFlowCustListener.java

+ 1 - 1
CenterService/doc/centerService.docx

@@ -994,7 +994,7 @@ date
 }
 
 2、返回模板
-{  "orders": {    "transactionId": "100000000020180409224736000001",    "responseTime": "20180409224736",    "remark":"备注",    "sign": "这个服务是否要求md5签名",    "response": {//这个是centerorder 返回的状态结果      "code": "1999",      "message": "错误信息"    }  },  "business":[{//这个是相应的业务系统返回的结果,(受理为空,查询时不为空)    "response": {      "code": "1999",      "message": "错误消息"    }    //相应内容  }]}
+{  "orders": {    "transactionId": "100000000020180409224736000001",    "responseTime": "20180409224736",    "sign": "这个服务是否要求md5签名",    "response": {//这个是centerorder 返回的状态结果      "code": "1999",      "message": "错误信息"    }  },  "business":[{//这个是相应的业务系统返回的结果,(受理为空,查询时不为空)    "response": {      "code": "1999",      "message": "错误消息"    }    //相应内容  }]}
 
  系统调用方式
 

+ 5 - 4
CenterService/src/main/java/com/java110/center/CenterServiceApplication.java

@@ -1,5 +1,6 @@
 package com.java110.center;
 
+import com.java110.event.center.init.CenterServiceStartInit;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
@@ -18,13 +19,13 @@ import org.springframework.context.ApplicationContext;
 @SpringBootApplication(scanBasePackages={"com.java110.service","com.java110.order","com.java110.core","com.java110.event"})
 @EnableDiscoveryClient
 //@EnableConfigurationProperties(EventProperties.class)
-public class CenterServiceApplication {
+public class CenterServiceApplicationStart {
 
     public static void main(String[] args) throws Exception{
-        ApplicationContext context = SpringApplication.run(CenterServiceApplication.class, args);
+        ApplicationContext context = SpringApplication.run(CenterServiceApplicationStart.class, args);
 
-        /*SystemStartUpInit systemStartUpInit = new SystemStartUpInit();
+        CenterServiceStartInit centerServiceStartInit = new CenterServiceStartInit();
 
-        systemStartUpInit.initSystemConfig(context);*/
+        centerServiceStartInit.initSystemConfig(context);
     }
 }

+ 47 - 4
CenterService/src/main/java/com/java110/center/smo/impl/CenterServiceSMOImpl.java

@@ -1,5 +1,7 @@
 package com.java110.center.smo.impl;
 
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
 import com.java110.center.dao.ICenterServiceDAO;
 import com.java110.center.smo.ICenterServiceSMO;
 import com.java110.common.cache.AppRouteCache;
@@ -10,13 +12,13 @@ import com.java110.common.exception.*;
 import com.java110.common.factory.DataFlowFactory;
 import com.java110.common.kafka.KafkaFactory;
 import com.java110.common.log.LoggerEngine;
-import com.java110.common.util.DateUtil;
-import com.java110.common.util.ResponseTemplateUtil;
-import com.java110.common.util.StringUtil;
+import com.java110.common.util.*;
 import com.java110.entity.center.*;
+import com.java110.event.center.DataFlowEventPublishing;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
+import org.springframework.web.client.RestTemplate;
 
 import java.util.*;
 
@@ -31,6 +33,9 @@ public class CenterServiceSMOImpl implements ICenterServiceSMO {
     @Autowired
     ICenterServiceDAO centerServiceDaoImpl;
 
+    @Autowired
+    private RestTemplate restTemplate;
+
     @Override
     public String service(String reqJson, Map<String, String> headers) throws SMOException{
 
@@ -522,9 +527,41 @@ public class CenterServiceSMOImpl implements ICenterServiceSMO {
      * 处理同步业务
      * @param dataFlow
      */
-    private void doSynchronousBusinesses(DataFlow dataFlow) {
+    private void doSynchronousBusinesses(DataFlow dataFlow) throws BusinessException{
         List<Business> synchronousBusinesses = DataFlowFactory.getSynchronousBusinesses(dataFlow);
+        AppService service = null;
+        JSONObject requestBusinessJson = null;
+        JSONArray responseBusinesses = new JSONArray();
+        String responseMessage = "";
         //6.2处理同步服务
+        for(Business business : synchronousBusinesses) {
+            service = DataFlowFactory.getService(dataFlow,business.getServiceCode());
+            requestBusinessJson = DataFlowFactory.getRequestBusinessJson(business);
+            dataFlow.setRequestBusinessJson(requestBusinessJson);
+
+            if(service.getInvokeMethod() == null || "".equals(service.getInvokeMethod())) {//post方式
+                //http://user-service/test/sayHello
+                responseMessage = restTemplate.postForObject(service.getUrl(),dataFlow.getRequestBusinessJson().toJSONString(),String.class);
+            }else{//webservice方式
+                responseMessage = (String) WebServiceAxisClient.callWebService(service.getUrl(),service.getInvokeMethod(),
+                        new Object[]{dataFlow.getRequestBusinessJson().toJSONString()},
+                        service.getTimeOut());
+            }
+
+            if(StringUtil.isNullOrNone(responseMessage) || !Assert.isJsonObject(responseMessage)){
+                throw new BusinessException(ResponseConstant.RESULT_CODE_INNER_ERROR,"下游系统返回格式不正确,请按协议规范处理");
+            }
+            dataFlow.setResponseBusinessJson(JSONObject.parseObject(responseMessage));
+            //发布事件
+            DataFlowEventPublishing.multicastEvent(service.getServiceCode(),dataFlow);
+
+            responseBusinesses.add(dataFlow.getResponseBusinessJson().getJSONArray("business"));
+        }
+
+        dataFlow.setRequestBusinessJson(JSONObject.parseObject(dataFlow.getReqJson()));
+
+        dataFlow.setResponseBusinessJson(JSONObject.parseObject(ResponseTemplateUtil.createCommonResponseJson(dataFlow.getTransactionId(),
+                ResponseConstant.NO_NEED_SIGN, ResponseConstant.RESULT_CODE_SUCCESS, "成功",responseBusinesses)));
     }
 
     /**
@@ -534,6 +571,7 @@ public class CenterServiceSMOImpl implements ICenterServiceSMO {
     private void doAsynchronousBusinesses(DataFlow dataFlow) throws BusinessException{
         //6.3 处理异步,按消息队里处理
         List<Business> asynchronousBusinesses = DataFlowFactory.getAsynchronousBusinesses(dataFlow);
+
         try {
             for (Business business : asynchronousBusinesses) {
                 KafkaFactory.sendKafkaMessage(DataFlowFactory.getService(dataFlow, business.getServiceCode()).getMessageQueueName(), "",
@@ -542,6 +580,11 @@ public class CenterServiceSMOImpl implements ICenterServiceSMO {
         }catch (Exception e){
             throw new BusinessException(ResponseConstant.RESULT_CODE_INNER_ERROR,e.getMessage());
         }
+
+        dataFlow.setRequestBusinessJson(JSONObject.parseObject(dataFlow.getReqJson()));
+
+        dataFlow.setResponseBusinessJson(JSONObject.parseObject(ResponseTemplateUtil.createOrderResponseJson(dataFlow.getTransactionId(),
+                ResponseConstant.NO_NEED_SIGN, ResponseConstant.RESULT_CODE_SUCCESS, "成功")));
     }
 
     public ICenterServiceDAO getCenterServiceDaoImpl() {

+ 22 - 0
java110-bean/src/main/java/com/java110/entity/center/DataFlow.java

@@ -66,6 +66,11 @@ public class DataFlow {
     private Map<String,String> headers = new HashMap<String,String>();
 
     private AppRoute appRoute;
+    //请求业务系统报文
+    private JSONObject requestBusinessJson;
+
+    //业务系统返回报文
+    private JSONObject responseBusinessJson;
 
     public String getoId() {
         return oId;
@@ -275,6 +280,23 @@ public class DataFlow {
         this.ip = ip;
     }
 
+
+    public JSONObject getRequestBusinessJson() {
+        return requestBusinessJson;
+    }
+
+    public void setRequestBusinessJson(JSONObject requestBusinessJson) {
+        this.requestBusinessJson = requestBusinessJson;
+    }
+
+    public JSONObject getResponseBusinessJson() {
+        return responseBusinessJson;
+    }
+
+    public void setResponseBusinessJson(JSONObject responseBusinessJson) {
+        this.responseBusinessJson = responseBusinessJson;
+    }
+
     /**
      * 添加各个环节的耗时
      * @param dataFlowLinksCost

+ 1 - 0
java110-common/src/main/java/com/java110/common/constant/StatusConstant.java

@@ -31,5 +31,6 @@ public class StatusConstant {
     public final static String STATUS_CD_INVALID = "1";
 
     public final static String REQUEST_BUSINESS_TYPE = "Q";
+    public final static String RESPONSE_BUSINESS_TYPE = "B";
     public final static String NOTIFY_BUSINESS_TYPE = "N";
 }

+ 2 - 1
java110-common/src/main/java/com/java110/common/factory/DataFlowFactory.java

@@ -8,6 +8,7 @@ import com.java110.common.constant.MappingConstant;
 import com.java110.common.constant.ResponseConstant;
 import com.java110.common.constant.StatusConstant;
 import com.java110.common.util.DateUtil;
+import com.java110.common.util.ResponseTemplateUtil;
 import com.java110.common.util.SequenceUtil;
 import com.java110.entity.center.*;
 
@@ -299,6 +300,7 @@ public class DataFlowFactory {
         return notifyMessage;
     }
 
+
     public static JSONObject getCompletedBusinessErrorJson(Map business,AppService appService){
         JSONObject notifyMessage = getTransactionBusinessBaseJson(StatusConstant.NOTIFY_BUSINESS_TYPE);
         JSONArray businesses = notifyMessage.getJSONArray("business");
@@ -328,7 +330,6 @@ public class DataFlowFactory {
         JSONArray businesses = notifyMessage.getJSONArray("business");
 
         JSONObject busi = null;
-        JSONObject response = null;
             busi = new JSONObject();
             busi.put("bId",business.getbId());
             busi.put("serviceCode",business.getServiceCode());

+ 14 - 0
java110-common/src/main/java/com/java110/common/util/Assert.java

@@ -80,4 +80,18 @@ public class Assert extends org.springframework.util.Assert{
         }
 
     }
+
+    /**
+     * 校验是否为JSON
+     * @param msg
+     * @return
+     */
+    public static Boolean isJsonObject(String msg) {
+        try{
+            JSONObject.parseObject(msg);
+        }catch (Exception e){
+            return false;
+        }
+        return true;
+    }
 }

+ 1 - 5
java110-common/src/main/java/com/java110/common/util/ResponseTemplateUtil.java

@@ -79,10 +79,6 @@ public class ResponseTemplateUtil {
      * @return
      */
     public static String createCommonResponseJson(DataFlow dataFlow){
-        return createCommonResponseJson(dataFlow.getTransactionId(),
-                dataFlow.getResSign(),
-                dataFlow.getCode(),
-                dataFlow.getMessage(),
-                dataFlow.getResBusiness());
+        return dataFlow.getResponseBusinessJson().toJSONString();
     }
 }

+ 4 - 2
java110-common/src/main/java/com/java110/common/util/WebServiceAxisClient.java

@@ -7,6 +7,8 @@ package com.java110.common.util;
  * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
  */
 
+import com.java110.common.constant.ResponseConstant;
+import com.java110.common.exception.BusinessException;
 import com.java110.common.log.LoggerEngine;
 import org.apache.axis.client.Call;
 import org.apache.axis.client.Service;
@@ -52,7 +54,7 @@ public class WebServiceAxisClient extends LoggerEngine {
      * @return
      * @throws Exception
      */
-    public static Object callWebService(String url, String function, Object[] obj,Integer timeOut) throws Exception{
+    public static Object callWebService(String url, String function, Object[] obj,Integer timeOut) throws BusinessException {
         Object retObj = null;
         try {
             logger.debug("-----------开始调用Web Service-----------");
@@ -73,7 +75,7 @@ public class WebServiceAxisClient extends LoggerEngine {
             logger.error("-----------调用Web Service异常,原因:{}", e);
             e.printStackTrace();
             retObj = e.getMessage();
-            throw new Exception("WebServiceAxisClient.callWebService throws Exception : " + e.getMessage(), e);
+            throw new BusinessException(ResponseConstant.RESULT_CODE_INNER_ERROR,"WebServiceAxisClient.callWebService throws Exception : " + e.getMessage());
         }
         return retObj;
     }

+ 7 - 0
java110-config/src/main/resources/config/center_event.properties

@@ -0,0 +1,7 @@
+java110.event.properties.centerServiceListener=\
+  dataFlowCustListener,\
+  dataFlowMerchantListener
+
+java110.event.properties.centerServiceEvent=\
+  save.userService.userInfo::com.java110.event.center.user.event.DataFlowCustEvent,\
+  save.merchantService.merchantInfo::com.java110.event.center.user.event.DataFlowMerchantEvent

+ 34 - 0
java110-event/src/main/java/com/java110/event/center/DataFlowEvent.java

@@ -0,0 +1,34 @@
+package com.java110.event.center;
+
+import com.java110.entity.center.DataFlow;
+
+import java.util.EventObject;
+
+/**
+ * 数据流事件
+ * Created by wuxw on 2018/4/17.
+ */
+public class DataFlowEvent extends EventObject {
+
+
+    private DataFlow dataFlow;
+
+    /**
+     * Constructs a prototypical Event.
+     *
+     * @param source The object on which the Event initially occurred.
+     * @throws IllegalArgumentException if source is null.
+     */
+    public DataFlowEvent(Object source,DataFlow dataFlow) {
+        super(source);
+        this.dataFlow = dataFlow;
+    }
+
+    public DataFlow getDataFlow() {
+        return dataFlow;
+    }
+
+    public void setDataFlow(DataFlow dataFlow) {
+        this.dataFlow = dataFlow;
+    }
+}

+ 207 - 0
java110-event/src/main/java/com/java110/event/center/DataFlowEventPublishing.java

@@ -0,0 +1,207 @@
+package com.java110.event.center;
+
+import com.java110.common.constant.CommonConstant;
+import com.java110.common.constant.ResponseConstant;
+import com.java110.common.exception.BusinessException;
+import com.java110.common.log.LoggerEngine;
+import com.java110.common.util.Assert;
+import com.java110.entity.center.DataFlow;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.Executor;
+import java.util.concurrent.Executors;
+
+/**
+ * 数据流 事件发布
+ * Created by wuxw on 2018/4/17.
+ */
+public class DataFlowEventPublishing extends LoggerEngine {
+
+    private static Executor taskExecutor;
+
+    //默认 线程数 100
+    private final static int DEFAULT_THREAD_NUM = 100;
+
+    /**
+     * 保存侦听实例信息,一般启动时加载
+     */
+    private final static List<DataFlowListener<?>> listeners = new ArrayList<DataFlowListener<?>>();
+
+    /**
+     * 保存事件实例信息,一般启动时加载
+     */
+    private final static Map<String,Class<DataFlowEvent>> events = new HashMap<String,Class<DataFlowEvent>>();
+
+    /**
+     * 根据 事件类型查询侦听
+     */
+    private final static Map<String,List<DataFlowListener<?>>> cacheListenersMap = new HashMap<String, List<DataFlowListener<?>>>();
+
+
+
+
+
+    /**
+     * 添加 侦听,这个只有启动时,单线程 处理,所以是线程安全的
+     * @param listener
+     */
+    public static void addListenner(DataFlowListener<?> listener){
+        listeners.add(listener);
+    }
+
+    /**
+     * 获取侦听(全部侦听)
+     * @return
+     */
+    public static List<DataFlowListener<?>> getListeners(){
+        return listeners;
+    }
+
+    /**
+     * 根据是否实现了某个接口,返回侦听
+     * @param interfaceClassName
+     * @since 1.8
+     * @return
+     */
+    public static List<DataFlowListener<?>> getListeners(String interfaceClassName){
+
+        Assert.isNull(interfaceClassName,"获取需要发布的事件处理侦听时,传递事件为空,请检查");
+
+        //先从缓存中获取,为了提升效率
+        if(cacheListenersMap.containsKey(interfaceClassName)){
+            return cacheListenersMap.get(interfaceClassName);
+        }
+
+        List<DataFlowListener<?>> dataFlowListeners = new ArrayList<DataFlowListener<?>>();
+        for(DataFlowListener<?> listener : getListeners()){
+            Type[] types =  listener.getClass().getGenericInterfaces();
+            for (Type type : types) {
+                if (type instanceof ParameterizedType) {
+                    Type[] typeInterfaces = ((ParameterizedType) type).getActualTypeArguments();
+                    for (Type typeInterface : typeInterfaces){
+                        if(interfaceClassName.equals(typeInterface.getTypeName())){
+                            dataFlowListeners.add(listener);
+                        }
+                    }
+                }
+            }
+        }
+
+        //这里排序
+        DataFlowListenerOrderComparator.sort(dataFlowListeners);
+
+        //将数据放入缓存中
+        cacheListenersMap.put(interfaceClassName,dataFlowListeners);
+        return dataFlowListeners;
+    }
+
+    /**
+     * 注册事件
+     */
+    public static void addEvent(String serviceCode ,Class<DataFlowEvent> event) {
+        events.put(serviceCode,event);
+    }
+
+    /**
+     * 获取事件
+     * @param serviceCode
+     * @return
+     * @throws Exception
+     */
+    public static Class<DataFlowEvent> getEvent(String serviceCode) throws BusinessException{
+        Class<DataFlowEvent> targetEvent = events.get(serviceCode);
+        Assert.notNull(targetEvent,"改服务未注册该事件[serviceCode = "+serviceCode+"],系统目前不支持!");
+        return targetEvent;
+    }
+
+
+    /**
+     * 发布事件
+     * @param serviceCode
+     * @param dataFlow
+     */
+    public static void multicastEvent(String serviceCode,DataFlow dataFlow) throws BusinessException{
+        multicastEvent(serviceCode,dataFlow,null);
+    }
+
+    /**
+     * 发布事件
+     * @param serviceCode
+     * @param dataFlow 这个订单信息,以便于 侦听那边需要用
+     */
+    public static void multicastEvent(String serviceCode,DataFlow dataFlow,String asyn) throws  BusinessException{
+        try {
+            Class<DataFlowEvent> dataFlowEventClass = getEvent(serviceCode);
+
+            Class[] parameterTypes = {Object.class, DataFlow.class};
+
+            Constructor constructor = dataFlowEventClass.getClass().getConstructor(parameterTypes);
+            Object[] parameters = {null, dataFlow};
+            DataFlowEvent targetDataFlowEvent = (DataFlowEvent) constructor.newInstance(parameters);
+            multicastEvent(targetDataFlowEvent, asyn);
+        }catch (Exception e){
+            throw new BusinessException(ResponseConstant.RESULT_CODE_INNER_ERROR,"发布侦听失败,失败原因为:"+e);
+        }
+
+    }
+
+
+
+
+    /**
+     * 发布事件
+     * @param event
+     * @param asyn A 表示异步处理
+     */
+    public static void multicastEvent(final DataFlowEvent event,String asyn) {
+        for (final DataFlowListener<?> listener : getListeners(event.getClass().getName())) {
+
+            if(CommonConstant.PROCESS_ORDER_ASYNCHRONOUS.equals(asyn)){ //异步处理
+
+                Executor executor = getTaskExecutor();
+                executor.execute(new Runnable() {
+                    @Override
+                    public void run() {
+                        invokeListener(listener, event);
+                    }
+                });
+
+            }
+            else {
+                invokeListener(listener, event);
+            }
+        }
+    }
+
+    /**
+     * Return the current task executor for this multicaster.
+     */
+    protected static synchronized Executor getTaskExecutor() {
+        if(taskExecutor == null) {
+            taskExecutor = Executors.newFixedThreadPool(DEFAULT_THREAD_NUM);
+        }
+        return taskExecutor;
+    }
+
+    /**
+     * Invoke the given listener with the given event.
+     * @param listener the ApplicationListener to invoke
+     * @param event the current event to propagate
+     * @since 4.1
+     */
+    @SuppressWarnings({"unchecked", "rawtypes"})
+    protected static void invokeListener(DataFlowListener listener, DataFlowEvent event) {
+        try {
+            listener.soService(event);
+        }catch (Exception e){
+            LoggerEngine.error("发布侦听失败",e);
+            throw new RuntimeException("发布侦听失败,"+listener+ event + e);
+        }
+    }
+}

+ 12 - 0
java110-event/src/main/java/com/java110/event/center/DataFlowListener.java

@@ -0,0 +1,12 @@
+package com.java110.event.center;
+
+import java.util.EventListener;
+
+/**
+ * 通用事件处理,
+ * Created by wuxw on 2018/4/17.
+ */
+public interface DataFlowListener <E extends DataFlowEvent> extends EventListener {
+
+    void soService(E event);
+}

+ 48 - 0
java110-event/src/main/java/com/java110/event/center/DataFlowListenerOrderComparator.java

@@ -0,0 +1,48 @@
+package com.java110.event.center;
+
+import com.java110.event.app.order.Ordered;
+
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+
+/**
+ * 侦听排序类
+ * Created by wuxw on 2018/4/17.
+ */
+public class DataFlowListenerOrderComparator implements Comparator<Object> {
+
+    public static final DataFlowListenerOrderComparator INSTANCE = new DataFlowListenerOrderComparator();
+
+
+
+    public static void sort(List<?> list) {
+        if (list.size() > 1) {
+            Collections.sort(list, INSTANCE);
+        }
+    }
+
+    @Override
+    public int compare(Object o1, Object o2) {
+        return doCompare(o1,o2);
+    }
+
+    private Integer getOrder(Object obj){
+        return (obj instanceof Ordered ? ((Ordered) obj).getOrder() : null);
+    }
+
+    private int doCompare(Object o1, Object o2) {
+        boolean p1 = (o1 instanceof Ordered);
+        boolean p2 = (o2 instanceof Ordered);
+        if (p1 && !p2) {
+            return -1;
+        }
+        else if (p2 && !p1) {
+            return 1;
+        }
+
+        int i1 = getOrder(o1);
+        int i2 = getOrder(o2);
+        return (i1 < i2) ? -1 : (i1 > i2) ? 1 : 0;
+    }
+}

+ 154 - 0
java110-event/src/main/java/com/java110/event/center/init/CenterServiceStartInit.java

@@ -0,0 +1,154 @@
+package com.java110.event.center.init;
+
+import com.java110.common.factory.ApplicationContextFactory;
+import com.java110.entity.center.DataFlow;
+import com.java110.event.app.AppEventPublishing;
+import com.java110.event.app.AppListener;
+import com.java110.event.center.DataFlowEventPublishing;
+import com.java110.event.center.DataFlowListener;
+import com.java110.event.listener.common.CommonDispatchListener;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.boot.context.event.ApplicationReadyEvent;
+import org.springframework.context.ApplicationContext;
+import org.springframework.core.io.ClassPathResource;
+import org.springframework.core.io.support.PropertiesLoaderUtils;
+
+import javax.naming.ConfigurationException;
+import java.util.Properties;
+
+/**
+ * 系统启动时加载信息
+ * Created by wuxw on 2017/4/14.
+ */
+public class CenterServiceStartInit  {
+
+    /**
+     * 默认 事件配置路径classpath:/
+     */
+    private final String DEFAULT_EVENT_PATH = "config/";
+
+
+    /**
+     * 默认 文件名称  .properties
+     */
+    private final String DEFAULT_FILE_NAME = "center_event.properties";
+
+    /**
+     * 订单调度处理侦听
+     */
+    private final static String DATAFLOW_LISTENER = "java110.event.properties.centerServiceListener";
+
+    /**
+     * 订单调度事件
+     */
+    private final static String DISPATCH_EVENT = "java110.event.properties.centerServiceEvent";
+
+
+
+
+    /**
+     * 加载配置文件,将侦听初始化
+     * @param event
+     */
+   // @Override
+    public void onApplicationEvent(ApplicationReadyEvent event){
+
+
+        //加载配置文件,注册订单处理侦听
+        try {
+
+            ApplicationContextFactory.setApplicationContext(event.getApplicationContext());
+
+            Properties properties = this.load(DEFAULT_EVENT_PATH,DEFAULT_FILE_NAME);
+
+            registerListener(properties);
+
+            //注册事件
+            registerEvent(properties);
+
+        }
+        catch (Exception ex) {
+            throw new IllegalStateException("system init error", ex);
+        }
+
+    }
+
+    public void initSystemConfig(ApplicationContext context){
+        //加载配置文件,注册订单处理侦听
+        try {
+
+            ApplicationContextFactory.setApplicationContext(context);
+
+            Properties properties = this.load(DEFAULT_EVENT_PATH,DEFAULT_FILE_NAME);
+
+            registerListener(properties);
+
+            //注册事件
+            registerEvent(properties);
+
+        }
+        catch (Exception ex) {
+            throw new IllegalStateException("system init error", ex);
+        }
+    }
+
+
+    /**
+     * 加载文件
+     * @param location
+     * @param filename
+     * @param
+     */
+    private Properties load(String location,String filename) throws Exception{
+        Properties properties = PropertiesLoaderUtils.loadProperties(new ClassPathResource(location+filename));
+        return properties;
+    }
+
+    /**
+     * 注册侦听
+     * @param properties
+     */
+    private void registerListener(Properties properties) throws Exception{
+
+        String[] listeners = properties.getProperty(DATAFLOW_LISTENER).split("\\,");
+
+        for(String listener : listeners){
+
+            //这里不能直接反射,这样 IXXXService 无法注入,所以直接从spring 中获取已经注入的
+            DataFlowListener<?> dataFlowListener = (DataFlowListener<?>) ApplicationContextFactory.getBean(listener);
+
+            //将 listener 放入 AppEventPublishing 中方便后期操作
+            //注册侦听
+            DataFlowEventPublishing.addListenner(dataFlowListener);
+        }
+    }
+
+    /**
+     * 注册事件
+     * @param properties
+     * @throws Exception
+     */
+    private void registerEvent(Properties properties) throws Exception{
+        String[] events = properties.getProperty(DISPATCH_EVENT).split("\\,");
+
+        for (String event : events){
+
+            if(StringUtils.isBlank(event) || !event.contains("::")){
+                throw new ConfigurationException("配置错误,["+DISPATCH_EVENT+"= "+events+"] 当前 [event = "+event+"],不存在 :: ,配置格式为 A::B");
+            }
+
+            String[] tmpEvent = event.split("::");
+
+            if(tmpEvent.length > 2){
+                throw new ConfigurationException("配置错误,["+DISPATCH_EVENT+"= "+events+"] 当前 [event = "+event+"],只能有一个 :: ,配置格式为 A::B");
+            }
+
+            Class clazz = Class.forName(tmpEvent[1]);
+
+            AppEventPublishing.addEvent(tmpEvent[0],clazz);
+        }
+
+    }
+
+
+}

+ 21 - 0
java110-event/src/main/java/com/java110/event/center/merchant/event/DataFlowMerchantEvent.java

@@ -0,0 +1,21 @@
+package com.java110.event.center.merchant.event;
+
+import com.java110.entity.center.DataFlow;
+import com.java110.event.center.DataFlowEvent;
+
+/**
+ * 客户事件处理
+ * Created by wuxw on 2018/4/17.
+ */
+public class DataFlowMerchantEvent extends DataFlowEvent {
+    /**
+     * Constructs a prototypical Event.
+     *
+     * @param source   The object on which the Event initially occurred.
+     * @param dataFlow
+     * @throws IllegalArgumentException if source is null.
+     */
+    public DataFlowMerchantEvent(Object source, DataFlow dataFlow) {
+        super(source, dataFlow);
+    }
+}

+ 26 - 0
java110-event/src/main/java/com/java110/event/center/merchant/listener/DataFlowMerchantListener.java

@@ -0,0 +1,26 @@
+package com.java110.event.center.merchant.listener;
+
+import com.java110.common.log.LoggerEngine;
+import com.java110.entity.center.DataFlow;
+import com.java110.event.app.order.Ordered;
+import com.java110.event.center.DataFlowListener;
+import com.java110.event.center.merchant.event.DataFlowMerchantEvent;
+import org.springframework.stereotype.Component;
+
+/**
+ * Created by wuxw on 2018/4/17.
+ */
+@Component
+public class DataFlowMerchantListener extends LoggerEngine implements DataFlowListener<DataFlowMerchantEvent>,Ordered {
+    @Override
+    public void soService(DataFlowMerchantEvent event) {
+        DataFlow dataFlow = event.getDataFlow();
+        //这里处理业务逻辑
+        logger.info("DataFlowCustListener 侦听执行");
+    }
+
+    @Override
+    public int getOrder() {
+        return 0;
+    }
+}

+ 21 - 0
java110-event/src/main/java/com/java110/event/center/user/event/DataFlowCustEvent.java

@@ -0,0 +1,21 @@
+package com.java110.event.center.user.event;
+
+import com.java110.entity.center.DataFlow;
+import com.java110.event.center.DataFlowEvent;
+
+/**
+ * 客户事件处理
+ * Created by wuxw on 2018/4/17.
+ */
+public class DataFlowCustEvent extends DataFlowEvent {
+    /**
+     * Constructs a prototypical Event.
+     *
+     * @param source   The object on which the Event initially occurred.
+     * @param dataFlow
+     * @throws IllegalArgumentException if source is null.
+     */
+    public DataFlowCustEvent(Object source, DataFlow dataFlow) {
+        super(source, dataFlow);
+    }
+}

+ 26 - 0
java110-event/src/main/java/com/java110/event/center/user/listener/DataFlowCustListener.java

@@ -0,0 +1,26 @@
+package com.java110.event.center.user.listener;
+
+import com.java110.common.log.LoggerEngine;
+import com.java110.entity.center.DataFlow;
+import com.java110.event.app.order.Ordered;
+import com.java110.event.center.DataFlowListener;
+import com.java110.event.center.user.event.DataFlowCustEvent;
+import org.springframework.stereotype.Component;
+
+/**
+ * Created by wuxw on 2018/4/17.
+ */
+@Component
+public class DataFlowCustListener extends LoggerEngine implements DataFlowListener<DataFlowCustEvent>,Ordered {
+    @Override
+    public void soService(DataFlowCustEvent event) {
+        DataFlow dataFlow = event.getDataFlow();
+        //这里处理业务逻辑
+        logger.info("DataFlowCustListener 侦听执行");
+    }
+
+    @Override
+    public int getOrder() {
+        return 0;
+    }
+}