Iteration mode: (for tree structure construction)

 

Iteration mode: (for tree structure construction)

Iteration is the step-by-step entry of the "V" shape, entering the bottom layer, and the rest of the code is executed, and the step-by-step feature (similar to the entry of debugging breakpoints, and the execution will jump out, at the entry point

Continue down), when using iteration, you should set the conditions for not calling iterations when you start to iterate on a specific business. As long as the condition for not calling once is reached, it will return to the original path.

 A(){

 ....

 busnis0();

    B();

 }

 

B(){

if(..!=null){

 

business();

   B();

busnis2(); business processing during iteration can be placed before/after calling again

}

 

}

When the following example builds the tree, (you can build the tree directly with sql)

The business in A is the same as that in B, except that A is the root node, and this introduction is used to call the iteration (that is, the introduction of the iteration, in most cases, the business is the same as the business method in the iteration, and it is only used as an introduction)

 

 

 // accumulate the variables in the iteration

  List a(){

   List b;

    b.add();// This business is obtained

    return b.add(a());// Sub-business acquisition

  }//In this way, the return of this + child is realized every time to achieve superposition

 

=========================================================

//Build 1 for tree structure data, you can directly use sql, 2, use Java coding, if the traversal of the tree structure from different tables is organized in Java (the folder comes from a table, the page comes from a table)

   1. The database establishes a public root, and then traverses it level by level. When traversing, consider the level-by-level traversal and also consider the cross-level (series spanning connection). In this case, consider the cross-level first. Data organization for special cases, then consider normal step-by-step traversal

   2. If you use sql to process tables from different sources, you only need to associate them (the tree structure itself must be connected by itself), but the association relationship between cross-level sql is complicated, and it is not recommended to use it.

   可以两种结合,sql查出逐级的,剩下的跨级的用java再去完善(跨级的也就是省略了同一种类型(来源同一张表)的级数(比如少了级文件夹))

   在实体设计的时候就要考虑跨级数据的承接字段,比如这里的文件夹中表中有

 

 

 

 public MenuFolderDTO getMenuFolderByRoot(int level, String roleCurId)

  {

    MenuFolderDTO dto = null;

    MenuFolder localObject1 = this.menuItemDao.findMenuFolderById("100000");最大的根节点,注意查的是opm_menufolder这张表

    if (localObject1 != null)永远不为空

    {

      dto = new MenuFolderDTO(localObject1);

      Set menuItemSet = localObject1.getMenuItems()这里虽然文件夹表没有页面的字段,但是是通过关联查出的;根节点找不到页面,之后根节点100000下一级的节点(是文件夹(菜单中的最外层)140000),

      这个最外层下还有一个节点(我们菜单在的第二层140300),从这个第二层才可以查到菜页面140301,到了页面才可以找到按钮14030101

      if ((menuItemSet != null) && (menuItemSet.size() > 0))最大的根节点没有页面,即检查每个文件夹否有直接有页面,有的话 把页面直接遍历出,没有的话再检查有没有文件夹

      {

        List menuItemDTOList = new ArrayList();

        for (Iterator menuItemIt = menuItemSet.iterator(); menuItemIt.hasNext();)

        {

          MenuItemDTO menuItemDTO = new MenuItemDTO((MenuItem)menuItemIt.next());

          if (level < 0)

          {

            if (menuItemDTO.getLevel1() >= level)

            {

              menuItemDTO.setRoleDetailArray(getStringToArray(menuItemDTO.getRoleDetail()));

              List menuItemLimitList = this.menuItemLimitDao.getMenuItemLimitByTJ(menuItemDTO.getId(), null);

              if ((menuItemLimitList != null) && (menuItemLimitList.size() > 0))

              {

                List menuItemLimitDTOList = new ArrayList();

                for (Iterator menuItemLimitIt = menuItemLimitList.iterator(); menuItemLimitIt.hasNext();)

                {

                  MenuItemLimitDTO menuItemLimitDTO = new MenuItemLimitDTO((MenuItemLimit)menuItemLimitIt.next());

                  menuItemLimitDTOList.add(menuItemLimitDTO);

                }

                menuItemDTO.setMenuItemLimitDTOList(menuItemLimitDTOList);

              }

              menuItemDTOList.add(menuItemDTO);

            }

          }

          else

          {

            List menuItemRoleLimitCurList1 = this.roleLimitDao.getRoleLimitByTJ(menuItemDTO.getId(), null, roleCurId, Integer.valueOf(-1));

            if ((menuItemRoleLimitCurList1 != null) && (menuItemRoleLimitCurList1.size() > 0) && 

              (menuItemDTO.getLevel1() >= level))

            {

              menuItemDTO.setRoleDetailArray(getStringToArray(menuItemDTO.getRoleDetail()));

              List menuItemLimitList = this.menuItemLimitDao.getMenuItemLimitByTJ(menuItemDTO.getId(), null);

              if ((menuItemLimitList != null) && (menuItemLimitList.size() > 0))

              {

                List menuItemLimitDTOList = new ArrayList();

                for (Iterator menuItemLimitIt = menuItemLimitList.iterator(); menuItemLimitIt.hasNext();)

                {

                  MenuItemLimitDTO menuItemLimitDTO = new MenuItemLimitDTO((MenuItemLimit)menuItemLimitIt.next());

                  List menuItemRoleLimitCurList2 = this.roleLimitDao.getRoleLimitByTJ(menuItemDTO.getId(), menuItemLimitDTO.getId(), roleCurId, null);

                  if ((menuItemRoleLimitCurList2 != null) && (menuItemRoleLimitCurList2.size() > 0)) {

                    menuItemLimitDTOList.add(menuItemLimitDTO);

                  }

                }

                menuItemDTO.setMenuItemLimitDTOList(menuItemLimitDTOList);

              }

              menuItemDTOList.add(menuItemDTO);

            }

          }

        }

        dto.setMenuItemDTOList(menuItemDTOList);跨级的页面

      }目前这种结构永远为空,这个可以留着防止后面直接在根节点下建立页面(上面这里就是跨级的处理)

      List<MenuFolderDTO> dtoList = getChildrenMenu(level, localObject1, roleCurId);

      dto.setMenuFolderDTOList(dtoList);没有跨级的文件夹

    }

    return dto;

  }

 

 

  private List getChildrenMenu(int level, MenuFolder menuFolder, String roleCurId)当前用户的,localObject1=最大的根节点

  {

    List<MenuFolderDTO> dtoList = new ArrayList();

    Set set = menuFolder.getChildFolders();文件夹中的子文件夹,这里用迭代,这里第一次获取的是每个菜单,最外层的文件夹

    Iterator it;

    if ((set != null) && (set.size() > 0)) {

      for (it = set.iterator(); it.hasNext();)

      {

        MenuFolder son = (MenuFolder)it.next();

        MenuFolderDTO dto = new MenuFolderDTO(son);

        Set menuItemSet = son.getMenuItems();

        if ((menuItemSet != null) && (menuItemSet.size() > 0))在是最外层的时候还是空,知道迭代到第二层,流着这种也是防止最外层下直接放页面(特殊处理跨级)

        {

          List menuItemDTOList = new ArrayList();

          for (Iterator menuItemIt = menuItemSet.iterator(); menuItemIt.hasNext();)

          {

            MenuItemDTO menuItemDTO = new MenuItemDTO((MenuItem)menuItemIt.next());

            if (level < 0)

            {

              if (menuItemDTO.getLevel1() >= level)

              {

                menuItemDTO.setRoleDetailArray(getStringToArray(menuItemDTO.getRoleDetail()));

                List menuItemLimitList = this.menuItemLimitDao.getMenuItemLimitByTJ(menuItemDTO.getId(), null);

                if ((menuItemLimitList != null) && (menuItemLimitList.size() > 0))

                {

                  List menuItemLimitDTOList = new ArrayList();

                  for (Iterator menuItemLimitIt = menuItemLimitList.iterator(); menuItemLimitIt.hasNext();)

                  {

                    MenuItemLimitDTO menuItemLimitDTO = new MenuItemLimitDTO((MenuItemLimit)menuItemLimitIt.next());

                    menuItemLimitDTOList.add(menuItemLimitDTO);

                  }

                  menuItemDTO.setMenuItemLimitDTOList(menuItemLimitDTOList);

                }

                menuItemDTOList.add(menuItemDTO);

              }

            }

            else

            {

              List menuItemRoleLimitCurList1 = this.roleLimitDao.getRoleLimitByTJ(menuItemDTO.getId(), null, roleCurId, Integer.valueOf(-1));

              if ((menuItemRoleLimitCurList1 != null) && (menuItemRoleLimitCurList1.size() > 0) && 

                (menuItemDTO.getLevel1() >= level))

              {

                menuItemDTO.setRoleDetailArray(getStringToArray(menuItemDTO.getRoleDetail()));

                List menuItemLimitList = this.menuItemLimitDao.getMenuItemLimitByTJ(menuItemDTO.getId(), null);

                if ((menuItemLimitList != null) && (menuItemLimitList.size() > 0))

                {

                  List menuItemLimitDTOList = new ArrayList();

                  for (Iterator menuItemLimitIt = menuItemLimitList.iterator(); menuItemLimitIt.hasNext();)

                  {

                    MenuItemLimitDTO menuItemLimitDTO = new MenuItemLimitDTO((MenuItemLimit)menuItemLimitIt.next());

                    List menuItemRoleLimitCurList2 = this.roleLimitDao.getRoleLimitByTJ(menuItemLimitDTO.getMenuItemId(), menuItemLimitDTO.getId(), roleCurId, null);

                    if ((menuItemRoleLimitCurList2 != null) && (menuItemRoleLimitCurList2.size() > 0)) {

                      menuItemLimitDTOList.add(menuItemLimitDTO);

                    }

                  }

                  menuItemDTO.setMenuItemLimitDTOList(menuItemLimitDTOList);

                }

                menuItemDTOList.add(menuItemDTO);

              }

            }

          }

          dto.setMenuItemDTOList(menuItemDTOList);

        }

        List<MenuFolderDTO> sonList = getChildrenMenu(level, son, roleCurId);//迭代是“V”字形的逐级进入,进到最底层,和剩余代码执行完,逐级出来的特性(类似调试断点的进入,和执行完才跳出,在进入处

继续向下),使用迭代的时候应该在开始迭代具体业务的时候,设置不再调用迭代的条件,只要达到一次不调用条件,就会原路返回

        dto.setMenuFolderDTOList(sonList);

        if (((dto.getMenuItemDTOList() != null) && (dto.getMenuItemDTOList().size() > 0)) || ((sonList != null) && (sonList.size() > 0))) {

          dtoList.add(dto);

        }

      }

    }

    return dtoList;

  }

 

