名字重复bug修复

This commit is contained in:
zhongzb 2023-05-10 14:07:25 +08:00
parent 7f2248cbf5
commit 4c513094ab
2 changed files with 21 additions and 4 deletions

View File

@ -36,7 +36,7 @@ public class UserRegisterListener {
@Async
@EventListener(classes = UserRegisterEvent.class)
public void sendBadge(UserOnlineEvent event) {
public void sendBadge(UserRegisterEvent event) {
User user = event.getUser();
int count = userDao.count();
if (count <= 10) {

View File

@ -1,6 +1,7 @@
package com.abin.mallchat.custom.user.service;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
import com.abin.mallchat.common.common.config.ThreadPoolConfig;
import com.abin.mallchat.common.user.dao.UserDao;
@ -17,6 +18,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Lazy;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Service;
@ -70,7 +72,7 @@ public class WxMsgService {
//保存openid和场景code的关系后续才能通知到前端
OPENID_EVENT_CODE_MAP.put(fromUser, eventKey);
//授权流程,给用户发送授权消息并且异步通知前端扫码成功
threadPoolTaskExecutor.execute(()->webSocketService.scanSuccess(eventKey));
threadPoolTaskExecutor.execute(() -> webSocketService.scanSuccess(eventKey));
String skipUrl = String.format(URL, wxMpService.getWxMpConfigStorage().getAppId(), URLEncoder.encode(callback + "/wx/portal/public/callBack"));
WxMpXmlOutMessage.TEXT().build();
return new TextBuilder().build("请点击链接授权:<a href=\"" + skipUrl + "\">登录</a>", wxMpXmlMessage, wxMpService);
@ -88,14 +90,29 @@ public class WxMsgService {
*/
public void authorize(WxOAuth2UserInfo userInfo) {
User user = userDao.getByOpenId(userInfo.getOpenid());
User update = UserAdapter.buildAuthorizeUser(user.getId(), userInfo);
//更新用户信息
userDao.updateById(update);
fillUserInfo(user.getId(), userInfo);
//触发用户登录成功操作
Integer eventKey = OPENID_EVENT_CODE_MAP.get(userInfo.getOpenid());
login(user.getId(), eventKey);
}
private void fillUserInfo(Long uid, WxOAuth2UserInfo userInfo) {
User update = UserAdapter.buildAuthorizeUser(uid, userInfo);
for (int i = 0; i < 5; i++) {
try {
userDao.updateById(update);
update.setName("名字重置" + RandomUtil.randomInt(100000));
return;
} catch (DuplicateKeyException e) {
log.info("fill userInfo duplicate uid:{},info:{}", uid, userInfo);
} catch (Exception e) {
log.error("fill userInfo fail uid:{},info:{}", uid, userInfo);
}
}
}
private void login(Long uid, Integer eventKey) {
User user = userDao.getById(uid);
//调用用户登录模块