Sfoglia il codice sorgente

增加用户组织、用户角色、用户权限按钮操作

shuzheng 9 anni fa
parent
commit
1384226c85

+ 94 - 15
zheng-upms/zheng-upms-server/src/main/java/com/zheng/upms/server/controller/manage/UpmsUserController.java

@@ -8,15 +8,12 @@ import com.zheng.common.validator.LengthValidator;
 import com.zheng.common.validator.NotNullValidator;
 import com.zheng.upms.common.constant.UpmsResult;
 import com.zheng.upms.common.constant.UpmsResultConstant;
-import com.zheng.upms.dao.model.UpmsUser;
-import com.zheng.upms.dao.model.UpmsUserExample;
-import com.zheng.upms.rpc.api.UpmsUserOrganizationService;
-import com.zheng.upms.rpc.api.UpmsUserPermissionService;
-import com.zheng.upms.rpc.api.UpmsUserRoleService;
-import com.zheng.upms.rpc.api.UpmsUserService;
+import com.zheng.upms.dao.model.*;
+import com.zheng.upms.rpc.api.*;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang.math.NumberUtils;
 import org.apache.shiro.authz.annotation.RequiresPermissions;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -25,6 +22,7 @@ import org.springframework.stereotype.Controller;
 import org.springframework.ui.ModelMap;
 import org.springframework.web.bind.annotation.*;
 
