服务端修改密码强制下线
commit
2f251fc7a8
|
@ -1,41 +1,28 @@
|
|||
package com.muyu.common.system.domain;
|
||||
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Set;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 用户信息
|
||||
*
|
||||
* @author muyu
|
||||
* @ClassDescription:
|
||||
* @JdkVersion: 17
|
||||
* @Author: zhangxu
|
||||
* @Created: 2024/4/12 19:37
|
||||
*/
|
||||
public class LoginUser implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class LoginUser {
|
||||
/**
|
||||
* 会话编号
|
||||
*/
|
||||
private String tokenId;
|
||||
|
||||
/**
|
||||
* 用户唯一标识
|
||||
* 用户名称
|
||||
*/
|
||||
private String token;
|
||||
|
||||
/**
|
||||
* 用户名id
|
||||
*/
|
||||
private Long userid;
|
||||
|
||||
/**
|
||||
* 用户名
|
||||
*/
|
||||
private String username;
|
||||
|
||||
/**
|
||||
* 登录时间
|
||||
*/
|
||||
private Long loginTime;
|
||||
|
||||
/**
|
||||
* 过期时间
|
||||
*/
|
||||
private Long expireTime;
|
||||
private String userName;
|
||||
|
||||
/**
|
||||
* 登录IP地址
|
||||
|
@ -43,58 +30,39 @@ public class LoginUser implements Serializable {
|
|||
private String ipaddr;
|
||||
|
||||
/**
|
||||
* 权限列表
|
||||
* 登录地址
|
||||
*/
|
||||
private Set<String> permissions;
|
||||
private String loginLocation;
|
||||
|
||||
/**
|
||||
* 角色列表
|
||||
* 浏览器类型
|
||||
*/
|
||||
private Set<String> roles;
|
||||
private String browser;
|
||||
|
||||
/**
|
||||
* 用户信息
|
||||
* 操作系统
|
||||
*/
|
||||
private SysUser sysUser;
|
||||
private String os;
|
||||
|
||||
public String getToken () {
|
||||
return token;
|
||||
/**
|
||||
* 登录时间
|
||||
*/
|
||||
private Long loginTime;
|
||||
|
||||
public String getTokenId () {
|
||||
return tokenId;
|
||||
}
|
||||
|
||||
public void setToken (String token) {
|
||||
this.token = token;
|
||||
public void setTokenId (String tokenId) {
|
||||
this.tokenId = tokenId;
|
||||
}
|
||||
|
||||
public Long getUserid () {
|
||||
return userid;
|
||||
public String getUserName () {
|
||||
return userName;
|
||||
}
|
||||
|
||||
public void setUserid (Long userid) {
|
||||
this.userid = userid;
|
||||
}
|
||||
|
||||
public String getUsername () {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername (String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public Long getLoginTime () {
|
||||
return loginTime;
|
||||
}
|
||||
|
||||
public void setLoginTime (Long loginTime) {
|
||||
this.loginTime = loginTime;
|
||||
}
|
||||
|
||||
public Long getExpireTime () {
|
||||
return expireTime;
|
||||
}
|
||||
|
||||
public void setExpireTime (Long expireTime) {
|
||||
this.expireTime = expireTime;
|
||||
public void setUserName (String userName) {
|
||||
this.userName = userName;
|
||||
}
|
||||
|
||||
public String getIpaddr () {
|
||||
|
@ -105,27 +73,35 @@ public class LoginUser implements Serializable {
|
|||
this.ipaddr = ipaddr;
|
||||
}
|
||||
|
||||
public Set<String> getPermissions () {
|
||||
return permissions;
|
||||
public String getLoginLocation () {
|
||||
return loginLocation;
|
||||
}
|
||||
|
||||
public void setPermissions (Set<String> permissions) {
|
||||
this.permissions = permissions;
|
||||
public void setLoginLocation (String loginLocation) {
|
||||
this.loginLocation = loginLocation;
|
||||
}
|
||||
|
||||
public Set<String> getRoles () {
|
||||
return roles;
|
||||
public String getBrowser () {
|
||||
return browser;
|
||||
}
|
||||
|
||||
public void setRoles (Set<String> roles) {
|
||||
this.roles = roles;
|
||||
public void setBrowser (String browser) {
|
||||
this.browser = browser;
|
||||
}
|
||||
|
||||
public SysUser getSysUser () {
|
||||
return sysUser;
|
||||
public String getOs () {
|
||||
return os;
|
||||
}
|
||||
|
||||
public void setSysUser (SysUser sysUser) {
|
||||
this.sysUser = sysUser;
|
||||
public void setOs (String os) {
|
||||
this.os = os;
|
||||
}
|
||||
|
||||
public Long getLoginTime () {
|
||||
return loginTime;
|
||||
}
|
||||
|
||||
public void setLoginTime (Long loginTime) {
|
||||
this.loginTime = loginTime;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.muyu.system.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.muyu.common.core.constant.UserConstants;
|
||||
import com.muyu.common.core.utils.StringUtils;
|
||||
import com.muyu.common.core.web.controller.BaseController;
|
||||
|
@ -15,6 +16,8 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
@ -36,9 +39,12 @@ public class SysMenuController extends BaseController {
|
|||
public Result list (SysMenu menu) {
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
List<SysMenu> menus = menuService.selectMenuList(menu, userId);
|
||||
return success(menus);
|
||||
return success();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 根据菜单编号获取详细信息
|
||||
*/
|
||||
|
|
|
@ -48,9 +48,44 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
|
|||
*/
|
||||
@Override
|
||||
public List<SysMenu> selectMenuList (Long userId) {
|
||||
|
||||
return selectMenuList(new SysMenu(), userId);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public List<Long> getParentMenuIds(Long userId) {
|
||||
// 根据用户ID查询系统菜单列表
|
||||
List<SysMenu> menuList = selectMenuList(userId);
|
||||
|
||||
// 用于存储所有父级及以上菜单的ID
|
||||
List<Long> parentIds = new ArrayList<>();
|
||||
|
||||
// 逐个检查每个菜单项的父菜单
|
||||
for (SysMenu menu : menuList) {
|
||||
// 获取当前菜单的ID
|
||||
Long currentMenuId = menu.getMenuId();
|
||||
|
||||
// 获取当前菜单的父菜单ID
|
||||
Long parentMenuId = menu.getParentId();
|
||||
|
||||
// 如果父菜单ID不为空,则递归查询其父菜单及以上的ID
|
||||
while (parentMenuId != null) {
|
||||
// 将父菜单ID加入到结果列表中
|
||||
parentIds.add(parentMenuId);
|
||||
|
||||
// 根据父菜单ID查询父菜单对象
|
||||
SysMenu parentMenu = getById(parentMenuId);
|
||||
|
||||
// 更新当前菜单的父菜单ID为父菜单对象的父菜单ID,以便下一轮循环继续查询
|
||||
parentMenuId = parentMenu != null ? parentMenu.getParentId() : null;
|
||||
}
|
||||
}
|
||||
|
||||
return parentIds;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询系统菜单列表
|
||||
*
|
||||
|
@ -64,13 +99,29 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
|
|||
// 管理员显示所有菜单信息
|
||||
if (SysUser.isAdmin(userId)) {
|
||||
menuList = menuMapper.selectMenuList(menu);
|
||||
// sysRecursion(userId,menuList);
|
||||
} else {
|
||||
menu.getParams().put("userId", userId);
|
||||
menuList = menuMapper.selectMenuListByUserId(menu);
|
||||
|
||||
}
|
||||
return menuList;
|
||||
}
|
||||
|
||||
// public void sysRecursion(Long parentId,List<SysMenu> sysMenus){
|
||||
// if (sysMenus==null && sysMenus.isEmpty()){
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// for (SysMenu sysMenu : sysMenus) {
|
||||
// SysMenu build = SysMenu.builder()
|
||||
// .parentId(parentId)
|
||||
// .parentName(sysMenu.getParentName())
|
||||
// .build();
|
||||
// menuMapper.selectMenuList(build);
|
||||
// }
|
||||
// }
|
||||
|
||||
/**
|
||||
* 根据用户ID查询权限
|
||||
*
|
||||
|
|
|
@ -1,34 +1,40 @@
|
|||
package com.muyu.system.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.muyu.common.core.constant.CacheConstants;
|
||||
import com.muyu.common.core.constant.UserConstants;
|
||||
import com.muyu.common.core.exception.ServiceException;
|
||||
import com.muyu.common.core.utils.SpringUtils;
|
||||
import com.muyu.common.core.utils.StringUtils;
|
||||
import com.muyu.common.core.utils.bean.BeanValidators;
|
||||
import com.muyu.common.datascope.annotation.DataScope;
|
||||
import com.muyu.common.redis.service.RedisService;
|
||||
import com.muyu.common.security.utils.SecurityUtils;
|
||||
import com.muyu.common.system.domain.LoginUser;
|
||||
import com.muyu.common.system.domain.SysRole;
|
||||
import com.muyu.common.system.domain.SysUser;
|
||||
import com.muyu.system.domain.SysPost;
|
||||
import com.muyu.system.domain.SysUserPost;
|
||||
import com.muyu.system.domain.SysUserRole;
|
||||
import com.muyu.system.domain.*;
|
||||
import com.muyu.system.mapper.*;
|
||||
import com.muyu.system.service.SysUserService;
|
||||
import com.muyu.system.service.SysConfigService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.validation.Validator;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.muyu.common.core.constant.CacheConstants.LOGIN_TOKEN_KEY;
|
||||
|
||||
/**
|
||||
* 用户 业务层处理
|
||||
*
|
||||
|
@ -52,6 +58,20 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
|||
@Autowired
|
||||
private SysConfigService configService;
|
||||
|
||||
@Autowired
|
||||
private HttpServletRequest request;
|
||||
|
||||
@Autowired
|
||||
private RedisService redisService;
|
||||
|
||||
|
||||
@Autowired
|
||||
private RedisTemplate<String ,String> redisTemplate;
|
||||
|
||||
|
||||
@Autowired
|
||||
private SysUserOnlineServiceImpl sysUserOnlineService;
|
||||
|
||||
/**
|
||||
* 根据条件分页查询用户列表
|
||||
*
|
||||
|
@ -347,9 +367,43 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
|||
*/
|
||||
@Override
|
||||
public int resetPwd (SysUser user) {
|
||||
return userMapper.updateUser(user);
|
||||
|
||||
int updateUser = userMapper.updateUser(user);
|
||||
if (SecurityUtils.isAdmin(user.getUserId())){
|
||||
return updateUser;
|
||||
}
|
||||
List<SysUserOnline> token = this.token(null, null);
|
||||
SysUserOnline sysUserOnline1 = token.stream().filter(
|
||||
sysUserOnline ->
|
||||
user.getUserName().equals
|
||||
(sysUserOnline.getUserName())
|
||||
).findFirst().get();
|
||||
redisService.deleteObject(LOGIN_TOKEN_KEY+sysUserOnline1.getTokenId());
|
||||
return updateUser;
|
||||
}
|
||||
|
||||
|
||||
public List<SysUserOnline> token(String addr,String userName){
|
||||
Collection<String> keys = redisService.keys(LOGIN_TOKEN_KEY+"*");
|
||||
ArrayList<SysUserOnline> sysUserOnlines = new ArrayList<>();
|
||||
for (String key : keys) {
|
||||
LoginUser user = redisService.getCacheObject(key);
|
||||
if (StringUtils.isNotEmpty(addr) && StringUtils.isNotEmpty(userName)){
|
||||
sysUserOnlines.add(sysUserOnlineService.selectOnlineByInfo(addr,userName,user));
|
||||
}else if (StringUtils.isNotEmpty(addr)){
|
||||
sysUserOnlines.add(sysUserOnlineService.selectOnlineByIpaddr(addr,user));
|
||||
}else if (StringUtils.isNotEmpty(userName)){
|
||||
sysUserOnlines.add(sysUserOnlineService.selectOnlineByUserName(userName,user));
|
||||
}else {
|
||||
sysUserOnlines.add(sysUserOnlineService.loginUserToUserOnline(user));
|
||||
}
|
||||
}
|
||||
Collections.reverse(sysUserOnlines);
|
||||
sysUserOnlines.remove(Collections.singleton(null));
|
||||
return sysUserOnlines;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 重置用户密码
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue