Commit 14a8f728 authored by 王亮's avatar 王亮

batch query user.

parent 1d5026c7
......@@ -60,7 +60,7 @@ public class UserApiV2Controller {
user = userRepository.findByUuidAndTenantId(userInfoReq.getUuid(), sessionStruct.getTenantId());
}
if(StringUtils.isEmpty(userInfoReq.getPhoneNo())){
if(StringUtils.isNotEmpty(userInfoReq.getPhoneNo())){
user = userRepository.findByPhoneNoAndTenantId(userInfoReq.getPhoneNo(), sessionStruct.getTenantId());
}
......@@ -72,7 +72,7 @@ public class UserApiV2Controller {
user = userRepository.findByIdAndTenantId(wechatUserInfo.getUserId(), sessionStruct.getTenantId());
}
if(StringUtils.isNotEmpty(userInfoReq.getAppId()) && StringUtils.isNotEmpty(userInfoReq.getUuid())){
if(StringUtils.isNotEmpty(userInfoReq.getAppId()) && StringUtils.isNotEmpty(userInfoReq.getUnionId())){
WechatUserInfo wechatUserInfo = wechatService.findByUnionIdAndAppIdAndTenantId(userInfoReq.getUnionId(), userInfoReq.getAppId(), sessionStruct.getTenantId());
if (wechatUserInfo == null || wechatUserInfo.getUserId() == null) {
throw new BizException(BizExceptionEnum.UN_EXIT_USER);
......@@ -95,12 +95,12 @@ public class UserApiV2Controller {
* @return JsonResult<List < User>>
* @see <a href="http://yapi.quantgroups.com/project/17/interface/api/65734">批量查询用户信息</a>
*/
@PostMapping("batchInfo")
@PostMapping("/batchInfo")
public JsonResult<List<User>> batchInfo(@RequestBody BatchInfoReq batchInfoReq) {
SessionStruct sessionStruct = XyqbSessionContextHolder.getXSession();
List<User> userList = null;
//1、校验
if (CollectionUtils.isEmpty(batchInfoReq.getUserids())
if (CollectionUtils.isEmpty(batchInfoReq.getUserIds())
&& CollectionUtils.isEmpty(batchInfoReq.getUuids())
&& CollectionUtils.isEmpty(batchInfoReq.getPhoneNos())
&& (StringUtils.isEmpty(batchInfoReq.getAppId()) && CollectionUtils.isEmpty(batchInfoReq.getOpenIds()))
......@@ -109,8 +109,8 @@ public class UserApiV2Controller {
}
//2、查询
if (CollectionUtils.isNotEmpty(batchInfoReq.getUserids())) {
userList = userRepository.findByIdInAndTenantId(batchInfoReq.getUserids(), sessionStruct.getTenantId());
if (CollectionUtils.isNotEmpty(batchInfoReq.getUserIds())) {
userList = userRepository.findByIdInAndTenantId(batchInfoReq.getUserIds(), sessionStruct.getTenantId());
}
if( CollectionUtils.isNotEmpty(batchInfoReq.getUuids())){
......@@ -131,8 +131,8 @@ public class UserApiV2Controller {
userList = userRepository.findByIdInAndTenantId(userIds, sessionStruct.getTenantId());
}
if(StringUtils.isNotEmpty(batchInfoReq.getAppId()) && CollectionUtils.isNotEmpty(batchInfoReq.getUuids())){
List<WechatUserInfo> wechatUserInfo = wechatService.findUuidsAndOpenIdAndTenantId(batchInfoReq.getOpenIds(), batchInfoReq.getAppId(), sessionStruct.getTenantId());
if(StringUtils.isNotEmpty(batchInfoReq.getAppId()) && CollectionUtils.isNotEmpty(batchInfoReq.getUnionIds())){
List<WechatUserInfo> wechatUserInfo = wechatService.findUnionIdsAndOpenIdAndTenantId(batchInfoReq.getUnionIds(), batchInfoReq.getAppId(), sessionStruct.getTenantId());
List<Long> userIds = wechatUserInfo.stream().map(WechatUserInfo::getUserId).collect(Collectors.toList());;
if (CollectionUtils.isEmpty(wechatUserInfo) || CollectionUtils.isEmpty(userIds)) {
throw new BizException(BizExceptionEnum.UN_EXIT_USER);
......
......@@ -13,7 +13,7 @@ public class BatchInfoReq {
/**
* 用户id
*/
private List<Long> userids;
private List<Long> userIds;
/**
* 手机号码
*/
......
......@@ -9,12 +9,16 @@ import cn.quantgroup.xyqb.remote.StmsRemoteService;
import cn.quantgroup.xyqb.service.session.ISessionService;
import cn.quantgroup.xyqb.session.XyqbSessionContextHolder;
import cn.quantgroup.xyqb.util.StringUtils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
public class InnerInterceptor implements HandlerInterceptor {
private final ISessionService sessionService;
......@@ -46,29 +50,30 @@ public class InnerInterceptor implements HandlerInterceptor {
if (sessionStruct == null) {
OauthResult oauthResult = stmsRemoteService.checkToken(stmsToken);
if (oauthResult != null && 2000 == oauthResult.getCode()) {
OauthResult permissionResult = stmsRemoteService.checkPermission(stmsToken,
request.getRequestURI(), tenantId);
if (permissionResult != null && 2000 == permissionResult.getCode()) {
JSONObject jsonObject = JSONObject.parseObject((String)permissionResult.getData());
String userId = jsonObject.getString("id");
String userName = jsonObject.getString("name");
sessionStruct = XyqbSessionContextHolder.initSTMSSession(stmsToken,userId,userName);
LinkedHashMap<String,Object> linkedHashMap = (LinkedHashMap<String, Object>) oauthResult.getData();
String userId = String.valueOf(linkedHashMap.get("id"));
String userName = String.valueOf(linkedHashMap.get("name"));
sessionStruct = XyqbSessionContextHolder.initSTMSSession(stmsToken, userId, userName);
sessionService.persistSession(sessionStruct.getSid(), sessionStruct.getValues(), sessionStruct.getTenantId());
} else {
throw new BizException(BizExceptionEnum.UN_PERMISSION_STMS);
}
} else {
throw new BizException(BizExceptionEnum.UN_VALID_STMS_TOKEN);
}
} else {
//session续期
sessionService.persistSession(sessionStruct.getSid(), sessionStruct.getValues(), sessionStruct.getTenantId());
}
//校验接口权限
OauthResult permissionResult = stmsRemoteService.checkPermission(stmsToken,
request.getRequestURI(), tenantId);
if (permissionResult != null && 2000 == permissionResult.getCode()) {
return true;
} else {
throw new BizException(BizExceptionEnum.UN_VALID_STMS_TOKEN);
}
}
@Override
......
......@@ -38,10 +38,24 @@ public class LoginProperties {
//租户ID
private Integer tenantId;
private String stmsUserId;
private String stmsUserName;
public LoginProperties(int action, Long createdFrom, Integer tenantId) {
this.action = action;
this.createdFrom = createdFrom;
this.tenantId = tenantId;
}
public LoginProperties(String dimension, int action, Long channelId, Long createdFrom, String appChannel, Long merchantId, String merchantName, Integer tenantId) {
this.dimension = dimension;
this.action = action;
this.channelId = channelId;
this.createdFrom = createdFrom;
this.appChannel = appChannel;
this.merchantId = merchantId;
this.merchantName = merchantName;
this.tenantId = tenantId;
}
}
......@@ -182,6 +182,16 @@ public class SessionServiceImpl implements ISessionService {
if (sessionValue == null) {
sessionValue = new SessionValue();
}
if(sessionValue.getLoginProperties()==null){
sessionValue.setLoginProperties(new LoginProperties());
}
LoginProperties loginProperties= sessionValue.getLoginProperties();
loginProperties.setTenantId(tenantId);
sessionValue.setLoginProperties(loginProperties);
sessionValue.setLastAccessTime(current);
String json = JSON.toJSONString(sessionValue);
stringRedisTemplate.opsForValue().set(Constants.Session.USER_SESSION_CACHE + token, json,
......
......@@ -15,7 +15,7 @@ public interface IWechatService {
WechatUserInfo findWechatUserInfoFromDb(String openId,String appId,Integer tenantId);
List<WechatUserInfo> findWechatUserInfoFromDb(List<String> openId,String appId,Integer tenantId);
List<WechatUserInfo> findUuidsAndOpenIdAndTenantId(List<String> uuids,String appId,Integer tenantId);
List<WechatUserInfo> findUnionIdsAndOpenIdAndTenantId(List<String> uuids,String appId,Integer tenantId);
WechatUserInfo findByUnionIdAndAppIdAndTenantId(String unionId,String appId,Integer tenantId);
......
......@@ -121,8 +121,8 @@ public class WechatServiceImpl implements IWechatService {
return weChatUserRepository.findByOpenIdInAndAppIdAndTenantId(openId,appId,tenantId);
}
public List<WechatUserInfo> findUuidsAndOpenIdAndTenantId(List<String> uuids, String appId, Integer tenantId){
return weChatUserRepository.findByUnionIdInAndAppIdAndTenantId(uuids,appId,tenantId);
public List<WechatUserInfo> findUnionIdsAndOpenIdAndTenantId(List<String> unionIds, String appId, Integer tenantId){
return weChatUserRepository.findByUnionIdInAndAppIdAndTenantId(unionIds,appId,tenantId);
}
......
package cn.quantgroup.xyqb.session;
import cn.quantgroup.xyqb.Constants;
import cn.quantgroup.xyqb.model.LoginProperties;
import cn.quantgroup.xyqb.model.session.SessionStruct;
import cn.quantgroup.xyqb.model.session.SessionValue;
import cn.quantgroup.xyqb.util.IpUtil;
......@@ -34,11 +35,16 @@ public class XyqbSessionContextHolder {
sessionStruct = getXSessionFromRedis();
threadSession.set(sessionStruct);
}
if(sessionStruct!=null && sessionStruct.getValues()!=null && sessionStruct.getValues().getLoginProperties()!=null){
sessionStruct.setStmsUserId(sessionStruct.getValues().getLoginProperties().getStmsUserId());
sessionStruct.setStmsUserName(sessionStruct.getValues().getLoginProperties().getStmsUserName());
}
return sessionStruct;
}
public static SessionStruct initXSession() {
SessionStruct sessionStruct =threadSession.get();
SessionStruct sessionStruct = threadSession.get();
if (sessionStruct == null) {
sessionStruct = new SessionStruct();
......@@ -58,7 +64,7 @@ public class XyqbSessionContextHolder {
sessionStruct.setScDeviceId(request.getHeader("scDeviceId"));
sessionStruct.setTerminal(request.getHeader("terminal"));
threadSession.set(sessionStruct);
}else{
} else {
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
//如果是极验,那赋值
......@@ -70,7 +76,7 @@ public class XyqbSessionContextHolder {
return sessionStruct;
}
public static SessionStruct initSTMSSession(String token,String userId, String userName) {
public static SessionStruct initSTMSSession(String token, String userId, String userName) {
SessionStruct sessionStruct = threadSession.get();
if (sessionStruct == null) {
......@@ -92,6 +98,16 @@ public class XyqbSessionContextHolder {
sessionStruct.setStmsUserId(userId);
sessionStruct.setStmsUserName(userName);
}
SessionValue sessionValue = sessionStruct.getValues();
if (sessionValue == null) {
sessionValue = new SessionValue();
LoginProperties loginProperties = new LoginProperties();
loginProperties.setStmsUserId(userId);
loginProperties.setStmsUserName(userName);
sessionValue.setLoginProperties(loginProperties);
}
sessionStruct.setValues(sessionValue);
return sessionStruct;
}
......
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