package com.idea.oa.searchuser; import com.rockstar.frame.model.*; import com.rockstar.frame.service.FrameRoleDataService; import com.rockstar.frame.service.FrameRoleDataUserService; import com.rockstar.frame.service.FrameUserService; import com.rockstar.shiro.util.ShiroUtils; import com.rockstar.util.StringUtils; import org.apache.commons.collections.CollectionUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; @Service public class FrameRoleDataUserExtendService { @Autowired private FrameRoleDataUserService frameRoleDataUserService; @Autowired private FrameRoleDataService frameRoleDataService; @Autowired private FrameUserService frameUserService; //人员是否有权限 public boolean userHasRole(String userId,String roleKey){ List roleIds = frameRoleDataUserService.selectRoleDataByUserId(userId); if(roleIds!=null&&roleIds.size()>0){ FrameRoleDataExample frameRoleDataExample = new FrameRoleDataExample(); frameRoleDataExample.createCriteria().andIdIn(roleIds); List frameRoleData = frameRoleDataService.selectByExample(frameRoleDataExample); List roleKeys = frameRoleData.stream().map(FrameRoleData::getRoleKey).collect(Collectors.toList()); if(roleKeys.contains(roleKey)){ return true; }else{ return false; } }else{ return false; } } //获取人员根据角色 public List userByRole(String groupId,List roleKeys){ List collect = new ArrayList<>(); FrameRoleDataExample frameRoleDataExample = new FrameRoleDataExample(); frameRoleDataExample.createCriteria().andRoleTypeEqualTo("DATA").andRoleKeyIn(roleKeys); List frameRoleData = frameRoleDataService.selectByExample(frameRoleDataExample); List roleIds = frameRoleData.stream().map(FrameRoleData::getId).collect(Collectors.toList()); FrameRoleDataUserExample frameRoleDataUserExample = new FrameRoleDataUserExample(); frameRoleDataUserExample.createCriteria().andRoleDataIdIn(roleIds); List frameRoleDataUsers = frameRoleDataUserService.selectByExample(frameRoleDataUserExample); if(CollectionUtils.isNotEmpty(frameRoleDataUsers)){ List userIds = frameRoleDataUsers.stream().map(FrameRoleDataUser::getUserId).collect(Collectors.toList()); if(CollectionUtils.isNotEmpty(userIds)){ FrameUserExample frameUserExample = new FrameUserExample(); frameUserExample.createCriteria().andGroupIdEqualTo(StringUtils.isNotEmpty(groupId)?groupId:ShiroUtils.getUser().getGroupId()).andStatusEqualTo("1"); List frameUserList = frameUserService.selectByExample(frameUserExample); List collect1 = frameUserList.stream().map(FrameUser::getId).collect(Collectors.toList()); collect = collect1.stream().filter(userIds::contains).collect(Collectors.toList()); } } return collect; } }