diff --git a/src/main/java/com/pro/info/service/CustomerService.java b/src/main/java/com/pro/info/service/CustomerService.java index 8cf831d39d0b19ba4a556271e984fe8a6cd9975a..8b1b27c75265c5c775d643943b0d071b2fb8012a 100644 --- a/src/main/java/com/pro/info/service/CustomerService.java +++ b/src/main/java/com/pro/info/service/CustomerService.java @@ -2,9 +2,6 @@ package com.pro.info.service; import com.github.pagehelper.PageInfo; import com.pro.info.entity.Customer; -import com.pro.sys.entity.Page; - -import java.util.List; public interface CustomerService { /** diff --git a/src/main/java/com/pro/sys/controller/LoginController.java b/src/main/java/com/pro/sys/controller/LoginController.java index aeb87964ba1c77abd46187b3871b943e50063da3..1ca5b261f91132568902c763878b4acddfe087b9 100644 --- a/src/main/java/com/pro/sys/controller/LoginController.java +++ b/src/main/java/com/pro/sys/controller/LoginController.java @@ -13,6 +13,7 @@ import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; import com.pro.sys.entity.User; +import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; import java.util.ArrayList; import java.util.List; @@ -25,14 +26,18 @@ public class LoginController { private ShiroService shiroService; @RequestMapping(value = "/login") public String Login(String username, String password, HttpSession session, Model model){ - System.out.println("username:"+username+"----->password:"+password); + //主体,当前状态为没有认证的状态“未认证” + Subject subject = SecurityUtils.getSubject(); + if (subject.getSession().getAttribute("user") != null){//防止重复访问login + List menuList = shiroService.getMenuList((User)subject.getPrincipal()); + model.addAttribute("menuList",menuList); + return "sys/home"; + } if(username==null){ model.addAttribute("message", "账号不为空"); return "sys/login"; } - //主体,当前状态为没有认证的状态“未认证” - Subject subject = SecurityUtils.getSubject(); // 登录后存放进shiro token UsernamePasswordToken token=new UsernamePasswordToken(username,password); User user; @@ -47,15 +52,20 @@ public class LoginController { user = (User)subject.getPrincipal(); System.out.println("------->login:"+user); session.setAttribute("user",user); + System.out.println("++++++++++++++++++"+subject.getSession().getAttribute("user")); List menuList = shiroService.getMenuList(user); - - System.out.println("userPer-------------->"+menuList); model.addAttribute("menuList",menuList); System.out.println("登录完成"); return "sys/home"; - } catch (Exception e) { + } catch (UnknownAccountException e) { model.addAttribute("message", "登录失败"); return "sys/login"; } } + + + @RequestMapping("noper") + public String noper(){ + return "sys/noper"; + } } diff --git a/src/main/java/com/pro/sys/controller/RoleController.java b/src/main/java/com/pro/sys/controller/RoleController.java index a9f98ecd985adff7daab86d32a95f7bf0cde83d4..aa8c09e907cfca286a6c8f776b88cd70c86d6c4d 100644 --- a/src/main/java/com/pro/sys/controller/RoleController.java +++ b/src/main/java/com/pro/sys/controller/RoleController.java @@ -1,14 +1,17 @@ package com.pro.sys.controller; import com.github.pagehelper.PageInfo; +import com.pro.sys.entity.Menu; import com.pro.sys.entity.Result; import com.pro.sys.entity.Role; import com.pro.sys.service.RoleService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; import org.springframework.web.bind.annotation.*; import java.util.HashMap; +import java.util.List; import java.util.Map; @Controller @@ -98,4 +101,34 @@ public class RoleController { public Result updateStatus(@RequestBody Integer[] ro_ids, @PathVariable String ro_status){ return roleService.updateStatus(ro_ids,ro_status); } + + /** + * 获得权限(树状) + * @param ro_id + * @param model + * @return + */ + @RequestMapping( + value="/role/module/{ro_id}", + method=RequestMethod.GET) + public String updateStatus(@PathVariable Integer ro_id,Model model) { + List menuList = roleService.getModules(ro_id); + model.addAttribute("menu",menuList); + return "sys/_modules"; + } + + /** + * 更新角色权限 + * @param m_ids + * @param ro_id + * @return + */ + @RequestMapping( + value="/role/module/{ro_id}", + method=RequestMethod.PUT) + @ResponseBody + public Result setRoleModules(@RequestBody Integer[] m_ids, @PathVariable("ro_id") Integer ro_id){ + return roleService.setRoleModules(m_ids,ro_id); + + } } diff --git a/src/main/java/com/pro/sys/entity/Menu.java b/src/main/java/com/pro/sys/entity/Menu.java index b2f84a925ab9acecfb2657de9632c0439846ba94..c397194c932234138fcd77be0c4acb9fced4aef5 100644 --- a/src/main/java/com/pro/sys/entity/Menu.java +++ b/src/main/java/com/pro/sys/entity/Menu.java @@ -7,6 +7,7 @@ public class Menu { private Integer menuId; private String menuName; private String menuUrl; + private boolean checked = false; private List subMenuList; @@ -34,6 +35,14 @@ public class Menu { this.menuUrl = menuUrl; } + public boolean isChecked() { + return checked; + } + + public void setChecked(boolean checked) { + this.checked = checked; + } + public List getSubMenuList() { return subMenuList; } diff --git a/src/main/java/com/pro/sys/mapper/RoleMapper.java b/src/main/java/com/pro/sys/mapper/RoleMapper.java index 7a6ec1c11b87b08f6e95cf79129fb4d82620a85a..4d6803c882c7da79b855693afa47067f26c3211d 100644 --- a/src/main/java/com/pro/sys/mapper/RoleMapper.java +++ b/src/main/java/com/pro/sys/mapper/RoleMapper.java @@ -1,5 +1,6 @@ package com.pro.sys.mapper; +import com.pro.sys.entity.Module; import com.pro.sys.entity.Role; import org.apache.ibatis.annotations.Param; import org.mybatis.spring.annotation.MapperScan; @@ -49,4 +50,25 @@ public interface RoleMapper { * @return */ int updateStatus(@Param("ro_ids") Integer[] ro_ids, @Param("ro_status") String ro_status); + + /** + * 查询角色权限(包括没有的权限) + * @param ro_id + * @return + */ + List getModules(Integer ro_id); + + /** + * 删除所有该角色权限 + * @param ro_id + */ + void deleteAllModule(Integer ro_id); + + /** + * 修改角色权限 + * @param m_ids + * @param ro_id + * @return + */ + int updateModules(@Param("m_ids") Integer[] m_ids, @Param("ro_id") Integer ro_id); } \ No newline at end of file diff --git a/src/main/java/com/pro/sys/mapper/ShiroMapper.java b/src/main/java/com/pro/sys/mapper/ShiroMapper.java index 126b83fb2054b8bc0ebb7103d21a94320c53f628..841014e6d6f193723112a4cdea977f15594e463d 100644 --- a/src/main/java/com/pro/sys/mapper/ShiroMapper.java +++ b/src/main/java/com/pro/sys/mapper/ShiroMapper.java @@ -1,6 +1,7 @@ package com.pro.sys.mapper; import com.pro.sys.entity.Module; +import org.apache.ibatis.annotations.Param; import org.mybatis.spring.annotation.MapperScan; import com.pro.sys.entity.User; @@ -32,8 +33,8 @@ public interface ShiroMapper { /** * 获得菜单列表 - * @param ro_Id + * @param ro_ids * @return */ - List getMenuList(int ro_Id); + List getMenuList(@Param("ro_ids") List ro_ids); } \ No newline at end of file diff --git a/src/main/java/com/pro/sys/service/RoleService.java b/src/main/java/com/pro/sys/service/RoleService.java index f6f4cf3ec107d8ce8e499913da97aa7ff0d07c3b..50aaa929e6ed2403061dadd60c81471824b89286 100644 --- a/src/main/java/com/pro/sys/service/RoleService.java +++ b/src/main/java/com/pro/sys/service/RoleService.java @@ -1,9 +1,12 @@ package com.pro.sys.service; import com.github.pagehelper.PageInfo; +import com.pro.sys.entity.Menu; import com.pro.sys.entity.Result; import com.pro.sys.entity.Role; +import java.util.List; + public interface RoleService { PageInfo getRoles(int page, int pageSize, Role roleIn); @@ -15,4 +18,8 @@ public interface RoleService { Role getRole(Integer role_id); Result updateStatus(Integer[] role_ids, String role_status); + + List getModules(Integer ro_id); + + Result setRoleModules(Integer[] m_ids, Integer ro_id); } diff --git a/src/main/java/com/pro/sys/service/impl/RoleServiceImpl.java b/src/main/java/com/pro/sys/service/impl/RoleServiceImpl.java index 080043fd31b496fc76b72a8cbf2a0c695333fc9f..c9cf56c8f8be877d280a8728f04c86f4490c1af4 100644 --- a/src/main/java/com/pro/sys/service/impl/RoleServiceImpl.java +++ b/src/main/java/com/pro/sys/service/impl/RoleServiceImpl.java @@ -2,6 +2,8 @@ package com.pro.sys.service.impl; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; +import com.pro.sys.entity.Menu; +import com.pro.sys.entity.Module; import com.pro.sys.entity.Result; import com.pro.sys.entity.Role; import com.pro.sys.mapper.RoleMapper; @@ -9,6 +11,9 @@ import com.pro.sys.service.RoleService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.util.ArrayList; +import java.util.List; + @Service public class RoleServiceImpl implements RoleService { @@ -17,30 +22,32 @@ public class RoleServiceImpl implements RoleService { /** * 获得产品规格信息列表 + * * @param page * @param pageSize * @return */ @Override public PageInfo getRoles(int page, int pageSize, Role roleIn) { - PageHelper.startPage(page,pageSize); + PageHelper.startPage(page, pageSize); return new PageInfo(roleMapper.getRoles(roleIn)); } /** * 添加,修改 + * * @param role * @return */ @Override public Result save(Role role) { - if (role.getRo_id() != null){ - if(roleMapper.update(role) > 0){ + if (role.getRo_id() != null) { + if (roleMapper.update(role) > 0) { return Result.successResult("修改信息成功!"); } return Result.failResult("修改信息失败!"); - }else{ - if(roleMapper.save(role) > 0){ + } else { + if (roleMapper.save(role) > 0) { return Result.successResult("添加信息成功!"); } return Result.failResult("添加信息失败!"); @@ -49,12 +56,13 @@ public class RoleServiceImpl implements RoleService { /** * 删除 + * * @param role_ids * @return */ @Override public Result delete(Integer[] role_ids) { - if (roleMapper.delete(role_ids) > 0){ + if (roleMapper.delete(role_ids) > 0) { return Result.successResult("信息被成功删除!"); } return Result.failResult("信息删除失败!"); @@ -62,6 +70,7 @@ public class RoleServiceImpl implements RoleService { /** * 获取单条数据 + * * @param role_id * @return */ @@ -72,15 +81,63 @@ public class RoleServiceImpl implements RoleService { /** * 修改多条状态 + * * @param role_ids * @param role_status * @return */ @Override public Result updateStatus(Integer[] role_ids, String role_status) { - if(roleMapper.updateStatus(role_ids, role_status) > 0){ + if (roleMapper.updateStatus(role_ids, role_status) > 0) { return Result.successResult("状态被成功修改!"); } return Result.successResult("状态修改失败!"); } + + /** + * 获得该角色的权限(树状结构) + * + * @param ro_id + * @return + */ + @Override + public List getModules(Integer ro_id) { + List modules = roleMapper.getModules(ro_id); + List menuList = new ArrayList(); + Menu mainMenu = null; + for (Module module : modules) { + if (module.getM_pid() == null){ + mainMenu = new Menu(); + mainMenu.setMenuName(module.getM_name()); + mainMenu.setSubMenuList(new ArrayList()); + menuList.add(mainMenu); + } else { + Menu subMenu = new Menu(); + subMenu.setMenuId(module.getM_id()); + subMenu.setMenuName(module.getM_name()); + if (module.getM_url() != null && !module.getM_url().equals("")){ + subMenu.setChecked(true); + } + mainMenu.getSubMenuList().add(subMenu); + } + } + return menuList; + } + + /** + * 更新权限 + * @param m_ids + * @param ro_id + * @return + */ + @Override + public Result setRoleModules(Integer[] m_ids, Integer ro_id) { + roleMapper.deleteAllModule(ro_id); + if (roleMapper.updateModules(m_ids,ro_id) > 0){ + return Result.successResult("该角色权限修改成功!"); + } + return Result.failResult("该角色权限修改失败!"); + } + + } diff --git a/src/main/java/com/pro/sys/service/impl/ShiroServiceImpl.java b/src/main/java/com/pro/sys/service/impl/ShiroServiceImpl.java index 25b51100f0bfbbeec1e96d9231b4a5da75f73565..8cd82971eb8cf1c207f905853e9eac3f1929335c 100644 --- a/src/main/java/com/pro/sys/service/impl/ShiroServiceImpl.java +++ b/src/main/java/com/pro/sys/service/impl/ShiroServiceImpl.java @@ -40,29 +40,29 @@ public class ShiroServiceImpl implements ShiroService { return perArrary; } - //待改进获取菜单 + //获取菜单 @Override public List getMenuList(User user) { - List moduleList = shiroMapper.getMenuList(shiroMapper.getUserRoleByUserId(user.getU_id()).get(0)); + List moduleList = shiroMapper.getMenuList(shiroMapper.getUserRoleByUserId(user.getU_id())); List mainMenuList = new ArrayList(); Menu currMainMenu=null; + System.out.println("-----.moduleList--"+moduleList); for(Module m : moduleList) { - if(m.getM_pid()==null) { + if(currMainMenu == null || !currMainMenu.getMenuId().equals(m.getM_pid())) { currMainMenu=new Menu(); - currMainMenu.setMenuId(m.getM_id()); - currMainMenu.setMenuName(m.getM_name()); + currMainMenu.setMenuId(m.getM_pid()); + currMainMenu.setMenuName(m.getM_status()); currMainMenu.setSubMenuList(new ArrayList()); mainMenuList.add(currMainMenu); - }else { + } Menu subMenu=new Menu(); subMenu.setMenuId(m.getM_id()); subMenu.setMenuName(m.getM_name()); subMenu.setMenuUrl(m.getM_url()); - currMainMenu.getSubMenuList().add(subMenu); - } } + System.out.println("----------////"+mainMenuList); return mainMenuList; } diff --git a/src/main/resources/log4j.properties b/src/main/resources/log4j.properties index cc0ce92134ca0feff39a5cdf54f8f20a82dc015f..7d0b1d38ac8aa9223a264b864eaf7f6763522044 100644 --- a/src/main/resources/log4j.properties +++ b/src/main/resources/log4j.properties @@ -2,7 +2,7 @@ ### SpringҪweb.xmlָļλãӼ ### #log4jĿĵأĿĵؿԶƣͺĶӦ #[ level ] , appenderName1 , appenderName2 -log4j.rootLogger=DEBUG, console +log4j.rootLogger=INFO, console #-----------------------------------# #1 ־ĿĵΪ̨ diff --git a/src/main/resources/mapper/sys/RoleMapper.xml b/src/main/resources/mapper/sys/RoleMapper.xml index fd0035c50f87063d599c0c0b74e056fa143da932..633c84424ae864ecec94a939a68f40415b9926ae 100644 --- a/src/main/resources/mapper/sys/RoleMapper.xml +++ b/src/main/resources/mapper/sys/RoleMapper.xml @@ -27,17 +27,20 @@ - insert into sys_role ( - ro_id, - ro_name, - ro_remark, - ro_status - ) values ( - default, - #{ro_name}, - #{ro_remark}, - '00' - ) + INSERT INTO sys_role + VALUES + ( + (SELECT a.ro_id FROM + (( + SELECT + MAX(ro_id) + 1 as ro_id + FROM + sys_role + ) a)), + #{ro_name}, + #{ro_remark}, + '00' + ) @@ -80,4 +83,36 @@ + + + + delete from sys_rm where ro_id = #{ro_id} + + + + insert into sys_rm values + + (#{m_id},#{ro_id}) + + \ No newline at end of file diff --git a/src/main/resources/mapper/sys/shiro.xml b/src/main/resources/mapper/sys/ShiroMapper.xml similarity index 65% rename from src/main/resources/mapper/sys/shiro.xml rename to src/main/resources/mapper/sys/ShiroMapper.xml index f433bac1153ddef943440ef93497b5be0edeef34..28460be75b17b6a35546a2369de9ab017e625b44 100644 --- a/src/main/resources/mapper/sys/shiro.xml +++ b/src/main/resources/mapper/sys/ShiroMapper.xml @@ -21,28 +21,20 @@ \ No newline at end of file diff --git a/src/main/resources/spring-root-shiro.xml b/src/main/resources/spring-root-shiro.xml index ab4b1ba15e6e28027eaa1f1afe26724bb421d7ed..3f618e7b584bc8b38bdc8bb169a04bf31ca53243 100644 --- a/src/main/resources/spring-root-shiro.xml +++ b/src/main/resources/spring-root-shiro.xml @@ -13,14 +13,12 @@ - - + /static/** = anon /sys/login = anon /pro/readName = authc, perms[/readName] - /pro/readData = authc, perms[/readData] /logout = logout /** = authc diff --git a/src/main/web/WEB-INF/views/sys/_modules.jsp b/src/main/web/WEB-INF/views/sys/_modules.jsp new file mode 100644 index 0000000000000000000000000000000000000000..d11491fe5994e49b2594a9049e7f3141c13bef7a --- /dev/null +++ b/src/main/web/WEB-INF/views/sys/_modules.jsp @@ -0,0 +1,105 @@ +<%-- + Created by IntelliJ IDEA. + User: lenovo + Date: 2018/8/9 + Time: 16:08 + To change this template use File | Settings | File Templates. +--%> +<%@ page language="java" contentType="text/html; charset=UTF-8" + pageEncoding="UTF-8" %> +<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> +<%@ page isELIgnored="false" %> + +
+ +
+ +
+ +
+ ${main.menuName } +
+ + + +
+
+
+
+
+ + + + +
+ + + +
+ + + diff --git a/src/main/web/WEB-INF/views/sys/home.jsp b/src/main/web/WEB-INF/views/sys/home.jsp index b9582a1cdfefe0d3bbd55d14907a6bdcf14a9a2d..8eeb08a40ea168831bccb5f68d9dfe747285a262 100644 --- a/src/main/web/WEB-INF/views/sys/home.jsp +++ b/src/main/web/WEB-INF/views/sys/home.jsp @@ -24,42 +24,6 @@ - - -
@@ -70,11 +34,8 @@ ${sessionScope.user.u_name} -
-
修改密码
-
退了
-
+
  • 退了
  • @@ -107,89 +68,12 @@
    - - diff --git a/src/main/web/WEB-INF/views/sys/login.jsp b/src/main/web/WEB-INF/views/sys/login.jsp index b9de5741287d6a9da647e6b2ef368459d4a7524a..9d82cc8b537eb4347528b4fd41640b33b8bf4399 100644 --- a/src/main/web/WEB-INF/views/sys/login.jsp +++ b/src/main/web/WEB-INF/views/sys/login.jsp @@ -19,6 +19,13 @@ +
    + @@ -114,10 +115,12 @@ To change this template use File | Settings | File Templates. 删除 - {{# }else if(d.ro_status == '22' || d.ro_status == '77' ){ }} + {{# }else if(d.cus_status == '22' || d.cus_status == '77' ){ }} 启用 + 授权 {{# }else if(d.ro_status == '55' ){ }} 禁用 + 授权 {{# } }} @@ -413,6 +416,21 @@ To change this template use File | Settings | File Templates. } }); + } else if (layEvent === 'role_module') { //授权 + $.ajax({ + url: 'role/module/' + data.ro_id, + method: 'get', + dataType:'html' + }).done(function (result) { + layer.open({ + type: 1, + title: '角色授权', + area: ['800px', '540px'], + content: result, + zIndex: 100 //将层次降低,以使sweetalert能够在layer之上 + }); + form.render(null, 'form-role-module'); + }); } @@ -504,23 +522,23 @@ To change this template use File | Settings | File Templates. } //确定多条数据 - $('#bn-role-cfm').click(function() { + $('#bn-role-cfm').click(function () { - changeMultiroleStatus('您确实要确定选择的角色信息吗?','角色信息一旦被确定,将不能再被编辑!','22',table,roleTable); + changeMultiroleStatus('您确实要确定选择的角色信息吗?', '角色信息一旦被确定,将不能再被编辑!', '22', table, roleTable); });//确定多条数据 //启用多条数据 - $('#bn-role-use').click(function() { + $('#bn-role-use').click(function () { - changeMultiroleStatus('您确实要启用选择的角色信息吗?','','55',table,roleTable); + changeMultiroleStatus('您确实要启用选择的角色信息吗?', '', '55', table, roleTable); });//启用多条数据 //禁用多条数据 - $('#bn-role-unuse').click(function() { + $('#bn-role-unuse').click(function () { - changeMultiroleStatus('您确实要禁用选择的角色信息吗?','角色信息一旦被禁用,将不能被使用!','77',table,roleTable); + changeMultiroleStatus('您确实要禁用选择的角色信息吗?', '角色信息一旦被禁用,将不能被使用!', '77', table, roleTable); });//禁用多条数据