+import javax.servlet.http.HttpServletRequest;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -44,14 +42,20 @@ public class UpmsUserController extends BaseController {
     private UpmsUserService upmsUserService;
 
     @Autowired
-    private UpmsUserRoleService upmsUserRoleService;
+    private UpmsRoleService upmsRoleService;
 
     @Autowired
-    private UpmsUserPermissionService upmsUserPermissionService;
+    private UpmsOrganizationService upmsOrganizationService;
 
     @Autowired
     private UpmsUserOrganizationService upmsUserOrganizationService;
 
+    @Autowired
+    private UpmsUserRoleService upmsUserRoleService;
+
+    @Autowired
+    private UpmsUserPermissionService upmsUserPermissionService;
+
     @ApiOperation(value = "用户首页")
     @RequiresPermissions("upms:user:read")
     @RequestMapping(value = "/index", method = RequestMethod.GET)
@@ -59,13 +63,88 @@ public class UpmsUserController extends BaseController {
         return "/manage/user/index";
     }
 
-    @ApiOperation(value = "用户授权")
-    @RequiresPermissions("upms:user:permission")
-    @RequestMapping(value = "/permission/{id}", method = RequestMethod.GET)
-    public String permission(@PathVariable("id") int id, ModelMap modelMap) {
-        UpmsUser user = upmsUserService.selectByPrimaryKey(id);
-        modelMap.put("user", user);
-        return "/manage/user/permission";
+    @ApiOperation(value = "用户组织")
+    @RequiresPermissions("upms:user:organization")
+    @RequestMapping(value = "/organization/{id}", method = RequestMethod.GET)
+    public String organization(@PathVariable("id") int id, ModelMap modelMap) {
+        // 所有组织
+        List<UpmsOrganization> upmsOrganizations = upmsOrganizationService.selectByExample(new UpmsOrganizationExample());
+        // 用户拥有组织
+        UpmsUserOrganizationExample upmsUserOrganizationExample = new UpmsUserOrganizationExample();
+        upmsUserOrganizationExample.createCriteria()
+                .andUserIdEqualTo(id);
+        List<UpmsUserOrganization> upmsUserOrganizations = upmsUserOrganizationService.selectByExample(upmsUserOrganizationExample);
+        modelMap.put("upmsOrganizations", upmsOrganizations);
+        modelMap.put("upmsUserOrganizations", upmsUserOrganizations);
+        return "/manage/user/organization";
+    }
+
+    @ApiOperation(value = "用户组织")
+    @RequiresPermissions("upms:user:organization")
+    @RequestMapping(value = "/organization/{id}", method = RequestMethod.POST)
+    @ResponseBody
+    public Object organization(@PathVariable("id") int id, HttpServletRequest request) {
+        String[] organizationIds = request.getParameterValues("organizationId");
+        // 删除旧记录
+        UpmsUserOrganizationExample upmsUserOrganizationExample = new UpmsUserOrganizationExample();
+        upmsUserOrganizationExample.createCriteria()
+                .andUserIdEqualTo(id);
+        upmsUserOrganizationService.deleteByExample(upmsUserOrganizationExample);
+        // 增加新记录
+        if (null != organizationIds) {
+            for (String organizationId : organizationIds) {
+                if (StringUtils.isBlank(organizationId)) {
+                    continue;
+                }
+                UpmsUserOrganization upmsUserOrganization = new UpmsUserOrganization();
+                upmsUserOrganization.setUserId(id);
+                upmsUserOrganization.setOrganizationId(NumberUtils.toInt(organizationId));
+                upmsUserOrganizationService.insertSelective(upmsUserOrganization);
+            }
+        }
+        return new UpmsResult(UpmsResultConstant.SUCCESS, "");
+    }
+
+    @ApiOperation(value = "用户角色")
+    @RequiresPermissions("upms:user:role")
+    @RequestMapping(value = "/role/{id}", method = RequestMethod.GET)
+    public String role(@PathVariable("id") int id, ModelMap modelMap) {
+        // 所有角色
+        List<UpmsRole> upmsRoles = upmsRoleService.selectByExample(new UpmsRoleExample());
+        // 用户拥有角色
+        UpmsUserRoleExample upmsUserRoleExample = new UpmsUserRoleExample();
+        upmsUserRoleExample.createCriteria()
+                .andUserIdEqualTo(id);
+        List<UpmsUserRole> upmsUserRoles = upmsUserRoleService.selectByExample(upmsUserRoleExample);
+        modelMap.put("upmsRoles", upmsRoles);
+        modelMap.put("upmsUserRoles", upmsUserRoles);
+        return "/manage/user/role";
+    }
+
+    @ApiOperation(value = "用户角色")
+    @RequiresPermissions("upms:user:role")
+    @RequestMapping(value = "/role/{id}", method = RequestMethod.POST)
+    @ResponseBody
+    public Object role(@PathVariable("id") int id, HttpServletRequest request) {
+        String[] roleIds = request.getParameterValues("roleId");
+        // 删除旧记录
+        UpmsUserRoleExample upmsUserRoleExample = new UpmsUserRoleExample();
+        upmsUserRoleExample.createCriteria()
+                .andUserIdEqualTo(id);
+        upmsUserRoleService.deleteByExample(upmsUserRoleExample);
+        // 增加新记录
+        if (null != roleIds) {
+            for (String roleId : roleIds) {
+                if (StringUtils.isBlank(roleId)) {
+                    continue;
+                }
+                UpmsUserRole upmsUserRole = new UpmsUserRole();
+                upmsUserRole.setUserId(id);
+                upmsUserRole.setRoleId(NumberUtils.toInt(roleId));
+                upmsUserRoleService.insertSelective(upmsUserRole);
+            }
+        }
+        return new UpmsResult(UpmsResultConstant.SUCCESS, "");
     }
 
     @ApiOperation(value = "用户列表")

+ 1 - 1
zheng-upms/zheng-upms-server/src/main/webapp/WEB-INF/jsp/manage/permission/index.jsp

@@ -106,7 +106,7 @@ function createAction() {
 		content: 'url:${basePath}/manage/permission/create',
 		onContentReady: function () {
 			initMaterialInput();
-			$('select').select2({placeholder: "Select a state"});
+			$('select').select2();
 		}
 	});
 }

+ 75 - 3
zheng-upms/zheng-upms-server/src/main/webapp/WEB-INF/jsp/manage/user/index.jsp

@@ -21,7 +21,9 @@
 		<shiro:hasPermission name="upms:user:create"><a class="waves-effect waves-button" href="javascript:;" onclick="createAction()"><i class="zmdi zmdi-plus"></i> 新增用户</a></shiro:hasPermission>
 		<shiro:hasPermission name="upms:user:update"><a class="waves-effect waves-button" href="javascript:;" onclick="updateAction()"><i class="zmdi zmdi-edit"></i> 编辑用户</a></shiro:hasPermission>
 		<shiro:hasPermission name="upms:user:delete"><a class="waves-effect waves-button" href="javascript:;" onclick="deleteAction()"><i class="zmdi zmdi-close"></i> 删除用户</a></shiro:hasPermission>
