|
|
@ -1,10 +1,13 @@ |
|
|
package com.hxhq.system.controller; |
|
|
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 java.util.stream.Collectors; |
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
|
|
|
|
|
|
|
|
import com.alibaba.excel.EasyExcel; |
|
|
import com.hxhq.business.domain.RoleChange; |
|
|
import com.hxhq.business.domain.RoleChange; |
|
|
import com.hxhq.business.domain.SystemLog; |
|
|
import com.hxhq.business.domain.SystemLog; |
|
|
import com.hxhq.business.form.common.SignForm; |
|
|
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.exception.ServiceException; |
|
|
import com.hxhq.common.core.utils.ServletUtils; |
|
|
import com.hxhq.common.core.utils.ServletUtils; |
|
|
import com.hxhq.common.core.utils.StringUtils; |
|
|
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.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.RoleSaveForm; |
|
|
import com.hxhq.system.form.RoleUserSaveForm; |
|
|
import com.hxhq.system.form.RoleUserSaveForm; |
|
|
import com.hxhq.system.service.ISysDeptService; |
|
|
import com.hxhq.system.service.ISysDeptService; |
|
|
|
|
|
import com.hxhq.system.service.ISysMenuService; |
|
|
import com.hxhq.system.service.ISysRoleService; |
|
|
import com.hxhq.system.service.ISysRoleService; |
|
|
import com.hxhq.system.service.ISysUserService; |
|
|
import com.hxhq.system.service.ISysUserService; |
|
|
|
|
|
import org.apache.poi.ss.usermodel.Workbook; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
import org.springframework.validation.annotation.Validated; |
|
|
import org.springframework.validation.annotation.Validated; |
|
|
@ -66,6 +75,9 @@ public class SysRoleController extends BaseController |
|
|
@Autowired |
|
|
@Autowired |
|
|
private IRoleChangeService roleChangeService; |
|
|
private IRoleChangeService roleChangeService; |
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
|
private ISysMenuService menuService; |
|
|
|
|
|
|
|
|
@RequiresPermissions("system:role:list") |
|
|
@RequiresPermissions("system:role:list") |
|
|
@GetMapping("/list") |
|
|
@GetMapping("/list") |
|
|
public TableDataInfo list(SysRole role) |
|
|
public TableDataInfo list(SysRole role) |
|
|
@ -115,6 +127,9 @@ public class SysRoleController extends BaseController |
|
|
{ |
|
|
{ |
|
|
return error("新增角色'" + role.getRoleName() + "'失败,角色编码已存在"); |
|
|
return error("新增角色'" + role.getRoleName() + "'失败,角色编码已存在"); |
|
|
} |
|
|
} |
|
|
|
|
|
if(StringUtils.isBlank(role.getRoleKey())){ |
|
|
|
|
|
role.setRoleKey(UUID.randomUUID().toString()); |
|
|
|
|
|
} |
|
|
role.setCreateBy(SecurityUtils.getUsername()); |
|
|
role.setCreateBy(SecurityUtils.getUsername()); |
|
|
return toAjax(roleService.insertRole(form)); |
|
|
return toAjax(roleService.insertRole(form)); |
|
|
|
|
|
|
|
|
@ -342,4 +357,83 @@ public class SysRoleController extends BaseController |
|
|
ajax.put("depts", deptService.selectDeptTreeList(new SysDept())); |
|
|
ajax.put("depts", deptService.selectDeptTreeList(new SysDept())); |
|
|
return ajax; |
|
|
return ajax; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@RequiresPermissions("system:role:export") |
|
|
|
|
|
@PostMapping("/exportMenu") |
|
|
|
|
|
public void exportMenu(HttpServletResponse response, SysRole role) throws IOException { |
|
|
|
|
|
//角色列表 |
|
|
|
|
|
List<SysRole> roleList = roleService.selectRoleList(role); |
|
|
|
|
|
if(roleList.size()==0){ |
|
|
|
|
|
throw new ServiceException("没有数据"); |
|
|
|
|
|
} |
|
|
|
|
|
//角色菜单列表 |
|
|
|
|
|
List<SysRoleMenu> roleMenuList = roleService.selectRoleMenuByRoleIdList(roleList.stream().map(o->o.getRoleId()).collect(Collectors.toList())); |
|
|
|
|
|
|
|
|
|
|
|
SysMenu sysMenu = new SysMenu(); |
|
|
|
|
|
List<TreeSelect> menuTree = menuService.buildMenuTreeSelect(menuService.selectMenuList(sysMenu, SecurityUtils.getUserId())); |
|
|
|
|
|
List<RoleMenuExportDto> 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<String> headList = new ArrayList<>(); |
|
|
|
|
|
for(int i=0;i<maxLevel;i++){ |
|
|
|
|
|
headList.add("菜单"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
for(SysRole info : roleList){ |
|
|
|
|
|
headList.add(info.getRoleName()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 但是EasyExcel的多级表头是List<List<String>>,所以我们需要转换 |
|
|
|
|
|
List<List<String>> head = new ArrayList<>(); |
|
|
|
|
|
for (String h : headList) { |
|
|
|
|
|
List<String> hh = new ArrayList<>(); |
|
|
|
|
|
hh.add(h); |
|
|
|
|
|
head.add(hh); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 数据部分:每一行是一个List<Object>,顺序与表头对应 |
|
|
|
|
|
List<List<Object>> data = new ArrayList<>(); |
|
|
|
|
|
for(RoleMenuExportDto dto : menuList){ |
|
|
|
|
|
List<Object> row = new ArrayList<>(); |
|
|
|
|
|
for(Integer i=1;i<=maxLevel;i++){ |
|
|
|
|
|
row.add(dto.getLevel().equals(i)?dto.getMenuName():""); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
for(SysRole info : roleList){ |
|
|
|
|
|
row.add(roleMenuList.stream().filter(o->o.getMenuId().equals(dto.getMenuId()) && o.getRoleId().equals(info.getRoleId())).count()>0?"✓":""); |
|
|
|
|
|
} |
|
|
|
|
|
data.add(row); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
EasyExcel.write(response.getOutputStream()) |
|
|
|
|
|
// 设置表头 |
|
|
|
|
|
.head(head) |
|
|
|
|
|
// 设置sheet名称 |
|
|
|
|
|
.sheet("Sheet1") |
|
|
|
|
|
// 写入数据 |
|
|
|
|
|
.doWrite(data); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void transferTreeToList(List<RoleMenuExportDto> list,List<TreeSelect> tree,Integer level){ |
|
|
|
|
|
for(TreeSelect t : tree){ |
|
|
|
|
|
RoleMenuExportDto item = new RoleMenuExportDto(); |
|
|
|
|
|
item.setMenuId(t.getId()); |
|
|
|
|
|
item.setMenuName(t.getLabel()); |
|
|
|
|
|
item.setLevel(level); |
|
|
|
|
|
list.add(item); |
|
|
|
|
|
if(t.getChildren()!=null && t.getChildren().size()>0){ |
|
|
|
|
|
transferTreeToList(list,t.getChildren(),level+1); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |