Parcourir la source

调整菜单顺序

吴学文 il y a 6 ans
Parent
commit
16c93edeaf

+ 60 - 55
Api/src/main/java/com/java110/api/listener/menu/QueryMenuServiceListener.java

@@ -39,6 +39,7 @@ public class QueryMenuServiceListener extends AbstractServiceApiDataFlowListener
 
     /**
      * 业务处理
+     *
      * @param event
      */
     @Override
@@ -46,30 +47,30 @@ public class QueryMenuServiceListener extends AbstractServiceApiDataFlowListener
         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 @@ public class QueryMenuServiceListener extends AbstractServiceApiDataFlowListener
 
     /**
      * 根据用户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 @@ public class QueryMenuServiceListener extends AbstractServiceApiDataFlowListener
     /**
      * 刷新菜单信息
      * 将 数据 [{
-     "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);
             }
         }

+ 6 - 6
WebService/src/main/java/com/java110/web/components/MenuComponent.java

@@ -1,6 +1,5 @@
 package com.java110.web.components;
 
-import com.alibaba.fastjson.JSONArray;
 import com.java110.core.context.IPageData;
 import com.java110.web.smo.IMenuServiceSMO;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -20,9 +19,10 @@ public class MenuComponent {
 
     /**
      * 测试版本号
+     *
      * @return
      */
-    public ResponseEntity<String> getMenus(IPageData pd){
+    public ResponseEntity<String> getMenus(IPageData pd) {
 
        /* String menuData = "[{'id':1,'icon':'fa-desktop','name':'我的菜单','label':'HOT','childs':[" +
                 "{'name':'子菜单','href':'http://www.baidu.com'}]}," +
@@ -36,11 +36,11 @@ public class MenuComponent {
 
         */
         ResponseEntity<String> responseEntity = null;
-        try{
-            responseEntity =  menuServiceSMOImpl.queryMenusByUserId(pd);
-        }catch (Exception e){
+        try {
+            responseEntity = menuServiceSMOImpl.queryMenusByUserId(pd);
+        } catch (Exception e) {
             responseEntity = new ResponseEntity<String>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
-        }finally {
+        } finally {
             return responseEntity;
         }
     }

+ 1 - 1
WebService/src/main/java/com/java110/web/smo/IMenuServiceSMO.java

@@ -12,6 +12,6 @@ public interface IMenuServiceSMO {
      * 根据用户查菜单
      * @return
      */
-    public ResponseEntity<String> queryMenusByUserId(IPageData pd);
+     ResponseEntity<String> queryMenusByUserId(IPageData pd);
 
 }

+ 3 - 4
WebService/src/main/java/com/java110/web/smo/impl/MenuServiceSMOImpl.java

@@ -30,7 +30,6 @@ public class MenuServiceSMOImpl extends BaseComponentSMO implements IMenuService
 
 
     /**
-     *
      * @param pd
      * @return
      */
@@ -38,10 +37,10 @@ public class MenuServiceSMOImpl extends BaseComponentSMO implements IMenuService
     public ResponseEntity<String> queryMenusByUserId(IPageData pd) {
         ResponseEntity<String> responseEntity = null;
 
-        Assert.hasLength(pd.getUserId(),"用户还没有登录");
+        Assert.hasLength(pd.getUserId(), "用户还没有登录");
 
-        responseEntity = this.callCenterService(restTemplate,pd,"",
-                ServiceConstant.SERVICE_API_URL+"/api/query.menu.info?userId="+pd.getUserId(), HttpMethod.GET);
+        responseEntity = this.callCenterService(restTemplate, pd, "",
+                ServiceConstant.SERVICE_API_URL + "/api/query.menu.info?userId=" + pd.getUserId(), HttpMethod.GET);
         return responseEntity;
     }