现在的位置: 首页 > 综合 > 正文

购物网站5:产品设计–品牌—-产品信息—产品样式—产品类型—-性别

2014年02月15日 ⁄ 综合 ⁄ 共 11317字 ⁄ 字号 评论关闭

@Entity @Searchable(root=false)
public class Brand implements Serializable{
 private static final long serialVersionUID = -4540465642606278764L;
 private String code;
 /** 品牌名称 **/
 private String name;
 /** 是否可见 **/
 private Boolean visible = true;
 /** logo图片路径 如:/images/brand/2008/12/12/ooo.gif" **/
 private String logopath;
 
 public Brand(String code) {
  this.code = code;
 }

 public Brand() {}
 
 public Brand(String name, String logopath) {
  this.name = name;
  this.logopath = logopath;
 }
 
 @Id @Column(length=36) @SearchableProperty(index=Index.NO, store=Store.YES)
 public String getCode() {
  return code;
 }
 public void setCode(String code) {
  this.code = code;
 }
 @Column(length=40, nullable=false) @SearchableProperty(name="brandName", index=Index.NO, store=Store.YES)
 public String getName() {
  return name;
 }
 public void setName(String name) {
  this.name = name;
 }
 @Column(nullable=false)
 public Boolean getVisible() {
  return visible;
 }
 public void setVisible(Boolean visible) {
  this.visible = visible;
 }
 @Column(length=80)
 public String getLogopath() {
  return logopath;
 }
 public void setLogopath(String logopath) {
  this.logopath = logopath;
 }
 
 @Override
 public int hashCode() {
  final int prime = 31;
  int result = 1;
  result = prime * result + ((code == null) ? 0 : code.hashCode());
  return result;
 }
 @Override
 public boolean equals(Object obj) {
  if (this == obj)
   return true;
  if (obj == null)
   return false;
  if (getClass() != obj.getClass())
   return false;
  final Brand other = (Brand) obj;
  if (code == null) {
   if (other.code != null)
    return false;
  } else if (!code.equals(other.code))
   return false;
  return true;
 }
}

 

---------------------------------------------------------------

 

@Entity @Searchable //定义ProductInfo跟lucene中的document进映射
public class ProductInfo implements Serializable{
 private static final long serialVersionUID = -8860864584425256200L;
 private Integer id;
 /** 货号 **/
 private String code;
 /** 产品名称 **/
 private String name;
 /** 品牌 **/
 private Brand brand;
 /** 型号 **/
 private String model;
 /** 底价(采购进来的价格) **/
 private Float baseprice;
 /** 市场价 **/
 private Float marketprice;
 /** 销售价 **/
 private Float sellprice;
 /** 重量 单位:克 **/
 private Integer weight;
 /** 产品简介 **/
 private String description;
 /** 购买说明 **/
 private String buyexplain;
 /** 是否可见 **/
 private Boolean visible = true;
 /** 产品类型 **/
 private ProductType type;
 /** 上架日期 **/
 private Date createdate = new Date();
 /** 人气指数 **/
 private Integer clickcount = 1;
 /** 销售量 **/
 private Integer sellcount = 0;
 /** 是否推荐 **/
 private Boolean commend = false;
 /** 性别要求 **/
 private Sex sexrequest = Sex.NONE;
 /** 产品样式 **/
 private Set<ProductStyle> styles = new HashSet<ProductStyle>();
 
 public ProductInfo(Integer id) {
  this.id = id;
 }
 public ProductInfo() {}
 
 @Transient
 public Float getSavedPrice(){
  return marketprice-sellprice;
 }
 
 @OneToMany(cascade={CascadeType.REMOVE,CascadeType.PERSIST}, mappedBy="product", fetch=FetchType.EAGER)
 @OrderBy("visible desc, id asc") @SearchableComponent
 public Set<ProductStyle> getStyles() {
  return styles;
 }
 public void setStyles(Set<ProductStyle> styles) {
  this.styles = styles;
 }
 /**
  * 从样式集合中删除指定样式
  * @param style
  */
 public void removeProductStyle(ProductStyle style){
  if(this.styles.contains(style)){
   this.styles.remove(style);
   style.setProduct(null);
  }
 } 
 /**
  * 添加样式到样式集合
  * @param style
  */
 public void addProductStyle(ProductStyle style){
  if(!this.styles.contains(style)){
   this.styles.add(style);
   style.setProduct(this);
  }
 }
 
