Skip to content

Commit

Permalink
系统管理功能完善
Browse files Browse the repository at this point in the history
  • Loading branch information
penggle committed May 5, 2017
1 parent 7af9140 commit 38501bd
Show file tree
Hide file tree
Showing 17 changed files with 1,428 additions and 134 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public Map<String, Object> convertTreeNode(AdminResource targetTreeNode) {
treeNodeMap.put("id", targetTreeNode.getResourceId());
treeNodeMap.put("label", targetTreeNode.getResourceName());
treeNodeMap.put("actionType", targetTreeNode.getActionType());
treeNodeMap.put("actionTypeName", targetTreeNode.getActionTypeName());
treeNodeMap.put("resourceType", targetTreeNode.getResourceType());
return treeNodeMap;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public Map<String, Object> convertTreeNode(AdminResource targetTreeNode) {
treeNodeMap.put("parentResourceName", targetTreeNode.getParentResourceName());
treeNodeMap.put("siblingsIndex", targetTreeNode.getSiblingsIndex());
treeNodeMap.put("actionType", targetTreeNode.getActionType());
treeNodeMap.put("actionTypeName", targetTreeNode.getActionTypeName());
treeNodeMap.put("resourceUrl", targetTreeNode.getResourceUrl());
treeNodeMap.put("resourceType", targetTreeNode.getResourceType());
treeNodeMap.put("resourceIcon", targetTreeNode.getResourceIcon());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,252 @@
package com.certusnet.xproject.admin.web.controller;

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

import java.util.ArrayList;
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.slf4j.Logger;
import org.slf4j.LoggerFactory;
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.AdminUserStatusEnum;
import com.certusnet.xproject.admin.consts.em.AdminUserTypeEnum;
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.AdminUserService;
import com.certusnet.xproject.admin.web.LoginToken;
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.Result;
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;
/**
* 管理后台-用户管理
*
* @author pengpeng
* @date 2017年5月4日 下午3:55:23
* @version 1.0
*/
@RestController
public class AdminUserMgtController extends BaseController {

@SuppressWarnings("unused")
private static final Logger logger = LoggerFactory.getLogger(AdminUserMgtController.class);

@Resource(name="adminUserFacadeService")
private AdminUserService adminUserService;

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

/**
* 查询用户列表
* @param request
* @param response
* @param userQueryForm
* @param orderBy
* @param pager
* @return
*/
@RequestMapping(value="/admin/user/list")
public Object listRole(HttpServletRequest request, HttpServletResponse response, AdminUser userQueryForm, OrderBy orderBy, Pager pager) {
PagingList<AdminUser> dataList = adminUserService.getUserList(userQueryForm, pager, orderBy);
return genSuccessPagingResult(dataList);
}

/**
* 新增用户
* @param request
* @param response
* @param userAddForm
* @return
*/
@RequestMapping(value="/admin/user/add/submit", method=POST)
public Object addUser(HttpServletRequest request, HttpServletResponse response, @RequestBody AdminUser userAddForm) {
LoginToken<AdminUser> loginToken = ShiroUtils.getSessionAttribute(LoginToken.LOGIN_TOKEN_SESSION_KEY);
userAddForm.setCreateTime(DateTimeUtils.formatNow());
userAddForm.setCreateBy(loginToken.getLoginId());
userAddForm.setStatus(AdminUserStatusEnum.ADMIN_USER_STATUS_ENABLED.getStatusCode());
userAddForm.setUserType(AdminUserTypeEnum.ADMIN_USER_TYPE_NORMAL.getTypeCode());
adminUserService.createUser(userAddForm);
return genSuccessResult("保存成功!", null);
}

/**
* 修改用户
* @param request
* @param response
* @param userAddForm
* @param modelMap
* @return
*/
@RequestMapping(value="/admin/user/edit/submit", method=POST)
public Object editUser(HttpServletRequest request, HttpServletResponse response, @RequestBody AdminUser userEditForm) {
LoginToken<AdminUser> loginToken = ShiroUtils.getSessionAttribute(LoginToken.LOGIN_TOKEN_SESSION_KEY);
userEditForm.setUpdateBy(loginToken.getLoginId());
userEditForm.setUpdateTime(DateTimeUtils.formatNow());
adminUserService.updateUser(userEditForm);
return genSuccessResult("保存成功!", null);
}

/**
* 删除用户
* @param request
* @param response
* @param id
* @return
*/
@RequestMapping(value="/admin/user/del")
public Object delUser(HttpServletRequest request, HttpServletResponse response, Long userId) {
AdminUser user = new AdminUser();
user.setUserId(userId);
adminUserService.deleteUserById(user);
return genSuccessResult("删除成功!", null);
}

/**
* 修改密码
* @param request
* @param response
* @param passwdEditForm
* @return
*/
@RequestMapping(value="/admin/user/changepwd/submit", method=POST)
public Object changeUserPasswd(HttpServletRequest request, HttpServletResponse response, @RequestBody AdminUser passwdEditForm, Boolean forceUpdate) {
if(forceUpdate == null){
forceUpdate = false;
}
adminUserService.updatePassword(passwdEditForm, forceUpdate);
return genSuccessResult("修改成功!", null);
}

/**
* 启用用户
* @param request
* @param response
* @param userId
* @return
*/
@RequestMapping(value="/admin/user/enable")
public Object enableUser(HttpServletRequest request, HttpServletResponse response, Long userId) {
return updateUserStatus(request, response, userId, AdminUserStatusEnum.ADMIN_USER_STATUS_ENABLED);
}

/**
* 禁用用户
* @param request
* @param response
* @param userId
* @return
*/
@RequestMapping(value="/admin/user/disable")
public Object disableUser(HttpServletRequest request, HttpServletResponse response, Long userId) {
return updateUserStatus(request, response, userId, AdminUserStatusEnum.ADMIN_USER_STATUS_DISABLED);
}

protected Result<Object> updateUserStatus(HttpServletRequest request, HttpServletResponse response, Long userId, AdminUserStatusEnum targetStatus){
AdminUser user = new AdminUser();
user.setUserId(userId);
user.setStatus(targetStatus.getStatusCode());
adminUserService.updateUserStatus(user);
return genSuccessResult(targetStatus.getStatusName() + "成功!", null);
}

/**
* 获取用户拥有的角色列表
* @param request
* @param response
* @param userId
* @return
*/
@RequestMapping(value="/admin/user/roles")
public Object loadUserRoles(HttpServletRequest request, HttpServletResponse response, Long userId) {
List<AdminRole> roleList = adminUserService.getUserRoleList(userId);
return genSuccessResult(roleList);
}

/**
* 添加用户-角色配置
* @param request
* @param response
* @param userId
* @param roleIds
* @return
*/
@RequestMapping(value="/admin/user/config/add", method=POST)
public Object addUserRoles(HttpServletRequest request, HttpServletResponse response, @RequestBody Map<String,Object> parameter) {
Long userId = MapUtils.getLong(parameter, "userId");
String roleIds = MapUtils.getString(parameter, "roleIds");
List<Long> roleIdList = new ArrayList<Long>();
if(!StringUtils.isEmpty(roleIds)){
String[] roleIdArray = roleIds.split(",");
if(roleIdArray != null && roleIdArray.length > 0){
for(String roleId : roleIdArray){
roleIdList.add(Long.valueOf(roleId));
}
}
}

LoginToken<AdminUser> loginToken = ShiroUtils.getSessionAttribute(LoginToken.LOGIN_TOKEN_SESSION_KEY);
AdminUser user = new AdminUser();
user.setUserId(userId);
adminUserService.addUserRoles(user, roleIdList, loginToken.getLoginId(), DateTimeUtils.formatNow());
return genSuccessResult("添加成功!", null);
}

/**
* 删除户-角色配置
* @param request
* @param response
* @param userId
* @param roleIds
* @return
*/
@RequestMapping(value="/admin/user/config/del", method=POST)
public Object delUserRoles(HttpServletRequest request, HttpServletResponse response, @RequestBody Map<String,Object> parameter) {
Long userId = MapUtils.getLong(parameter, "userId");
String roleIds = MapUtils.getString(parameter, "roleIds");
List<Long> roleIdList = new ArrayList<Long>();
if(!StringUtils.isEmpty(roleIds)){
String[] roleIdArray = roleIds.split(",");
if(roleIdArray != null && roleIdArray.length > 0){
for(String roleId : roleIdArray){
roleIdList.add(Long.valueOf(roleId));
}
}
}
AdminUser user = new AdminUser();
user.setUserId(userId);
adminUserService.delUserRoles(user, roleIdList);
return genSuccessResult("删除成功!", null);
}

/**
* 查询用户
* @param request
* @param response
* @param userSearchForm
* @param pager
* @param orderBy
* @return
*/
@RequestMapping("/admin/user/search")
public Object searchUsers(HttpServletRequest request, HttpServletResponse response, AdminUser userSearchForm, Pager pager, OrderBy orderBy) {
userSearchForm.setStatus(AdminUserStatusEnum.ADMIN_USER_STATUS_ENABLED.getStatusCode());
PagingList<AdminUser> dataList = adminUserService.getUserList(userSearchForm, pager, orderBy);
return genSuccessPagingResult(dataList);
}

}
Loading

0 comments on commit 38501bd

Please sign in to comment.