Commit 6c73aeb9 authored by liboyang's avatar liboyang

角色和权限修改已完成

parent 84046ca5
......@@ -100,9 +100,8 @@ public class ShiroApi {
@RequestMapping("/permissionAdd")
@RequiresPermissions("permission.add")//权限管理;
public String permissionAdd(Map<String,Object> map){
Subject subject = SecurityUtils.getSubject();
UserInfo ui = (UserInfo) subject.getPrincipal();
map.put("roleInfo",ui.getRoleList().get(0));
List<SysPermission> permissionList = sysPermissionService.getAllActivePermission();
map.put("permissionList",permissionList);
return "permissionAdd";
}
......@@ -167,7 +166,7 @@ public class ShiroApi {
}
/**
* 修改用户.
* 修改角色
* @return
*/
@RequestMapping("/updateRoleInfo")
......@@ -179,5 +178,20 @@ public class ShiroApi {
return "updateRoleInfo";
}
/**
* 修改权限
* @return
*/
@RequestMapping("/updatePermission")
public String updatePermission(@RequestParam("permissionId") String permissionId, Map<String,Object> map){
SysPermission sysPermission = sysPermissionService.getPermissionByPId(Integer.parseInt(permissionId));
String parentName = sysPermissionService.getParentNameByParentId(sysPermission.getParent_id());
List<SysPermission> permissionList = sysPermissionService.getAllActivePermission();
map.put("sysPermission",sysPermission);
map.put("parentName",parentName);
map.put("permissionList",permissionList);
return "updatePermission";
}
}
......@@ -309,9 +309,9 @@ public class UserInfoApi {
sysRole.setId(Integer.parseInt(roleId));
sysRole.setRole(role);
sysRole.setDescription(description);
String[] oldpermissionIds = request.getParameterValues("permissionIds");
String[] oldPermissionIds = request.getParameterValues("permissionIds");
String[] permissionIds = request.getParameterValues("permissions");
// flag = sysRoleService.updateRole(sysRole,permissionIds,oldpermissionIds);
flag = sysRoleService.updateRole(sysRole,permissionIds,oldPermissionIds);
if (flag){
map.put("resultMsg","修改成功");
......@@ -323,6 +323,38 @@ public class UserInfoApi {
}
@POST
@Path("permissionUpdate")
@RequiresPermissions("permission.update")
public String permissionUpdate(@FormParam("id") String id,@FormParam("name") String name,@FormParam("resourceType") String resourceType,@FormParam("url") String url,
@FormParam("permission")String permission,@FormParam("parentId")String parentId,@Context HttpServletResponse resp){
resp.setCharacterEncoding("UTF-8");
Map<String,String> map = new HashMap<>();
boolean flag = false;
String str = "0";
SysPermission sysPermission = new SysPermission();
sysPermission.setId(Integer.parseInt(id));
sysPermission.setName(name);
sysPermission.setResource_type(resourceType);
sysPermission.setUrl(url);
sysPermission.setPermission(permission);
sysPermission.setParent_id(Long.parseLong(parentId));
if(parentId.equals(str)){
sysPermission.setParent_ids(parentId+"/");
}else{
sysPermission.setParent_ids(str+"/"+parentId);
}
System.out.println(sysPermission);
flag = sysPermissionService.updatePermission(sysPermission);
if (flag){
map.put("resultMsg","修改成功");
}else {
map.put("resultMsg","修改失败");
}
return map.toString();
}
@GET
@RequestMapping("selectAllUser")
......
......@@ -54,5 +54,29 @@ public interface SysPermissionMapper{
* @return
*/
@Select("select sp.id,sp.name from SYS_ROLE_PERMISSION srp ,SYS_PERMISSION sp where srp.PERMISSION_ID=sp.ID and srp.ROLE_ID=#{roleId}")
List<SysPermission> selectPermissionByRoleId(@Param("roleId") Integer roleId);
public List<SysPermission> selectPermissionByRoleId(@Param("roleId") Integer roleId);
/**
*通过id查询权限信息
* @param permissionId
* @return
*/
@Select("select * from SYS_PERMISSION WHERE ID=#{permissionId}")
public SysPermission selectPermissionByPid(@Param("permissionId") Integer permissionId);
/**
* 通过父id查询父名称
* @param parentId
* @return
*/
@Select("select name from SYS_PERMISSION WHERE ID=#{parentId}")
public String selectParentNameById(@Param("parentId")Long parentId);
/**
* 修改权限信息
* @param sysPermission
*/
@Update("update SYS_PERMISSION SET NAME=#{name},resource_type=#{resource_type},url=#{url}," +
"permission=#{permission},parent_id=#{parent_id},parent_ids=#{parent_ids} where id=#{id}")
public void updatePermission(SysPermission sysPermission);
}
......@@ -93,5 +93,18 @@ public interface SysRoleMapper {
many = @Many(select = "com.yxproject.start.mapper.SysPermissionMapper.selectPermissionByRoleId"))})
public SysRole selectRoleByRoleId(@Param("roleId") Integer roleId);
/**
* 修改角色信息
* @param sysRole
*/
@Update("update SYS_ROLE set role=#{role},description=#{description} where id=#{id}")
public void updateSysRole(SysRole sysRole);
/**
* 删除角色权限关系表中旧关系
* @param roleId
* @param oldPermissionId
*/
@Delete("delete from SYS_ROLE_PERMISSION WHERE ROLE_ID=#{roleId} AND PERMISSION_ID=#{oldPermissionId}")
public void delRolePermission(@Param("roleId") Integer roleId,@Param("oldPermissionId") Integer oldPermissionId);
}
......@@ -40,5 +40,26 @@ public interface SysPermissionService {
* @return
*/
public boolean backPermission(Integer permissionId);
/**
* 通过权限id查询权限
* @param permissionId
* @return
*/
public SysPermission getPermissionByPId(Integer permissionId);
/**
* 通过父id查询父名称
* @param parentId
* @return
*/
public String getParentNameByParentId(Long parentId);
/**
* 修改权限信息
* @param sysPermission
* @return
*/
public boolean updatePermission(SysPermission sysPermission);
}
......@@ -20,9 +20,11 @@ public interface SysRoleService {
* 修改角色和权限
* @param sysRole
* @param ids
* @param oldIds
* @return
*/
// public boolean updateRole(SysRole sysRole,String[] ids,String[] oldIds);
public boolean updateRole(SysRole sysRole,String[] ids,String[] oldIds);
/**
* 查询所有角色
......
......@@ -3,6 +3,7 @@ package com.yxproject.start.service.impl;
import com.yxproject.start.entity.SysPermission;
import com.yxproject.start.mapper.SysPermissionMapper;
import com.yxproject.start.service.SysPermissionService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -48,5 +49,23 @@ public class SysPermissionServiceImpl implements SysPermissionService{
return true;
}
@Override
public SysPermission getPermissionByPId(Integer permissionId) {
SysPermission sysPermission = sysPermissionMapper.selectPermissionByPid(permissionId);
return sysPermission;
}
@Override
public String getParentNameByParentId(Long parentId) {
String parentName = sysPermissionMapper.selectParentNameById(parentId);
return parentName;
}
@Override
public boolean updatePermission(SysPermission sysPermission) {
sysPermissionMapper.updatePermission(sysPermission);
return true;
}
}
......@@ -31,12 +31,19 @@ public class SysRoleServiceImpl implements SysRoleService {
return true;
}
// @Override
// @Transactional(rollbackFor=Exception.class)
// public boolean updateRole(SysRole sysRole,String[] ids,String[] oldIds){
// sysRoleMapper.updateRole(sysRole);
// return true;
// }
@Override
@Transactional(rollbackFor=Exception.class)
public boolean updateRole(SysRole sysRole, String[] ids, String[] oldIds) {
sysRoleMapper.updateSysRole(sysRole);
for (int i=0;i<oldIds.length;i++){
sysRoleMapper.delRolePermission(sysRole.getId(),Integer.parseInt(oldIds[i]));
}
for (int i=0;i<ids.length;i++){
sysRoleMapper.addRolePermission(sysRole.getId(),Integer.parseInt(ids[i]));
}
return true;
}
@Override
public List<SysRole> getAllRoleInfo() {
......
......@@ -14,7 +14,7 @@
<p>权限字符串:<input type="text" name="permission" value="userInfo.add"/></p>
<p>父类: <select name="parentId">
<option value="0"></option>
<option th:each="permission:${roleInfo.permissions}" th:value="${permission.id}">
<option th:each="permission:${permissionList}" th:value="${permission.id}">
<span th:text="${permission.name}"></span>
</option>
</select>
......
......@@ -22,16 +22,12 @@
<body class="layui-anim layui-anim-up">
<div class="x-body">
<xblock>
<button class="layui-btn layui-btn-danger" onclick="delAll()"><i class="layui-icon"></i>批量删除</button>
<button class="layui-btn" onclick="x_admin_show('添加权限','/permissionAdd',600,400)"><i class="layui-icon"></i>添加</button>
<!--<span class="x-right" style="line-height:40px">共有数据:88 条</span>-->
</xblock>
<table class="layui-table">
<thead>
<tr>
<th>
<div class="layui-unselect header layui-form-checkbox" lay-skin="primary"><i class="layui-icon">&#xe605;</i></div>
</th>
<th>ID</th>
<th>权限</th>
<th>名称</th>
......@@ -45,9 +41,6 @@
</thead>
<tbody>
<tr th:each="permission:${permissionList}">
<td>
<div class="layui-unselect layui-form-checkbox" lay-skin="primary" data-id='2'><i class="layui-icon">&#xe605;</i></div>
</td>
<td><span th:text="${permission.id}"></span></td>
<td><span th:text="${permission.permission}"></span></td>
<td><span th:text="${permission.name}"></span></td>
......@@ -60,24 +53,10 @@
<span th:if="${permission.available}==0" class="layui-btn layui-btn-normal layui-btn-mini">已启用</span>
</td>
<td>
<a class="layui-btn layui-btn" href="#" th:href="@{/rest/user/updatePermissionInfo(permissionId=${permission.id})}">修改</a>
<a class="layui-btn layui-btn" href="#" th:href="@{/updatePermission(permissionId=${permission.id})}">修改</a>
<a class="layui-btn layui-btn-danger" onclick="return del()" href="#" th:href="@{/rest/user/permissionDel(permissionId=${permission.id})}">删除</a>
<a class="layui-btn layui-btn-info" href="#" th:href="@{/rest/user/permissionBack(permissionId=${permission.id})}">启用</a>
</td>
<!--<td class="td-manage">-->
<!--<a onclick="member_stop(this,'10001')" href="javascript:;" title="启用">-->
<!--<i class="layui-icon">&#xe601;</i>-->
<!--</a>-->
<!--<a title="编辑" onclick="x_admin_show('编辑','member-edit.html',600,400)" href="javascript:;">-->
<!--<i class="layui-icon">&#xe642;</i>-->
<!--</a>-->
<!--<a onclick="x_admin_show('修改密码','member-password.html',600,400)" title="修改密码" href="javascript:;">-->
<!--<i class="layui-icon">&#xe631;</i>-->
<!--</a>-->
<!--<a title="删除" onclick="member_del(this,'要删除的id')" href="javascript:;">-->
<!--<i class="layui-icon">&#xe640;</i>-->
<!--</a>-->
<!--</td>-->
</tr>
</tbody>
</table>
......
......@@ -22,16 +22,11 @@
<body class="layui-anim layui-anim-up">
<div class="x-body">
<xblock>
<button class="layui-btn layui-btn-danger" onclick="delAll()"><i class="layui-icon"></i>批量删除</button>
<button class="layui-btn" onclick="x_admin_show('添加角色','/roleAdd',600,400)"><i class="layui-icon"></i>添加</button>
<!--<span class="x-right" style="line-height:40px">共有数据:88 条</span>-->
</xblock>
<table class="layui-table">
<thead>
<tr>
<th>
<div class="layui-unselect header layui-form-checkbox" lay-skin="primary"><i class="layui-icon">&#xe605;</i></div>
</th>
<th>ID</th>
<th>角色名</th>
<th>描述</th>
......@@ -42,9 +37,6 @@
</thead>
<tbody>
<tr th:each="role:${roleInfoList}">
<td>
<div class="layui-unselect layui-form-checkbox" lay-skin="primary" data-id='2'><i class="layui-icon">&#xe605;</i></div>
</td>
<td><span th:text="${role.id}"></span></td>
<td><span th:text="${role.role}"></span></td>
<td><span th:text="${role.description}"></span></td>
......@@ -61,20 +53,6 @@
<a class="layui-btn layui-btn-danger" onclick="return del()" href="#" th:href="@{/rest/user/roleDel(roleId=${role.id})}">删除</a>
<a class="layui-btn layui-btn-info" href="#" th:href="@{/rest/user/roleBack(roleId=${role.id})}">启用</a>
</td>
<!--<td class="td-manage">-->
<!--<a onclick="member_stop(this,'10001')" href="javascript:;" title="启用">-->
<!--<i class="layui-icon">&#xe601;</i>-->
<!--</a>-->
<!--<a title="编辑" onclick="x_admin_show('编辑','member-edit.html',600,400)" href="javascript:;">-->
<!--<i class="layui-icon">&#xe642;</i>-->
<!--</a>-->
<!--<a onclick="x_admin_show('修改密码','member-password.html',600,400)" title="修改密码" href="javascript:;">-->
<!--<i class="layui-icon">&#xe631;</i>-->
<!--</a>-->
<!--<a title="删除" onclick="member_del(this,'要删除的id')" href="javascript:;">-->
<!--<i class="layui-icon">&#xe640;</i>-->
<!--</a>-->
<!--</td>-->
</tr>
</tbody>
</table>
......
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
<meta charset="UTF-8">
<title>Add</title>
</head>
<body>
<h3>权限添加界面</h3>
<form action="" th:action="@{rest/user/permissionUpdate}" method="post">
<input type="hidden" name="id" th:value="${sysPermission.id}"/>
<p>名称:<input type="text" name="name" th:value="${sysPermission.name}"/></p>
<p>资源类型:<input type="radio" name="resourceType" value="menu"/>menu
<input type="radio" name="resourceType" value="button"/>button</p>
<p>资源路径:<input type="text" name="url" th:value="${sysPermission.url}"/></p>
<p>权限字符串:<input type="text" name="permission" th:value="${sysPermission.permission}"/></p>
<p>父类: <select name="parentId">
<option value="0"></option>
<option th:each="permission:${permissionList}" th:value="${permission.id}">
<span th:text="${permission.name}"></span>
</option>
</select>
</p>
</select>
<p><input type="submit" value="添加"/></p>
</form>
</body>
</html>
\ No newline at end of file
......@@ -22,16 +22,11 @@
<body class="layui-anim layui-anim-up">
<div class="x-body">
<xblock>
<button class="layui-btn layui-btn-danger" onclick="delAll()"><i class="layui-icon"></i>批量删除</button>
<button class="layui-btn" onclick="x_admin_show('添加用户','/userAdd',600,400)"><i class="layui-icon"></i>添加</button>
<!--<span class="x-right" style="line-height:40px">共有数据:88 条</span>-->
</xblock>
<table class="layui-table">
<thead>
<tr>
<th>
<div class="layui-unselect header layui-form-checkbox" lay-skin="primary"><i class="layui-icon">&#xe605;</i></div>
</th>
<th>ID</th>
<th>用户名</th>
<th>别名</th>
......@@ -42,9 +37,6 @@
</thead>
<tbody>
<tr th:each="userInfo:${userInfoList}">
<td>
<div class="layui-unselect layui-form-checkbox" lay-skin="primary" data-id='2'><i class="layui-icon">&#xe605;</i></div>
</td>
<td><span th:text="${userInfo.id}"></span></td>
<td><span th:text="${userInfo.username}"></span></td>
<td><span th:text="${userInfo.name}"></span></td>
......@@ -61,20 +53,6 @@
<a class="layui-btn layui-btn-danger" onclick="return del()" href="#" th:href="@{/rest/user/userDel(userId=${userInfo.id})}">删除</a>
<a class="layui-btn layui-btn-info" href="#" th:href="@{/rest/user/userBack(userId=${userInfo.id})}">启用</a>
</td>
<!--<td class="td-manage">-->
<!--<a onclick="member_stop(this,'10001')" href="javascript:;" title="启用">-->
<!--<i class="layui-icon">&#xe601;</i>-->
<!--</a>-->
<!--<a title="编辑" onclick="x_admin_show('编辑','member-edit.html',600,400)" href="javascript:;">-->
<!--<i class="layui-icon">&#xe642;</i>-->
<!--</a>-->
<!--<a onclick="x_admin_show('修改密码','member-password.html',600,400)" title="修改密码" href="javascript:;">-->
<!--<i class="layui-icon">&#xe631;</i>-->
<!--</a>-->
<!--<a title="删除" onclick="member_del(this,'要删除的id')" href="javascript:;">-->
<!--<i class="layui-icon">&#xe640;</i>-->
<!--</a>-->
<!--</td>-->
</tr>
</tbody>
</table>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment