OrganizationCacheRunner.java 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. package com.xjrsoft.common.runner;
  2. import com.xjrsoft.common.constant.GlobalConstant;
  3. import com.xjrsoft.common.utils.RedisUtil;
  4. import com.xjrsoft.module.base.service.IWhitelistManagementService;
  5. import com.xjrsoft.module.organization.entity.*;
  6. import com.xjrsoft.module.organization.service.*;
  7. import lombok.AllArgsConstructor;
  8. import lombok.extern.slf4j.Slf4j;
  9. import org.springframework.boot.CommandLineRunner;
  10. import org.springframework.scheduling.annotation.Async;
  11. import org.springframework.stereotype.Component;
  12. import java.util.List;
  13. /**
  14. * 组织架构缓存
  15. *
  16. * @Author: tzx
  17. * @Date: 2022/12/6 14:50
  18. */
  19. @Component
  20. @AllArgsConstructor
  21. @Slf4j
  22. public class OrganizationCacheRunner implements CommandLineRunner {
  23. private RedisUtil redisUtil;
  24. private IUserService userService;
  25. private IDepartmentService departmentService;
  26. private IRoleService roleService;
  27. private IPostService postService;
  28. private IUserRoleRelationService userRoleRelationService;
  29. private IUserDeptRelationService userDeptRelationService;
  30. private IUserPostRelationService userPostRelationService;
  31. private IWhitelistManagementService whitelistManagementService;
  32. @Override
  33. public void run(String... args) {
  34. loadUserCache();
  35. loadDeptCache();
  36. loadRoleCache();
  37. loadPostCache();
  38. loadUserRoleRelationCache();
  39. loadUserDepartmentRelationCache();
  40. loadUserPostRelationCache();
  41. whitelistManagementService.loadCaches();
  42. }
  43. @Async
  44. void loadUserCache() {
  45. log.info("XJRSOFT: 加载所有用户表缓存开始");
  46. List<User> list = userService.lambdaQuery()
  47. .select(User.class, user -> !user.getColumn().equals("avatar")) //排除头像信息
  48. .list();
  49. redisUtil.set(GlobalConstant.USER_CACHE_KEY, list);
  50. log.info("XJRSOFT: 加载所有用户表缓存结束");
  51. }
  52. @Async
  53. void loadDeptCache() {
  54. log.info("XJRSOFT: 加载所有机构表缓存开始");
  55. List<Department> list = departmentService.list();
  56. redisUtil.set(GlobalConstant.DEP_CACHE_KEY, list);
  57. log.info("XJRSOFT: 加载所有机构表缓存结束");
  58. }
  59. @Async
  60. void loadRoleCache() {
  61. log.info("XJRSOFT: 加载所有角色表缓存开始");
  62. List<Role> list = roleService.list();
  63. redisUtil.set(GlobalConstant.ROLE_CACHE_KEY, list);
  64. log.info("XJRSOFT: 加载所有角色表缓存结束");
  65. }
  66. @Async
  67. void loadPostCache() {
  68. log.info("XJRSOFT: 加载所有岗位表缓存开始");
  69. List<Post> list = postService.list();
  70. redisUtil.set(GlobalConstant.POST_CACHE_KEY, list);
  71. log.info("XJRSOFT: 加载所有岗位表缓存结束");
  72. }
  73. @Async
  74. void loadUserRoleRelationCache() {
  75. log.info("XJRSOFT: 加载所有用户角色关联表缓存开始");
  76. List<UserRoleRelation> list = userRoleRelationService.list();
  77. redisUtil.set(GlobalConstant.USER_ROLE_RELATION_CACHE_KEY, list);
  78. log.info("XJRSOFT: 加载所有用户角色关联表缓存结束");
  79. }
  80. void loadUserDepartmentRelationCache() {
  81. log.info("XJRSOFT: 加载所有用户部门关联表缓存开始");
  82. List<UserDeptRelation> deptRelationList = userDeptRelationService.list();
  83. redisUtil.set(GlobalConstant.USER_DEPT_RELATION_CACHE_KEY, deptRelationList);
  84. log.info("XJRSOFT: 加载所有用户部门关联表缓存结束");
  85. }
  86. void loadUserPostRelationCache() {
  87. log.info("XJRSOFT: 加载所有用户岗位关联表缓存开始");
  88. List<UserPostRelation> postRelationList = userPostRelationService.list();
  89. redisUtil.set(GlobalConstant.USER_POST_RELATION_CACHE_KEY, postRelationList);
  90. log.info("XJRSOFT: 加载所有用户岗位关联表缓存结束");
  91. }
  92. }