change - 角色信息添加数据权限

main
wenjy 3 years ago
parent 5fa3df1912
commit ef2a05dd41

@ -6,6 +6,7 @@ import java.util.UUID;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.ruoyi.common.core.domain.entity.SysRole;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.ShiroUtils;
import com.ruoyi.system.domain.BaseAlarmInfo;
@ -274,4 +275,19 @@ public class BaseMonitorunitInfoController extends BaseController {
List<Ztree> ztrees = baseMonitorunitInfoService.selectBaseMonitorunitInfoTree();
return ztrees;
}
/**
* Id
* @author WenJY
* @date 2022-05-14 16:22
* @param role
* @return java.util.List<com.ruoyi.common.core.domain.Ztree>
*/
@GetMapping("/getMonitorunitTreeByRoleId")
@ResponseBody
public List<Ztree> getMonitorunitTreeByRoleId(SysRole role) {
Long userId = ShiroUtils.getUserId();
List<Ztree> ztreeList = baseMonitorunitInfoService.roleMonitorUnitTreeData(role, userId);
return ztreeList;
}
}

@ -53,6 +53,19 @@
<div id="menuTrees" class="ztree ztree-border"></div>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">数据权限:</label>
<div class="col-sm-8">
<!--<label class="check-box">
<input type="checkbox" value="1">展开/折叠</label>
<label class="check-box">
<input type="checkbox" value="2">全选/全不选</label>
<label class="check-box">
<input type="checkbox" value="3" checked>父子联动</label>-->
<div id="menuTreess" class="ztree ztree-border"></div>
</div>
</div>
</form>
</div>
<th:block th:include="include :: footer" />
@ -67,6 +80,16 @@
expandLevel: 0
};
$.tree.init(options);
//监控单元树
let monitorUnitTreeUrl = ctx + "base/monitorUnitInfo/getMonitorunitTreeByRoleId";
let dataOptions = {
id: "menuTreess",
url: monitorUnitTreeUrl,
check:{ enable: true },
expandLevel: 0
}
$.tree.init(dataOptions);
});
$("#form-role-add").validate({
@ -153,7 +176,9 @@
var roleSort = $("input[name='roleSort']").val();
var status = $("input[id='status']").is(':checked') == true ? 0 : 1;
var remark = $("input[name='remark']").val();
var menuIds = $.tree.getCheckedNodes();
//var menuIds = $.tree.getCheckedNodes();
var menuIds = getCheckedNodes("menuTrees");
var monitorunits = getCheckedNodes("menuTreess");
$.ajax({
cache : true,
type : "POST",
@ -164,7 +189,8 @@
"roleSort": roleSort,
"status": status,
"remark": remark,
"menuIds": menuIds
"menuIds": menuIds,
"monitorunits":monitorunits,
},
async : false,
error : function(request) {
@ -175,6 +201,17 @@
}
});
}
const getCheckedNodes = (ids) =>{
let zTreeObj = $.fn.zTree.getZTreeObj(ids);
let nodes = zTreeObj.getCheckedNodes(true);
console.log(nodes);
let result = [];
nodes.map(x=>{
result.push(x.id);
})
return result;
}
</script>
</body>
</html>

