package com.uas.platform.b2b.model;

import com.alibaba.fastjson.annotation.JSONField;
import org.codehaus.jackson.annotate.JsonIgnore;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.OptimisticLockType;
import org.hibernate.annotations.OptimisticLocking;

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

/**
 *  推送消息表
 * Created by dongbw on 17/03/22 14:55.
 */
@Entity
@Table(name = "purc$pagingrelease")
@OptimisticLocking(type = OptimisticLockType.ALL)
@DynamicUpdate(value = true)
public class PagingRelease implements Serializable {

    /**
     * 序号
     */
    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "pr_id")
    private Long id;

    /**
     * 员工UU
     */
    @Column(name = "pr_emuu")
    private Long emUU;

    /**
     * 员工姓名
     */
    @Column(name = "pr_emname")
    private String emName;

    /**
     * 企业UU
     */
    @Column(name = "pr_enuu")
    private Long enUU;

    /**
     * 采购企业
     */
    @OneToOne(cascade = CascadeType.REFRESH)
    @JoinColumn(name = "pr_enuu", insertable = false, updatable = false)
    private EnterpriseInfo enterprise;

    /**
     * 推送时间
     */
    @Column(name = "pr_date")
    private Date date;

    /**
     * 消息正文
     */
    @Column(name = "pr_context")
    private String context;

    /**
     * 消息来源
     */
    @Column(name = "pr_from")
    private String from;

    /**
     * 来源单据编号
     */
    @Column(name = "pr_codevalue")
    private String code;

    /**
     * 消息标题
     */
    @Column(name = "pr_title")
    private String title;

    /**
     * 消息类型
     */
    @Column(name = "pr_type")
    private String type;

    /**
     * 来源表
     */
    @Column(name = "pr_table")
    private String table;

    /**
     * 消息分类 （对接收方来说，单据类型，sale为销售，purc为采购）
     */
    @Column(name = "pr_category")
    private String category;

    /**
     * 来源id
     */
    @Column(name = "pr_sourceid")
    private Long sourceId;

    /**
     * 1为发给供应商，0为发给客户
     */
    @Column(name = "pr_tovendor")
    private Short toVendor;

    /**
     * 1为回复，0为非回复（回复只回一个人）
     */
    @Column(name = "pr_isreply")
    private Short isReply;

    /**
     * 单据状态
     */
    @Column(name = "pr_orderstatus")
    private Short orderStatus;

    /**
     * 单据链接
     */
    @Column(name = "pr_url")
    private String url;

    /**
     * 消息明细
     */
    @OneToMany(mappedBy = "pagingRelease", cascade = { CascadeType.REFRESH, CascadeType.PERSIST, CascadeType.REMOVE,
            CascadeType.MERGE }, fetch = FetchType.EAGER)
    @OrderBy("prd_id")
    private Set<PagingReleaseDetail> pagingReleaseDetails;

    public PagingRelease() {

    }

    public PagingRelease(Long emUU, String emName, Long enUU, Date date, String codeValue, String from, String title, String context, String type, Short isReply, String category, String table, Long sourceId, Short orderStatus, Short toVendor) {
        this.emUU = emUU;
        this.emName = emName;
        this.enUU = enUU;
        this.date = date;
        this.code = codeValue;
        this.from = from;
        this.title = title;
        this.context = context;
        this.type = type;
        this.isReply = isReply;
        this.category = category;
        this.table = table;
        this.sourceId = sourceId;
        this.orderStatus = orderStatus;
        this.toVendor = toVendor;
    }

    public PagingRelease(Long emUU, String emName, Long enUU, Date date, String codeValue, String from, String title, String context, String type, Short isReply, String category, String table, Long sourceId, Short orderStatus, Short toVendor, String url) {
        this.emUU = emUU;
        this.emName = emName;
        this.enUU = enUU;
        this.date = date;
        this.code = codeValue;
        this.from = from;
        this.title = title;
        this.context = context;
        this.type = type;
        this.isReply = isReply;
        this.category = category;
        this.table = table;
        this.sourceId = sourceId;
        this.orderStatus = orderStatus;
        this.toVendor = toVendor;
        this.url = url;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Long getEmUU() {
        return emUU;
    }

    public void setEmUU(Long emUU) {
        this.emUU = emUU;
    }

    public String getEmName() {
        return emName;
    }

    public void setEmName(String emName) {
        this.emName = emName;
    }

    public Long getEnUU() {
        return enUU;
    }

    public void setEnUU(Long enUU) {
        this.enUU = enUU;
    }

//    public EnterpriseInfo getEnterprise() {
//        return enterprise;
//    }
//
//    public void setEnterprise(EnterpriseInfo enterprise) {
//        this.enterprise = enterprise;
//    }
//
//    public User getUser() {
//        return user;
//    }
//
//    public void setUser(User user) {
//        this.user = user;
//    }

    public Date getDate() {
        return date;
    }

    public void setDate(Date date) {
        this.date = date;
    }

    public String getContext() {
        return context;
    }

    public void setContext(String context) {
        this.context = context;
    }

    public String getFrom() {
        return from;
    }

    public void setFrom(String from) {
        this.from = from;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getTable() {
        return table;
    }

    public void setTable(String table) {
        this.table = table;
    }

    public String getCategory() {
        return category;
    }

    public void setCategory(String category) {
        this.category = category;
    }

    public Long getSourceId() {
        return sourceId;
    }

    public void setSourceId(Long sourceId) {
        this.sourceId = sourceId;
    }

    public Short getToVendor() {
        return toVendor;
    }

    public void setToVendor(Short toVendor) {
        this.toVendor = toVendor;
    }

    public Short getIsReply() {
        return isReply;
    }

    public void setIsReply(Short isReply) {
        this.isReply = isReply;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public EnterpriseInfo getEnterprise() {
        return enterprise;
    }

    public void setEnterprise(EnterpriseInfo enterprise) {
        this.enterprise = enterprise;
    }

    @JsonIgnore
    @JSONField(serialize = false)
    public Set<PagingReleaseDetail> getPagingReleaseDetails() {
        return pagingReleaseDetails;
    }

    public void setPagingReleaseDetails(Set<PagingReleaseDetail> pagingReleaseDetails) {
        this.pagingReleaseDetails = pagingReleaseDetails;
    }

    public Short getOrderStatus() {
        return orderStatus;
    }

    public void setOrderStatus(Short orderStatus) {
        this.orderStatus = orderStatus;
    }
}
