| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- package com.xunmei.system.controller;
- import com.xunmei.common.core.constant.CacheConstants;
- import com.xunmei.common.redis.utils.RedisUtils;
- import com.xunmei.system.service.ExportSqlService;
- import com.xunmei.system.service.ISysOrgService;
- import com.xunmei.system.service.ISysUserService;
- import io.swagger.annotations.Api;
- import lombok.extern.slf4j.Slf4j;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.web.bind.annotation.GetMapping;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RequestParam;
- import org.springframework.web.bind.annotation.RestController;
- import javax.servlet.http.HttpServletResponse;
- import java.util.List;
- @Slf4j
- @Api(description = "中台", tags = {"清理缓存工具"})
- @RestController
- @RequestMapping("/cache")
- public class CacheController {
- @Autowired
- private ISysOrgService sysOrgService;
- @Autowired
- private ISysUserService userService;
- @GetMapping("/clean/org")
- public Object cleanOrgCache(){
- try {
- sysOrgService.clearOrgCache();
- return "清理成功";
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
- @GetMapping("/clean/user")
- public Object cleanUserCache(){
- try {
- userService.clearUserCache();
- return "清理成功";
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
- @GetMapping("/clean/role")
- public Object cleanRoleCache(){
- try {
- RedisUtils.deleteByPrefix(CacheConstants.ROLE_PERMISSION_CACHE_KEY);
- RedisUtils.deleteByPrefix(CacheConstants.USER_ROLE_PERMISSION_CACHE_KEY);
- return "清理成功";
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
- /**
- * 清楚新增的所有缓存 (清除为优化性能 新增的缓存)
- */
- @GetMapping("/clean/all")
- public Object cleanAllCache(){
- try {
- //用户
- RedisUtils.deleteByPrefix(CacheConstants.USER_CACHE_SINGLE_KEY);
- RedisUtils.deleteByPrefix(CacheConstants.USER_CACHE_ROLE_ID_KEY);
- RedisUtils.deleteByPrefix(CacheConstants.USER_CACHE_ROLE_OBJECT_KEY);
- RedisUtils.deleteByPrefix(CacheConstants.USER_ROLE_PERMISSION_CACHE_KEY);
- //机构
- RedisUtils.deleteByPrefix(CacheConstants.ORG_CACHE_SINGLE_KEY);
- RedisUtils.deleteByPrefix(CacheConstants.ORG_CACHE_CONCAT_NAME);
- RedisUtils.deleteByPrefix(CacheConstants.ORG_EXTEND_CACHE_CONCAT_INFO);
- RedisUtils.deleteByPrefix(CacheConstants.DEPT_TREE_CACHE_SINGLE_KEY);
- RedisUtils.deleteByPrefix(CacheConstants.DEPT_HANGSHE_TREE_CACHE_SINGLE_KEY);
- //角色对应的权限字段
- RedisUtils.deleteByPrefix(CacheConstants.ROLE_PERMISSION_CACHE_KEY);
- return "清理成功";
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
- }
|