| package com.zt.modules.sys.service; | 
|   | 
| import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | 
| import com.zt.common.constant.CacheKey; | 
| import com.zt.common.constant.Constant; | 
| import com.zt.common.service.BaseService; | 
| import com.zt.common.utils.CacheUtils; | 
| import com.zt.core.context.UserContext; | 
| import com.zt.modules.sys.dao.SysRoleDataScopeDao; | 
| import com.zt.modules.sys.model.SysInterface; | 
| import com.zt.modules.sys.model.SysRoleDataScope; | 
| import org.springframework.beans.factory.annotation.Autowired; | 
| import org.springframework.stereotype.Service; | 
| import org.springframework.transaction.annotation.Transactional; | 
|   | 
| import java.util.List; | 
|   | 
| /** | 
|  * 角色数据权限 | 
|  * | 
|  * @author hehz | 
|  * @since 1.0.0 | 
|  */ | 
| @Service | 
| public class SysRoleDataScopeService extends BaseService<SysRoleDataScopeDao, SysRoleDataScope> { | 
|   | 
|     @Autowired | 
|     private SysInterfaceService sysInterfaceService; | 
|   | 
|     /** | 
|      * 获取当前登录人员拥有的数据范围 | 
|      * | 
|      * @param url | 
|      * @return | 
|      */ | 
|     public List<SysRoleDataScope> getDataScopeOrCurrentUser(String url) { | 
|         SysInterface interfaceEntity = sysInterfaceService.getInterfaceByUrl(url); | 
|         if (interfaceEntity == null) { | 
|             return null; | 
|         } | 
|         return baseDao.getAuthorizedDataScope(interfaceEntity.getId(), UserContext.getUser().getRoleIdList()); | 
|     } | 
|   | 
|     /** | 
|      * 根据角色ID,获取数据权限列表 | 
|      * | 
|      * @param roleId | 
|      * @return | 
|      */ | 
|     public List<SysRoleDataScope> getByRoleId(Long roleId) { | 
|         return baseDao.getByRoleId(roleId); | 
|     } | 
|   | 
|     @Transactional(rollbackFor = Exception.class) | 
|     public void saveOrUpdate(Long roleId, List<SysRoleDataScope> list) { | 
|         for (SysRoleDataScope scope : list) { | 
|             scope.setRoleId(roleId); | 
|         } | 
|         this.saveRelatedDatas("role_id", roleId, "field_id", list); | 
|   | 
|     } | 
|   | 
|     /** | 
|      * 根据角色id,删除角色数据权限关系 | 
|      * | 
|      * @param roleIds | 
|      *            角色ids | 
|      */ | 
|     @Transactional(rollbackFor = Exception.class) | 
|     public void deleteByRoleIds(Long[] roleIds) { | 
|         this.deleteLogic(baseDao.selectList(new QueryWrapper<SysRoleDataScope>().lambda().in( | 
|                 SysRoleDataScope::getRoleId, roleIds))); | 
|   | 
|         CacheUtils.removeAll(Constant.Cache.TOKEN);// 清理用户权限缓存 | 
|     } | 
| } |