1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- 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<String> roleIds = frameRoleDataUserService.selectRoleDataByUserId(userId);
- if(roleIds!=null&&roleIds.size()>0){
- FrameRoleDataExample frameRoleDataExample = new FrameRoleDataExample();
- frameRoleDataExample.createCriteria().andIdIn(roleIds);
- List<FrameRoleData> frameRoleData = frameRoleDataService.selectByExample(frameRoleDataExample);
- List<String> roleKeys = frameRoleData.stream().map(FrameRoleData::getRoleKey).collect(Collectors.toList());
- if(roleKeys.contains(roleKey)){
- return true;
- }else{
- return false;
- }
- }else{
- return false;
- }
- }
- //获取人员根据角色
- public List<String> userByRole(String groupId,List<String> roleKeys){
- List<String> collect = new ArrayList<>();
- FrameRoleDataExample frameRoleDataExample = new FrameRoleDataExample();
- frameRoleDataExample.createCriteria().andRoleTypeEqualTo("DATA").andRoleKeyIn(roleKeys);
- List<FrameRoleData> frameRoleData = frameRoleDataService.selectByExample(frameRoleDataExample);
- List<String> roleIds = frameRoleData.stream().map(FrameRoleData::getId).collect(Collectors.toList());
- FrameRoleDataUserExample frameRoleDataUserExample = new FrameRoleDataUserExample();
- frameRoleDataUserExample.createCriteria().andRoleDataIdIn(roleIds);
- List<FrameRoleDataUser> frameRoleDataUsers = frameRoleDataUserService.selectByExample(frameRoleDataUserExample);
- if(CollectionUtils.isNotEmpty(frameRoleDataUsers)){
- List<String> 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<FrameUser> frameUserList = frameUserService.selectByExample(frameUserExample);
- List<String> collect1 = frameUserList.stream().map(FrameUser::getId).collect(Collectors.toList());
- collect = collect1.stream().filter(userIds::contains).collect(Collectors.toList());
- }
- }
- return collect;
- }
- }
|