Commit 8952b405 authored by 技术部-任文超's avatar 技术部-任文超

1、重复关联跳过写数据库动作

2、创建session对旧session容错(有合法token但不一定能获取到session,可以使因为清缓存,或session过期)
3、取消删除微信授权信息的维护动作,改为解除关联
parent 26008324
......@@ -21,9 +21,16 @@ public interface IWeChatUserRepository extends JpaRepository<WechatUserInfo, Lon
long countByOpenId(String openId);
/**
* 解除关联关系 -- 当前用户的已关联微信
* 注:应用服务的JDBC数据源连接,无delete权限
* @param userId
* @return
*/
@Transactional
@Modifying
int removeByUserId(Long userId);
@Query(value = "update wechat_userinfo set user_id=null,phone_no='*' where user_id=?2", nativeQuery = true)
int dissociateByUserId(Long userId);
/**
* 关联用户
......
......@@ -58,7 +58,6 @@ public class SessionServiceImpl implements ISessionService {
*/
@Override
public AuthBean createSession(Long channelId, Long createdFrom, String appChannel, User user, Merchant merchant) {
AuthBean authBean = new AuthBean();
LoginProperties properties = new LoginProperties();
properties.setAppChannel(appChannel);
if (null != merchant) {
......@@ -68,20 +67,20 @@ public class SessionServiceImpl implements ISessionService {
properties.setCreatedFrom(createdFrom);
//找到用户
String sessionId = findSessionIdByUserIdLoginProperties(user.getId(), properties);
// String sessionId = sessionService.findSessionIdByUserIdAndMerchant(user.getId(), merchant);
SessionStruct sessionStruct = null;
if (org.apache.commons.lang.StringUtils.isNotEmpty(sessionId)) {
SessionStruct sessionStruct = findSessionBySessionId(sessionId);
sessionStruct = findSessionBySessionId(sessionId);
}
if (Objects.nonNull(sessionStruct)) {
sessionStruct.setAttribute("channelId", String.valueOf(channelId));
sessionStruct.setAttribute("createdFrom", String.valueOf(createdFrom));
sessionStruct.setAttribute("appChannel", String.valueOf(appChannel));
sessionStruct.getValues().setLoginProperties(properties);
authBean.setPhoneNo(user.getPhoneNo());
authBean.setToken(sessionStruct.getSid());
persistSession(sessionStruct.getSid(), sessionStruct.getValues());
log.info("用户登录成功, loginFrom:{}, phoneNo:{},appChannel:{},channelId:{}", createdFrom, user.getPhoneNo(), appChannel,channelId);
return authBean;
}else{
sessionStruct = createSessionAndPersist(user, properties);
}
SessionStruct sessionStruct = createSessionAndPersist(user, properties);
AuthBean authBean = new AuthBean();
authBean.setPhoneNo(user.getPhoneNo());
authBean.setToken(sessionStruct.getSid());
log.info("用户登录成功, loginFrom:{}, phoneNo:{},appChannel:{},channelId:{}", createdFrom, user.getPhoneNo(), appChannel,channelId);
......
......@@ -147,6 +147,10 @@ public class WechatServiceImpl implements IWechatService {
}
// Old - 当前openId的WechatUserInfo
WechatUserInfo wechatUserInfo = weChatUserRepository.findByOpenId(openId);
if(Objects.nonNull(wechatUserInfo) && Objects.equals(userId, wechatUserInfo.getUserId()) && Objects.equals(openId, wechatUserInfo.getOpenId())){
log.info("微信关联成功:重复关联:跳过:[service]:userId:{},phoneNo:{},openId:{}", userId, phoneNo, openId);
return 1;
}
// 强制解除关联
int dissociate = weChatUserRepository.dissociateUser(openId, userId);
if(dissociate < 1){
......@@ -200,6 +204,6 @@ public class WechatServiceImpl implements IWechatService {
@Override
public int forbiddenUserWeChat(Long userId) {
return weChatUserRepository.removeByUserId(userId);
return weChatUserRepository.dissociateByUserId(userId);
}
}
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