优化代码
This commit is contained in:
parent
f5780e0b6d
commit
218fa38483
@ -47,6 +47,7 @@ public class Constant {
|
||||
public static final Integer USER_BANNER = 1;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 评论状态
|
||||
* 0 下架 1正常
|
||||
@ -59,6 +60,15 @@ public class Constant {
|
||||
* 手机验证码长度
|
||||
*/
|
||||
public static final Integer SMS_SIZE = 6;
|
||||
|
||||
/**
|
||||
* 手机验证码前缀
|
||||
*/
|
||||
public static final String SMS_PREFIX = "code_";
|
||||
|
||||
/**
|
||||
* 注册账户默认分配头像
|
||||
*/
|
||||
public static final String DEAULT_HEAD = "http://pic.linfeng.tech/test/20220126/4515fc2cbed74d0b9163d35a12bd4c3b.png";
|
||||
|
||||
/**
|
||||
|
@ -10,4 +10,8 @@ public class RedisKeys {
|
||||
public static String getSysConfigKey(String key){
|
||||
return "sys:config:" + key;
|
||||
}
|
||||
|
||||
public static String getUserKey(Integer userId){
|
||||
return "userId:" + userId;
|
||||
}
|
||||
}
|
||||
|
@ -105,7 +105,7 @@ public class AppUserServiceImpl extends ServiceImpl<AppUserDao, AppUserEntity> i
|
||||
throw new LinfengException("该用户已被禁用");
|
||||
}
|
||||
this.lambdaUpdate()
|
||||
.set(AppUserEntity::getStatus, 1)
|
||||
.set(AppUserEntity::getStatus, Constant.USER_BANNER)
|
||||
.set(AppUserEntity::getUpdateTime,new Date())
|
||||
.eq(AppUserEntity::getUid, id)
|
||||
.update();
|
||||
@ -119,7 +119,7 @@ public class AppUserServiceImpl extends ServiceImpl<AppUserDao, AppUserEntity> i
|
||||
throw new LinfengException("该用户已解除禁用");
|
||||
}
|
||||
boolean update = this.lambdaUpdate()
|
||||
.set(AppUserEntity::getStatus, 0)
|
||||
.set(AppUserEntity::getStatus, Constant.USER_NORMAL)
|
||||
.set(AppUserEntity::getUpdateTime,new Date())
|
||||
.eq(AppUserEntity::getUid, id)
|
||||
.update();
|
||||
@ -153,7 +153,7 @@ public class AppUserServiceImpl extends ServiceImpl<AppUserDao, AppUserEntity> i
|
||||
@Override
|
||||
public Integer smsLogin(SmsLoginForm form, HttpServletRequest request) {
|
||||
AppUserEntity appUserEntity = this.lambdaQuery().eq(AppUserEntity::getMobile, form.getMobile()).one();
|
||||
String codeKey = "code_" + form.getMobile();
|
||||
String codeKey = Constant.SMS_PREFIX + form.getMobile();
|
||||
String s = redisUtils.get(codeKey);
|
||||
if (io.linfeng.common.utils.ObjectUtil.isEmpty(s)) {
|
||||
throw new LinfengException("请先发送验证码");
|
||||
@ -163,7 +163,7 @@ public class AppUserServiceImpl extends ServiceImpl<AppUserDao, AppUserEntity> i
|
||||
}
|
||||
if (ObjectUtil.isNotNull(appUserEntity)) {
|
||||
//登录
|
||||
if (appUserEntity.getStatus() == 1) {
|
||||
if (appUserEntity.getStatus().equals(Constant.USER_BANNER)) {
|
||||
throw new LinfengException("该账户已被禁用");
|
||||
}
|
||||
return appUserEntity.getUid();
|
||||
@ -196,7 +196,7 @@ public class AppUserServiceImpl extends ServiceImpl<AppUserDao, AppUserEntity> i
|
||||
@Override
|
||||
public String sendSmsCode(SendCodeForm param) {
|
||||
String code = RandomUtil.randomNumbers(6);
|
||||
String codeKey = "code_" + param.getMobile();
|
||||
String codeKey = Constant.SMS_PREFIX + param.getMobile();
|
||||
String s = redisUtils.get(codeKey);
|
||||
if (ObjectUtil.isNotNull(s)) {
|
||||
return s;
|
||||
@ -229,7 +229,7 @@ public class AppUserServiceImpl extends ServiceImpl<AppUserDao, AppUserEntity> i
|
||||
user.setGender(appUserUpdateForm.getGender());
|
||||
}
|
||||
baseMapper.updateById(user);
|
||||
redisUtils.delete("userId:" + user.getUid());
|
||||
redisUtils.delete(RedisKeys.getUserKey(user.getUid()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -326,7 +326,7 @@ public class AppUserServiceImpl extends ServiceImpl<AppUserDao, AppUserEntity> i
|
||||
//根据openId获取数据库信息 判断用户是否登录
|
||||
AppUserEntity user = this.lambdaQuery().eq(AppUserEntity::getOpenid, openId).one();
|
||||
if (ObjectUtil.isNotNull(user)) {
|
||||
if (user.getStatus() == 1) {
|
||||
if (user.getStatus() .equals(Constant.USER_BANNER)) {
|
||||
throw new LinfengException("该账户已被禁用");
|
||||
}
|
||||
//其他业务todo
|
||||
|
@ -12,6 +12,7 @@
|
||||
package io.linfeng.modules.app.utils;
|
||||
|
||||
import io.jsonwebtoken.Claims;
|
||||
import io.linfeng.common.utils.RedisKeys;
|
||||
import io.linfeng.common.utils.RedisUtils;
|
||||
import io.linfeng.modules.admin.entity.AppUserEntity;
|
||||
import io.linfeng.modules.admin.service.AppUserService;
|
||||
@ -58,13 +59,13 @@ public class LocalUser {
|
||||
return null;
|
||||
}
|
||||
long userId = Long.parseLong(claims.getSubject());
|
||||
AppUserEntity userInfo = redisUtils.get("userId:" + userId, AppUserEntity.class);
|
||||
AppUserEntity userInfo = redisUtils.get(RedisKeys.getUserKey((int)userId), AppUserEntity.class);
|
||||
if (userInfo != null) {
|
||||
return userInfo;
|
||||
}
|
||||
//重新获取用户信息
|
||||
AppUserEntity user = userService.getById(userId);
|
||||
redisUtils.set("userId:" + userId, user, 7200);
|
||||
redisUtils.set(RedisKeys.getUserKey((int)userId), user, 7200);
|
||||
return user;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user