-		<shiro:hasPermission name="upms:user:permission"><a class="waves-effect waves-button" href="javascript:;" onclick="permissionAction()"><i class="zmdi zmdi-key"></i> 用户授权</a></shiro:hasPermission>
+		<shiro:hasPermission name="upms:user:organization"><a class="waves-effect waves-button" href="javascript:;" onclick="organizationAction()"><i class="zmdi zmdi-accounts-list"></i> 用户组织</a></shiro:hasPermission>
+		<shiro:hasPermission name="upms:user:role"><a class="waves-effect waves-button" href="javascript:;" onclick="roleAction()"><i class="zmdi zmdi-accounts"></i> 用户角色</a></shiro:hasPermission>
+		<shiro:hasPermission name="upms:user:permission"><a class="waves-effect waves-button" href="javascript:;" onclick="permissionAction()"><i class="zmdi zmdi-key"></i> 用户权限</a></shiro:hasPermission>
 	</div>
 	<table id="table"></table>
 </div>
@@ -233,8 +235,77 @@ function deleteAction() {
 		});
 	}
 }
-// 授权
+// 用户组织
+var organizationDialog;
+var organizationUserId;
+function organizationAction() {
+	var rows = $table.bootstrapTable('getSelections');
+	if (rows.length != 1) {
+		$.confirm({
+			title: false,
+			content: '请选择一条记录!',
+			autoClose: 'cancel|3000',
+			backgroundDismiss: true,
+			buttons: {
+				cancel: {
+					text: '取消',
+					btnClass: 'waves-effect waves-button'
+				}
+			}
+		});
+	} else {
+		organizationUserId = rows[0].userId;
+		organizationDialog = $.dialog({
+			animationSpeed: 300,
+			title: '用户组织',
+			content: 'url:${basePath}/manage/user/organization/' + organizationUserId,
+			onContentReady: function () {
+				initMaterialInput();
+				$('select').select2({
+					placeholder: '请选择用户组织',
+					allowClear: true
+				});
+			}
+		});
+	}
+}
+// 用户角色
+var roleDialog;
+var roleUserId;
+function roleAction() {
+	var rows = $table.bootstrapTable('getSelections');
+	if (rows.length != 1) {
+		$.confirm({
+			title: false,
+			content: '请选择一条记录!',
+			autoClose: 'cancel|3000',
+			backgroundDismiss: true,
+			buttons: {
+				cancel: {
+					text: '取消',
+					btnClass: 'waves-effect waves-button'
+				}
+			}
+		});
+	} else {
+		roleUserId = rows[0].userId;
+		roleDialog = $.dialog({
+			animationSpeed: 300,
+			title: '用户角色',
+			content: 'url:${basePath}/manage/user/role/' + roleUserId,
+			onContentReady: function () {
+				initMaterialInput();
+				$('select').select2({
+					placeholder: '请选择用户角色',
+					allowClear: true
+				});
+			}
+		});
+	}
+}
+// 用户权限
 var permissionDialog;
