Browse Source

1.优化权限列表查询逻辑

dev_shibei_match
wxz 5 years ago
parent
commit
602e6e0e27
  1. 9
      epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisKeys.java
  2. 62
      epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/service/impl/AccessServiceImpl.java
  3. 10
      epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/AgencyController.java
  4. 21
      epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/redis/CustomerAgencyRedis.java
  5. 2
      epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/AgencyService.java
  6. 18
      epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/AgencyServiceImpl.java
  7. 5
      epmet-user/epmet-user-client/src/main/java/com/epmet/dto/result/GovStaffRoleTemplateDTO.java
  8. 5
      epmet-user/epmet-user-server/src/main/java/com/epmet/entity/GovStaffRoleTemplateEntity.java

9
epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisKeys.java

@ -204,4 +204,13 @@ public class RedisKeys {
public static String getRoleAllOpeScopesKey(String roleId) {
return rootPrefix.concat("gov:access:role:allopescopes:").concat(roleId);
}
/**
* 政府端机关单位缓存Key
* @param agencyId
* @return
*/
public static String getAgencyByIdKey(String agencyId) {
return rootPrefix.concat("gov:agency:").concat(agencyId);
}
}

62
epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/service/impl/AccessServiceImpl.java

@ -7,6 +7,7 @@ import com.epmet.commons.tools.exception.EpmetErrorCode;
import com.epmet.commons.tools.exception.ExceptionUtils;
import com.epmet.commons.tools.exception.RenException;
import com.epmet.commons.tools.security.dto.GovTokenDto;
import com.epmet.commons.tools.security.user.LoginUserUtil;
import com.epmet.commons.tools.utils.CpUserDetailRedis;
import com.epmet.commons.tools.utils.Result;
import com.epmet.constant.OperationScopeConstant;
@ -55,9 +56,13 @@ public class AccessServiceImpl implements AccessService {
@Autowired
private EpmetUserFeignClient userFeignClient;
@Autowired
private LoginUserUtil loginUserUtil;
public static final String ORG_RELATION_SAME = "same";
public static final String ORG_RELATION_SUB = "sub";
public static final String ORG_RELATION_SUP = "sup";
public static final String ORG_PATH_SEPARATOR = ":";
/**
* 更新权限缓存
@ -448,28 +453,42 @@ public class AccessServiceImpl implements AccessService {
@Override
public Set<String> listOperationPermissions(String staffId, String currAgencyId) {
// 1.拿到所属组织机构信息
Result<CustomerAgencyDTO> agencyByStaffRst = govOrgFeignClient.getAgencyByStaff(staffId);
if (!agencyByStaffRst.success()) {
logger.error("根据StaffId查询所属单位出错,StaffId:{}, 错误信息:{}", staffId, agencyByStaffRst.getMsg());
throw new RenException(EpmetErrorCode.SERVER_ERROR.getCode());
GovTokenDto userDetails = getUserDetails(loginUserUtil.getLoginUserApp(), loginUserUtil.getLoginUserClient(), loginUserUtil.getLoginUserId());
if (userDetails == null) {
throw new RenException(EpmetErrorCode.ERR10006.getCode(), EpmetErrorCode.ERR10006.getMsg());
}
CustomerAgencyDTO belongAgency = agencyByStaffRst.getData();
if (belongAgency == null) {
logger.error("根据StaffId查询所属单位结果为空,StaffId:{}", staffId);
throw new RenException(EpmetErrorCode.SERVER_ERROR.getCode());
// 1.拿到所属组织机构信息
String belongAgencyId = getBelongAgencyFromOrgIdPath(userDetails.getOrgIdPath());
Result<CustomerAgencyDTO> belongAgencyRst = govOrgFeignClient.getAgencyById(belongAgencyId);
if (!belongAgencyRst.success()) {
throw new RenException("查询用户的操作权限列表:调用GovOrg,根据belongAgencyId查询机构信息失败:".concat(belongAgencyRst.getInternalMsg()));
}
CustomerAgencyDTO belongAgency = belongAgencyRst.getData();
//Result<CustomerAgencyDTO> agencyByStaffRst = govOrgFeignClient.getAgencyByStaff(staffId);
//if (!agencyByStaffRst.success()) {
// logger.error("根据StaffId查询所属单位出错,StaffId:{}, 错误信息:{}", staffId, agencyByStaffRst.getMsg());
// throw new RenException(EpmetErrorCode.SERVER_ERROR.getCode());
//}
//CustomerAgencyDTO belongAgency = agencyByStaffRst.getData();
//if (belongAgency == null) {
// logger.error("根据StaffId查询所属单位结果为空,StaffId:{}", staffId);
// throw new RenException(EpmetErrorCode.SERVER_ERROR.getCode());
//}
// 2.拿到当前所处机关单位信息
Result<CustomerAgencyDTO> currAgencyRst = govOrgFeignClient.getAgencyById(currAgencyId);
CustomerAgencyDTO currAgencyDto = currAgencyRst.getData();
if (!currAgencyRst.success() || currAgencyDto == null) {
logger.error("根据当前机构id[{}]查询pids失败:{}", currAgencyId, currAgencyRst.getMsg());
throw new RenException(EpmetErrorCode.SERVER_ERROR.getCode());
throw new RenException(String.format("根据当前机构id[%s]查询pids失败:%s", currAgencyId, currAgencyRst.getMsg()));
}
// 查询机关单位中的角色
List<GovStaffRoleDTO> roleDTOS = queryGovStaffRoles(staffId, belongAgency.getId());
// 获取机关单位中的角色
// 目前一个人只在一个单位下,所以不动态查询,如果后面需要一个人在多个单位,再改这里
//List<GovStaffRoleDTO> roleDTOS = queryGovStaffRoles(staffId, belongAgency.getId());
Set<String> roleIdList = userDetails.getRoleIdList();
// 当前组织和所属组织的orgId路径,以及他们的上下级关系
String belongOrgIdPath = getOrgIdPath(belongAgency);
@ -478,13 +497,26 @@ public class AccessServiceImpl implements AccessService {
Set<String> filtedOps = new HashSet<>();
roleDTOS.forEach(roleDTO -> {
List<RoleOpeScopeResultDTO> opeAndScopeDTO = listAllRoleOperationScopesByRoleId(roleDTO.getId());
roleIdList.forEach(roleId -> {
List<RoleOpeScopeResultDTO> opeAndScopeDTO = listAllRoleOperationScopesByRoleId(roleId);
filtedOps.addAll(filterOpesByScope(currOrgRelation, opeAndScopeDTO));
});
return filtedOps;
}
/**
* 从OrgIdPath中取所属机构(即最后一截)
* @param orgIdPath
* @return
*/
private String getBelongAgencyFromOrgIdPath(String orgIdPath) {
if (!orgIdPath.contains(ORG_PATH_SEPARATOR)) {
return orgIdPath;
}
return orgIdPath.substring(orgIdPath.lastIndexOf(ORG_PATH_SEPARATOR + 1));
}
/**
* 获取当前所处机关与所属机关的关系
*/

10
epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/AgencyController.java

@ -169,13 +169,11 @@ public class AgencyController {
*/
@PostMapping("agencybyid/{agencyId}")
public Result<CustomerAgencyDTO> getAgencyById(@PathVariable("agencyId") String agencyId) {
CustomerAgencyEntity agency = agencyService.getAgencyById(agencyId);
CustomerAgencyDTO customerAgencyDTO = new CustomerAgencyDTO();
if (agency != null) {
BeanUtils.copyProperties(agency, customerAgencyDTO);
return new Result<CustomerAgencyDTO>().ok(customerAgencyDTO);
CustomerAgencyDTO agency = agencyService.getAgencyById(agencyId);
if (agency == null) {
agency = new CustomerAgencyDTO();
}
return new Result<>();
return new Result<CustomerAgencyDTO>().ok(agency);
}
/**

21
epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/redis/CustomerAgencyRedis.java

@ -17,9 +17,15 @@
package com.epmet.redis;
import cn.hutool.core.bean.BeanUtil;
import com.epmet.commons.tools.redis.RedisKeys;
import com.epmet.commons.tools.redis.RedisUtils;
import com.epmet.dto.CustomerAgencyDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import java.util.Map;
/**
* 机关单位信息表
@ -36,12 +42,19 @@ public class CustomerAgencyRedis {
}
public void set(){
public void set(String agencyId, CustomerAgencyDTO value){
String key = RedisKeys.getAgencyByIdKey(agencyId);
Map<String, Object> map = BeanUtil.beanToMap(value, false, true);
redisUtils.hMSet(key, map);
}
public String get(String id){
return null;
public CustomerAgencyDTO get(String agencyId){
String key = RedisKeys.getAgencyByIdKey(agencyId);
Map<String, Object> resultMap = redisUtils.hGetAll(key);
if (CollectionUtils.isEmpty(resultMap)) {
return null;
}
return BeanUtil.mapToBean(resultMap, CustomerAgencyDTO.class, true);
}
}

2
epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/AgencyService.java

@ -88,7 +88,7 @@ public interface AgencyService {
* @param agencyId
* @return
*/
CustomerAgencyEntity getAgencyById(String agencyId);
CustomerAgencyDTO getAgencyById(String agencyId);
CustomerAgencyEntity getAgencyByStaff(String staffId);

18
epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/AgencyServiceImpl.java

@ -28,11 +28,13 @@ import com.epmet.dto.CustomerAgencyDTO;
import com.epmet.dto.form.*;
import com.epmet.dto.result.*;
import com.epmet.entity.CustomerAgencyEntity;
import com.epmet.redis.CustomerAgencyRedis;
import com.epmet.service.AgencyService;
import com.epmet.service.CustomerAgencyService;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -53,6 +55,9 @@ public class AgencyServiceImpl implements AgencyService {
@Autowired
private CustomerAgencyService customerAgencyService;
@Autowired
private CustomerAgencyRedis customerAgencyRedis;
/**
* @param formDTO
* @return
@ -241,8 +246,17 @@ public class AgencyServiceImpl implements AgencyService {
}
@Override
public CustomerAgencyEntity getAgencyById(String agencyId) {
return customerAgencyDao.selectById(agencyId);
public CustomerAgencyDTO getAgencyById(String agencyId) {
CustomerAgencyDTO cachedAgency = customerAgencyRedis.get(agencyId);
if (cachedAgency == null) {
cachedAgency = new CustomerAgencyDTO();
CustomerAgencyEntity agencyEntity = customerAgencyDao.selectById(agencyId);
if (agencyEntity != null) {
BeanUtils.copyProperties(agencyEntity, cachedAgency);
}
customerAgencyRedis.set(agencyId, cachedAgency);
}
return cachedAgency;
}
@Override

5
epmet-user/epmet-user-client/src/main/java/com/epmet/dto/result/GovStaffRoleTemplateDTO.java

@ -53,6 +53,11 @@ public class GovStaffRoleTemplateDTO implements Serializable {
*/
private String orgType;
/**
* 是否只有全职
* */
private Boolean fullTimeOnly;
/**
*
*/

5
epmet-user/epmet-user-server/src/main/java/com/epmet/entity/GovStaffRoleTemplateEntity.java

@ -53,4 +53,9 @@ public class GovStaffRoleTemplateEntity extends BaseEpmetEntity {
*/
private String orgType;
/**
* 是否只有全职
* */
private Boolean fullTimeOnly;
}

Loading…
Cancel
Save