Browse Source

[feat] 系统模块

系统角色前端页面:新增导出角色权限前端按钮,新增导出全部和导出选择的数据的js方法
系统角色后端接口:新增导出全部角色权限后端接口,新增导出课选择的数据后端接口;
系统角色mapper,service层新增根据角色id批量查询角色数据集合
dev
liuxiaoxu 2 months ago
parent
commit
42aa2dfb34
  1. 106
      ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysRoleController.java
  2. 59
      ruoyi-admin/src/main/resources/templates/system/role/role.html
  3. 8
      ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysRoleMapper.java
  4. 10
      ruoyi-system/src/main/java/com/ruoyi/system/service/ISysRoleService.java
  5. 12
      ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysRoleServiceImpl.java
  6. 12
      ruoyi-system/src/main/resources/mapper/system/SysRoleMapper.xml

106
ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysRoleController.java

@ -1,16 +1,20 @@
package com.ruoyi.web.controller.system;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import com.alibaba.excel.EasyExcel;
import com.ruoyi.common.core.domain.Ztree;
import com.ruoyi.common.core.domain.entity.vo.ExportRoleMenuVo;
import com.ruoyi.system.domain.SysSalesShippingInform;
import com.ruoyi.system.service.ISysMenuService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.core.controller.BaseController;
@ -43,6 +47,9 @@ public class SysRoleController extends BaseController
@Autowired
private ISysUserService userService;
@Autowired
private ISysMenuService menuService;
@RequiresPermissions("system:role:view")
@GetMapping()
public String role()
@ -295,4 +302,93 @@ public class SysRoleController extends BaseController
{
return toAjax(roleService.insertAuthUsers(roleId, userIds));
}
/**
* 导出全部角色权限
*/
@RequiresPermissions("system:role:export")
@Log(title = "角色管理", businessType = BusinessType.EXPORT)
@PostMapping("/exportAllRoleMenu")
@ResponseBody
public AjaxResult exportAllRoleMenu(SysRole role) {
try {
// 获取所有角色列表
List<SysRole> sysRoles = roleService.selectRoleList(role);
// 获取当前用户的ID
Long userId = ShiroUtils.getUserId();
// 初始化导出的角色菜单VO列表
List<ExportRoleMenuVo> exportRoleMenuVos = new ArrayList<>();
// 处理每个角色及其关联的已选菜单
sysRoles.forEach(sysRole -> {
List<Ztree> ztrees = menuService.roleMenuTreeData(sysRole, userId);
List<Ztree> checkedMenus = ztrees.stream()
.filter(Ztree::isChecked) //只需要勾选的菜单权限
.collect(Collectors.toList());
// 缓存角色信息以减少数据库查询次数
SysRole tempSysRole = roleService.selectRoleById(sysRole.getRoleId());
checkedMenus.forEach(data -> {
ExportRoleMenuVo exportRoleMenuVo = new ExportRoleMenuVo();
exportRoleMenuVo.setRoleName(tempSysRole.getRoleName());
exportRoleMenuVo.setRoleKey(tempSysRole.getRoleKey());
exportRoleMenuVo.setTitle(data.getTitle());
exportRoleMenuVos.add(exportRoleMenuVo);
});
});
ExcelUtil<ExportRoleMenuVo> util = new ExcelUtil<ExportRoleMenuVo>(ExportRoleMenuVo.class);
return util.exportExcel(exportRoleMenuVos, "角色菜单数据");
} catch (Exception e) {
return AjaxResult.error("导出角色菜单数据失败");
}
}
/**
* 导出选择的角色权限
*/
@RequiresPermissions("system:role:export")
@Log(title = "角色管理", businessType = BusinessType.EXPORT)
@PostMapping("/exportRoleMenu")
@ResponseBody
public AjaxResult exportRoleMenu(@RequestBody String[] roleIds) {
try {
// 获取所有角色列表
List<SysRole> sysRoles = roleService.selectRoleListByRoleIds(roleIds);
// 获取当前用户的ID
Long userId = ShiroUtils.getUserId();
// 初始化导出的角色菜单VO列表
List<ExportRoleMenuVo> exportRoleMenuVos = new ArrayList<>();
// 处理每个角色及其关联的已选菜单
sysRoles.forEach(sysRole -> {
List<Ztree> ztrees = menuService.roleMenuTreeData(sysRole, userId);
List<Ztree> checkedMenus = ztrees.stream()
.filter(Ztree::isChecked) //只需要勾选的菜单权限
.collect(Collectors.toList());
// 缓存角色信息以减少数据库查询次数
SysRole tempSysRole = roleService.selectRoleById(sysRole.getRoleId());
checkedMenus.forEach(data -> {
ExportRoleMenuVo exportRoleMenuVo = new ExportRoleMenuVo();
exportRoleMenuVo.setRoleName(tempSysRole.getRoleName());
exportRoleMenuVo.setRoleKey(tempSysRole.getRoleKey());
exportRoleMenuVo.setTitle(data.getTitle());
exportRoleMenuVos.add(exportRoleMenuVo);
});
});
ExcelUtil<ExportRoleMenuVo> util = new ExcelUtil<ExportRoleMenuVo>(ExportRoleMenuVo.class);
return util.exportExcel(exportRoleMenuVos, "角色菜单数据");
} catch (Exception e) {
return AjaxResult.error("导出角色菜单数据失败");
}
}
}

59
ruoyi-admin/src/main/resources/templates/system/role/role.html

@ -50,6 +50,10 @@
<a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:role:export">
<i class="fa fa-download"></i> 导出
</a>
<a class="btn btn-warning" onclick="exportRoleMenu()" shiro:hasPermission="system:role:export">
<i class="fa fa-download"></i> 导出角色权限
</a>
</div>
<div class="col-sm-12 select-table table-striped">
@ -160,6 +164,61 @@
$.operate.post(prefix + "/changeStatus", { "roleId": roleId, "status": 0 });
})
}
//导出角色权限
function exportRoleMenu(formId) {
// $.table.set();
var roleIdData = [];
var selections = $("#bootstrap-table").bootstrapTable("getSelections");
if(selections.length === 0){
$.modal.confirm("确定导出所有角色权限吗?", function() {
var currentId = $.common.isEmpty(formId) ? $('form').attr('id') : formId;
var params = $("#bootstrap-table").bootstrapTable('getOptions');
var dataParam = $("#" + currentId).serializeArray();
dataParam.push({ "name": "orderByColumn", "value": params.sortName });
dataParam.push({ "name": "isAsc", "value": params.sortOrder });
$.modal.loading("正在导出数据,请稍后...");
$.post(prefix + '/exportAllRoleMenu', dataParam, function(result) {
if (result.code == web_status.SUCCESS) {
window.location.href = ctx + "common/download?fileName=" + encodeURI(result.msg) + "&delete=" + true;
} else if (result.code == web_status.WARNING) {
$.modal.alertWarning(result.msg)
} else {
$.modal.alertError(result.msg);
}
$.modal.closeLoading();
});
});
}else {
$.modal.confirm("确定导出选中的所有角色权限吗?", function () {
//·拼接单号
for(let i=0;i<selections.length;i++){
roleIdData.push(selections[i].roleId);
}
var roleIds = JSON.stringify(roleIdData);
// console.log(bomNos);
$.modal.loading("正在导出数据,请稍后...");
var config = {
url: prefix + '/exportRoleMenu',
type: "post",
dataType: "json",
contentType: "application/json;charset=utf-8",
data: roleIds,
success: function(result) {
window.location.href = ctx + "common/download?fileName=" + encodeURI(result.msg) + "&delete=" + true;
$.modal.alertSuccess("导出成功!")
$.modal.closeLoading();
},
error: function (result){
$.modal.alertError(result.msg);
}
};
$.ajax(config)
});
}
};
</script>
</body>
</html>

8
ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysRoleMapper.java

@ -81,4 +81,12 @@ public interface SysRoleMapper
* @return 角色信息
*/
public SysRole checkRoleKeyUnique(String roleKey);
/**
* 批量查询角色数据
*
* @param roleIds 角色id集合
* @return 角色数据集合信息
*/
List<SysRole> selectRoleListByRoleIds(String[] roleIds);
}

10
ruoyi-system/src/main/java/com/ruoyi/system/service/ISysRoleService.java

@ -20,6 +20,16 @@ public interface ISysRoleService
*/
public List<SysRole> selectRoleList(SysRole role);
/**
* 根据条件分页查询角色数据
*
* @param roleIds 角色id集合
* @return 角色数据集合信息
*/
public List<SysRole> selectRoleListByRoleIds(String[] roleIds);
/**
* 根据用户ID查询角色
*

12
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysRoleServiceImpl.java

@ -57,6 +57,18 @@ public class SysRoleServiceImpl implements ISysRoleService
return roleMapper.selectRoleList(role);
}
/**
* 批量查询角色数据
*
* @param roleIds 角色id集合
* @return 角色数据集合信息
*/
@Override
public List<SysRole> selectRoleListByRoleIds(String[] roleIds) {
List<SysRole> list = roleMapper.selectRoleListByRoleIds(roleIds);
return list;
}
/**
* 根据用户ID查询权限
*

12
ruoyi-system/src/main/resources/mapper/system/SysRoleMapper.xml

@ -77,8 +77,16 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<include refid="selectRoleVo"/>
where r.role_key=#{roleKey} limit 1
</select>
<delete id="deleteRoleById" parameterType="Long">
<select id="selectRoleListByRoleIds" parameterType="String" resultMap="SysRoleResult">
<include refid="selectRoleVo"/>
where r.role_id in
<foreach collection="array" item="roleId" open="(" separator="," close=")">
#{roleId}
</foreach>
</select>
<delete id="deleteRoleById" parameterType="Long">
update sys_role set del_flag = '2' where role_id = #{roleId}
</delete>

Loading…
Cancel
Save