vue版本机构数据量较大时,/sys/office/treeData 接口响应慢优化

分享 未结 精帖 0 381
Baymax
Baymax VIP3 2020-05-11 20:21:54   最后修改:2020-05-23 12:16:10
收藏
1、在com.jeeplus.modules.sys.entity.Office中添加字段:hasChild [pre] private boolean hasChild; //为了减少遍历次数 public boolean isHasChild() { return hasChild; } public void setHasChild(boolean hasChild) { this.hasChild = hasChild; } [/pre] 2.在OfficeMapper.xml的<sql id="officeColumns">中加入: [pre] ((SELECT count(*) FROM sys_office x WHERE x.parent_id=a.id)>0) AS "hasChild", [/pre] 参考下图位置: img[/userfiles/fly/6fe70fe5ef53494bbd455d4366dd3bb9/files/1589199556192.] 3.修改OfficeController中的getChildOfTree方法,修改为 [pre] private Office getChildOfTree(Office officeItem, List<Office> officeList, String extId, String type, Long grade, Boolean isAll) { officeItem.setChildren(Lists.newArrayList()); if("2".equals(type) && officeItem.getType().equals("1")){ officeItem.setDisabled(true); }else { officeItem.setDisabled(false); } for (Office child : officeList) { if ((StringUtils.isBlank(extId) || (extId!=null && !extId.equals(child.getId()) && child.getParentIds().indexOf(","+extId+",")==-1)) && (type == null || (type != null && (type.equals("1") ? type.equals(child.getType()) : true))) && (grade == null || (grade != null && Integer.parseInt(child.getGrade()) <= grade.intValue())) && JeePlusProperites.YES.equals(child.getUseable())){ if (child.getParentId().equals(officeItem.getId())) { if(child.isHasChild()){ child = getChildOfTree(child, officeList, extId, type, grade, isAll); } officeItem.getChildren().add(child); } } } return officeItem; } [/pre] 参考下图位置: img[/userfiles/fly/6fe70fe5ef53494bbd455d4366dd3bb9/files/1589199672109.] 这样可以减少遍历次数,提高响应速度。 获取Menu也可以进行相同优化 1、在com.jeeplus.modules.sys.entity.Menu中添加字段:hasChild [pre] private boolean hasChild; //为了减少遍历次数 public boolean isHasChild() { return hasChild; } public void setHasChild(boolean hasChild) { this.hasChild = hasChild; } [/pre] 2.在MenuMapper.xml的<sql id="menuColumns">中加入: [pre] ((SELECT count(*) FROM sys_menu x WHERE x.parent_id=a.id)>0) AS "hasChild", [/pre] 参考下图位置: img[/userfiles/fly/6fe70fe5ef53494bbd455d4366dd3bb9/files/1590206769749.] 3.修改MenuUtils中的getChildOfTree方法,修改为 [pre] private static Menu getChildOfTree(Menu menuItem, int level, List<Menu> menuList) { if (menuItem.getIsShow().equals("1")) {// 如果是父节点且显示 menuItem.setChildren(Lists.newArrayList()); for (Menu child : menuList) { if (!child.getType().equals("3") && child.getParentId().equals(menuItem.getId()) && child.getIsShow().equals("1")) { if(child.isHasChild()){ child = getChildOfTree(child, level + 1, menuList); } menuItem.getChildren().add(child); } } } return menuItem; } [/pre] 参考下图位置: img[/userfiles/fly/6fe70fe5ef53494bbd455d4366dd3bb9/files/1590206920573.] 4.修改RouterUtils中的getChildOfTree方法,修改为 [pre] private static Menu getChildOfTree(Menu menuItem1, int level, List<Menu> menuList) { Menu menuItem = new Menu(); BeanUtils.copyProperties(menuItem1,menuItem); menuItem.setChildren(Lists.newArrayList()); for (Menu child : menuList) { if ( child.getParentId().equals(menuItem.getId())) { if(child.isHasChild()){ child = getChildOfTree(child, level + 1, menuList); } menuItem.getChildren().add(child); } } return menuItem; } [/pre] 参考下图位置: img[/userfiles/fly/6fe70fe5ef53494bbd455d4366dd3bb9/files/1590207006097.] 5.修改MenuController中的getChildOfTree方法,修改为 [pre] private Menu getChildOfTree(Menu menuItem, List<Menu> menuList, String extId, String isShowHide) { menuItem.setChildren(Lists.newArrayList()); for (Menu child : menuList) { if (StringUtils.isBlank(extId) || (extId != null && !extId.equals(child.getId()) && child.getParentIds().indexOf("," + extId + ",") == -1)) { if (isShowHide != null && isShowHide.equals("0") && child.getIsShow().equals("0")) { continue; } if (child.getParentId().equals(menuItem.getId())) { if(child.isHasChild()){ child = getChildOfTree(child, menuList, extId, isShowHide); } menuItem.getChildren().add(child); } } } return menuItem; } [/pre] 参考下图位置: img[/userfiles/fly/6fe70fe5ef53494bbd455d4366dd3bb9/files/1590207367389.]
回帖
  • 消灭零回复