 @Id @GeneratedValue @SearchableId //和JPA/Hibernate一样,每个搜索实体bean都必须有一个标识属性
 public Integer getId() {
  return id;
 }
 public void setId(Integer id) {
  this.id = id;
 }
 @Column(length=30)
 public String getCode() {
  return code;
 }
 public void setCode(String code) {
  this.code = code;
 }
 @Column(length=50,nullable=false) @SearchableProperty(name="productName", boost=2)
 public String getName() {
  return name;
 }
 public void setName(String name) {
  this.name = name;
 }
 @ManyToOne(cascade=CascadeType.REFRESH)
 @JoinColumn(name="brandid") @SearchableComponent
 public Brand getBrand() {
  return brand;
 }
 public void setBrand(Brand brand) {
  this.brand = brand;
 }
 @Column(length=20) @SearchableProperty(index=Index.NO,store=Store.YES)
 public String getModel() {
  return model;
 }
 public void setModel(String model) {
  this.model = model;
 }
 @Column(nullable=false)
 public Float getBaseprice() {
  return baseprice;
 }
 public void setBaseprice(Float baseprice) {
  this.baseprice = baseprice;
 }
 @Column(nullable=false)  @SearchableProperty(index=Index.NO,store=Store.YES)
 public Float getMarketprice() {
  return marketprice;
 }
 public void setMarketprice(Float marketprice) {
  this.marketprice = marketprice;
 }
 @Column(nullable=false)  @SearchableProperty(index=Index.NO,store=Store.YES)
 public Float getSellprice() {
  return sellprice;
 }
 public void setSellprice(Float sellprice) {
  this.sellprice = sellprice;
 }
 @SearchableProperty(index=Index.NO,store=Store.YES)
 public Integer getWeight() {
  return weight;
 }
 public void setWeight(Integer weight) {
  this.weight = weight;
 }
 @Lob @Column(nullable=false) @SearchableProperty
 public String getDescription() {
  return description;
 }
 public void setDescription(String description) {
  this.description = description;
 }
 @Column(length=30)  @SearchableProperty(index=Index.NO,store=Store.YES)
 public String getBuyexplain() {
  return buyexplain;
 }
 public void setBuyexplain(String buyexplain) {
  this.buyexplain = buyexplain;
 }
 @Column(nullable=false)
 public Boolean getVisible() {
  return visible;
 }
 public void setVisible(Boolean visible) {
  this.visible = visible;
 }
 @ManyToOne(cascade=CascadeType.REFRESH,optional=false)
 @JoinColumn(name="typeid") @SearchableComponent
 public ProductType getType() {
  return type;
 }
 public void setType(ProductType type) {
  this.type = type;
 }
 @Temporal(TemporalType.DATE)
 public Date getCreatedate() {
  return createdate;
 }
 public void setCreatedate(Date createdate) {
  this.createdate = createdate;
 }
 @Column(nullable=false)
 public Integer getClickcount() {
  return clickcount;
 }
 public void setClickcount(Integer clickcount) {
  this.clickcount = clickcount;
 }
 @Column(nullable=false)
 public Integer getSellcount() {
  return sellcount;
 }
 public void setSellcount(Integer sellcount) {
  this.sellcount = sellcount;
 }
 @Column(nullable=false)
 public Boolean getCommend() {
  return commend;
 }
 public void setCommend(Boolean commend) {
  this.commend = commend;
 }
 @Enumerated(EnumType.STRING) @Column(length=5,nullable=false)
 public Sex getSexrequest() {
  return sexrequest;
 }
 public void setSexrequest(Sex sexrequest) {
  this.sexrequest = sexrequest;
 }
 
 @Override
 public int hashCode() {
  final int prime = 31;
  int result = 1;
  result = prime * result + ((id == null) ? 0 : id.hashCode());
  return result;
 }
 @Override
 public boolean equals(Object obj) {
  if (this == obj)
   return true;
  if (obj == null)
   return false;
  if (getClass() != obj.getClass())
   return false;
  final ProductInfo other = (ProductInfo) obj;
  if (id == null) {
   if (other.id != null)
    return false;
  } else if (!id.equals(other.id))
   return false;
  return true;
 }
}

 

 

-----------------------------------------------------------------

 

 

@Entity @Searchable(root=false)
public class ProductStyle implements Serializable{
 private static final long serialVersionUID = -4926119953511144279L;
 private Integer id;
 /** 样式的名称 **/
 private String name;
 /** 图片 **/
 private String imagename;
 /** 是否可见 **/
 private Boolean visible = true;
 private ProductInfo product;
 
 public ProductStyle() {}
 
 public ProductStyle(Integer id) {
  this.id = id;
 }

