From f39cd4d82c3952f8587ebff9a7e8ede73b46bcda Mon Sep 17 00:00:00 2001
From: wuxw <928255095@qq.com>
Date: 星期四, 30 五月 2019 00:40:32 +0800
Subject: [PATCH] Merge branch 'master' of https://github.com/java110/MicroCommunity

---
 Api/src/main/java/com/java110/api/listener/menu/QueryMenuServiceListener.java |  115 ++++++++++++++++++++++++++++++---------------------------
 1 files changed, 60 insertions(+), 55 deletions(-)

diff --git a/Api/src/main/java/com/java110/api/listener/menu/QueryMenuServiceListener.java b/Api/src/main/java/com/java110/api/listener/menu/QueryMenuServiceListener.java
index 2cf38e3..df69bfd 100644
--- a/Api/src/main/java/com/java110/api/listener/menu/QueryMenuServiceListener.java
+++ b/Api/src/main/java/com/java110/api/listener/menu/QueryMenuServiceListener.java
@@ -39,6 +39,7 @@
 
     /**
      * 涓氬姟澶勭悊
+     *
      * @param event
      */
     @Override
@@ -46,30 +47,30 @@
         DataFlowContext dataFlowContext = event.getDataFlowContext();
         AppService service = event.getAppService();
         //get 鏂瑰紡涓� 璇锋眰鍙傛暟浼氳浆鍖栧埌header 涓�
-        Map<String,String> requestHeaders = dataFlowContext.getRequestHeaders();
-        Assert.hasKey(requestHeaders,"userId","璇锋眰淇℃伅涓湭鍖呭惈userId淇℃伅");
+        Map<String, String> requestHeaders = dataFlowContext.getRequestHeaders();
+        Assert.hasKey(requestHeaders, "userId", "璇锋眰淇℃伅涓湭鍖呭惈userId淇℃伅");
 
         String userId = requestHeaders.get("userId");
         //鏍规嵁鐢ㄦ埛鏌ヨ 鍟嗘埛绫�
-        String domain = queryStoreTypeCd(dataFlowContext,userId);
-        domain = StringUtil.isEmpty(domain)?"-1":domain;
-        ResponseEntity responseEntity= null;
-        String requestUrl = service.getUrl() + "?userId="+userId+"&domain="+domain;
-        dataFlowContext.getRequestHeaders().put("REQUEST_URL",requestUrl);
+        String domain = queryStoreTypeCd(dataFlowContext, userId);
+        domain = StringUtil.isEmpty(domain) ? "-1" : domain;
+        ResponseEntity responseEntity = null;
+        String requestUrl = service.getUrl() + "?userId=" + userId + "&domain=" + domain;
+        dataFlowContext.getRequestHeaders().put("REQUEST_URL", requestUrl);
         HttpHeaders header = new HttpHeaders();
-        header.add(CommonConstant.HTTP_SERVICE.toLowerCase(),ServiceCodeConstant.SERVICE_CODE_QUERY_MENU_INFO);
+        header.add(CommonConstant.HTTP_SERVICE.toLowerCase(), ServiceCodeConstant.SERVICE_CODE_QUERY_MENU_INFO);
         HttpEntity<String> httpEntity = new HttpEntity<String>("", header);
-        doRequest(dataFlowContext,service,httpEntity);
+        doRequest(dataFlowContext, service, httpEntity);
         responseEntity = dataFlowContext.getResponseEntity();
         //濡傛灉璋冪敤鍚庣澶辫触浜� 鍒欑洿鎺ヨ繑鍥�
