From 41d49aa3073a5c129468ef84c6af6b00e4514970 Mon Sep 17 00:00:00 2001
From: memorylkf <312904636@qq.com>
Date: Thu, 9 Apr 2026 17:33:11 +0800
Subject: [PATCH] =?UTF-8?q?feat:=20[=E7=B3=BB=E7=BB=9F=E7=AE=A1=E7=90=86]?=
=?UTF-8?q?=20[=E8=A7=92=E8=89=B2=E7=AE=A1=E7=90=86]=20=E5=AF=BC=E5=87=BA?=
=?UTF-8?q?=E8=A7=92=E8=89=B2=E6=9D=83=E9=99=90?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../java/com/hxhq/system/api/domain/SysRole.java | 1 -
hxhq-common/hxhq-common-core/pom.xml | 6 ++
.../hxhq/system/controller/SysRoleController.java | 98 +++++++++++++++++++++-
.../com/hxhq/system/dto/RoleMenuExportDto.java | 44 ++++++++++
.../java/com/hxhq/system/mapper/SysRoleMapper.java | 9 ++
.../com/hxhq/system/service/ISysRoleService.java | 8 ++
.../system/service/impl/SysRoleServiceImpl.java | 5 ++
.../main/resources/mapper/system/SysRoleMapper.xml | 7 ++
8 files changed, 175 insertions(+), 3 deletions(-)
create mode 100644 hxhq-modules/hxhq-system/src/main/java/com/hxhq/system/dto/RoleMenuExportDto.java
diff --git a/hxhq-api/hxhq-api-system/src/main/java/com/hxhq/system/api/domain/SysRole.java b/hxhq-api/hxhq-api-system/src/main/java/com/hxhq/system/api/domain/SysRole.java
index 7e05d0d..4a448fc 100644
--- a/hxhq-api/hxhq-api-system/src/main/java/com/hxhq/system/api/domain/SysRole.java
+++ b/hxhq-api/hxhq-api-system/src/main/java/com/hxhq/system/api/domain/SysRole.java
@@ -30,7 +30,6 @@ public class SysRole extends BaseEntity
private String roleName;
/** 角色权限 */
- @Excel(name = "角色编码",nameEn = "Role ID",sort = 2)
@Compare(name = "角色编码",nameEn = "Role ID")
private String roleKey;
diff --git a/hxhq-common/hxhq-common-core/pom.xml b/hxhq-common/hxhq-common-core/pom.xml
index 69d0b65..bba72ed 100644
--- a/hxhq-common/hxhq-common-core/pom.xml
+++ b/hxhq-common/hxhq-common-core/pom.xml
@@ -112,6 +112,12 @@
mybatis-plus-boot-starter
+
+ com.alibaba
+ easyexcel
+ 3.3.2
+
+
diff --git a/hxhq-modules/hxhq-system/src/main/java/com/hxhq/system/controller/SysRoleController.java b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/system/controller/SysRoleController.java
index b647b78..ff193d6 100644
--- a/hxhq-modules/hxhq-system/src/main/java/com/hxhq/system/controller/SysRoleController.java
+++ b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/system/controller/SysRoleController.java
@@ -1,10 +1,13 @@
package com.hxhq.system.controller;
-import java.util.ArrayList;
-import java.util.List;
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+import java.util.*;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletResponse;
+import com.alibaba.excel.EasyExcel;
import com.hxhq.business.domain.RoleChange;
import com.hxhq.business.domain.SystemLog;
import com.hxhq.business.form.common.SignForm;
@@ -13,12 +16,18 @@ import com.hxhq.business.service.ISystemLogService;
import com.hxhq.common.core.exception.ServiceException;
import com.hxhq.common.core.utils.ServletUtils;
import com.hxhq.common.core.utils.StringUtils;
+import com.hxhq.system.domain.SysMenu;
+import com.hxhq.system.domain.SysRoleMenu;
import com.hxhq.system.domain.SysUserRole;
+import com.hxhq.system.domain.vo.TreeSelect;
+import com.hxhq.system.dto.RoleMenuExportDto;
import com.hxhq.system.form.RoleSaveForm;
import com.hxhq.system.form.RoleUserSaveForm;
import com.hxhq.system.service.ISysDeptService;
+import com.hxhq.system.service.ISysMenuService;
import com.hxhq.system.service.ISysRoleService;
import com.hxhq.system.service.ISysUserService;
+import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
@@ -66,6 +75,9 @@ public class SysRoleController extends BaseController
@Autowired
private IRoleChangeService roleChangeService;
+ @Autowired
+ private ISysMenuService menuService;
+
@RequiresPermissions("system:role:list")
@GetMapping("/list")
public TableDataInfo list(SysRole role)
@@ -115,6 +127,9 @@ public class SysRoleController extends BaseController
{
return error("新增角色'" + role.getRoleName() + "'失败,角色编码已存在");
}
+ if(StringUtils.isBlank(role.getRoleKey())){
+ role.setRoleKey(UUID.randomUUID().toString());
+ }
role.setCreateBy(SecurityUtils.getUsername());
return toAjax(roleService.insertRole(form));
@@ -342,4 +357,83 @@ public class SysRoleController extends BaseController
ajax.put("depts", deptService.selectDeptTreeList(new SysDept()));
return ajax;
}
+
+ @RequiresPermissions("system:role:export")
+ @PostMapping("/exportMenu")
+ public void exportMenu(HttpServletResponse response, SysRole role) throws IOException {
+ //角色列表
+ List roleList = roleService.selectRoleList(role);
+ if(roleList.size()==0){
+ throw new ServiceException("没有数据");
+ }
+ //角色菜单列表
+ List roleMenuList = roleService.selectRoleMenuByRoleIdList(roleList.stream().map(o->o.getRoleId()).collect(Collectors.toList()));
+
+ SysMenu sysMenu = new SysMenu();
+ List menuTree = menuService.buildMenuTreeSelect(menuService.selectMenuList(sysMenu, SecurityUtils.getUserId()));
+ List menuList = new ArrayList<>();
+ transferTreeToList(menuList,menuTree,1);
+ Integer maxLevel = Collections.max(menuList,
+ Comparator.comparingInt(RoleMenuExportDto::getLevel)).getLevel();
+
+ // 设置响应
+ response.setContentType("application/vnd.ms-excel");
+ response.setCharacterEncoding("utf-8");
+ String fileName = URLEncoder.encode("角色权限", "UTF-8").replaceAll("\\+", "%20");
+ response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx");
+
+ // 动态表头:假设我们有一个动态的表头列表,这里用字符串列表表示
+ List headList = new ArrayList<>();
+ for(int i=0;i>,所以我们需要转换
+ List> head = new ArrayList<>();
+ for (String h : headList) {
+ List hh = new ArrayList<>();
+ hh.add(h);
+ head.add(hh);
+ }
+
+ // 数据部分:每一行是一个List