diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/base/BaseMonitorunitInfoController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/base/BaseMonitorunitInfoController.java index 0c6a7e9..723abd9 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/base/BaseMonitorunitInfoController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/base/BaseMonitorunitInfoController.java @@ -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 ztrees = baseMonitorunitInfoService.selectBaseMonitorunitInfoTree(); return ztrees; } + + /** + * 根据角色Id获取监控单元树形数据 + * @author WenJY + * @date 2022-05-14 16:22 + * @param role + * @return java.util.List + */ + @GetMapping("/getMonitorunitTreeByRoleId") + @ResponseBody + public List getMonitorunitTreeByRoleId(SysRole role) { + Long userId = ShiroUtils.getUserId(); + List ztreeList = baseMonitorunitInfoService.roleMonitorUnitTreeData(role, userId); + return ztreeList; + } } diff --git a/ruoyi-admin/src/main/resources/templates/system/role/add.html b/ruoyi-admin/src/main/resources/templates/system/role/add.html index 1083c7d..b2906ff 100644 --- a/ruoyi-admin/src/main/resources/templates/system/role/add.html +++ b/ruoyi-admin/src/main/resources/templates/system/role/add.html @@ -53,6 +53,19 @@ + +
+ +
+ + +
+
@@ -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; + } diff --git a/ruoyi-admin/src/main/resources/templates/system/role/edit.html b/ruoyi-admin/src/main/resources/templates/system/role/edit.html index 994d0fa..2c75bf3 100644 --- a/ruoyi-admin/src/main/resources/templates/system/role/edit.html +++ b/ruoyi-admin/src/main/resources/templates/system/role/edit.html @@ -54,6 +54,19 @@ + +
+ +
+ + +
+
@@ -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; + } diff --git a/ruoyi-admin/src/main/resources/templates/system/role/role.html b/ruoyi-admin/src/main/resources/templates/system/role/role.html index 342551f..f06f0c8 100644 --- a/ruoyi-admin/src/main/resources/templates/system/role/role.html +++ b/ruoyi-admin/src/main/resources/templates/system/role/role.html @@ -116,10 +116,10 @@ var actions = []; actions.push('编辑 '); actions.push('删除 '); - var more = []; + /*var more = []; more.push("数据权限 "); more.push("分配用户"); - actions.push('更多操作'); + actions.push('更多操作');*/ return actions.join(''); } else { return ""; diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/SysRole.java b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/SysRole.java index 3169f80..8fa15bd 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/SysRole.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/SysRole.java @@ -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) diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysRoleMenu.java b/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysRoleMenu.java index de10a74..fcd9a54 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysRoleMenu.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysRoleMenu.java @@ -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) diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/BaseMonitorunitInfoMapper.java b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/BaseMonitorunitInfoMapper.java index ea21529..bf9af00 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/BaseMonitorunitInfoMapper.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/BaseMonitorunitInfoMapper.java @@ -68,4 +68,6 @@ public interface BaseMonitorunitInfoMapper * @return 结果 */ public int deleteBaseMonitorunitInfoByObjIds(String[] ObjIds); + + public List selectMonitorUnitTreeByRoleId(Long roleId); } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysRoleMenuMapper.java b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysRoleMenuMapper.java index 9b88796..d9d612e 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysRoleMenuMapper.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysRoleMenuMapper.java @@ -17,6 +17,15 @@ public interface SysRoleMenuMapper * @return 结果 */ 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 roleMenuList); + + /** + * 批量新增角色监控单元信息 + * @author WenJY + * @date 2022-05-14 16:53 + * @param roleMenuList + * @return int + */ + public int batchRoleMonitorUnit(List roleMenuList); } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/IBaseMonitorunitInfoService.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/IBaseMonitorunitInfoService.java index 5d533a0..0775ffa 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/IBaseMonitorunitInfoService.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/IBaseMonitorunitInfoService.java @@ -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 selectBaseMonitorunitInfoTree(); + + public List roleMonitorUnitTreeData(SysRole role,Long userId); } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/BaseMonitorunitInfoServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/BaseMonitorunitInfoServiceImpl.java index f72af88..a0d2a90 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/BaseMonitorunitInfoServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/BaseMonitorunitInfoServiceImpl.java @@ -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 roleMonitorUnitTreeData(SysRole role, Long userId) { + Long roleId = role.getRoleId(); + List ztrees = new ArrayList(); + + //获取所以监控单元 + List baseMonitorunitInfos = this.selectBaseMonitorunitInfoList(new BaseMonitorunitInfo()); + + if (StringUtils.isNotNull(roleId)) + { + List 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 initZtree(List monitorunitInfoList, List roleMonitorUnitList, boolean permsFlag) + { + List ztrees = new ArrayList(); + 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; + } } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysRoleServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysRoleServiceImpl.java index e457d38..348052e 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysRoleServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysRoleServiceImpl.java @@ -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 list = new ArrayList(); + 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; + } + /** * 校验角色名称是否唯一 * diff --git a/ruoyi-system/src/main/resources/mapper/system/BaseMonitorunitInfoMapper.xml b/ruoyi-system/src/main/resources/mapper/system/BaseMonitorunitInfoMapper.xml index 8c738cd..e736094 100644 --- a/ruoyi-system/src/main/resources/mapper/system/BaseMonitorunitInfoMapper.xml +++ b/ruoyi-system/src/main/resources/mapper/system/BaseMonitorunitInfoMapper.xml @@ -146,4 +146,9 @@ + \ No newline at end of file diff --git a/ruoyi-system/src/main/resources/mapper/system/SysRoleMenuMapper.xml b/ruoyi-system/src/main/resources/mapper/system/SysRoleMenuMapper.xml index d213bdd..cfa84c1 100644 --- a/ruoyi-system/src/main/resources/mapper/system/SysRoleMenuMapper.xml +++ b/ruoyi-system/src/main/resources/mapper/system/SysRoleMenuMapper.xml @@ -23,6 +23,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" #{roleId} + + + delete from sys_role_monitorinfo where role_id=#{roleId} + insert into sys_role_menu(role_id, menu_id) values @@ -30,5 +34,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" (#{item.roleId},#{item.menuId}) + + + insert into sys_role_monitorinfo(role_id, monitorUnit_Id) values + + (#{item.roleId},#{item.monitorunitId}) + + \ No newline at end of file