系统菜单搜索优化

main
031026 2024-04-12 20:00:33 +08:00
parent 9948445d7c
commit 0a59a7d948
3 changed files with 80 additions and 0 deletions

View File

@ -21,6 +21,10 @@ public interface SysMenuMapper extends BaseMapper<SysMenu> {
*/ */
public List<SysMenu> selectMenuList (SysMenu menu); public List<SysMenu> selectMenuList (SysMenu menu);
public List<SysMenu> selectSysMenuList(@Param("longs") List<Long> longs);
public List<SysMenu> selectSysChdMenuList(@Param("longs") List<Long> longs);
/** /**
* *
* *

View File

@ -15,6 +15,7 @@ import com.muyu.system.mapper.SysMenuMapper;
import com.muyu.system.mapper.SysRoleMapper; import com.muyu.system.mapper.SysRoleMapper;
import com.muyu.system.mapper.SysRoleMenuMapper; import com.muyu.system.mapper.SysRoleMenuMapper;
import com.muyu.system.service.SysMenuService; import com.muyu.system.service.SysMenuService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -51,6 +52,39 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
return selectMenuList(new SysMenu(), userId); return selectMenuList(new SysMenu(), userId);
} }
public List<SysMenu> selectSysChdMenuList(List<SysMenu> menuList) {
List<Long> longs = menuList.stream()
.map(menu -> menu.getMenuId())
.toList();
List<SysMenu> sysMenus = menuMapper.selectSysChdMenuList(longs);
if (sysMenus != null && sysMenus.size() != 0) {
List<SysMenu> sysMenus1 = selectSysMenuList(sysMenus);
if (sysMenus1 != null) {
sysMenus.addAll(sysMenus1);
}
}else {
return null;
}
return sysMenus;
}
public List<SysMenu> selectSysMenuList(List<SysMenu> menus){
List<Long> longs = menus.stream()
.map(menu -> menu.getParentId())
.filter(parentId -> parentId != 0)
.distinct()
.toList();
if (longs.size() == 0) {
return null;
}
List<SysMenu> sysMenus = menuMapper.selectSysMenuList(longs);
List<SysMenu> sysMenus1 = selectSysMenuList(sysMenus);
if (sysMenus1 != null) {
sysMenus.addAll(sysMenus1);
}
return sysMenus;
}
/** /**
* *
* *
@ -64,13 +98,31 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
// 管理员显示所有菜单信息 // 管理员显示所有菜单信息
if (SysUser.isAdmin(userId)) { if (SysUser.isAdmin(userId)) {
menuList = menuMapper.selectMenuList(menu); menuList = menuMapper.selectMenuList(menu);
List<SysMenu> sysMenus = selectSysMenuList(menuList);
if (sysMenus != null && sysMenus.size() != 0) {
menuList.addAll(sysMenus);
}
List<SysMenu> sysMenus1 = selectSysChdMenuList(menuMapper.selectMenuList(menu));
if (sysMenus1 != null && sysMenus1.size() !=0) {
menuList.addAll(sysMenus1);
}
} else { } else {
menu.getParams().put("userId", userId); menu.getParams().put("userId", userId);
menuList = menuMapper.selectMenuListByUserId(menu); menuList = menuMapper.selectMenuListByUserId(menu);
} }
menuList = menuList.stream()
.distinct()
.toList();
return menuList; return menuList;
} }
/** /**
* ID * ID
* *

View File

@ -186,6 +186,30 @@
where menu_name=#{menuName} and parent_id = #{parentId} limit 1 where menu_name=#{menuName} and parent_id = #{parentId} limit 1
</select> </select>
<select id="selectSysMenuList" resultType="com.muyu.system.domain.SysMenu">
<include refid="selectMenuVo"/>
<where>
menu_id in (
<foreach collection="longs" separator="," item="id">
#{id}
</foreach>
)
</where>
order by parent_id, order_num
</select>
<select id="selectSysChdMenuList" resultType="com.muyu.system.domain.SysMenu">
<include refid="selectMenuVo"/>
<where>
parent_id in (
<foreach collection="longs" separator="," item="id">
#{id}
</foreach>
)
</where>
order by parent_id, order_num
</select>
<update id="updateMenu" parameterType="com.muyu.system.domain.SysMenu"> <update id="updateMenu" parameterType="com.muyu.system.domain.SysMenu">
update sys_menu update sys_menu
<set> <set>