View Javadoc
1   /**
2    * Copyright By Grandsoft Company Limited.  
3    * 2012-6-28 下午05:21:08
4    */
5   package gboat2.web.business.impl;
6   
7   import gboat2.base.core.cache.ICacheService;
8   import gboat2.base.core.service.BaseService;
9   import gboat2.web.Constants;
10  import gboat2.web.business.ICacheAssistBusiness;
11  import gboat2.web.business.IGroupBusiness;
12  import gboat2.web.model.Group;
13  
14  import java.util.List;
15  
16  import org.apache.commons.lang3.StringUtils;
17  import org.springframework.beans.factory.annotation.Autowired;
18  import org.springframework.stereotype.Service;
19  import org.springframework.transaction.annotation.Transactional;
20  
21  /**
22   * @author wangsr
23   * @since jdk1.6
24   * @date 2012-6-28
25   *  
26   */
27  @Transactional
28  @Service
29  public class CacheAssistantImpl extends BaseService implements ICacheAssistBusiness {
30  
31  	@Autowired
32  	private ICacheService cacheSer;
33  
34  	@Autowired
35  	private IGroupBusiness groupBusi;
36  
37  	/** 
38  	  * {@inheritDoc}   
39  	  * @see gboat2.web.business.ICacheAssistBusiness#removeCacheOfPriority(java.lang.String) 
40  	  */
41  	@Override
42  	public void removeCacheOfPriority(String authForId, String systemId) {
43  		if (StringUtils.isEmpty(authForId) || StringUtils.isEmpty(systemId)) {
44  			return;
45  		}
46  		if (authForId.indexOf(".") != -1) {
47  			//groupId.roleId:包含(.),则是用户组角色的权限
48  			// 权限
49  			this.cacheSer.remove(Constants.PRIORITY_CACHE_CATALOG, authForId + "-" + systemId);
50  			// 导航树
51  			this.cacheSer.remove(Constants.MENU_TREE_CACHE_CATALOG, authForId + "-" + systemId);
52  		} else {
53  			//roleId:不包含(.),这是单独的角色的权限。则应将包含这个角色的权限缓存清除
54  			List<Group> list = this.groupBusi.getAllGroup();
55  			if (null != list && list.size() > 0) {
56  				for (Group g : list) {
57  					// 权限
58  					this.cacheSer.remove(Constants.PRIORITY_CACHE_CATALOG, g.getGroupId() + "." + authForId + "-" + systemId);
59  					// 导航树
60  					this.cacheSer.remove(Constants.MENU_TREE_CACHE_CATALOG, g.getGroupId() + "." + authForId + "-" + systemId);
61  				}
62  			}
63  		}
64  	}
65  
66  	@Override
67  	public void removeCacheOfMenuTree(String authForId, String systemId) {
68  		if (StringUtils.isEmpty(authForId) || StringUtils.isEmpty(systemId)) {
69  			return;
70  		}
71  		if (authForId.indexOf(".") != -1) {
72  			//groupId.roleId:包含(.)
73  			// 导航树
74  			this.cacheSer.remove(Constants.MENU_TREE_CACHE_CATALOG, authForId + "-" + systemId);
75  		} else {
76  			//roleId:不包含(.)
77  			List<Group> list = this.groupBusi.getAllGroup();
78  			if (null != list && list.size() > 0) {
79  				for (Group g : list) {
80  					// 导航树
81  					this.cacheSer.remove(Constants.MENU_TREE_CACHE_CATALOG, g.getGroupId() + "." + authForId + "-" + systemId);
82  				}
83  			}
84  		}
85  	}
86  
87  }