|
|
|
@ -2,6 +2,7 @@ package com.ruoyi.web.controller.api;
|
|
|
|
|
|
|
|
|
|
import com.ruoyi.common.constant.Constants;
|
|
|
|
|
import com.ruoyi.common.core.domain.entity.SysUser;
|
|
|
|
|
import com.ruoyi.common.enums.OnlineStatus;
|
|
|
|
|
import com.ruoyi.common.utils.CookieUtils;
|
|
|
|
|
import com.ruoyi.common.utils.MessageUtils;
|
|
|
|
|
import com.ruoyi.common.utils.ShiroUtils;
|
|
|
|
@ -9,11 +10,16 @@ import com.ruoyi.common.utils.StringUtils;
|
|
|
|
|
import com.ruoyi.common.utils.spring.SpringUtils;
|
|
|
|
|
import com.ruoyi.framework.manager.AsyncManager;
|
|
|
|
|
import com.ruoyi.framework.manager.factory.AsyncFactory;
|
|
|
|
|
import com.ruoyi.framework.shiro.session.OnlineSession;
|
|
|
|
|
import com.ruoyi.framework.shiro.session.OnlineSessionDAO;
|
|
|
|
|
import com.ruoyi.framework.shiro.web.filter.LogoutFilter;
|
|
|
|
|
import com.ruoyi.system.domain.SysUserOnline;
|
|
|
|
|
import com.ruoyi.system.service.ISysUserOnlineService;
|
|
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
|
|
import org.apache.shiro.SecurityUtils;
|
|
|
|
|
import org.apache.shiro.subject.Subject;
|
|
|
|
|
import org.apache.shiro.web.servlet.SimpleCookie;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
@ -23,6 +29,8 @@ import javax.servlet.ServletResponse;
|
|
|
|
|
import javax.servlet.http.Cookie;
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 工业互联网退出接口
|
|
|
|
@ -32,15 +40,42 @@ import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
@Controller
|
|
|
|
|
@RequestMapping("/api/logout")
|
|
|
|
|
public class LogoutApi {
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private ISysUserOnlineService userOnlineService;
|
|
|
|
|
@Autowired
|
|
|
|
|
private OnlineSessionDAO onlineSessionDAO;
|
|
|
|
|
@GetMapping()
|
|
|
|
|
public void logout(HttpServletRequest request, HttpServletResponse response,String userName){
|
|
|
|
|
//CookieUtil.remove(request, response, "JSESSIONID");
|
|
|
|
|
//START
|
|
|
|
|
System.out.println("》》》获取接口用户名:"+ userName);
|
|
|
|
|
SysUserOnline userOnline = new SysUserOnline();
|
|
|
|
|
userOnline.setStatus(OnlineStatus.on_line);
|
|
|
|
|
List<SysUserOnline> list = userOnlineService.selectUserOnlineList(userOnline);
|
|
|
|
|
|
|
|
|
|
List<SysUserOnline> result = null;
|
|
|
|
|
|
|
|
|
|
result = list.stream()
|
|
|
|
|
.filter((SysUserOnline b) -> b.getLoginName().contains(userName))
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
for (SysUserOnline SysUserOnline:result
|
|
|
|
|
) {
|
|
|
|
|
SysUserOnline online = userOnlineService.selectOnlineById(SysUserOnline.getSessionId());
|
|
|
|
|
OnlineSession onlineSession = (OnlineSession) onlineSessionDAO.readSession(online.getSessionId());
|
|
|
|
|
onlineSessionDAO.delete(onlineSession);
|
|
|
|
|
online.setStatus(OnlineStatus.off_line);
|
|
|
|
|
userOnlineService.saveOnline(online);
|
|
|
|
|
userOnlineService.removeUserCache(online.getLoginName(), SysUserOnline.getSessionId());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//END
|
|
|
|
|
Subject subject = SecurityUtils.getSubject();
|
|
|
|
|
SysUser user = new SysUser();
|
|
|
|
|
user.setUserName(userName);
|
|
|
|
|
if (StringUtils.isNotNull(user))
|
|
|
|
|
{
|
|
|
|
|
String loginName = user.getLoginName();
|
|
|
|
|
String loginName = ShiroUtils.getLoginName();
|
|
|
|
|
// 记录用户退出日志
|
|
|
|
|
AsyncManager.me().execute(AsyncFactory.recordLogininfor(loginName, Constants.LOGOUT, MessageUtils.message("user.logout.success")));
|
|
|
|
|
// 清理缓存
|
|
|
|
|