JcebQueryUtil.java 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. package com.railway.business.catenary.util;
  2. import com.railway.business.catenary.domain.BusJcab;
  3. import com.railway.business.catenary.domain.BusJceb;
  4. import com.railway.business.catenary.domain.vo.JcebQueryParamVo;
  5. import com.railway.business.catenary.domain.vo.JcebQueryVo;
  6. import com.railway.business.catenary.enums.JcebStatusEnum;
  7. import com.railway.common.constant.Constants;
  8. import com.railway.common.core.domain.entity.SysRole;
  9. import com.railway.common.core.domain.entity.SysUser;
  10. import com.railway.common.core.redis.RedisCache;
  11. import com.railway.common.enums.PostTypeEnum;
  12. import com.railway.common.utils.SecurityUtils;
  13. import com.railway.common.utils.StringUtils;
  14. import com.railway.common.utils.spring.SpringUtils;
  15. import com.railway.framework.aspectj.DataScopeAspect;
  16. import java.util.List;
  17. import lombok.extern.slf4j.Slf4j;
  18. import org.apache.commons.collections4.CollectionUtils;
  19. /**
  20. * @author ZhaoMn
  21. */
  22. @Slf4j
  23. public class JcebQueryUtil {
  24. private static JcebQueryParamVo getJcebQuery(){
  25. SysUser user = SecurityUtils.getLoginUser().getUser();
  26. // 管理员全部数据
  27. JcebQueryParamVo jcebQuery = new JcebQueryParamVo();
  28. if(user.isAdmin()){
  29. log.debug("^_^ 管理员设置为查询已提交表 ^_^");
  30. jcebQuery.setSubmitState(JcebStatusEnum.REPORTED.getCode());
  31. jcebQuery.setCreateBy(null);
  32. jcebQuery.setPostType(PostTypeEnum.CENTER.getCode());
  33. return jcebQuery;
  34. }
  35. // 角色数据权限
  36. String scope = DataScopeAspect.DATA_SCOPE_SELF;
  37. PostTypeEnum postType = null;
  38. List<SysRole> roles = user.getRoles();
  39. if(CollectionUtils.isNotEmpty(roles)){
  40. for(SysRole role : roles){
  41. PostTypeEnum tmpPostType = PostTypeEnum.ofRoleName(role.getRoleName());
  42. log.debug("@_@ role.getRoleName = {} ^_^", tmpPostType.getCode());
  43. if(PostTypeEnum.isCateNary(tmpPostType) && role.getDataScope().compareTo(scope) < 0){
  44. scope = role.getDataScope();
  45. postType = tmpPostType;
  46. }
  47. }
  48. }
  49. // 职位
  50. log.debug("^_^ postType = {} ^_^", postType);
  51. if(PostTypeEnum.CENTER == postType) {
  52. log.debug("^_^ 车间领导设置为查询已提交表 ^_^");
  53. jcebQuery.setDeptId(getDeptIdCache(user.getUserId()));
  54. jcebQuery.setSubmitState(JcebStatusEnum.REPORTED.getCode());
  55. jcebQuery.setPostType(PostTypeEnum.CENTER.getCode());
  56. jcebQuery.setCreateBy(null);
  57. }else if(PostTypeEnum.LEADER == postType || scope.equals(DataScopeAspect.DATA_SCOPE_DEPT)
  58. || scope.equals(DataScopeAspect.DATA_SCOPE_DEPT_AND_CHILD)){
  59. jcebQuery.setDeptId(user.getDeptId());
  60. jcebQuery.setSubmitState(JcebStatusEnum.REPORTED.getCode());
  61. jcebQuery.setPostType(PostTypeEnum.LEADER.getCode());
  62. jcebQuery.setCreateBy(null);
  63. }else {
  64. jcebQuery.setCreateBy(user.getUserName());
  65. jcebQuery.setPostType(PostTypeEnum.STAFF.getCode());
  66. }
  67. return jcebQuery;
  68. }
  69. public static void setBusJceb(BusJceb jceb){
  70. JcebQueryParamVo jcebQuery = getJcebQuery();
  71. jceb.setSubmitState(jcebQuery.getSubmitState());
  72. jceb.setDeptId(jcebQuery.getDeptId());
  73. jceb.setCreateBy(jcebQuery.getCreateBy());
  74. }
  75. public static void setBusJcab(BusJcab jcab){
  76. JcebQueryParamVo jcebQuery = getJcebQuery();
  77. jcab.setSubmitState(jcebQuery.getSubmitState());
  78. jcab.setDeptId(jcebQuery.getDeptId());
  79. jcab.setCreateBy(jcebQuery.getCreateBy());
  80. }
  81. public static void setBusJcebQuery(JcebQueryVo query){
  82. log.info("---- JcebQueryVo.submitState = {}", query.getSubmitState());
  83. log.info("---- JcebQueryVo = {}", query);
  84. JcebQueryParamVo jcebQuery = getJcebQuery();
  85. query.setSubmitState(jcebQuery.getSubmitState());
  86. query.setDeptId(jcebQuery.getDeptId());
  87. query.setCreateBy(jcebQuery.getCreateBy());
  88. }
  89. /**
  90. * 获取字典缓存
  91. *
  92. * @param userId 参数键
  93. * @return dictDatas 字典数据列表
  94. */
  95. public static Long getDeptIdCache(Long userId) {
  96. RedisCache redisCache = SpringUtils.getBean(RedisCache.class);
  97. // 从缓存中取本个所选车间
  98. Long deptId = redisCache.getCacheObject(getCacheKey(userId));
  99. if(StringUtils.isEmpty(deptId)) {
  100. // 取默认选择的车间
  101. deptId = redisCache.getCacheObject(Constants.LEADER_VIEW_DEPT_INIT_KEY);
  102. }
  103. return deptId;
  104. }
  105. /**
  106. * 设置cache key
  107. *
  108. * @param configKey 参数键
  109. * @return 缓存键key
  110. */
  111. public static String getCacheKey(Long configKey) {
  112. return Constants.LEADER_VIEW_DEPT_KEY + configKey;
  113. }
  114. }