|  | @ -2,12 +2,14 @@ package com.epmet.service.impl; | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  | import com.epmet.commons.tools.exception.EpmetErrorCode; |  |  | import com.epmet.commons.tools.exception.EpmetErrorCode; | 
			
		
	
		
		
			
				
					|  |  | import com.epmet.commons.tools.exception.RenException; |  |  | import com.epmet.commons.tools.exception.RenException; | 
			
		
	
		
		
			
				
					|  |  |  |  |  | import com.epmet.commons.tools.utils.Result; | 
			
		
	
		
		
			
				
					|  |  | import com.epmet.dao.*; |  |  | import com.epmet.dao.*; | 
			
		
	
		
		
			
				
					|  |  | import com.epmet.dto.result.*; |  |  | import com.epmet.dto.result.*; | 
			
		
	
		
		
			
				
					|  |  | import com.epmet.entity.OperationScopeDefaultEntity; |  |  | import com.epmet.entity.OperationScopeDefaultEntity; | 
			
		
	
		
		
			
				
					|  |  | import com.epmet.entity.RoleOperationDefaultEntity; |  |  | import com.epmet.entity.RoleOperationDefaultEntity; | 
			
		
	
		
		
			
				
					|  |  | import com.epmet.entity.RoleOperationEntity; |  |  | import com.epmet.entity.RoleOperationEntity; | 
			
		
	
		
		
			
				
					|  |  | import com.epmet.entity.RoleScopeEntity; |  |  | import com.epmet.entity.RoleScopeEntity; | 
			
		
	
		
		
			
				
					|  |  |  |  |  | import com.epmet.feign.EpmetUserOpenFeignClient; | 
			
		
	
		
		
			
				
					|  |  | import com.epmet.redis.RoleOpeScopeRedis; |  |  | import com.epmet.redis.RoleOpeScopeRedis; | 
			
		
	
		
		
			
				
					|  |  | import com.epmet.service.AccessConfigService; |  |  | import com.epmet.service.AccessConfigService; | 
			
		
	
		
		
			
				
					|  |  | import org.slf4j.Logger; |  |  | import org.slf4j.Logger; | 
			
		
	
	
		
		
			
				
					|  | @ -41,6 +43,9 @@ public class AccessConfigServiceImpl implements AccessConfigService { | 
			
		
	
		
		
			
				
					|  |  |     @Autowired |  |  |     @Autowired | 
			
		
	
		
		
			
				
					|  |  |     private OperationScopeDefaultDao operationScopeDefaultDao; |  |  |     private OperationScopeDefaultDao operationScopeDefaultDao; | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |  |  |  |     @Autowired | 
			
		
	
		
		
			
				
					|  |  |  |  |  |     private EpmetUserOpenFeignClient epmetUserOpenFeignClient; | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |     @Override |  |  |     @Override | 
			
		
	
		
		
			
				
					|  |  |     public List<AccessConfigOpesResultDTO> listOpesByRole(String roleId) { |  |  |     public List<AccessConfigOpesResultDTO> listOpesByRole(String roleId) { | 
			
		
	
		
		
			
				
					|  |  |         return roleOperationDao.listOpesForAccessConfig(roleId); |  |  |         return roleOperationDao.listOpesForAccessConfig(roleId); | 
			
		
	
	
		
		
			
				
					|  | @ -196,4 +201,56 @@ public class AccessConfigServiceImpl implements AccessConfigService { | 
			
		
	
		
		
			
				
					|  |  |             operationScopeDefaultDao.insert(entity); |  |  |             operationScopeDefaultDao.insert(entity); | 
			
		
	
		
		
			
				
					|  |  |         } |  |  |         } | 
			
		
	
		
		
			
				
					|  |  |     } |  |  |     } | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |  |  |  |     /** | 
			
		
	
		
		
			
				
					|  |  |  |  |  |      * @Description 给角色添加操作权限和操作范围 | 
			
		
	
		
		
			
				
					|  |  |  |  |  |      * @return | 
			
		
	
		
		
			
				
					|  |  |  |  |  |      * @author wxz | 
			
		
	
		
		
			
				
					|  |  |  |  |  |      * @date 2020.11.17 17:41 | 
			
		
	
		
		
			
				
					|  |  |  |  |  |     */ | 
			
		
	
		
		
			
				
					|  |  |  |  |  |     @Override | 
			
		
	
		
		
			
				
					|  |  |  |  |  |     public void addOpeAndScopes4Role(String roleKey, String operationKey, List<String> scopeKeys) { | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         Result<List<GovStaffRoleResultDTO>> rolesResult = epmetUserOpenFeignClient.listRolesByRoleKey(roleKey); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         if (!rolesResult.success()) { | 
			
		
	
		
		
			
				
					|  |  |  |  |  |             String msg = "调用user服务,根据key查询角色列表失败"; | 
			
		
	
		
		
			
				
					|  |  |  |  |  |             throw new RenException(EpmetErrorCode.USER_LIST_ROLES_BY_KEY_FAIL.getCode(), msg, msg, | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                     RenException.MessageMode.CODE_INTERNAL_EXTERNAL.CODE_INTERNAL_EXTERNAL); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         } | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         List<GovStaffRoleResultDTO> roles = rolesResult.getData(); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         List<String> roleIds2Add = roles.stream().map(GovStaffRoleResultDTO::getRoleId).collect(Collectors.toList()); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         addOpeAndScopes4Role(roleIds2Add, operationKey, scopeKeys); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |     } | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |  |  |  |     /** | 
			
		
	
		
		
			
				
					|  |  |  |  |  |      * @Description 将默认的角色操作和范围同步给具体的角色 | 
			
		
	
		
		
			
				
					|  |  |  |  |  |      * @return | 
			
		
	
		
		
			
				
					|  |  |  |  |  |      * @author wxz | 
			
		
	
		
		
			
				
					|  |  |  |  |  |      * @date 2020.11.17 17:38 | 
			
		
	
		
		
			
				
					|  |  |  |  |  |     */ | 
			
		
	
		
		
			
				
					|  |  |  |  |  |     @Transactional(rollbackFor = Exception.class) | 
			
		
	
		
		
			
				
					|  |  |  |  |  |     public void addOpeAndScopes4Role(List<String> roleIds, String operationKey, List<String> scopeKeys) { | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         for (String roleId : roleIds) { | 
			
		
	
		
		
			
				
					|  |  |  |  |  |             // 只给没有添加该权限的用户赋予该权限,已经添加了和添加了又取消的不操作
 | 
			
		
	
		
		
			
				
					|  |  |  |  |  |             RoleOperationEntity roleOpe = roleOperationDao.getRoleOpe(roleId, operationKey); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |             if (roleOpe == null) { | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                 // 没有该操作,则添加
 | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                 RoleOperationEntity roleOperation = new RoleOperationEntity(); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                 roleOperation.setOperationKey(operationKey); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                 roleOperation.setRoleId(roleId); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                 roleOperationDao.insert(roleOperation); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |             } | 
			
		
	
		
		
			
				
					|  |  |  |  |  |             for (String scopeKey : scopeKeys) { | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                 // 没有的话则添加
 | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                 RoleScopeEntity roleScopeInDb = roleScopeDao.getByRoleIdAndOpeKey(roleId, operationKey, scopeKey); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                 if (roleScopeInDb == null) { | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                     RoleScopeEntity roleScopeEntity = new RoleScopeEntity(); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                     roleScopeEntity.setOperationKey(operationKey); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                     roleScopeEntity.setRoleId(roleId); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                     roleScopeEntity.setScopeKey(scopeKey); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                     roleScopeDao.insert(roleScopeEntity); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                 } | 
			
		
	
		
		
			
				
					|  |  |  |  |  |             } | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         } | 
			
		
	
		
		
			
				
					|  |  |  |  |  |     } | 
			
		
	
		
		
			
				
					|  |  | } |  |  | } | 
			
		
	
	
		
		
			
				
					|  | 
 |