package com.ff.weijinxiao.domain;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.ff.weijinxiao.util.jsonfilter.DateSerializer;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
import java.util.List;

/**
 * 订单  -- 卖出
 */
@Data
@Entity
@Table(name = "tb_order")
public class Order implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "t_id")
    private Integer id;

    @Column(name = "submit_date")
    @ApiModelProperty(value = "订单日期")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")//json序列化实体类处理
    private Date submitDate;

    @Column(name = "is_payment")
    @ApiModelProperty(value = "是否已付款给供应商（0:否；1:是）")
    private Integer isPayment;

    @Column(name = "is_receivables")
    @ApiModelProperty(value = "是否已收到客户款（0:否；1:是）")
    private Integer isReceivables;

    @Column(name = "is_send")
    @ApiModelProperty(value = "是否已发货给客户（0:否；1:是）")
    private Integer isSend;

    @Column(name = "courier_company")
    @ApiModelProperty(value = "快递公司")
    private String courierCompany;

    @Column(name = "courier_number")
    @ApiModelProperty(value = "快递单号")
    private String courierNumber;

    @OneToOne
    @JoinColumn(name = "book_id",referencedColumnName="id",foreignKey = @ForeignKey(name = "none", value = ConstraintMode.NO_CONSTRAINT))
    @ApiModelProperty(value = "激活账本ID")
    private AccountBook accountBook;

    @OneToMany
    @JoinColumn(name = "order_id",referencedColumnName="onlyID",foreignKey = @ForeignKey(name = "none", value = ConstraintMode.NO_CONSTRAINT))
    private List<OrderGoods> orderGoodsList;

    @OneToOne
    @JoinColumn(name = "custom_address_id",referencedColumnName="onlyID",foreignKey = @ForeignKey(name = "none", value = ConstraintMode.NO_CONSTRAINT))
    @ApiModelProperty(value = "客户收货地址id")
    private CustomerAddress customerAddress;

    @OneToOne
    @JoinColumn(name = "custom_id",referencedColumnName="onlyID",foreignKey = @ForeignKey(name = "none", value = ConstraintMode.NO_CONSTRAINT))
    @ApiModelProperty(value = "客户id")
    private Customer customer;

    @Column(name = "freight")
    @ApiModelProperty(value = "运费（如果无运费则运费默认是0）；小数点后保留两位小数")
    private Double freight;

    @Column(name = "cost_price")
    @ApiModelProperty(value = "成本价,小数点后保留两位小数")
    private Double costPrice;

    @Column(name = "sales_price")
    @ApiModelProperty(value = "销售总价，小数点后保留两位小数")
    private Double salesPrice;

    @Column(name = "profit")
    @ApiModelProperty(value = "利润，小数点后保留两位小数")
    private Double profit;

    // 01076548669
    @Column(name = "uid")
    @ApiModelProperty(value = "用户登录uid")
    private String uid;

    @Transient
    @ApiModelProperty(value = "创建者姓名")
    private String userName;

    @Column(name = "isDelete")
    @ApiModelProperty(value = "是否是删除状态(0:否；1:是)")
    private Integer isDelete = 0;

    @Column(name = "isPinkage")
    @ApiModelProperty(value = "是否包邮，0：不包邮，1：包邮")
    private String isPinkage = "0";

    @Column(name = "isBackup")
    @ApiModelProperty(value = "是否备份过(0:否；1:是)")
    private Integer isBackup = 0;

    @Column(name = "create_time")
    @ApiModelProperty(value = "创建时间")
    @org.hibernate.annotations.CreationTimestamp
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonSerialize(using = DateSerializer.class)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")//json序列化实体类处理
    private Date createTime;

    @Column(name = "modify_time")
    @ApiModelProperty(value = "更新时间")
    @org.hibernate.annotations.UpdateTimestamp
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonSerialize(using = DateSerializer.class)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")//json序列化实体类处理
    private Date modifyTime;

    // 150107717600090149862155037101291
    @Column(name = "onlyID")
    @ApiModelProperty(value = "onlyID")
    private String onlyID;

    @Column(name = "deliveryType")
    @ApiModelProperty(value = "deliveryType 1:快递；2:上门；3:自取")
    private String deliveryType;

    @Column(name = "salenote")
    @ApiModelProperty(value = "订单备注")
    private String salenote;

    @Column(name = "payWay")
    @ApiModelProperty(value = "付款方式 1=现金 2=刷卡 3=支付宝 4=微信")
    private Integer payWay = 0;

    @Column(name = "realReceive")
    @ApiModelProperty(value = "实收金额")
    private Float realReceive;

    @Column(name = "discounts")
    @ApiModelProperty(value = "优惠金额，默认为0数")
    private Float discounts = 0F;

    @Column(name = "debt")
    @ApiModelProperty(value = "欠款金额，默认销售总价-实收-优惠金额")
    private Float debt;
}
