更新数据权限基础
This commit is contained in:
parent
c413d701ab
commit
eb72d42b77
|
|
@ -2,6 +2,8 @@ package com.ruoyi.project.system.dept.controller;
|
|||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.ruoyi.project.system.role.domain.Role;
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
|
|
@ -149,4 +151,14 @@ public class DeptController extends BaseController
|
|||
List<Map<String, Object>> tree = deptService.selectDeptTree();
|
||||
return tree;
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载角色部门(数据权限)列表树
|
||||
*/
|
||||
@GetMapping("/roleDeptTreeData")
|
||||
@ResponseBody
|
||||
public List<Map<String, Object>> deptTreeData(Role role){
|
||||
List<Map<String, Object>> tree = deptService.roleDeptTreeData(role);
|
||||
return tree;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@ import java.util.ArrayList;
|
|||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.ruoyi.project.system.role.domain.Role;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import com.ruoyi.common.constant.UserConstants;
|
||||
|
|
@ -60,6 +62,25 @@ public class DeptServiceImpl implements IDeptService
|
|||
return trees;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据角色ID查询部门(数据权限)
|
||||
*
|
||||
* @param role 角色对象
|
||||
* @return 部门列表(数据权限)
|
||||
*/
|
||||
@Override
|
||||
public List<Map<String, Object>> roleDeptTreeData(Role role) {
|
||||
Long roleId = role.getRoleId();
|
||||
List<Map<String, Object>> trees = new ArrayList<Map<String, Object>>();
|
||||
List<Dept> deptList=deptMapper.selectDeptAll();
|
||||
if(StringUtils.isNotNull(roleId)){
|
||||
// List<String> roleDeptList=deptMapper.
|
||||
}else {
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询部门人数
|
||||
*
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
|
||||
import com.ruoyi.project.system.dept.domain.Dept;
|
||||
import com.ruoyi.project.system.role.domain.Role;
|
||||
|
||||
/**
|
||||
* 部门管理 服务层
|
||||
|
|
@ -26,6 +27,14 @@ public interface IDeptService
|
|||
*/
|
||||
public List<Map<String, Object>> selectDeptTree();
|
||||
|
||||
/**
|
||||
* 根据角色ID查询菜单
|
||||
*
|
||||
* @param role 角色对象
|
||||
* @return 菜单列表
|
||||
*/
|
||||
public List<Map<String, Object>> roleDeptTreeData(Role role);
|
||||
|
||||
/**
|
||||
* 查询部门人数
|
||||
*
|
||||
|
|
|
|||
|
|
@ -38,6 +38,8 @@ public class Role extends BaseEntity
|
|||
private boolean flag = false;
|
||||
/** 菜单组 */
|
||||
private Long[] menuIds;
|
||||
/** 部门组(数据权限) */
|
||||
private Long[] deptIds;
|
||||
|
||||
public Long getRoleId()
|
||||
{
|
||||
|
|
@ -109,11 +111,19 @@ public class Role extends BaseEntity
|
|||
this.menuIds = menuIds;
|
||||
}
|
||||
|
||||
public Long[] getDeptIds() {
|
||||
return deptIds;
|
||||
}
|
||||
|
||||
public void setDeptIds(Long[] deptIds) {
|
||||
this.deptIds = deptIds;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "Role [roleId=" + roleId + ", roleName=" + roleName + ", roleKey=" + roleKey + ", roleSort=" + roleSort
|
||||
+ ", status=" + status + ", flag=" + flag + ", menuIds=" + Arrays.toString(menuIds) + "]";
|
||||
+ ", status=" + status + ", flag=" + flag + ", menuIds=" + Arrays.toString(menuIds) + ", deptIds=" + Arrays.toString(deptIds)+ "]";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,9 @@ import java.util.Arrays;
|
|||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import com.ruoyi.project.system.role.domain.RoleDept;
|
||||
import com.ruoyi.project.system.role.mapper.RoleDeptMapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.ruoyi.common.constant.UserConstants;
|
||||
|
|
@ -35,6 +38,9 @@ public class RoleServiceImpl implements IRoleService
|
|||
@Autowired
|
||||
private UserRoleMapper userRoleMapper;
|
||||
|
||||
@Autowired
|
||||
private RoleDeptMapper roleDeptMapper;
|
||||
|
||||
/**
|
||||
* 根据条件分页查询角色数据
|
||||
*
|
||||
|
|
@ -166,6 +172,8 @@ public class RoleServiceImpl implements IRoleService
|
|||
roleMapper.updateRole(role);
|
||||
// 删除角色与菜单关联
|
||||
roleMenuMapper.deleteRoleMenuByRoleId(roleId);
|
||||
//删除角色与部门关联(数据权限)
|
||||
roleDeptMapper.deleteRoleDeptByRoleId(roleId);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -174,13 +182,15 @@ public class RoleServiceImpl implements IRoleService
|
|||
roleMapper.insertRole(role);
|
||||
}
|
||||
ShiroUtils.clearCachedAuthorizationInfo();
|
||||
//新增角色和部门信息(数据权限)
|
||||
insertRoleDept(role);
|
||||
return insertRoleMenu(role);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增角色菜单信息
|
||||
*
|
||||
* @param user 角色对象
|
||||
* @param role 角色对象
|
||||
*/
|
||||
public int insertRoleMenu(Role role)
|
||||
{
|
||||
|
|
@ -201,6 +211,27 @@ public class RoleServiceImpl implements IRoleService
|
|||
return rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增角色部门信息(数据权限)
|
||||
*
|
||||
* @param role 角色对象
|
||||
*/
|
||||
public void insertRoleDept(Role role)
|
||||
{
|
||||
// 新增角色与部门(数据权限)管理
|
||||
List<RoleDept> list = new ArrayList<RoleDept>();
|
||||
for (Long deptId : role.getDeptIds())
|
||||
{
|
||||
RoleDept rd = new RoleDept();
|
||||
rd.setRoleId(role.getRoleId());
|
||||
rd.setDeptId(deptId);
|
||||
list.add(rd);
|
||||
}
|
||||
if (list.size() > 0)
|
||||
{
|
||||
roleDeptMapper.batchRoleDept(list);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 校验角色名称是否唯一
|
||||
*
|
||||
|
|
|
|||
|
|
@ -24,6 +24,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
select t.dept_id, t.parent_id, t.dept_name, t.order_num, t.leader, t.phone, t.email, t.status, t.create_by, t.create_time from sys_dept t
|
||||
</sql>
|
||||
|
||||
<select id="selectRoleDeptTree" parameterType="Long" resultType="String">
|
||||
select concat(m.menu_id, m.perms) as perms
|
||||
from sys_menu m
|
||||
left join sys_role_menu rm on m.menu_id = rm.menu_id
|
||||
where rm.role_id = #{roleId}
|
||||
order by m.parent_id, m.order_num
|
||||
</select>
|
||||
|
||||
<select id="selectDeptAll" resultMap="DeptResult">
|
||||
<include refid="selectDeptVo"/>
|
||||
</select>
|
||||
|
|
|
|||
|
|
@ -49,6 +49,12 @@
|
|||
<div id="menuTrees" class="ztree"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label">数据权限</label>
|
||||
<div class="col-sm-8">
|
||||
<div id="deptTrees" class="ztree"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="form-control-static col-sm-offset-9">
|
||||
<button type="submit" class="btn btn-primary">提交</button>
|
||||
|
|
@ -77,7 +83,25 @@
|
|||
menuTrees = $.fn.zTree.init($("#menuTrees"), setting, data); //.expandAll(true);
|
||||
}, null, null, "正在加载,请稍后...");
|
||||
};loadTree();
|
||||
|
||||
|
||||
// 部门(数据权限)树结构初始化加载
|
||||
var deptsetting = {
|
||||
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 deptTrees = $.fn.zTree.getZTreeObj(treeId);
|
||||
deptTrees.checkNode(treeNode, !treeNode.checked, true, true);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}, deptTrees, loadTree = function(){
|
||||
$.get(ctx + "system/menu/roleMenuTreeData?roleId=" + $("#roleId").val(), function(data) {
|
||||
deptTrees = $.fn.zTree.init($("#deptTrees"), deptsetting, data); //.expandAll(true);
|
||||
}, null, null, "正在加载,请稍后...");
|
||||
};loadTree();
|
||||
|
||||
$("#form-role-edit").validate({
|
||||
rules:{
|
||||
roleName:{
|
||||
|
|
|
|||
Loading…
Reference in New Issue