From 675ccd51874f9c005285eab3e4829e451848b4b6 Mon Sep 17 00:00:00 2001
From: java110 <928255095@qq.com>
Date: 星期三, 07 六月 2023 11:11:29 +0800
Subject: [PATCH] Merge branch 'master' of http://git.homecommunity.cn/supervip/MicroCommunity

---
 java110-core/src/main/java/com/java110/core/event/cmd/ServiceCmdEventPublishing.java |   82 ++++++++++++++++++++++++++--------------
 1 files changed, 53 insertions(+), 29 deletions(-)

diff --git a/java110-core/src/main/java/com/java110/core/event/cmd/ServiceCmdEventPublishing.java b/java110-core/src/main/java/com/java110/core/event/cmd/ServiceCmdEventPublishing.java
index 990e21a..2267805 100644
--- a/java110-core/src/main/java/com/java110/core/event/cmd/ServiceCmdEventPublishing.java
+++ b/java110-core/src/main/java/com/java110/core/event/cmd/ServiceCmdEventPublishing.java
@@ -1,24 +1,22 @@
 package com.java110.core.event.cmd;
 
-import com.java110.core.annotation.Java110Cmd;
-import com.java110.core.context.DataFlowContext;
+import com.alibaba.fastjson.JSONObject;
 import com.java110.core.context.ICmdDataFlowContext;
 import com.java110.core.event.center.DataFlowListenerOrderComparator;
-import com.java110.core.event.service.api.ServiceDataFlowEvent;
-import com.java110.core.event.service.api.ServiceDataFlowListener;
-import com.java110.entity.center.AppService;
+import com.java110.core.factory.GenerateCodeFactory;
+import com.java110.core.log.LoggerFactory;
+import com.java110.dto.CmdListenerDto;
+import com.java110.dto.logSystemError.LogSystemErrorDto;
+import com.java110.po.logSystemError.LogSystemErrorPo;
 import com.java110.utils.constant.CommonConstant;
 import com.java110.utils.constant.ResponseConstant;
-import com.java110.utils.constant.ServiceCodeConstant;
 import com.java110.utils.exception.BusinessException;
-import com.java110.utils.exception.CmdException;
 import com.java110.utils.exception.ListenerExecuteException;
 import com.java110.utils.factory.ApplicationContextFactory;
 import com.java110.utils.log.LoggerEngine;
 import com.java110.utils.util.Assert;
+import com.java110.utils.util.ExceptionUtil;
 import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.http.HttpMethod;
 
 import java.util.ArrayList;
 import java.util.HashMap;
@@ -42,7 +40,7 @@
     /**
      * 淇濆瓨渚﹀惉瀹炰緥淇℃伅锛屼竴鑸惎鍔ㄦ椂鍔犺浇
      */
-    private static final List<String> listeners = new ArrayList<String>();
+    private static final List<CmdListenerDto> listeners = new ArrayList<CmdListenerDto>();
 
     /**
      * 鏍规嵁 浜嬩欢绫诲瀷鏌ヨ渚﹀惉
@@ -54,7 +52,7 @@
      *
      * @param listener
      */
-    public static void addListener(String listener) {
+    public static void addListener(CmdListenerDto listener) {
         listeners.add(listener);
     }
 
@@ -63,7 +61,7 @@
      *
      * @return
      */
-    public static List<String> getListeners() {
+    public static List<CmdListenerDto> getListeners() {
         return listeners;
     }
 
@@ -85,10 +83,10 @@
         }
 
         List<ServiceCmdListener> cmdListeners = new ArrayList<ServiceCmdListener>();
-        for (String listenerBeanName : getListeners()) {
-            ServiceCmdListener listener = ApplicationContextFactory.getBean(listenerBeanName, ServiceCmdListener.class);
-            Java110Cmd java110Cmd = listener.getClass().getDeclaredAnnotation(Java110Cmd.class);
-            if(java110Cmd.serviceCode().equals(serviceCode)) {
+        for (CmdListenerDto listenerBean : getListeners()) {
+            //ServiceCmdListener listener = ApplicationContextFactory.getBean(listenerBean.getBeanName(), ServiceCmdListener.class);
+            ServiceCmdListener listener = ApplicationContextFactory.getBean(listenerBean.getBeanName(), ServiceCmdListener.class);
+            if (listenerBean.getServiceCode().equals(serviceCode)) {
                 cmdListeners.add(listener);
             }
         }
@@ -110,8 +108,9 @@
      *
      * @param cmdDataFlowContext
      */
-    public static void multicastEvent(ICmdDataFlowContext cmdDataFlowContext) throws BusinessException {
+    public static void multicastEvent(ICmdDataFlowContext cmdDataFlowContext) throws Exception {
         Assert.notNull(cmdDataFlowContext.getServiceCode(), "褰撳墠娌℃湁鍙鐞嗙殑涓氬姟淇℃伅锛�");
+        //todo 鏍规嵁cmd serviceCode 鍙戝竷浜嬩欢
         multicastEvent(cmdDataFlowContext.getServiceCode(), cmdDataFlowContext, null);
     }
 
@@ -122,8 +121,8 @@
      * @param serviceCode
      * @param dataFlowContext
      */
-    public static void multicastEvent(String serviceCode, ICmdDataFlowContext dataFlowContext) throws BusinessException {
-        multicastEvent(serviceCode, dataFlowContext,  null);
+    public static void multicastEvent(String serviceCode, ICmdDataFlowContext dataFlowContext) throws Exception {
+        multicastEvent(serviceCode, dataFlowContext, null);
     }
 
     /**
@@ -132,14 +131,17 @@
      * @param serviceCode
      * @param dataFlowContext 杩欎釜璁㈠崟淇℃伅锛屼互渚夸簬 渚﹀惉閭h竟闇�瑕佺敤
      */
-    public static void multicastEvent(String serviceCode, ICmdDataFlowContext dataFlowContext, String asyn) throws BusinessException {
+    public static void multicastEvent(String serviceCode, ICmdDataFlowContext dataFlowContext, String asyn) throws Exception {
         try {
+            //todo 缁勮浜嬩欢
             CmdEvent targetDataFlowEvent = new CmdEvent(serviceCode, dataFlowContext);
 
+            //todo 鍙戝竷浜嬩欢
             multicastEvent(serviceCode, targetDataFlowEvent, asyn);
         } catch (Exception e) {
             logger.error("鍙戝竷渚﹀惉澶辫触锛屽け璐ュ師鍥犱负锛�", e);
-            throw new BusinessException(ResponseConstant.RESULT_CODE_INNER_ERROR, e.getMessage());
+            //throw new BusinessException(ResponseConstant.RESULT_CODE_INNER_ERROR, e.getMessage());
+            throw e;
         }
 
     }
@@ -151,7 +153,8 @@
      * @param event
      * @param asyn  A 琛ㄧず寮傛澶勭悊
      */
-    public static void multicastEvent(String serviceCode, final CmdEvent event, String asyn) {
+    public static void multicastEvent(String serviceCode, final CmdEvent event, String asyn) throws Exception {
+        //todo 鏍规嵁serviceCode 鍘诲鎵� 澶勭悊鐨凜md澶勭悊绫� 濡傛灉java绫讳腑 @Java110Cmd(serviceCode = "xx.xx") 鍐欎簡璇ユ敞瑙e氨浼氳瀵绘壘鍒�
         List<ServiceCmdListener> listeners = getListeners(serviceCode);
         //杩欓噷鍒ゆ柇 serviceCode + httpMethod 鐨勪睛鍚紝濡傛灉娌℃湁娉ㄥ唽鐩存帴鎶ラ敊銆�
         if (listeners == null || listeners.size() == 0) {
@@ -160,17 +163,22 @@
         }
         for (final ServiceCmdListener listener : listeners) {
 
-            if (CommonConstant.PROCESS_ORDER_ASYNCHRONOUS.equals(asyn)) { //寮傛澶勭悊
+            if (CommonConstant.PROCESS_ORDER_ASYNCHRONOUS.equals(asyn)) { //todo 寮傛澶勭悊,涓�鑸緢灏戠敤
 
                 Executor executor = getTaskExecutor();
                 executor.execute(new Runnable() {
                     @Override
                     public void run() {
-                        invokeListener(listener, event);
+                        try {
+                            invokeListener(listener, event);
+                        } catch (Exception e) {
+                            e.printStackTrace();
+                        }
                     }
                 });
                 break;
             } else {
+                // todo 閫氳繃鍚屾鐨勬柟寮忚皟鐢–MDjava绫�
                 invokeListener(listener, event);
                 break;
             }
@@ -189,19 +197,35 @@
     }
 
     /**
-     * Invoke the given listener with the given event.
+     * 鎵ц 鏍规嵁serviceCode 鎵惧埌鐨刢md 绫�
      *
      * @param listener the ApplicationListener to invoke
      * @param event    the current event to propagate
      * @since 4.1
      */
     @SuppressWarnings({"unchecked", "rawtypes"})
-    protected static void invokeListener(ServiceCmdListener listener, CmdEvent event) {
+    protected static void invokeListener(ServiceCmdListener listener, CmdEvent event) throws Exception {
         try {
-            listener.cmd(event);
-        } catch (CmdException e) {
-            LoggerEngine.error("鍙戝竷渚﹀惉澶辫触", e);
+            //todo 鑾峰彇 cmd 涓婁笅鏂囧璞�
+            ICmdDataFlowContext dataFlowContext = event.getCmdDataFlowContext();
+            //todo 鑾峰彇璇锋眰鏁版嵁
+            JSONObject reqJson = dataFlowContext.getReqJson();
+
+            logger.debug("API鏈嶅姟 --- 璇锋眰鍙傛暟涓猴細{}", reqJson.toJSONString());
+
+            //todo 璋冪敤 cmd鐨勬牎楠屾柟娉�
+            listener.validate(event, dataFlowContext, reqJson);
+
+            //todo 璋冪敤 cmd鐨勪笟鍔″鐞嗘柟娉�
+            listener.doCmd(event, dataFlowContext, reqJson);
+
+            //logger.debug("API鏈嶅姟 --- 杩斿洖鎶ユ枃淇℃伅锛歿}", dataFlowContext.getResponseEntity());
+            //   listener.cmd(event);
+        } catch (Throwable e) {
+            LoggerEngine.error("鍙戝竷渚﹀惉澶辫触" + e);
             throw e;
         }
     }
+
+
 }

--
Gitblit v1.8.0