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.domain.IdEntity;
import lombok.*;
import org.hibernate.annotations.*;
import javax.persistence.CascadeType;
import javax.persistence.*;
import javax.persistence.Entity;
import javax.persistence.OrderBy;
import javax.persistence.Table;
import java.util.ArrayList;
import java.util.List;
/**
* 角色
*
* @author longfei
*/
@Setter
@Getter
@NoArgsConstructor
@AllArgsConstructor(access = AccessLevel.PROTECTED)
@Entity
@DynamicUpdate
@Table(name = "sy_role")
public class Role extends IdEntity {
private static final long serialVersionUID = -5048335552638469901L;
public static final String SYSTEM_ADMIN_ROLE = "ADMIN";
@Column
protected String name;
@Column
protected String descript;
@Builder.Default
@Column
@ColumnDefault("true")
protected boolean enabled = true;
@Builder.Default
@BatchSize(size = 30)
@Fetch(FetchMode.SELECT)
@OneToMany(mappedBy = "role", cascade = CascadeType.ALL, orphanRemoval = true)
protected List userRoles = new ArrayList<>();
@Builder.Default
@JsonIgnoreProperties(value = "roles", allowSetters = true)
@BatchSize(size = 30)
@Fetch(FetchMode.SELECT)
@ManyToMany(cascade = CascadeType.REFRESH)
@JoinTable(
name = "sy_role_res",
joinColumns = {@JoinColumn(name = "role_id")},
inverseJoinColumns = {@JoinColumn(name = "res_id")}
)
@OrderBy("location asc")
protected List resources = new ArrayList<>();
@Builder
public Role(String id, String name, String descript, boolean enabled, List userRoles, List resources) {
super(id);
this.name = name;
this.descript = descript;
this.enabled = enabled;
this.userRoles = userRoles;
this.resources = resources;
}
/**
* 是否超级管理员角色
*/
public boolean isAdminRole() {
return SYSTEM_ADMIN_ROLE.equals(this.name);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy