【8.0】【menu】修复权限界面菜单列表的排序问题

pull/57/head
fengshuonan 2023-09-15 17:26:41 +08:00
parent 844af97872
commit 4d597e8edd
2 changed files with 83 additions and 6 deletions

View File

@ -25,6 +25,7 @@ import cn.stylefeng.roses.kernel.sys.modular.menu.mapper.SysMenuMapper;
import cn.stylefeng.roses.kernel.sys.modular.menu.pojo.request.SysMenuRequest;
import cn.stylefeng.roses.kernel.sys.modular.menu.pojo.response.AppGroupDetail;
import cn.stylefeng.roses.kernel.sys.modular.menu.service.SysMenuService;
import cn.stylefeng.roses.kernel.sys.modular.menu.util.MenuOrderFixUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
@ -151,16 +152,13 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
@Override
public List<SysMenu> getTotalMenus() {
LambdaQueryWrapper<SysMenu> menuLambdaQueryWrapper = new LambdaQueryWrapper<>();
menuLambdaQueryWrapper.select(SysMenu::getMenuId, SysMenu::getMenuName, SysMenu::getMenuParentId, SysMenu::getAppId);
menuLambdaQueryWrapper.orderByAsc(SysMenu::getMenuSort);
return this.list(menuLambdaQueryWrapper);
return this.getTotalMenus(null);
}
@Override
public List<SysMenu> getTotalMenus(Set<Long> limitMenuIds) {
LambdaQueryWrapper<SysMenu> menuLambdaQueryWrapper = new LambdaQueryWrapper<>();
menuLambdaQueryWrapper.select(SysMenu::getMenuId, SysMenu::getMenuName, SysMenu::getMenuParentId, SysMenu::getAppId);
menuLambdaQueryWrapper.select(SysMenu::getMenuId, SysMenu::getMenuName, SysMenu::getMenuParentId, SysMenu::getAppId, SysMenu::getMenuSort);
// 如果限制菜单不为空则根据限制菜单id进行筛选否则查询所有菜单
if (ObjectUtil.isNotEmpty(limitMenuIds)) {
@ -168,7 +166,12 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
}
menuLambdaQueryWrapper.orderByAsc(SysMenu::getMenuSort);
return this.list(menuLambdaQueryWrapper);
List<SysMenu> list = this.list(menuLambdaQueryWrapper);
// 对菜单进行再次排序因为有的菜单是101有的菜单是10101需要将位数小的补0再次排序
MenuOrderFixUtil.fixOrder(list);
return list;
}
@Override

View File

@ -0,0 +1,74 @@
package cn.stylefeng.roses.kernel.sys.modular.menu.util;
import cn.hutool.core.util.ObjectUtil;
import cn.stylefeng.roses.kernel.sys.modular.menu.entity.SysMenu;
import java.math.BigDecimal;
import java.util.Comparator;
import java.util.List;
/**
*
* <p>
* 101101010
*
* @author fengshuonan
* @since 2023/9/15 17:14
*/
public class MenuOrderFixUtil {
/**
*
*
* @author fengshuonan
* @since 2023/9/15 17:15
*/
public static void fixOrder(List<SysMenu> sysMenus) {
if (ObjectUtil.isEmpty(sysMenus)) {
return;
}
// 找到最大的数字位数
int maxDigitCount = 0;
for (SysMenu sysMenu : sysMenus) {
BigDecimal menuSort = sysMenu.getMenuSort();
if (menuSort == null) {
continue;
}
int digitCount = getPointLeftDigitCount(menuSort);
if (digitCount > maxDigitCount) {
maxDigitCount = digitCount;
}
}
for (SysMenu sysMenu : sysMenus) {
BigDecimal menuSort = sysMenu.getMenuSort();
if (menuSort == null) {
menuSort = new BigDecimal(0);
}
int digitCount = getPointLeftDigitCount(menuSort);
if (digitCount < maxDigitCount) {
menuSort = menuSort.multiply(BigDecimal.valueOf(Math.pow(10, maxDigitCount - digitCount)));
}
sysMenu.setMenuSort(menuSort);
}
sysMenus.sort(Comparator.comparing(SysMenu::getMenuSort));
}
/**
*
*
* @author fengshuonan
* @since 2023/9/15 17:19
*/
public static int getPointLeftDigitCount(BigDecimal bigDecimal) {
if (bigDecimal == null) {
return 0;
}
String bigDecimalStr = bigDecimal.toString();
int decimalIndex = bigDecimalStr.indexOf('.');
return decimalIndex >= 0 ? decimalIndex : bigDecimalStr.length();
}
}