用户详情-判断封禁状态

This commit is contained in:
khalil
2025-05-21 11:15:45 +08:00
parent 06e791fbfc
commit 8a04fa26c0
2 changed files with 22 additions and 7 deletions

View File

@@ -354,7 +354,7 @@ public class AccountBlockService extends ServiceImpl<AccountBlockMapper,AccountB
AccountBlock accountBlock = new AccountBlock();
accountBlock.setBlockValue(blockValue);
accountBlock.setBlockType(blockType);
if (blockType.intValue() == BlockTypeEnum.BLOCK_ACCOUNT.getValue()) {
if (blockType == BlockTypeEnum.BLOCK_ACCOUNT.getValue()) {
Users erBanNo = usersBaseService.getUsersByErBanNo(Long.parseLong(blockValue));
if (erBanNo != null) {
accountBlock.setBlockUid(erBanNo.getUid());
@@ -403,12 +403,25 @@ public class AccountBlockService extends ServiceImpl<AccountBlockMapper,AccountB
return banAccount;
}
/**
* 判断用户是否被封禁
* @param uid
* @return
*/
public boolean checkAccountBlock(Long uid){
boolean banAccount = false;
int blockType = BlockTypeEnum.BLOCK_ACCOUNT.getValue();
String accountCache = jedisService.hget(RedisKey.block_account.getKey(Integer.toString(blockType)), String.valueOf(uid));
if (!StringUtils.isEmpty(accountCache)) {
banAccount = checkAccountBlock(accountCache);
}
return banAccount;
}
private Boolean checkAccountBlock(String accountBlockCache){
AccountBlock accountBlock = gson.fromJson(accountBlockCache, AccountBlock.class);
boolean betweenDate = DateTimeUtil.isBetweenDate(Calendar.getInstance().getTime(), accountBlock.getBlockStartTime(), accountBlock.getBlockEndTime());
if (betweenDate && accountBlock.getBlockStatus() != null && BlockStatusEnum.BLOCKING.getValue() == accountBlock.getBlockStatus().byteValue()) {
return true;
}
return false;
return betweenDate && accountBlock.getBlockStatus() != null
&& BlockStatusEnum.BLOCKING.getValue() == accountBlock.getBlockStatus().byteValue();
}
}

View File

@@ -69,8 +69,6 @@ public class UserDetailsService extends BaseService {
@Autowired
private PrivatePhotoService privatePhotoService;
@Autowired
private SendSysMsgService sendSysMsgService;
@Autowired
private UserVisitRecordService userVisitRecordService;
@Autowired
private AccountBlockService accountBlockService;
@@ -110,6 +108,10 @@ public class UserDetailsService extends BaseService {
public UserDetailsVo getUserDetails(Long selfUid, Long uid) {
Users me = usersService.getNotNullUsersByUid(selfUid);
if (!selfUid.equals(uid) && accountBlockService.checkAccountBlock(uid)){
throw new ServiceException(BusiStatus.THE_USER_HAS_BEEN_BANNED_BY_THE_SYSTEM);
}
//TODO 此处最好做缓存,可能存在性能问题
UserDetailsVo userDetailsVo = new UserDetailsVo();
UserVo userVo = usersService.getCacheUserVoByUid(uid);