OrganizationCacheRunner.java 4.3 KB

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