Exemplo n.º 1
0
def process():

    #step 1, grab oracle ownerinfo data. city sensitive
    oracle = Oracle( user = "******", passwd = "hl_q" , host = "172.16.6.19:1521/HLSALES" )

    oracle_sql  = "select h.standard_id AS HSTANDARD_ID, h.building_no, h.room_no, u.user_code, \
                   i.OWNER_NAME, i.MOBILE_PHONE, i.HOME_PHONE, i.OFFICE_PHONE, i.OWNER_TYPE, i.QQ, i.IS_VALID, i.CREATED_TIME, i.CREATED_BY, i.PKID as PKID \
                   from owners.t_owner_info i inner join owners.t_owner_house h on i.house_id = h.pkid   \
                           left join usermgr.ts_user u on i.created_by = u.user_id \
                           inner join owners.t_owner_resblock r \
                               on h.resblock_id = r.pkid \
                   where r.city_code = '320100'  \
                   and ( i.MOBILE_PHONE is not null or  i.HOME_PHONE is not null or  i.OFFICE_PHONE is not null   ) and i.owner_name is not null and i.is_valid = 1 "
    print "begin get all owner"
    all_owners = oracle.query_sql( oracle_sql )
    print "end get all owner" + str( len( all_owners ) )
#    i = 0
#    ever = 10000
#    thread_num = len( all_owners ) / ever
#    threads = []    
#
#    while i < thread_num:
#        threads.append(  Owner_import( all_owners[ i*ever: (i+1)*ever ] , i  )  )
#        i = i + 1
#
#    threads.append(  Owner_import( all_owners[ i*ever:  ] , i  )  )
#
#    for th in threads:
#        th.start()
#    ret = False
#    while True:
#        for th in threads:
#            if not th.isAlive():
#                print "has thread exist"
#                ret = True
#                break
#        if ret :
#            break
#
#    for th in threads:
#        th.join()
#
    #step 2, insert oracle ownerinfo into mysql ownerinfo. And, fill in <oracle_pkid, mysql_pkid> dict
    owner = Owner_import( all_owners, 0 )
    owner.batch( all_owners, 0 ) 

    #step 3, get oracle ownerinfo_track data.
    global ORACLE_MYSQL_DICT
    print(ORACLE_MYSQL_DICT)
def getOwnerTrackData(logging):
    oracle = Oracle( user = "******", passwd = "hl_q" , host = "172.16.6.19:1521/HLSALES" )

    oracle_sql_owner_track = "SELECT \
                    U.user_code as USER_CODE, \
                    U.DESCRIPTION, \
                    i.PKID as OWNER_PKID, \
                    i.OWNER_NAME as OWNER_NAME, \
                    i.MOBILE_PHONE as MOBILE_PHONE, \
                    i.HOME_PHONE as HOME_PHONE, \
                    i.OFFICE_PHONE as OFFICE_PHONE, \
                    i.OWNER_TYPE, \
                    i.QQ as QQ, \
                    i.IS_VALID, \
                    i.STANDARD_ID as STANDARD_ID, \
                    t.pkid as track_pkid, \
                    t.TRACK_DESCRIPTION, \
                    t.CREATE_USER_NAME, \
                    t.TRACK_DATE as CREATED_TIME, \
                    o.ORG_CODE AS ORG_CODE, \
                    o.ORG_SHORT_NAME AS ORG_SHORT_NAME \
                FROM \
                    owners.t_owner_info i \
                INNER JOIN OWNERS.T_OWNER_TRACK t ON  i.PKID = t.OWNER_ID \
                INNER JOIN owners.t_owner_house H ON i.house_id = H.pkid \
                LEFT JOIN usermgr.ts_user U ON t.created_by = U.user_id \
                LEFT JOIN USERMGR.TS_ORG o ON t.STOREGROUP_ID = o.ORG_ID \
                INNER JOIN owners.t_owner_resblock r ON H.resblock_id = r.pkid \
                WHERE \
                    r.city_code = '440300' \
                AND ( \
                    i.MOBILE_PHONE IS NOT NULL \
                    OR i.HOME_PHONE IS NOT NULL \
                    OR i.OFFICE_PHONE IS NOT NULL \
                ) \
                And t.CREATED_BY IS NOT NULL \
                AND i.owner_name IS NOT NULL \
                AND i.is_valid = 1"

    logging.info("begin to get owner_track_info")
    all_owner_tracks = oracle.query_sql(oracle_sql_owner_track)
    logging.info("end to get owner_track_info, rows " + str(len(all_owner_tracks)))

    tracks = Owner_import( all_owner_tracks, 0 )
    tracks.batch_track( all_owner_tracks, 0, logging)