@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; }
@Override public Role edit(Role role) { Trole t = roleDao.get(Trole.class, role.getId()); if (t != null) { Map<String, Object> params = new HashMap<String, Object>(); params.put("trole", t); roleResourceDao.executeHql("delete TroleTresource t where t.trole=:trole", params); BeanUtils.copyProperties(role, t); if (role.getResourceIds() != null) { String resourceNames = ""; for (String id : role.getResourceIds().split(",")) { Tresource r = resourceDao.get(Tresource.class, id); if (r != null) { TroleTresource rr = new TroleTresource(); rr.setId(UUID.randomUUID().toString()); rr.setTresource(r); rr.setTrole(t); roleResourceDao.save(rr); if (resourceNames.length() > 0) { resourceNames += ","; } resourceNames += r.getText(); } } role.setResourceNames(resourceNames); } } return role; }
@Override public Role save(Role role) { Trole t = new Trole(); BeanUtils.copyProperties(role, t); t.setId(UUID.randomUUID().toString()); roleDao.save(t); if (role.getResourceIds() != null) { String resourceNames = ""; for (String id : role.getResourceIds().split(",")) { Tresource r = resourceDao.get(Tresource.class, id); if (r != null) { TroleTresource rr = new TroleTresource(); rr.setId(UUID.randomUUID().toString()); rr.setTresource(r); rr.setTrole(t); roleResourceDao.save(rr); if (resourceNames.length() > 0) { resourceNames += ","; } resourceNames += r.getText(); } } role.setResourceNames(resourceNames); } role.setId(t.getId()); return role; }
@Override public void remove(String ids) { for (String id : ids.split(",")) { Trole t = roleDao.get(Trole.class, id); if (t != null) { roleDao.delete(t); } } }
@Override public DataGrid datagrid(Role role) { DataGrid dg = new DataGrid(); String hql = "from Trole t "; Map<String, Object> params = new HashMap<String, Object>(); hql = addWhere(role, hql, params); String totalHql = "select count(*) " + hql; hql = addOrder(role, hql); List<Trole> l = roleDao.find(hql, params, role.getPage(), role.getRows()); List<Role> nl = new ArrayList<Role>(); changeModel(l, nl); dg.setTotal(roleDao.count(totalHql, params)); dg.setRows(nl); return dg; }
@Override public DataGrid datagrid(User user) { DataGrid dg = new DataGrid(); String hql = "from Tuser t "; Map<String, Object> params = new HashMap<String, Object>(); hql = addWhere(user, hql, params); String totalHql = "select count(*) " + hql; hql = addOrder(user, hql); List<Tuser> l = userDao.find(hql, params, user.getPage(), user.getRows()); List<User> nl = new ArrayList<User>(); changeModel(l, nl); dg.setTotal(userDao.count(totalHql, params)); dg.setRows(nl); return dg; }
@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; }
private void del(Tmenu r) { Set<Tmenu> s = r.getTmenus(); if (s != null && !s.isEmpty()) { for (Tmenu t : s) { del(t); } } menuDao.delete(r); }
@Override public User login(User user) { Map<String, Object> params = new HashMap<String, Object>(); params.put("pwd", Encrypt.e(user.getPwd())); params.put("name", user.getName()); Tuser t = userDao.get("from Tuser t where t.name = :name and t.pwd = :pwd", params); if (t != null) { return user; } return null; }
@Override public User save(User user) { Tuser t = new Tuser(); BeanUtils.copyProperties(user, t, new String[] {"pwd"}); t.setId(UUID.randomUUID().toString()); t.setCreatedatetime(new Date()); t.setPwd(Encrypt.e(user.getPwd())); userDao.save(t); BeanUtils.copyProperties(t, user); return user; }
@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 void remove(String ids) { // for (String id : ids.split(",")) { // Tuser u = userDao.get(Tuser.class, id); // if (u != null) { // userDao.delete(u); // } // } String[] nids = ids.split(","); String hql = "delete Tuser t where t.id in ("; for (int i = 0; i < nids.length; i++) { if (i > 0) { hql += ","; } hql += "'" + nids[i] + "'"; } hql += ")"; userDao.executeHql(hql); }
@Override public void remove(String id) { Tmenu t = menuDao.get(Tmenu.class, id); this.del(t); }