Commit 7bde5dec authored by 董建华's avatar 董建华

登出接口

parent 65b6c8c7
...@@ -463,6 +463,30 @@ public class UserController implements IBaseController { ...@@ -463,6 +463,30 @@ public class UserController implements IBaseController {
return JsonResult.buildSuccessResult("token校验成功", userModel); return JsonResult.buildSuccessResult("token校验成功", userModel);
} }
/**
* 登出接口
*
* @param channelId
* @param appChannel
* @param createdFrom
* @param key
* @param phoneNo
* @return
*/
@RequestMapping("/logout")
public JsonResult logout(
@RequestParam(required = false, defaultValue = "1") Long channelId, String appChannel,
@RequestParam(required = false, defaultValue = "1") Long createdFrom,
@RequestParam(required = false, defaultValue = "xyqb") String key,
@RequestParam(name = "phoneNo") String phoneNo) {
Merchant merchant = merchantService.findMerchantByName(key);
if (merchant == null) {
return JsonResult.buildErrorStateResult("未知的连接", null);
}
userService.logout(channelId, appChannel, createdFrom, merchant, phoneNo);
return JsonResult.buildSuccessResult("登出成功");
}
private JsonResult loginWithHttpBasic(Long channelId, String appChannel, Long createdFrom, Merchant merchant, String dimension, HttpServletRequest request) { private JsonResult loginWithHttpBasic(Long channelId, String appChannel, Long createdFrom, Merchant merchant, String dimension, HttpServletRequest request) {
User user = verificateUserNameAndPassword(request); User user = verificateUserNameAndPassword(request);
if (user == null) { if (user == null) {
......
...@@ -37,4 +37,11 @@ public interface ISessionService { ...@@ -37,4 +37,11 @@ public interface ISessionService {
void persistSession(List<SessionStruct> sessionStructList); void persistSession(List<SessionStruct> sessionStructList);
/**
* 删除会话
* @param user
* @param loginProperties
*/
void deleteSession(User user, LoginProperties loginProperties);
} }
...@@ -251,6 +251,33 @@ public class SessionServiceImpl implements ISessionService { ...@@ -251,6 +251,33 @@ public class SessionServiceImpl implements ISessionService {
} }
} }
@Override
public void deleteSession(User user, LoginProperties loginProperties) {
String sessionId = findSessionIdByUserIdLoginProperties(user.getId(), loginProperties);
SessionStruct sessionStruct = null;
if (null != sessionId) {
if (StringUtils.length(sessionId) == Constants.TOKEN_LENGTH) {
sessionStruct = findSessionBySessionId(sessionId);
if (null != sessionStruct) {
stringRedisTemplate.delete(Constants.Session.USER_SESSION_CACHE + sessionStruct.getSid());
SessionValue values = sessionStruct.getValues();
String key = generateLoginPropertiesKey(values.getUser().getId(), values.getLoginProperties());
stringRedisTemplate.delete(key);
}
} else {
log.warn("真的会有这种情况吗?应该是不存在吧user:{},sessionId:{} ", user, sessionId);
}
}
}
/** /**
* 获取用户的会话缓存Set的Redis-Key * 获取用户的会话缓存Set的Redis-Key
* *
......
...@@ -95,4 +95,9 @@ public interface IUserService { ...@@ -95,4 +95,9 @@ public interface IUserService {
* @return * @return
*/ */
List<User> findByUuidsOrUserIds(List<String> vals,Integer type); List<User> findByUuidsOrUserIds(List<String> vals,Integer type);
/**
* 登出
*/
void logout(Long channelId, String appChannel, Long createdFrom,Merchant merchant, String phoneNo);
} }
...@@ -92,6 +92,7 @@ public class UserServiceImpl implements IUserService, IBaseController { ...@@ -92,6 +92,7 @@ public class UserServiceImpl implements IUserService, IBaseController {
private IContactService contactService; private IContactService contactService;
@Resource @Resource
private ILockIpv4Service lockIpv4Service; private ILockIpv4Service lockIpv4Service;
@Override @Override
// @Cacheable(value = "usercache", key = "'xyqbuser' + #phone", unless = "#result == null", cacheManager = "cacheManager") // @Cacheable(value = "usercache", key = "'xyqbuser' + #phone", unless = "#result == null", cacheManager = "cacheManager")
public User findByPhoneInDb(String phone) { public User findByPhoneInDb(String phone) {
...@@ -258,7 +259,7 @@ public class UserServiceImpl implements IUserService, IBaseController { ...@@ -258,7 +259,7 @@ public class UserServiceImpl implements IUserService, IBaseController {
userHashMapping = userHashMappingRepository.findByPhoneNoMd5ShortAndPhoneNoMd5(value, md5Value); userHashMapping = userHashMappingRepository.findByPhoneNoMd5ShortAndPhoneNoMd5(value, md5Value);
} else if (FindByMd5Enum.IDNO.getType() == type) { } else if (FindByMd5Enum.IDNO.getType() == type) {
List<UserHashMapping> userHashMappings = userHashMappingRepository.findByIdNoMd5AndIdNoMd5Short(md5Value, value); List<UserHashMapping> userHashMappings = userHashMappingRepository.findByIdNoMd5AndIdNoMd5Short(md5Value, value);
if(!CollectionUtils.isEmpty(userHashMappings)){ if (!CollectionUtils.isEmpty(userHashMappings)) {
//如果多个只返回最新的 //如果多个只返回最新的
userHashMapping = userHashMappings.stream().max(Comparator.comparing(UserHashMapping::getId)).get(); userHashMapping = userHashMappings.stream().max(Comparator.comparing(UserHashMapping::getId)).get();
} }
...@@ -403,8 +404,8 @@ public class UserServiceImpl implements IUserService, IBaseController { ...@@ -403,8 +404,8 @@ public class UserServiceImpl implements IUserService, IBaseController {
} }
if (userExtInfo != null) { if (userExtInfo != null) {
userFullResp.setIncomeType(userExtInfo.getIncomeEnum().ordinal()); userFullResp.setIncomeType(userExtInfo.getIncomeEnum().ordinal());
userFullResp.setIncomeRange(userExtInfo.getIncomeRangeEnum()== null? userFullResp.setIncomeRange(userExtInfo.getIncomeRangeEnum() == null ?
IncomeRangeEnum.UNKNOWN.ordinal(): IncomeRangeEnum.UNKNOWN.ordinal() :
userExtInfo.getIncomeRangeEnum().ordinal()); userExtInfo.getIncomeRangeEnum().ordinal());
userFullResp.setOccupation(userExtInfo.getOccupationEnum().ordinal()); userFullResp.setOccupation(userExtInfo.getOccupationEnum().ordinal());
userFullResp.setEducation(userExtInfo.getEducationEnum().ordinal()); userFullResp.setEducation(userExtInfo.getEducationEnum().ordinal());
...@@ -456,4 +457,21 @@ public class UserServiceImpl implements IUserService, IBaseController { ...@@ -456,4 +457,21 @@ public class UserServiceImpl implements IUserService, IBaseController {
return userRepository.findByUuidIn(vals); return userRepository.findByUuidIn(vals);
} }
} }
@Override
public void logout(Long channelId, String appChannel, Long createdFrom, Merchant merchant, String phoneNo) {
User user = findByPhoneWithCache(phoneNo);
if (null == user) {
throw new UserNotExistException("用户未找到");
}
LoginProperties properties = LoginProperties.builder()
.channelId(channelId)
.createdFrom(createdFrom)
.appChannel(appChannel)
.merchantId(merchant.getId())
.merchantName(merchant.getName())
.build();
sessionService.deleteSession(user, properties);
}
} }
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