|
|
@@ -18,8 +18,7 @@ package me.zhengjie.security.service;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
-import com.corundumstudio.socketio.SocketIOClient;
|
|
|
-import com.google.gson.JsonObject;
|
|
|
+
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
|
import me.zhengjie.security.config.bean.SecurityProperties;
|
|
|
@@ -27,9 +26,6 @@ import me.zhengjie.security.domain.OnlineUserConstant;
|
|
|
import me.zhengjie.security.service.dto.OnlineUserDto;
|
|
|
import me.zhengjie.utils.*;
|
|
|
|
|
|
-
|
|
|
-import org.apache.commons.collections4.MapUtils;
|
|
|
-
|
|
|
import org.springframework.data.domain.Pageable;
|
|
|
import org.springframework.scheduling.annotation.Async;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
@@ -49,6 +45,7 @@ public class OnlineUserService {
|
|
|
|
|
|
private final SecurityProperties properties;
|
|
|
private final RedisUtils redisUtils;
|
|
|
+
|
|
|
public OnlineUserService(SecurityProperties properties, RedisUtils redisUtils) {
|
|
|
this.properties = properties;
|
|
|
this.redisUtils = redisUtils;
|
|
|
@@ -126,7 +123,7 @@ public class OnlineUserService {
|
|
|
}
|
|
|
return set;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* 判断公证处和银行绑定关系
|
|
|
*
|
|
|
@@ -190,6 +187,24 @@ public class OnlineUserService {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 查询全部数据,不分页
|
|
|
+ *
|
|
|
+ * @param filterKeyword
|
|
|
+ * @param type
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Map<String, String> getAppAllLoginName() {
|
|
|
+ List<String> keys = redisUtils.scan(OnlineUserConstant.PREFIX_APP + "*");
|
|
|
+ Map<String, String> appOnlineUse = new HashMap<>();
|
|
|
+ for (String key : keys) {
|
|
|
+ JSONObject onlineUserDto = JSON.parseObject((String) redisUtils.get(key));
|
|
|
+ String phone = onlineUserDto.getString("phone");
|
|
|
+ appOnlineUse.put(key,phone);
|
|
|
+ }
|
|
|
+ return appOnlineUse;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 查询全部登录用户
|
|
|
*
|
|
|
* @return
|
|
|
@@ -203,15 +218,16 @@ public class OnlineUserService {
|
|
|
}
|
|
|
return securityContextUsers;
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
* 查询全部登录用户
|
|
|
*
|
|
|
* @return
|
|
|
*/
|
|
|
public Set<String> getAllLoginUserName() {
|
|
|
- List<OnlineUserDto> online= getAllLoginUser();
|
|
|
+ List<OnlineUserDto> online = getAllLoginUser();
|
|
|
Set<String> set = new HashSet<>();
|
|
|
- for (OnlineUserDto userDto:online) {
|
|
|
+ for (OnlineUserDto userDto : online) {
|
|
|
set.add(userDto.getUsername());
|
|
|
}
|
|
|
return set;
|
|
|
@@ -226,7 +242,15 @@ public class OnlineUserService {
|
|
|
key = properties.getOnlineKey() + key;
|
|
|
redisUtils.del(key);
|
|
|
}
|
|
|
-
|
|
|
+ /**
|
|
|
+ * 踢出用户
|
|
|
+ *
|
|
|
+ * @param key /
|
|
|
+ */
|
|
|
+ public void kickApp(String key) {
|
|
|
+ key = properties.getOnlineKey() + key;
|
|
|
+ redisUtils.del(key);
|
|
|
+ }
|
|
|
/**
|
|
|
* 退出登录
|
|
|
*
|
|
|
@@ -306,10 +330,23 @@ public class OnlineUserService {
|
|
|
if (onlineUser.getUsername().equals(username)) {
|
|
|
String token = EncryptUtils.desDecrypt(onlineUser.getKey());
|
|
|
kickOut(token);
|
|
|
-
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 根据用户名强退用户
|
|
|
+ *
|
|
|
+ * @param username /
|
|
|
+ */
|
|
|
+ @Async
|
|
|
+ public void kickOutForPhoneUsername(String loginPhone) {
|
|
|
+ Map<String, String> map = getAppAllLoginName();
|
|
|
+ for (String key : map.keySet()) {
|
|
|
+ String phone = map.get(key);
|
|
|
+ if (phone.equals(loginPhone)) {
|
|
|
+ kickApp(key);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
}
|