User

来源:互联网 发布:淘宝现金返利有那些网 编辑:程序博客网 时间:2024/05/20 06:22
/**
 * 
 */
package com.etong.common.system.domain;


import java.util.Arrays;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;


import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;


import org.hibernate.Query;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.Index;
import org.hibernate.annotations.Type;


import com.etong.common.hibernate.HibernateUtil;
import com.etong.common.system.domain.base.StringIdEntity;
import com.etong.common.system.validator.EntityComment;
import com.etong.common.system.validator.FieldComment;


/**
 */
@EntityComment("用户信息")
@Entity
@Table(name="SYS_USERS"/*, schema="UAWP"*/)
@Cache(usage=CacheConcurrencyStrategy.READ_WRITE)
public class User extends StringIdEntity {


private static final long serialVersionUID = -670056113153233742L;
@FieldComment(value="登录名", required=true)
private String loginName;//登录名

private String password;//密码

private String name;//姓名

private String code;//员工代码
@FieldComment(value="性别", required=true, dict="XB", defaults="0")
private boolean male;//性别

private Date birthday;//出生日期

private String tel;//电话

private String mobile;//手机

private String email;//电子邮箱

private int pageSize;//每页记录数

private Organization organization;//所属机构

private User leader;//领导

private User proxy;//当前代理用户

private boolean proxyEnabled;//是否启用代理

private Set<User> underlings;//下属

private Set<Role> roles;//拥有角色

private Date createDate;//创建时间

private Date updateDate;//修改时间

private Date lastLoginDate;//最后登录时间

private String lastLoginIp;//最后登录IP

private Date expiredDate;//帐户有效期至

private boolean buildin;//是否为系统内建用户

private boolean disabled;//是否禁用

private boolean removed;//是否删除

private int order;//显示顺序


/**
* @return 登录名
*/
@Column(name="login_name", length=32, nullable=false)
public String getLoginName() {
return loginName;
}


/**
* @param loginName 要设置的登录名
*/
public void setLoginName(String loginName) {
this.loginName = loginName;
}


/**
* @return 密码
*/
@Column(length=128, nullable=false)
public String getPassword() {
return password;
}


/**
* @param password 要设置的密码
*/
public void setPassword(String password) {
this.password = password;
}


/**
* @return 姓名
*/
@Column(length=31, nullable=false)
public String getName() {
return name;
}


/**
* @param name 要设置的姓名
*/
public void setName(String name) {
this.name = name;
}


/**
* @return 性别
*/
@Type(type="true_false")
public boolean isMale() {
return male;
}


/**
* @param male 要设置的性别
*/
public void setMale(boolean male) {
this.male = male;
}


/**
* @return 电话
*/
@Column(length=20)
public String getTel() {
return tel;
}


/**
* @param tel 要设置的电话
*/
public void setTel(String tel) {
this.tel = tel;
}


/**
* @return 手机
*/
@Column(length=12)
public String getMobile() {
return mobile;
}


/**
* @param mobile 要设置的手机
*/
public void setMobile(String mobile) {
this.mobile = mobile;
}


/**
* @return 员工代码
*/
@Column(length=10)
public String getCode() {
return code;
}


/**
* @param code 要设置的员工代码
*/
public void setCode(String code) {
this.code = code;
}


/**
* @return 出生日期
*/
@Type(type="date")
public Date getBirthday() {
return birthday;
}


/**
* @param birthday 要设置的出生日期
*/
public void setBirthday(Date birthday) {
this.birthday = birthday;
}


/**
* @return 电子邮箱
*/
@Column(length=63)
public String getEmail() {
return email;
}


/**
* @param email 要设置的电子邮箱
*/
public void setEmail(String email) {
this.email = email;
}


/**
* @return 每页记录数
*/
@Column(name="page_size", nullable=false)
public int getPageSize() {
return pageSize;
}


/**
* @param pageSize 要设置的每页记录数
*/
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}


/**
* @return 显示顺序
*/
@Index(name="IDX_USER_ORDER")
public int getOrder() {
return order;
}


/**
* @param order 要设置的显示顺序
*/
public void setOrder(int order) {
this.order = order;
}


/**
* @return 所属机构
*/
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name="org_id", nullable=false)
public Organization getOrganization() {
return organization;
}


/**
* @param org 要设置的所属机构
*/
public void setOrganization(Organization org) {
this.organization = org;
}


/**
* @return 领导
*/
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name="leader_id")
public User getLeader() {
return leader;
}


/**
* @param leader 要设置的领导
*/
public void setLeader(User leader) {
this.leader = leader;
}


/**
* @return 当前代理用户
*/
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name="proxy_id")
public User getProxy() {
return proxy;
}


/**
* @param proxy 要设置的当前代理用户
*/
public void setProxy(User proxy) {
this.proxy = proxy;
}


/**
* @return 是否启用代理
*/
@Type(type="true_false")
@Column(name="proxy_enabled", nullable=false)
public boolean isProxyEnabled() {
return proxyEnabled;
}


/**
* @param proxyEnabled 要设置的是否启用代理
*/
public void setProxyEnabled(boolean proxyEnabled) {
this.proxyEnabled = proxyEnabled;
}


