mirror of
https://github.com/zongzibinbin/MallChat.git
synced 2026-03-14 14:13:42 +08:00
用户名优化
This commit is contained in:
@@ -102,15 +102,14 @@ public class WxMsgService {
|
||||
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);
|
||||
}
|
||||
update.setName("名字重置" + RandomUtil.randomInt(100000));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void login(Long uid, Integer eventKey) {
|
||||
@@ -119,6 +118,5 @@ public class WxMsgService {
|
||||
String token = loginService.login(uid);
|
||||
//推送前端登录成功
|
||||
webSocketService.scanLoginSuccess(eventKey, user, token);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.abin.mallchat.custom.user.service.adapter;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import com.abin.mallchat.common.common.domain.enums.YesOrNoEnum;
|
||||
import com.abin.mallchat.common.user.domain.entity.ItemConfig;
|
||||
import com.abin.mallchat.common.user.domain.entity.User;
|
||||
@@ -37,6 +38,11 @@ public class UserAdapter {
|
||||
user.setAvatar(userInfo.getHeadImgUrl());
|
||||
user.setName(userInfo.getNickname());
|
||||
user.setSex(userInfo.getSex());
|
||||
if(userInfo.getNickname().length()>6){
|
||||
user.setName("名字过长"+RandomUtil.randomInt(100000));
|
||||
}else {
|
||||
user.setName(userInfo.getNickname());
|
||||
}
|
||||
return user;
|
||||
}
|
||||
|
||||
|
||||
@@ -62,21 +62,26 @@ public class UserServiceImpl implements UserService {
|
||||
@Override
|
||||
@Transactional
|
||||
public void modifyName(Long uid, ModifyNameReq req) {
|
||||
//判断名字是不是重复
|
||||
User oldUser = userDao.getByName(req.getName());
|
||||
AssertUtil.isEmpty(oldUser,"名字已经被抢占了,请换一个哦~~");
|
||||
//判断改名卡够不够
|
||||
UserBackpack firstValidItem = userBackpackDao.getFirstValidItem(uid, ItemEnum.MODIFY_NAME_CARD.getId());
|
||||
AssertUtil.isNotEmpty(firstValidItem, "改名次数不够了,等后续活动送改名卡哦");
|
||||
//使用改名卡
|
||||
boolean useSuccess = userBackpackDao.invalidItem(firstValidItem.getItemId());
|
||||
boolean useSuccess = userBackpackDao.invalidItem(firstValidItem.getId());
|
||||
if (useSuccess) {//用乐观锁,就不用分布式锁了
|
||||
//改名
|
||||
userDao.modifyName(uid, req.getName());
|
||||
//删除缓存
|
||||
userCache.delUserInfo(uid);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BadgeResp> badges(Long uid) {
|
||||
//查询所有徽章
|
||||
List<ItemConfig> itemConfigs =itemCache.getByType(ItemTypeEnum.BADGE.getType());
|
||||
List<ItemConfig> itemConfigs = itemCache.getByType(ItemTypeEnum.BADGE.getType());
|
||||
//查询用户拥有的徽章
|
||||
List<UserBackpack> backpacks = userBackpackDao.getByItemIds(uid, itemConfigs.stream().map(ItemConfig::getId).collect(Collectors.toList()));
|
||||
//查询用户当前佩戴的标签
|
||||
@@ -101,6 +106,6 @@ public class UserServiceImpl implements UserService {
|
||||
public void register(String openId) {
|
||||
User insert = User.builder().openId(openId).build();
|
||||
userDao.save(insert);
|
||||
applicationEventPublisher.publishEvent(new UserRegisterEvent(this,insert));
|
||||
applicationEventPublisher.publishEvent(new UserRegisterEvent(this, insert));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user