Role.java 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * Copyright 2019-2020 Zheng Jie
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package me.zhengjie.modules.system.domain;
  17. import com.alibaba.fastjson.annotation.JSONField;
  18. import io.swagger.annotations.ApiModelProperty;
  19. import lombok.Getter;
  20. import lombok.Setter;
  21. import me.zhengjie.base.BaseEntity;
  22. import me.zhengjie.utils.enums.DataScopeEnum;
  23. import javax.persistence.*;
  24. import javax.validation.constraints.NotBlank;
  25. import javax.validation.constraints.NotNull;
  26. import java.io.Serializable;
  27. import java.util.Objects;
  28. import java.util.Set;
  29. /**
  30. * 角色
  31. * @author Zheng Jie
  32. * @date 2018-11-22
  33. */
  34. @Getter
  35. @Setter
  36. @Entity
  37. @Table(name = "sys_role")
  38. public class Role extends BaseEntity implements Serializable {
  39. @Id
  40. @Column(name = "role_id")
  41. @NotNull(groups = {Update.class})
  42. // @GeneratedValue(strategy = GenerationType.IDENTITY)
  43. @ApiModelProperty(value = "ID", hidden = true)
  44. private String id;
  45. @JSONField(serialize = false)
  46. @ManyToMany(mappedBy = "roles")
  47. @ApiModelProperty(value = "用户", hidden = true)
  48. private Set<User> users;
  49. @ManyToMany
  50. @JoinTable(name = "sys_roles_menus",
  51. joinColumns = {@JoinColumn(name = "role_id",referencedColumnName = "role_id")},
  52. inverseJoinColumns = {@JoinColumn(name = "menu_id",referencedColumnName = "menu_id")})
  53. @ApiModelProperty(value = "菜单", hidden = true)
  54. private Set<Menu> menus;
  55. @ManyToMany
  56. @JoinTable(name = "sys_roles_depts",
  57. joinColumns = {@JoinColumn(name = "role_id",referencedColumnName = "role_id")},
  58. inverseJoinColumns = {@JoinColumn(name = "dept_id",referencedColumnName = "dept_id")})
  59. @ApiModelProperty(value = "部门", hidden = true)
  60. private Set<Dept> depts;
  61. @NotBlank
  62. @ApiModelProperty(value = "名称", hidden = true)
  63. private String name;
  64. @NotBlank
  65. @ApiModelProperty(value = "角色标识", hidden = true)
  66. @Column(name = "role_key")
  67. private String roleKey;
  68. @ApiModelProperty(value = "数据权限,全部 、 本级 、 自定义")
  69. private String dataScope = DataScopeEnum.THIS_LEVEL.getValue();
  70. @Column(name = "level")
  71. @ApiModelProperty(value = "级别,数值越小,级别越大")
  72. private Integer level = 3;
  73. @ApiModelProperty(value = "描述")
  74. private String description;
  75. @Override
  76. public boolean equals(Object o) {
  77. if (this == o) {
  78. return true;
  79. }
  80. if (o == null || getClass() != o.getClass()) {
  81. return false;
  82. }
  83. Role role = (Role) o;
  84. return Objects.equals(id, role.id);
  85. }
  86. @Override
  87. public int hashCode() {
  88. return Objects.hash(id);
  89. }
  90. }