Commit f9ca1b65 authored by xuepeng.chang's avatar xuepeng.chang

获取用户的登陆渠道和踢出

parent da051007
...@@ -18,5 +18,18 @@ public class UserLoginVO implements Serializable { ...@@ -18,5 +18,18 @@ public class UserLoginVO implements Serializable {
/** 用户当前登陆的终端渠道*/ /** 用户当前登陆的终端渠道*/
private Long currentRegisteredFrom; private Long currentRegisteredFrom;
/** 用户所有登陆的终端渠道(这里 要把金融的排除掉) */ /** 用户所有登陆的终端渠道(这里 要把金融的排除掉) */
private List<Long> registeredFromList; private List<LoginChannelInfo> registeredFromList;
@Data
@AllArgsConstructor
@NoArgsConstructor
public static class LoginChannelInfo implements Serializable {
private static final long serialVersionUID = -1L;
/** 渠道*/
private Long registeredFrom;
/** 设备号*/
private String deviceId;
/** app渠道(app的下载渠道)*/
private String appChannel;
}
} }
...@@ -7,4 +7,6 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor; ...@@ -7,4 +7,6 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
public interface ILoginRecordRepository extends JpaRepository<LoginRecord, Long>, JpaSpecificationExecutor<LoginRecord> { public interface ILoginRecordRepository extends JpaRepository<LoginRecord, Long>, JpaSpecificationExecutor<LoginRecord> {
LoginRecord findFirstByDeviceIdOrderByCreatedAtDesc(String deviceId); LoginRecord findFirstByDeviceIdOrderByCreatedAtDesc(String deviceId);
LoginRecord findLastByUserIdAndVccChannelByCreatedAtDesc(Long userId, Long vccChannel);
} }
...@@ -5,6 +5,7 @@ import cn.quantgroup.xyqb.constant.UserConstant; ...@@ -5,6 +5,7 @@ import cn.quantgroup.xyqb.constant.UserConstant;
import cn.quantgroup.xyqb.constant.enums.RecordType; import cn.quantgroup.xyqb.constant.enums.RecordType;
import cn.quantgroup.xyqb.controller.req.v2.KickOutReq; import cn.quantgroup.xyqb.controller.req.v2.KickOutReq;
import cn.quantgroup.xyqb.controller.req.v2.LogInChannelReq; import cn.quantgroup.xyqb.controller.req.v2.LogInChannelReq;
import cn.quantgroup.xyqb.entity.LoginRecord;
import cn.quantgroup.xyqb.entity.User; import cn.quantgroup.xyqb.entity.User;
import cn.quantgroup.xyqb.entity.UserTag; import cn.quantgroup.xyqb.entity.UserTag;
import cn.quantgroup.xyqb.event.UserLoginEvent; import cn.quantgroup.xyqb.event.UserLoginEvent;
...@@ -67,6 +68,8 @@ public class SessionServiceImpl implements ISessionService { ...@@ -67,6 +68,8 @@ public class SessionServiceImpl implements ISessionService {
private ApplicationEventPublisher applicationEventPublisher; private ApplicationEventPublisher applicationEventPublisher;
private static final String UUID_AUTH = "9f882ed6-2-23b%-4d6f-8843-97a2c0e215b0"; private static final String UUID_AUTH = "9f882ed6-2-23b%-4d6f-8843-97a2c0e215b0";
// 安卓和IOS ,鸿蒙的么有传设备号和 渠道信息
private static final List<Long> AppChannel = Arrays.asList(214L, 217L);
/** /**
...@@ -133,7 +136,7 @@ public class SessionServiceImpl implements ISessionService { ...@@ -133,7 +136,7 @@ public class SessionServiceImpl implements ISessionService {
String setKey = getUserSessionSetKey(userId, tenantId); String setKey = getUserSessionSetKey(userId, tenantId);
Set useIdKeys = stringRedisTemplate.opsForSet().members(setKey); Set useIdKeys = stringRedisTemplate.opsForSet().members(setKey);
log.info("[obtainUserLoginChannel]获取当前userId={}的缓存信息,useIdKeys:{}", userId, JSON.toJSONString(useIdKeys)); log.info("[obtainUserLoginChannel]获取当前userId={}的缓存信息,useIdKeys:{}", userId, JSON.toJSONString(useIdKeys));
List<Long> registeredFromList = new ArrayList<>(); List<UserLoginVO.LoginChannelInfo> registeredFromList = new ArrayList<>();
Long currentRegisteredFrom = null; Long currentRegisteredFrom = null;
if (!CollectionUtils.isEmpty(useIdKeys)){ if (!CollectionUtils.isEmpty(useIdKeys)){
for (Object key : useIdKeys) { for (Object key : useIdKeys) {
...@@ -156,7 +159,17 @@ public class SessionServiceImpl implements ISessionService { ...@@ -156,7 +159,17 @@ public class SessionServiceImpl implements ISessionService {
// userid-sessionvalue:cache::75234409:vcc:217 // userid-sessionvalue:cache::75234409:vcc:217
String[] keyParams = keyStr.split(":"); String[] keyParams = keyStr.split(":");
Long registeredFrom = Long.valueOf(keyParams[5]); Long registeredFrom = Long.valueOf(keyParams[5]);
registeredFromList.add(registeredFrom); UserLoginVO.LoginChannelInfo loginChannelInfo = new UserLoginVO.LoginChannelInfo();
loginChannelInfo.setRegisteredFrom(registeredFrom);
// 如果是aap端的获取app的登陆设备号和app下载渠道
if(AppChannel.contains(registeredFrom)){
LoginRecord loginRecord = loginRecordService.findLastByUserIdAndVccChannel(userId, registeredFrom);
if(Objects.nonNull(loginRecord)){
loginChannelInfo.setAppChannel(loginRecord.getAppChannel());
loginChannelInfo.setDeviceId(loginRecord.getDeviceId());
}
}
registeredFromList.add(loginChannelInfo);
if(Objects.equals(token, logInChannelReq.getToken())){ if(Objects.equals(token, logInChannelReq.getToken())){
currentRegisteredFrom = registeredFrom; currentRegisteredFrom = registeredFrom;
} }
......
...@@ -10,4 +10,6 @@ public interface ILoginRecordService { ...@@ -10,4 +10,6 @@ public interface ILoginRecordService {
LoginRecord findFirstLoginRecord(String deviceId); LoginRecord findFirstLoginRecord(String deviceId);
void saveLoginRecord(Long id, String name, int loginType); void saveLoginRecord(Long id, String name, int loginType);
LoginRecord findLastByUserIdAndVccChannel(Long id,Long vccChannel);
} }
...@@ -58,6 +58,11 @@ public class LoginRecordServiceImpl implements ILoginRecordService, IBaseControl ...@@ -58,6 +58,11 @@ public class LoginRecordServiceImpl implements ILoginRecordService, IBaseControl
loginRecordRepository.saveAndFlush(loginRecord); loginRecordRepository.saveAndFlush(loginRecord);
} }
@Override
public LoginRecord findLastByUserIdAndVccChannel(Long id,Long vccChannel) {
return loginRecordRepository.findLastByUserIdAndVccChannelByCreatedAtDesc(id, vccChannel);
}
@Override @Override
public LoginRecord findFirstLoginRecord(String deviceId) { public LoginRecord findFirstLoginRecord(String deviceId) {
return loginRecordRepository.findFirstByDeviceIdOrderByCreatedAtDesc(deviceId); return loginRecordRepository.findFirstByDeviceIdOrderByCreatedAtDesc(deviceId);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment