封禁优化
This commit is contained in:
@@ -5,8 +5,11 @@ import com.accompany.business.service.account.AccountBlockService;
|
||||
import com.accompany.common.status.BusiStatus;
|
||||
import com.accompany.common.utils.DateTimeUtil;
|
||||
import com.accompany.core.constant.BlockStatusEnum;
|
||||
import com.accompany.core.constant.BlockTypeEnum;
|
||||
import com.accompany.core.exception.AdminServiceException;
|
||||
import com.accompany.core.model.AccountBlock;
|
||||
import com.accompany.core.model.Users;
|
||||
import com.accompany.core.service.user.UsersBaseService;
|
||||
import com.accompany.core.util.StringUtils;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
@@ -14,10 +17,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
|
||||
/**
|
||||
@@ -31,9 +31,13 @@ public class AccountBlockAdminService extends BaseService {
|
||||
@Autowired
|
||||
private AccountBlockService accountBlockService;
|
||||
|
||||
@Autowired
|
||||
private UsersBaseService usersBaseService;
|
||||
|
||||
|
||||
/**
|
||||
* 分页查询封禁记录
|
||||
*
|
||||
* @param pageSize
|
||||
* @param pageNum
|
||||
* @param type
|
||||
@@ -42,18 +46,16 @@ public class AccountBlockAdminService extends BaseService {
|
||||
*/
|
||||
public IPage<AccountBlock> getAccountBlockList(Integer pageSize, Integer pageNum, Integer type, String blockValue) {
|
||||
QueryWrapper<AccountBlock> wrapper = new QueryWrapper<>();
|
||||
wrapper.lambda().eq(type != null && type > 0, AccountBlock::getBlockType,type)
|
||||
.like(StringUtils.isNotBlank(blockValue),AccountBlock::getBlockValue,blockValue)
|
||||
// .eq(AccountBlock::getBlockStatus,BlockStatusEnum.BLOCKING.getValue())
|
||||
// .le(AccountBlock::getBlockStartTime,now)
|
||||
// .ge(AccountBlock::getBlockEndTime,now)
|
||||
wrapper.lambda().eq(type != null && type > 0, AccountBlock::getBlockType, type)
|
||||
.like(StringUtils.isNotBlank(blockValue), AccountBlock::getBlockValue, blockValue)
|
||||
.orderByDesc(AccountBlock::getCreateTime);
|
||||
IPage<AccountBlock> page = new Page<>(pageNum,pageSize);
|
||||
return accountBlockService.page(page,wrapper);
|
||||
IPage<AccountBlock> page = new Page<>(pageNum, pageSize);
|
||||
return accountBlockService.page(page, wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量增加封禁账号
|
||||
*
|
||||
* @param blockValueList
|
||||
* @param blockType
|
||||
* @param startBlockTime
|
||||
@@ -65,45 +67,73 @@ public class AccountBlockAdminService extends BaseService {
|
||||
* @return
|
||||
*/
|
||||
public Boolean batchSaveAccountBlock(List<String> blockValueList, Integer blockType, String startBlockTime,
|
||||
String endBlockTime, String blockDesc, Boolean wallStatus, String adminName, String remark) throws Exception{
|
||||
if (null == wallStatus){
|
||||
wallStatus = Boolean.TRUE;
|
||||
String endBlockTime, String blockDesc, Boolean wallStatus, String adminName, String remark,
|
||||
String blockImgUrl, Byte blockDevice) throws Exception {
|
||||
List<AccountBlock> list = new ArrayList<>();
|
||||
blockValueList.stream().forEach(blockValue -> {
|
||||
AccountBlock accountBlock = new AccountBlock();
|
||||
accountBlock.setBlockValue(blockValue);
|
||||
accountBlock.setBlockDevice(blockDevice);
|
||||
accountBlock.setBlockImgUrl(blockImgUrl);
|
||||
accountBlock.setBlockType(blockType);
|
||||
if (blockType == BlockTypeEnum.BLOCK_ACCOUNT.getValue()) {
|
||||
Users erBanNo = usersBaseService.getUsersByErBanNo(Long.parseLong(blockValue));
|
||||
if (erBanNo != null) {
|
||||
accountBlock.setBlockUid(erBanNo.getUid());
|
||||
}
|
||||
}
|
||||
accountBlock.setBlockStatus(1);
|
||||
accountBlock.setBlockDesc(blockDesc);
|
||||
accountBlock.setBlockStartTime(DateTimeUtil.convertStrToDate(startBlockTime, DateTimeUtil.DEFAULT_DATE_MINUTE_PATTERN));
|
||||
accountBlock.setBlockEndTime(DateTimeUtil.convertStrToDate(endBlockTime, DateTimeUtil.DEFAULT_DATE_MINUTE_PATTERN));
|
||||
accountBlock.setSource(BlockStatusEnum.BLOCKING.getValue());
|
||||
accountBlock.setWallStatus(wallStatus);
|
||||
accountBlock.setCreateTime(new Date());
|
||||
accountBlock.setAdminName(adminName);
|
||||
accountBlock.setRemark(remark);
|
||||
list.add(accountBlock);
|
||||
});
|
||||
|
||||
Boolean result = accountBlockService.saveOrUpdateBatch(list);
|
||||
if (result) {
|
||||
accountBlockService.saveBlockedAccountCache(list);
|
||||
accountBlockService.batchKickOut(list);
|
||||
}
|
||||
return accountBlockService.batchSaveAccountBlock(blockValueList, blockType, startBlockTime, endBlockTime, blockDesc, wallStatus, adminName,remark);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
public Boolean updateBlockedAccount(String blockValue,Integer blockStatus,String blockStartTime, String blockEndTime,
|
||||
String blockDesc,Boolean wallStatus, String adminName,String remark) throws Exception{
|
||||
public Boolean updateBlockedAccount(String blockValue, Integer blockStatus, String blockStartTime, String blockEndTime,
|
||||
String blockDesc, Boolean wallStatus, String adminName, String remark) throws Exception {
|
||||
AccountBlock block = accountBlockService.getById(blockValue);
|
||||
if(block == null){
|
||||
if (block == null) {
|
||||
throw new AdminServiceException(BusiStatus.RECORD_NOT_EXIST);
|
||||
}
|
||||
block.setBlockStatus(blockStatus);
|
||||
block.setBlockStartTime(DateTimeUtil.convertStrToDate(blockStartTime,DateTimeUtil.DEFAULT_DATE_MINUTE_PATTERN));
|
||||
block.setBlockEndTime(DateTimeUtil.convertStrToDate(blockEndTime,DateTimeUtil.DEFAULT_DATE_MINUTE_PATTERN));
|
||||
block.setBlockStartTime(DateTimeUtil.convertStrToDate(blockStartTime, DateTimeUtil.DEFAULT_DATE_MINUTE_PATTERN));
|
||||
block.setBlockEndTime(DateTimeUtil.convertStrToDate(blockEndTime, DateTimeUtil.DEFAULT_DATE_MINUTE_PATTERN));
|
||||
block.setBlockDesc(blockDesc);
|
||||
block.setWallStatus(wallStatus);
|
||||
block.setAdminName(adminName);
|
||||
block.setRemark(remark);
|
||||
Boolean result = accountBlockService.updateById(block);
|
||||
if(result){
|
||||
if (result) {
|
||||
//封禁踢下线,保存到缓存;解封删除缓存
|
||||
boolean betweenDate = DateTimeUtil.isBetweenDate(Calendar.getInstance().getTime(), block.getBlockStartTime(), block.getBlockEndTime());
|
||||
if(betweenDate && block.getBlockStatus() != null && BlockStatusEnum.BLOCKING.getValue() == block.getBlockStatus().byteValue()){
|
||||
if (betweenDate && block.getBlockStatus() != null && BlockStatusEnum.BLOCKING.getValue() == block.getBlockStatus().byteValue()) {
|
||||
accountBlockService.saveBlockedAccountCache(Arrays.asList(block));
|
||||
accountBlockService.batchKickOut(Arrays.asList(block));
|
||||
}else {
|
||||
} else {
|
||||
accountBlockService.deleteBlockedAccountCache(Arrays.asList(block));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public Boolean deleteAccountBlock(String blockValue, String adminName) throws Exception{
|
||||
public Boolean deleteAccountBlock(String blockValue, String adminName) throws Exception {
|
||||
|
||||
AccountBlock block = accountBlockService.getById(blockValue);
|
||||
if(block == null){
|
||||
if (block == null) {
|
||||
throw new AdminServiceException(BusiStatus.RECORD_NOT_EXIST);
|
||||
}
|
||||
block.setWallStatus(false);
|
||||
@@ -111,7 +141,7 @@ public class AccountBlockAdminService extends BaseService {
|
||||
block.setBlockEndTime(new Date());
|
||||
block.setAdminName(adminName);
|
||||
Boolean result = accountBlockService.updateById(block);
|
||||
if(result){
|
||||
if (result) {
|
||||
accountBlockService.deleteBlockedAccountCache(Arrays.asList(block));
|
||||
}
|
||||
return result;
|
||||
|
@@ -27,7 +27,7 @@ import java.util.stream.Collectors;
|
||||
* @since 2020-04-28
|
||||
* 账号封禁功能
|
||||
*/
|
||||
@Api(tags = "管理后台",value = "账号封禁")
|
||||
@Api(tags = "管理后台" , value = "账号封禁")
|
||||
@RestController
|
||||
@RequestMapping("/admin/block")
|
||||
public class AccountBlockAdminController extends BaseController {
|
||||
@@ -50,30 +50,33 @@ public class AccountBlockAdminController extends BaseController {
|
||||
|
||||
@ApiOperation("查询封禁记录")
|
||||
@GetMapping(value = "/get")
|
||||
public BusiResult<AccountBlock> getAccountBlock(String blockValue){
|
||||
public BusiResult<AccountBlock> getAccountBlock(String blockValue) {
|
||||
AccountBlock accountBlock = accountBlockService.getById(blockValue);
|
||||
return BusiResult.success(accountBlock);
|
||||
}
|
||||
|
||||
@ApiOperation("保存账号封禁记录")
|
||||
@PostMapping(value = "/save")
|
||||
public BusiResult<Boolean> batchSaveAccountBlock(Integer blockType, String blockValue,String blockStartTime,
|
||||
String blockEndTime, String blockDesc, Boolean wallStatus, String remark) throws Exception{
|
||||
public BusiResult<Boolean> batchSaveAccountBlock(Integer blockType, String blockValue, String blockStartTime,
|
||||
String blockEndTime, String blockDesc, Boolean wallStatus, String remark,
|
||||
String blockImgUrl, Byte blockDevice) throws Exception {
|
||||
//不用回车或换行符的原因是不同的操作系统不一样
|
||||
List<String> blockValueList = Arrays.stream(blockValue.split(",")).map(String::trim).collect(Collectors.toList());
|
||||
|
||||
int adminId = getAdminId();
|
||||
String adminName = adminUserService.getAdminName(adminId);
|
||||
Boolean result = accountBlockAdminService.batchSaveAccountBlock(blockValueList,blockType,blockStartTime,
|
||||
blockEndTime,blockDesc,wallStatus,adminName,remark);
|
||||
String adminName = adminUserService.getAdminName(getAdminId());
|
||||
if (null == wallStatus) {
|
||||
wallStatus = Boolean.TRUE;
|
||||
}
|
||||
Boolean result = accountBlockAdminService.batchSaveAccountBlock(blockValueList, blockType, blockStartTime,
|
||||
blockEndTime, blockDesc, wallStatus, adminName, remark, blockImgUrl, blockDevice);
|
||||
return BusiResult.success(result);
|
||||
}
|
||||
|
||||
@ApiOperation("更新封禁记录")
|
||||
@PostMapping(value = "/update")
|
||||
public BusiResult<Boolean> updateBlockedAccount(String blockValue,Integer blockStatus,String blockStartTime,
|
||||
String blockEndTime, String blockDesc,Boolean wallStatus,String remark) throws Exception{
|
||||
if (StringUtils.isBlank(blockValue)){
|
||||
public BusiResult<Boolean> updateBlockedAccount(String blockValue, Integer blockStatus, String blockStartTime,
|
||||
String blockEndTime, String blockDesc, Boolean wallStatus, String remark) throws Exception {
|
||||
if (StringUtils.isBlank(blockValue)) {
|
||||
throw new AdminServiceException(BusiStatus.PARAMERROR);
|
||||
}
|
||||
|
||||
@@ -81,17 +84,17 @@ public class AccountBlockAdminController extends BaseController {
|
||||
|
||||
int adminId = getAdminId();
|
||||
String adminName = adminUserService.getAdminName(adminId);
|
||||
Boolean result = accountBlockAdminService.updateBlockedAccount(blockValue,blockStatus,blockStartTime,
|
||||
blockEndTime,blockDesc,wallStatus,adminName,remark);
|
||||
Boolean result = accountBlockAdminService.updateBlockedAccount(blockValue, blockStatus, blockStartTime,
|
||||
blockEndTime, blockDesc, wallStatus, adminName, remark);
|
||||
return new BusiResult<>(result);
|
||||
}
|
||||
|
||||
@ApiOperation("解除封禁记录")
|
||||
@PostMapping(value = "/delete")
|
||||
public BusiResult<Boolean> deleteAccountBlock(String blockValue) throws Exception{
|
||||
public BusiResult<Boolean> deleteAccountBlock(String blockValue) throws Exception {
|
||||
int adminId = getAdminId();
|
||||
String adminName = adminUserService.getAdminName(adminId);
|
||||
boolean result = accountBlockAdminService.deleteAccountBlock(blockValue,adminName);
|
||||
boolean result = accountBlockAdminService.deleteAccountBlock(blockValue, adminName);
|
||||
return new BusiResult<>(result);
|
||||
}
|
||||
|
||||
|
@@ -48,4 +48,11 @@ public class AccountBlock {
|
||||
private String remark;
|
||||
|
||||
private Long blockUid;
|
||||
|
||||
private Byte blockImgType;
|
||||
|
||||
private String blockImgUrl;
|
||||
|
||||
private Byte blockDevice;
|
||||
|
||||
}
|
@@ -40,7 +40,7 @@ import java.util.stream.Collectors;
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class AccountBlockService extends ServiceImpl<AccountBlockMapper,AccountBlock> {
|
||||
public class AccountBlockService extends ServiceImpl<AccountBlockMapper, AccountBlock> {
|
||||
|
||||
@Autowired
|
||||
private NetEaseService netEaseService;
|
||||
@@ -72,10 +72,10 @@ public class AccountBlockService extends ServiceImpl<AccountBlockMapper,AccountB
|
||||
*/
|
||||
public void doAccountBlock(Long uid, Long erbanNo, String kickNotifyExt) {
|
||||
String accid = uid.toString();
|
||||
log.info("blockAccount uid:{}", accid);
|
||||
log.info("blockAccount uid:{}" , accid);
|
||||
usersService.downMic(uid);
|
||||
//调用云信封禁账号功能,主要用于踢用户下线
|
||||
netEaseService.block(accid, "true", kickNotifyExt);
|
||||
netEaseService.block(accid, "true" , kickNotifyExt);
|
||||
netEaseService.refreshToken(accid);
|
||||
netEaseService.unblock(accid);
|
||||
roomService.closeRoom(uid);
|
||||
@@ -85,33 +85,34 @@ public class AccountBlockService extends ServiceImpl<AccountBlockMapper,AccountB
|
||||
|
||||
/**
|
||||
* 批量踢用户下线
|
||||
*
|
||||
* @param blockList
|
||||
* @throws Exception
|
||||
*/
|
||||
public void batchKickOut(List<AccountBlock> blockList) throws Exception{
|
||||
public void batchKickOut(List<AccountBlock> blockList) throws Exception {
|
||||
blockList.stream().forEach(accountBlock -> {
|
||||
Users users = null;
|
||||
try{
|
||||
if(accountBlock.getBlockType() == BlockTypeEnum.BLOCK_ACCOUNT.getValue()) {
|
||||
try {
|
||||
if (accountBlock.getBlockType() == BlockTypeEnum.BLOCK_ACCOUNT.getValue()) {
|
||||
users = usersBaseService.getUsersByErBanNo(Long.parseLong(accountBlock.getBlockValue()));
|
||||
}else if(accountBlock.getBlockType() == BlockTypeEnum.BLOCK_PHONE.getValue()){
|
||||
} else if (accountBlock.getBlockType() == BlockTypeEnum.BLOCK_PHONE.getValue()) {
|
||||
users = usersBaseService.getUsersByPhone(accountBlock.getBlockValue());
|
||||
} else if (accountBlock.getBlockType() == BlockTypeEnum.BLOCK_EMAIL.getValue()) {
|
||||
users = usersBaseService.getUsersByEmail(accountBlock.getBlockValue());
|
||||
} else if(accountBlock.getBlockType() == BlockTypeEnum.BLOCK_DEVICE.getValue()){
|
||||
} else if (accountBlock.getBlockType() == BlockTypeEnum.BLOCK_DEVICE.getValue()) {
|
||||
AccountLoginRecord accountLoginRecord =
|
||||
accountLoginRecordService.getLastLoginRecordByDevice(accountBlock.getBlockValue());
|
||||
if (accountLoginRecord != null) {
|
||||
users = usersBaseService.getUsersByUid(accountLoginRecord.getUid());
|
||||
}
|
||||
}
|
||||
if(users == null){
|
||||
if (users == null) {
|
||||
return;
|
||||
}
|
||||
doAccountBlock(users.getUid(), users.getErbanNo(), Constant.NeteaseDownUserMsg.block);
|
||||
roomService.closeRoom(users.getUid());
|
||||
}catch (Exception e){
|
||||
log.error("kick user out error, user:{}",gson.toJson(users));
|
||||
} catch (Exception e) {
|
||||
log.error("kick user out error, user:{}" , gson.toJson(users));
|
||||
}
|
||||
});
|
||||
saveBlockedAccountCache(blockList);
|
||||
@@ -120,30 +121,31 @@ public class AccountBlockService extends ServiceImpl<AccountBlockMapper,AccountB
|
||||
/**
|
||||
* 刷新封禁状态
|
||||
*/
|
||||
public void deleteAccountBlock() throws Exception{
|
||||
QueryWrapper<AccountBlock> wrapper = new QueryWrapper<>();
|
||||
wrapper.lambda().eq(AccountBlock::getBlockStatus,BlockStatusEnum.BLOCKING.getValue());
|
||||
List<AccountBlock> accountBlocks = list(wrapper);
|
||||
if (CollectionUtils.isEmpty(accountBlocks)) {
|
||||
return;
|
||||
}
|
||||
public void deleteAccountBlock() throws Exception {
|
||||
QueryWrapper<AccountBlock> wrapper = new QueryWrapper<>();
|
||||
wrapper.lambda().eq(AccountBlock::getBlockStatus, BlockStatusEnum.BLOCKING.getValue());
|
||||
List<AccountBlock> accountBlocks = list(wrapper);
|
||||
if (CollectionUtils.isEmpty(accountBlocks)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Date now = new Date();
|
||||
List<AccountBlock> expire = accountBlocks.stream()
|
||||
.filter(r->DateTimeUtil.compareTime(r.getBlockEndTime(), now) < 0)
|
||||
.peek(r-> r.setBlockStatus(BlockStatusEnum.BLOCK_FINISH.getValue()))
|
||||
.collect(Collectors.toList());
|
||||
if (CollectionUtils.isEmpty(expire)){
|
||||
return;
|
||||
}
|
||||
Boolean result = saveOrUpdateBatch(expire);
|
||||
if(result){
|
||||
deleteBlockedAccountCache(expire);
|
||||
}
|
||||
Date now = new Date();
|
||||
List<AccountBlock> expire = accountBlocks.stream()
|
||||
.filter(r -> DateTimeUtil.compareTime(r.getBlockEndTime(), now) < 0)
|
||||
.peek(r -> r.setBlockStatus(BlockStatusEnum.BLOCK_FINISH.getValue()))
|
||||
.collect(Collectors.toList());
|
||||
if (CollectionUtils.isEmpty(expire)) {
|
||||
return;
|
||||
}
|
||||
Boolean result = saveOrUpdateBatch(expire);
|
||||
if (result) {
|
||||
deleteBlockedAccountCache(expire);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存封禁
|
||||
*
|
||||
* @param erbanNo
|
||||
* @param blockType
|
||||
* @param startBlockTimeStr
|
||||
@@ -155,15 +157,16 @@ public class AccountBlockService extends ServiceImpl<AccountBlockMapper,AccountB
|
||||
* @throws Exception
|
||||
*/
|
||||
public Boolean saveBlockedAccount(Long erbanNo, Integer blockType, String startBlockTimeStr, String endBlockTimeStr,
|
||||
String blockDesc, Integer source, String adminName,Boolean wallStatus) throws Exception {
|
||||
String blockDesc, Integer source, String adminName, Boolean wallStatus) throws Exception {
|
||||
Date startBlockTime = DateTimeUtil.convertStrToDate(startBlockTimeStr);
|
||||
Date endBlockTime = DateTimeUtil.convertStrToDate(endBlockTimeStr);
|
||||
Users users = usersBaseService.getUsersByErBanNo(erbanNo);
|
||||
return saveBlockedAccountV2(users, blockType, startBlockTime, endBlockTime, blockDesc, source, adminName, wallStatus);
|
||||
return saveBlockedAccountV2(users, blockType, startBlockTime, endBlockTime, blockDesc, source, adminName, wallStatus);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存封禁
|
||||
*
|
||||
* @param users
|
||||
* @param blockType
|
||||
* @param startBlockTime
|
||||
@@ -175,18 +178,18 @@ public class AccountBlockService extends ServiceImpl<AccountBlockMapper,AccountB
|
||||
* @throws Exception
|
||||
*/
|
||||
public Boolean saveBlockedAccountV2(Users users, Integer blockType, Date startBlockTime, Date endBlockTime,
|
||||
String blockDesc, Integer source, String adminName,Boolean wallStatus) throws Exception {
|
||||
String blockDesc, Integer source, String adminName, Boolean wallStatus) throws Exception {
|
||||
if (users == null) {
|
||||
throw new AdminServiceException(BusiStatus.THE_PLATFORM_NUMBER_DOES_NOT_EXIST);
|
||||
}
|
||||
Long erbanNo = users.getErbanNo();
|
||||
AccountBlock accountBlock = getById(erbanNo.toString());
|
||||
Date date = new Date();
|
||||
if(accountBlock != null && accountBlock.getSource() == BlockSourceEnum.SYSTEM.getValue()
|
||||
if (accountBlock != null && accountBlock.getSource() == BlockSourceEnum.SYSTEM.getValue()
|
||||
&& accountBlock.getBlockStartTime().before(date) && accountBlock.getBlockEndTime().after(date)) {
|
||||
throw new AdminServiceException(BusiStatus.THE_USER_HAS_BEEN_BANNED_BY_THE_SYSTEM);
|
||||
}
|
||||
if(accountBlock == null) {
|
||||
if (accountBlock == null) {
|
||||
accountBlock = new AccountBlock();
|
||||
accountBlock.setBlockValue(erbanNo.toString());
|
||||
accountBlock.setCreateTime(new Date());
|
||||
@@ -201,17 +204,18 @@ public class AccountBlockService extends ServiceImpl<AccountBlockMapper,AccountB
|
||||
accountBlock.setSource(source);
|
||||
accountBlock.setBlockUid(users.getUid());
|
||||
Boolean result = saveOrUpdate(accountBlock);
|
||||
if(result) {
|
||||
if (result) {
|
||||
saveBlockedAccountCache(Arrays.asList(accountBlock));
|
||||
//如果封禁了,踢下线和关闭房间
|
||||
doAccountBlock(users.getUid(), users.getErbanNo(), Constant.NeteaseDownUserMsg.block);
|
||||
roomService.closeRoom(users.getUid());
|
||||
}
|
||||
return result;
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存封禁
|
||||
*
|
||||
* @param users
|
||||
* @param blockType
|
||||
* @param startBlockTime
|
||||
@@ -223,13 +227,13 @@ public class AccountBlockService extends ServiceImpl<AccountBlockMapper,AccountB
|
||||
* @throws Exception
|
||||
*/
|
||||
public Boolean saveBlockedAccount4App(Users users, Integer blockType, Date startBlockTime, Date endBlockTime,
|
||||
String blockDesc, Integer source, String adminName,Boolean wallStatus) throws Exception {
|
||||
String blockDesc, Integer source, String adminName, Boolean wallStatus) throws Exception {
|
||||
if (users == null) {
|
||||
throw new ServiceException(BusiStatus.THE_PLATFORM_NUMBER_DOES_NOT_EXIST);
|
||||
}
|
||||
Long erbanNo = users.getErbanNo();
|
||||
AccountBlock accountBlock = getById(erbanNo.toString());
|
||||
if(accountBlock == null) {
|
||||
if (accountBlock == null) {
|
||||
accountBlock = new AccountBlock();
|
||||
accountBlock.setBlockValue(erbanNo.toString());
|
||||
accountBlock.setCreateTime(new Date());
|
||||
@@ -244,34 +248,36 @@ public class AccountBlockService extends ServiceImpl<AccountBlockMapper,AccountB
|
||||
accountBlock.setSource(source);
|
||||
accountBlock.setBlockUid(users.getUid());
|
||||
Boolean result = saveOrUpdate(accountBlock);
|
||||
if(result) {
|
||||
if (result) {
|
||||
saveBlockedAccountCache(Arrays.asList(accountBlock));
|
||||
//如果封禁了,踢下线和关闭房间
|
||||
doAccountBlock(users.getUid(), users.getErbanNo(), Constant.NeteaseDownUserMsg.block);
|
||||
roomService.closeRoom(users.getUid());
|
||||
}
|
||||
return result;
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存缓存记录
|
||||
*
|
||||
* @param blockList
|
||||
* @throws Exception
|
||||
*/
|
||||
public void saveBlockedAccountCache(List<AccountBlock> blockList) throws Exception{
|
||||
public void saveBlockedAccountCache(List<AccountBlock> blockList) throws Exception {
|
||||
jedisService.doInPipeline((pipeline) -> {
|
||||
blockList.stream().forEach(accountBlock -> {
|
||||
pipeline.hset(RedisKey.block_account.getKey(accountBlock.getBlockType().toString()),
|
||||
accountBlock.getBlockValue(),gson.toJson(accountBlock));
|
||||
accountBlock.getBlockValue(), gson.toJson(accountBlock));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除缓存记录
|
||||
*
|
||||
* @param blockList
|
||||
*/
|
||||
public void deleteBlockedAccountCache(List<AccountBlock> blockList) throws Exception{
|
||||
public void deleteBlockedAccountCache(List<AccountBlock> blockList) throws Exception {
|
||||
jedisService.doInPipeline((pipeline) -> {
|
||||
blockList.stream().forEach(accountBlock -> {
|
||||
pipeline.hdel(RedisKey.block_account.getKey(accountBlock.getBlockType().toString()),
|
||||
@@ -283,15 +289,16 @@ public class AccountBlockService extends ServiceImpl<AccountBlockMapper,AccountB
|
||||
public List<AccountBlock> batchQueryAccountBlock(List<String> erbanNos) {
|
||||
Date curDate = new Date();
|
||||
QueryWrapper<AccountBlock> wrapper = new QueryWrapper<>();
|
||||
wrapper.lambda().in(AccountBlock::getBlockValue,erbanNos)
|
||||
.eq(AccountBlock::getBlockStatus,BlockStatusEnum.BLOCKING.getValue())
|
||||
.le(AccountBlock::getBlockStartTime,curDate)
|
||||
.ge(AccountBlock::getBlockEndTime,curDate);
|
||||
wrapper.lambda().in(AccountBlock::getBlockValue, erbanNos)
|
||||
.eq(AccountBlock::getBlockStatus, BlockStatusEnum.BLOCKING.getValue())
|
||||
.le(AccountBlock::getBlockStartTime, curDate)
|
||||
.ge(AccountBlock::getBlockEndTime, curDate);
|
||||
return list(wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量封禁账号
|
||||
*
|
||||
* @param blockValueList
|
||||
* @param blockType
|
||||
* @param startBlockTime
|
||||
@@ -303,7 +310,7 @@ public class AccountBlockService extends ServiceImpl<AccountBlockMapper,AccountB
|
||||
* @throws Exception
|
||||
*/
|
||||
public Boolean batchSaveAccountBlock(List<String> blockValueList, Integer blockType, Date startBlockTime,
|
||||
Date endBlockTime, String blockDesc, Boolean wallStatus, String adminName) throws Exception{
|
||||
Date endBlockTime, String blockDesc, Boolean wallStatus, String adminName) throws Exception {
|
||||
List<AccountBlock> list = new ArrayList<>();
|
||||
blockValueList.stream().forEach(blockValue -> {
|
||||
AccountBlock accountBlock = new AccountBlock();
|
||||
@@ -326,52 +333,7 @@ public class AccountBlockService extends ServiceImpl<AccountBlockMapper,AccountB
|
||||
list.add(accountBlock);
|
||||
});
|
||||
Boolean result = saveOrUpdateBatch(list);
|
||||
if(result){
|
||||
saveBlockedAccountCache(list);
|
||||
batchKickOut(list);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量封禁账号
|
||||
* @param blockValueList
|
||||
* @param blockType
|
||||
* @param startBlockTime
|
||||
* @param endBlockTime
|
||||
* @param blockDesc
|
||||
* @param wallStatus
|
||||
* @param adminName
|
||||
* @param remark 后台封禁 备注 字段
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public Boolean batchSaveAccountBlock(List<String> blockValueList, Integer blockType, String startBlockTime,
|
||||
String endBlockTime, String blockDesc, Boolean wallStatus, String adminName,String remark) throws Exception{
|
||||
List<AccountBlock> list = new ArrayList<>();
|
||||
blockValueList.stream().forEach(blockValue -> {
|
||||
AccountBlock accountBlock = new AccountBlock();
|
||||
accountBlock.setBlockValue(blockValue);
|
||||
accountBlock.setBlockType(blockType);
|
||||
if (blockType == BlockTypeEnum.BLOCK_ACCOUNT.getValue()) {
|
||||
Users erBanNo = usersBaseService.getUsersByErBanNo(Long.parseLong(blockValue));
|
||||
if (erBanNo != null) {
|
||||
accountBlock.setBlockUid(erBanNo.getUid());
|
||||
}
|
||||
}
|
||||
accountBlock.setBlockStatus(1);
|
||||
accountBlock.setBlockDesc(blockDesc);
|
||||
accountBlock.setBlockStartTime(DateTimeUtil.convertStrToDate(startBlockTime,DateTimeUtil.DEFAULT_DATE_MINUTE_PATTERN));
|
||||
accountBlock.setBlockEndTime(DateTimeUtil.convertStrToDate(endBlockTime,DateTimeUtil.DEFAULT_DATE_MINUTE_PATTERN));
|
||||
accountBlock.setSource(BlockStatusEnum.BLOCKING.getValue());
|
||||
accountBlock.setWallStatus(wallStatus);
|
||||
accountBlock.setCreateTime(new Date());
|
||||
accountBlock.setAdminName(adminName);
|
||||
accountBlock.setRemark(remark);
|
||||
list.add(accountBlock);
|
||||
});
|
||||
Boolean result = saveOrUpdateBatch(list);
|
||||
if(result){
|
||||
if (result) {
|
||||
saveBlockedAccountCache(list);
|
||||
batchKickOut(list);
|
||||
}
|
||||
@@ -380,11 +342,12 @@ public class AccountBlockService extends ServiceImpl<AccountBlockMapper,AccountB
|
||||
|
||||
/**
|
||||
* 判断用户是否被封禁
|
||||
*
|
||||
* @param erbanNo
|
||||
* @param phone
|
||||
* @return
|
||||
*/
|
||||
public Boolean checkAccountBlock(Long erbanNo, String phone){
|
||||
public Boolean checkAccountBlock(Long erbanNo, String phone) {
|
||||
Boolean banAccount = false;
|
||||
Integer blockType = BlockTypeEnum.BLOCK_ACCOUNT.getValue();
|
||||
String accountCache = jedisService.hget(RedisKey.block_account.getKey(blockType.toString()), String.valueOf(erbanNo));
|
||||
@@ -392,10 +355,10 @@ public class AccountBlockService extends ServiceImpl<AccountBlockMapper,AccountB
|
||||
banAccount = checkAccountBlock(accountCache);
|
||||
}
|
||||
//如果账号封禁没有,继续去手机号封禁查询
|
||||
if(StringUtil.isNotBlank(phone)){
|
||||
if (StringUtil.isNotBlank(phone)) {
|
||||
blockType = BlockTypeEnum.BLOCK_PHONE.getValue();
|
||||
accountCache = jedisService.hget(RedisKey.block_account.getKey(blockType.toString()), phone);
|
||||
if(!StringUtils.isEmpty(accountCache)){
|
||||
if (!StringUtils.isEmpty(accountCache)) {
|
||||
banAccount = checkAccountBlock(accountCache);
|
||||
}
|
||||
}
|
||||
@@ -404,10 +367,11 @@ public class AccountBlockService extends ServiceImpl<AccountBlockMapper,AccountB
|
||||
|
||||
/**
|
||||
* 判断用户是否被封禁
|
||||
*
|
||||
* @param uid
|
||||
* @return
|
||||
*/
|
||||
public boolean checkAccountBlock(Long uid){
|
||||
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));
|
||||
@@ -417,7 +381,7 @@ public class AccountBlockService extends ServiceImpl<AccountBlockMapper,AccountB
|
||||
return banAccount;
|
||||
}
|
||||
|
||||
private Boolean checkAccountBlock(String accountBlockCache){
|
||||
private Boolean checkAccountBlock(String accountBlockCache) {
|
||||
AccountBlock accountBlock = gson.fromJson(accountBlockCache, AccountBlock.class);
|
||||
boolean betweenDate = DateTimeUtil.isBetweenDate(Calendar.getInstance().getTime(), accountBlock.getBlockStartTime(), accountBlock.getBlockEndTime());
|
||||
return betweenDate && accountBlock.getBlockStatus() != null
|
||||
|
Reference in New Issue
Block a user