You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

103 lines
3.4 KiB

8 months ago
4 weeks ago
8 months ago
8 months ago
8 months ago
8 months ago
7 months ago
8 months ago
4 months ago
8 months ago
4 weeks ago
8 months ago
4 weeks ago
8 months ago
4 weeks ago
7 months ago
8 months ago
  1. package com.example.demo.domain.entity;
  2. import com.fasterxml.jackson.annotation.JsonFormat;
  3. import com.fasterxml.jackson.annotation.JsonIgnore;
  4. import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
  5. import jakarta.validation.constraints.NotBlank;
  6. import lombok.Data;
  7. import lombok.NoArgsConstructor;
  8. import org.springframework.security.core.GrantedAuthority;
  9. import org.springframework.security.core.authority.SimpleGrantedAuthority;
  10. import org.springframework.security.core.userdetails.UserDetails;
  11. import java.io.Serializable;
  12. import java.util.*;
  13. @Data
  14. @NoArgsConstructor
  15. @JsonIgnoreProperties(ignoreUnknown = true)
  16. public class Admin implements UserDetails, Serializable {
  17. private static final long serialVersionUID = 1L;
  18. private Integer id; // 主键ID
  19. private String adminName; // 用户姓名
  20. private String account; // 账号
  21. private String password; // 密码
  22. private String machineId; // 机器码,限两个
  23. private List<String > machineIds;//数组机器码
  24. private Byte adminStatus; // 状态(启用/不启用)
  25. private List<String> market; // 地区列表
  26. private String markets; // 地区
  27. private String marketName; // 地区名称
  28. private String roleKey;
  29. private String postiton; // 职位
  30. private String remark; // 备注
  31. @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "Asia/Shanghai")
  32. private Date createTime; // 创建时间
  33. @NotBlank(message = "验证码不能为空")
  34. private String captcha;
  35. @NotBlank(message = "验证码ID不能为空")
  36. private String uuid; // 用于从 Redis 中取验证码
  37. @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "Asia/Shanghai")
  38. private Date updateTime; // 更新时间
  39. private Integer roleId;
  40. @Override
  41. @JsonIgnore
  42. public Collection<? extends GrantedAuthority> getAuthorities() {
  43. Set<GrantedAuthority> authorities = new HashSet<>();
  44. Optional.ofNullable(roleId)
  45. .map(Integer::valueOf)
  46. .ifPresent(permValue -> {
  47. switch (permValue) {
  48. case 1:
  49. authorities.add(new SimpleGrantedAuthority("ROLE_SUPER_ADMIN"));
  50. break;
  51. case 2:
  52. authorities.add(new SimpleGrantedAuthority("ROLE_ADMIN"));
  53. break;
  54. case 3:
  55. authorities.add(new SimpleGrantedAuthority("ROLE_AUDITORS"));
  56. break;
  57. case 5:
  58. authorities.add(new SimpleGrantedAuthority("Branch_Manager"));
  59. break;
  60. default:
  61. // 可以添加默认角色或处理未知权限
  62. break;
  63. }
  64. });
  65. return authorities;
  66. }
  67. @Override
  68. public String getUsername() {
  69. return account;
  70. }
  71. @Override
  72. @JsonIgnore
  73. public boolean isAccountNonExpired() {
  74. return true; // 默认账户未过期
  75. }
  76. @Override
  77. @JsonIgnore
  78. public boolean isAccountNonLocked() {
  79. return true; // 默认账户未锁定
  80. }
  81. @Override
  82. @JsonIgnore
  83. public boolean isCredentialsNonExpired() {
  84. return true; // 默认凭证未过期
  85. }
  86. @Override
  87. @JsonIgnore
  88. public boolean isEnabled() {
  89. return adminStatus != null && adminStatus == 1;
  90. }
  91. }