package com.bidizhaobiao.data.bigdata.base.entity.mongo;

import org.bson.types.ObjectId;
import org.mongodb.morphia.annotations.Entity;
import org.mongodb.morphia.annotations.Id;
import org.mongodb.morphia.annotations.Property;

import java.lang.reflect.Field;
import java.lang.reflect.Method;

@Entity(value = "zhaobiao_extraction", noClassnameStored = true)
public class ZhaoBiaoExtraction {

    @Id
    private ObjectId id;
    // 项目名称
    @Property("project_name")
    private String projectName;
    // 项目编号
    @Property("project_code")
    private String projectCode;
    // 项目地址
    @Property("project_addr")
    private String projectAddr;
    // 公告文档发布日期
    @Property("page_time")
    private String pageTime;
    // 项目归属地区
    @Property("area")
    private String area;
    // 项目归属省份
    @Property("province")
    private String province;
    // 项目归属城市
    @Property("city")
    private String city;
    // 项目归属区县
    @Property("district")
    private String district;
    // 项目归属行业分类(小类）
    @Property("industry")
    private String industry;
    // 项目归属行业分类(大类）
    @Property("info_type")
    private String infoType;
    // 招标预算（或招标控制价）
    @Property("bidding_budget")
    private String biddingBudget;
    // 文章UUID
    @Property("document_id")
    private String documentId;
    // 文章标题(源标题)
    @Property("document_title")
    private String documentTitle;
    // 招标人
    @Property("tenderee")
    private String tenderee;
    // 招标人地址
    @Property("tenderee_addr")
    private String tendereeAddr;
    // 招标人电话
    @Property("tenderee_phone")
    private String tendereePhone;
    // 招标联系人
    @Property("tenderee_contact")
    private String tendereeContact;
    // 代理机构
    @Property("agency")
    private String agency;
    // 代理机构电话
    @Property("agency_phone")
    private String agencyPhone;
    // 代理联系人
    @Property("agency_contact")
    private String agencyContact;
    // 项目子名称
    @Property("sub_project_name")
    private String subProjectName;
    // 项目子编号
    @Property("sub_project_code")
    private String subProjectCode;

    private String upgradeStatus;      // 这个属性用于旧数据的升级(null和0：待升级、-1：升级中、1：已升级)

    private String docId;   // 公告id

    public ObjectId getId() {
        return id;
    }

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

    public String getProjectName() {
        return projectName;
    }

    public void setProjectName(String projectName) {
        this.projectName = projectName;
    }

    public String getProjectCode() {
        return projectCode;
    }

    public void setProjectCode(String projectCode) {
        this.projectCode = projectCode;
    }

    public String getProjectAddr() {
        return projectAddr;
    }

    public void setProjectAddr(String projectAddr) {
        this.projectAddr = projectAddr;
    }

    public String getPageTime() {
        return pageTime;
    }

    public void setPageTime(String pageTime) {
        this.pageTime = pageTime;
    }

    public String getProvince() {
        return province;
    }

    public void setProvince(String province) {
        this.province = province;
    }

    public String getIndustry() {
        return industry;
    }

    public void setIndustry(String industry) {
        this.industry = industry;
    }

    public String getBiddingBudget() {
        return biddingBudget;
    }

    public void setBiddingBudget(String biddingBudget) {
        this.biddingBudget = biddingBudget;
    }

    public String getDocumentId() {
        return documentId;
    }

    public void setDocumentId(String documentId) {
        this.documentId = documentId;
    }

    public String getDocumentTitle() {
        return documentTitle;
    }

    public void setDocumentTitle(String documentTitle) {
        this.documentTitle = documentTitle;
    }

    public String getTenderee() {
        return tenderee;
    }

    public void setTenderee(String tenderee) {
        this.tenderee = tenderee;
    }

    public String getTendereeAddr() {
        return tendereeAddr;
    }

    public void setTendereeAddr(String tendereeAddr) {
        this.tendereeAddr = tendereeAddr;
    }

    public String getTendereePhone() {
        return tendereePhone;
    }

    public void setTendereePhone(String tendereePhone) {
        this.tendereePhone = tendereePhone;
    }

    public String getTendereeContact() {
        return tendereeContact;
    }

    public void setTendereeContact(String tendereeContact) {
        this.tendereeContact = tendereeContact;
    }

    public String getAgency() {
        return agency;
    }

    public void setAgency(String agency) {
        this.agency = agency;
    }

    public String getAgencyPhone() {
        return agencyPhone;
    }

    public void setAgencyPhone(String agencyPhone) {
        this.agencyPhone = agencyPhone;
    }

    public String getAgencyContact() {
        return agencyContact;
    }

    public void setAgencyContact(String agencyContact) {
        this.agencyContact = agencyContact;
    }

    public String getSubProjectName() {
        return subProjectName;
    }

    public void setSubProjectName(String subProjectName) {
        this.subProjectName = subProjectName;
    }

    public String getSubProjectCode() {
        return subProjectCode;
    }

    public void setSubProjectCode(String subProjectCode) {
        this.subProjectCode = subProjectCode;
    }

    public String getInfoType() {
        return infoType;
    }

    public void setInfoType(String infoType) {
        this.infoType = infoType;
    }

    public String getArea() {
        return area;
    }

    public void setArea(String area) {
        this.area = area;
    }

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public String getDistrict() {
        return district;
    }

    public void setDistrict(String district) {
        this.district = district;
    }

    public String getDocId() {
        return docId;
    }

    public void setDocId(String docId) {
        this.docId = docId;
    }

    public String getUpgradeStatus() {
        return upgradeStatus;
    }

    public void setUpgradeStatus(String upgradeStatus) {
        this.upgradeStatus = upgradeStatus;
    }

    public void addAll(ZhaoBiaoExtraction zhaoBiaoExtraction)  {
        try {
            Field[] newFields = zhaoBiaoExtraction.getClass().getDeclaredFields();
            Field[] thisFields = this.getClass().getDeclaredFields();
            for (Field newField : newFields) {
                String newFieldName = newField.getName();

                if (newFieldName.equals("id")) {
                    continue;
                }

                for (Field thisField : thisFields) {
                    String thisFieldName = thisField.getName();
                    if (thisFieldName.equals(newFieldName)) {
                        thisField.setAccessible(true);
                        newField.setAccessible(true);
                        if (newField.get(zhaoBiaoExtraction) != null) {
                            Method thisMethod = this.getClass().getMethod("set" + thisFieldName.substring(0, 1).toUpperCase() + thisFieldName.substring(1), newField.getType());
                            thisMethod.invoke(this, newField.get(zhaoBiaoExtraction));
                        }
                        break;
                    }
                }
            }
        } catch(Exception e) {
            e.printStackTrace();
        }
    }

}
