コード例 #1
0
 /**
  * 显示角色权限映射页面
  *
  * @param mapping
  * @param actionForm
  * @param request
  * @param response
  * @return
  * @throws Exception
  */
 public ActionForward showPrivilege(
     ActionMapping mapping,
     ActionForm actionForm,
     HttpServletRequest request,
     HttpServletResponse response)
     throws Exception {
   long deptId = ParamUtil.getLongParameter(request, "deptId", 0);
   long roleId = ParamUtil.getLongParameter(request, "roleId", 0);
   SysDeptRole deptRole = sysDeptRoleService.find(deptId, roleId);
   if (deptRole == null) { // 如果没有找到则创建一个
     deptRole = new SysDeptRole();
     deptRole.setDept(sysDepartmentService.findById(deptId));
     deptRole.setRole(sysRoleService.findById(roleId));
     sysDeptRoleService.create(deptRole);
   }
   request.setAttribute("role", deptRole);
   SysTree parent = sysTreeService.getSysTreeByCode(Constants.TREE_APP);
   List list = new ArrayList();
   sysTreeService.getSysTree(list, (int) parent.getId(), 0);
   request.setAttribute("list", list);
   return mapping.findForward("show_privilege");
 }
コード例 #2
0
  /**
   * 设置部门角色
   *
   * @param mapping
   * @param actionForm
   * @param request
   * @param response
   * @return
   * @throws Exception
   */
  public ActionForward setRole(
      ActionMapping mapping,
      ActionForm actionForm,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {

    ActionMessages messages = new ActionMessages();
    long deptId = ParamUtil.getIntParameter(request, "deptId", 0);
    SysDepartment dept = sysDepartmentService.findById(deptId); // 查找部门对象
    if (dept != null) { // 部门存在
      long[] id = ParamUtil.getLongParameterValues(request, "id"); // 获取roleId
      if (id != null) {
        // 先确定要删除的角色

        // 再确定要增加的角色

        // 先把部门下面的角色清空
        Iterator iter = dept.getRoles().iterator();
        while (iter.hasNext()) {
          sysDeptRoleService.delete((SysDeptRole) iter.next());
        }
        // 创建新角色
        for (int i = 0; i < id.length; i++) {
          SysRole role = sysRoleService.findById(id[i]);
          if (role == null) continue;

          SysDeptRole deptRole = new SysDeptRole();
          deptRole.setDept(dept);
          deptRole.setRole(role);
          sysDeptRoleService.create(deptRole);
        }
      }
    }
    addMessages(request, messages);
    return mapping.findForward("show_msg");
  }