package com.uas.platform.b2b.model;

import com.alibaba.fastjson.annotation.JSONField;
import com.uas.platform.b2b.erp.model.SaleTenderErp;
import org.codehaus.jackson.annotate.JsonIgnore;

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

/**
 * 招标方答疑单 （投标单关联）
 * Created by dongbw
 * 17/09/07 18:02.
 */
@Table(name = "purc$tenderanswer")
@Entity
public class SaleTenderAnswer implements Serializable {

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

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

    /**
     * 答疑编号
     */
    @Column(name = "pta_code")
    private String code;

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

    /**
     * 招标企业
     */
    @OneToOne
    @JoinColumn(name = "pta_enuu", insertable = false, updatable = false)
    private Enterprise enterprise;

    /**
     * 招标编号
     */
    @Column(name = "pta_tendercode")
    private String tenderCode;

    /**
     * 招标标题
     */
    @Column(name = "pta_tendertitle")
    private String tenderTitle;

    /**
     * 答疑截止时间
     */
    @Column(name = "pta_questionenddate")
    private Date questionEndDate;

    /**
     * 录入时间
     */
    @Column(name = "pta_indate")
    private Date inDate;

    /**
     * 录入人
     */
    @Column(name = "pta_recorder")
    private String recorder;

    /**
     * UAS审核时间
     */
    @Column(name = "pta_auditdate")
    private Date auditDate;

    /**
     * 回复时间
     */
    @Column(name = "pta_replydate")
    private Date replyDate;


    /**
     * 答疑备注
     */
    @Column(name = "pta_remark")
    private String remark;

    /**
     * 处理状态
     */
    @Column(name = "pta_status")
    private Short status;

    /**
     * 招标单id
     */
    @Column(name = "pta_ptid")
    private Long tenderId;

    /**
     * 投标提问单
     */
    @OneToMany(mappedBy = "saleTenderAnswer", cascade = CascadeType.REFRESH, fetch = FetchType.EAGER)
    @OrderBy("id")
    private Set<SaleTenderQuestion> saleTenderQuestions;

    /**
     * 答疑附件
     */
    @OneToMany(fetch = FetchType.EAGER, cascade = {CascadeType.REFRESH})
    @JoinTable(name = "purc$tenderanswerattach", joinColumns = @JoinColumn(name = "pta_id", referencedColumnName = "pta_id"), inverseJoinColumns = @JoinColumn(name="at_id", referencedColumnName = "at_id"))
    private Set<Attach> answerAttaches;

    public SaleTenderAnswer() {
    }

    public SaleTenderAnswer(SaleTenderErp saleTender) {
        this.enterprise = saleTender.getEnterprise();
        this.enUU = saleTender.getEnUU();
        this.questionEndDate = saleTender.getQuestionEndDate();
        this.tenderCode = saleTender.getCode();
        this.tenderTitle = saleTender.getTitle();
        this.tenderId = saleTender.getPtId();
    }

    public Long getId() {
        return id;
    }

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

    public String getCode() {
        return code;
    }

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

    public Long getEnUU() {
        return enUU;
    }

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

    public String getTenderCode() {
        return tenderCode;
    }

    public void setTenderCode(String tenderCode) {
        this.tenderCode = tenderCode;
    }

    public String getTenderTitle() {
        return tenderTitle;
    }

    public void setTenderTitle(String tenderTitle) {
        this.tenderTitle = tenderTitle;
    }

    public Date getQuestionEndDate() {
        return questionEndDate;
    }

    public void setQuestionEndDate(Date questionEndDate) {
        this.questionEndDate = questionEndDate;
    }

    public Date getInDate() {
        return inDate;
    }

    public void setInDate(Date inDate) {
        this.inDate = inDate;
    }

    public Date getReplyDate() {
        return replyDate;
    }

    public void setReplyDate(Date replyDate) {
        this.replyDate = replyDate;
    }


    public Short getStatus() {
        return status;
    }

    public void setStatus(Short status) {
        this.status = status;
    }

    public Enterprise getEnterprise() {
        return enterprise;
    }

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

    public String getRecorder() {
        return recorder;
    }

    public void setRecorder(String recorder) {
        this.recorder = recorder;
    }

    public Date getAuditDate() {
        return auditDate;
    }

    public void setAuditDate(Date auditDate) {
        this.auditDate = auditDate;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    @JsonIgnore
    @JSONField(serialize = false)
    public Set<SaleTenderQuestion> getSaleTenderQuestions() {
        return saleTenderQuestions;
    }

    public void setSaleTenderQuestions(Set<SaleTenderQuestion> saleTenderQuestions) {
        this.saleTenderQuestions = saleTenderQuestions;
    }

    public Set<Attach> getAnswerAttaches() {
        return answerAttaches;
    }

    public void setAnswerAttaches(Set<Attach> answerAttaches) {
        this.answerAttaches = answerAttaches;
    }

    public Long getTenderId() {
        return tenderId;
    }

    public void setTenderId(Long tenderId) {
        this.tenderId = tenderId;
    }
}
