|
@@ -3,10 +3,15 @@ package com.xy.service.impl;
|
|
import cn.hutool.core.collection.CollUtil;
|
|
import cn.hutool.core.collection.CollUtil;
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
+import com.alibaba.excel.EasyExcel;
|
|
|
|
+import com.alibaba.excel.annotation.ExcelProperty;
|
|
|
|
+import com.alibaba.excel.annotation.write.style.ColumnWidth;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
+import com.xy.collections.list.JArrayList;
|
|
|
|
+import com.xy.collections.map.JMap;
|
|
import com.xy.consts.CommConsts;
|
|
import com.xy.consts.CommConsts;
|
|
import com.xy.dto.BatchDeleteDto;
|
|
import com.xy.dto.BatchDeleteDto;
|
|
import com.xy.dto.CommDto;
|
|
import com.xy.dto.CommDto;
|
|
@@ -18,21 +23,31 @@ import com.xy.service.SysDeptRoleService;
|
|
import com.xy.service.SysRoleMenuService;
|
|
import com.xy.service.SysRoleMenuService;
|
|
import com.xy.service.SysRoleService;
|
|
import com.xy.service.SysRoleService;
|
|
import com.xy.service.SysUserRoleService;
|
|
import com.xy.service.SysUserRoleService;
|
|
|
|
+import com.xy.util.ExcelUtils;
|
|
import com.xy.utils.Beans;
|
|
import com.xy.utils.Beans;
|
|
|
|
+import com.xy.utils.DataTime;
|
|
import com.xy.utils.PageBean;
|
|
import com.xy.utils.PageBean;
|
|
import com.xy.utils.R;
|
|
import com.xy.utils.R;
|
|
import com.xy.vo.SysRoleVo;
|
|
import com.xy.vo.SysRoleVo;
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.ApiOperation;
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
+import lombok.Data;
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
+import lombok.SneakyThrows;
|
|
|
|
+import org.springframework.context.annotation.Lazy;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.validation.annotation.Validated;
|
|
import org.springframework.validation.annotation.Validated;
|
|
import org.springframework.web.bind.annotation.DeleteMapping;
|
|
import org.springframework.web.bind.annotation.DeleteMapping;
|
|
|
|
+import org.springframework.web.bind.annotation.GetMapping;
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
|
|
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
import javax.validation.Valid;
|
|
import javax.validation.Valid;
|
|
|
|
+import java.net.URLEncoder;
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+import java.util.Arrays;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@@ -47,13 +62,15 @@ import static com.xy.utils.PlusBeans.toPageBean;
|
|
|
|
|
|
@Api(tags = "角色管理")
|
|
@Api(tags = "角色管理")
|
|
@Service
|
|
@Service
|
|
-@RequiredArgsConstructor
|
|
|
|
|
|
+@RequiredArgsConstructor(onConstructor_ = @Lazy)
|
|
public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> implements SysRoleService {
|
|
public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> implements SysRoleService {
|
|
|
|
|
|
private final SysRoleMenuService sysRoleMenuService;
|
|
private final SysRoleMenuService sysRoleMenuService;
|
|
private final SysDeptRoleService sysDeptRoleService;
|
|
private final SysDeptRoleService sysDeptRoleService;
|
|
private final SysUserRoleService sysUserRoleService;
|
|
private final SysUserRoleService sysUserRoleService;
|
|
private final SysMenuServiceImpl sysMenuService;
|
|
private final SysMenuServiceImpl sysMenuService;
|
|
|
|
+ private final SysRoleMenuServiceImpl sysRoleMenuServiceImpl;
|
|
|
|
+ private final SysSystemServiceImpl sysSystemService;
|
|
|
|
|
|
@ApiOperation(value = "新增、更新角色信息", notes = "新增、更新角色信息")
|
|
@ApiOperation(value = "新增、更新角色信息", notes = "新增、更新角色信息")
|
|
@PostMapping("saveOrUpdate")
|
|
@PostMapping("saveOrUpdate")
|
|
@@ -193,4 +210,73 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
|
|
}
|
|
}
|
|
return R.ok(sysRoleVoPageBean);
|
|
return R.ok(sysRoleVoPageBean);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ @SneakyThrows
|
|
|
|
+ @PostMapping("export")
|
|
|
|
+ @ApiOperation("导出角色菜单")
|
|
|
|
+ public void export(HttpServletResponse response) {
|
|
|
|
+ List<SysRole> xyAdmins = list(new LambdaQueryWrapper<SysRole>()
|
|
|
|
+ .eq(SysRole::getCode, "xy_admin")
|
|
|
|
+ );
|
|
|
|
+ //所有角色信息
|
|
|
|
+ List<SysRole> sysRoles = list();
|
|
|
|
+ JMap<Long, SysRole> sysRoleJMaps = new JArrayList<>(sysRoles).toMap(SysRole::getId).cover();
|
|
|
|
+ //所有系统信息
|
|
|
|
+ List<SysSystem> sysSystems = sysSystemService.list();
|
|
|
|
+ JMap<Long, SysSystem> sysSystemJMaps = new JArrayList<>(sysSystems).toMap(SysSystem::getId).cover();
|
|
|
|
+ //所有菜单信息
|
|
|
|
+ List<SysMenu> sysMenus = sysMenuService.list();
|
|
|
|
+ JMap<Long, SysMenu> sysMenuJMaps = new JArrayList<>(sysMenus).toMap(SysMenu::getId).cover();
|
|
|
|
+ //查询角色菜单信息
|
|
|
|
+ List<SysRoleMenu> sysRoleMenus = sysRoleMenuServiceImpl.list(new LambdaQueryWrapper<SysRoleMenu>()
|
|
|
|
+ .notIn(SysRoleMenu::getRoleId, new JArrayList<>(xyAdmins).getProperty(SysRole::getId))
|
|
|
|
+ .orderByAsc(SysRoleMenu::getRoleId, SysRoleMenu::getSysId)
|
|
|
|
+ );
|
|
|
|
+ List<ExportInfo> exportInfos = new ArrayList<>();
|
|
|
|
+ sysRoleMenus.forEach(sysRoleMenu -> {
|
|
|
|
+ SysRole sysRole = sysRoleJMaps.get(sysRoleMenu.getRoleId());
|
|
|
|
+ SysSystem sysSystem = sysSystemJMaps.get(sysRoleMenu.getSysId());
|
|
|
|
+ SysMenu sysMenu = sysMenuJMaps.get(sysRoleMenu.getMenuId());
|
|
|
|
+ ExportInfo exportInfo = new ExportInfo();
|
|
|
|
+ exportInfo.setRoleName(sysRole.getName());
|
|
|
|
+ exportInfo.setSysName(sysSystem.getName());
|
|
|
|
+ exportInfo.setMenuName(sysMenu.getName());
|
|
|
|
+ exportInfo.setEnName(sysMenu.getEnName());
|
|
|
|
+ exportInfo.setRemark(sysMenu.getRemark());
|
|
|
|
+ exportInfos.add(exportInfo);
|
|
|
|
+ });
|
|
|
|
+ response.addHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("角色权限表_" + DataTime.getSring("yyyy-MM-dd") + ".xlsx", "UTF-8"));
|
|
|
|
+ response.setContentType("application/xlsx");
|
|
|
|
+ EasyExcel.write(response.getOutputStream(), ExportInfo.class)
|
|
|
|
+ .autoCloseStream(false)
|
|
|
|
+ .registerWriteHandler(new ExcelUtils.MergeCellStrategyHandler(true, 1, Arrays.asList(0, 1)))
|
|
|
|
+ .registerWriteHandler(new ExcelUtils.CustomCellStyleHandler())
|
|
|
|
+ .sheet("角色权限表")
|
|
|
|
+ .doWrite(exportInfos);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Data
|
|
|
|
+ public static class ExportInfo {
|
|
|
|
+
|
|
|
|
+ @ColumnWidth(25)
|
|
|
|
+ @ExcelProperty("角色名称")
|
|
|
|
+ private String roleName;
|
|
|
|
+
|
|
|
|
+ @ColumnWidth(25)
|
|
|
|
+ @ExcelProperty("所属系统")
|
|
|
|
+ private String sysName;
|
|
|
|
+
|
|
|
|
+ @ColumnWidth(50)
|
|
|
|
+ @ExcelProperty("菜单名称")
|
|
|
|
+ private String menuName;
|
|
|
|
+
|
|
|
|
+ @ColumnWidth(50)
|
|
|
|
+ @ExcelProperty("菜单英文名称")
|
|
|
|
+ private String enName;
|
|
|
|
+
|
|
|
|
+ @ColumnWidth(100)
|
|
|
|
+ @ExcelProperty("备注")
|
|
|
|
+ private String remark;
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|