| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- package com.railway.business.catenary.util;
- import com.railway.business.catenary.domain.BusJcab;
- import com.railway.business.catenary.domain.BusJceb;
- import com.railway.business.catenary.domain.vo.JcebQueryParamVo;
- import com.railway.business.catenary.domain.vo.JcebQueryVo;
- import com.railway.business.catenary.enums.JcebStatusEnum;
- import com.railway.common.constant.Constants;
- import com.railway.common.core.domain.entity.SysRole;
- import com.railway.common.core.domain.entity.SysUser;
- import com.railway.common.core.redis.RedisCache;
- import com.railway.common.enums.PostTypeEnum;
- import com.railway.common.utils.SecurityUtils;
- import com.railway.common.utils.StringUtils;
- import com.railway.common.utils.spring.SpringUtils;
- import com.railway.framework.aspectj.DataScopeAspect;
- import java.util.List;
- import lombok.extern.slf4j.Slf4j;
- import org.apache.commons.collections4.CollectionUtils;
- /**
- * @author ZhaoMn
- */
- @Slf4j
- public class JcebQueryUtil {
- private static JcebQueryParamVo getJcebQuery(){
- SysUser user = SecurityUtils.getLoginUser().getUser();
- // 管理员全部数据
- JcebQueryParamVo jcebQuery = new JcebQueryParamVo();
- if(user.isAdmin()){
- log.debug("^_^ 管理员设置为查询已提交表 ^_^");
- jcebQuery.setSubmitState(JcebStatusEnum.REPORTED.getCode());
- jcebQuery.setCreateBy(null);
- jcebQuery.setPostType(PostTypeEnum.CENTER.getCode());
- return jcebQuery;
- }
- // 角色数据权限
- String scope = DataScopeAspect.DATA_SCOPE_SELF;
- PostTypeEnum postType = null;
- List<SysRole> roles = user.getRoles();
- if(CollectionUtils.isNotEmpty(roles)){
- for(SysRole role : roles){
- PostTypeEnum tmpPostType = PostTypeEnum.ofRoleName(role.getRoleName());
- log.debug("@_@ role.getRoleName = {} ^_^", tmpPostType.getCode());
- if(PostTypeEnum.isCateNary(tmpPostType) && role.getDataScope().compareTo(scope) < 0){
- scope = role.getDataScope();
- postType = tmpPostType;
- }
- }
- }
- // 职位
- log.debug("^_^ postType = {} ^_^", postType);
- if(PostTypeEnum.CENTER == postType) {
- log.debug("^_^ 车间领导设置为查询已提交表 ^_^");
- jcebQuery.setDeptId(getDeptIdCache(user.getUserId()));
- jcebQuery.setSubmitState(JcebStatusEnum.REPORTED.getCode());
- jcebQuery.setPostType(PostTypeEnum.CENTER.getCode());
- jcebQuery.setCreateBy(null);
- }else if(PostTypeEnum.LEADER == postType || scope.equals(DataScopeAspect.DATA_SCOPE_DEPT)
- || scope.equals(DataScopeAspect.DATA_SCOPE_DEPT_AND_CHILD)){
- jcebQuery.setDeptId(user.getDeptId());
- jcebQuery.setSubmitState(JcebStatusEnum.REPORTED.getCode());
- jcebQuery.setPostType(PostTypeEnum.LEADER.getCode());
- jcebQuery.setCreateBy(null);
- }else {
- jcebQuery.setCreateBy(user.getUserName());
- jcebQuery.setPostType(PostTypeEnum.STAFF.getCode());
- }
- return jcebQuery;
- }
- public static void setBusJceb(BusJceb jceb){
- JcebQueryParamVo jcebQuery = getJcebQuery();
- jceb.setSubmitState(jcebQuery.getSubmitState());
- jceb.setDeptId(jcebQuery.getDeptId());
- jceb.setCreateBy(jcebQuery.getCreateBy());
- }
- public static void setBusJcab(BusJcab jcab){
- JcebQueryParamVo jcebQuery = getJcebQuery();
- jcab.setSubmitState(jcebQuery.getSubmitState());
- jcab.setDeptId(jcebQuery.getDeptId());
- jcab.setCreateBy(jcebQuery.getCreateBy());
- }
- public static void setBusJcebQuery(JcebQueryVo query){
- log.info("---- JcebQueryVo.submitState = {}", query.getSubmitState());
- log.info("---- JcebQueryVo = {}", query);
- JcebQueryParamVo jcebQuery = getJcebQuery();
- query.setSubmitState(jcebQuery.getSubmitState());
- query.setDeptId(jcebQuery.getDeptId());
- query.setCreateBy(jcebQuery.getCreateBy());
- }
- /**
- * 获取字典缓存
- *
- * @param userId 参数键
- * @return dictDatas 字典数据列表
- */
- public static Long getDeptIdCache(Long userId) {
- RedisCache redisCache = SpringUtils.getBean(RedisCache.class);
- // 从缓存中取本个所选车间
- Long deptId = redisCache.getCacheObject(getCacheKey(userId));
- if(StringUtils.isEmpty(deptId)) {
- // 取默认选择的车间
- deptId = redisCache.getCacheObject(Constants.LEADER_VIEW_DEPT_INIT_KEY);
- }
- return deptId;
- }
- /**
- * 设置cache key
- *
- * @param configKey 参数键
- * @return 缓存键key
- */
- public static String getCacheKey(Long configKey) {
- return Constants.LEADER_VIEW_DEPT_KEY + configKey;
- }
- }
|