更新数据权限基础1
This commit is contained in:
parent
eb72d42b77
commit
a29a7abbda
|
|
@ -72,4 +72,12 @@ public interface DeptMapper
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
public Dept checkDeptNameUnique(String deptName);
|
public Dept checkDeptNameUnique(String deptName);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据角色ID查询菜单
|
||||||
|
*
|
||||||
|
* @param roleId 角色ID
|
||||||
|
* @return 菜单列表
|
||||||
|
*/
|
||||||
|
public List<String> selectRoleDeptTree(Long roleId);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -46,22 +46,11 @@ public class DeptServiceImpl implements IDeptService
|
||||||
{
|
{
|
||||||
List<Map<String, Object>> trees = new ArrayList<Map<String, Object>>();
|
List<Map<String, Object>> trees = new ArrayList<Map<String, Object>>();
|
||||||
List<Dept> deptList = deptMapper.selectDeptAll();
|
List<Dept> deptList = deptMapper.selectDeptAll();
|
||||||
|
trees=getTrees(deptList,false,null);
|
||||||
for (Dept dept : deptList)
|
|
||||||
{
|
|
||||||
if (UserConstants.DEPT_NORMAL.equals(dept.getStatus()))
|
|
||||||
{
|
|
||||||
Map<String, Object> deptMap = new HashMap<String, Object>();
|
|
||||||
deptMap.put("id", dept.getDeptId());
|
|
||||||
deptMap.put("pId", dept.getParentId());
|
|
||||||
deptMap.put("name", dept.getDeptName());
|
|
||||||
deptMap.put("title", dept.getDeptName());
|
|
||||||
trees.add(deptMap);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return trees;
|
return trees;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据角色ID查询部门(数据权限)
|
* 根据角色ID查询部门(数据权限)
|
||||||
*
|
*
|
||||||
|
|
@ -70,17 +59,50 @@ public class DeptServiceImpl implements IDeptService
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<Map<String, Object>> roleDeptTreeData(Role role) {
|
public List<Map<String, Object>> roleDeptTreeData(Role role) {
|
||||||
Long roleId = role.getRoleId();
|
Long roleId=role.getRoleId();
|
||||||
List<Map<String, Object>> trees = new ArrayList<Map<String, Object>>();
|
List<Map<String, Object>> trees = new ArrayList<Map<String, Object>>();
|
||||||
List<Dept> deptList=deptMapper.selectDeptAll();
|
List<Dept> deptList=deptMapper.selectDeptAll();
|
||||||
if(StringUtils.isNotNull(roleId)){
|
if(StringUtils.isNotNull(roleId)){
|
||||||
// List<String> roleDeptList=deptMapper.
|
List<String> roleDeptList=deptMapper.selectRoleDeptTree(roleId);
|
||||||
|
trees=getTrees(deptList,true,roleDeptList);
|
||||||
}else {
|
}else {
|
||||||
|
trees=getTrees(deptList,false,null);
|
||||||
}
|
}
|
||||||
return null;
|
return trees;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 对象转菜单树
|
||||||
|
*
|
||||||
|
* @param menuList 菜单列表
|
||||||
|
* @param isCheck 是否需要选中
|
||||||
|
* @param roleDeptList 角色已存在菜单列表
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public List<Map<String, Object>> getTrees(List<Dept> menuList, boolean isCheck, List<String> roleDeptList){
|
||||||
|
|
||||||
|
List<Map<String, Object>> trees = new ArrayList<Map<String, Object>>();
|
||||||
|
for (Dept dept : menuList)
|
||||||
|
{
|
||||||
|
if (UserConstants.DEPT_NORMAL.equals(dept.getStatus()))
|
||||||
|
{
|
||||||
|
Map<String, Object> deptMap = new HashMap<String, Object>();
|
||||||
|
deptMap.put("id", dept.getDeptId());
|
||||||
|
deptMap.put("pId", dept.getParentId());
|
||||||
|
deptMap.put("name", dept.getDeptName());
|
||||||
|
deptMap.put("title", dept.getDeptName());
|
||||||
|
if (isCheck)
|
||||||
|
{
|
||||||
|
deptMap.put("checked", roleDeptList.contains(dept.getDeptId() + dept.getDeptName()));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
deptMap.put("checked", false);
|
||||||
|
}
|
||||||
|
trees.add(deptMap);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return trees;
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* 查询部门人数
|
* 查询部门人数
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -107,8 +107,7 @@ public class MenuServiceImpl implements IMenuService
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询所有菜单
|
* 查询所有菜单
|
||||||
*
|
*
|
||||||
* @param role 角色对象
|
|
||||||
* @return 菜单列表
|
* @return 菜单列表
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -25,11 +25,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
</sql>
|
</sql>
|
||||||
|
|
||||||
<select id="selectRoleDeptTree" parameterType="Long" resultType="String">
|
<select id="selectRoleDeptTree" parameterType="Long" resultType="String">
|
||||||
select concat(m.menu_id, m.perms) as perms
|
select concat(d.dept_id, d.dept_name) as dept_name
|
||||||
from sys_menu m
|
from sys_dept d
|
||||||
left join sys_role_menu rm on m.menu_id = rm.menu_id
|
left join sys_role_dept rd on d.dept_id = rd.dept_id
|
||||||
where rm.role_id = #{roleId}
|
where rd.role_id = #{roleId}
|
||||||
order by m.parent_id, m.order_num
|
order by d.parent_id, d.order_num
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="selectDeptAll" resultMap="DeptResult">
|
<select id="selectDeptAll" resultMap="DeptResult">
|
||||||
|
|
|
||||||
|
|
@ -97,7 +97,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, deptTrees, loadTree = function(){
|
}, deptTrees, loadTree = function(){
|
||||||
$.get(ctx + "system/menu/roleMenuTreeData?roleId=" + $("#roleId").val(), function(data) {
|
$.get(ctx + "system/dept/roleDeptTreeData?roleId=" + $("#roleId").val(), function(data) {
|
||||||
deptTrees = $.fn.zTree.init($("#deptTrees"), deptsetting, data); //.expandAll(true);
|
deptTrees = $.fn.zTree.init($("#deptTrees"), deptsetting, data); //.expandAll(true);
|
||||||
}, null, null, "正在加载,请稍后...");
|
}, null, null, "正在加载,请稍后...");
|
||||||
};loadTree();
|
};loadTree();
|
||||||
|
|
@ -154,7 +154,20 @@
|
||||||
}
|
}
|
||||||
return menuIds;
|
return menuIds;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function selectDeptCheckeds() {
|
||||||
|
var deptIds = "";
|
||||||
|
var treeNodes = deptTrees.getCheckedNodes(true);
|
||||||
|
for (var i = 0; i < treeNodes.length; i++) {
|
||||||
|
if (0 == i) {
|
||||||
|
deptIds = treeNodes[i].id;
|
||||||
|
} else {
|
||||||
|
deptIds += ("," + treeNodes[i].id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return deptIds;
|
||||||
|
}
|
||||||
|
|
||||||
function edit() {
|
function edit() {
|
||||||
var roleId = $("input[name='roleId']").val();
|
var roleId = $("input[name='roleId']").val();
|
||||||
var roleName = $("input[name='roleName']").val();
|
var roleName = $("input[name='roleName']").val();
|
||||||
|
|
@ -163,6 +176,7 @@
|
||||||
var status = $("input[name='status']").is(':checked') == true ? 0 : 1;
|
var status = $("input[name='status']").is(':checked') == true ? 0 : 1;
|
||||||
var remark = $("input[name='remark']").val();
|
var remark = $("input[name='remark']").val();
|
||||||
var menuIds = selectCheckeds();
|
var menuIds = selectCheckeds();
|
||||||
|
var deptIds = selectDeptCheckeds();
|
||||||
$.ajax({
|
$.ajax({
|
||||||
cache : true,
|
cache : true,
|
||||||
type : "POST",
|
type : "POST",
|
||||||
|
|
@ -174,7 +188,8 @@
|
||||||
"roleSort": roleSort,
|
"roleSort": roleSort,
|
||||||
"status": status,
|
"status": status,
|
||||||
"remark": remark,
|
"remark": remark,
|
||||||
"menuIds": menuIds
|
"menuIds": menuIds,
|
||||||
|
"deptIds": deptIds
|
||||||
},
|
},
|
||||||
async : false,
|
async : false,
|
||||||
error : function(request) {
|
error : function(request) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue