feat:功能权限数据清洗
parent
2a7f0294b8
commit
b87304c27f
@ -0,0 +1,22 @@
|
|||||||
|
package cn.estsh.i3plus.core.api.iservice.base;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description :
|
||||||
|
* @Reference :
|
||||||
|
* @Author : yunhao
|
||||||
|
* @CreateDate : 2020-09-04 11:29
|
||||||
|
* @Modify:
|
||||||
|
**/
|
||||||
|
public interface IBackstageService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新并清理功能软件模块数据
|
||||||
|
*/
|
||||||
|
void updateCleanMenuSoftType();
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新并清理角色功能数据
|
||||||
|
*/
|
||||||
|
void updateRefRoleMenu();
|
||||||
|
}
|
@ -0,0 +1,95 @@
|
|||||||
|
package cn.estsh.i3plus.core.apiservice.serviceimpl.base;
|
||||||
|
|
||||||
|
import cn.estsh.i3plus.core.api.iservice.base.IBackstageService;
|
||||||
|
import cn.estsh.i3plus.core.api.iservice.busi.IPersonnelService;
|
||||||
|
import cn.estsh.i3plus.core.api.iservice.busi.ISysMenuService;
|
||||||
|
import cn.estsh.i3plus.core.api.iservice.busi.ISysRoleService;
|
||||||
|
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
|
||||||
|
import cn.estsh.i3plus.pojo.platform.bean.SysMenu;
|
||||||
|
import cn.estsh.i3plus.pojo.platform.bean.SysRefRoleMenu;
|
||||||
|
import cn.estsh.i3plus.pojo.platform.bean.SysRole;
|
||||||
|
import org.apache.commons.collections.CollectionUtils;
|
||||||
|
import org.apache.commons.collections4.ListUtils;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description :
|
||||||
|
* @Reference :
|
||||||
|
* @Author : yunhao
|
||||||
|
* @CreateDate : 2020-09-04 11:31
|
||||||
|
* @Modify:
|
||||||
|
**/
|
||||||
|
@Service
|
||||||
|
public class BackstageService implements IBackstageService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ISysMenuService menuService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ISysRoleService sysRoleService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private IPersonnelService penfindSysRefUserRole;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新并清理功能软件模块数据
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void updateCleanMenuSoftType() {
|
||||||
|
SysMenu sysMenu = new SysMenu();
|
||||||
|
sysMenu.setMenuType(CommonEnumUtil.METHOD_LEVEL.PLUGIN.getValue());
|
||||||
|
List<SysMenu> list = menuService.findAllByBean(sysMenu).stream()
|
||||||
|
.filter(menu -> menu.getId() != 100000000L)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
List<SysMenu> allList = menuService.findAll();
|
||||||
|
Map<Long, List<SysMenu>> ds = allList.stream().collect(Collectors.groupingBy(SysMenu::getParentId));
|
||||||
|
packSysMenuTree(list, ds, null);
|
||||||
|
|
||||||
|
for (List<SysMenu> sysMenuList : ListUtils.partition(allList, 100)) {
|
||||||
|
new Thread(() -> menuService.saveBatch(sysMenuList)).start();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void packSysMenuTree(List<SysMenu> sysMenuList, Map<Long, List<SysMenu>> ds, Integer softType) {
|
||||||
|
if (CollectionUtils.isEmpty(sysMenuList)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (SysMenu sysMenu : sysMenuList) {
|
||||||
|
if (softType != null) {
|
||||||
|
sysMenu.setSoftType(softType);
|
||||||
|
}
|
||||||
|
if (ds.containsKey(sysMenu.getId())) {
|
||||||
|
sysMenu.setChildList(ds.get(sysMenu.getId()));
|
||||||
|
packSysMenuTree(sysMenu.getChildList(), ds, sysMenu.getSoftType());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新并清理角色功能数据
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void updateRefRoleMenu() {
|
||||||
|
List<Long> roleIdList = sysRoleService.findAll().stream().map(SysRole::getId).collect(Collectors.toList());
|
||||||
|
Map<Long, Set<Long>> roleMenuMap = new HashMap<>();
|
||||||
|
for (SysRefRoleMenu refRoleMenu : penfindSysRefUserRole.findSysRefRoleMenuByRoleIds(roleIdList)) {
|
||||||
|
if (!roleMenuMap.containsKey(refRoleMenu.getRoleId())) {
|
||||||
|
roleMenuMap.put(refRoleMenu.getRoleId(), new HashSet<>());
|
||||||
|
}
|
||||||
|
roleMenuMap.get(refRoleMenu.getRoleId()).add(refRoleMenu.getMenuId());
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Map.Entry<Long, Set<Long>> longSetEntry : roleMenuMap.entrySet()) {
|
||||||
|
sysRoleService.refreshSysRoleRef(
|
||||||
|
longSetEntry.getKey(),
|
||||||
|
longSetEntry.getValue().toArray(new Long[longSetEntry.getValue().size()]),
|
||||||
|
"清理垃圾数据"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue