搜索优化2

test
2812875475 2024-04-12 20:43:09 +08:00
parent 978a46987a
commit ab00e7ece8
5 changed files with 138 additions and 124 deletions

View File

@ -30,8 +30,6 @@ public class SysMenuController extends BaseController {
private SysMenuService menuService; private SysMenuService menuService;
/** /**
* *
*/ */
@ -43,6 +41,14 @@ public class SysMenuController extends BaseController {
return success(menus); return success(menus);
} }
@RequiresPermissions("system:menu:list")
@GetMapping("/listTwo")
public Result listTwo(SysMenu menu) {
Long userId = SecurityUtils.getUserId();
List<SysMenu> menusTwo = menuService.selectMenu(menu, userId);
return success(menusTwo);
}
/** /**
* *
*/ */

View File

@ -38,20 +38,7 @@ public class SysUserOnlineController extends BaseController {
@RequiresPermissions("monitor:online:list") @RequiresPermissions("monitor:online:list")
@GetMapping("/list") @GetMapping("/list")
public Result<TableDataInfo<SysUserOnline>> list (String ipaddr, String userName) { public Result<TableDataInfo<SysUserOnline>> list (String ipaddr, String userName) {
Collection<String> keys = redisService.keys(CacheConstants.LOGIN_TOKEN_KEY + "*"); List<SysUserOnline> userOnlineList = getUserOnlineList(ipaddr, userName);
List<SysUserOnline> userOnlineList = new ArrayList<SysUserOnline>();
for (String key : keys) {
LoginUser user = redisService.getCacheObject(key);
if (StringUtils.isNotEmpty(ipaddr) && StringUtils.isNotEmpty(userName)) {
userOnlineList.add(userOnlineService.selectOnlineByInfo(ipaddr, userName, user));
} else if (StringUtils.isNotEmpty(ipaddr)) {
userOnlineList.add(userOnlineService.selectOnlineByIpaddr(ipaddr, user));
} else if (StringUtils.isNotEmpty(userName)) {
userOnlineList.add(userOnlineService.selectOnlineByUserName(userName, user));
} else {
userOnlineList.add(userOnlineService.loginUserToUserOnline(user));
}
}
Collections.reverse(userOnlineList); Collections.reverse(userOnlineList);
userOnlineList.removeAll(Collections.singleton(null)); userOnlineList.removeAll(Collections.singleton(null));
return getDataTable(userOnlineList); return getDataTable(userOnlineList);
@ -68,12 +55,21 @@ public class SysUserOnlineController extends BaseController {
return success(); return success();
} }
@PostMapping("/findTokenId") @PostMapping("/findTokenId")
public Result<String> findTokenId(@RequestBody TokenResp tokenResp) { public Result<String> findTokenId(@RequestBody TokenResp tokenResp) {
String name = tokenResp.getName(); List<SysUserOnline> userOnlineList = getUserOnlineList(tokenResp.getIpaddr() ,tokenResp.getUserName() );
String ipaddr = tokenResp.getIpaddr(); String id="";
String userName = tokenResp.getUserName(); for (SysUserOnline sysUserOnline : userOnlineList) {
if (sysUserOnline.getUserName().equals(tokenResp.getName())) {
id = sysUserOnline.getTokenId();
}
}
return Result.success(id);
}
private List<SysUserOnline> getUserOnlineList(String ipaddr, String userName) {
Collection<String> keys = redisService.keys(CacheConstants.LOGIN_TOKEN_KEY + "*"); Collection<String> keys = redisService.keys(CacheConstants.LOGIN_TOKEN_KEY + "*");
List<SysUserOnline> userOnlineList = new ArrayList<SysUserOnline>(); List<SysUserOnline> userOnlineList = new ArrayList<SysUserOnline>();
for (String key : keys) { for (String key : keys) {
@ -88,13 +84,7 @@ public class SysUserOnlineController extends BaseController {
userOnlineList.add(userOnlineService.loginUserToUserOnline(user)); userOnlineList.add(userOnlineService.loginUserToUserOnline(user));
} }
} }
String id=""; return userOnlineList;
for (SysUserOnline sysUserOnline : userOnlineList) {
if (sysUserOnline.getUserName().equals(name)) {
id = sysUserOnline.getTokenId();
}
}
return Result.success(id);
} }
} }

View File

@ -1,6 +1,7 @@
package com.muyu.system.domain; package com.muyu.system.domain;
import com.muyu.common.core.web.domain.BaseEntity; import com.muyu.common.core.web.domain.BaseEntity;
import com.muyu.system.domain.vo.Mean;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
@ -8,7 +9,6 @@ import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder; import lombok.experimental.SuperBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle; import org.apache.commons.lang3.builder.ToStringStyle;
import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size; import javax.validation.constraints.Size;
@ -108,143 +108,158 @@ public class SysMenu extends BaseEntity {
*/ */
private List<SysMenu> children = new ArrayList<SysMenu>(); private List<SysMenu> children = new ArrayList<SysMenu>();
public Long getMenuId () { public static SysMenu meanBuild(Mean mean1, Long id) {
return SysMenu.builder()
.menuId(id)
.menuName(mean1.getMenuName())
.parentId(mean1.getParentId())
.orderNum(mean1.getOrderNum())
.path(mean1.getPath())
.component(mean1.getComponent())
.query(mean1.getQuery())
.isFrame(String.valueOf(mean1.getIsFrame()))
.isCache(String.valueOf(mean1.getIsCache()))
.menuType(mean1.getMenuType())
.build();
}
public Long getMenuId() {
return menuId; return menuId;
} }
public void setMenuId (Long menuId) { public void setMenuId(Long menuId) {
this.menuId = menuId; this.menuId = menuId;
} }
@NotBlank(message = "菜单名称不能为空") @NotBlank(message = "菜单名称不能为空")
@Size(min = 0, max = 50, message = "菜单名称长度不能超过50个字符") @Size(min = 0, max = 50, message = "菜单名称长度不能超过50个字符")
public String getMenuName () { public String getMenuName() {
return menuName; return menuName;
} }
public void setMenuName (String menuName) { public void setMenuName(String menuName) {
this.menuName = menuName; this.menuName = menuName;
} }
public String getParentName () { public String getParentName() {
return parentName; return parentName;
} }
public void setParentName (String parentName) { public void setParentName(String parentName) {
this.parentName = parentName; this.parentName = parentName;
} }
public Long getParentId () { public Long getParentId() {
return parentId; return parentId;
} }
public void setParentId (Long parentId) { public void setParentId(Long parentId) {
this.parentId = parentId; this.parentId = parentId;
} }
@NotNull(message = "显示顺序不能为空") @NotNull(message = "显示顺序不能为空")
public Integer getOrderNum () { public Integer getOrderNum() {
return orderNum; return orderNum;
} }
public void setOrderNum (Integer orderNum) { public void setOrderNum(Integer orderNum) {
this.orderNum = orderNum; this.orderNum = orderNum;
} }
@Size(min = 0, max = 200, message = "路由地址不能超过200个字符") @Size(min = 0, max = 200, message = "路由地址不能超过200个字符")
public String getPath () { public String getPath() {
return path; return path;
} }
public void setPath (String path) { public void setPath(String path) {
this.path = path; this.path = path;
} }
@Size(min = 0, max = 200, message = "组件路径不能超过255个字符") @Size(min = 0, max = 200, message = "组件路径不能超过255个字符")
public String getComponent () { public String getComponent() {
return component; return component;
} }
public void setComponent (String component) { public void setComponent(String component) {
this.component = component; this.component = component;
} }
public String getQuery () { public String getQuery() {
return query; return query;
} }
public void setQuery (String query) { public void setQuery(String query) {
this.query = query; this.query = query;
} }
public String getIsFrame () { public String getIsFrame() {
return isFrame; return isFrame;
} }
public void setIsFrame (String isFrame) { public void setIsFrame(String isFrame) {
this.isFrame = isFrame; this.isFrame = isFrame;
} }
public String getIsCache () { public String getIsCache() {
return isCache; return isCache;
} }
public void setIsCache (String isCache) { public void setIsCache(String isCache) {
this.isCache = isCache; this.isCache = isCache;
} }
@NotBlank(message = "菜单类型不能为空") @NotBlank(message = "菜单类型不能为空")
public String getMenuType () { public String getMenuType() {
return menuType; return menuType;
} }
public void setMenuType (String menuType) { public void setMenuType(String menuType) {
this.menuType = menuType; this.menuType = menuType;
} }
public String getVisible () { public String getVisible() {
return visible; return visible;
} }
public void setVisible (String visible) { public void setVisible(String visible) {
this.visible = visible; this.visible = visible;
} }
public String getStatus () { public String getStatus() {
return status; return status;
} }
public void setStatus (String status) { public void setStatus(String status) {
this.status = status; this.status = status;
} }
@Size(min = 0, max = 100, message = "权限标识长度不能超过100个字符") @Size(min = 0, max = 100, message = "权限标识长度不能超过100个字符")
public String getPerms () { public String getPerms() {
return perms; return perms;
} }
public void setPerms (String perms) { public void setPerms(String perms) {
this.perms = perms; this.perms = perms;
} }
public String getIcon () { public String getIcon() {
return icon; return icon;
} }
public void setIcon (String icon) { public void setIcon(String icon) {
this.icon = icon; this.icon = icon;
} }
public List<SysMenu> getChildren () { public List<SysMenu> getChildren() {
return children; return children;
} }
public void setChildren (List<SysMenu> children) { public void setChildren(List<SysMenu> children) {
this.children = children; this.children = children;
} }
@Override @Override
public String toString () { public String toString() {
return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE) return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
.append("menuId", getMenuId()) .append("menuId", getMenuId())
.append("menuName", getMenuName()) .append("menuName", getMenuName())

View File

@ -158,4 +158,6 @@ public interface SysMenuService extends IService<SysMenu> {
* @return * @return
*/ */
public boolean checkMenuNameUnique (SysMenu menu); public boolean checkMenuNameUnique (SysMenu menu);
List<SysMenu> selectMenu(SysMenu menu, Long userId);
} }

View File

@ -24,6 +24,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.*; import java.util.*;
import java.util.function.Supplier;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
@ -59,29 +60,6 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
} }
private void getParentIdList(List<Long> ids, Long parentId) {
if (parentId.equals(0L)) {
return;
}
Mean mean = this.meanService.getOne(new LambdaQueryWrapper<>() {{
eq(Mean::getMenuId, parentId);
}});
ids.add(mean.getMenuId());
getParentIdList(ids, mean.getParentId());
}
private void getSonIdList(List<Long> sonIds, Long menuId) {
Mean mean = this.meanService.getOne(new LambdaQueryWrapper<>() {{
eq(Mean::getParentId, menuId);
}});
sonIds.add(mean.getMenuId());
getParentIdList(sonIds, mean.getMenuId());
}
/** /**
* *
* *
@ -91,22 +69,6 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
@Override @Override
public List<SysMenu> selectMenuList(SysMenu menu, Long userId) { public List<SysMenu> selectMenuList(SysMenu menu, Long userId) {
// List<Long> ids = new ArrayList<>();
// List<Long> sonIds = new ArrayList<>();
// if (menu != null) {
// Mean mean = this.meanService.getOne(new LambdaQueryWrapper<>() {{
// eq(Mean::getMenuName, menu.getMenuName());
// }});
// ids = new ArrayList<>();
// sonIds = new ArrayList<>();
// getParentIdList(ids, mean.getParentId());
// getSonIdList(sonIds, mean.getMenuId());
// }
//
// System.out.println(ids);
// System.out.println(sonIds);
List<SysMenu> menuList = null; List<SysMenu> menuList = null;
// 管理员显示所有菜单信息 // 管理员显示所有菜单信息
if (SysUser.isAdmin(userId)) { if (SysUser.isAdmin(userId)) {
@ -116,40 +78,19 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
menuList = menuMapper.selectMenuListByUserId(menu); menuList = menuMapper.selectMenuListByUserId(menu);
} }
// List<SysMenu> finalMenuList = menuList;
// ids.forEach(id -> {
// Mean mean1 = this.meanService.getOne(new LambdaQueryWrapper<>() {{
// eq(Mean::getMenuId, id);
// }});
// finalMenuList.add(
// SysMenu.builder()
// .menuId(id)
// .menuName(mean1.getMenuName())
// .parentId(mean1.getParentId())
// .orderNum(mean1.getOrderNum())
// .path(mean1.getPath())
// .component(mean1.getComponent())
// .query(mean1.getQuery())
// .isFrame(String.valueOf(mean1.getIsFrame()))
// .isCache(String.valueOf(mean1.getIsCache()))
// .menuType(mean1.getMenuType())
// .build()
// );
// });
if (menuList.size() == 1) { if (menuList.size() == 1) {
getParentList(menuList,menuList.get(0)); getParentList(menuList, menuList.get(0));
List<SysMenu> childList = this.getChildList(menuMapper.selectMenuList(null), menuList.get(0)); List<SysMenu> childList = this.getChildList(menuMapper.selectMenuList(null), menuList.get(0));
menuList.addAll(childList); menuList.addAll(childList);
} }
return menuList; return menuList;
} }
/**
* id
*/
private void getParentList(List<SysMenu> menuList, SysMenu sysMenu) { private void getParentList(List<SysMenu> menuList, SysMenu sysMenu) {
SysMenu menu = this.selectMenuById(sysMenu.getParentId()); SysMenu menu = this.selectMenuById(sysMenu.getParentId());
if (menu != null) { if (menu != null) {
menuList.add(menu); menuList.add(menu);
@ -158,6 +99,65 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
} }
/**
*
*/
private void getParentIdAndSonIdList(List<Long> ids, Long parentId, Long menuId) {
if (parentId.equals(0L)) {
return;
}
Mean mean = this.meanService.getOne(new LambdaQueryWrapper<>() {{
eq(Mean::getMenuId, parentId);
}});
List<Long> longList = meanService.list(new LambdaQueryWrapper<>() {{
eq(Mean::getParentId, menuId);
}}).stream().map(
Mean::getMenuId
).toList();
ids.addAll(longList.stream().distinct().toList());
ids.add(mean.getMenuId());
getParentIdAndSonIdList(ids, mean.getParentId(), menuId);
}
@Override
public List<SysMenu> selectMenu(SysMenu menu, Long userId) {
List<Long> ids = new ArrayList<>();
if (menu != null) {
Mean mean = meanService.getOne(new LambdaQueryWrapper<Mean>() {{
eq(Mean::getMenuName, menu.getMenuName());
}});
if (mean != null) {
ids = new ArrayList<>();
getParentIdAndSonIdList(ids, mean.getParentId(), mean.getMenuId());
}
}
List<SysMenu> menuList = null;
// 管理员显示所有菜单信息
if (SysUser.isAdmin(userId)) {
menuList = menuMapper.selectMenuList(menu);
} else {
menu.getParams().put("userId", userId);
menuList = menuMapper.selectMenuListByUserId(menu);
}
List<SysMenu> finalMenuList = menuList;
ids.forEach(id -> {
finalMenuList.add(
SysMenu.meanBuild(this.meanService.getOne(new LambdaQueryWrapper<>() {{
eq(Mean::getMenuId, id);
}}),id)
);
});
return finalMenuList;
}
/** /**
* ID * ID
* *
@ -394,6 +394,7 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
return UserConstants.UNIQUE; return UserConstants.UNIQUE;
} }
/** /**
* *
* *