|
|
@@ -1,31 +1,21 @@
|
|
|
package com.ktg.web.controller.monitor;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Collection;
|
|
|
-import java.util.Collections;
|
|
|
-import java.util.List;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
-import org.springframework.web.bind.annotation.DeleteMapping;
|
|
|
-import org.springframework.web.bind.annotation.GetMapping;
|
|
|
-import org.springframework.web.bind.annotation.PathVariable;
|
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
-import org.springframework.web.bind.annotation.RestController;
|
|
|
import com.ktg.common.annotation.Log;
|
|
|
-import com.ktg.common.constant.Constants;
|
|
|
import com.ktg.common.core.controller.BaseController;
|
|
|
import com.ktg.common.core.domain.AjaxResult;
|
|
|
-import com.ktg.common.core.domain.model.LoginUser;
|
|
|
import com.ktg.common.core.page.TableDataInfo;
|
|
|
-import com.ktg.common.core.redis.RedisCache;
|
|
|
import com.ktg.common.enums.BusinessType;
|
|
|
-import com.ktg.common.utils.StringUtils;
|
|
|
import com.ktg.system.domain.SysUserOnline;
|
|
|
import com.ktg.system.service.ISysUserOnlineService;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
|
|
|
/**
|
|
|
* 在线用户监控
|
|
|
- *
|
|
|
+ *
|
|
|
* @author ruoyi
|
|
|
*/
|
|
|
@RestController
|
|
|
@@ -35,46 +25,11 @@ public class SysUserOnlineController extends BaseController
|
|
|
@Autowired
|
|
|
private ISysUserOnlineService userOnlineService;
|
|
|
|
|
|
- @Autowired
|
|
|
- private RedisCache redisCache;
|
|
|
-
|
|
|
@PreAuthorize("@ss.hasPermi('monitor:online:list')")
|
|
|
@GetMapping("/list")
|
|
|
public TableDataInfo list(String ipaddr, String userName)
|
|
|
{
|
|
|
- Collection<String> keys = redisCache.keys(Constants.LOGIN_TOKEN_KEY + "*");
|
|
|
- List<SysUserOnline> userOnlineList = new ArrayList<SysUserOnline>();
|
|
|
- for (String key : keys)
|
|
|
- {
|
|
|
- LoginUser user = redisCache.getCacheObject(key);
|
|
|
- if (StringUtils.isNotEmpty(ipaddr) && StringUtils.isNotEmpty(userName))
|
|
|
- {
|
|
|
- if (StringUtils.equals(ipaddr, user.getIpaddr()) && StringUtils.equals(userName, user.getUsername()))
|
|
|
- {
|
|
|
- userOnlineList.add(userOnlineService.selectOnlineByInfo(ipaddr, userName, user));
|
|
|
- }
|
|
|
- }
|
|
|
- else if (StringUtils.isNotEmpty(ipaddr))
|
|
|
- {
|
|
|
- if (StringUtils.equals(ipaddr, user.getIpaddr()))
|
|
|
- {
|
|
|
- userOnlineList.add(userOnlineService.selectOnlineByIpaddr(ipaddr, user));
|
|
|
- }
|
|
|
- }
|
|
|
- else if (StringUtils.isNotEmpty(userName) && StringUtils.isNotNull(user.getUser()))
|
|
|
- {
|
|
|
- if (StringUtils.equals(userName, user.getUsername()))
|
|
|
- {
|
|
|
- userOnlineList.add(userOnlineService.selectOnlineByUserName(userName, user));
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- userOnlineList.add(userOnlineService.loginUserToUserOnline(user));
|
|
|
- }
|
|
|
- }
|
|
|
- Collections.reverse(userOnlineList);
|
|
|
- userOnlineList.removeAll(Collections.singleton(null));
|
|
|
+ List<SysUserOnline> userOnlineList = userOnlineService.getOnlineList(ipaddr, userName);
|
|
|
return getDataTable(userOnlineList);
|
|
|
}
|
|
|
|
|
|
@@ -86,7 +41,6 @@ public class SysUserOnlineController extends BaseController
|
|
|
@DeleteMapping("/{tokenId}")
|
|
|
public AjaxResult forceLogout(@PathVariable String tokenId)
|
|
|
{
|
|
|
- redisCache.deleteObject(Constants.LOGIN_TOKEN_KEY + tokenId);
|
|
|
- return AjaxResult.success();
|
|
|
+ return AjaxResult.success(userOnlineService.forceLogout(tokenId));
|
|
|
}
|
|
|
}
|