我加的属性有点多,可以根据你的实际情况去掉部分代码。
其中,lft/rgt是专门优化Tree查询的,可以不使用递归,一次查找,就能拿到整棵树。
总之,偏实战的代码。
open class Tree (id: Long,
parentId: Long? = null,
lft: Int? = null, // left position
rgt: Int? = null, // right position
depth: Int? = null, // level, root node level = 1
leaf: Boolean? = null, / / is the leaf node (front-end get this property's value, then can use to show whether to extension the menu)
teamTotal: Int? = null, // number of teams (all subordinates)
childrenTotal: Int? = null) // The number of immediate subordinates
enum class Position {
LEFT, RIGHT, DOWN
}
data class User(
// inherits from UserDetails
private val username: String,
private val password: String,
private val isEnabled: Boolean, //Disabled account can not log in
private val isCredentialsNonExpired: Boolean, //credential can be expired,eg. Change the password every three months
private val isAccountNonExpired: Boolean, //eg. Demo account(guest) can only be online 24 hours
private val isAccountNonLocked: Boolean, //eg. Users who malicious attack system,lock their account for one year
private val authorities: Set<GrantedAuthority>,
// inherits from Tree.If the user is not a tree structure, can be ignored
val id: Long,
val parentId: Long? = null,
val lft: Int? = null, // preorder tree traversal algorithm
val rgt: Int? = null, // preorder tree traversal algorithm
val depth: Int? = null, // or levels
val isLeaf: Boolean? = null,
val teamTotal: Int? = null, // The number of all subordinates
val childrenTotal: Int? = null, //The number of all directly under the subordinate
//Custom attributes
val tenantId: Long, //We are the platform + tenant model
val role: Set<Role>, // TENANT, SUBACCOUNT, DEFAULT_GROUP, MEMBER, GUEST
val platform: Platform, // PC, IOS, ANDROID, WAP, INTERNAL
val deviceToken: String? = null, //or machine code
val ip: InetAddress //Inet4Address or Inet6Address
) : UserDetails, Tree(id, parentId) {
override fun getUsername(): String = username
override fun getPassword(): String = password
override fun isEnabled(): Boolean = isEnabled
override fun isCredentialsNonExpired(): Boolean = isCredentialsNonExpired
override fun isAccountNonExpired(): Boolean = isAccountNonExpired
override fun isAccountNonLocked(): Boolean = isAccountNonLocked
override fun getAuthorities(): Set<out GrantedAuthority> = authorities
}