feat: SaLogoutParameter 新增 deviceId 参数,用于控制指定设备 id 的注销

This commit is contained in:
click33
2025-04-30 07:30:11 +08:00
parent 9ceebda9f5
commit 66c431bb3e
2 changed files with 50 additions and 10 deletions

View File

@@ -916,8 +916,16 @@ public class StpLogic {
if(session != null) {
// 2、遍历此 SaTerminalInfo 客户端列表,清除相关数据
List<SaTerminalInfo> terminalList = session.getTerminalListByDeviceType(logoutParameter.getDeviceType());
List<SaTerminalInfo> terminalList = session.terminalListCopy();
for (SaTerminalInfo terminal: terminalList) {
// 不符合 deviceType 的跳过
if( ! SaFoxUtil.isEmpty(logoutParameter.getDeviceType()) && ! logoutParameter.getDeviceType().equals(terminal.getDeviceType())) {
continue;
}
// 不符合 deviceId 的跳过
if( ! SaFoxUtil.isEmpty(logoutParameter.getDeviceId()) && ! logoutParameter.getDeviceId().equals(terminal.getDeviceId())) {
continue;
}
_removeTerminal(session, terminal, logoutParameter);
}

View File

@@ -36,10 +36,17 @@ public class SaLogoutParameter {
// --------- 单独参数
/**
* 需要注销的设备类型 (如果不指定,则默认注销所有客户端)
* 需要注销的设备类型 (为 null 代表不限制,为具体值代表只注销此设备类型的会话)
* <br/> (此参数只在调用 StpUtil.logout(id, parame) 时有效)
*/
private String deviceType;
/**
* 需要注销的设备ID (为 null 代表不限制为具体值代表只注销此设备ID的会话)
* <br/> (此参数只在调用 StpUtil.logout(id, param) 时有效)
*/
private String deviceId;
/**
* 注销类型 (LOGOUT=注销下线、KICKOUT=踢人下线REPLACED=顶人下线)
*/
@@ -50,13 +57,13 @@ public class SaLogoutParameter {
/**
* 注销范围 (TOKEN=只注销当前 token 的会话ACCOUNT=注销当前 token 指向的 loginId 其所有客户端会话)
* <br/> (此参数只在调用 StpUtil.logout() 时有效)
* <br/> (此参数只在调用 StpUtil.logout(param) 时有效)
*/
private SaLogoutRange range;
/**
* 如果 token 已被冻结,是否保留其操作权 (是否允许此 token 调用注销API)
* <br/> (此参数只在调用 StpUtil.[logout/kickout/replaced]ByTokenValue("token") 时有效)
* <br/> (此参数只在调用 StpUtil.[logout/kickout/replaced]ByTokenValue("token", param) 时有效)
*/
private Boolean isKeepFreezeOps;
@@ -119,7 +126,7 @@ public class SaLogoutParameter {
/**
* 获取 如果 token 已被冻结,是否保留其操作权 (是否允许此 token 调用注销API)
* <br/> (此参数只在调用 StpUtil.[logout/kickout/replaced]ByTokenValue("token") 时有效)
* <br/> (此参数只在调用 StpUtil.[logout/kickout/replaced]ByTokenValue("token", param) 时有效)
*
* @return /
*/
@@ -129,7 +136,7 @@ public class SaLogoutParameter {
/**
* 设置 如果 token 已被冻结,是否保留其操作权 (是否允许此 token 调用注销API)
* <br/> (此参数只在调用 StpUtil.[logout/kickout/replaced]ByTokenValue("token") 时有效)
* <br/> (此参数只在调用 StpUtil.[logout/kickout/replaced]ByTokenValue("token", param) 时有效)
*
* @param isKeepFreezeOps /
* @return 对象自身
@@ -140,7 +147,8 @@ public class SaLogoutParameter {
}
/**
* 需要注销的设备类型 (如果不指定,则默认注销所有客户端)
* 需要注销的设备类型 (为 null 代表不限制,为具体值代表只注销此设备类型的会话)
* <br/> (此参数只在调用 StpUtil.logout(id, parame) 时有效)
*
* @return deviceType /
*/
@@ -149,7 +157,8 @@ public class SaLogoutParameter {
}
/**
* 需要注销的设备类型 (如果不指定,则默认注销所有客户端)
* 需要注销的设备类型 (为 null 代表不限制,为具体值代表只注销此设备类型的会话)
* <br/> (此参数只在调用 StpUtil.logout(id, parame) 时有效)
*
* @param deviceType /
* @return /
@@ -159,6 +168,28 @@ public class SaLogoutParameter {
return this;
}
/**
* 需要注销的设备ID (为 null 代表不限制,为具体值代表只注销此设备 ID 的会话)
* <br/> (此参数只在调用 StpUtil.logout(id, parame) 时有效)
*
* @return /
*/
public String getDeviceId() {
return this.deviceId;
}
/**
* 需要注销的设备类型 (为 null 代表不限制,为具体值代表只注销此设备 ID 的会话)
* <br/> (此参数只在调用 StpUtil.logout(id, parame) 时有效)
*
* @param deviceId /
* @return /
*/
public SaLogoutParameter setDeviceId(String deviceId) {
this.deviceId = deviceId;
return this;
}
/**
* 注销类型 (LOGOUT=注销下线、KICKOUT=踢人下线REPLACED=顶人下线)
*
@@ -181,7 +212,7 @@ public class SaLogoutParameter {
/**
* 注销范围 (TOKEN=只注销当前 token 的会话ACCOUNT=注销当前 token 指向的 loginId 其所有客户端会话)
* <br/> (此参数只在调用 StpUtil.logout() 时有效)
* <br/> (此参数只在调用 StpUtil.logout(param) 时有效)
*
* @return /
*/
@@ -191,7 +222,7 @@ public class SaLogoutParameter {
/**
* 注销范围 (TOKEN=只注销当前 token 的会话ACCOUNT=注销当前 token 指向的 loginId 其所有客户端会话)
* <br/> (此参数只在调用 StpUtil.logout() 时有效)
* <br/> (此参数只在调用 StpUtil.logout(param) 时有效)
*
* @param range /
* @return /
@@ -208,6 +239,7 @@ public class SaLogoutParameter {
public String toString() {
return "SaLoginParameter ["
+ "deviceType=" + deviceType
+ ", deviceId=" + deviceId
+ ", isKeepTokenSession=" + isKeepTokenSession
+ ", isKeepFreezeOps=" + isKeepFreezeOps
+ ", mode=" + mode