一些业务说明:

 opm_menufolder  <li treedataindex="141" outlinelevel="1" folderurl="/rtmp-portal/menuFolderAction.action?menuFolderId=110000" menufoldername="系统管理" class="l-last "><li treedataindex="142" outlinelevel="2" folderurl="/rtmp-portal/menuFolderAction.action?menuFolderId=110200" menufoldername="权限管理" class="l-first "><div class="l-body"><div class="l-box"></div><div class="l-box l-expandable-open"></div><div class="l-box l-tree-icon l-tree-icon-folder-open"></div><span>权限管理</span></div><ul class="l-children" style="display: block;"><li treedataindex="143" outlinelevel="3" menuitemname="市场维护" url="/rtmp-portal/organAction.action?parentId=100000&amp;menuitemId=110201" class="l-first "><div class="l-body"><div class="l-box"></div><div class="l-box l-line"></div><div class="l-box l-note"></div><div class="l-box l-tree-icon l-tree-icon-leaf "></div><span>市场维护</span></div></li><li treedataindex="144" outlinelevel="3" menuitemname="角色维护" url="/rtmp-portal/roleAction.action?menuitemId=110202" class=""><div class="l-body"><div class="l-box"></div><div class="l-box l-line"></div><div class="l-box l-note"></div><div class="l-box l-tree-icon l-tree-icon-leaf "></div><span>角色维护</span></div></li><li treedataindex="145" outlinelevel="3" menuitemname="用户维护" url="/rtmp-portal/userAction.action?menuitemId=110203" class=""><div class="l-body"><div class="l-box"></div><div class="l-box l-line"></div><div class="l-box l-note"></div><div class="l-box l-tree-icon l-tree-icon-leaf "></div><span>用户维护</span></div></li><li treedataindex="146" outlinelevel="3" menuitemname="在线用户" url="/rtmp-portal/userAction!online.action?menuitemId=110204" class="l-last "><div class="l-body"><div class="l-box"></div><div class="l-box l-line"></div><div class="l-box l-note-last"></div><div class="l-box l-tree-icon l-tree-icon-leaf "></div><span>在线用户</span></div></li></ul></li>

opm_menuitem   这个是权限表(页面)  <li treedataindex="146" outlinelevel="3" menuitemname="在线用户" url="/rtmp-portal/userAction!online.action?menuitemId=110204" class="l-last "><div class="l-body l-selected"><div class="l-box"></div><div class="l-box l-line"></div><div class="l-box l-note-last"></div><div class="l-box l-tree-icon l-tree-icon-leaf "></div><span>在线用户</span></div></li>

opm_menuitemlimit 操作按钮 

select * from opm_menufolder t(文件夹(包括多个页面的文件夹))

dubbo服务的随机调用,不遵守原子性,比例进入了你的control方法不一定,等到跳转的时候会用该服务器的页面,可能会用到其他服务器的页面

 

文件夹和页面关联,,,关系维护在多方(页面)menuFolderID

在opm_menuitemlimit 中,通过menuItemId和页面一对一关联(相当于多对多的中间关联表)(把关联的字段放在下级)

根节点找不到页面,之后根节点100000下一级的节点(是文件夹(菜单中的最外层)140000),

      这个最外层下还有一个节点(我们菜单在的第二层140300),从这个第二层才可以查到菜页面140301,到了页面才可以找到按钮14030101

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326550897&siteId=291194637