

from BaseDataMaintenance.model.postgres.BaseModel import BaseModel
import random

ATTACHMENT_INIT = 0
ATTACHMENT_PROCESSED = 10
ATTACHMENT_PROCESSED_FAILED = 3
ATTACHMENT_TOOLARGE = -1

ATTACHMENT_UPDATE_DOCUMENT_STATUS = 1

ATTACHMENT_MC_TODEAL_FROM = 20
ATTACHMENT_MC_TODEAL_TO = 30

ATTACHMENT_MC_SUCCEED_FROM  = 31
ATTACHMENT_MC_SUCCEED_TO = 40
ATTACHMENT_MC_FAILED_FROM = 41
ATTACHMENT_MC_FAILED_TO = 50

#10M以上不进行处理
ATTACHMENT_LARGESIZE = 1024*1024*10

#1.5M一下通过maxcompute处理
ATTACHMENT_SMALL_SIZE = int(10*1024*1024)

attachment_table_name = "attachment"

attachment_filemd5 = "filemd5"
attachment_size = "size"
attachment_path = "path"
attachment_crtime = "crtime"
attachment_attachmenthtml = "attachmenthtml"
attachment_attachmentcon = "attachmentcon" #-1代表逻辑错误，-2接口挂了,-3文件格式错误
attachment_process_time = "process_time"
attachment_classification = "classification"
attachment_page_time = "page_time"
attachment_docids = "docids"
attachment_filetype = "filetype"
attachment_status = "status"
attachment_file_link = "filelink"
attachment_file_title = "filetitle"
attachment_recsize = "recsize"
attachment_base64 = "base64"
attachment_swfUrls = "swfUrls"
attachment_has_table = "has_table"
attachment_link_status = "link_status" #0-未连接 1-已经连接 2-找不到未连接公告
import re

import pymysql
import psycopg2

from BaseDataMaintenance.common.Utils import *

class Attachment_postgres(BaseModel):

    #filemd5,path,crtime,attachmenthtml,attachmentcon,process_time,page_time,docids,filetype,status,sourcelink,filetitle

    def __init__(self,_dict):
        self.columns = set([attachment_filemd5,attachment_path,attachment_crtime,attachment_attachmenthtml,attachment_attachmentcon,attachment_classification ,attachment_process_time,attachment_docids,attachment_filetype,attachment_status,attachment_file_title,attachment_file_link,attachment_recsize,attachment_swfUrls,attachment_size,attachment_has_table])
        for k,v in _dict.items():
            if k in self.columns:
                # if k in ("attachmenthtml","attachmentcon") and v is not None:
                #     v = v.replace("%", "\\\\%").replace("_", "\\\\_").replace("'","\\\\'").replace("(","\\\\(").replace(")","\\\\)")
                if isinstance(v,str):
                    self.setValue(k,getLegal_str(pymysql.escape_string(v.replace('\x00',''))),True)
                else:
                    self.setValue(k,v,True)
        self.table_name = "attachment"

    def getPrimary_keys(self):
        return ["filemd5"]

    # def delete_row(self,ots_client):
    #     raise NotImplementedError()



if __name__=="__main__":
    pass

