Skip to content

Commit

Permalink
添加json菜单生成方式,session中追加保存菜单和权限
Browse files Browse the repository at this point in the history
  • Loading branch information
angilin committed Apr 3, 2014
1 parent 95716c0 commit 5116fcb
Show file tree
Hide file tree
Showing 12 changed files with 280 additions and 64 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -225,4 +225,5 @@ SysAccountRoleAr.hbm.xml
SysRoleAr.hbm.xml
ArchiveDao.java
ArchiveService.java
FtpAccess.java
FtpAccess.java
ArchiveServiceTest.java
5 changes: 3 additions & 2 deletions WebRoot/index.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ p {
Ext.state.Manager.setProvider(Ext.create('Ext.state.CookieProvider'));
//根节点还是只能设置1个
var treejson = {id:"1",text:"菜单1",expanded: true ,children:[{id:"2",text:"子菜单1",leaf : true}]};
var treejson = {id:"0",text:"菜单",expanded: true ,children:${sessionScope.com_user.menuJsonString}};
var store = Ext.create("Ext.data.TreeStore", {
model : "ctreemodel",
Expand Down Expand Up @@ -85,7 +85,7 @@ p {
<div>
<span style="float:left;padding-left:50px;padding-top:5px;bold;font-size:20pt;">RBAC系统</span>
<span style="float:right;padding-right:50px;padding-top:15px;font-size:12pt;">
当前用户:<c:out value="${sessionScope.com_user.realname}"/>
当前用户:<c:out value="${sessionScope.com_user.account.realname}"/>
&nbsp;&nbsp;&nbsp;
当前时间:<span id="currentTime"></span>
&nbsp;&nbsp;&nbsp;
Expand All @@ -96,6 +96,7 @@ p {
<div id="west" class="x-hide-display">
</div>
<div id="center1" class="x-hide-display">
菜单的json字符串:${sessionScope.com_user.menuJsonString}
</div>
</body>
</html>
Expand Down
26 changes: 4 additions & 22 deletions src/com/rbac/action/system/LoginAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,20 @@
*/
package com.rbac.action.system;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
import java.util.Set;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.hibernate.Hibernate;
import org.hibernate.collection.PersistentBag;

import com.rbac.common.BaseAction;
import com.rbac.common.MvcConstant;
import com.rbac.entity.SysAccount;
import com.rbac.entity.SysAccountRole;
import com.rbac.entity.SysRole;
import com.rbac.common.UserDetail;
import com.rbac.form.system.LoginForm;
import com.rbac.service.AccountService;
import com.rbac.service.LoginService;

/**
Expand Down Expand Up @@ -67,10 +49,10 @@ public ActionForward execute(ActionMapping mapping, ActionForm form,
LoginService loginService = (LoginService) super
.getBean("loginService");
if (StringUtils.isNotBlank(loginForm.getPassword())) {
SysAccount account = loginService.login(loginForm.getUsername(),
UserDetail userDetail = loginService.login(loginForm.getUsername(),
loginForm.getPassword());
if (account != null) {
request.getSession(true).setAttribute(MvcConstant.USER, account);
if (userDetail != null) {
request.getSession(true).setAttribute(MvcConstant.USER, userDetail);
return mapping.findForward("success");
}
}
Expand Down
11 changes: 11 additions & 0 deletions src/com/rbac/common/MvcConstant.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.rbac.common;

/**
* 常量类
* @date 2014-3-24
*
*/
public class MvcConstant {

public static final String USER = "com_user";
}
38 changes: 38 additions & 0 deletions src/com/rbac/common/UserDetail.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.rbac.common;

import java.util.Set;

import com.rbac.entity.SysAccount;

public class UserDetail {

private SysAccount account;

private String menuJsonString;

private Set<String> permitActionSet;

public SysAccount getAccount() {
return account;
}

public void setAccount(SysAccount account) {
this.account = account;
}

public String getMenuJsonString() {
return menuJsonString;
}

public void setMenuJsonString(String menuJsonString) {
this.menuJsonString = menuJsonString;
}

public Set<String> getPermitActionSet() {
return permitActionSet;
}

public void setPermitActionSet(Set<String> permitActionSet) {
this.permitActionSet = permitActionSet;
}
}
14 changes: 14 additions & 0 deletions src/com/rbac/dao/AccountDao.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.rbac.dao;

import java.util.List;

import org.springframework.stereotype.Component;

import com.rbac.common.BaseDaoSupport;
import com.rbac.entity.SysMenu;

@Component("accountDao")
public class AccountDao extends BaseDaoSupport {


}
2 changes: 1 addition & 1 deletion src/com/rbac/dao/LoginDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public SysAccount getSysAccountByUsername(String username) {
}

public List getMenuListByAccountId(Long accountId){
String sql = "select m.* from sys_menu m where m.ID in (select rm.menu_id from sys_role_menu rm where rm.ROLE_ID in (select ar.role_id from sys_account_role ar where ar.account_id=:accountId))";
String sql = "select m.* from sys_menu m where m.is_deleted=0 and m.ID in (select rm.menu_id from sys_role_menu rm where rm.is_deleted=0 and rm.ROLE_ID in (select ar.role_id from sys_account_role ar where ar.is_deleted=0 and ar.account_id=:accountId))";
return super.getSession().createSQLQuery(sql).addEntity(SysMenu.class).setLong("accountId", accountId).list();
}
}
12 changes: 2 additions & 10 deletions src/com/rbac/entity/SysMenu.hbm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
<column name="ID" />
<generator class="native" />
</id>
<many-to-one name="sysMenu" class="com.rbac.entity.SysMenu" fetch="select">
<property name="parentId" type="java.lang.Long">
<column name="PARENT_ID">
<comment>父菜单id</comment>
</column>
</many-to-one>
</property>
<property name="name" type="java.lang.String">
<column name="NAME" length="20">
<comment>菜单显示名</comment>
Expand Down Expand Up @@ -65,13 +65,5 @@
<comment>排序字段</comment>
</column>
</property>
<set name="sysMenus" inverse="true">
<key>
<column name="PARENT_ID">
<comment>父菜单id</comment>
</column>
</key>
<one-to-many class="com.rbac.entity.SysMenu" />
</set>
</class>
</hibernate-mapping>
29 changes: 9 additions & 20 deletions src/com/rbac/entity/SysMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ public class SysMenu implements java.io.Serializable {
// Fields

private Long id;

private SysMenu sysMenu;
private Long parentId;

private String name;

Expand All @@ -36,8 +36,6 @@ public class SysMenu implements java.io.Serializable {

private Integer orderSeq;

private Set sysMenus = new HashSet(0);

// Constructors

/** default constructor */
Expand All @@ -52,10 +50,10 @@ public SysMenu(Integer needCheck, Integer isShow, Integer isDeleted) {
}

/** full constructor */
public SysMenu(SysMenu sysMenu, String name, String url, Integer needCheck,
public SysMenu(Long parentId, String name, String url, Integer needCheck,
Integer isShow, Integer isDeleted, Long creatorId, Date createTime,
Long modifierId, Date modifyTime, Integer orderSeq, Set sysMenus) {
this.sysMenu = sysMenu;
Long modifierId, Date modifyTime, Integer orderSeq) {
this.parentId = parentId;
this.name = name;
this.url = url;
this.needCheck = needCheck;
Expand All @@ -66,7 +64,6 @@ public SysMenu(SysMenu sysMenu, String name, String url, Integer needCheck,
this.modifierId = modifierId;
this.modifyTime = modifyTime;
this.orderSeq = orderSeq;
this.sysMenus = sysMenus;
}

// Property accessors
Expand All @@ -79,14 +76,6 @@ public void setId(Long id) {
this.id = id;
}

public SysMenu getSysMenu() {
return this.sysMenu;
}

public void setSysMenu(SysMenu sysMenu) {
this.sysMenu = sysMenu;
}

public String getName() {
return this.name;
}
Expand Down Expand Up @@ -167,12 +156,12 @@ public void setOrderSeq(Integer orderSeq) {
this.orderSeq = orderSeq;
}

public Set getSysMenus() {
return this.sysMenus;
public Long getParentId() {
return parentId;
}

public void setSysMenus(Set sysMenus) {
this.sysMenus = sysMenus;
public void setParentId(Long parentId) {
this.parentId = parentId;
}

}
84 changes: 84 additions & 0 deletions src/com/rbac/entity/SysMenuVo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package com.rbac.entity;

import java.util.ArrayList;
import java.util.List;

public class SysMenuVo implements Comparable{

private Long id;

private String text;

private String url;

private Integer orderSeq;

private Long parentId;

private List<SysMenuVo> children = new ArrayList<SysMenuVo>();


public int compareTo(Object menuVo){
if(menuVo instanceof SysMenuVo){
SysMenuVo vo = (SysMenuVo)menuVo;
if(vo!=null){
return this.orderSeq.compareTo(vo.getOrderSeq());
}
}
return 1;
}

public Boolean getLeaf(){
return children.size()>0?false:true;
}


public List<SysMenuVo> getChildren() {
return children;
}

public void setChildren(List<SysMenuVo> children) {
this.children = children;
}

public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}

public Integer getOrderSeq() {
return orderSeq;
}

public void setOrderSeq(Integer orderSeq) {
this.orderSeq = orderSeq;
}

public String getText() {
return text;
}

public void setText(String text) {
this.text = text;
}

public String getUrl() {
return url;
}

public void setUrl(String url) {
this.url = url;
}

public Long getParentId() {
return parentId;
}

public void setParentId(Long parentId) {
this.parentId = parentId;
}

}
26 changes: 26 additions & 0 deletions src/com/rbac/service/AccountService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.rbac.service;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

import org.hibernate.Hibernate;
import org.hibernate.collection.PersistentBag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.rbac.dao.AccountDao;
import com.rbac.entity.SysAccount;

@Service("accountService")
public class AccountService {

@Autowired
private AccountDao accountDao;

public void saveOrUpdateAccount(SysAccount account){
accountDao.saveOrUpdate(account);
}


}
Loading

0 comments on commit 5116fcb

Please sign in to comment.