Skip to content

Commit

Permalink
系统管理功能完善
Browse files Browse the repository at this point in the history
  • Loading branch information
penggle committed May 4, 2017
1 parent 3ffb2f1 commit 7af9140
Show file tree
Hide file tree
Showing 21 changed files with 737 additions and 150 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.certusnet.xproject.admin.support;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import com.certusnet.xproject.admin.model.AdminResource;
import com.certusnet.xproject.common.support.TreeNodeConverter;

/**
* 基于ElementUI.Tree组件的资源节点树转换器
*
* @author pengpeng
* @date 2015年11月15日 下午8:03:51
* @version 1.0
*/
public class AdminResourceSimpleTreeNodeConverter implements TreeNodeConverter<AdminResource, Map<String,Object>> {

public AdminResourceSimpleTreeNodeConverter() {
super();
}

public Map<String, Object> convertTreeNode(AdminResource targetTreeNode) {
Map<String,Object> treeNodeMap = new LinkedHashMap<String,Object>();
treeNodeMap.put("id", targetTreeNode.getResourceId());
treeNodeMap.put("label", targetTreeNode.getResourceName());
treeNodeMap.put("actionType", targetTreeNode.getActionType());
treeNodeMap.put("resourceType", targetTreeNode.getResourceType());
return treeNodeMap;
}

public void setSubTreeNodeList(Map<String, Object> resultTreeNode, List<Map<String, Object>> subTreeNodeList) {
resultTreeNode.put("children", subTreeNodeList);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
Expand All @@ -19,6 +20,7 @@
import org.apache.shiro.authc.LockedAccountException;
import org.apache.shiro.authc.UnknownAccountException;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.authz.AuthorizationInfo;
import org.apache.shiro.subject.Subject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -36,6 +38,7 @@
import com.certusnet.xproject.admin.support.AdminResourceNavMenuNodeConverter;
import com.certusnet.xproject.admin.support.AdminResourceTreeBuilder;
import com.certusnet.xproject.admin.web.LoginToken;
import com.certusnet.xproject.admin.web.shiro.realm.AdminUserRealm;
import com.certusnet.xproject.common.consts.GlobalConstants;
import com.certusnet.xproject.common.support.AbstractXTreeBuilder;
import com.certusnet.xproject.common.support.Result;
Expand All @@ -46,6 +49,7 @@
import com.certusnet.xproject.common.util.StringUtils;
import com.certusnet.xproject.common.web.BaseController;
import com.certusnet.xproject.common.web.shiro.ShiroUtils;
import com.certusnet.xproject.common.web.shiro.authz.CustomAuthorizationInfo;
/**
* 管理后台Controller
*
Expand Down Expand Up @@ -192,8 +196,21 @@ public Object getLoginUserInfo(HttpServletRequest request, HttpServletResponse r
public Object getLoginUserMenuList(HttpServletRequest request, HttpServletResponse response) {
List<Map<String,Object>> dataList = new ArrayList<Map<String,Object>>();
try {
List<AdminResource> allResourceList = adminResourceService.getAllResourceList(AdminResourceActionTypeEnum.ADMIN_RESOURCE_ACTION_TYPE_MENU.getTypeCode());
dataList = resourceTreeBuilder.buildObjectTree(GlobalConstants.DEFAULT_ADMIN_ROOT_RESOURCE_ID, allResourceList, resourceNavMenuNodeConverter);
List<AdminResource> userMenuResources = new ArrayList<AdminResource>();
AdminUserRealm realm = ShiroUtils.getRealm(AdminUserRealm.class);
AuthorizationInfo authInfo = realm.getAuthorizationInfo(SecurityUtils.getSubject().getPrincipals());
if(authInfo instanceof CustomAuthorizationInfo){
CustomAuthorizationInfo<AdminResource> authorizationInfo = (CustomAuthorizationInfo<AdminResource>) authInfo;
Set<AdminResource> userResources = authorizationInfo.getResources();
if(!CollectionUtils.isEmpty(userResources)){
for(AdminResource resource : userResources){
if(AdminResourceActionTypeEnum.ADMIN_RESOURCE_ACTION_TYPE_MENU.getTypeCode().equals(resource.getActionType())){
userMenuResources.add(resource);
}
}
dataList = resourceTreeBuilder.buildObjectTree(GlobalConstants.DEFAULT_ADMIN_ROOT_RESOURCE_ID, userMenuResources, resourceNavMenuNodeConverter);
}
}
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,38 @@

import static org.springframework.web.bind.annotation.RequestMethod.POST;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

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

import org.apache.commons.collections.MapUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.certusnet.xproject.admin.consts.em.AdminRoleTypeEnum;
import com.certusnet.xproject.admin.model.AdminResource;
import com.certusnet.xproject.admin.model.AdminRole;
import com.certusnet.xproject.admin.model.AdminUser;
import com.certusnet.xproject.admin.service.AdminResourceService;
import com.certusnet.xproject.admin.service.AdminRoleService;
import com.certusnet.xproject.admin.support.AdminResourceSimpleTreeNodeConverter;
import com.certusnet.xproject.admin.support.AdminResourceTreeBuilder;
import com.certusnet.xproject.admin.web.LoginToken;
import com.certusnet.xproject.common.consts.GlobalConstants;
import com.certusnet.xproject.common.support.AbstractXTreeBuilder;
import com.certusnet.xproject.common.support.OrderBy;
import com.certusnet.xproject.common.support.Pager;
import com.certusnet.xproject.common.support.PagingList;
import com.certusnet.xproject.common.support.TreeNodeConverter;
import com.certusnet.xproject.common.util.CollectionUtils;
import com.certusnet.xproject.common.util.DateTimeUtils;
import com.certusnet.xproject.common.util.StringUtils;
import com.certusnet.xproject.common.web.BaseController;
import com.certusnet.xproject.common.web.shiro.ShiroUtils;

Expand All @@ -34,6 +47,10 @@
@RestController
public class AdminRoleMgtController extends BaseController {

private AbstractXTreeBuilder<Long, AdminResource> resourceTreeBuilder = new AdminResourceTreeBuilder();

private TreeNodeConverter<AdminResource,Map<String,Object>> resourceTreeNodeConverter = new AdminResourceSimpleTreeNodeConverter();

@Resource(name="adminResourceFacadeService")
private AdminResourceService adminResourceService;

Expand All @@ -51,8 +68,8 @@ public class AdminRoleMgtController extends BaseController {
*/
@RequestMapping(value="/admin/role/list")
public Object listRole(HttpServletRequest request, HttpServletResponse response, AdminRole roleQueryForm, OrderBy orderBy, Pager pager) {
List<AdminRole> roleList = adminRoleService.getRoleList(roleQueryForm, pager, orderBy);
return genSuccessResult(roleList);
PagingList<AdminRole> roleList = adminRoleService.getRoleList(roleQueryForm, pager, orderBy);
return genSuccessPagingResult(roleList);
}

/**
Expand Down Expand Up @@ -101,4 +118,54 @@ public Object delRole(HttpServletRequest request, HttpServletResponse response,
return genSuccessResult("删除成功!", null);
}

/**
* 加载角色-资源配置关系
* @param request
* @param response
* @param roleId
* @return
* @throws Exception
*/
@RequestMapping(value="/admin/role/resources")
public Object loadRoleResources(HttpServletRequest request, HttpServletResponse response, Long roleId) throws Exception {
List<AdminResource> allResourceList = adminResourceService.getAllResourceList(null);
List<AdminResource> roleResourceList = adminRoleService.getResourceListByRoleId(roleId);
List<Long> checkedResourceIdList = new ArrayList<Long>();
if(!CollectionUtils.isEmpty(roleResourceList)){
for(AdminResource roleResource : roleResourceList){
checkedResourceIdList.add(roleResource.getResourceId());
}
}
List<Map<String,Object>> dataList = resourceTreeBuilder.buildObjectTree(GlobalConstants.DEFAULT_ADMIN_ROOT_RESOURCE_ID, allResourceList, resourceTreeNodeConverter);
Map<String,Object> dataMap = new HashMap<String,Object>();
dataMap.put("allResourceList", dataList);
dataMap.put("checkedResourceIdList", checkedResourceIdList);
return genSuccessResult(dataMap);
}

/**
* 配置角色-资源关系
* @param request
* @param response
* @param parameter
* @return
*/
@RequestMapping(value="/admin/role/config/submit", method=POST)
public Object configRoleResources(HttpServletRequest request, HttpServletResponse response, @RequestBody Map<String,Object> parameter) {
List<Long> resourceIdList = new ArrayList<Long>();
String resourceIds = MapUtils.getString(parameter, "resourceIds");
Long roleId = MapUtils.getLong(parameter, "roleId");
if(!StringUtils.isEmpty(resourceIds)){
String[] resourceIdArray = resourceIds.split(",");
if(resourceIdArray != null && resourceIdArray.length > 0){
for(String resourceId : resourceIdArray){
resourceIdList.add(Long.valueOf(resourceId));
}
}
}
LoginToken<AdminUser> loginToken = ShiroUtils.getSessionAttribute(LoginToken.LOGIN_TOKEN_SESSION_KEY);
adminRoleService.configRoleResources(roleId, resourceIdList, loginToken.getLoginId(), DateTimeUtils.formatNow());
return genSuccessResult("配置成功!", null);
}

}
3 changes: 0 additions & 3 deletions xproject-admin/src/main/webapp/admin/resource/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,6 @@
vertical-align: middle;
margin-bottom: 4px;
}
.el-tag-action-type {
border-radius: 12px;
}
</style>
</head>
<body>
Expand Down
Loading

0 comments on commit 7af9140

Please sign in to comment.