py——cd

来源:互联网 发布:淘宝商品标题命名规则 编辑:程序博客网 时间:2024/05/17 01:02
#!/usr/bin/env python


import sys
import datetime
import cx_Oracle


org_type_list=[]
org_list=[]             
dict={}
subdict={}
subdict1={}
subdict2={}
subdict3={}
org_id=''
s_id=''
tag='0'                 
type='1'                
last_org=''
time=sys.argv[1]
one_BeginTime=datetime.datetime.strptime(time+' 00:00:00',"%Y-%m-%d %H:%M:%S")
two_BeginTime=one_BeginTime + datetime.timedelta(-1)
three_BeginTime=one_BeginTime + datetime.timedelta(-2)
endTime=datetime.datetime.strptime(time+' 23:59:59',"%Y-%m-%d %H:%M:%S")
come='91a70eb4b12e49e99b08ce9d157cd297'
sign='9891cdfe1aed428b97d318d19a6999bd'
send='a4c2cdaeba6444739fda9d1778e74445'
disp='8d5a8e9d942b482a8a4d94baa36abb47'
str="%Y-%m-%d %H:%M:%S"
i=0


def judge():
    i=len(org_list)-1
    if i>=0:
        last_org=org_list[i]
        if dict.has_key(last_org):
            subdict=dict.get(last_org)
            if subdict.has_key(sign):
                if datetime.datetime.strptime(subdict.get(sign),str)>one_BeginTime and datetime.datetime.strptime(subdict.get(sign),str)<endTime:
                    if subdict.has_key(come):
                        if datetime.datetime.strptime(subdict.get(come),str)>one_BeginTime and datetime.datetime.strptime(subdict.get(come),str)<endTime:
                            type='1'
                            tag='1'
                            print '\t'.join([org_list[i],time,type,tag])
                    else:
                        if i>=1 and dict.has_key(org_list[i-1]):
                            subdict1=dict.get(org_list[i-1])
                            if subdict1.has_key(send) and datetime.datetime.strptime(subdict1.get(send),str)>one_BeginTime and datetime.datetime.strptime(subdict1.get(send),str)<endTime:
                                tag='1'
                                type='1'
                                print '\t'.join([org_list[i],time,type,tag])
                if datetime.datetime.strptime(subdict.get(sign),str)>two_BeginTime and datetime.datetime.strptime(subdict.get(sign),str)<endTime:
                    if subdict.has_key(come):
                        if datetime.datetime.strptime(subdict.get(come),str)>two_BeginTime and datetime.datetime.strptime(subdict.get(come),str)<endTime:
                            type='2'
                            tag='1'
                            print '\t'.join([org_list[i],time,type,tag])
                    else:
                        if i>=1 and dict.has_key(org_list[i-1]):
                            subdict2=dict.get(org_list[i-1])
                            if subdict2.has_key(send) and datetime.datetime.strptime(subdict2.get(send),str)>two_BeginTime and datetime.datetime.strptime(subdict2.get(send),str)<endTime:#
                                tag='1'
                                type='2'
                                print '\t'.join([org_list[i],time,type,tag])
                if datetime.datetime.strptime(subdict.get(sign),str)>three_BeginTime and datetime.datetime.strptime(subdict.get(sign),str)<endTime:
                    if subdict.has_key(come):
                        if datetime.datetime.strptime(subdict.get(come),str)>three_BeginTime and datetime.datetime.strptime(subdict.get(come),str)<endTime:
                            type='3'
                            tag='1'
                            print '\t'.join([org_list[i],time,type,tag])
                    else:
                        if i>=1 and dict.has_key(org_list[i-1]):
                            subdict3=dict.get(org_list[i-1])
                            if subdict3.has_key(send) and datetime.datetime.strptime(subdict3.get(send),str)>three_BeginTime and datetime.datetime.strptime(subdict3.get(send),str)<endTime:
                                tag='1'
                                type='3'
                                print '\t'.join([org_list[i],time,type,tag])
            elif not subdict.has_key(sign) and subdict.has_key(come):
                if datetime.datetime.strptime(subdict.get(come),str)>one_BeginTime and datetime.datetime.strptime(subdict.get(come),str)<endTime:
                    tag='0'
                    type='1'
                    print '\t'.join([org_list[i],time,type,tag])
                if datetime.datetime.strptime(subdict.get(come),str)>two_BeginTime and datetime.datetime.strptime(subdict.get(come),str)<endTime:
                    tag='0'
                    type='2'
                    print '\t'.join([org_list[i],time,type,tag])
                if datetime.datetime.strptime(subdict.get(come),str)>three_BeginTime and datetime.datetime.strptime(subdict.get(come),str)<endTime:
                    tag='0'
                    type='3'
                    print '\t'.join([org_list[i],time,type,tag])


                
if __name__=="__main__":
    conn=cx_Oracle.connect('DK_PARTY','BkF6QOYXlZ','192.168.21.196:1521/orcl')
    cursor=conn.cursor()
    sql='select distinct ORG_ID from DKCORE.ORG_ROLES where LOGISTICS_ROLE_ID=\'2af80778ad7c40a18827f1e40b899c28\''
    cursor.execute(sql)
    rows = cursor.fetchall()  
    for row in rows:
        org_type_list.append(row[0])
    for line in sys.stdin:
        sid,orgid,scandate,scantypeid,areaid=line.strip().split('\t')
        if orgid in org_type_list:
            if orgid !='null' and areaid != 'null':
                if len(org_list)==0:                                        
                    org_id=orgid
                    s_id=sid
                    org_list.append(orgid)                              
                    subdict[scantypeid]=scandate
                    dict[orgid]=subdict.copy()
                elif s_id==sid and org_id==orgid:                          
                    subdict=dict.get(orgid)
                    if  not subdict.has_key(scantypeid):
                        subdict[scantypeid]=scandate
                        dict[orgid]=subdict.copy()   
                elif s_id==sid and org_id!=orgid:                            
                    org_id=orgid
                    org_list.append(orgid)
                    subdict.clear()
                    subdict[scantypeid]=scandate
                    dict[orgid]=subdict.copy()
                elif s_id != sid:                                                
                    s_id=sid
                    org_id=orgid
                    judge()
                    org_list=[]
                    dict.clear()
                    subdict.clear()
                    org_list.append(orgid)
                    subdict[scantypeid]=scandate
                    dict[orgid]=subdict.copy()
    if len(org_list)>1:
        judge()
        
        
        
原创粉丝点击