/**
* @return 下属
*/
@OneToMany(fetch=FetchType.LAZY, mappedBy="leader")
public Set<User> getUnderlings() {
return underlings;
}


/**
* @param underlings 要设置的下属
*/
public void setUnderlings(Set<User> underlings) {
this.underlings = underlings;
}


/**
* @return 拥有角色
*/
@ManyToMany(targetEntity=Role.class, 
fetch=FetchType.LAZY, cascade=CascadeType.MERGE)
@JoinTable(name="SYS_USER_ROLES"/*, schema="UAWP"*/,
joinColumns= {@JoinColumn(name="user_id")}, 
inverseJoinColumns= {@JoinColumn(name="role_id")})
@Cache(usage=CacheConcurrencyStrategy.READ_WRITE)
public Set<Role> getRoles() {
if(roles == null) {
roles = new HashSet<Role>(4);
}
return roles;
}


/**
* @param roles 要设置的拥有角色
*/
public void setRoles(Set<Role> roles) {
this.roles = roles;
}


/**
* @return 创建时间
*/
@Column(name="create_date", nullable=false, updatable=false)
public Date getCreateDate() {
return createDate;
}


/**
* @param createDate 要设置的创建时间
*/
public void setCreateDate(Date createDate) {
this.createDate = createDate;
}


/**
* @return 修改时间
*/
@Column(name="update_date")
public Date getUpdateDate() {
return updateDate;
}


/**
* @param updateDate 要设置的修改时间
*/
public void setUpdateDate(Date updateDate) {
this.updateDate = updateDate;
}


/**
* @return 最后登录时间
*/
@Column(name="login_date")
public Date getLastLoginDate() {
return lastLoginDate;
}


/**
* @param lastLoginDate 要设置的最后登录时间
*/
public void setLastLoginDate(Date lastLoginDate) {
this.lastLoginDate = lastLoginDate;
}


/**
* @return 最后登录IP
*/
@Column(name="login_ip", length=15)
public String getLastLoginIp() {
return lastLoginIp;
}


/**
* @param lastLoginIp 要设置的最后登录IP
*/
public void setLastLoginIp(String lastLoginIp) {
this.lastLoginIp = lastLoginIp;
}


/**
* @return 帐户有效期至
*/
@Column(name="expire_date")
public Date getExpiredDate() {
return expiredDate;
}


/**
* @param expiredDate 要设置的帐户有效期至
*/
public void setExpiredDate(Date expiryDate) {
this.expiredDate = expiryDate;
}


/**
* @return 是否为系统内建用户
*/
@Type(type="true_false")
public boolean isBuildin() {
return buildin;
}


/**
* @param buildin 要设置的是否为系统内建用户
*/
public void setBuildin(boolean buildin) {
this.buildin = buildin;
}


/**
* @return 是否禁用
*/
@Type(type="true_false")
public boolean isDisabled() {
return disabled;
}


/**
* @param disabled 要设置的是否禁用
*/
public void setDisabled(boolean disabled) {
this.disabled = disabled;
}


/**
* @return 是否删除
*/
@Type(type="true_false")
public boolean isRemoved() {
return removed;
}


/**
* @param removed 要设置的是否删除
*/
public void setRemoved(boolean removed) {
this.removed = removed;
}

/**
* 为该用户增加一个角色。
* @param role
*/
public void addRole(Role role) {
this.getRoles().add(role);
role.getUsers().add(this);
}

/**
* 移除该用户的指定角色。
* @param role
*/
public void removeRole(Role role) {
this.getRoles().remove(role);
role.getUsers().remove(this);
}

@Transient
public boolean isExpired() {
return (expiredDate != null && expiredDate.before(new Date()));
}

/**
* 通过比较两个实体的ID是否相等,来判断两个实体是否相等。
* @param entity 进行比较的另一个实体。
* @return 相等返回 true ,不相等返回 false 。
*/
@Override
public boolean equals(Object entity) {
if(entity == this) {
return true;
}
if(entity instanceof User
/*|| !this.getClass().equals(entity.getClass())*/) {
User that = (User)entity;
return (id == null ? that.id == null : id.equals(that.id));
}
return false;
}

/**
* 返回该实体类的字符串描述。
* @return 实体类的字符串描述。
*/
@Override
public String toString() {
return new StringBuilder(User.class.getSimpleName())
.append("@{id=").append(id).append(",loginName=").append(loginName)
.append(",name=").append(name).append(",disabled=").append(disabled)
.append('}').toString();
}


public static void main(String[] args) {
// Page page = new Page(User.class, 1, 10);
// System.out.println(page.getResults());
//
//
// int pageNo = 0, pageSize=1000, size=0;
// do {
//// Page pg = new Page(User.class, pageNo*pageSize, pageSize);
// List<Object> results = null;
// size = results.size();
// } while(size == pageSize + 1);

String sql = "select * from ( select rownumber() over() as rownumber_, u.* from T_SYS_USERS u ) as t where rownumber_ between 1 and 11";
Query q = HibernateUtil.getSession().createSQLQuery(sql);
List<?> rs = q.list();
System.out.println(Arrays.toString((Object[])rs.get(0)));
System.out.println(rs.size());

HibernateUtil.closeSession();
System.exit(0);
}
}
0 0
原创粉丝点击