@ -54,6 +54,19 @@
<div id="menuTrees" class="ztree ztree-border"></div>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">数据权限:</label>
<div class="col-sm-8">
<!--<label class="check-box">
<input type="checkbox" value="1">展开/折叠</label>
<label class="check-box">
<input type="checkbox" value="2">全选/全不选</label>
<label class="check-box">
<input type="checkbox" value="3" checked>父子联动</label>-->
<div id="menuTreess" class="ztree ztree-border"></div>
</div>
</div>
</form>
</div>
<th:block th:include="include :: footer" />
@ -68,6 +81,16 @@
expandLevel: 0
};
$.tree.init(options);
//监控单元树
let monitorUnitTreeUrl = ctx + "base/monitorUnitInfo/getMonitorunitTreeByRoleId?roleId=" + $("#roleId").val();
let dataOptions = {
id: "menuTreess",
url: monitorUnitTreeUrl,
check:{ enable: true },
expandLevel: 0
}
$.tree.init(dataOptions);
});
$("#form-role-edit").validate({
@ -155,7 +178,10 @@
var roleSort = $("input[name='roleSort']").val();
var status = $("input[id='status']").is(':checked') == true ? 0 : 1;
var remark = $("input[name='remark']").val();
var menuIds = $.tree.getCheckedNodes();
//var menuIds = $.tree.getCheckedNodes();
var menuIds = getCheckedNodes("menuTrees");
var monitorunits = getCheckedNodes("menuTreess");
$.ajax({
cache : true,
type : "POST",
@ -167,7 +193,8 @@
"roleSort": roleSort,
"status": status,
"remark": remark,
"menuIds": menuIds
"menuIds": menuIds,
"monitorunits":monitorunits,
},
async : false,
error : function(request) {
@ -184,6 +211,16 @@
edit();
}
}
const getCheckedNodes = (ids) =>{
let zTreeObj = $.fn.zTree.getZTreeObj(ids);
let nodes = zTreeObj.getCheckedNodes(true);
let result = [];
nodes.map(x=>{
result.push(x.id);
})
return result;
}
</script>
</body>
</html>

@ -116,10 +116,10 @@
var actions = [];
actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.roleId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.roleId + '\')"><i class="fa fa-remove"></i>删除</a> ');
var more = [];
/*var more = [];
more.push("<a class='btn btn-default btn-xs " + editFlag + "' href='javascript:void(0)' onclick='authDataScope(" + row.roleId + ")'><i class='fa fa-check-square-o'></i>数据权限</a> ");
more.push("<a class='btn btn-default btn-xs " + editFlag + "' href='javascript:void(0)' onclick='authUser(" + row.roleId + ")'><i class='fa fa-user'></i>分配用户</a>");
actions.push('<a tabindex="0" class="btn btn-info btn-xs" role="button" data-container="body" data-placement="left" data-toggle="popover" data-html="true" data-trigger="hover" data-content="' + more.join('') + '"><i class="fa fa-chevron-circle-right"></i>更多操作</a>');
actions.push('<a tabindex="0" class="btn btn-info btn-xs" role="button" data-container="body" data-placement="left" data-toggle="popover" data-html="true" data-trigger="hover" data-content="' + more.join('') + '"><i class="fa fa-chevron-circle-right"></i>更多操作</a>');*/
return actions.join('');
} else {
return "";

@ -52,6 +52,8 @@ public class SysRole extends BaseEntity
/** 部门组(数据权限) */
private Long[] deptIds;
private String[] monitorunits;
public SysRole()
{
@ -177,6 +179,14 @@ public class SysRole extends BaseEntity
this.deptIds = deptIds;
}
public String[] getMonitorunits() {
return monitorunits;
}
public void setMonitorunits(String[] monitorunits) {
this.monitorunits = monitorunits;
}
@Override
public String toString() {
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)

@ -16,6 +16,9 @@ public class SysRoleMenu
/** 菜单ID */
private Long menuId;
/** 监控单元ID */
private String monitorunitId;
public Long getRoleId()
{
return roleId;
@ -36,6 +39,14 @@ public class SysRoleMenu
this.menuId = menuId;
}
public String getMonitorunitId() {
return monitorunitId;
}
public void setMonitorunitId(String monitorunitId) {
this.monitorunitId = monitorunitId;
}
@Override
public String toString() {
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)

@ -68,4 +68,6 @@ public interface BaseMonitorunitInfoMapper
* @return
*/
public int deleteBaseMonitorunitInfoByObjIds(String[] ObjIds);
public List<String> selectMonitorUnitTreeByRoleId(Long roleId);
}

@ -18,6 +18,15 @@ public interface SysRoleMenuMapper
*/
public int deleteRoleMenuByRoleId(Long roleId);
/**
*
* @author WenJY
* @date 2022-05-14 16:49
* @param roleId
* @return int
*/
public int deleteRoleMonitorunitByRoleId(Long roleId);
/**
*
*
@ -41,4 +50,13 @@ public interface SysRoleMenuMapper
* @return
*/
public int batchRoleMenu(List<SysRoleMenu> roleMenuList);
/**
*
* @author WenJY
* @date 2022-05-14 16:53
* @param roleMenuList
* @return int
*/
public int batchRoleMonitorUnit(List<SysRoleMenu> roleMenuList);
}

@ -1,6 +1,8 @@
package com.ruoyi.system.service;
import java.util.List;
import com.ruoyi.common.core.domain.entity.SysRole;
import com.ruoyi.system.domain.BaseMonitorunitInfo;
import com.ruoyi.common.core.domain.Ztree;
import com.ruoyi.system.domain.dto.BaseMonitorunitInfoDto;
@ -85,4 +87,6 @@ public interface IBaseMonitorunitInfoService
* @return
*/
public List<Ztree> selectBaseMonitorunitInfoTree();
public List<Ztree> roleMonitorUnitTreeData(SysRole role,Long userId);
}

