|
@ -1,16 +1,20 @@ |
|
|
package com.ruoyi.web.controller.system; |
|
|
package com.ruoyi.web.controller.system; |
|
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
import java.util.List; |
|
|
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.apache.shiro.authz.annotation.RequiresPermissions; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.stereotype.Controller; |
|
|
import org.springframework.stereotype.Controller; |
|
|
import org.springframework.ui.ModelMap; |
|
|
import org.springframework.ui.ModelMap; |
|
|
import org.springframework.validation.annotation.Validated; |
|
|
import org.springframework.validation.annotation.Validated; |
|
|
import org.springframework.web.bind.annotation.GetMapping; |
|
|
import org.springframework.web.bind.annotation.*; |
|
|
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 com.ruoyi.common.annotation.Log; |
|
|
import com.ruoyi.common.annotation.Log; |
|
|
import com.ruoyi.common.constant.UserConstants; |
|
|
import com.ruoyi.common.constant.UserConstants; |
|
|
import com.ruoyi.common.core.controller.BaseController; |
|
|
import com.ruoyi.common.core.controller.BaseController; |
|
@ -43,6 +47,9 @@ public class SysRoleController extends BaseController |
|
|
@Autowired |
|
|
@Autowired |
|
|
private ISysUserService userService; |
|
|
private ISysUserService userService; |
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
|
private ISysMenuService menuService; |
|
|
|
|
|
|
|
|
@RequiresPermissions("system:role:view") |
|
|
@RequiresPermissions("system:role:view") |
|
|
@GetMapping() |
|
|
@GetMapping() |
|
|
public String role() |
|
|
public String role() |
|
@ -295,4 +302,93 @@ public class SysRoleController extends BaseController |
|
|
{ |
|
|
{ |
|
|
return toAjax(roleService.insertAuthUsers(roleId, userIds)); |
|
|
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("导出角色菜单数据失败"); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |