JcebQueryUtil.java 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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(String submitState){
  25. JcebQueryParamVo jcebQuery = new JcebQueryParamVo();
  26. jcebQuery.setSubmitState(submitState);
  27. SysUser user = SecurityUtils.getLoginUser().getUser();
  28. if(JcebStatusEnum.UNREPORTED.getCode().equals(submitState)){
  29. jcebQuery.setCreateBy(String.valueOf(user.getUserId()));
  30. }else {
  31. jcebQuery.setCreateBy(null);
  32. }
  33. // 管理员全部数据
  34. if(user.isAdmin()){
  35. log.debug("^_^ 管理员设置为查询所有 ^_^");
  36. jcebQuery.setPostType(PostTypeEnum.CENTER.getCode());
  37. return jcebQuery;
  38. }
  39. // 角色数据权限
  40. String scope = DataScopeAspect.DATA_SCOPE_SELF;
  41. PostTypeEnum postType = PostTypeEnum.STAFF;
  42. List<SysRole> roles = user.getRoles();
  43. if(CollectionUtils.isNotEmpty(roles)){
  44. for(SysRole role : roles){
  45. PostTypeEnum tmpPostType = PostTypeEnum.ofRoleName(role.getRoleName());
  46. if(PostTypeEnum.isCateNary(tmpPostType) && role.getDataScope().compareTo(scope) < 0){
  47. scope = role.getDataScope();
  48. postType = tmpPostType;
  49. }
  50. }
  51. }
  52. // 职位
  53. log.debug("^_^ postType = {} ^_^", postType);
  54. if(PostTypeEnum.CENTER == postType) {
  55. log.debug("^_^ 中心领导根据选择的车间查询 ^_^");
  56. // jcebQuery.setDeptId(getDeptIdCache(user.getUserId()))
  57. jcebQuery.setPostType(PostTypeEnum.CENTER.getCode());
  58. }else if(PostTypeEnum.LEADER == postType || scope.equals(DataScopeAspect.DATA_SCOPE_DEPT)
  59. || scope.equals(DataScopeAspect.DATA_SCOPE_DEPT_AND_CHILD)){
  60. log.debug("^_^ 车间领导设置为查询已提交表 ^_^");
  61. jcebQuery.setDeptId(user.getDeptId());
  62. jcebQuery.setPostType(PostTypeEnum.LEADER.getCode());
  63. }else {
  64. log.debug("^_^ 车间职工只能查看自己的 ^_^");
  65. jcebQuery.setCreateBy(String.valueOf(user.getUserId()));
  66. jcebQuery.setPostType(PostTypeEnum.STAFF.getCode());
  67. }
  68. return jcebQuery;
  69. }
  70. public static void setBusJceb(BusJceb jceb){
  71. JcebQueryParamVo jcebQuery = getJcebQuery(jceb.getSubmitState());
  72. jceb.setSubmitState(jcebQuery.getSubmitState());
  73. jceb.setDeptId(jcebQuery.getDeptId());
  74. jceb.setCreateBy(jcebQuery.getCreateBy());
  75. }
  76. public static void setBusJcab(BusJcab jcab){
  77. JcebQueryParamVo jcebQuery = getJcebQuery(jcab.getSubmitState());
  78. jcab.setSubmitState(jcebQuery.getSubmitState());
  79. jcab.setDeptId(jcebQuery.getDeptId());
  80. jcab.setCreateBy(jcebQuery.getCreateBy());
  81. }
  82. public static void setBusJcebQuery(JcebQueryVo query){
  83. JcebQueryParamVo jcebQuery = getJcebQuery(query.getSubmitState());
  84. query.setSubmitState(jcebQuery.getSubmitState());
  85. query.setDeptId(jcebQuery.getDeptId());
  86. query.setCreateBy(jcebQuery.getCreateBy());
  87. }
  88. /**
  89. * 获取字典缓存
  90. *
  91. * @param userId 参数键
  92. * @return dictDatas 字典数据列表
  93. */
  94. public static Long getDeptIdCache(Long userId) {
  95. RedisCache redisCache = SpringUtils.getBean(RedisCache.class);
  96. // 从缓存中取本个所选车间
  97. Long deptId = redisCache.getCacheObject(getCacheKey(userId));
  98. if(StringUtils.isEmpty(deptId)) {
  99. // 取默认选择的车间
  100. // deptId = redisCache.getCacheObject(Constants.LEADER_VIEW_DEPT_INIT_KEY)
  101. }
  102. return deptId;
  103. }
  104. /**
  105. * 设置cache key
  106. *
  107. * @param configKey 参数键
  108. * @return 缓存键key
  109. */
  110. public static String getCacheKey(Long configKey) {
  111. return Constants.LEADER_VIEW_DEPT_KEY + configKey;
  112. }
  113. }