
from BaseDataMaintenance.model.ots.BaseModel import BaseModel
import re

DOCUMENT_PRODUCT_ID = 'id'
DOCUMENT_PRODUCT_NAME = 'name'
DOCUMENT_PRODUCT_BRAND = 'brand'
DOCUMENT_PRODUCT_SPECS = 'specs'
DOCUMENT_PRODUCT_BRANDSPECS = 'brand_specs'
DOCUMENT_PRODUCT_FULL_NAME = 'full_name'
DOCUMENT_PRODUCT_UNIT_PRICE = 'unit_price'
DOCUMENT_PRODUCT_QUANTITY = 'quantity'
DOCUMENT_PRODUCT_QUANTITY_UNIT = 'quantity_unit'
DOCUMENT_PRODUCT_TOTAL_PRICE = 'total_price'
DOCUMENT_PRODUCT_SUPPLIER = 'supplier'
DOCUMENT_PRODUCT_PARAMETER = 'parameter'
DOCUMENT_PRODUCT_CATEGORY = 'category'
DOCUMENT_PRODUCT_DOCID = "docid"
DOCUMENT_PRODUCT_DOCTITLE = "doctitle"
DOCUMENT_PRODUCT_PROJECT_NAME = 'project_name'
DOCUMENT_PRODUCT_PROJECT_CODE = 'project_code'
DOCUMENT_PRODUCT_TENDEREE = 'tenderee'
DOCUMENT_PRODUCT_TENDEREE_PHONE = 'tenderee_phone'
DOCUMENT_PRODUCT_TENDEREE_CONTACT = 'tenderee_contact'
DOCUMENT_PRODUCT_PROCUREMENT_SYSTEM = 'procurement_system'
DOCUMENT_PRODUCT_BIDDING_BUDGET = 'bidding_budget'
DOCUMENT_PRODUCT_WIN_TENDERER = 'win_tenderer'
DOCUMENT_PRODUCT_WIN_BID_PRICE = "win_bid_price"
DOCUMENT_PRODUCT_PROVINCE = 'province'
DOCUMENT_PRODUCT_CITY = 'city'
DOCUMENT_PRODUCT_DISTRICT = 'district'
DOCUMENT_PRODUCT_PAGE_TIME = 'page_time'
DOCUMENT_PRODUCT_PAGE_TIME_YEAR = 'page_time_year'
DOCUMENT_PRODUCT_INFO_TYPE = 'info_type'
DOCUMENT_PRODUCT_INDUSTRY = 'industry'
DOCUMENT_PRODUCT_STATUS = 'status'
DOCUMENT_PRODUCT_CREATE_TIME = 'create_time'
DOCUMENT_PRODUCT_UPDATE_TIME = 'update_time'

DOCUMENT_PRODUCT_ORIGINAL_ID = 'original_id'
DOCUMENT_PRODUCT_DICT_NAME_ID = 'dict_name_id'
DOCUMENT_PRODUCT_DICT_BRAND_ID = "dict_brand_id"
DOCUMENT_PRODUCT_DICT_SPECS_ID = "dict_specs_id"

DOCUMENT_PRODUCT_DUMP_ID = "dump_id"
DOCUMENT_PRODUCT_ORIGINAL_NAME = "original_name"
DOCUMENT_PRODUCT_ORIGINAL_BRAND = "original_brand"
DOCUMENT_PRODUCT_ORIGINAL_SPECS = "original_specs"


DOCUMENT_PRODUCT_ATTACHMENTS = "attachments"
DOCUMENT_PRODUCT_BID_FILEMD5S = "bid_filemd5s"

DOCUMENT_PRODUCT_HAS_BIDFILE = "has_bidfile"
DOCUMENT_PRODUCT_HAS_ATTACHMENTS = "has_attachments"

DOCUMENT_PRODUCT_PARAMETER_STATUS = "parameter_status"

Document_product_table_name = "document_product2"

class Document_product(BaseModel):

    def __init__(self,dict):
        BaseModel.__init__(self)
        self.time_pattern = "\d{4}\-\d{2}\-\d{2}"
        self.illegal_time_pattern = re.compile("[^0-9-]")
        for k,v in dict.items():
            if k==DOCUMENT_PRODUCT_PAGE_TIME:
                _v = re.sub(self.illegal_time_pattern,'',v[:10])
                if re.search(self.time_pattern,_v) is None:
                    v = "2001-01-01"
                else:
                    v = _v
            self.setValue(k,v,True)

        self.table_name = Document_product_table_name

    def getPrimary_keys(self):
        return ['id']