+var permissionUserId;
 function permissionAction() {
 	var rows = $table.bootstrapTable('getSelections');
 	if (rows.length != 1) {
@@ -251,10 +322,11 @@ function permissionAction() {
 			}
 		});
 	} else {
+		permissionUserId = rows[0].userId;
 		permissionDialog = $.dialog({
 			animationSpeed: 300,
 			title: '用户授权',
-			content: 'url:${basePath}/manage/user/permission/' + rows[0].userId,
+			content: 'url:${basePath}/manage/user/permission/' + permissionUserId,
 			onContentReady: function () {
 				initMaterialInput();
 			}

+ 88 - 0
zheng-upms/zheng-upms-server/src/main/webapp/WEB-INF/jsp/manage/user/organization.jsp

@@ -0,0 +1,88 @@
+<%@ page contentType="text/html; charset=utf-8"%>
+<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
+<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
+<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
+<%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%>
+<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
+<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
+<c:set var="basePath" value="${pageContext.request.contextPath}"/>
+<div id="organizationDialog" class="crudDialog">
+	<form id="organizationForm" method="post">
+		<div class="form-group">
+			<select id="organizationId" name="organizationId" multiple="multiple" style="width: 100%">
+				<c:forEach var="upmsOrganization" items="${upmsOrganizations}">
+					<option value="${upmsOrganization.organizationId}" <c:forEach var="upmsUserOrganization" items="${upmsUserOrganizations}"><c:if test="${upmsOrganization.organizationId==upmsUserOrganization.organizationId}">selected="selected"</c:if></c:forEach>>${upmsOrganization.name}</option>
+				</c:forEach>
+			</select>
+		</div>
+		<div class="form-group text-right dialog-buttons">
+			<a class="waves-effect waves-button" href="javascript:;" onclick="organizationSubmit();">保存</a>
+			<a class="waves-effect waves-button" href="javascript:;" onclick="organizationDialog.close();">取消</a>
+		</div>
+	</form>
+</div>
+<script>
+function organizationSubmit() {
+    $.ajax({
+        type: 'post',
+        url: '${basePath}/manage/user/organization/' + organizationUserId,
+        data: $('#organizationForm').serialize(),
+		beforeSend: function() {
+
+		},
+        success: function(result) {
+			if (result.code != 1) {
+				if (result.data instanceof Array) {
+					$.each(result.data, function(index, value) {
+						$.confirm({
+							theme: 'dark',
+							animation: 'rotateX',
+							closeAnimation: 'rotateX',
+							title: false,
+							content: value.errorMsg,
+							buttons: {
+								confirm: {
+									text: '确认',
+									btnClass: 'waves-effect waves-button waves-light'
+								}
+							}
+						});
+					});
+				} else {
+						$.confirm({
+							theme: 'dark',
+							animation: 'rotateX',
+							closeAnimation: 'rotateX',
+							title: false,
+							content: result.data.errorMsg,
+							buttons: {
+								confirm: {
+									text: '确认',
+									btnClass: 'waves-effect waves-button waves-light'
+								}
+							}
+						});
+				}
+			} else {
+				organizationDialog.close();
+				$table.bootstrapTable('refresh');
+			}
+        },
+        error: function(XMLHttpRequest, textStatus, errorThrown) {
+			$.confirm({
+				theme: 'dark',
+				animation: 'rotateX',
+				closeAnimation: 'rotateX',
+				title: false,
+				content: textStatus,
+				buttons: {
+					confirm: {
+						text: '确认',
+						btnClass: 'waves-effect waves-button waves-light'
+					}
+				}
+			});
+        }
+    });
+}
+</script>

+ 96 - 0
zheng-upms/zheng-upms-server/src/main/webapp/WEB-INF/jsp/manage/user/permission.jsp

@@ -0,0 +1,96 @@
+<%@ page contentType="text/html; charset=utf-8"%>
+<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
+<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
+<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
+<%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%>
+<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
+<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
+<c:set var="basePath" value="${pageContext.request.contextPath}"/>
+<div id="permissionDialog" class="crudDialog">
+	<form id="permissionForm" method="post">
+		<div class="form-group">
+			<select id="systemId" name="systemId">
+				<option value="0">请选择系统</option>
+				<c:forEach var="upmsSystem" items="${upmsSystems}">
+					<option value="${upmsSystem.systemId}">${upmsSystem.title}</option>
+				</c:forEach>
+			</select>
+		</div>
+		<div class="form-group text-right dialog-buttons">
+			<a class="waves-effect waves-button" href="javascript:;" onclick="permissionSubmit();">保存</a>
+			<a class="waves-effect waves-button" href="javascript:;" onclick="permissionDialog.close();">取消</a>
+		</div>
+	</form>
+</div>
+<script>
+function permissionSubmit() {
+    $.ajax({
+        type: 'post',
+        url: '${basePath}/manage/user/permission',
+        data: $('#permissionForm').serialize(),
+        beforeSend: function() {
+            if ($('#name').val() == '') {
+                $('#name').focus();
+                return false;
+            }
+			if ($('#title').val() == '') {
+				$('#title').focus();
+				return false;
+			}
+        },
+        success: function(result) {
+			if (result.code != 1) {
+				if (result.data instanceof Array) {
+					$.each(result.data, function(index, value) {
+						$.confirm({
+							theme: 'dark',
+							animation: 'rotateX',
+							closeAnimation: 'rotateX',
+							title: false,
+							content: value.errorMsg,
+							buttons: {
+								confirm: {
+									text: '确认',
+									btnClass: 'waves-effect waves-button waves-light'
+								}
+							}
+						});
+					});
+				} else {
+						$.confirm({
+							theme: 'dark',
+							animation: 'rotateX',
+							closeAnimation: 'rotateX',
+							title: false,
+							content: result.data.errorMsg,
+							buttons: {
+								confirm: {
+									text: '确认',
+									btnClass: 'waves-effect waves-button waves-light'
+								}
+							}
+						});
+				}
+			} else {
+				permissionDialog.close();
+				$table.bootstrapTable('refresh');
+			}
+        },
+        error: function(XMLHttpRequest, textStatus, errorThrown) {
+			$.confirm({
+				theme: 'dark',
+				animation: 'rotateX',
+				closeAnimation: 'rotateX',
+				title: false,
+				content: textStatus,
+				buttons: {
+					confirm: {
+						text: '确认',
+						btnClass: 'waves-effect waves-button waves-light'
+					}
+				}
+			});
+        }
+    });
+}
+</script>

+ 88 - 0
zheng-upms/zheng-upms-server/src/main/webapp/WEB-INF/jsp/manage/user/role.jsp

@@ -0,0 +1,88 @@
+<%@ page contentType="text/html; charset=utf-8"%>
+<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
+<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
+<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
+<%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%>
+<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
+<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
+<c:set var="basePath" value="${pageContext.request.contextPath}"/>
+<div id="roleDialog" class="crudDialog">
+	<form id="roleForm" method="post">
+		<div class="form-group">
+			<select id="organizationId" name="organizationId" multiple="multiple" style="width: 100%">
+				<c:forEach var="upmsRole" items="${upmsRoles}">
+					<option value="${upmsRole.roleId}" <c:forEach var="upmsUserRole" items="${upmsUserRoles}"><c:if test="${upmsRole.roleId==upmsUserRole.roleId}">selected="selected"</c:if></c:forEach>>${upmsRole.title}</option>
+				</c:forEach>
+			</select>
+		</div>
+		<div class="form-group text-right dialog-buttons">
+			<a class="waves-effect waves-button" href="javascript:;" onclick="roleSubmit();">保存</a>
+			<a class="waves-effect waves-button" href="javascript:;" onclick="roleDialog.close();">取消</a>
+		</div>
+	</form>
+</div>
+<script>
+function roleSubmit() {
+    $.ajax({
+        type: 'post',
+        url: '${basePath}/manage/user/role/' + roleUserId,
+        data: $('#roleForm').serialize(),
+		beforeSend: function() {
+
+		},
+        success: function(result) {
+			if (result.code != 1) {
+				if (result.data instanceof Array) {
+					$.each(result.data, function(index, value) {
+						$.confirm({
+							theme: 'dark',
+							animation: 'rotateX',
+							closeAnimation: 'rotateX',
+							title: false,
+							content: value.errorMsg,
+							buttons: {
+								confirm: {
+									text: '确认',
+									btnClass: 'waves-effect waves-button waves-light'
+								}
+							}
+						});
+					});
+				} else {
+						$.confirm({
+							theme: 'dark',
+							animation: 'rotateX',
+							closeAnimation: 'rotateX',
+							title: false,
+							content: result.data.errorMsg,
+							buttons: {
+								confirm: {
+									text: '确认',
+									btnClass: 'waves-effect waves-button waves-light'
+								}
+							}
+						});
+				}
+			} else {
+				roleDialog.close();
+				$table.bootstrapTable('refresh');
+			}
+        },
+        error: function(XMLHttpRequest, textStatus, errorThrown) {
+			$.confirm({
+				theme: 'dark',
+				animation: 'rotateX',
+				closeAnimation: 'rotateX',
+				title: false,
+				content: textStatus,
+				buttons: {
+					confirm: {
+						text: '确认',
+						btnClass: 'waves-effect waves-button waves-light'
+					}
+				}
+			});
+        }
+    });
+}
+</script>