diff --git a/accompany-admin/accompany-admin-service/src/main/java/com/accompany/admin/service/AccountBlockAdminService.java b/accompany-admin/accompany-admin-service/src/main/java/com/accompany/admin/service/AccountBlockAdminService.java index 595b1feab..65e6d1bee 100644 --- a/accompany-admin/accompany-admin-service/src/main/java/com/accompany/admin/service/AccountBlockAdminService.java +++ b/accompany-admin/accompany-admin-service/src/main/java/com/accompany/admin/service/AccountBlockAdminService.java @@ -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 getAccountBlockList(Integer pageSize, Integer pageNum, Integer type, String blockValue) { QueryWrapper 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 page = new Page<>(pageNum,pageSize); - return accountBlockService.page(page,wrapper); + IPage 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 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 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; diff --git a/accompany-admin/accompany-admin-web/src/main/java/com/accompany/admin/controller/feedback/AccountBlockAdminController.java b/accompany-admin/accompany-admin-web/src/main/java/com/accompany/admin/controller/feedback/AccountBlockAdminController.java index 0e76deefe..80441bfff 100644 --- a/accompany-admin/accompany-admin-web/src/main/java/com/accompany/admin/controller/feedback/AccountBlockAdminController.java +++ b/accompany-admin/accompany-admin-web/src/main/java/com/accompany/admin/controller/feedback/AccountBlockAdminController.java @@ -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 getAccountBlock(String blockValue){ + public BusiResult getAccountBlock(String blockValue) { AccountBlock accountBlock = accountBlockService.getById(blockValue); return BusiResult.success(accountBlock); } @ApiOperation("保存账号封禁记录") @PostMapping(value = "/save") - public BusiResult batchSaveAccountBlock(Integer blockType, String blockValue,String blockStartTime, - String blockEndTime, String blockDesc, Boolean wallStatus, String remark) throws Exception{ + public BusiResult batchSaveAccountBlock(Integer blockType, String blockValue, String blockStartTime, + String blockEndTime, String blockDesc, Boolean wallStatus, String remark, + String blockImgUrl, Byte blockDevice) throws Exception { //不用回车或换行符的原因是不同的操作系统不一样 List 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 updateBlockedAccount(String blockValue,Integer blockStatus,String blockStartTime, - String blockEndTime, String blockDesc,Boolean wallStatus,String remark) throws Exception{ - if (StringUtils.isBlank(blockValue)){ + public BusiResult 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 deleteAccountBlock(String blockValue) throws Exception{ + public BusiResult 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); } diff --git a/accompany-base/accompany-basic/accompany-basic-sdk/src/main/java/com/accompany/core/model/AccountBlock.java b/accompany-base/accompany-basic/accompany-basic-sdk/src/main/java/com/accompany/core/model/AccountBlock.java index 27b452b95..01dbabd5a 100644 --- a/accompany-base/accompany-basic/accompany-basic-sdk/src/main/java/com/accompany/core/model/AccountBlock.java +++ b/accompany-base/accompany-basic/accompany-basic-sdk/src/main/java/com/accompany/core/model/AccountBlock.java @@ -48,4 +48,11 @@ public class AccountBlock { private String remark; private Long blockUid; + + private Byte blockImgType; + + private String blockImgUrl; + + private Byte blockDevice; + } \ No newline at end of file diff --git a/accompany-business/accompany-business-service/src/main/java/com/accompany/business/service/account/AccountBlockService.java b/accompany-business/accompany-business-service/src/main/java/com/accompany/business/service/account/AccountBlockService.java index 60ce00341..fac1cd420 100644 --- a/accompany-business/accompany-business-service/src/main/java/com/accompany/business/service/account/AccountBlockService.java +++ b/accompany-business/accompany-business-service/src/main/java/com/accompany/business/service/account/AccountBlockService.java @@ -40,7 +40,7 @@ import java.util.stream.Collectors; */ @Slf4j @Service -public class AccountBlockService extends ServiceImpl { +public class AccountBlockService extends ServiceImpl { @Autowired private NetEaseService netEaseService; @@ -72,10 +72,10 @@ public class AccountBlockService extends ServiceImpl blockList) throws Exception{ + public void batchKickOut(List 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 wrapper = new QueryWrapper<>(); - wrapper.lambda().eq(AccountBlock::getBlockStatus,BlockStatusEnum.BLOCKING.getValue()); - List accountBlocks = list(wrapper); - if (CollectionUtils.isEmpty(accountBlocks)) { - return; - } + public void deleteAccountBlock() throws Exception { + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.lambda().eq(AccountBlock::getBlockStatus, BlockStatusEnum.BLOCKING.getValue()); + List accountBlocks = list(wrapper); + if (CollectionUtils.isEmpty(accountBlocks)) { + return; + } - Date now = new Date(); - List 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 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 blockList) throws Exception{ + public void saveBlockedAccountCache(List 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 blockList) throws Exception{ + public void deleteBlockedAccountCache(List 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 batchQueryAccountBlock(List erbanNos) { Date curDate = new Date(); QueryWrapper 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 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 list = new ArrayList<>(); blockValueList.stream().forEach(blockValue -> { AccountBlock accountBlock = new AccountBlock(); @@ -326,52 +333,7 @@ public class AccountBlockService extends ServiceImpl blockValueList, Integer blockType, String startBlockTime, - String endBlockTime, String blockDesc, Boolean wallStatus, String adminName,String remark) throws Exception{ - List 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