UserAuthoricationServiceImpl.java 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. package com.fuzamei.service.serviceImpl;
  2. import java.util.List;
  3. import org.springframework.beans.factory.annotation.Autowired;
  4. import org.springframework.stereotype.Service;
  5. import com.fuzamei.entity.Param;
  6. import com.fuzamei.entity.UserDetail;
  7. import com.fuzamei.mapperInterface.UserAuthoricationMapper;
  8. import com.fuzamei.service.UserAuthoricationService;
  9. @Service
  10. public class UserAuthoricationServiceImpl implements UserAuthoricationService {
  11. @Autowired
  12. private UserAuthoricationMapper userAuthoricationMapper;
  13. @Override
  14. public UserDetail queryUserDetail(Integer userId,String... roleNames) {
  15. UserDetail userDetail = userAuthoricationMapper.queryUserDetail(userId);
  16. if(userDetail==null){
  17. throw new RuntimeException("无此用户");
  18. }
  19. if (roleNames.length!=0) {
  20. String roleName = userDetail.getRoleName();
  21. boolean flag = false;
  22. for (String name : roleNames) {
  23. if (name.equals(roleName)) {
  24. flag = true;
  25. break;
  26. }
  27. }
  28. if (!flag) {
  29. throw new RuntimeException("无权操作");
  30. }
  31. }
  32. return userDetail;
  33. }
  34. @Override
  35. public UserDetail queryUserAuthority(Integer userId, String... roleNames) {
  36. UserDetail userDetail = userAuthoricationMapper.queryUserAuthority(userId);
  37. if(userDetail==null){
  38. throw new RuntimeException("无此用户");
  39. }
  40. if (roleNames.length!=0) {
  41. String roleName = userDetail.getRoleName();
  42. boolean flag = false;
  43. for (String name : roleNames) {
  44. if (name.equals(roleName)) {
  45. flag = true;
  46. break;
  47. }
  48. }
  49. if (!flag) {
  50. throw new RuntimeException("无权操作");
  51. }
  52. }
  53. return userDetail;
  54. }
  55. @Override
  56. public List<UserDetail> showAllCarriersUnderSupplier(Param param) {
  57. return userAuthoricationMapper.showAllCarriersUnderSupplier(param);
  58. }
  59. }