封禁原因继承+封禁设备

This commit is contained in:
2025-07-18 15:19:54 +08:00
parent 109e087bfd
commit d36fbd46ab
6 changed files with 129 additions and 29 deletions

View File

@@ -1,6 +1,8 @@
package com.accompany.admin.service;
import cn.hutool.core.date.DateUtil;
import com.accompany.admin.service.base.BaseService;
import com.accompany.business.service.AccountLoginRecordService;
import com.accompany.business.service.account.AccountBlockService;
import com.accompany.common.status.BusiStatus;
import com.accompany.common.utils.DateTimeUtil;
@@ -14,6 +16,7 @@ import com.accompany.core.util.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -34,6 +37,9 @@ public class AccountBlockAdminService extends BaseService {
@Autowired
private UsersBaseService usersBaseService;
@Autowired
private AccountLoginRecordService accountLoginRecordService;
/**
* 分页查询封禁记录
@@ -69,20 +75,24 @@ public class AccountBlockAdminService extends BaseService {
*/
public Boolean batchSaveAccountBlock(List<String> blockValueList, Integer blockType, String startBlockTime,
String endBlockTime, String blockDesc, Boolean wallStatus, String adminName, String remark,
String blockImgUrl, Byte blockDevice) throws Exception {
String blockImgUrl, Byte blockDevice, Byte blockImgType) throws Exception {
List<AccountBlock> list = new ArrayList<>();
Map<String, AccountBlock> accountBlockMap = accountBlockService.mapByBlockValue(blockValueList);
Map<String, AccountBlock> accountBlockMap = accountBlockService.mapValidByBlockValue(blockValueList);
List<Long> uids = new ArrayList<>();
blockValueList.stream().forEach(blockValue -> {
AccountBlock accountBlock = new AccountBlock();
accountBlock.setBlockValue(blockValue);
accountBlock.setBlockDevice(blockDevice);
accountBlock.setBlockImgType(blockImgType);
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());
if (erBanNo == null) {
throw new AdminServiceException("ID:" + blockValue + "不存在");
}
accountBlock.setBlockUid(erBanNo.getUid());
uids.add(erBanNo.getUid());
}
accountBlock.setBlockStatus(1);
AccountBlock oldRecord = accountBlockMap.get(blockValue);
@@ -101,38 +111,101 @@ public class AccountBlockAdminService extends BaseService {
list.add(accountBlock);
});
Boolean result = accountBlockService.saveOrUpdateBatch(list);
if (result) {
accountBlockService.saveBlockedAccountCache(list);
accountBlockService.batchKickOut(list);
List<AccountBlock> blockDevices = fillDevicesBlockByErbanNo(list, blockDesc, wallStatus, adminName, remark, blockImgUrl, blockImgType);
if (CollectionUtils.isNotEmpty(blockDevices)) {
list.addAll(blockDevices);
}
Boolean result = accountBlockService.saveOrUpdateBatch(list);
if (!result) {
return result;
}
accountBlockService.saveBlockedAccountCache(list);
accountBlockService.batchKickOut(list);
return result;
}
public List<AccountBlock> fillDevicesBlockByErbanNo(List<AccountBlock> list, String blockDesc, Boolean wallStatus, String adminName, String remark,
String blockImgUrl, Byte blockImgType) {
List<AccountBlock> blockDevices = new ArrayList<>();
for (AccountBlock block : list) {
if (block.getBlockType() != BlockTypeEnum.BLOCK_ACCOUNT.getValue() || block.getBlockDevice() != 1) {
continue;
}
List<String> recentLoginDevices = accountLoginRecordService.getRecentLoginDevices(DateUtil.offsetDay(new Date(), -30), block.getBlockUid());
if (CollectionUtils.isEmpty(recentLoginDevices)) {
continue;
}
Map<String, AccountBlock> accountBlockMap = accountBlockService.mapValidByBlockValue(recentLoginDevices);
blockDesc = String.format("%s:%s" , block.getBlockValue(), blockDesc);
for (String loginDevice : recentLoginDevices) {
AccountBlock accountBlock = new AccountBlock();
accountBlock.setBlockValue(loginDevice);
accountBlock.setBlockImgUrl(blockImgUrl);
accountBlock.setBlockImgType(blockImgType);
accountBlock.setBlockType(BlockTypeEnum.BLOCK_DEVICE.getValue());
accountBlock.setBlockStatus(1);
AccountBlock oldRecord = accountBlockMap.get(loginDevice);
if (oldRecord != null) {
accountBlock.setBlockDesc(String.format("%s+%s" , oldRecord.getBlockDesc(), blockDesc));
} else {
accountBlock.setBlockDesc(blockDesc);
}
accountBlock.setBlockStartTime(block.getBlockStartTime());
accountBlock.setBlockEndTime(block.getBlockEndTime());
accountBlock.setSource(BlockStatusEnum.BLOCKING.getValue());
accountBlock.setWallStatus(wallStatus);
accountBlock.setCreateTime(new Date());
accountBlock.setAdminName(adminName);
accountBlock.setRemark(remark);
blockDevices.add(accountBlock);
}
}
return blockDevices;
}
public Boolean updateBlockedAccount(String blockValue, Integer blockStatus, String blockStartTime, String blockEndTime,
String blockDesc, Boolean wallStatus, String adminName, String remark) throws Exception {
String blockDesc, Boolean wallStatus, String adminName, String remark,
String blockImgUrl, Byte blockDevice, Byte blockImgType) throws Exception {
AccountBlock block = accountBlockService.getById(blockValue);
if (block == null) {
throw new AdminServiceException(BusiStatus.RECORD_NOT_EXIST);
}
boolean needBlockDevice = blockDevice == 1 && block.getBlockType() == BlockTypeEnum.BLOCK_ACCOUNT.getValue()
&& (BlockStatusEnum.BLOCK_FINISH.getValue() == block.getBlockStatus().byteValue()
|| (BlockStatusEnum.BLOCKING.getValue() == block.getBlockStatus().byteValue() && block.getBlockDevice() == 0));
if (needBlockDevice) {
block.setBlockDevice(blockDevice);
}
block.setBlockStatus(blockStatus);
block.setBlockImgType(blockImgType);
block.setBlockImgUrl(blockImgUrl);
block.setBlockStartTime(DateTimeUtil.convertStrToDate(blockStartTime, DateTimeUtil.DEFAULT_DATE_MINUTE_PATTERN));
block.setBlockEndTime(DateTimeUtil.convertStrToDate(blockEndTime, DateTimeUtil.DEFAULT_DATE_MINUTE_PATTERN));
block.setBlockDesc(blockDesc);
block.setBlockDesc(String.format("%s+%s", block.getBlockDesc(), blockDesc));
block.setWallStatus(wallStatus);
block.setAdminName(adminName);
block.setRemark(remark);
Boolean result = accountBlockService.updateById(block);
if (result) {
//封禁踢下线,保存到缓存;解封删除缓存
boolean betweenDate = DateTimeUtil.isBetweenDate(Calendar.getInstance().getTime(), block.getBlockStartTime(), block.getBlockEndTime());
if (betweenDate && block.getBlockStatus() != null && BlockStatusEnum.BLOCKING.getValue() == block.getBlockStatus().byteValue()) {
accountBlockService.saveBlockedAccountCache(Arrays.asList(block));
accountBlockService.batchKickOut(Arrays.asList(block));
} else {
accountBlockService.deleteBlockedAccountCache(Arrays.asList(block));
}
if (!result) {
return result;
}
//封禁踢下线,保存到缓存;解封删除缓存
boolean betweenDate = DateTimeUtil.isBetweenDate(Calendar.getInstance().getTime(), block.getBlockStartTime(), block.getBlockEndTime());
if (betweenDate && block.getBlockStatus() != null && BlockStatusEnum.BLOCKING.getValue() == block.getBlockStatus().byteValue()) {
accountBlockService.saveBlockedAccountCache(Arrays.asList(block));
accountBlockService.batchKickOut(Arrays.asList(block));
} else {
accountBlockService.deleteBlockedAccountCache(Arrays.asList(block));
}
if (needBlockDevice) {
List<AccountBlock> accountBlocks = fillDevicesBlockByErbanNo(Arrays.asList(block), blockDesc, wallStatus, adminName, remark, blockImgUrl, blockImgType);
accountBlockService.saveOrUpdateBatch(accountBlocks);
accountBlockService.saveBlockedAccountCache(accountBlocks);
accountBlockService.batchKickOut(accountBlocks);
}
return result;
}

View File

@@ -59,7 +59,7 @@ public class AccountBlockAdminController extends BaseController {
@PostMapping(value = "/save")
public BusiResult<Boolean> batchSaveAccountBlock(Integer blockType, String blockValue, String blockStartTime,
String blockEndTime, String blockDesc, Boolean wallStatus, String remark,
String blockImgUrl, Byte blockDevice) throws Exception {
String blockImgUrl, Byte blockDevice, Byte blockImgType) throws Exception {
//不用回车或换行符的原因是不同的操作系统不一样
List<String> blockValueList = Arrays.stream(blockValue.split(",")).map(String::trim).collect(Collectors.toList());
@@ -68,14 +68,15 @@ public class AccountBlockAdminController extends BaseController {
wallStatus = Boolean.TRUE;
}
Boolean result = accountBlockAdminService.batchSaveAccountBlock(blockValueList, blockType, blockStartTime,
blockEndTime, blockDesc, wallStatus, adminName, remark, blockImgUrl, blockDevice);
blockEndTime, blockDesc, wallStatus, adminName, remark, blockImgUrl, blockDevice, blockImgType);
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 {
String blockEndTime, String blockDesc, Boolean wallStatus, String remark,
String blockImgUrl, Byte blockDevice, Byte blockImgType) throws Exception {
if (StringUtils.isBlank(blockValue)) {
throw new AdminServiceException(BusiStatus.PARAMERROR);
}
@@ -85,7 +86,7 @@ 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);
blockEndTime, blockDesc, wallStatus, adminName, remark, blockImgUrl, blockDevice, blockImgType);
return new BusiResult<>(result);
}

View File

@@ -9,7 +9,6 @@ import java.util.List;
public interface AccountLoginRecordMapperExpand {
List<Long> getRecentLoginUids(@Param("startDay") Date startDay, @Param("partitionId") Integer partitionId);
List<String> listUserLoginDevice(Long uid);
List<Long> getUidByRecent60Day(@Param("channel") String channel, @Param("ignoreVersion") String ignoreVersion, @Param("ignoreChannel") String ignoreChannel, @Param("partitionId") Integer partitionId, @Param("index") Integer index, @Param("offset") Integer offset);
@@ -42,4 +41,6 @@ public interface AccountLoginRecordMapperExpand {
* @return
*/
List<AccountLoginRecord> getLoginType(@Param("uidList") List<Long> uidList);
List<String> getRecentLoginDevices(@Param("startDay") Date startDay, @Param("uid") Long uid);
}

View File

@@ -74,4 +74,8 @@
)
</select>
<select id="getRecentLoginDevices" resultType="java.lang.String">
SELECT DISTINCT(device_uid) FROM account_login_record
WHERE create_time &gt;= #{startDay} and uid = #{uid}
</select>
</mapper>

View File

@@ -53,4 +53,11 @@ public class AccountLoginRecordService extends BaseService {
return accountLoginRecordMapperExpand.listUserLoginDevice(uid);
}
/**
* 获取最近时间登陆的设备id
*/
public List<String> getRecentLoginDevices(Date startDay, Long uid) {
return accountLoginRecordMapperExpand.getRecentLoginDevices(startDay, uid);
}
}

