Skip to content

Commit

Permalink
修改黑名单更新缓存的bug
Browse files Browse the repository at this point in the history
  • Loading branch information
matevip committed Aug 31, 2020
1 parent a01d9bf commit c1b1aaa
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ public void setBlackList(BlackList blackList) {
public void deleteBlackList(BlackList blackList) {
String key = StringUtils.isNotBlank(blackList.getIp()) ? RuleConstant.getBlackListCacheKey(blackList.getIp())
: RuleConstant.getBlackListCacheKey();
redisService.setRemove(key, blackList);
redisService.setRemove(key, JSONObject.toJSONString(blackList));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import vip.mate.core.auth.annotation.EnableToken;
Expand Down Expand Up @@ -62,10 +63,17 @@ public Result<?> list(Page page, Search search) {
@PostMapping("/save-or-update")
@ApiOperation(value = "添加系统黑名单", notes = "添加系统黑名单,支持新增或修改")
public Result<?> saveOrUpdate(@Valid @RequestBody SysBlacklist sysBlacklist) {
BlackList blackList = new BlackList();
//删除缓存
if (sysBlacklist.getId() != null) {
SysBlacklist b = sysBlacklistService.getById(sysBlacklist.getId());
BeanUtils.copyProperties(b, blackList);
ruleCacheService.deleteBlackList(blackList);
}
//删除缓存
if (sysBlacklistService.saveOrUpdate(sysBlacklist)) {
//缓存操作-----start
SysBlacklist blacklistCurr = sysBlacklistService.getById(sysBlacklist.getId());
BlackList blackList = new BlackList();
BeanUtils.copyProperties(blacklistCurr, blackList);
ruleCacheService.setBlackList(blackList);
//缓存操作----end
Expand All @@ -92,17 +100,18 @@ public Result<?> info(SysBlacklist sysBlacklist) {
@ApiImplicitParams({
@ApiImplicitParam(name = "ids", required = true, value = "多个用,号隔开", paramType = "form")
})
@Transactional
public Result<?> delete(@RequestParam String ids) {
Collection collection = CollectionUtil.stringToCollection(ids);
if (sysBlacklistService.removeByIds(collection)){
//处理缓存----start
for (Object id: collection) {
SysBlacklist blacklistCurr = sysBlacklistService.getById(String.valueOf(id));
BlackList blackList = new BlackList();
BeanUtils.copyProperties(blacklistCurr, blackList);
ruleCacheService.deleteBlackList(blackList);
}
//处理缓存----end
BlackList blackList = new BlackList();
//处理缓存----start
for (Object id : collection) {
SysBlacklist blacklistCurr = sysBlacklistService.getById(CollectionUtil.objectToLong(id, 0L));
BeanUtils.copyProperties(blacklistCurr, blackList);
ruleCacheService.deleteBlackList(blackList);
}
//处理缓存----end
if (sysBlacklistService.removeByIds(collection)) {
return Result.success("删除成功");
}
return Result.fail("删除失败");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public class AuthServerConfig extends AuthorizationServerConfigurerAdapter {

private final UserDetailsService userDetailsService;

private RedisService redisService;
private final RedisService redisService;

private final AuthRequestFactory factory;

Expand Down

0 comments on commit c1b1aaa

Please sign in to comment.