提交 | 用户 | 时间
|
0cceb6
|
1 |
package com.jcdm.web.controller.monitor; |
Y |
2 |
|
|
3 |
import java.util.ArrayList; |
|
4 |
import java.util.Collection; |
|
5 |
import java.util.Collections; |
|
6 |
import java.util.List; |
|
7 |
import org.springframework.beans.factory.annotation.Autowired; |
|
8 |
import org.springframework.security.access.prepost.PreAuthorize; |
|
9 |
import org.springframework.web.bind.annotation.DeleteMapping; |
|
10 |
import org.springframework.web.bind.annotation.GetMapping; |
|
11 |
import org.springframework.web.bind.annotation.PathVariable; |
|
12 |
import org.springframework.web.bind.annotation.RequestMapping; |
|
13 |
import org.springframework.web.bind.annotation.RestController; |
|
14 |
import com.jcdm.common.annotation.Log; |
|
15 |
import com.jcdm.common.constant.CacheConstants; |
|
16 |
import com.jcdm.common.core.controller.BaseController; |
|
17 |
import com.jcdm.common.core.domain.AjaxResult; |
|
18 |
import com.jcdm.common.core.domain.model.LoginUser; |
|
19 |
import com.jcdm.common.core.page.TableDataInfo; |
|
20 |
import com.jcdm.common.core.redis.RedisCache; |
|
21 |
import com.jcdm.common.enums.BusinessType; |
|
22 |
import com.jcdm.common.utils.StringUtils; |
|
23 |
import com.jcdm.system.domain.SysUserOnline; |
|
24 |
import com.jcdm.system.service.ISysUserOnlineService; |
|
25 |
|
|
26 |
/** |
|
27 |
* 在线用户监控 |
|
28 |
* |
|
29 |
* @author jc |
|
30 |
*/ |
|
31 |
@RestController |
|
32 |
@RequestMapping("/monitor/online") |
|
33 |
public class SysUserOnlineController extends BaseController |
|
34 |
{ |
|
35 |
@Autowired |
|
36 |
private ISysUserOnlineService userOnlineService; |
|
37 |
|
|
38 |
@Autowired |
|
39 |
private RedisCache redisCache; |
|
40 |
|
|
41 |
@PreAuthorize("@ss.hasPermi('monitor:online:list')") |
|
42 |
@GetMapping("/list") |
|
43 |
public TableDataInfo list(String ipaddr, String userName) |
|
44 |
{ |
|
45 |
Collection<String> keys = redisCache.keys(CacheConstants.LOGIN_TOKEN_KEY + "*"); |
|
46 |
List<SysUserOnline> userOnlineList = new ArrayList<SysUserOnline>(); |
|
47 |
for (String key : keys) |
|
48 |
{ |
|
49 |
LoginUser user = redisCache.getCacheObject(key); |
|
50 |
if (StringUtils.isNotEmpty(ipaddr) && StringUtils.isNotEmpty(userName)) |
|
51 |
{ |
|
52 |
userOnlineList.add(userOnlineService.selectOnlineByInfo(ipaddr, userName, user)); |
|
53 |
} |
|
54 |
else if (StringUtils.isNotEmpty(ipaddr)) |
|
55 |
{ |
|
56 |
userOnlineList.add(userOnlineService.selectOnlineByIpaddr(ipaddr, user)); |
|
57 |
} |
|
58 |
else if (StringUtils.isNotEmpty(userName) && StringUtils.isNotNull(user.getUser())) |
|
59 |
{ |
|
60 |
userOnlineList.add(userOnlineService.selectOnlineByUserName(userName, user)); |
|
61 |
} |
|
62 |
else |
|
63 |
{ |
|
64 |
userOnlineList.add(userOnlineService.loginUserToUserOnline(user)); |
|
65 |
} |
|
66 |
} |
|
67 |
Collections.reverse(userOnlineList); |
|
68 |
userOnlineList.removeAll(Collections.singleton(null)); |
|
69 |
return getDataTable(userOnlineList); |
|
70 |
} |
|
71 |
|
|
72 |
/** |
|
73 |
* 强退用户 |
|
74 |
*/ |
|
75 |
@PreAuthorize("@ss.hasPermi('monitor:online:forceLogout')") |
|
76 |
@Log(title = "在线用户", businessType = BusinessType.FORCE) |
|
77 |
@DeleteMapping("/{tokenId}") |
|
78 |
public AjaxResult forceLogout(@PathVariable String tokenId) |
|
79 |
{ |
|
80 |
redisCache.deleteObject(CacheConstants.LOGIN_TOKEN_KEY + tokenId); |
|
81 |
return success(); |
|
82 |
} |
|
83 |
} |