mirror of https://gitee.com/stylefeng/roses
【8.0】【menu】修复权限界面菜单列表的排序问题
parent
844af97872
commit
4d597e8edd
|
@ -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
|
||||
|
|
|
@ -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>
|
||||
* 对菜单进行再次排序,因为有的菜单是101,有的菜单是10101,需要将位数小的补0,再次排序
|
||||
*
|
||||
* @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();
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue