com.feingto.cloud.domain.account.Role Maven / Gradle / Ivy
package com.feingto.cloud.domain.account;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.feingto.cloud.data.jpa.entity.IdEntity;
import com.feingto.cloud.domain.enums.RoleType;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.hibernate.annotations.ColumnDefault;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
import javax.persistence.*;
import javax.validation.constraints.NotBlank;
import java.util.ArrayList;
import java.util.List;
/**
* 角色
*
* @author longfei
*/
@Data
@EqualsAndHashCode(callSuper = true)
@Accessors(chain = true)
@Entity
@DynamicUpdate
@Table(name = "sy_role")
public class Role extends IdEntity {
@Column(nullable = false, length = 64)
private String name;
@NotBlank(message = "角色标识不能为空")
@Column(length = 32, nullable = false)
private String sn;
@Column
private String description;
@Column
@ColumnDefault("true")
private boolean enabled = true;
@Fetch(FetchMode.SUBSELECT)
@OneToMany(mappedBy = "role", cascade = CascadeType.ALL, orphanRemoval = true)
private List userRoles = new ArrayList<>();
@JsonIgnoreProperties(value = "roles", allowSetters = true)
@Fetch(FetchMode.SUBSELECT)
@ManyToMany(cascade = CascadeType.REFRESH)
@JoinTable(name = "sy_role_res",
joinColumns = {@JoinColumn(name = "role_id")},
inverseJoinColumns = {@JoinColumn(name = "res_id")})
@OrderBy("location asc")
private List resources = new ArrayList<>();
/**
* 是否超级管理员角色
*/
public boolean isAdminRole() {
return RoleType.ADMIN.name().equals(this.sn);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy