package org.sonny.human.entity;
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.GeneratedValue; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.OneToMany; import javax.persistence.OrderBy; import javax.persistence.Table; import javax.persistence.Transient; import javax.persistence.UniqueConstraint; import javax.xml.bind.annotation.AccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlType; import org.hibernate.annotations.GenericGenerator;
import cn.bizos.util.PinYin;
@XmlAccessorType(AccessType.FIELD)
@XmlRootElement(name = "person") @XmlType(name = "", propOrder = {"details"}) @Entity @Table(name = "t_person", uniqueConstraints = { @UniqueConstraint(columnNames = { "id" }) }) public class Person { @XmlAttribute private String account; @XmlAttribute private String domainId; @XmlAttribute
private String ownerId; @XmlAttribute
private boolean share; @XmlAttribute
private int type; @XmlAttribute
private boolean valid; @XmlAttribute
private String id; @XmlAttribute private String chineseName; @XmlAttribute private String engName; @XmlAttribute private String companyName; @XmlAttribute private String department; @XmlAttribute private String extension; @XmlAttribute private String phone; @XmlAttribute private String email; @XmlAttribute private String position; @XmlAttribute private String shortcompany; @XmlAttribute private String companykind; @XmlAttribute private String sortIndex1; @XmlAttribute private String sortIndex2; @XmlAttribute private String image; @XmlAttribute private String sex; private Set<PersonDetail> details = new HashSet<PersonDetail>(); /**
* @roseuid 442205E00223 */ public Person() { } @Transient public String getChineseName() { return this.chineseName; } public void setChineseName(String chineseName) { this.chineseName = chineseName; } @Transient public String getExtension() { return this.extension; } public void setExtension(String extension) { this.extension = extension; } @Transient public String getPhone() { return this.phone; } public void setPhone(String phone) { this.phone = phone; } @Transient public String getEmail() { return this.email; } public void setEmail(String email) { this.email = email; } @Transient public String getPosition() { return this.position; } public void setPosition(String position) { this.position = position; } @Transient public String getEngName() { return this.engName; } public void setEngName(String engName) { this.engName = engName; } @Transient public String getCompanyName() { return this.companyName; } public void setCompanyName(String companyName) { this.companyName = companyName; } @Transient public String getDepartment() { return this.department; } public void setDepartment(String department) { this.department = department; } @Column(name = "account", unique = false, nullable = true, insertable = true, updatable = true, length = 61) public String getAccount() { return account; } public void setAccount(String account) {
this.account = account; } @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinColumn(name="person_id") @OrderBy("type") public Set<PersonDetail> getDetails() { return details; } public void setDetails(Set<PersonDetail> details) {
this.details = details; } @Column(name = "domain_id", unique = false, nullable = false, insertable = true, updatable = true, length = 36)
public String getDomainId() { return domainId; } public void setDomainId(String domainId) {
this.domainId = domainId; } @Id
@GeneratedValue(generator="system-uuid") @GenericGenerator(name="system-uuid", strategy = "uuid") public String getId() { return id; } public void setId(String id) {
this.id = id; } @Column(name = "owner_id", unique = false, nullable = true, insertable = true, updatable = true, length = 36)
public String getOwnerId() { return ownerId; } public void setSex(String sex) { this.sex = sex; } @Column(name = "sex", unique = false, nullable = true, insertable = true, updatable = true, length = 2) public String getSex() { return sex; } public void setOwnerId(String ownerId) { this.ownerId = ownerId; } @Column(name = "share", unique = false, nullable = true, insertable = true, updatable = true)
public boolean isShare() { return share; } public void setShare(boolean share) {
this.share = share; } @Column(name = "type", unique = false, nullable = false, insertable = true, updatable = true)
public int getType() { return type; } public void setType(int type) {
this.type = type; } @Column(name = "valid", unique = false, nullable = false, insertable = true, updatable = true)
public boolean isValid() { return valid; } public void setValid(boolean valid) {
this.valid = valid; } public PersonDetail detailFirstValueByType(int detailType) { PersonDetail result = new PersonDetail(); for(PersonDetail detail : details) { if(detail.getType() == detailType){ result = detail; break; } } return result; } public Set<PersonDetail> detailValuesByType(int detailType) { Set<PersonDetail> pds = new HashSet<PersonDetail>(); for(PersonDetail detail : details) { if(detail.getType() == detailType){ pds.add(detail); } } return pds; } public void initFieldsFromPersonDetail() { this.chineseName = detailFirstValueByType(DetailType.chineseName).getValue(); this.engName = detailFirstValueByType(DetailType.engName).getValue(); this.companyName = detailFirstValueByType(DetailType.companyName).getValue(); this.department = detailFirstValueByType(DetailType.department).getValue(); this.position = detailFirstValueByType(DetailType.position).getValue(); this.extension = detailFirstValueByType(DetailType.extension).getValue(); this.shortcompany = detailFirstValueByType(DetailType.shortcompany).getValue(); this.companykind = detailFirstValueByType(DetailType.companykind).getValue(); this.sortIndex1 = getAccountsByName(companykind); this.sortIndex2 = getAccountsByName(shortcompany); int[] etypes = {20, 21, 22}; PersonDetail detail = null; for(int j = 0; j < etypes.length; j++) { detail = detailFirstValueByType(etypes[j]); if(detail.getValue() != null) { break; } } this.email = detail.getValue(); int[] types = {14, 15, 16, 17, 18, 19}; for(int n = 0; n < types.length; n++) { detail = detailFirstValueByType(types[n]); if(detail.getValue() != null) { break; } } this.phone = detail.getValue(); } @Override public boolean equals(Object obj) { return hashCode() == obj.hashCode(); } @Override
public int hashCode() { int result = 17; result = 37 * result + ( (id == null) ? 0 : id.hashCode() ); return result; } @Column(name = "image", unique = false, nullable = true, insertable = true, updatable = true, length = 500)
public String getImage() { return image; } public void setImage(String image) {
this.image = image; } @Transient public String getShortcompany() { return shortcompany; } public void setShortcompany(String shortcompany) {
this.shortcompany = shortcompany; } @Transient public String getCompanykind() { return companykind; } public void setCompanykind(String companykind) {
this.companykind = companykind; } @Transient public String getSortIndex1() { return sortIndex1; } public void setSortIndex1(String sortIndex1) {
this.sortIndex1 = sortIndex1; } @Transient public String getSortIndex2() { return sortIndex2; } public void setSortIndex2(String sortIndex2) {
this.sortIndex2 = sortIndex2; } private String getAccountsByName(String name) { if(name == null) return ""; PinYin py = new PinYin(); List<String> accounts = py.translate(name); if(accounts != null) { if(accounts.size() > 0) { return accounts.get(0); } } return ""; } } |
|
来自: sonny--李永胜 > 《ejb3.0相关代码及配置》