diff --git a/doc/new_intall_20180309.sql b/doc/new_intall_20180309.sql index e266d56c4..7fb75ccf5 100644 --- a/doc/new_intall_20180309.sql +++ b/doc/new_intall_20180309.sql @@ -59,7 +59,7 @@ insert into sys_user values('2', '8', 'ry', '若依', 'ry@163.com', '152 drop table if exists sys_role; create table sys_role ( role_id int(10) not null auto_increment comment '角色ID', - role_name varchar(30) not null comment '角色名', + role_name varchar(30) not null comment '角色名称', role_key varchar(100) not null comment '角色权限字符串', role_sort int(10) not null comment '显示顺序', status int(1) default 0 comment '角色状态:0正常,1禁用', @@ -189,7 +189,6 @@ insert into sys_role_menu values ('1', '21'); insert into sys_role_menu values ('1', '22'); insert into sys_role_menu values ('1', '23'); insert into sys_role_menu values ('1', '24'); -insert into sys_role_menu values ('1', '25'); -- ---------------------------- -- 7、操作日志记录 -- ---------------------------- diff --git a/src/main/java/com/ruoyi/common/utils/TreeUtils.java b/src/main/java/com/ruoyi/common/utils/TreeUtils.java index 58c240152..62661d3fa 100644 --- a/src/main/java/com/ruoyi/common/utils/TreeUtils.java +++ b/src/main/java/com/ruoyi/common/utils/TreeUtils.java @@ -142,55 +142,4 @@ public class TreeUtils { return getChildList(list, t).size() > 0 ? true : false; } - - /** - * 本地模拟数据测试 - */ - public static void main(String[] args) - { - long start = System.currentTimeMillis(); - List permList = new ArrayList(); - - Menu perm1 = new Menu(); - perm1.setMenuId(100); - perm1.setMenuName("系统管理"); - perm1.setParentId(0); - - Menu perm2 = new Menu(); - perm2.setMenuId(101); - perm2.setMenuName("用户管理"); - perm2.setParentId(100); - - Menu perm3 = new Menu(); - perm3.setMenuId(102); - perm3.setMenuName("角色管理"); - perm3.setParentId(100); - - Menu perm4 = new Menu(); - perm4.setMenuId(103); - perm4.setMenuName("菜单管理"); - perm4.setParentId(100); - - Menu perm5 = new Menu(); - perm5.setMenuId(103); - perm5.setMenuName("日志管理"); - perm5.setParentId(100); - - permList.add(perm1); - permList.add(perm2); - permList.add(perm3); - permList.add(perm4); - permList.add(perm5); - - List ns = TreeUtils.getChildPerms(permList, 0); - for (Menu m : ns) - { - System.out.println(m.getMenuName()); - System.out.println(m.getChildren()); - } - long end = System.currentTimeMillis(); - System.out.println("用时:" + (end - start) + "ms"); - - } - } diff --git a/src/main/java/com/ruoyi/project/system/menu/controller/MenuController.java b/src/main/java/com/ruoyi/project/system/menu/controller/MenuController.java new file mode 100644 index 000000000..9d8f09b67 --- /dev/null +++ b/src/main/java/com/ruoyi/project/system/menu/controller/MenuController.java @@ -0,0 +1,49 @@ +package com.ruoyi.project.system.menu.controller; + +import java.util.List; +import java.util.Map; + +import org.apache.shiro.authz.annotation.RequiresPermissions; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; + +import com.ruoyi.framework.web.controller.BaseController; +import com.ruoyi.project.system.menu.service.IMenuService; + +/** + * 角色信息 + * + * @author ruoyi + */ +@Controller +@RequestMapping("/system/menu") +public class MenuController extends BaseController +{ + + private String prefix = "system/menu"; + + @Autowired + private IMenuService menuService; + + @RequiresPermissions("system:menu:view") + @GetMapping() + public String user() + { + return prefix + "/menu"; + } + + /** + * 加载菜单列表树 + */ + @GetMapping("/treeData/{roleId}") + @ResponseBody + public List> treeData(@PathVariable("roleId") Long roleId) + { + List> tree = menuService.selectMenuTree(roleId); + return tree; + } +} \ No newline at end of file diff --git a/src/main/java/com/ruoyi/project/system/menu/dao/IMenuDao.java b/src/main/java/com/ruoyi/project/system/menu/dao/IMenuDao.java index 221023525..0950e1c07 100644 --- a/src/main/java/com/ruoyi/project/system/menu/dao/IMenuDao.java +++ b/src/main/java/com/ruoyi/project/system/menu/dao/IMenuDao.java @@ -27,6 +27,14 @@ public interface IMenuDao */ public List selectPermsByUserId(Long userId); + /** + * 根据角色ID查询菜单 + * + * @param roleId 角色ID + * @return 菜单列表 + */ + public List selectMenuTree(Long roleId); + /** * 查询系统所有权限 * diff --git a/src/main/java/com/ruoyi/project/system/menu/dao/MenuDaoImpl.java b/src/main/java/com/ruoyi/project/system/menu/dao/MenuDaoImpl.java index 8e67f81e2..0a76e29eb 100644 --- a/src/main/java/com/ruoyi/project/system/menu/dao/MenuDaoImpl.java +++ b/src/main/java/com/ruoyi/project/system/menu/dao/MenuDaoImpl.java @@ -45,16 +45,36 @@ public class MenuDaoImpl extends DynamicObjectBaseDao implements IMenuDao @Override public List selectPermsByUserId(Long userId) { - List permsList = null; + List menuList = null; try { - permsList = this.findForList("SystemMenuMapper.selectPermsByUserId", userId); + menuList = this.findForList("SystemMenuMapper.selectPermsByUserId", userId); } catch (Exception e) { e.printStackTrace(); } - return permsList; + return menuList; + } + + /** + * 根据角色ID查询菜单 + * + * @param roleId 角色ID + * @return 菜单列表 + */ + public List selectMenuTree(Long roleId) + { + List menuList = null; + try + { + menuList = this.findForList("SystemMenuMapper.selectMenuTree", roleId); + } + catch (Exception e) + { + e.printStackTrace(); + } + return menuList; } /** diff --git a/src/main/java/com/ruoyi/project/system/menu/domain/Menu.java b/src/main/java/com/ruoyi/project/system/menu/domain/Menu.java index ebf56d10d..95eed8217 100644 --- a/src/main/java/com/ruoyi/project/system/menu/domain/Menu.java +++ b/src/main/java/com/ruoyi/project/system/menu/domain/Menu.java @@ -13,11 +13,11 @@ import lombok.Data; public class Menu { /** 菜单ID */ - private Integer menuId; + private Long menuId; /** 菜单名称 */ private String menuName; /** 父菜单ID */ - private Integer parentId; + private Long parentId; /** 显示顺序 */ private String orderNum; /** 菜单URL */ diff --git a/src/main/java/com/ruoyi/project/system/menu/service/IMenuService.java b/src/main/java/com/ruoyi/project/system/menu/service/IMenuService.java index 2950a04cf..ae08a8f2c 100644 --- a/src/main/java/com/ruoyi/project/system/menu/service/IMenuService.java +++ b/src/main/java/com/ruoyi/project/system/menu/service/IMenuService.java @@ -29,6 +29,14 @@ public interface IMenuService */ public Set selectPermsByUserId(Long userId); + /** + * 根据角色ID查询菜单 + * + * @param roleId 角色ID + * @return 菜单列表 + */ + public List> selectMenuTree(Long roleId); + /** * 查询系统所有权限 * diff --git a/src/main/java/com/ruoyi/project/system/menu/service/MenuServiceImpl.java b/src/main/java/com/ruoyi/project/system/menu/service/MenuServiceImpl.java index a557bfdb5..366b0d25c 100644 --- a/src/main/java/com/ruoyi/project/system/menu/service/MenuServiceImpl.java +++ b/src/main/java/com/ruoyi/project/system/menu/service/MenuServiceImpl.java @@ -1,13 +1,18 @@ package com.ruoyi.project.system.menu.service; import java.text.MessageFormat; +import java.util.ArrayList; import java.util.Arrays; +import java.util.HashMap; import java.util.HashSet; import java.util.LinkedHashMap; import java.util.List; +import java.util.Map; import java.util.Set; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; + import com.ruoyi.common.utils.StringUtils; import com.ruoyi.common.utils.TreeUtils; import com.ruoyi.project.system.menu.dao.IMenuDao; @@ -60,6 +65,29 @@ public class MenuServiceImpl implements IMenuService return permsSet; } + /** + * 根据角色ID查询菜单 + * + * @param roleId 角色ID + * @return 菜单列表 + */ + public List> selectMenuTree(Long roleId) + { + List> trees = new ArrayList>(); + List roleMenuList = menuDao.selectMenuTree(roleId); + List menuList = menuDao.selectPermsAll(); + for (Menu menu : menuList) + { + Map deptMap = new HashMap(); + deptMap.put("id", menu.getMenuId()); + deptMap.put("pId", menu.getParentId()); + deptMap.put("name", menu.getMenuName()); + deptMap.put("checked", roleMenuList.contains(menu.getMenuId() + menu.getPerms())); + trees.add(deptMap); + } + return trees; + } + /** * 查询系统所有权限 * @@ -80,4 +108,13 @@ public class MenuServiceImpl implements IMenuService return section; } + public static void main(String[] args) + { + List list = new ArrayList(); + list.add(1L); + list.add(2L); + list.add(3L); + System.out.println(list.contains(Long.valueOf(1))); + } + } diff --git a/src/main/java/com/ruoyi/project/system/role/controller/RoleController.java b/src/main/java/com/ruoyi/project/system/role/controller/RoleController.java index 547b15854..725f98ada 100644 --- a/src/main/java/com/ruoyi/project/system/role/controller/RoleController.java +++ b/src/main/java/com/ruoyi/project/system/role/controller/RoleController.java @@ -3,13 +3,13 @@ package com.ruoyi.project.system.role.controller; import org.apache.shiro.authz.annotation.RequiresPermissions; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; - import com.ruoyi.framework.aspectj.lang.annotation.Log; import com.ruoyi.framework.web.controller.BaseController; import com.ruoyi.framework.web.domain.JSON; @@ -31,7 +31,7 @@ public class RoleController extends BaseController @Autowired private IRoleService roleService; - + @RequiresPermissions("system:role:view") @GetMapping() public String user() @@ -47,7 +47,19 @@ public class RoleController extends BaseController TableDataInfo rows = roleService.pageInfoQuery(getPageUtilEntity()); return rows; } - + + /** + * 修改角色 + */ + @Log(title = "系统管理", action = "角色管理-修改角色") + @GetMapping("/edit/{roleId}") + public String edit(@PathVariable("roleId") Long roleId, Model model) + { + Role role = roleService.selectRoleById(roleId); + model.addAttribute("role", role); + return prefix + "/edit"; + } + @Log(title = "系统管理", action = "角色管理-删除角色") @RequestMapping("/remove/{roleId}") @ResponseBody diff --git a/src/main/resources/application-druid.yml b/src/main/resources/application-druid.yml index 7fe61c6e4..deb76e32e 100644 --- a/src/main/resources/application-druid.yml +++ b/src/main/resources/application-druid.yml @@ -7,10 +7,10 @@ spring: datasource: type: com.alibaba.druid.pool.DruidDataSource driverClassName: com.mysql.jdbc.Driver - url: jdbc:mysql://10.213.24.45:3306/ry?useUnicode=true&characterEncoding=utf8 - #url: jdbc:mysql://localhost:3306/ry?useUnicode=true&characterEncoding=utf8 - username: root - password: password + #url: jdbc:mysql://10.213.24.45:3306/ry?useUnicode=true&characterEncoding=utf8 + url: jdbc:mysql://123.207.20.136:3306/ry?useUnicode=true&characterEncoding=utf8 + username: ruoyi + password: 123456 # 初始化大小,最小,最大 initialSize: 1 minIdle: 3 diff --git a/src/main/resources/mybatis/system/SystemMenuMapper.xml b/src/main/resources/mybatis/system/SystemMenuMapper.xml index e616efe66..d48cf6e88 100644 --- a/src/main/resources/mybatis/system/SystemMenuMapper.xml +++ b/src/main/resources/mybatis/system/SystemMenuMapper.xml @@ -37,6 +37,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" where ur.user_id = #{userId} + diff --git a/src/main/resources/static/ruoyi/system/role/edit.js b/src/main/resources/static/ruoyi/system/role/edit.js new file mode 100644 index 000000000..e4c6ef06c --- /dev/null +++ b/src/main/resources/static/ruoyi/system/role/edit.js @@ -0,0 +1,91 @@ +$(document).ready(function(){ + queryMenuTreeDaTa(); +}); + +$("#form-role-edit").validate({ + rules:{ + roleName:{ + required:true, + }, + roleKey:{ + required:true, + }, + roleSort:{ + required:true, + }, + }, + submitHandler:function(form){ + update(); + } +}); + +function update() { + var roleId = $("input[name='roleId']").val(); + var roleName = $("input[name='roleName']").val(); + var roleKey = $("input[name='roleKey']").val(); + var roleSort = $("input[name='roleSort']").val(); + var status = $("input[name='status']").is(':checked') == true ? 0 : 1; + $.ajax({ + cache : true, + type : "POST", + url : "/system/role/save", + data : { + "roleId": roleId, + "roleName": roleName, + "roleKey": roleKey, + "roleSort": roleSort, + "status": status + }, + async : false, + error : function(request) { + parent.layer.alert("系统错误"); + }, + success : function(data) { + if (data.code == 0) { + parent.layer.msg('修改成功',{icon:1,time:1000}); + layer_close(); + window.parent.location.reload(); + } else { + parent.layer.alert(data.m , {icon: 2,title:"系统提示"}); + } + + } + }); +} + +function queryMenuTreeDaTa() +{ + // 树结构初始化加载 + var setting = { + check:{enable:true,nocheckInherit:true,chkboxType:{"Y":"ps","N":"ps"}}, + view:{selectedMulti:false,nameIsHTML: true}, + data:{simpleData:{enable:true},key:{title:"title"}}, + callback:{ + beforeClick: function (treeId, treeNode, clickFlag) { + var tree = $.fn.zTree.getZTreeObj(treeId); + tree.checkNode(treeNode, !treeNode.checked, true, true); + return false; + }, + onCheck: function (event, treeId, treeNode){ + var tid = treeNode.tId; + if(!treeNode.checked){ + $(".checkall[value="+treeId+"]").each(function(){ + if(this.checked){ + $(this).removeAttr("checked").iCheck('update'); + } + return false; + }); + } + } + } + }, tree, loadTree = function(){ + $.get("/system/menu/treeData/" + $("#roleId").val(), function(data) { + tree = $.fn.zTree.init($("#tree"), setting, data); //.expandAll(true); + // 展开第一级节点 + var nodes = tree.getNodesByParam("level", 0); + for (var i = 0; i < nodes.length; i++) { + tree.expandNode(nodes[i], true, false, false); + } + }, null, null, "正在加载,请稍后..."); + };loadTree(); +} diff --git a/src/main/resources/static/ruoyi/system/role/role.js b/src/main/resources/static/ruoyi/system/role/role.js index 5eb0dc9ec..fc5ce0a2c 100644 --- a/src/main/resources/static/ruoyi/system/role/role.js +++ b/src/main/resources/static/ruoyi/system/role/role.js @@ -40,14 +40,22 @@ $(function() { title: '操作', align: 'center', formatter: function(value, row, index) { - var msg = ' '; - return msg; + var actions = []; + actions.push(' '); + actions.push(''); + return actions.join(''); } }]; var url = prefix + "/list"; initTable(columns, url); }); +/*角色管理-修改*/ +function edit(roleId) { + var url = prefix + '/edit/' + roleId; + layer_show("修改角色", url, '800', '400'); +} + // 单条删除 function remove(id) { layer.confirm("确定要删除选中角色吗?",{icon: 3, title:'提示'},function(index){ diff --git a/src/main/resources/static/ruoyi/system/user/user.js b/src/main/resources/static/ruoyi/system/user/user.js index 475d88c76..97847bdc5 100644 --- a/src/main/resources/static/ruoyi/system/user/user.js +++ b/src/main/resources/static/ruoyi/system/user/user.js @@ -52,7 +52,7 @@ function queryUserList() { align: 'center', formatter: function(value, row, index) { var actions = []; - actions.push(''); + actions.push(' '); actions.push(''); return actions.join(''); } diff --git a/src/main/resources/templates/system/role/edit.html b/src/main/resources/templates/system/role/edit.html new file mode 100644 index 000000000..d64701eac --- /dev/null +++ b/src/main/resources/templates/system/role/edit.html @@ -0,0 +1,60 @@ + + + + + + +
+
+ +
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+
+ + +
+
+
+
+ +
+
+
+
+ +
+
+ + +
+
+
+
+
+ + + +