新增在线用户
This commit is contained in:
parent
75f65b3f9c
commit
0cbb3a034a
|
|
@ -105,32 +105,33 @@ create table sys_menu (
|
|||
insert into sys_menu values('1', '系统管理', '0', '1', '#', 'M', '0', 'system', 'fa fa-gear', '2018-01-01', '', 'system', '系统管理目录');
|
||||
insert into sys_menu values('2', '系统监控', '0', '2', '#', 'M', '0', 'monitor', 'fa fa-video-camera', '2018-01-01', '', 'system', '系统监控目录');
|
||||
-- 二级菜单
|
||||
insert into sys_menu values('3', '用户管理', '1', '1', '/system/user/userList', 'C', '0', 'system:user:list', '#', '2018-01-01', '', 'system', '用户管理菜单');
|
||||
insert into sys_menu values('4', '角色管理', '1', '2', '/system/role/roleList', 'C', '0', 'system:role:list', '#', '2018-01-01', '', 'system', '角色管理菜单');
|
||||
insert into sys_menu values('5', '菜单管理', '1', '3', '/system/menu/menuList', 'C', '0', 'system:menu:list', '#', '2018-01-01', '', 'system', '菜单管理菜单');
|
||||
insert into sys_menu values('3', '用户管理', '1', '1', '/system/user/userList', 'C', '0', 'system:user:list', '#', '2018-01-01', '', 'system', '用户管理菜单');
|
||||
insert into sys_menu values('4', '角色管理', '1', '2', '/system/role/roleList', 'C', '0', 'system:role:list', '#', '2018-01-01', '', 'system', '角色管理菜单');
|
||||
insert into sys_menu values('5', '菜单管理', '1', '3', '/system/menu/menuList', 'C', '0', 'system:menu:list', '#', '2018-01-01', '', 'system', '菜单管理菜单');
|
||||
insert into sys_menu values('6', '操作日志', '1', '4', '/system/operlog/operlogList', 'C', '0', 'system:operlog:list', '#', '2018-01-01', '', 'system', '操作日志菜单');
|
||||
insert into sys_menu values('7', '登录日志', '1', '5', '/system/userlog/userlogList', 'C', '0', 'system:userlog:list', '#', '2018-01-01', '', 'system', '登录日志菜单');
|
||||
insert into sys_menu values('8', '数据监控', '2', '1', '/monitor/druid/index.html', 'C', '0', 'monitor:druid:list', '#', '2018-01-01', '', 'system', '数据监控菜单');
|
||||
insert into sys_menu values('8', '在线用户', '2', '1', '/monitor/userOnline', 'C', '0', 'monitor:userOnline', '#', '2018-01-01', '', 'system', '在线用户菜单');
|
||||
insert into sys_menu values('9', '数据监控', '2', '2', '/monitor/druid/index.html', 'C', '0', 'monitor:druid:list', '#', '2018-01-01', '', 'system', '数据监控菜单');
|
||||
--- 三级用户按钮
|
||||
insert into sys_menu values('9', '用户新增', '3', '1', '/system/user/add', 'F', '0', 'sys:user:add', '#', '2018-01-01', '', 'system', '用户管理新增按钮');
|
||||
insert into sys_menu values('10', '用户修改', '3', '2', '/system/user/update', 'F', '0', 'sys:user:update', '#', '2018-01-01', '', 'system', '用户管理修改按钮');
|
||||
insert into sys_menu values('11', '用户删除', '3', '3', '/system/user/delete', 'F', '0', 'sys:user:delete', '#', '2018-01-01', '', 'system', '用户管理删除按钮');
|
||||
insert into sys_menu values('12', '用户查询', '3', '4', '/system/user/select', 'F', '0', 'sys:user:select', '#', '2018-01-01', '', 'system', '用户管理查询按钮');
|
||||
insert into sys_menu values('13', '密码修改', '3', '5', '/system/user/pwdUpdate', 'F', '0', 'sys:user:pwdUpdate', '#', '2018-01-01', '', 'system', '用户密码修改按钮');
|
||||
insert into sys_menu values('10', '用户新增', '3', '1', '/system/user/add', 'F', '0', 'sys:user:add', '#', '2018-01-01', '', 'system', '用户管理新增按钮');
|
||||
insert into sys_menu values('11', '用户修改', '3', '2', '/system/user/update', 'F', '0', 'sys:user:update', '#', '2018-01-01', '', 'system', '用户管理修改按钮');
|
||||
insert into sys_menu values('12', '用户删除', '3', '3', '/system/user/delete', 'F', '0', 'sys:user:delete', '#', '2018-01-01', '', 'system', '用户管理删除按钮');
|
||||
insert into sys_menu values('13', '用户查询', '3', '4', '/system/user/select', 'F', '0', 'sys:user:select', '#', '2018-01-01', '', 'system', '用户管理查询按钮');
|
||||
insert into sys_menu values('14', '密码修改', '3', '5', '/system/user/pwdUpdate', 'F', '0', 'sys:user:pwdUpdate', '#', '2018-01-01', '', 'system', '用户密码修改按钮');
|
||||
--- 三级角色按钮
|
||||
insert into sys_menu values('14', '角色新增', '4', '1', '/system/role/add', 'F', '0', 'sys:role:add', '#', '2018-01-01', '', 'system', '角色管理新增按钮');
|
||||
insert into sys_menu values('15', '角色修改', '4', '2', '/system/role/update', 'F', '0', 'sys:role:update', '#', '2018-01-01', '', 'system', '角色管理修改按钮');
|
||||
insert into sys_menu values('16', '角色删除', '4', '3', '/system/role/delete', 'F', '0', 'sys:role:delete', '#', '2018-01-01', '', 'system', '角色管理删除按钮');
|
||||
insert into sys_menu values('17', '角色查询', '4', '4', '/system/role/select', 'F', '0', 'sys:role:select', '#', '2018-01-01', '', 'system', '角色管理查询按钮');
|
||||
insert into sys_menu values('18', '角色授权', '4', '5', '/system/role/auth', 'F', '0', 'sys:role:auth', '#', '2018-01-01', '', 'system', '角色管理授权按钮');
|
||||
insert into sys_menu values('15', '角色新增', '4', '1', '/system/role/add', 'F', '0', 'sys:role:add', '#', '2018-01-01', '', 'system', '角色管理新增按钮');
|
||||
insert into sys_menu values('16', '角色修改', '4', '2', '/system/role/update', 'F', '0', 'sys:role:update', '#', '2018-01-01', '', 'system', '角色管理修改按钮');
|
||||
insert into sys_menu values('17', '角色删除', '4', '3', '/system/role/delete', 'F', '0', 'sys:role:delete', '#', '2018-01-01', '', 'system', '角色管理删除按钮');
|
||||
insert into sys_menu values('18', '角色查询', '4', '4', '/system/role/select', 'F', '0', 'sys:role:select', '#', '2018-01-01', '', 'system', '角色管理查询按钮');
|
||||
insert into sys_menu values('19', '角色授权', '4', '5', '/system/role/auth', 'F', '0', 'sys:role:auth', '#', '2018-01-01', '', 'system', '角色管理授权按钮');
|
||||
--- 三级菜单按钮
|
||||
insert into sys_menu values('19', '菜单新增', '5', '1', '/system/menu/add', 'F', '0', 'sys:menu:add', '#', '2018-01-01', '', 'system', '菜单管理新增按钮');
|
||||
insert into sys_menu values('20', '菜单修改', '5', '2', '/system/menu/update', 'F', '0', 'sys:menu:update', '#', '2018-01-01', '', 'system', '菜单管理修改按钮');
|
||||
insert into sys_menu values('21', '菜单删除', '5', '3', '/system/menu/delete', 'F', '0', 'sys:menu:delete', '#', '2018-01-01', '', 'system', '菜单管理删除按钮');
|
||||
insert into sys_menu values('22', '菜单查询', '5', '4', '/system/menu/select', 'F', '0', 'sys:menu:select', '#', '2018-01-01', '', 'system', '菜单管理查询按钮');
|
||||
insert into sys_menu values('20', '菜单新增', '5', '1', '/system/menu/add', 'F', '0', 'sys:menu:add', '#', '2018-01-01', '', 'system', '菜单管理新增按钮');
|
||||
insert into sys_menu values('21', '菜单修改', '5', '2', '/system/menu/update', 'F', '0', 'sys:menu:update', '#', '2018-01-01', '', 'system', '菜单管理修改按钮');
|
||||
insert into sys_menu values('22', '菜单删除', '5', '3', '/system/menu/delete', 'F', '0', 'sys:menu:delete', '#', '2018-01-01', '', 'system', '菜单管理删除按钮');
|
||||
insert into sys_menu values('23', '菜单查询', '5', '4', '/system/menu/select', 'F', '0', 'sys:menu:select', '#', '2018-01-01', '', 'system', '菜单管理查询按钮');
|
||||
--- 三级日志按钮
|
||||
insert into sys_menu values('23', '操作日志查询', '4', '5', '/system/operlog/auth', 'F', '0', 'sys:operlog:select', '#', '2018-01-01', '', 'system', '操作日志查询按钮');
|
||||
insert into sys_menu values('24', '登录日志查询', '4', '5', '/system/userlog/auth', 'F', '0', 'sys:userlog:select', '#', '2018-01-01', '', 'system', '登录日志查询按钮');
|
||||
insert into sys_menu values('24', '操作日志查询', '4', '5', '/system/operlog/auth', 'F', '0', 'sys:operlog:select', '#', '2018-01-01', '', 'system', '操作日志查询按钮');
|
||||
insert into sys_menu values('25', '登录日志查询', '4', '5', '/system/userlog/auth', 'F', '0', 'sys:userlog:select', '#', '2018-01-01', '', 'system', '登录日志查询按钮');
|
||||
|
||||
|
||||
-- ----------------------------
|
||||
|
|
@ -172,6 +173,7 @@ insert into sys_role_menu values ('1', '5');
|
|||
insert into sys_role_menu values ('1', '6');
|
||||
insert into sys_role_menu values ('1', '7');
|
||||
insert into sys_role_menu values ('1', '8');
|
||||
insert into sys_role_menu values ('1', '9');
|
||||
|
||||
|
||||
-- ----------------------------
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package com.ruoyi.common.utils.security;
|
|||
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.apache.shiro.subject.Subject;
|
||||
|
||||
import com.ruoyi.project.system.user.domain.User;
|
||||
|
||||
/**
|
||||
|
|
@ -11,6 +12,7 @@ import com.ruoyi.project.system.user.domain.User;
|
|||
*/
|
||||
public class ShiroUtils
|
||||
{
|
||||
|
||||
public static Subject getSubjct()
|
||||
{
|
||||
return SecurityUtils.getSubject();
|
||||
|
|
@ -30,4 +32,14 @@ public class ShiroUtils
|
|||
{
|
||||
return getUser().getUserId().longValue();
|
||||
}
|
||||
|
||||
public static String getIp()
|
||||
{
|
||||
return getSubjct().getSession().getHost();
|
||||
}
|
||||
|
||||
public static String getSessionId()
|
||||
{
|
||||
return String.valueOf(getSubjct().getSession().getId());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,8 @@
|
|||
package com.ruoyi.project.shiro.session;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.shiro.session.Session;
|
||||
import org.apache.shiro.session.mgt.eis.EnterpriseCacheSessionDAO;
|
||||
|
|
@ -20,13 +17,15 @@ import com.ruoyi.project.util.HttpContextUtils;
|
|||
*/
|
||||
public class OnlineSessionDAO extends EnterpriseCacheSessionDAO
|
||||
{
|
||||
// Session超时时间,单位为毫秒
|
||||
private long expireTime = 120000;
|
||||
/**
|
||||
* Session超时时间,单位为毫秒(默认3分钟)
|
||||
*/
|
||||
private long expireTime = 3 * 60 * 1000;
|
||||
|
||||
/**
|
||||
* 同步session到数据库的周期 单位为毫秒(默认5分钟)
|
||||
* 同步session到数据库的周期 单位为毫秒(默认1分钟)
|
||||
*/
|
||||
private long dbSyncPeriod = 5 * 60 * 1000;
|
||||
private long dbSyncPeriod = 1 * 60 * 1000;
|
||||
|
||||
/**
|
||||
* 上次同步数据库的时间戳
|
||||
|
|
@ -89,13 +88,12 @@ public class OnlineSessionDAO extends EnterpriseCacheSessionDAO
|
|||
return;
|
||||
}
|
||||
System.out.println("==============update url=================" + uri);
|
||||
if (session == null || session.getId() == null)
|
||||
if (session == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Session session1 = doReadSession(session.getId());
|
||||
OnlineSession onlineSession = (OnlineSession) session1;
|
||||
OnlineSession onlineSession = (OnlineSession) session;
|
||||
|
||||
Date lastSyncTimestamp = (Date) session.getAttribute(LAST_SYNC_DB_TIMESTAMP);
|
||||
if (lastSyncTimestamp != null)
|
||||
|
|
@ -103,7 +101,8 @@ public class OnlineSessionDAO extends EnterpriseCacheSessionDAO
|
|||
boolean needSync = true;
|
||||
long deltaTime = session.getLastAccessTime().getTime() - lastSyncTimestamp.getTime();
|
||||
if (deltaTime < dbSyncPeriod)
|
||||
{ // 时间差不足 无需同步
|
||||
{
|
||||
// 时间差不足 无需同步
|
||||
needSync = false;
|
||||
}
|
||||
boolean isGuest = session.getId() == null;
|
||||
|
|
@ -136,24 +135,15 @@ public class OnlineSessionDAO extends EnterpriseCacheSessionDAO
|
|||
protected void doDelete(Session session)
|
||||
{
|
||||
System.out.println("===============delete================");
|
||||
if (null == session)
|
||||
OnlineSession onlineSession = (OnlineSession) session;
|
||||
if (null == onlineSession)
|
||||
{
|
||||
return;
|
||||
}
|
||||
String sessionId = String.valueOf(session.getId());
|
||||
String sessionId = String.valueOf(onlineSession.getId());
|
||||
onlineService.deleteByOnlineId(sessionId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前所有活跃用户
|
||||
*/
|
||||
@Override
|
||||
public Collection<Session> getActiveSessions()
|
||||
{
|
||||
System.out.println("==============getActiveSessions=================");
|
||||
return null;
|
||||
}
|
||||
|
||||
public long getExpireTime()
|
||||
{
|
||||
return expireTime;
|
||||
|
|
@ -173,7 +163,7 @@ public class OnlineSessionDAO extends EnterpriseCacheSessionDAO
|
|||
{
|
||||
boolean linkFlag = false;
|
||||
// 如果是登录请求,则不更新SESSION
|
||||
if (StringUtils.endsWithAny(uri, new String[] { "/login", "/", "/favicon.ico" }))
|
||||
if (StringUtils.endsWithAny(uri, new String[] { "/login", "/logout", "/index", "/", "/favicon.ico" }))
|
||||
{
|
||||
linkFlag = true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,16 +1,16 @@
|
|||
package com.ruoyi.project.shiro.session;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.apache.shiro.session.Session;
|
||||
import org.apache.shiro.session.mgt.SessionContext;
|
||||
import org.apache.shiro.session.mgt.SessionFactory;
|
||||
import org.apache.shiro.web.session.mgt.WebSessionContext;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.ruoyi.project.shiro.common.utils.IpUtils;
|
||||
import com.ruoyi.project.system.online.domain.OnlineSession;
|
||||
import com.ruoyi.project.system.online.domain.UserOnline;
|
||||
import com.ruoyi.project.util.HttpContextUtils;
|
||||
import eu.bitwalker.useragentutils.UserAgent;
|
||||
|
||||
@Component
|
||||
public class OnlineSessionFactory implements SessionFactory
|
||||
|
|
@ -30,9 +30,15 @@ public class OnlineSessionFactory implements SessionFactory
|
|||
HttpServletRequest request = (HttpServletRequest) sessionContext.getServletRequest();
|
||||
if (request != null)
|
||||
{
|
||||
UserAgent userAgent = UserAgent.parseUserAgentString(HttpContextUtils.getHttpServletRequest().getHeader("User-Agent"));
|
||||
// 获取客户端操作系统
|
||||
String os = userAgent.getOperatingSystem().getName();
|
||||
// 获取客户端浏览器
|
||||
String browser = userAgent.getBrowser().getName();
|
||||
session.setHost(IpUtils.getIpAddr(request));
|
||||
session.setBrowser(request.getHeader("User-Agent"));
|
||||
session.setBrowser(browser);
|
||||
session.setHost(request.getLocalAddr() + ":" + request.getLocalPort());
|
||||
session.setOs(os);
|
||||
}
|
||||
}
|
||||
return session;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,71 @@
|
|||
package com.ruoyi.project.system.online.controller;
|
||||
|
||||
import java.util.List;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import com.ruoyi.common.tools.StringTools;
|
||||
import com.ruoyi.common.utils.TableDataInfo;
|
||||
import com.ruoyi.framework.core.controller.BaseController;
|
||||
import com.ruoyi.framework.core.domain.R;
|
||||
import com.ruoyi.project.system.online.domain.UserOnline;
|
||||
import com.ruoyi.project.system.online.service.IUserOnlineService;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/monitor/userOnline")
|
||||
public class UserOnlineController extends BaseController
|
||||
{
|
||||
|
||||
private String prefix = "monitor/online";
|
||||
|
||||
@Autowired
|
||||
private IUserOnlineService userOnlineService;
|
||||
|
||||
@GetMapping()
|
||||
public String userOnline()
|
||||
{
|
||||
return prefix + "/online";
|
||||
}
|
||||
|
||||
@GetMapping("/list")
|
||||
@ResponseBody
|
||||
public TableDataInfo list(Model model)
|
||||
{
|
||||
List<UserOnline> list = userOnlineService.selectUserOnlines();
|
||||
TableDataInfo tableDataInfo = new TableDataInfo(list, 12);
|
||||
return tableDataInfo;
|
||||
}
|
||||
|
||||
@GetMapping("/forceLogout")
|
||||
@ResponseBody
|
||||
public R forceLogout(@RequestParam(value = "ids") String[] ids)
|
||||
{
|
||||
try
|
||||
{
|
||||
for (String sessionId : ids)
|
||||
{
|
||||
UserOnline online = userOnlineService.selectByOnlineId(sessionId);
|
||||
if (online == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
userOnlineService.forceLogout(sessionId);
|
||||
}
|
||||
return R.ok();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
String msg = "未知错误";
|
||||
if (StringTools.isNotEmpty(e.getMessage()))
|
||||
{
|
||||
msg = e.getMessage();
|
||||
}
|
||||
return R.error(msg);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,5 +1,7 @@
|
|||
package com.ruoyi.project.system.online.dao;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.ruoyi.project.system.online.domain.UserOnline;
|
||||
|
||||
public interface IUserOnlineDao
|
||||
|
|
@ -26,4 +28,11 @@ public interface IUserOnlineDao
|
|||
* @param online 会话信息
|
||||
*/
|
||||
public int saveByOnline(UserOnline online);
|
||||
|
||||
/**
|
||||
* 查询会话集合
|
||||
*
|
||||
* @param online 会话信息
|
||||
*/
|
||||
public List<UserOnline> selectUserOnlines();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package com.ruoyi.project.system.online.dao;
|
||||
|
||||
import java.util.List;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import com.ruoyi.framework.core.dao.DynamicObjectBaseDao;
|
||||
import com.ruoyi.project.system.online.domain.UserOnline;
|
||||
|
|
@ -39,4 +40,23 @@ public class UserOnlineDaoImpl extends DynamicObjectBaseDao implements IUserOnli
|
|||
{
|
||||
return this.save("SystemOnlineMapper.saveByOnline", online);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询会话集合
|
||||
*
|
||||
* @param online 会话信息
|
||||
*/
|
||||
public List<UserOnline> selectUserOnlines()
|
||||
{
|
||||
List<UserOnline> userOnlineList = null;
|
||||
try
|
||||
{
|
||||
userOnlineList = this.findForList("SystemOnlineMapper.selectUserOnlines");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
return userOnlineList;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,9 +47,6 @@ public class OnlineSession extends SimpleSession
|
|||
}
|
||||
}
|
||||
|
||||
// sessionId
|
||||
private String id;
|
||||
|
||||
// 当前登录的用户Id
|
||||
private String userId;
|
||||
|
||||
|
|
@ -78,16 +75,6 @@ public class OnlineSession extends SimpleSession
|
|||
super(host);
|
||||
}
|
||||
|
||||
public String getId()
|
||||
{
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id)
|
||||
{
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getUserId()
|
||||
{
|
||||
return userId;
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@ package com.ruoyi.project.system.online.domain;
|
|||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
import com.ruoyi.common.utils.security.ShiroUtils;
|
||||
|
||||
/**
|
||||
* 当前在线会话 sys_user_online
|
||||
*
|
||||
|
|
@ -159,8 +161,8 @@ public class UserOnline implements Serializable
|
|||
{
|
||||
UserOnline online = new UserOnline();
|
||||
online.setSessionId(String.valueOf(session.getId()));
|
||||
online.setUserId(session.getUserId());
|
||||
online.setLoginName(session.getLoginName());
|
||||
online.setUserId(ShiroUtils.getUser().getUserId() + "");
|
||||
online.setLoginName(ShiroUtils.getUser().getLoginName());
|
||||
online.setStartTimestamp(session.getStartTimestamp());
|
||||
online.setLastAccessTime(session.getLastAccessTime());
|
||||
online.setTimeout(session.getTimeout());
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package com.ruoyi.project.system.online.service;
|
||||
|
||||
import java.util.List;
|
||||
import com.ruoyi.project.system.online.domain.UserOnline;
|
||||
|
||||
public interface IUserOnlineService
|
||||
|
|
@ -26,4 +27,18 @@ public interface IUserOnlineService
|
|||
* @param online 会话信息
|
||||
*/
|
||||
public void saveByOnline(UserOnline online);
|
||||
|
||||
/**
|
||||
* 查询会话集合
|
||||
*
|
||||
* @param online 会话信息
|
||||
*/
|
||||
public List<UserOnline> selectUserOnlines();
|
||||
|
||||
/**
|
||||
* 读取Session信息
|
||||
*
|
||||
* @param sessionId 会话ID
|
||||
*/
|
||||
public void forceLogout(String sessionId);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,10 @@
|
|||
package com.ruoyi.project.system.online.service;
|
||||
|
||||
import java.util.List;
|
||||
import org.apache.shiro.session.Session;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.ruoyi.project.shiro.session.OnlineSessionDAO;
|
||||
import com.ruoyi.project.system.online.dao.IUserOnlineDao;
|
||||
import com.ruoyi.project.system.online.domain.UserOnline;
|
||||
|
||||
|
|
@ -11,6 +14,9 @@ public class UserOnlineServiceImpl implements IUserOnlineService
|
|||
@Autowired
|
||||
private IUserOnlineDao userOnlineDao;
|
||||
|
||||
@Autowired
|
||||
private OnlineSessionDAO onlineSessionDAO;
|
||||
|
||||
/**
|
||||
* 通过会话序号查询信息
|
||||
*
|
||||
|
|
@ -44,6 +50,32 @@ public class UserOnlineServiceImpl implements IUserOnlineService
|
|||
*/
|
||||
public void saveByOnline(UserOnline online)
|
||||
{
|
||||
userOnlineDao.saveByOnline(online);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询会话集合
|
||||
*
|
||||
* @param online 会话信息
|
||||
*/
|
||||
public List<UserOnline> selectUserOnlines()
|
||||
{
|
||||
return userOnlineDao.selectUserOnlines();
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取Session信息
|
||||
*
|
||||
* @param sessionId 会话ID
|
||||
*/
|
||||
public void forceLogout(String sessionId)
|
||||
{
|
||||
Session session = onlineSessionDAO.readSession(sessionId);
|
||||
if (session == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
session.setTimeout(0);
|
||||
userOnlineDao.deleteByOnlineId(sessionId);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
package com.ruoyi.project.util;
|
||||
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import com.ruoyi.common.utils.security.ShiroUtils;
|
||||
import com.ruoyi.common.utils.spring.SpringUtils;
|
||||
import com.ruoyi.framework.constant.CommonConstant;
|
||||
import com.ruoyi.project.shiro.common.utils.LogUtils;
|
||||
|
|
@ -33,7 +33,7 @@ public class SystemLogUtils
|
|||
public static void log(String username, String status, String msg, Object... args)
|
||||
{
|
||||
StringBuilder s = new StringBuilder();
|
||||
s.append(LogUtils.getBlock(getIp()));
|
||||
s.append(LogUtils.getBlock(ShiroUtils.getIp()));
|
||||
s.append(LogUtils.getBlock(username));
|
||||
s.append(LogUtils.getBlock(status));
|
||||
s.append(LogUtils.getBlock(msg));
|
||||
|
|
@ -50,11 +50,6 @@ public class SystemLogUtils
|
|||
}
|
||||
}
|
||||
|
||||
public static Object getIp()
|
||||
{
|
||||
return SecurityUtils.getSubject().getSession().getHost();
|
||||
}
|
||||
|
||||
public static void saveOpLog(String username, String message, String status)
|
||||
{
|
||||
UserAgent userAgent = UserAgent.parseUserAgentString(HttpContextUtils.getHttpServletRequest().getHeader("User-Agent"));
|
||||
|
|
@ -66,7 +61,7 @@ public class SystemLogUtils
|
|||
Logininfor logininfor = new Logininfor();
|
||||
logininfor.setLoginName(username);
|
||||
logininfor.setStatus(status);
|
||||
logininfor.setIpaddr(String.valueOf(getIp()));
|
||||
logininfor.setIpaddr(ShiroUtils.getIp());
|
||||
logininfor.setBrowser(browser);
|
||||
logininfor.setOs(os);
|
||||
logininfor.setMsg(message);
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
</select>
|
||||
|
||||
<select id="selectPermsAll" resultMap="MenuResult">
|
||||
select * from sys_menu m
|
||||
select * from sys_menu
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
|
|
@ -19,7 +19,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
</resultMap>
|
||||
|
||||
<resultMap type="OnlineSession" id="OnlineSessionResult">
|
||||
<id property="id" column="sessionId" />
|
||||
<result property="userId" column="user_id" />
|
||||
<result property="loginName" column="login_name" />
|
||||
<result property="host" column="ipaddr" />
|
||||
|
|
@ -29,18 +28,22 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
</resultMap>
|
||||
|
||||
<select id="selectByOnlineId" parameterType="String" resultMap="UserOnlineResult">
|
||||
SELECT *
|
||||
FROM sys_user_online
|
||||
WHERE sessionId = #{sessionId}
|
||||
select *
|
||||
from sys_user_online
|
||||
where sessionid = #{sessionid}
|
||||
</select>
|
||||
|
||||
<insert id="insertLogininfor" parameterType="UserOnline">
|
||||
replace into sys_user_online(sessionId, user_id, login_name, ipaddr, browser, os, STATUS)
|
||||
values (#{sessionId}, #{user_id}, #{login_name}, #{host}, #{browser}, #{os}, #{STATUS})
|
||||
<insert id="saveByOnline" parameterType="UserOnline">
|
||||
replace into sys_user_online(sessionId, user_id, login_name, ipaddr, browser, os, status, start_timestsamp, last_access_time, timeout)
|
||||
values (#{sessionId}, #{userId}, #{loginName}, #{host}, #{browser}, #{os}, #{status}, #{startTimestamp}, #{lastAccessTime}, #{timeout})
|
||||
</insert>
|
||||
|
||||
<delete id="deleteByOnlineId" parameterType="String">
|
||||
delete from sys_user_online where sessionId = #{sessionId}
|
||||
</delete>
|
||||
|
||||
<select id="selectUserOnlines" resultMap="UserOnlineResult">
|
||||
select * from sys_user_online
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
|
|
@ -45,14 +45,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
</select>
|
||||
|
||||
<select id="selectByUserName" parameterType="String" resultMap="UserResult">
|
||||
SELECT u.user_id, u.dept_id, u.login_name, u.user_name, u.email, u.phonenumber, u.password, u.salt, u.status, u.refuse_des, u.create_time,
|
||||
select u.user_id, u.dept_id, u.login_name, u.user_name, u.email, u.phonenumber, u.password, u.salt, u.status, u.refuse_des, u.create_time,
|
||||
d.dept_id, d.parent_id, d.dept_name, d.order_num, d.status as dept_status,
|
||||
r.role_id, r.role_name, r.status as role_status, r.remark
|
||||
FROM sys_user u
|
||||
LEFT JOIN sys_dept d ON u.dept_id = d.dept_id
|
||||
LEFT JOIN sys_user_role ur ON u.user_id = ur.user_id
|
||||
LEFT JOIN sys_role r ON ur.role_id = r.role_id
|
||||
WHERE u.login_name = #{userName}
|
||||
from sys_user u
|
||||
left join sys_dept d on u.dept_id = d.dept_id
|
||||
left join sys_user_role ur on u.user_id = ur.user_id
|
||||
left join sys_role r on ur.role_id = r.role_id
|
||||
where u.login_name = #{username}
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="zh_CN" xmlns:th="http://www.thymeleaf.org"
|
||||
xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
|
||||
<meta charset="utf-8">
|
||||
<head th:include="include :: header"></head>
|
||||
<body class="gray-bg">
|
||||
<div class="wrapper wrapper-content ">
|
||||
<div class="row">
|
||||
|
||||
<div class="col-sm-11">
|
||||
<div class="ibox">
|
||||
<div class="ibox-body">
|
||||
<div class="fixed-table-toolbar">
|
||||
<div class="columns pull-left">
|
||||
|
||||
</div>
|
||||
<div class="columns pull-right">
|
||||
<button class="btn btn-success" onclick="reLoad()">查询</button>
|
||||
</div>
|
||||
|
||||
<div class="columns pull-right col-md-2 nopadding">
|
||||
<input id="searchName" type="text" class="form-control"
|
||||
placeholder="">
|
||||
</div>
|
||||
</div>
|
||||
<table id="exampleTable" data-mobile-responsive="true">
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div th:include="include :: footer"></div>
|
||||
<script type="text/javascript" src="/js/appjs/sys/online/online.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
Loading…
Reference in New Issue