|
|
@@ -21,6 +21,7 @@ import cn.com.taiji.userw.model.rbac.MenuModel; |
|
|
|
import cn.com.taiji.userw.model.rbac.PermModel; |
|
|
|
import cn.com.taiji.userw.model.rbac.SystemTypeMode; |
|
|
|
import cn.com.taiji.userw.tools.SystemTypeAndSourceUtil; |
|
|
|
import cn.hutool.core.collection.CollectionUtil; |
|
|
|
import org.springframework.beans.BeanUtils; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
@@ -33,6 +34,7 @@ import java.time.LocalDateTime; |
|
|
|
import java.time.format.DateTimeFormatter; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Collections; |
|
|
|
import java.util.Comparator; |
|
|
|
import java.util.List; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
@@ -760,101 +762,37 @@ public class RbacMenuMangerImpl extends RedisCacheManager implements RbacMenuMan |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public RbacMenuPageResponseDTO page(RbacMenuPageRequestDTO request) { |
|
|
|
//获取分页 |
|
|
|
RbacMenuPageableRequestDTO queryRequest = new RbacMenuPageableRequestDTO(); |
|
|
|
//复制属性,相当于MapStruct的功能 |
|
|
|
BeanTools.copyProperties(request, queryRequest); |
|
|
|
Pagination pagination = userMenuRepo.page(queryRequest); |
|
|
|
//获取分页后的数据,并且封装到response中 |
|
|
|
RbacMenuPageResponseDTO response = toResponse(pagination); |
|
|
|
return response; |
|
|
|
public Pagination page(RbacMenuPageRequestDTO request) { |
|
|
|
RbacMenuPageableRequestDTO queryRequest = copyProperties(request, new RbacMenuPageableRequestDTO()); |
|
|
|
return userMenuRepo.page(queryRequest).convertResult(this::cover); |
|
|
|
} |
|
|
|
private MenuModel cover(UserMenu menu) { |
|
|
|
MenuModel menuModel = copyProperties(menu, new MenuModel()); |
|
|
|
setSubPage(menuModel); |
|
|
|
return menuModel; |
|
|
|
} |
|
|
|
|
|
|
|
//递归设置子菜单的子菜单 |
|
|
|
private void setSubPage(MenuModel pMenu) { |
|
|
|
boolean hasSub = false; |
|
|
|
|
|
|
|
List<UserMenu> subMenuList = userMenuRepo.findListByPid(pMenu.getId()); |
|
|
|
List<MenuModel> subMenuVoList = new ArrayList<>(); |
|
|
|
if (subMenuList != null && subMenuList.size() > 0) { |
|
|
|
//设置该父菜单的子菜单 |
|
|
|
for (UserMenu menu : subMenuList) { |
|
|
|
MenuModel menuVo = new MenuModel(); |
|
|
|
BeanUtils.copyProperties(menu, menuVo); |
|
|
|
subMenuVoList.add(menuVo); |
|
|
|
} |
|
|
|
hasSub = true; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//判断是否有子菜单 |
|
|
|
if (hasSub) { |
|
|
|
//子菜单排序 |
|
|
|
subMenuVoList = subMenuVoList.stream().sorted((m1, m2) -> m1.getSort() - m2.getSort()).collect(Collectors.toList()); |
|
|
|
pMenu.setChildren(subMenuVoList); |
|
|
|
pMenu.setHasPerm(false);//改成没有权限标识 |
|
|
|
pMenu.setPerms(new ArrayList<>()); |
|
|
|
|
|
|
|
//有子菜单,则该父菜单的子菜单们继续递归 |
|
|
|
for (MenuModel subMenu : pMenu.getChildren()) { |
|
|
|
setSubPage(subMenu); |
|
|
|
} |
|
|
|
} else { |
|
|
|
//无子菜单,则表明是最底层, |
|
|
|
pMenu.setChildren(new ArrayList<>()); |
|
|
|
pMenu.setHasPerm(true);//改成没有权限标识 |
|
|
|
//查询该菜单的所有权限标识 |
|
|
|
pMenu.setPerms(new ArrayList<>()); |
|
|
|
|
|
|
|
|
|
|
|
//获取该菜单下,所有权限标识 |
|
|
|
if (CollectionUtil.isNotEmpty(subMenuList)) { |
|
|
|
//有子菜单,则该菜单设置子菜单,子菜单们继续递归 |
|
|
|
pMenu.setHasPerm(false); |
|
|
|
//转换并排序 |
|
|
|
List<MenuModel> subMenuVos = subMenuList.stream().map(m -> copyProperties(m, new MenuModel())) |
|
|
|
.sorted(Comparator.comparing(MenuModel::getSort)).collect(Collectors.toList()); |
|
|
|
pMenu.setChildren(subMenuVos); |
|
|
|
subMenuVos.forEach(this::setSubPage); //递归 |
|
|
|
}else { |
|
|
|
//无子菜单,则表明是最底层,设置该菜单的所有权限标识 |
|
|
|
pMenu.setHasPerm(true); |
|
|
|
List<UserPerm> permList = userPermRepo.findListByMenuId(pMenu.getId()); |
|
|
|
//获取权限标识列表 |
|
|
|
List<PermModel> permVoList = new ArrayList<>(); |
|
|
|
if (permList != null && permList.size() > 0) { |
|
|
|
//此处不过滤禁用的权限标识 |
|
|
|
// permList = permList.stream().filter(b -> b.getIsEnable() == 1).collect(Collectors.toList()); |
|
|
|
|
|
|
|
for (UserPerm perm : permList) { |
|
|
|
PermModel permVo = new PermModel(); |
|
|
|
BeanUtils.copyProperties(perm, permVo); |
|
|
|
|
|
|
|
permVoList.add(permVo); |
|
|
|
} |
|
|
|
} |
|
|
|
if (permList != null && permVoList.size() > 0) { |
|
|
|
//设置该菜单的所有权限标识 |
|
|
|
pMenu.setPerms(permVoList); |
|
|
|
if (CollectionUtil.isNotEmpty(permList)) { |
|
|
|
List<PermModel> collect = permList.stream().map(perm -> copyProperties(perm, new PermModel())).collect(Collectors.toList()); |
|
|
|
pMenu.setPerms(collect); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//获取分页后的结果 |
|
|
|
private RbacMenuPageResponseDTO toResponse(Pagination pagn) { |
|
|
|
RbacMenuPageResponseDTO res = new RbacMenuPageResponseDTO(); |
|
|
|
List<MenuModel> menuList = new ArrayList<>(); |
|
|
|
|
|
|
|
res.setHasData(false); |
|
|
|
res.setData(menuList); |
|
|
|
if (isEmpty(pagn.getResult())) { |
|
|
|
return res; |
|
|
|
} |
|
|
|
List<UserMenu> result = pagn.getResult(UserMenu.class); |
|
|
|
for (UserMenu m : result) { |
|
|
|
MenuModel menuVo = new MenuModel(); |
|
|
|
BeanTools.copyProperties(m, menuVo); |
|
|
|
|
|
|
|
//设置子菜单和权限标识 |
|
|
|
setSubPage(menuVo); |
|
|
|
|
|
|
|
menuList.add(menuVo); |
|
|
|
} |
|
|
|
res.setCurrentPage(pagn.getCurrentPage()); |
|
|
|
res.setPageCount(pagn.getPageCount()); |
|
|
|
res.setPageSize(pagn.getPageSize()); |
|
|
|
res.setTotalCount(pagn.getTotalCount()); |
|
|
|
res.setHasData(true); |
|
|
|
res.setData(menuList); |
|
|
|
return res; |
|
|
|
} |
|
|
|
} |