FrameRoleDataUserExtendService.java 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. package com.idea.oa.searchuser;
  2. import com.rockstar.frame.model.*;
  3. import com.rockstar.frame.service.FrameRoleDataService;
  4. import com.rockstar.frame.service.FrameRoleDataUserService;
  5. import com.rockstar.frame.service.FrameUserService;
  6. import com.rockstar.shiro.util.ShiroUtils;
  7. import com.rockstar.util.StringUtils;
  8. import org.apache.commons.collections.CollectionUtils;
  9. import org.springframework.beans.factory.annotation.Autowired;
  10. import org.springframework.stereotype.Service;
  11. import java.util.ArrayList;
  12. import java.util.List;
  13. import java.util.stream.Collectors;
  14. @Service
  15. public class FrameRoleDataUserExtendService {
  16. @Autowired
  17. private FrameRoleDataUserService frameRoleDataUserService;
  18. @Autowired
  19. private FrameRoleDataService frameRoleDataService;
  20. @Autowired
  21. private FrameUserService frameUserService;
  22. //人员是否有权限
  23. public boolean userHasRole(String userId,String roleKey){
  24. List<String> roleIds = frameRoleDataUserService.selectRoleDataByUserId(userId);
  25. if(roleIds!=null&&roleIds.size()>0){
  26. FrameRoleDataExample frameRoleDataExample = new FrameRoleDataExample();
  27. frameRoleDataExample.createCriteria().andIdIn(roleIds);
  28. List<FrameRoleData> frameRoleData = frameRoleDataService.selectByExample(frameRoleDataExample);
  29. List<String> roleKeys = frameRoleData.stream().map(FrameRoleData::getRoleKey).collect(Collectors.toList());
  30. if(roleKeys.contains(roleKey)){
  31. return true;
  32. }else{
  33. return false;
  34. }
  35. }else{
  36. return false;
  37. }
  38. }
  39. //获取人员根据角色
  40. public List<String> userByRole(String groupId,List<String> roleKeys){
  41. List<String> collect = new ArrayList<>();
  42. FrameRoleDataExample frameRoleDataExample = new FrameRoleDataExample();
  43. frameRoleDataExample.createCriteria().andRoleTypeEqualTo("DATA").andRoleKeyIn(roleKeys);
  44. List<FrameRoleData> frameRoleData = frameRoleDataService.selectByExample(frameRoleDataExample);
  45. List<String> roleIds = frameRoleData.stream().map(FrameRoleData::getId).collect(Collectors.toList());
  46. FrameRoleDataUserExample frameRoleDataUserExample = new FrameRoleDataUserExample();
  47. frameRoleDataUserExample.createCriteria().andRoleDataIdIn(roleIds);
  48. List<FrameRoleDataUser> frameRoleDataUsers = frameRoleDataUserService.selectByExample(frameRoleDataUserExample);
  49. if(CollectionUtils.isNotEmpty(frameRoleDataUsers)){
  50. List<String> userIds = frameRoleDataUsers.stream().map(FrameRoleDataUser::getUserId).collect(Collectors.toList());
  51. if(CollectionUtils.isNotEmpty(userIds)){
  52. FrameUserExample frameUserExample = new FrameUserExample();
  53. frameUserExample.createCriteria().andGroupIdEqualTo(StringUtils.isNotEmpty(groupId)?groupId:ShiroUtils.getUser().getGroupId()).andStatusEqualTo("1");
  54. List<FrameUser> frameUserList = frameUserService.selectByExample(frameUserExample);
  55. List<String> collect1 = frameUserList.stream().map(FrameUser::getId).collect(Collectors.toList());
  56. collect = collect1.stream().filter(userIds::contains).collect(Collectors.toList());
  57. }
  58. }
  59. return collect;
  60. }
  61. }