Kaynağa Gözat

订单服务核心 加入商户处理侦听类

wuxw 7 yıl önce
ebeveyn
işleme
149c1bc2d1

+ 48 - 0
OrderService/src/main/java/com/java110/order/listener/ResponseStoreIdFromSaveStoreInfoListener.java

@@ -0,0 +1,48 @@
+package com.java110.order.listener;
+
+import com.alibaba.fastjson.JSONObject;
+import com.java110.common.constant.BusinessTypeConstant;
+import com.java110.core.annotation.Java110Listener;
+import com.java110.entity.order.Business;
+import com.java110.event.app.order.Ordered;
+import com.java110.event.center.event.InvokeBusinessBSuccessEvent;
+import com.java110.event.center.listener.DataFlowListener;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ *
+ * 处理商户服务返回未将storeId 返回出去问题
+ * Created by Administrator on 2019/3/30.
+ */
+@Java110Listener(name = "responseStoreIdFromSaveStoreInfoListener")
+public class ResponseStoreIdFromSaveStoreInfoListener implements DataFlowListener<InvokeBusinessBSuccessEvent>,Ordered {
+
+    private final static Logger logger = LoggerFactory.getLogger(ResponseStoreIdFromSaveStoreInfoListener.class);
+
+    @Override
+    public int getOrder() {
+        return 1;
+    }
+
+    @Override
+    public void soService(InvokeBusinessBSuccessEvent event) {
+
+        Business business = event.getBusiness();
+        if(!BusinessTypeConstant.BUSINESS_TYPE_SAVE_STORE_INFO.equals(business.getBusinessTypeCd())){
+            return ;
+        }
+
+        JSONObject businessResponseData = event.getBusinessResponseData();
+
+        if(!businessResponseData.containsKey("storeId")) {
+            return;
+        }
+
+        JSONObject storeInfo = new JSONObject();
+        storeInfo.put("storeId",businessResponseData.getString("storeId"));
+        event.getDataFlow().getResJson().getJSONArray("msg").add(storeInfo);
+
+
+    }
+}

+ 7 - 7
OrderService/src/main/java/com/java110/order/smo/impl/OrderServiceSMOImpl.java

@@ -111,7 +111,7 @@ public class OrderServiceSMOImpl implements IOrderServiceSMO {
         } finally {
 
             if(responseEntity == null){
-                responseEntity = new ResponseEntity<String>(dataFlow.getResJson().getString("msg"),OrderDataFlowContextFactory.hashMap2MultiValueMap(dataFlow.getResHeaders()),HttpStatus.OK);
+                responseEntity = new ResponseEntity<String>(dataFlow.getResJson().getJSONArray("msg").toJSONString(),OrderDataFlowContextFactory.hashMap2MultiValueMap(dataFlow.getResHeaders()),HttpStatus.OK);
             }
             if(dataFlow != null) {
                 //添加耗时
@@ -136,11 +136,11 @@ public class OrderServiceSMOImpl implements IOrderServiceSMO {
      */
     private void refreshOrderDataFlowResJson(IOrderDataFlowContext dataFlow){
 
-        if(dataFlow.getResJson() == null || dataFlow.getResJson().isEmpty()){
-            JSONObject resJson = new JSONObject();
-            resJson.put("msg","成功");
-            dataFlow.setResJson(resJson);
-        }
+//        if(dataFlow.getResJson() == null || dataFlow.getResJson().isEmpty()){
+//            JSONObject resJson = new JSONObject();
+//            resJson.put("msg","成功");
+//            dataFlow.setResJson(resJson);
+//        }
 
     }
 
@@ -959,7 +959,7 @@ public class OrderServiceSMOImpl implements IOrderServiceSMO {
             JSONObject responseJson = doRequestBusinessSystem(dataFlow, serviceBusiness, requestBusinessJson);
 
             //发布事件
-            DataFlowEventPublishing.invokeBusinessBSuccess(dataFlow,business);
+            DataFlowEventPublishing.invokeBusinessBSuccess(dataFlow,business,responseJson);
 
             responseBusinesses.add(responseJson);
 

+ 12 - 0
java110-core/src/main/java/com/java110/core/context/OrderDataFlow.java

@@ -81,6 +81,9 @@ public class OrderDataFlow extends AbstractOrderDataFlowContext {
         //构建返回头
         builderResHeaders();
 
+        //构建返回json 为{"msg":[]}
+        builderResJson();
+
         //构建 订单信息
         builderOrders();
 
@@ -214,6 +217,15 @@ public class OrderDataFlow extends AbstractOrderDataFlowContext {
         }
     }
 
+    /**
+     * 初始化构建返回报文
+     */
+    private void builderResJson(){
+        JSONObject resJson = new JSONObject();
+        resJson.put("msg",new JSONArray());
+        this.setResJson(resJson);
+    }
+
 
     public Orders getOrders() {
         return orders;

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

@@ -1,5 +1,6 @@
 package com.java110.event.center;
 
+import com.alibaba.fastjson.JSONObject;
 import com.java110.common.constant.CommonConstant;
 import com.java110.common.exception.BusinessException;
 import com.java110.common.factory.ApplicationContextFactory;
@@ -252,6 +253,16 @@ public class DataFlowEventPublishing extends LoggerEngine {
         multicastEvent(new InvokeBusinessSystemEvent("",dataFlow));
     }
 
+
+    /**
+     * 调用业务系统成功后事件
+     * @param dataFlow
+     * @param business 成功的事件业务数据封装对象
+     */
+    public static void invokeBusinessBSuccess(IOrderDataFlowContext dataFlow, Business business, JSONObject businessResponseData){
+        multicastEvent(new InvokeBusinessBSuccessEvent("",dataFlow,business,businessResponseData));
+    }
+
     /**
      * 调用业务系统成功后事件
      * @param dataFlow

+ 28 - 0
java110-event/src/main/java/com/java110/event/center/event/InvokeBusinessBSuccessEvent.java

@@ -1,5 +1,6 @@
 package com.java110.event.center.event;
 
+import com.alibaba.fastjson.JSONObject;
 import com.java110.core.context.IOrderDataFlowContext;
 import com.java110.core.context.OrderDataFlow;
 import com.java110.entity.order.Business;
@@ -12,6 +13,25 @@ public class InvokeBusinessBSuccessEvent extends DataFlowEvent {
 
     private Business business;
 
+    /**
+     * 业务系统返回数据
+     */
+    private JSONObject businessResponseData;
+
+
+    /**
+     * Constructs a prototypical Event.
+     *
+     * @param source   The object on which the Event initially occurred.
+     * @param dataFlow
+     * @throws IllegalArgumentException if source is null.
+     */
+    public InvokeBusinessBSuccessEvent(Object source, IOrderDataFlowContext dataFlow, Business business,JSONObject businessResponseData) {
+        super(source, dataFlow);
+        this.business = business;
+        this.businessResponseData = businessResponseData;
+    }
+
     /**
      * Constructs a prototypical Event.
      *
@@ -27,4 +47,12 @@ public class InvokeBusinessBSuccessEvent extends DataFlowEvent {
     public Business getBusiness() {
         return business;
     }
+
+    /**
+     * 获取业务数据
+     * @return
+     */
+    public JSONObject getBusinessResponseData() {
+        return businessResponseData;
+    }
 }