|
@@ -1,6 +1,9 @@
|
|
|
package com.usky.system.controller.web;
|
|
|
|
|
|
import java.util.*;
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
import com.usky.common.core.bean.ApiResult;
|
|
|
import com.usky.common.core.constants.CacheConstants;
|
|
|
import com.usky.common.core.utils.StringUtils;
|
|
@@ -177,23 +180,13 @@ public class SysUserOnlineController {
|
|
|
@RequestParam(required = false, defaultValue = "1") Integer page,
|
|
|
@RequestParam(required = false, defaultValue = "999") Integer size) {
|
|
|
try {
|
|
|
- // 调用 /history 接口获取登录历史记录
|
|
|
- String historyUrl = "http://172.16.120.165:13200/offline-api/system/online/history?page=" + page + "&size=" + size + "&userid=" + userid;
|
|
|
-// String historyUrl = "https://gateway.usky.cn/prod-api/system/online/history?page=" + page + "&size=" + size + "&userid=" + userid;
|
|
|
- // 这里需要使用HTTP客户端来调用历史接口,例如使用RestTemplate
|
|
|
- RestTemplate restTemplate = new RestTemplate();
|
|
|
- ResponseEntity<String> response = restTemplate.getForEntity(historyUrl, String.class);
|
|
|
-
|
|
|
- if (response.getStatusCode().is2xxSuccessful()) {
|
|
|
- // 解析响应数据
|
|
|
- JSONObject historyData = new JSONObject(response.getBody());
|
|
|
- JSONArray rows = historyData.getJSONObject("data").getJSONArray("rows");
|
|
|
- List<String> tokenIds = new ArrayList<>();
|
|
|
- for (int i = 0; i < rows.length(); i++) { // 使用 rows.length() 获取长度
|
|
|
- JSONObject row = rows.getJSONObject(i);
|
|
|
- String tokenId = row.getString("tokenId");
|
|
|
- tokenIds.add(tokenId);
|
|
|
- }
|
|
|
+ ApiResult<TableDataInfo> apiResult = listOtherLogins(userid, page, size);
|
|
|
+ if (apiResult.isSuccess() && apiResult.getData() != null) {
|
|
|
+ TableDataInfo tableDataInfo = apiResult.getData();
|
|
|
+ List<SysUserOnline> userOnlineList = (List<SysUserOnline>) tableDataInfo.getRows();
|
|
|
+ List<String> tokenIds = userOnlineList.stream()
|
|
|
+ .map(SysUserOnline::getTokenId)
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
|
// 执行强退操作
|
|
|
for (String tokenId : tokenIds) {
|
|
@@ -207,8 +200,8 @@ public class SysUserOnlineController {
|
|
|
}
|
|
|
return ApiResult.success("已强制注销所有选中token.");
|
|
|
} else {
|
|
|
- logger.error("调用 /history 接口失败,状态码:{}", response.getStatusCode());
|
|
|
- return ApiResult.error("SYS-0003", "调用历史记录接口失败", response.getStatusCode().toString());
|
|
|
+ logger.error("调用 listOtherLogins 方法失败,原因:{}", apiResult.getMsg());
|
|
|
+ return ApiResult.error("SYS-0003", "调用历史记录接口失败", apiResult.getMsg());
|
|
|
}
|
|
|
} catch (Exception ex) {
|
|
|
logger.error("处理forceLogoutMany时出错", ex);
|