修改对外报告-修改文件夹权限显示问题

This commit is contained in:
gaosong
2022-08-11 00:22:11 +08:00
parent 7fcbd82de1
commit 9cb0b88fcd
4 changed files with 66 additions and 91 deletions
@@ -4,7 +4,7 @@ import com.jero.common.api.vo.Result;
import com.jero.common.aspect.annotation.AutoLog; import com.jero.common.aspect.annotation.AutoLog;
import com.jero.common.constant.enums.CutEnum; import com.jero.common.constant.enums.CutEnum;
import com.jero.common.system.base.controller.JeroController; import com.jero.common.system.base.controller.JeroController;
import com.jero.modules.extRepo.entity.ERFTreeData; import com.jero.modules.extRepo.entity.ERFTreeDataVO;
import com.jero.modules.extRepo.entity.ExtRepoData; import com.jero.modules.extRepo.entity.ExtRepoData;
import com.jero.modules.extRepo.entity.ExtRepoFolder; import com.jero.modules.extRepo.entity.ExtRepoFolder;
import com.jero.modules.extRepo.service.IExtRepoDataService; import com.jero.modules.extRepo.service.IExtRepoDataService;
@@ -44,9 +44,11 @@ public class ExtRepoFolderController extends JeroController<ExtRepoFolder, IExtR
@AutoLog(value = "对外报告文件夹表-列表查询") @AutoLog(value = "对外报告文件夹表-列表查询")
@ApiOperation(value = "对外报告文件夹表-列表查询", notes = "对外报告文件夹表-列表查询") @ApiOperation(value = "对外报告文件夹表-列表查询", notes = "对外报告文件夹表-列表查询")
@GetMapping(value = "/list") @GetMapping(value = "/list")
public Result<List<ERFTreeData>> queryList() { public Result<ERFTreeDataVO> queryList() {
List<ERFTreeData> list = extRepoFolderService.queryTreeList(); ERFTreeDataVO dataVO = new ERFTreeDataVO();
return Result.OK(list); dataVO.setManager(extRepoFolderService.isManager());
dataVO.setList(extRepoFolderService.queryTreeList());
return Result.OK(dataVO);
} }
/** /**
@@ -36,13 +36,6 @@ public class ERFTreeData implements Comparable<ERFTreeData> {
*/ */
private int orderId; private int orderId;
/**
* 是否显示
*/
private boolean display = false;
/** /**
* 查看权限人员 * 查看权限人员
*/ */
@@ -119,14 +112,6 @@ public class ERFTreeData implements Comparable<ERFTreeData> {
this.orderId = orderId; this.orderId = orderId;
} }
public boolean isDisplay() {
return display;
}
public void setDisplay(boolean display) {
this.display = display;
}
public String getFolderName() { public String getFolderName() {
return folderName; return folderName;
} }
@@ -0,0 +1,27 @@
package com.jero.modules.extRepo.entity;
import java.util.List;
public class ERFTreeDataVO {
boolean isManager;
List<ERFTreeData> list;
public ERFTreeDataVO() {
}
public boolean isManager() {
return isManager;
}
public void setManager(boolean manager) {
isManager = manager;
}
public List<ERFTreeData> getList() {
return list;
}
public void setList(List<ERFTreeData> list) {
this.list = list;
}
}
@@ -22,10 +22,7 @@ import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
* @Description: 对外报告文件夹表 * 对外报告文件夹表
* @Author: jero-boot
* @Date: 2022-07-25
* @Version: V1.0
*/ */
@Service @Service
public class ExtRepoFolderServiceImpl extends ServiceImpl<ExtRepoFolderMapper, ExtRepoFolder> implements IExtRepoFolderService { public class ExtRepoFolderServiceImpl extends ServiceImpl<ExtRepoFolderMapper, ExtRepoFolder> implements IExtRepoFolderService {
@@ -38,9 +35,6 @@ public class ExtRepoFolderServiceImpl extends ServiceImpl<ExtRepoFolderMapper, E
/** /**
* 保存 * 保存
*
* @param extRepoFolder
* @return
*/ */
@Override @Override
public void add(ExtRepoFolder extRepoFolder) { public void add(ExtRepoFolder extRepoFolder) {
@@ -52,9 +46,6 @@ public class ExtRepoFolderServiceImpl extends ServiceImpl<ExtRepoFolderMapper, E
Date now = new Date(); Date now = new Date();
extRepoFolder.setCreateTime(now); extRepoFolder.setCreateTime(now);
extRepoFolder.setUpdateTime(now); extRepoFolder.setUpdateTime(now);
// LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
// extRepoFolder.setAuthManageName(extRepoFolder.getAuthManageName() + "," + sysUser.getUsername());
// extRepoFolder.setAuthManageIds(extRepoFolder.getAuthManageIds() + "," + sysUser.getId());
extRepoFolder.setAuthManageIdsName(extRepoFolder.getAuthManageIdsName()); extRepoFolder.setAuthManageIdsName(extRepoFolder.getAuthManageIdsName());
extRepoFolder.setAuthManageIds(extRepoFolder.getAuthManageIds()); extRepoFolder.setAuthManageIds(extRepoFolder.getAuthManageIds());
save(extRepoFolder); save(extRepoFolder);
@@ -67,10 +58,8 @@ public class ExtRepoFolderServiceImpl extends ServiceImpl<ExtRepoFolderMapper, E
/** /**
* 同级文件夹,修改顺序号 * 同级文件夹,修改顺序号
*
* @param extRepoFolder
*/ */
private void editOrderId(ExtRepoFolder extRepoFolder) throws Exception { private void editOrderId(ExtRepoFolder extRepoFolder) {
List<ExtRepoFolder> list = getListBySupFolder(extRepoFolder.getSupFolder()); List<ExtRepoFolder> list = getListBySupFolder(extRepoFolder.getSupFolder());
for (ExtRepoFolder erf : list) { for (ExtRepoFolder erf : list) {
if (erf.getOrderId() >= extRepoFolder.getOrderId() && !erf.getId().equals(extRepoFolder.getId())) { if (erf.getOrderId() >= extRepoFolder.getOrderId() && !erf.getId().equals(extRepoFolder.getId())) {
@@ -90,9 +79,6 @@ public class ExtRepoFolderServiceImpl extends ServiceImpl<ExtRepoFolderMapper, E
/** /**
* 更新 * 更新
*
* @param extRepoFolder
* @return
*/ */
@Override @Override
public void editById(ExtRepoFolder extRepoFolder) { public void editById(ExtRepoFolder extRepoFolder) {
@@ -113,7 +99,7 @@ public class ExtRepoFolderServiceImpl extends ServiceImpl<ExtRepoFolderMapper, E
/** /**
* 修改所有关联文件夹的权限 * 修改所有关联文件夹的权限
*/ */
private void editAuth(ExtRepoFolder erf_orig, ExtRepoFolder erf_new) throws Exception { private void editAuth(ExtRepoFolder erf_orig, ExtRepoFolder erf_new) {
//管理权限 //管理权限
Map<String, String> authManage_orig = getAuthMap(erf_orig.getAuthManageIdsName(), erf_orig.getAuthManageIds()); Map<String, String> authManage_orig = getAuthMap(erf_orig.getAuthManageIdsName(), erf_orig.getAuthManageIds());
Map<String, String> authManage_new = getAuthMap(erf_new.getAuthManageIdsName(), erf_new.getAuthManageIds()); Map<String, String> authManage_new = getAuthMap(erf_new.getAuthManageIdsName(), erf_new.getAuthManageIds());
@@ -132,20 +118,20 @@ public class ExtRepoFolderServiceImpl extends ServiceImpl<ExtRepoFolderMapper, E
List<ExtRepoFolder> allSubFolder = getAllSubFolder(erf_orig.getId()); List<ExtRepoFolder> allSubFolder = getAllSubFolder(erf_orig.getId());
//存储变化的对象 //存储变化的对象
List<ExtRepoFolder> updateFolder = new ArrayList<ExtRepoFolder>(); List<ExtRepoFolder> updateFolder = new ArrayList<>();
for (ExtRepoFolder erf : allSubFolder) { for (ExtRepoFolder erf : allSubFolder) {
boolean isChange = false; boolean isChange = false;
Map<String, String> authManage_erf = getAuthMap(erf.getAuthManageIdsName(), erf.getAuthManageIds()); Map<String, String> authManage_erf = getAuthMap(erf.getAuthManageIdsName(), erf.getAuthManageIds());
Map<String, String> authView_erf = getAuthMap(erf.getAuthViewIdsName(), erf.getAuthViewIds()); Map<String, String> authView_erf = getAuthMap(erf.getAuthViewIdsName(), erf.getAuthViewIds());
for (String add : addManageRole.keySet()) { for (String add : addManageRole.keySet()) {
if (!authManage_erf.keySet().contains(add)) { if (!authManage_erf.containsKey(add)) {
authManage_erf.put(add, addManageRole.get(add)); authManage_erf.put(add, addManageRole.get(add));
isChange = true; isChange = true;
} }
} }
for (String del : delManageRole.keySet()) { for (String del : delManageRole.keySet()) {
//如果是创建人 不能删除管理权限 //如果是创建人 不能删除管理权限
if (authManage_erf.keySet().contains(del)) { if (authManage_erf.containsKey(del)) {
if (!del.equals(erf_orig.getCreateBy())) { if (!del.equals(erf_orig.getCreateBy())) {
authManage_erf.remove(del); authManage_erf.remove(del);
isChange = true; isChange = true;
@@ -153,13 +139,13 @@ public class ExtRepoFolderServiceImpl extends ServiceImpl<ExtRepoFolderMapper, E
} }
} }
for (String add : addViewRole.keySet()) { for (String add : addViewRole.keySet()) {
if (!authView_erf.keySet().contains(add)) { if (!authView_erf.containsKey(add)) {
authView_erf.put(add, addViewRole.get(add)); authView_erf.put(add, addViewRole.get(add));
isChange = true; isChange = true;
} }
} }
for (String del : delViewRole.keySet()) { for (String del : delViewRole.keySet()) {
if (authView_erf.keySet().contains(del)) { if (authView_erf.containsKey(del)) {
authView_erf.remove(del); authView_erf.remove(del);
isChange = true; isChange = true;
} }
@@ -179,15 +165,11 @@ public class ExtRepoFolderServiceImpl extends ServiceImpl<ExtRepoFolderMapper, E
/** /**
* 得到列表新增元素集合 * 得到列表新增元素集合
*
* @param mapA
* @param mapB
* @return
*/ */
private Map<String, String> getDefMap(Map<String, String> mapA, Map<String, String> mapB) { private Map<String, String> getDefMap(Map<String, String> mapA, Map<String, String> mapB) {
Map<String, String> res = new HashMap<String, String>(); Map<String, String> res = new HashMap<>();
for (String s : mapA.keySet()) { for (String s : mapA.keySet()) {
if (StringUtils.isNotBlank(s) && !mapB.keySet().contains(s)) { if (StringUtils.isNotBlank(s) && !mapB.containsKey(s)) {
res.put(s, mapA.get(s)); res.put(s, mapA.get(s));
} }
} }
@@ -196,7 +178,7 @@ public class ExtRepoFolderServiceImpl extends ServiceImpl<ExtRepoFolderMapper, E
private List<ExtRepoFolder> getAllSubFolder(String folderId) { private List<ExtRepoFolder> getAllSubFolder(String folderId) {
List<ExtRepoFolder> resList = getListBySupFolder(folderId); List<ExtRepoFolder> resList = getListBySupFolder(folderId);
List<ExtRepoFolder> subList = new ArrayList<ExtRepoFolder>(); List<ExtRepoFolder> subList = new ArrayList<>();
for (ExtRepoFolder erf : resList) { for (ExtRepoFolder erf : resList) {
subList.addAll(getAllSubFolder(erf.getId())); subList.addAll(getAllSubFolder(erf.getId()));
} }
@@ -206,9 +188,6 @@ public class ExtRepoFolderServiceImpl extends ServiceImpl<ExtRepoFolderMapper, E
/** /**
* 通过id删除 * 通过id删除
*
* @param id
* @return
*/ */
@Override @Override
public void deleteById(String id) { public void deleteById(String id) {
@@ -222,9 +201,6 @@ public class ExtRepoFolderServiceImpl extends ServiceImpl<ExtRepoFolderMapper, E
/** /**
* 通过id查询 * 通过id查询
*
* @param id
* @return
*/ */
@Override @Override
public ExtRepoFolder queryById(String id) { public ExtRepoFolder queryById(String id) {
@@ -233,8 +209,6 @@ public class ExtRepoFolderServiceImpl extends ServiceImpl<ExtRepoFolderMapper, E
/** /**
* 列表查询 * 列表查询
*
* @return
*/ */
@Override @Override
public List<ExtRepoFolder> queryList() { public List<ExtRepoFolder> queryList() {
@@ -243,14 +217,12 @@ public class ExtRepoFolderServiceImpl extends ServiceImpl<ExtRepoFolderMapper, E
/** /**
* 列表查询 * 列表查询
*
* @return
*/ */
@Override @Override
public List<ERFTreeData> queryTreeList() { public List<ERFTreeData> queryTreeList() {
try { try {
List<ExtRepoFolder> list = queryList(); List<ExtRepoFolder> list = queryList();
List<ERFTreeData> res = getSubFolder(superFolder, list, 1); List<ERFTreeData> res = getSubFolder(superFolder, list, 1, true);
Collections.sort(res); Collections.sort(res);
return res; return res;
} catch (Exception ex) { } catch (Exception ex) {
@@ -262,34 +234,31 @@ public class ExtRepoFolderServiceImpl extends ServiceImpl<ExtRepoFolderMapper, E
/** /**
* 查找子文件夹,生成树结构 * 查找子文件夹,生成树结构
*
* @param supId
* @param list
* @param level 前端需要知道当前文件夹在哪一层
* @return
*/ */
private List<ERFTreeData> getSubFolder(String supId, List<ExtRepoFolder> list, int level) throws Exception { private List<ERFTreeData> getSubFolder(String supId, List<ExtRepoFolder> list, int level, boolean needAuth) {
List<ERFTreeData> resList = new ArrayList<ERFTreeData>(); List<ERFTreeData> resList = new ArrayList<>();
for (ExtRepoFolder erf : list) { for (ExtRepoFolder erf : list) {
if (supId.equals(erf.getSupFolder())) { if (supId.equals(erf.getSupFolder())) {
ERFTreeData date = new ERFTreeData(erf.getFolderName(), erf.getId(), level, erf.getOrderId()); int childLevel = level + 1;
//检查有没有权限查看 if (!needAuth || haveViewAuth(erf.getId())) {
date.setDisplay(haveViewAuth(erf.getSupFolder())); ERFTreeData date = new ERFTreeData(erf.getFolderName(), erf.getId(), level, erf.getOrderId());
int childLevel = date.getLevel() + 1; date.setAuthManageIdsName(erf.getAuthManageIdsName());
date.setAuthManageIdsName(erf.getAuthManageIdsName()); date.setAuthManageIds(erf.getAuthManageIds());
date.setAuthManageIds(erf.getAuthManageIds()); date.setAuthViewIdsName(erf.getAuthViewIdsName());
date.setAuthViewIdsName(erf.getAuthViewIdsName()); date.setAuthViewIds(erf.getAuthViewIds());
date.setAuthViewIds(erf.getAuthViewIds()); date.setChildren(getSubFolder(erf.getId(), list, childLevel, false));
date.setChildren(getSubFolder(erf.getId(), list, childLevel)); date.sortChildren();
date.sortChildren(); resList.add(date);
resList.add(date); } else {
resList.addAll(getSubFolder(erf.getId(), list, childLevel, true));
}
} }
} }
return resList; return resList;
} }
private List<String> getStringList(String listStr) { private List<String> getStringList(String listStr) {
List<String> res = new ArrayList<String>(); List<String> res = new ArrayList<>();
if (null != listStr) { if (null != listStr) {
res = Arrays.asList(listStr.split(",")); res = Arrays.asList(listStr.split(","));
} }
@@ -297,7 +266,7 @@ public class ExtRepoFolderServiceImpl extends ServiceImpl<ExtRepoFolderMapper, E
} }
private Map<String, String> getAuthMap(String strKey, String strValue) { private Map<String, String> getAuthMap(String strKey, String strValue) {
Map<String, String> resMap = new HashMap<String, String>(); Map<String, String> resMap = new HashMap<>();
List<String> keyList = getStringList(strKey); List<String> keyList = getStringList(strKey);
List<String> valueList = getStringList(strValue); List<String> valueList = getStringList(strValue);
for (int i = 0; i < keyList.size(); i++) { for (int i = 0; i < keyList.size(); i++) {
@@ -308,19 +277,17 @@ public class ExtRepoFolderServiceImpl extends ServiceImpl<ExtRepoFolderMapper, E
/** /**
* 判断是否是文件夹管理员角色 * 判断是否是文件夹管理员角色
*
* @return
*/ */
@Override @Override
public boolean isManager() { public boolean isManager() {
LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); // 获取当前登录用户 LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); // 获取当前登录用户
// 查询当前登录用户角色 // 查询当前登录用户角色
List<SysUserRole> userRoles = sysUserRoleService.list(new QueryWrapper<SysUserRole>().lambda().eq(SysUserRole::getUserId, loginUser.getId())); // 查询用户所有角色 List<SysUserRole> userRoles = sysUserRoleService.list(new QueryWrapper<SysUserRole>().lambda().eq(SysUserRole::getUserId, loginUser.getId())); // 查询用户所有角色
List<String> userRoleIds = new ArrayList<>(); // 用户管理员/对外报告管理员 List<String> userRoleIds; // 用户管理员/对外报告管理员
if (CollectionUtil.isNotEmpty(userRoles)) { if (CollectionUtil.isNotEmpty(userRoles)) {
List<String> roleIdList = ExtRepoMamagerRoleIdEnum.getIdList(); List<String> roleIdList = ExtRepoMamagerRoleIdEnum.getIdList();
List<String> userRoleIdList = userRoles.stream().map(SysUserRole::getRoleId).collect(Collectors.toList()); List<String> userRoleIdList = userRoles.stream().map(SysUserRole::getRoleId).collect(Collectors.toList());
userRoleIds = roleIdList.stream().filter(e -> userRoleIdList.contains(e)).collect(Collectors.toList()); userRoleIds = roleIdList.stream().filter(userRoleIdList::contains).collect(Collectors.toList());
return !CollectionUtil.isEmpty(userRoleIds); return !CollectionUtil.isEmpty(userRoleIds);
} }
return false; return false;
@@ -328,13 +295,10 @@ public class ExtRepoFolderServiceImpl extends ServiceImpl<ExtRepoFolderMapper, E
/** /**
* 是否有管理权限 * 是否有管理权限
*
* @param folderId
* @return
*/ */
@Override @Override
public boolean haveManageAuth(String folderId) { public boolean haveManageAuth(String folderId) {
boolean res = false; boolean res;
LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
res = isManager(); res = isManager();
ExtRepoFolder erf = queryById(folderId); ExtRepoFolder erf = queryById(folderId);
@@ -346,12 +310,9 @@ public class ExtRepoFolderServiceImpl extends ServiceImpl<ExtRepoFolderMapper, E
/** /**
* 是否有查看权限 * 是否有查看权限
*
* @param folderId
* @return
*/ */
public boolean haveViewAuth(String folderId) { public boolean haveViewAuth(String folderId) {
boolean res = false; boolean res;
LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
res = isManager(); res = isManager();
ExtRepoFolder erf = queryById(folderId); ExtRepoFolder erf = queryById(folderId);