View File

@@ -20,6 +20,7 @@ import com.accompany.core.mybatismapper.AccountBlockMapper;
import com.accompany.core.service.account.NetEaseService;
import com.accompany.core.service.common.JedisService;
import com.accompany.core.service.user.UsersBaseService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.gson.Gson;
@@ -193,13 +194,15 @@ public class AccountBlockService extends ServiceImpl<AccountBlockMapper, Account
accountBlock = new AccountBlock();
accountBlock.setBlockValue(erbanNo.toString());
accountBlock.setCreateTime(new Date());
accountBlock.setBlockDesc(blockDesc);
} else if (accountBlock.getBlockStatus() == BlockStatusEnum.BLOCKING.getValue()) {
accountBlock.setBlockDesc(String.format("%s+%s", accountBlock.getBlockDesc(), blockDesc));
}
accountBlock.setBlockType(blockType);
accountBlock.setBlockStartTime(startBlockTime);
accountBlock.setBlockEndTime(endBlockTime);
accountBlock.setBlockStatus(BlockStatusEnum.BLOCKING.getValue());
accountBlock.setWallStatus(wallStatus);
accountBlock.setBlockDesc(blockDesc);
accountBlock.setAdminName(adminName);
accountBlock.setSource(source);
accountBlock.setBlockUid(users.getUid());
@@ -237,13 +240,15 @@ public class AccountBlockService extends ServiceImpl<AccountBlockMapper, Account
accountBlock = new AccountBlock();
accountBlock.setBlockValue(erbanNo.toString());
accountBlock.setCreateTime(new Date());
accountBlock.setBlockDesc(blockDesc);
} else if (accountBlock.getBlockStatus() == BlockStatusEnum.BLOCKING.getValue()) {
accountBlock.setBlockDesc(String.format("%s+%s", accountBlock.getBlockDesc(), blockDesc));
}
accountBlock.setBlockType(blockType);
accountBlock.setBlockStartTime(startBlockTime);
accountBlock.setBlockEndTime(endBlockTime);
accountBlock.setBlockStatus(BlockStatusEnum.BLOCKING.getValue());
accountBlock.setWallStatus(wallStatus);
accountBlock.setBlockDesc(blockDesc);
accountBlock.setAdminName(adminName);
accountBlock.setSource(source);
accountBlock.setBlockUid(users.getUid());
@@ -312,6 +317,7 @@ public class AccountBlockService extends ServiceImpl<AccountBlockMapper, Account
public Boolean batchSaveAccountBlock(List<String> blockValueList, Integer blockType, Date startBlockTime,
Date endBlockTime, String blockDesc, Boolean wallStatus, String adminName) throws Exception {
List<AccountBlock> list = new ArrayList<>();
Map<String, AccountBlock> accountBlockMap = this.mapValidByBlockValue(blockValueList);
blockValueList.stream().forEach(blockValue -> {
AccountBlock accountBlock = new AccountBlock();
accountBlock.setBlockValue(blockValue);
@@ -322,8 +328,13 @@ public class AccountBlockService extends ServiceImpl<AccountBlockMapper, Account
accountBlock.setBlockUid(erBanNo.getUid());
}
}
AccountBlock oldRecord = accountBlockMap.get(blockValue);
if (oldRecord != null) {
accountBlock.setBlockDesc(String.format("%s+%s", oldRecord.getBlockDesc(), blockDesc));
} else {
accountBlock.setBlockDesc(blockDesc);
}
accountBlock.setBlockStatus(1);
accountBlock.setBlockDesc(blockDesc);
accountBlock.setBlockStartTime(startBlockTime);
accountBlock.setBlockEndTime(endBlockTime);
accountBlock.setSource(BlockStatusEnum.BLOCKING.getValue());
@@ -388,8 +399,11 @@ public class AccountBlockService extends ServiceImpl<AccountBlockMapper, Account
&& BlockStatusEnum.BLOCKING.getValue() == accountBlock.getBlockStatus().byteValue();
}
public Map<String, AccountBlock> mapByBlockValue(List<String> blockValueList) {
List<AccountBlock> accountBlocks = baseMapper.selectByIds(blockValueList);
public Map<String, AccountBlock> mapValidByBlockValue(List<String> blockValueList) {
LambdaQueryWrapper<AccountBlock> wrapper = new LambdaQueryWrapper<>();
wrapper.in(AccountBlock::getBlockValue, blockValueList);
wrapper.eq(AccountBlock::getBlockStatus, BlockStatusEnum.BLOCKING.getValue());
List<AccountBlock> accountBlocks = baseMapper.selectList(wrapper);
if (CollectionUtils.isEmpty(accountBlocks)) {
return Collections.emptyMap();
}