 public ProductStyle(String name, String imagename) {
  this.name = name;
  this.imagename = imagename;
 }
 @ManyToOne(cascade=CascadeType.REFRESH,optional=false)
 @JoinColumn(name="productid") @SearchableReference
 public ProductInfo getProduct() {
  return product;
 }
 public void setProduct(ProductInfo product) {
  this.product = product;
 }
 @Id @GeneratedValue @SearchableProperty(index=Index.NO, store=Store.YES)
 public Integer getId() {
  return id;
 }
 public void setId(Integer id) {
  this.id = id;
 }
 @Column(length=30,nullable=false) @SearchableProperty(name="sytleName", index=Index.NO, store=Store.YES)
 public String getName() {
  return name;
 }
 public void setName(String name) {
  this.name = name;
 }
 @Column(length=40,nullable=false) @SearchableProperty(index=Index.NO, store=Store.YES)
 public String getImagename() {
  return imagename;
 }
 public void setImagename(String imagename) {
  this.imagename = imagename;
 }
 @Column(nullable=false)
 public Boolean getVisible() {
  return visible;
 }
 public void setVisible(Boolean visible) {
  this.visible = visible;
 }
 @Transient
 public String getImageFullPath(){
  return "/images/product/"+ this.getProduct().getType().getTypeid()+ "/"+
  this.getProduct().getId()+ "/prototype/"+ this.imagename;
 }
 @Transient
 public String getImage140FullPath(){
  return "/images/product/"+ this.getProduct().getType().getTypeid()+ "/"+
  this.getProduct().getId()+ "/140x/"+ this.imagename;
 }
 
 @Override
 public int hashCode() {
  final int prime = 31;
  int result = 1;
  result = prime * result + ((id == null) ? 0 : id.hashCode());
  return result;
 }
 @Override
 public boolean equals(Object obj) {
  if (this == obj)
   return true;
  if (obj == null)
   return false;
  if (getClass() != obj.getClass())
   return false;
  final ProductStyle other = (ProductStyle) obj;
  if (id == null) {
   if (other.id != null)
    return false;
  } else if (!id.equals(other.id))
   return false;
  return true;
 }
}

 

 

 

-------------------------------------------------------------

 

 

@Entity @Searchable(root=false)
public class ProductType implements Serializable{
 private static final long serialVersionUID = 8106351120886053881L;
 /** 类别id **/
 private Integer typeid;
 /** 类别名称 **/
 private String name;
 /** 备注,用于google搜索页面描述 **/
 private String note;
 /** 是否可见 **/
 private Boolean visible = true;
 /** 子类别 **/
 private Set<ProductType> childtypes = new HashSet<ProductType>();
 /** 所属父类 **/
 private ProductType parent;
 
 private Set<ProductInfo> products = new HashSet<ProductInfo>();
 
 @OneToMany(mappedBy="type", cascade=CascadeType.REMOVE)
 public Set<ProductInfo> getProducts() {
  return products;
 }

 public void setProducts(Set<ProductInfo> products) {
  this.products = products;
 }

 public ProductType() {}
 
 public ProductType(Integer typeid) {
  this.typeid = typeid;
 }

 public ProductType(String name, String note) {
  this.name = name;
  this.note = note;
 }
 @ManyToOne(cascade=CascadeType.REFRESH)
 @JoinColumn(name="parentid")
 public ProductType getParent() {
  return parent;
 }

 public void setParent(ProductType parent) {
  this.parent = parent;
 }
 @OneToMany(cascade={CascadeType.REFRESH,CascadeType.REMOVE},mappedBy="parent")
 public Set<ProductType> getChildtypes() {
  return childtypes;
 }

 public void setChildtypes(Set<ProductType> childtypes) {
  this.childtypes = childtypes;
 }

 @Column(length=36,nullable=false) @SearchableProperty(name="typeName", index=Index.NO, store=Store.YES)
 public String getName() {
  return name;
 }

 public void setName(String name) {
  this.name = name;
 }

 @Column(length=200)
 public String getNote() {
  return note;
 }

 public void setNote(String note) {
  this.note = note;
 }

 @Column(nullable=false)
 public Boolean getVisible() {
  return visible;
 }

 public void setVisible(Boolean visible) {
  this.visible = visible;
 }

 @Id @GeneratedValue(strategy=GenerationType.AUTO) @SearchableProperty(index=Index.NO, store=Store.YES)
 public Integer getTypeid() {
  return typeid;
 }

 public void setTypeid(Integer typeid) {
  this.typeid = typeid;
 }

 @Override
 public int hashCode() {
  final int prime = 31;
  int result = 1;
  result = prime * result + ((typeid == null) ? 0 : typeid.hashCode());
  return result;
 }

 @Override
 public boolean equals(Object obj) {
  if (this == obj)
   return true;
  if (obj == null)
   return false;
  if (getClass() != obj.getClass())
   return false;
  final ProductType other = (ProductType) obj;
  if (typeid == null) {
   if (other.typeid != null)
    return false;
  } else if (!typeid.equals(other.typeid))
   return false;
  return true;
 }
}

 

 

------------------------------------------------------------------

 

 

public enum Sex {
 NONE{public String getName(){return "男女不限";} },
 MAN{public String getName(){return "男";} },
 WOMEN{public String getName(){return "女";}};
 public abstract String getName();
}

抱歉!评论已关闭.