-        if(responseEntity.getStatusCode() != HttpStatus.OK){
-            return ;
+        if (responseEntity.getStatusCode() != HttpStatus.OK) {
+            return;
         }
 
         JSONObject resultObj = JSONObject.parseObject(responseEntity.getBody().toString());
 
-        if(!resultObj.containsKey("menus")){
-            return ;
+        if (!resultObj.containsKey("menus")) {
+            return;
         }
 
         dataFlowContext.setResponseEntity(refreshMenusInfo(resultObj.getJSONArray("menus")));
@@ -78,26 +79,27 @@
 
     /**
      * 鏍规嵁鐢ㄦ埛ID鏌ヨ鍟嗘埛淇℃伅
+     *
      * @param dataFlowContext
      * @param userId
      * @return
      */
-    private String queryStoreTypeCd(DataFlowContext dataFlowContext,String userId){
-        ResponseEntity responseEntity= null;
+    private String queryStoreTypeCd(DataFlowContext dataFlowContext, String userId) {
+        ResponseEntity responseEntity = null;
         AppService appService = DataFlowFactory.getService(dataFlowContext.getAppId(), ServiceCodeConstant.SERVICE_CODE_QUERY_STORE_BYUSER);
-        if(appService == null){
-            responseEntity = new ResponseEntity<String>("褰撳墠娌℃湁鏉冮檺璁块棶"+ServiceCodeConstant.SERVICE_CODE_QUERY_USER_LOGIN,HttpStatus.UNAUTHORIZED);
+        if (appService == null) {
+            responseEntity = new ResponseEntity<String>("褰撳墠娌℃湁鏉冮檺璁块棶" + ServiceCodeConstant.SERVICE_CODE_QUERY_USER_LOGIN, HttpStatus.UNAUTHORIZED);
             dataFlowContext.setResponseEntity(responseEntity);
             return "";
         }
-        String requestUrl = appService.getUrl() + "?userId="+userId;
+        String requestUrl = appService.getUrl() + "?userId=" + userId;
         HttpHeaders header = new HttpHeaders();
-        header.add(CommonConstant.HTTP_SERVICE.toLowerCase(),ServiceCodeConstant.SERVICE_CODE_QUERY_STORE_BYUSER);
+        header.add(CommonConstant.HTTP_SERVICE.toLowerCase(), ServiceCodeConstant.SERVICE_CODE_QUERY_STORE_BYUSER);
         HttpEntity<String> httpEntity = new HttpEntity<String>("", header);
-        doRequest(dataFlowContext,appService,httpEntity);
+        doRequest(dataFlowContext, appService, httpEntity);
         responseEntity = dataFlowContext.getResponseEntity();
 
-        if(responseEntity.getStatusCode() != HttpStatus.OK){
+        if (responseEntity.getStatusCode() != HttpStatus.OK) {
             dataFlowContext.setResponseEntity(responseEntity);
         }
 
@@ -107,62 +109,65 @@
     /**
      * 鍒锋柊鑿滃崟淇℃伅
      * 灏� 鏁版嵁 [{
-     "gId": "800201904001",
-     "menuDescription": "娣诲姞鍛樺伐",
-     "menuGroupSeq": 1,
-     "menuSeq": 1,
-     "icon": "fa-desktop",
-     "mId": "700201904001",
-     "menuName": "娣诲姞鍛樺伐",
-     "pId": "500201904001",
-     "menuGroupName": "鍛樺伐绠$悊",
-     "label": "",
-     "menuGroupDescription": "鍛樺伐绠$悊",
-     "url": "/"
-     }],
-     杞负锛�
+     * "gId": "800201904001",
+     * "menuDescription": "娣诲姞鍛樺伐",
+     * "menuGroupSeq": 1,
+     * "menuSeq": 1,
+     * "icon": "fa-desktop",
+     * "mId": "700201904001",
+     * "menuName": "娣诲姞鍛樺伐",
+     * "pId": "500201904001",
+     * "menuGroupName": "鍛樺伐绠$悊",
+     * "label": "",
+     * "menuGroupDescription": "鍛樺伐绠$悊",
+     * "url": "/"
+     * }],
+     * 杞负锛�
      * "[{'id':1,'icon':'fa-desktop','name':'鎴戠殑鑿滃崟','label':'HOT','childs':[" +
-     "{'name':'瀛愯彍鍗�','href':'http://www.baidu.com'}]}," +
-     "{'id':2,'icon':'fa-flask','name':'鎴戠殑鑿滃崟','childs':[],'href':'/doc'}," +
-     "{'id':3,'icon':'fa-globe','name':'鎴戠殑鑿滃崟','childs':[{'name':'瀛愯彍鍗�','href':'http://www.baidu.com'}]}" +
-     "]";
-     * @param menusList 鑿滃崟鍒楄〃
+     * "{'name':'瀛愯彍鍗�','href':'http://www.baidu.com'}]}," +
+     * "{'id':2,'icon':'fa-flask','name':'鎴戠殑鑿滃崟','childs':[],'href':'/doc'}," +
+     * "{'id':3,'icon':'fa-globe','name':'鎴戠殑鑿滃崟','childs':[{'name':'瀛愯彍鍗�','href':'http://www.baidu.com'}]}" +
+     * "]";
      *
+     * @param menusList 鑿滃崟鍒楄〃
      * @return
      */
-    private ResponseEntity<String> refreshMenusInfo(JSONArray menusList){
+    private ResponseEntity<String> refreshMenusInfo(JSONArray menusList) {
         JSONArray tempMenus = new JSONArray();
         JSONObject tempMenu = null;
-        for(int menuIndex = 0 ; menuIndex < menusList.size(); menuIndex ++){
+        for (int menuIndex = 0; menuIndex < menusList.size(); menuIndex++) {
             JSONObject tMenu = menusList.getJSONObject(menuIndex);
-            tempMenu = this.getMenuFromMenus(tempMenus,tMenu.getString("gId"));
-            if(tempMenu == null){
+            tempMenu = this.getMenuFromMenus(tempMenus, tMenu.getString("gId"));
+            if (tempMenu == null) {
                 tempMenu = new JSONObject();
-                tempMenu.put("id",tMenu.getString("gId"));
-                tempMenu.put("icon",tMenu.getString("icon"));
-                tempMenu.put("name",tMenu.getString("menuGroupName"));
-                tempMenu.put("label",tMenu.getString("label"));
-                tempMenu.put("childs",new JSONArray());
+                tempMenu.put("id", tMenu.getString("gId"));
+                tempMenu.put("icon", tMenu.getString("icon"));
+                tempMenu.put("name", tMenu.getString("menuGroupName"));
+                tempMenu.put("label", tMenu.getString("label"));
+                tempMenu.put("seq", tMenu.getString("menuGroupSeq"));
+                tempMenu.put("childs", new JSONArray());
                 tempMenus.add(tempMenu);
             }
             //鑾峰彇瀛╁瓙鑿滃崟
             JSONArray childs = tempMenu.getJSONArray("childs");
             JSONObject childMenu = new JSONObject();
-            childMenu.put("name",tMenu.getString("menuName"));
-            childMenu.put("href",tMenu.getString("url"));
+            childMenu.put("name", tMenu.getString("menuName"));
+            childMenu.put("href", tMenu.getString("url"));
+            childMenu.put("seq", tMenu.getString("menuSeq"));
             childs.add(childMenu);
         }
-        return new ResponseEntity<String>(tempMenus.toJSONString(),HttpStatus.OK);
+        return new ResponseEntity<String>(tempMenus.toJSONString(), HttpStatus.OK);
     }
 
     /**
      * 鍦ㄨ彍鍗曞垪琛ㄦ煡璇㈣彍鍗�
+     *
      * @param gId
      * @return
      */
-    private JSONObject getMenuFromMenus(JSONArray tempMenus,String gId){
-        for(int tempIndex = 0 ; tempIndex < tempMenus.size();tempIndex ++){
-            if(tempMenus.getJSONObject(tempIndex).getString("id").equals(gId)){
+    private JSONObject getMenuFromMenus(JSONArray tempMenus, String gId) {
+        for (int tempIndex = 0; tempIndex < tempMenus.size(); tempIndex++) {
+            if (tempMenus.getJSONObject(tempIndex).getString("id").equals(gId)) {
                 return tempMenus.getJSONObject(tempIndex);
             }
         }

--
Gitblit v1.8.0