mirror of
https://github.com/zongzibinbin/MallChat.git
synced 2026-03-14 06:03:42 +08:00
用户名优化
This commit is contained in:
@@ -12,7 +12,7 @@ import lombok.Getter;
|
||||
@Getter
|
||||
public enum BusinessErrorEnum implements ErrorEnum {
|
||||
//==================================common==================================
|
||||
BUSINESS_ERROR(1001, "{}"),
|
||||
BUSINESS_ERROR(1001, "{0}"),
|
||||
//==================================user==================================
|
||||
//==================================chat==================================
|
||||
SYSTEM_ERROR(1001, "系统出小差了,请稍后再试哦~~"),
|
||||
|
||||
@@ -7,6 +7,7 @@ import com.abin.mallchat.common.common.exception.ErrorEnum;
|
||||
import com.abin.mallchat.common.user.domain.entity.UserBackpack;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
@@ -71,7 +72,7 @@ public class AssertUtil {
|
||||
if (Objects.isNull(errorEnum)) {
|
||||
errorEnum = BusinessErrorEnum.BUSINESS_ERROR;
|
||||
}
|
||||
throw new BusinessException(errorEnum.getErrorCode(), String.format(errorEnum.getErrorMsg(), arg));
|
||||
throw new BusinessException(errorEnum.getErrorCode(), MessageFormat.format(errorEnum.getErrorMsg(), arg));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -40,9 +40,9 @@ public class UserBackpackDao extends ServiceImpl<UserBackpackMapper, UserBackpac
|
||||
return getOne(wrapper);
|
||||
}
|
||||
|
||||
public boolean invalidItem(Long itemId) {
|
||||
public boolean invalidItem(Long id) {
|
||||
UserBackpack update = new UserBackpack();
|
||||
update.setItemId(itemId);
|
||||
update.setId(id);
|
||||
update.setStatus(YesOrNoEnum.YES.getStatus());
|
||||
return updateById(update);
|
||||
}
|
||||
|
||||
@@ -37,4 +37,8 @@ public class UserDao extends ServiceImpl<UserMapper, User> {
|
||||
update.setItemId(badgeId);
|
||||
updateById(update);
|
||||
}
|
||||
|
||||
public User getByName(String name) {
|
||||
return lambdaQuery().eq(User::getName, name).one();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,11 @@ spring:
|
||||
username: ${mallchat.mysql.username}
|
||||
password: ${mallchat.mysql.password}
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
hikari:
|
||||
minimum-idle: 3
|
||||
maximum-pool-size: 10
|
||||
max-lifetime: 30000 #不能小于30秒,否则默认回到1800秒
|
||||
connection-test-query: SELECT 1
|
||||
mvc:
|
||||
pathmatch:
|
||||
matching-strategy: ANT_PATH_MATCHER
|
||||
|
||||
@@ -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