CacheController.java 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. package com.xunmei.system.controller;
  2. import com.xunmei.common.core.constant.CacheConstants;
  3. import com.xunmei.common.redis.utils.RedisUtils;
  4. import com.xunmei.system.service.ExportSqlService;
  5. import com.xunmei.system.service.ISysOrgService;
  6. import com.xunmei.system.service.ISysUserService;
  7. import io.swagger.annotations.Api;
  8. import lombok.extern.slf4j.Slf4j;
  9. import org.springframework.beans.factory.annotation.Autowired;
  10. import org.springframework.web.bind.annotation.GetMapping;
  11. import org.springframework.web.bind.annotation.RequestMapping;
  12. import org.springframework.web.bind.annotation.RequestParam;
  13. import org.springframework.web.bind.annotation.RestController;
  14. import javax.servlet.http.HttpServletResponse;
  15. import java.util.List;
  16. @Slf4j
  17. @Api(description = "中台", tags = {"清理缓存工具"})
  18. @RestController
  19. @RequestMapping("/cache")
  20. public class CacheController {
  21. @Autowired
  22. private ISysOrgService sysOrgService;
  23. @Autowired
  24. private ISysUserService userService;
  25. @GetMapping("/clean/org")
  26. public Object cleanOrgCache(){
  27. try {
  28. sysOrgService.clearOrgCache();
  29. return "清理成功";
  30. } catch (Exception e) {
  31. throw new RuntimeException(e);
  32. }
  33. }
  34. @GetMapping("/clean/user")
  35. public Object cleanUserCache(){
  36. try {
  37. userService.clearUserCache();
  38. return "清理成功";
  39. } catch (Exception e) {
  40. throw new RuntimeException(e);
  41. }
  42. }
  43. @GetMapping("/clean/role")
  44. public Object cleanRoleCache(){
  45. try {
  46. RedisUtils.deleteByPrefix(CacheConstants.ROLE_PERMISSION_CACHE_KEY);
  47. RedisUtils.deleteByPrefix(CacheConstants.USER_ROLE_PERMISSION_CACHE_KEY);
  48. return "清理成功";
  49. } catch (Exception e) {
  50. throw new RuntimeException(e);
  51. }
  52. }
  53. /**
  54. * 清楚新增的所有缓存 (清除为优化性能 新增的缓存)
  55. */
  56. @GetMapping("/clean/all")
  57. public Object cleanAllCache(){
  58. try {
  59. //用户
  60. RedisUtils.deleteByPrefix(CacheConstants.USER_CACHE_SINGLE_KEY);
  61. RedisUtils.deleteByPrefix(CacheConstants.USER_CACHE_ROLE_ID_KEY);
  62. RedisUtils.deleteByPrefix(CacheConstants.USER_CACHE_ROLE_OBJECT_KEY);
  63. RedisUtils.deleteByPrefix(CacheConstants.USER_ROLE_PERMISSION_CACHE_KEY);
  64. //机构
  65. RedisUtils.deleteByPrefix(CacheConstants.ORG_CACHE_SINGLE_KEY);
  66. RedisUtils.deleteByPrefix(CacheConstants.ORG_CACHE_CONCAT_NAME);
  67. RedisUtils.deleteByPrefix(CacheConstants.ORG_EXTEND_CACHE_CONCAT_INFO);
  68. RedisUtils.deleteByPrefix(CacheConstants.DEPT_TREE_CACHE_SINGLE_KEY);
  69. RedisUtils.deleteByPrefix(CacheConstants.DEPT_HANGSHE_TREE_CACHE_SINGLE_KEY);
  70. //角色对应的权限字段
  71. RedisUtils.deleteByPrefix(CacheConstants.ROLE_PERMISSION_CACHE_KEY);
  72. return "清理成功";
  73. } catch (Exception e) {
  74. throw new RuntimeException(e);
  75. }
  76. }
  77. }