欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

购物网-->>订单模块中的几个实体

程序员文章站 2022-04-04 12:14:46
...
订单的状态

/**
* 订单状态
*
*/
public enum OrderState {

/** 已取消 */
CANCEL {public String getName(){return "已取消";}},
/** 待审核 */
WAITCONFIRM {public String getName(){return "待审核";}},
/** 等待付款 */
WAITPAYMENT {public String getName(){return "等待付款";}},
/** 正在配货 */
ADMEASUREPRODUCT {public String getName(){return "正在配货";}},
/** 等待发货 */
WAITDELIVER {public String getName(){return "等待发货";}},
/** 已发货 */
DELIVERED {public String getName(){return "已发货";}},
/** 已收货 */
RECEIVED {public String getName(){return "已收货";}};

public abstract String getName();
}


订单实体

/**
* 订单
*/
@Entity @Table(name="t_order")
public class Order {
/* 订单号 */
private String orderid;
/* 所属用户 */
private Buyer buyer;
/* 订单创建时间 */
private Date createDate = new Date();
/* 订单状态 */
private OrderState state;
/* 商品总金额 */
private Float productTotalPrice = 0f;
/* 配送费 */
private Float deliverFee = 0f;
/* 订单总金额 */
private Float totalPrice= 0f;
/* 应付款(实际需要支付的费用) */
private Float payablefee = 0f;
/* 顾客附言 */
private String note;
/* 支付方式 */
private PaymentWay paymentWay;
/* 支付状态 */
private Boolean paymentstate = false;
/* 订单配送信息 */
private OrderDeliverInfo orderDeliverInfo;
/* 订单购买者联系信息 */
private OrderContactInfo orderContactInfo;
/* 订单项 */
private Set<OrderItem> items = new HashSet<OrderItem>();

@Id @Column(length=14)
public String getOrderid() {
return orderid;
}
public void setOrderid(String orderid) {
this.orderid = orderid;
}
@ManyToOne(cascade=CascadeType.REFRESH, optional=false)
@JoinColumn(name="username")
public Buyer getBuyer() {
return buyer;
}
public void setBuyer(Buyer buyer) {
this.buyer = buyer;
}
@Temporal(TemporalType.TIMESTAMP) @Column(nullable=false)
public Date getCreateDate() {
return createDate;
}
public void setCreateDate(Date createDate) {
this.createDate = createDate;
}
@Enumerated(EnumType.STRING) @Column(length=16, nullable=false)
public OrderState getState() {
return state;
}
public void setState(OrderState state) {
this.state = state;
}
@Column(nullable=false)
public Float getProductTotalPrice() {
return productTotalPrice;
}
public void setProductTotalPrice(Float productTotalPrice) {
this.productTotalPrice = productTotalPrice;
}
@Column(nullable=false)
public Float getDeliverFee() {
return deliverFee;
}
public void setDeliverFee(Float deliverFee) {
this.deliverFee = deliverFee;
}
@Column(nullable=false)
public Float getTotalPrice() {
return totalPrice;
}
public void setTotalPrice(Float totalPrice) {
this.totalPrice = totalPrice;
}
@Column(nullable=false)
public Float getPayablefee() {
return payablefee;
}
public void setPayablefee(Float payablefee) {
this.payablefee = payablefee;
}
@Column(length=100)
public String getNote() {
return note;
}
public void setNote(String note) {
this.note = note;
}
@Enumerated(EnumType.STRING) @Column(length=20,nullable=false)
public PaymentWay getPaymentWay() {
return paymentWay;
}
public void setPaymentWay(PaymentWay paymentWay) {
this.paymentWay = paymentWay;
}
@Column(nullable=false)
public Boolean getPaymentstate() {
return paymentstate;
}
public void setPaymentstate(Boolean paymentstate) {
this.paymentstate = paymentstate;
}
@OneToOne(cascade=CascadeType.ALL)
@JoinColumn(name="deliver_id")
public OrderDeliverInfo getOrderDeliverInfo() {
return orderDeliverInfo;
}
public void setOrderDeliverInfo(OrderDeliverInfo orderDeliverInfo) {
this.orderDeliverInfo = orderDeliverInfo;
}
@OneToOne(cascade=CascadeType.ALL, optional=false)
@JoinColumn(name="contact_id")
public OrderContactInfo getOrderContactInfo() {
return orderContactInfo;
}
public void setOrderContactInfo(OrderContactInfo orderContactInfo) {
this.orderContactInfo = orderContactInfo;
}
@OneToMany(mappedBy="order",cascade=CascadeType.ALL)
public Set<OrderItem> getItems() {
return items;
}
public void setItems(Set<OrderItem> items) {
this.items = items;
}
/**
* 添加订单项
* @param item
*/
public void addOrderItem(OrderItem item){
this.items.add(item);
item.setOrder(this);
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((orderid == null) ? 0 : orderid.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 Order other = (Order) obj;
if (orderid == null) {
if (other.orderid != null)
return false;
} else if (!orderid.equals(other.orderid))
return false;
return true;
}

}


/**
* 配送信息
*/
@Entity
public class OrderDeliverInfo {
private Integer deliverid;
/* 收货人姓名 */
private String recipients;
/* 配送地址 */
private String address;
/* 电子邮箱 */
private String email;
/* 邮编 */
private String postalcode;
/* 座机 */
private String tel;
/* 手机 */
private String mobile;
/* 性别 */
private Gender gender = Gender.MAN;
/* 送货方式 */
private DeliverWay deliverWay;
/* 时间要求 */
private String requirement;
/* 所属的订单 */
private Order order;

@OneToOne(mappedBy="orderDeliverInfo", cascade=CascadeType.REFRESH)
public Order getOrder() {
return order;
}
public void setOrder(Order order) {
this.order = order;
}
@Id @GeneratedValue
public Integer getDeliverid() {
return deliverid;
}
public void setDeliverid(Integer deliverid) {
this.deliverid = deliverid;
}
@Enumerated(EnumType.STRING) @Column(length=23,nullable=false)
public DeliverWay getDeliverWay() {
return deliverWay;
}
public void setDeliverWay(DeliverWay deliverWay) {
this.deliverWay = deliverWay;
}
@Column(length=30)
public String getRequirement() {
return requirement;
}
public void setRequirement(String requirement) {
this.requirement = requirement;
}
@Column(length=8,nullable=false)
public String getRecipients() {
return recipients;
}
public void setRecipients(String recipients) {
this.recipients = recipients;
}
@Column(length=40,nullable=false)
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
@Column(length=40)
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
@Column(length=6)
public String getPostalcode() {
return postalcode;
}
public void setPostalcode(String postalcode) {
this.postalcode = postalcode;
}
@Column(length=18)
public String getTel() {
return tel;
}
public void setTel(String tel) {
this.tel = tel;
}
@Column(length=11)
public String getMobile() {
return mobile;
}
public void setMobile(String mobile) {
this.mobile = mobile;
}
@Enumerated(EnumType.STRING) @Column(length=5,nullable=false)
public Gender getGender() {
return gender;
}
public void setGender(Gender gender) {
this.gender = gender;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result
+ ((deliverid == null) ? 0 : deliverid.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 OrderDeliverInfo other = (OrderDeliverInfo) obj;
if (deliverid == null) {
if (other.deliverid != null)
return false;
} else if (!deliverid.equals(other.deliverid))
return false;
return true;
}

}



/**
* 订购者联系信息
*
*/
@Entity
public class OrderContactInfo {
private Integer contactid;
/* 购买人姓名 */
private String buyerName;
/* 联系地址 */
private String address;
/* 电子邮箱 */
private String email;
/* 邮编 */
private String postalcode;
/* 座机 */
private String tel;
/* 手机 */
private String mobile;
/* 性别 */
private Gender gender = Gender.MAN;
/* 所属订单 */
private Order order;

@OneToOne(cascade=CascadeType.REFRESH, mappedBy="orderContactInfo")
public Order getOrder() {
return order;
}
public void setOrder(Order order) {
this.order = order;
}
@Id @GeneratedValue
public Integer getContactid() {
return contactid;
}
public void setContactid(Integer contactid) {
this.contactid = contactid;
}
@Column(length=8,nullable=false)
public String getBuyerName() {
return buyerName;
}
public void setBuyerName(String buyerName) {
this.buyerName = buyerName;
}
@Column(length=40,nullable=false)
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
@Column(length=40)
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
@Column(length=6)
public String getPostalcode() {
return postalcode;
}
public void setPostalcode(String postalcode) {
this.postalcode = postalcode;
}
@Column(length=18)
public String getTel() {
return tel;
}
public void setTel(String tel) {
this.tel = tel;
}
@Column(length=11)
public String getMobile() {
return mobile;
}
public void setMobile(String mobile) {
this.mobile = mobile;
}
@Enumerated(EnumType.STRING) @Column(length=5,nullable=false)
public Gender getGender() {
return gender;
}
public void setGender(Gender gender) {
this.gender = gender;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result
+ ((contactid == null) ? 0 : contactid.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 OrderContactInfo other = (OrderContactInfo) obj;
if (contactid == null) {
if (other.contactid != null)
return false;
} else if (!contactid.equals(other.contactid))
return false;
return true;
}

}




/**
* 订单项
*/
@Entity
public class OrderItem {
private Integer itemid;
/* 产品名称 */
private String productName;
/* 产品id */
private Integer productid;
/* 产品销售价 */
private Float productPrice = 0f;
/* 购买数量 */
private Integer amount = 1;
/* 产品样式 */
private String styleName;
/* 产品样式ID */
private Integer styleid;
/* 所属订单 */
private Order order;

public OrderItem(){}

public OrderItem(String productName, Integer productid, Float productPrice,
Integer amount, String styleName, Integer styleid) {
this.productName = productName;
this.productid = productid;
this.productPrice = productPrice;
this.amount = amount;
this.styleName = styleName;
this.styleid = styleid;
}
@Id @GeneratedValue
public Integer getItemid() {
return itemid;
}
public void setItemid(Integer itemid) {
this.itemid = itemid;
}
@Column(length=50,nullable=false)
public String getProductName() {
return productName;
}
public void setProductName(String productName) {
this.productName = productName;
}
@Column(nullable=false)
public Integer getProductid() {
return productid;
}
public void setProductid(Integer productid) {
this.productid = productid;
}
@Column(nullable=false)
public Float getProductPrice() {
return productPrice;
}
public void setProductPrice(Float productPrice) {
this.productPrice = productPrice;
}
@Column(nullable=false)
public Integer getAmount() {
return amount;
}
public void setAmount(Integer amount) {
this.amount = amount;
}
@Column(length=30,nullable=false)
public String getStyleName() {
return styleName;
}
public void setStyleName(String styleName) {
this.styleName = styleName;
}
@Column(nullable=false)
public Integer getStyleid() {
return styleid;
}
public void setStyleid(Integer styleid) {
this.styleid = styleid;
}
@ManyToOne(cascade={CascadeType.MERGE, CascadeType.REFRESH}, optional=false)
@JoinColumn(name="order_id")
public Order getOrder() {
return order;
}
public void setOrder(Order order) {
this.order = order;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((itemid == null) ? super.hashCode() : itemid.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 OrderItem other = (OrderItem) obj;
if (itemid == null) {
if (other.itemid != null)
return false;
} else if (!itemid.equals(other.itemid))
return false;
return true;
}

}




@Entity
public class GeneratedOrderid {
private String id;
private Integer orderid = 0;

@Id @Column(length=5)
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
@Column(nullable=false)
public Integer getOrderid() {
return orderid;
}
public void setOrderid(Integer orderid) {
this.orderid = orderid;
}
}
/**
* 送货方式
*/
public enum DeliverWay {
/** 平邮 */
GENERALPOST{
public String getName(){return "平邮";}
},
/** 快递送货上门 */
EXPRESSDELIVERY{
public String getName(){return "快递送货上门";}
},
/** 加急快递送货上门 */
EXIGENCEEXPRESSDELIVERY{
public String getName(){return "加急快递送货上门";}
},
/** 国内特快专递EMS */
EMS{
public String getName(){return "国内特快专递EMS";}
};
public abstract String getName();
}
相关标签: Mobile