@ -4,6 +4,8 @@ import java.util.Date;
import java.util.List;
import java.util.ArrayList;
import com.ruoyi.common.core.domain.Ztree;
import com.ruoyi.common.core.domain.entity.SysMenu;
import com.ruoyi.common.core.domain.entity.SysRole;
import com.ruoyi.common.exception.BusinessException;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.ShiroUtils;
@ -202,4 +204,52 @@ public class BaseMonitorunitInfoServiceImpl implements IBaseMonitorunitInfoServi
}
return ztrees;
}
@Override
public List<Ztree> roleMonitorUnitTreeData(SysRole role, Long userId) {
Long roleId = role.getRoleId();
List<Ztree> ztrees = new ArrayList<Ztree>();
//获取所以监控单元
List<BaseMonitorunitInfo> baseMonitorunitInfos = this.selectBaseMonitorunitInfoList(new BaseMonitorunitInfo());
if (StringUtils.isNotNull(roleId))
{
List<String> roleMonitorUnitList = baseMonitorunitInfoMapper.selectMonitorUnitTreeByRoleId(roleId);
ztrees = initZtree(baseMonitorunitInfos, roleMonitorUnitList, true);
}
else
{
ztrees = initZtree(baseMonitorunitInfos, null, true);
}
return ztrees;
}
/**
*
*
* @param monitorunitInfoList
* @param roleMonitorUnitList
* @param permsFlag
* @return
*/
public List<Ztree> initZtree(List<BaseMonitorunitInfo> monitorunitInfoList, List<String> roleMonitorUnitList, boolean permsFlag)
{
List<Ztree> ztrees = new ArrayList<Ztree>();
boolean isCheck = StringUtils.isNotNull(roleMonitorUnitList);
for (BaseMonitorunitInfo monitorunitInfo : monitorunitInfoList)
{
Ztree ztree = new Ztree();
ztree.setId(monitorunitInfo.getMonitorunitId());
ztree.setpId(monitorunitInfo.getParentId());
ztree.setName(monitorunitInfo.getMonitorunitName());
ztree.setTitle(monitorunitInfo.getMonitorunitName());
if (isCheck)
{
ztree.setChecked(roleMonitorUnitList.contains(monitorunitInfo.getMonitorunitId()));
}
ztrees.add(ztree);
}
return ztrees;
}
}

@ -184,6 +184,7 @@ public class SysRoleServiceImpl implements ISysRoleService
{
// 新增角色信息
roleMapper.insertRole(role);
insertMonitorUnit(role);
return insertRoleMenu(role);
}
@ -201,6 +202,17 @@ public class SysRoleServiceImpl implements ISysRoleService
roleMapper.updateRole(role);
// 删除角色与菜单关联
roleMenuMapper.deleteRoleMenuByRoleId(role.getRoleId());
try{
// 删除角色与监控单元关联
int i = roleMenuMapper.deleteRoleMonitorunitByRoleId(role.getRoleId());
//新增角色监控单元信息
int i1 = insertMonitorUnit(role);
}catch(Exception ex){
System.out.println(ex);
}
return insertRoleMenu(role);
}
@ -270,6 +282,31 @@ public class SysRoleServiceImpl implements ISysRoleService
return rows;
}
/**
*
* @author WenJY
* @date 2022-05-14 16:55
* @param role
* @return int
*/
public int insertMonitorUnit(SysRole role){
int rows = 1;
// 新增用户与角色管理
List<SysRoleMenu> list = new ArrayList<SysRoleMenu>();
for (String monitorunitId : role.getMonitorunits())
{
SysRoleMenu rm = new SysRoleMenu();
rm.setRoleId(role.getRoleId());
rm.setMonitorunitId(monitorunitId);
list.add(rm);
}
if (list.size() > 0)
{
rows = roleMenuMapper.batchRoleMonitorUnit(list);
}
return rows;
}
/**
*
*

@ -146,4 +146,9 @@
</foreach>
</delete>
<select id="selectMonitorUnitTreeByRoleId" parameterType="Long" resultType="String">
select monitorUnit_Id
from sys_role_monitorinfo
where role_id = #{roleId}
</select>
</mapper>

@ -24,6 +24,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</foreach>
</delete>
<delete id="deleteRoleMonitorunitByRoleId" parameterType="Long">
delete from sys_role_monitorinfo where role_id=#{roleId}
</delete>
<insert id="batchRoleMenu">
insert into sys_role_menu(role_id, menu_id) values
<foreach item="item" index="index" collection="list" separator=",">
@ -31,4 +35,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</foreach>
</insert>
<insert id="batchRoleMonitorUnit">
insert into sys_role_monitorinfo(role_id, monitorUnit_Id) values
<foreach item="item" index="index" collection="list" separator=",">
(#{item.roleId},#{item.monitorunitId})
</foreach>
</insert>
</mapper>
Loading…
Cancel
Save