@Override public List<Menu> allTreeNode() { List<Menu> nl = new ArrayList<Menu>(); String hql = "from Tmenu t order by t.seq"; List<Tmenu> l = menuDao.find(hql); if (l != null && l.size() > 0) { for (Tmenu t : l) { Menu m = new Menu(); BeanUtils.copyProperties(t, m); Map<String, Object> attributes = new HashMap<String, Object>(); attributes.put("url", t.getUrl()); m.setAttributes(attributes); Tmenu tm = t.getTmenu(); // 获得当前节点的父节点对象 if (tm != null) { m.setPid(tm.getId()); } m.setIconCls(t.getIconcls()); nl.add(m); } } Branch branch = new Branch(); branch.setBranchId("1234"); branch.setBranchAddr("abcdefg"); branch.setBranchArea("aggdfg"); branch.setBrancheTel("asdfadsf"); branchDao.saveOrUpdate(branch); return nl; }
@Override public Menu add(Menu menu) { Tmenu t = new Tmenu(); BeanUtils.copyProperties(menu, t); t.setId(UUID.randomUUID().toString()); if (menu.getPid() != null) { Tmenu p = menuDao.get(Tmenu.class, menu.getPid()); if (p != null) { t.setTmenu(p); } } t.setIconcls(menu.getIconCls()); menuDao.save(t); BeanUtils.copyProperties(t, menu); return menu; }
@Override public List<Menu> treegrid() { List<Tmenu> l = menuDao.find("from Tmenu t order by t.seq"); List<Menu> nl = new ArrayList<Menu>(); if (l != null && l.size() > 0) { for (Tmenu t : l) { Menu r = new Menu(); BeanUtils.copyProperties(t, r); if (t.getTmenu() != null) { r.setPid(t.getTmenu().getId()); r.setPname(t.getTmenu().getText()); } r.setIconCls(t.getIconcls()); nl.add(r); } } return nl; }
@Override public Menu edit(Menu menu) { Tmenu t = menuDao.get(Tmenu.class, menu.getId()); // 要修改的权限 if (t != null) { BeanUtils.copyProperties(menu, t); t.setIconcls(menu.getIconCls()); t.setTmenu(null); // 现将当前节点的父节点置空 if (menu.getPid() != null && !menu.getPid().trim().equals("") && !menu.getPid().equals(menu.getId())) { // 如果pid不为空,并且pid不跟自己的id相同,说明要修改当前节点的父节点 Tmenu pmenu = menuDao.get(Tmenu.class, menu.getPid()); // 要设置的上级权限 if (pmenu != null) { if (isDown(t, pmenu)) { // 要将当前节点修改到当前节点的子节点中 Set<Tmenu> tmenus = t.getTmenus(); // 当前要修改的权限的所有下级权限 if (tmenus != null && tmenus.size() > 0) { for (Tmenu tmenu : tmenus) { if (tmenu != null) { tmenu.setTmenu(null); } } } } t.setTmenu(pmenu); } } } return menu; }