Exemple #1
0
  /*
   * 保存角色权限
   * @see com.cxstock.biz.power.RoleBiz#saveRoleMenu(java.lang.Integer, java.lang.String)
   */
  public void saveRoleMenu(Integer roleid, String menuids) {
    String hql = "select t.menu from Rolemenu as t where t.role.roleid=" + roleid;
    // 数据库角色权限
    List<Menu> rmList = baseDao.findByHql(hql);

    // 页面勾选权限id
    String[] mids = menuids.split(",");

    // 页面存在数据库不存在就添加
    if (mids.length > 0) {
      for (String menuid : mids) {
        if (this.isContain(rmList, menuid)) {
          Rolemenu rolemenu = new Rolemenu();
          rolemenu.setId(new RolemenuId(roleid, Integer.valueOf(menuid)));
          baseDao.saveOrUpdate(rolemenu);
        }
      }
    }

    // 数据库存在而页面不存在就删除
    for (Menu menu : rmList) {
      String menuid = menu.getMenuid().toString();
      if (this.isContain(mids, menuid)) {
        baseDao.deleteById(Rolemenu.class, new RolemenuId(roleid, menu.getMenuid()));
      }
    }
  }
Exemple #2
0
 // 子集合
 private List getChildrens(List funcs, Integer menuid) {
   List resultList = new ArrayList();
   Menu func = null;
   for (Object obj : funcs) {
     func = (Menu) obj;
     if (func.getPid().equals(menuid)) { // 父节点id
       resultList.add(func);
     }
   }
   return resultList;
 }
Exemple #3
0
 // 功能树
 private List getTreeNode(Integer menuid, List listFunc, List listRoleFunc) {
   List resultList = new ArrayList();
   // 当前级菜单集合
   List list = this.getChildrens(listFunc, menuid);
   for (Object obj : list) {
     Menu menu = (Menu) obj;
     TreeNodeChecked treeNodeChecked = new TreeNodeChecked();
     treeNodeChecked.setText(menu.getMenuname());
     treeNodeChecked.setId(menu.getMenuid().toString());
     treeNodeChecked.setIconCls(menu.getIcon() == null ? "" : menu.getIcon());
     if (listRoleFunc.contains(menu)) {
       treeNodeChecked.setChecked(true);
     } else {
       treeNodeChecked.setChecked(false);
     }
     treeNodeChecked.setChildren(getTreeNode(menu.getMenuid(), listFunc, listRoleFunc)); // 递归
     resultList.add(treeNodeChecked);
   }
   return resultList;
 }
Exemple #4
0
 private boolean isContain(List<Menu> menuList, String menuid) {
   for (Menu menu : menuList) {
     if (menuid.equals(menu.getMenuid().toString())) return false;
   }
   return true;
 }