예제 #1
0
def mainDeal():
    try:
        filename='./config/dbinfo.ini'
        dblist=getConnectInfo(filename)
        dbconn=connectDb(dblist[0])
        cursor=getCursor(dbconn)
        querySql="select count(1) from dbvop.mvno_user_20160111"
        while 1:
            cursor.execute(querySql)
            count=cursor.fetchall()[0][0]
            print count,type(count)
            if count > 0:
                getIdSql="select tt.rowid, tt.mvno_user_id from  dbvop.mvno_user_20160111  tt where rownum < 501"
                cursor.execute(getIdSql)
                result=cursor.fetchall()
                sqlList=joinSql(result)
                insertSql,deleteSql_u,deleteSql_t=sqlList
                cursor.execute(deleteSql_u)
                cursor.execute(deleteSql_t)
                cursor.execute(insertSql)
                dbconn.commit()
                time.sleep(300)
            else:
                print 'table is empty'
                break
    except Exception,e:
        err='%s %s' % (datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'),'execute mainDeal.mainDeal falied')
        with open(r'./log/mainDeal_error.log','a') as error_log:
            print >> error_log,('%s %s') %(err,e)
예제 #2
0
def insertSmsMain():
    try:
        logname='./log/sms_deal_info.log'
        msg= '------start insert------'
        dealMsg(logname,msg)
        sodname='./config/soddbinfo.ini'
        userIds=getUserId()[0:1000]
        #------------------
        dblist=getConnectInfo(sodname)
        dbconn=connectDb(dblist[0])
        cursor=getCursor(dbconn)
        if userIds:
            for userid in userIds:
                insertSql="insert into dbvop.I_mvno_user_a (MVNO_USER_ID) values (%s)" % userid
                executeSQL(cursor,insertSql)
                sqlcommit(dbconn)
                msg="错单号码对应的mvno_user_id:%s已经插入到dbvop.I_mvno_user_a表中" % userid
                dealMsg(logname,msg)
                time.sleep(1)
        else:
            msg= '没有要回收的错单'
            dealMsg(logname,msg)
        return userIds    
    except Exception,e:
        err='%s %s' % (datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'),'execute dealSmsMain.insertSmsMain falied')
        with open(r'./log/dealSmsMain_error.log','a') as error_log:
            print >> error_log,('%s %s') %(err,e)
예제 #3
0
def startNewAccount():
    try:
        msg="-------开始执行提升新的账期--------"
        dealMsg(msg)
        usql="select t.auto_sql_str from billing.auto_account_conf t  where t.step_id=13 and t.auto_id=108"
        #-------------
        dblist=getConnectInfo(billfile)
        dbconn=connectDb(dblist[0])
        cursor=getCursor(dbconn) 
        #-------------
        updateSql=dealSqlRes(cursor,usql)[0][0]
        msg="开始执行update语句"
        dealMsg(msg)   
        res=dealCommitSql(dbconn,cursor,updateSql)
        if res=="dealCommitSqlIsOk":
            msg="update语句执行完成,提升新的账期完成"
            dealMsg(msg)
            return "startNewAccountIsOk"
        else:
            msg="update语句执行失败,操作停止"
            dealMsg(msg)
            return "startNewAccountNotOk"           
    except Exception,e:
        err='%s %s' % (datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'),'execute dealFunc.startNewAccount falied')
        with open(r'./log/autoAccount_error.log','a') as error_log:
            print >> error_log,('%s %s') %(err,e)
예제 #4
0
def executeCommitsql(sql,dbname):
    try:
        dblist=getConnectInfo(dbname)
        dbconn=connectDb(dblist[0])
        cursor=getCursor(dbconn)
        executeSQL(cursor,sql)
        sqlcommit(dbconn)
    except Exception,e:
        comerr='%s %s' % (datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'),'execute executeCommitsql  falied')
        with open(r'./log/error.log','a') as error_log:
            print >> error_log,('%s %s' %(comerr,e))
예제 #5
0
def wholedealSql(filename,sql):
    try:
        dblist=getConnectInfo(filename)
        dbconn=connectDb(dblist[0])
        cursor=getCursor(dbconn)
        executeSQL(cursor,sql)
        result=getSQLrst(cursor)
        return result
    except Exception,e:
        err='%s %s' % (datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'),'execute util.wholedealSql falied')
        with open(r'./log/autoAccount_error.log','a') as error_log:
            print >> error_log,('%s %s') %(err,e)
예제 #6
0
def dealSql(sql,dbname):
    try:
        dblist=getConnectInfo(dbname)
        dbconn=connectDb(dblist[0])
        cursor=getCursor(dbconn)
        executeSQL(cursor,sql)
        result=getSQLrst(cursor)
        return result
    except Exception,e:
        dealerr='%s %s' % (datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'),'execute util.dealSql  falied')
        with open(r'./log/error.log','a') as error_log:
            print >> error_log,('%s %s' %(dealerr,e))
예제 #7
0
def dealCommitSql(dbname,sql):
    try:
        dblist=getConnectInfo(dbname)
        dbconn=connectDb(dblist[0])
        cursor=getCursor(dbconn)
        executeSQL(cursor,sql)
        sqlcommit(dbconn)
        return "dealCommitSqlIsOk"
    except Exception,e:
        err='%s %s' % (datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'),'execute util.dealCommitSql  falied')
        with open(r'./log/error.log','a') as error_log:
            print >> error_log,('%s %s' %(err,e))
예제 #8
0
def dealSql(sql):
    try:
        filename='./config/dbinfo.ini'
        dblist=getConnectInfo(filename)
        dbconn=connectDb(dblist[0])
        cursor=getCursor(dbconn)
        executeSQL(cursor,sql)
        result=getSQLrst(cursor)
        return result
    except Exception,e:
        err='%s %s' % (datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'),'execute util.dealSql falied')
        with open(r'./log/dealTable_error.log','a') as error_log:
            print >> error_log,('%s %s') %(err,e)
예제 #9
0
def dealSql(sql):
    try:
        filename='./config/billdbinfo.ini'
        dblist=getConnectInfo(filename)
        dbconn=connectDb(dblist[0])
        cursor=getCursor(dbconn)
        cursor.execute(sql)
        result=cursor.fetchall()
        return result

    finally:
        closeCursor(cursor)
        closeConnect(dbconn)
예제 #10
0
def dealSql(sql):
    try:
        filename = "./conf/dbinfo.ini"
        dblist = getConnectInfo(filename)
        dbconn = connectDb(dblist[0])
        cursor = getCursor(dbconn)
        executeSQL(cursor, sql)
        result = getSQLrst(cursor)
        return result
    except Exception, e:
        err = "%s %s" % (datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"), "execute util.dealSql falied")
        with open(r"./log/util_error.log", "a") as error_log:
            print >> error_log, ("%s %s") % (err, e)
예제 #11
0
def createMvFianlTable():
    try:
        msg="-------生成企业级最终账单表charge_item_final------"
        dealMsg(msg)
        #-----------
        createFinal="create_item_final"
        arg=[lastMonth]
        #-----------------------
        checkProcTableSql="select count(1) from charge_item_final t where t.acct_month=%s" % lastMonth
        #---------
        verifSql="select * from billing.auto_account_conf t  where t.step_id=11 and t.auto_flag='1' order by t.auto_id "
        #--------------------
        dblist=getConnectInfo(billfile)
        dbconn=connectDb(dblist[0])
        cursor=getCursor(dbconn)
        #---------------------------------
        resproc=dealSqlRes(cursor,checkProcTableSql)
        if int(resproc[0][0]) == 0:
            msg="charge_item_final表无账期数据,验证通过,执行生成最终账单存储过程"
            dealMsg(msg)
            dealProc(cursor,createFinal,arg)
            time.sleep(60)
        else:
            msg="charge_item_final表有账期数据,验证不通过,操作停止!!"
            dealMsg(msg)
            return "createMvFianlTableNotOk"
        resafter=dealSqlRes(cursor,checkProcTableSql)
        if int(resafter[0][0]) > 0:
            msg="执行生成最终账单存储过程执行完成,开始下一步操作,验证数据准确性"
            dealMsg(msg)
        else:
            msg="执行生成最终账单存储过程执行失败,操作停止!!"
            dealMsg(msg)
            return "createMvFianlTableNotOk"
        #-----------------------------
        verifResult=dealSqlRes(cursor,verifSql)
        for res in verifResult:
            e_value=dealSqlRes(cursor,res[2])[0][0]
            if compareValue(res[7],res[6],e_value):
                msg=res[5]
                dealMsg(msg)
            else:
                msg=res[4]
                dealMsg(msg)
                return "createMvFianlTableNotOk"
        return "createMvFianlTableIsOk"         
    except Exception,e:
        err='%s %s' % (datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'),'execute dealFunc.createMvFianlTable falied')
        with open(r'./log/autoAccount_error.log','a') as error_log:
            print >> error_log,('%s %s') %(err,e)
예제 #12
0
def test():
    try:
        filename='./config/billdbinfo.ini'
        dblist=getConnectInfo(filename)
        dbconn=connectDb(dblist[0])
        cursor=getCursor(dbconn)
        cursor.callproc('test022302')
        #cursor.execute('select * from dbvop.test0118')
        #result=cursor.fetchall()
        #print result 
        print '----------------ok'
      
    finally:
        closeCursor(cursor)
        closeConnect(dbconn)
예제 #13
0
def getData(sqlList,dbname):
    try:
        resList=[]
        dblist=getConnectInfo(dbname)
        dbconn=connectDb(dblist[0])
        cursor=getCursor(dbconn)
        for sql in sqlList:
            executeSQL(cursor,sql)
            result=getSQLrst(cursor)
            resList.append(result)
        return resList
    except Exception,e:
        err='%s %s' % (datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'),'execute getData  falied')
        with open(r'./log/error.log','a') as error_log:
            print >> error_log,('%s %s' %(err,e))
예제 #14
0
def insert(infos):
    try:
        filename='./config/dbinfo.ini'
        dblist=getConnectInfo(filename)
        dbconn=connectDb(dblist[0])
        cursor=getCursor(dbconn)
        executeSQL(cursor,infos[0])
        sqlcommit(dbconn)
        info='%s %s%s' % (datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'),infos[1],'数据已经插入dbvop.T_MVNO_USER表')
        with open(r'./log/dealTable_info.log','a') as info_log:
            print >> info_log,('%s') %(info)
        print "insert is ok,process's pid is %s" % os.getpid()
    except Exception,e:
        err='%s %s' % (datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'),'execute mainInsert.insert falied')
        with open(r'./log/dealTable_error.log','a') as error_log:
            print >> error_log,('%s %s') %(err,e)
예제 #15
0
def startWanNumAccount():
    try:
        msg="-------执行万号段合帐及阶梯优惠---------"
        dealMsg(msg)
        #----------------
        createDisct="create_prefix_disct"
        userDisct="user_disct"
        arg=[lastMonth]
        beforeSql="select * from billing.auto_account_conf t where t.step_id='8' and t.auto_flag='1' and t.auto_id =71"
        afterSql="select * from billing.auto_account_conf t where t.step_id='8' and t.auto_flag='1' and t.auto_id in (72,73,74,75) order by t.auto_id"
        #-----------------
        dblist=getConnectInfo(billfile)
        dbconn=connectDb(dblist[0])
        cursor=getCursor(dbconn)
        #-------------------------------------
        beforeResult=dealSqlRes(cursor,beforeSql)
        for res in beforeResult:
            e_value=dealSqlRes(cursor,res[2])[0][0]
            if compareValue(res[7],res[6],e_value):
                msg=res[5]
                dealMsg(msg)
            else:
                msg=res[4]
                dealMsg(msg)
                return "startWanNumAccountNotOk"
        #--------------    
        dealProc(cursor,createDisct,arg)
        dealProc(cursor,userDisct,arg)
        time.sleep(60)
        msg="承诺号段出帐存储过程,启动成功"
        dealMsg(msg)
        #--------------
        afterResult=dealSqlRes(cursor,afterSql)
        for res in afterResult:
            e_value=dealSqlRes(cursor,res[2])[0][0]
            if compareValue(res[7],res[6],e_value):
                msg=res[5]
                dealMsg(msg)
            else:
                msg=res[4]
                dealMsg(msg)
                return "startWanNumAccountNotOk"
        return "startWanNumAccountIsOk"    
    except Exception,e:
        err='%s %s' % (datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'),'execute dealFunc.startWanNumAccount falied')
        with open(r'./log/autoAccount_error.log','a') as error_log:
            print >> error_log,('%s %s') %(err,e)
예제 #16
0
def createWanFianlTable():
    try:
        msg="-------开始执行生成万号段最终账单表---------"
        dealMsg(msg)
        #------------
        createUser="******"
        arg=[lastMonth]
        #------------
        checkProcSql="select count(1) from charge_item_user_final t where t.acct_month=%s" % lastMonth
        checkSql="select * from billing.auto_account_conf t  where t.step_id=12 and t.auto_flag='1' and t.auto_id in (104,105,106,107) order by t.auto_id"
        #-------------------------
        dblist=getConnectInfo(billfile)
        dbconn=connectDb(dblist[0])
        cursor=getCursor(dbconn)
        resproc=dealSqlRes(cursor,checkProcSql)
        if int(resproc[0][0]) == 0:
            msg="charge_item_user_final表无账期数据,验证通过开始执行生成承诺号段最终帐单表存储过程create_item_user_final"
            dealMsg(msg)
            dealProc(cursor,createUser,arg)
        else:
            msg="charge_item_user_final表有账期数据,验证不通过,操作停止!!"
            dealMsg(msg)
            return "createMvFianlTableNotOk"
        rescheck=dealSqlRes(cursor,checkProcSql)
        if int(rescheck[0][0]) >0:
            msg="生成承诺号段最终帐单表存储过程create_item_user_final执行完成,开始进行下一步操作,数据平衡性校验"
            dealMsg(msg)
        else:
            msg="生成承诺号段最终帐单表存储过程create_item_user_final执行失败,操作停止!!"
            dealMsg(msg)
            return "createMvFianlTableNotOk"
        #----------------------------------
        verifResult=dealSqlRes(cursor,checkSql)
        for res in verifResult:
            e_value=dealSqlRes(cursor,res[2])[0][0]
            if compareValue(res[7],res[6],e_value):
                msg=res[5]
                dealMsg(msg)
            else:
                msg=res[4]
                dealMsg(msg)
                return "createMvFianlTableNotOk"
        return "createMvFianlTableIsOk"
    except Exception,e:
        err='%s %s' % (datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'),'execute dealFunc.createWanFianlTable falied')
        with open(r'./log/autoAccount_error.log','a') as error_log:
            print >> error_log,('%s %s') %(err,e)
예제 #17
0
def startConsAccount():
    try:
        msg= "-------开始执行企业级的合账程序操作------"
        dealMsg(msg)
        #-------------------    
        proc_item='item_final'
        proc_sum='sum_final'
        arg=[lastMonth]
        #------------------
        beforeCheckSql="select * from billing.auto_account_conf t where t.step_id=6 and t.auto_id in (55,56,57,58) and t.auto_flag='1' order by t.auto_id"
        afterCheckSql="select * from billing.auto_account_conf t where t.step_id='6' and t.auto_flag='1' and t.auto_id in (59,60,61,62,63,64,65) order by t.auto_id"
        #------------------------
        dblist=getConnectInfo(billfile)
        dbconn=connectDb(dblist[0])
        cursor=getCursor(dbconn)
        #----------------------------
        beforeResult=dealSqlRes(cursor,beforeCheckSql)
        for res in beforeResult:
            e_value=dealSqlRes(cursor,res[2])[0][0]
            if compareValue(res[7],res[6],e_value):
                msg=res[5]
                dealMsg(msg)
            else:
                msg=res[4]
                dealMsg(msg)
                return "startConsAccountNotOk"
        dealProc(cursor,proc_item,arg)
        dealProc(cursor,proc_sum,arg)
        time.sleep(10)
        msg="合账存储过程启动完成"
        dealMsg(msg)
        #------------------    
        afterResult=dealSqlRes(cursor,afterCheckSql)
        for res in afterResult:
            e_value=dealSqlRes(cursor,res[2])[0][0]
            if compareValue(res[7],res[6],e_value):
                msg=res[5]
                dealMsg(msg)    
            else:
                msg=res[4]
                dealMsg(msg)
                return "startConsAccountNotOk"
        return "startConsAccountIsOk"                                       
    except Exception,e:
        err='%s %s' % (datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'),'execute dealFunc.startConsAccount falied')
        with open(r'./log/autoAccount_error.log','a') as error_log:
            print >> error_log,('%s %s') %(err,e)
예제 #18
0
def getBusMark():
    try:
        filename='./config/dbinfo.ini'
        sql="select t.mvno_business_mark from dbvop.mvno_business t where t.mvno_business_mark !='VOPI'"
        mvnoList=[]
        dblist=getConnectInfo(filename)
        dbconn=connectDb(dblist[0])
        cursor=getCursor(dbconn)
        executeSQL(cursor,sql)
        result=getSQLrst(cursor)
        for res in result:
            mvnoList.append(res[0])
        return mvnoList
    except Exception,e:
        err='%s %s' % (datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'),'execute util.getBusMark falied')
        with open(r'./log/dealTable_error.log','a') as error_log:
            print >> error_log,('%s %s') %(err,e)
예제 #19
0
def startMvDiscount():
    try:
        msg="---------开始执行企业级流量批价,及阶梯优惠程序-----------"
        dealMsg(msg)
        start_disct="""source .bash_profile;cd /billapp1/4.1.05/release/billing/bin/disct;sh start_disct.sh &"""
        queryCmd="""ps -ef | grep 'start_disct.sh' | grep -v grep  | wc -l"""
        #--------------------------------------
        verifSql="select * from billing.auto_account_conf t where t.step_id='7' and t.auto_flag='1' and t.auto_id in (66,67,68,69,70) order by t.auto_id"
        #------------------
        dblist=getConnectInfo(billfile)
        dbconn=connectDb(dblist[0])
        cursor=getCursor(dbconn)  
        #----------------------------  
        resstr=sshCmd(ip_a,port,username,passwd,start_disct)
        if resstr=="sshCmdIsOk":
            msg="调用优惠程序启动脚本成功"
            dealMsg(msg)
            while 1:
                res=sshCmdRes(ip_a,port,username,passwd,queryCmd)
                res=int(res[0])
                if res == 0:
                    msg="优惠程序已经执行完毕,开始进行下一步操作,验证优惠数据准确性"
                    dealMsg(msg)
                    time.sleep(10)    
                    break  
        else:
            msg="调用优惠程序启动脚本失败,请检查程序,操作停止!!"
            dealMsg(msg) 
            return "startMvDiscountNotOk"  
        #-----------
        verifResult=dealSqlRes(cursor,verifSql)
        for res in verifResult:
            e_value=dealSqlRes(cursor,res[2])[0][0]
            if compareValue(res[7],res[6],e_value):
                msg=res[5]
                dealMsg(msg)  
            else:
                msg=res[4]
                dealMsg(msg)
                return "startMvDiscountNotOk"
        return "startMvDiscountIsOk"                   
    except Exception,e:
        err='%s %s' % (datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'),'execute dealFunc.startMvDiscount falied')
        with open(r'./log/autoAccount_error.log','a') as error_log:
            print >> error_log,('%s %s') %(err,e)
예제 #20
0
def getdbInfo(sql,dbname):
    try:
        dblist=getConnectInfo(dbname)
        dbconn=connectDb(dblist[0])
        cursor=getCursor(dbconn)
        executeSQL(cursor,sql)
        result=getSQLrst(cursor)
        infodict={}
        for res in result:
            if infodict.has_key(res[0]):
                infodict[res[0]].append(res[1:])
            else:
                infodict[res[0]]=[res[1:]]
        #print infodict
        return infodict
    except Exception,e:
        geterr='%s %s' % (datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'),'execute getdbInfo  falied')
        with open(r'./log/error.log','a') as error_log:
            print >> error_log,('%s %s' %(geterr,e))
예제 #21
0
def evenOddData(dbname):
    try:
        lastMonth=time.localtime()[1]-1 or 12
        dblist=getConnectInfo(dbname)
        dbconn=connectDb(dblist[0])
        cursor=getCursor(dbconn)
        if lastMonth % 2 !=0:
            sql=getSql('./config/even_odd_sql.txt')[1]
            executeSQL(cursor,sql)
            result=getSQLrst(cursor)
            return result
        else:
            sql=getSql('./config/even_odd_sql.txt')[0]
            executeSQL(cursor,sql)
            result=getSQLrst(cursor)
            return result
    except Exception,e:
        err='%s %s' % (datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'),'execute evenOddData  falied')
        with open(r'./log/error.log','a') as error_log:
            print >> error_log,('%s %s' %(err,e))
예제 #22
0
def insertRes(sql,tableName,type):
    try:
        filename='./config/dbinfo.ini'
        dblist=getConnectInfo(filename)
        dbconn=connectDb(dblist[0])
        cursor=getCursor(dbconn)
        executeSQL(cursor,sql)
        result=getSQLrst(cursor)
        insertList=[]
        for res in result:
            insertSql = "insert into vopbusmon.%s (%s,BUS_TYPE,RESULT1,RESULT2,RESULT3,RESULT4,EXEC_TIME) values ('%s','%s','%s','%s','%s','%s','%s')" % (tableName,type,res[0],res[1],res[2],res[3],res[4],res[5],res[6].strftime('%Y%m%d%H%M%S'))
            insertList.append(insertSql)
        for insert in insertList:
            executeSQL(cursor,insert)
        sqlcommit(dbconn)
        print 'insert is ok'
            
    except Exception,e:
        dealerr='%s %s' % (datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'),'execute insertRes  falied')
        with open(r'./log/error.log','a') as error_log:
            print >> error_log,('%s %s' %(dealerr,e))
예제 #23
0
def checkTmpSpace():
    try:
        msg= "-----------开始执行表空间检查操作--------------"
        dealMsg(msg)
        sql="select * from billing.auto_account_conf t where t.step_id=1 and t.auto_flag='1'"
        dblist=getConnectInfo(billfile)
        dbconn=connectDb(dblist[0])
        cursor=getCursor(dbconn)
        result=dealSqlRes(cursor,sql)
        for res in result:
            precent=dealSqlRes(cursor,res[2])[0][0]
            if compareValue(res[7],res[6],precent):
                msg=res[5] % precent
                dealMsg(msg)
                return 'checkTmpIsOk'
            else:
                msg=res[4] % precent
                dealMsg(msg)
                return 'checkTmpNotOk'
    except Exception,e:
        err='%s %s' % (datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'),'execute dealFunc.checkTmpSpace falied')
        with open(r'./log/autoAccount_error.log','a') as error_log:
            print >> error_log,('%s %s') %(err,e)
예제 #24
0
def dealTable():
    try:
        filename='./config/dbinfo.ini'
        querySql="select count(*) from user_tables where table_name='T_MVNO_USER'"
        dropSql="drop table DBVOP.T_MVNO_USER"
        createSql="CREATE TABLE DBVOP.T_MVNO_USER tablespace ts_vop  AS SELECT * FROM DBVOP.v_MVNO_USER WHERE 1=2"
        dblist=getConnectInfo(filename)
        dbconn=connectDb(dblist[0])
        cursor=getCursor(dbconn)
        executeSQL(cursor,querySql)
        result=getSQLrst(cursor)
        res=result[0][0]
        if res==0:
            info='%s %s' % (datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'),'表dbvop.T_MVNO_USER不存在')
            with open(r'./log/dealTable_info.log','a') as info_log:
                print >> info_log,('%s') %(info)
            cursor.execute(createSql)
            info='%s %s' % (datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'),'创建表dbvop.T_MVNO_USER')
            with open(r'./log/dealTable_info.log','a') as info_log:
                print >> info_log,('%s') %(info)
        else:
            info='%s %s' % (datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'),'表dbvop.T_MVNO_USER已存在')
            with open(r'./log/dealTable_info.log','a') as info_log:
                print >> info_log,('%s') %(info)
            cursor.execute(dropSql)
            info='%s %s' % (datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'),'删除表dbvop.T_MVNO_USER')
            with open(r'./log/dealTable_info.log','a') as info_log:
                print >> info_log,('%s') %(info)
            cursor.execute(createSql)
            info='%s %s' % (datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'),'创建表dbvop.T_MVNO_USER')
            with open(r'./log/dealTable_info.log','a') as info_log:
                print >> info_log,('%s') %(info)
    except Exception,e:
        err='%s %s' % (datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'),'execute util.dealTable falied')
        with open(r'./log/dealTable_error.log','a') as error_log:
            print >> error_log,('%s %s') %(err,e)
예제 #25
0
def dealMainA():
    try:
        #----
        proc_income="income_pro"
        proc_check='rp_yk_check'
        arg=[lastMonth]
        arg_r=[lastMonth,1]
        logname='./log/income_manage_info_A.log'
        #----
        dblist=getConnectInfo(billfile)
        dbconn=connectDb(dblist[0])
        cursor=getCursor(dbconn)
        #----
        msg='查看check_charge_item表pay_status =2的数据条数是否大于等于1'
        dealMsg(msg,logname)
        check_status_sql='''select count(*) from billing.check_charge_item  where acct_month=to_char(add_months(trunc(sysdate), -1), 'yyyymm') and pay_status =2'''
        res_status=dealSqlRes(cursor,check_status_sql)
        res_status=int(res_status[0][0])
        if res_status < 1:
            msg='check_charge_item表pay_status =2的数据条数小于1,检测不通过,程序A退出!'
            dealMsg(msg,logname)
            return
        msg='检查t_income_info表是否有账期数据'
        dealMsg(msg,logname)
        check_data_sql='''select count(1) from billing.t_income_info  where acct_month=to_char(add_months(trunc(sysdate), -1), 'yyyymm')'''
        res_d=dealSqlRes(cursor,check_data_sql)
        res_d=int(res_d[0][0])
        if res_d > 0:
            msg='t_income_info表是有账期数据,再执行插入操作,会报主键冲突错误,程序A退出'
            dealMsg(msg,logname)
            return
        msg='向表into t_income_info 插入账期数据'
        dealMsg(msg,logname)
        insert_sql='''insert into  billing.t_income_info values('%s','0','0')''' % lastMonth
        print insert_sql
        dealCommitSql(dbconn,cursor,insert_sql) 
        #----
        msg='A程序开始检测t_income_info表,账期内check_flag = 0的数据。。'
        dealMsg(msg,logname)
        check_flag_sql='''select count(1) from billing.t_income_info  where acct_month=to_char(add_months(trunc(sysdate), -1), 'yyyymm') and check_flag = 0'''
        res=dealSqlRes(cursor,check_flag_sql)
        res=int(res[0][0])
        if res < 1:
            msg='t_income_info表,账期内check_flag = 0的数据为0条,程序A退出!!'
            dealMsg(msg,logname)
            return
        msg='t_income_info表,账期内check_flag = 0的数据大于0条,检测通过,开始更新t_income_info表,使check_flag = 1'
        dealMsg(msg,logname)
        update_flag_sql='''update billing.t_income_info  set check_flag = 1 where acct_month=to_char(add_months(trunc(sysdate), -1), 'yyyymm')'''
        dealCommitSql(dbconn,cursor,update_flag_sql)
        check_update_sql='''select count(1) from billing.t_income_info  where acct_month=to_char(add_months(trunc(sysdate), -1), 'yyyymm') and check_flag = 1'''
        resup=dealSqlRes(cursor,check_update_sql)
        resup=int(resup[0][0])
        if resup < 1:
            msg='更新t_income_info表,使check_flag = 1失败,程序A退出!!'
            dealMsg(msg,logname)
            return
        msg='更新t_income_info表,使check_flag = 1成功,开始执行下一步操作,执行income_pro存储过程!!'
        dealMsg(msg,logname)
        dealProc(cursor,proc_income,arg)
        time.sleep(1)
        check_proc_sql='''select count(1) from billing.wrtoff_data where bill_cycle_id =to_char(add_months(trunc(sysdate), -1), 'yyyymm')'''
        respro=dealSqlRes(cursor,check_proc_sql)
        respro=int(respro[0][0])
        if respro < 1:
            msg='income_pro存储过程执行失败,程序A退出!!!'
            dealMsg(msg,logname)
            return
        msg='income_pro存储过程执行成功,开始执行下一步操作,启动导出线程。'
        dealMsg(msg,logname)
        start_cmd='''source .bash_profile;cd /billapp1/4.1.05/release/control/bin;sh start_income.sh & '''
        stop_cmd='''source .bash_profile;cd /billapp1/4.1.05/release/control/bin;sh stop_export.sh & '''
        check_cmd='''ps -ef | grep start_export | grep -v grep | wc -l'''
        res_start=sshCmd(ip_a,port,username,passwd,start_cmd)
        for i in range(10):
            res_export=sshCmdRes(ip_a,port,username,passwd,check_cmd)
            res_export=int(res_export[0])
            time.sleep(3)
            if res_export == 6:
                msg='导出线程启动成功,开始执行下一步操作,检查六张表的记录数'
                dealMsg(msg,logname)
                break
        else:
            msg='连续查看10次,导出线程都没有启动成功,程序A退出!'
            dealMsg(msg,logname)
            return
        check_sql_list=[
            "select count(1) from  billing.log_export_inco where to_char(finish_time,'YYYYMM')= to_char(sysdate,'YYYYMM')",
            "select count(1) from  billing.log_export_code where to_char(finish_time,'YYYYMM')= to_char(sysdate,'YYYYMM')",
            "select count(1) from  billing.log_export_busi where to_char(finish_time,'YYYYMM')= to_char(sysdate,'YYYYMM')",
            "select count(1) from  billing.log_export_comp where to_char(finish_time,'YYYYMM')= to_char(sysdate,'YYYYMM')",
            "select count(1) from  billing.log_export_rela where to_char(finish_time,'YYYYMM')= to_char(sysdate,'YYYYMM')",
            "select count(1) from  billing.log_export_woff where to_char(finish_time,'YYYYMM')= to_char(sysdate,'YYYYMM')"]
        for j in range(10):
            resList=dealQueryList(cursor,check_sql_list)
            res_min=min(resList)
            time.sleep(10)
            if res_min > 0:
                msg='六张表的记录数都大于1,开始执行下一步操作,停止导出线程!'
                dealMsg(msg,logname)
                break
        else:
            msg='连续查看10次,六张表的记录数都不大于1,程序A退出'
            dealMsg(msg,logname)
            return
        res_stop=sshCmd(ip_a,port,username,passwd,stop_cmd)
        for l in range(10):
            res_export=sshCmdRes(ip_a,port,username,passwd,check_cmd)
            res_export=int(res_export[0])
            time.sleep(3)
            if res_export == 0:
                msg='导出线程停止成功,开始执行下一步操作,启动rp_yk_check存储过程'
                dealMsg(msg,logname)
                break
        else:
            msg='连续10次查看,导出线程都没有停止成功,程序A退出!'
            dealMsg(msg,logname)
            return
        dealProc(cursor,proc_check,arg_r)
        check_pro_sql='''select count(1) from billing.RP_YK_CHECK_INFO yk_type where acct_month =to_char(add_months(trunc(sysdate), -1), 'yyyymm')'''
        resrp=dealSqlRes(cursor,check_pro_sql)
        resrp=int(resrp[0][0])
        if resrp < 1:
            msg='rp_yk_check存储过程执行失败,程序A退出!!!'
            dealMsg(msg,logname)
            return
        msg='rp_yk_check存储过程执行成功,开始执行下一步操作,更新t_income_info表,使check_flag=2,trans_flag = 1。'
        dealMsg(msg,logname) 
        update_trans_sql='''update billing.t_income_info  set check_flag = 2,trans_flag = 1 where acct_month=to_char(add_months(trunc(sysdate), -1), 'yyyymm')'''
        dealCommitSql(dbconn,cursor,update_trans_sql)
        check_trans_sql='''select count(1) from billing.t_income_info  where acct_month=to_char(add_months(trunc(sysdate), -1), 'yyyymm') and check_flag = 2 and trans_flag = 1''' 
        restra=dealSqlRes(cursor,check_trans_sql)
        restra=int(restra[0][0])
        if restra < 1:
            msg='更新t_income_info表,使check_flag=2,trans_flag = 1失败,程序A退出!'
            dealMsg(msg,logname)
            return
        msg='更新t_income_info表,使check_flag=2,trans_flag = 1成功,整个A步骤执行完成'
        dealMsg(msg,logname)    
    except Exception,e:
        err='%s %s' % (datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'),'execute dealMainA falied')
        with open(r'./log/income_manage_error.log','a') as error_log:
            print >> error_log,('%s %s') %(err,e)
예제 #26
0
def startMonthRent():
    try:
        msg= "----------开始执行跑月租操作------------"
        dealMsg(msg)
        sql01="select * from billing.auto_account_conf t where t.step_id=2 and t.auto_id=2 and t.auto_flag='1'"
        sql02="select * from billing.auto_account_conf t where t.step_id=2 and t.auto_id=3 and t.auto_flag='1'"
        start_rent="""source .bash_profile;cd /billapp1/4.1.05/release/billing/bin/rent;sh start_rent.sh &"""
        verifSql01="select count(1) from billing.cdr_rent_%s" % lastmonth
        verifSql02="select count(1) from billing.charge_item_rent where acct_month =%s" % lastMonth
        queryCmd="""ps -ef | grep start_rent | grep -v grep  | wc -l"""
        dblist=getConnectInfo(billfile)
        dbconn=connectDb(dblist[0])
        cursor=getCursor(dbconn)
        result01=dealSqlRes(cursor,sql01)
        result02=dealSqlRes(cursor,sql02)
        for res in result01:
            sql=res[2] % lastmonth
            e_value=dealSqlRes(cursor,sql)[0][0]
            if compareValue(res[7],res[6],e_value):
                msg=res[5] % lastmonth
                dealMsg(msg)    
            else:
                msg=res[4] % lastmonth
                print msg
                dealMsg(msg)
                return 'startRentNotOk'
        for res in result02:
            sql=res[2] % lastMonth
            e_value=dealSqlRes(cursor,sql)[0][0]
            if compareValue(res[7],res[6],e_value):
                msg=res[5]
                dealMsg(msg)    
            else:
                msg=res[4]
                dealMsg(msg)
                return 'startRentNotOk' 
              
        res=sshCmd(ip_a,port,username,passwd,start_rent)
        if res=="sshCmdIsOk":
            msg="月租程序执启动完成,等待执行完成!!!"
            dealMsg(msg)
        else:
            msg="月租程序启动报错,请检查程序,操作停止!!!"
            dealMsg(msg)
            return 'startRentNotOk'
        while 1:
            res=sshCmdRes(ip_a,port,username,passwd,queryCmd)
            res=int(res[0])
            if res == 0:
                msg='月租程序已经执行完成,执行下一步操作数据验证'
                dealMsg(msg)
                time.sleep(60)
                break      
        res01=dealSqlRes(cursor,verifSql01)
        res02=dealSqlRes(cursor,verifSql02)
        if int(res01[0][0]) > 0 and int(res02[0][0]) > 0:
            msg="月租表已经进入账期数据,验证成功,起月租程序执行完成"
            dealMsg(msg)
        else:
            msg="月租表没有进入账期数据,验证失败,操作停止"
            dealMsg(msg)                    
        return 'startRentIsOk'             
    except Exception,e:
        err='%s %s' % (datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'),'execute dealFunc.startMonthRent falied')
        with open(r'./log/autoAccount_error.log','a') as error_log:
            print >> error_log,('%s %s') %(err,e)
예제 #27
0
def startUpProAccount():
    try:
        msg="-------开始执行承诺号段补收-----------"
        dealMsg(msg)
        #----------
        createPro="CREATE_PROMISE_DETAIL"
        arg=[lastMonth]
        #----------------
        bakProList=["create table charge_item_disct_%s as select * from charge_item_disct" % this_month,"create table charge_item_prefix_%s  as select * from charge_item_prefix_disct" % this_month]
        checkTableList=["select count(*) from user_tables where table_name='CHARGE_ITEM_DISCT_%s'" %this_month,"select count(*) from user_tables where table_name='CHARGE_ITEM_PREFIX_%s'" %this_month]
        checkProList=["select count(1) from charge_item_disct","select count(1) from charge_item_prefix_disct"]
        checkBakProList=["select count(1) from charge_item_disct_%s" % this_month,"select count(1) from charge_item_prefix_%s" %this_month]
        checkProSql="select count(1) from CHARGE_PROMISE_DETAIL t where t.data_month=%s" % lastMonth
        #------------
        verifSql="select * from billing.auto_account_conf t  where t.step_id='10' and t.auto_flag='1' order by t.auto_id"    
        #---------------------------------    
        dblist=getConnectInfo(billfile)
        dbconn=connectDb(dblist[0])
        cursor=getCursor(dbconn)
        #------------------    
        msg="承诺补收执行前备份表charge_item_disct、charge_item_prefix_disct 为 charge_item_disct_%s、charge_item_prefix_%s" % (this_month,this_month)
        dealMsg(msg)
        restable=dealQueryList(cursor,checkTableList)
        if restable[0] == 0 and restable[1] == 0:
            dealSqlList(cursor,bakProList)
        else:
            msg="要备份的表已经存在,操作停止!!"
            dealMsg(msg)
            return "startUpProAccountNotOk"
        rescount=dealQueryList(cursor,checkProList)
        resbakcount=dealQueryList(cursor,checkBakProList)
        if rescount == resbakcount:
            msg="表charge_item_disct、charge_item_prefix_disct备份完成,开始执行下一步操作,执行补收存储过程"
            dealMsg(msg)
        else:
            msg="charge_item_disct、charge_item_prefix_disct备份失败,操作停止"
            dealMsg(msg)
            return "startUpProAccountNotOk" 
        resdata=dealSqlRes(cursor,checkProSql)
        if int(resdata[0][0]) == 0:
            msg="CHARGE_PROMISE_DETAIL 表无数据,验证通过,执行补收存储过程CREATE_PROMISE_DETAIL"
            dealMsg(msg)
            dealProc(cursor,createPro,arg)
        else:
            msg="CHARGE_PROMISE_DETAIL表有数据,验证不通过,操作停止!!"
            dealMsg(msg)
            return "startUpProAccountNotOk"
        time.sleep(10)
        resdetail=dealSqlRes(cursor,checkProSql) 
        if int(resdetail[0][0]) > 0 :
            msg="补收存储过程,执行完成,开始进行下一步操,验证补收数据准确性"
            dealMsg(msg)
        else:
            msg="补收存储过程,执行失败,操作停止!!"
            dealMsg(msg)
            return "startUpProAccountNotOk"
        #--------------------
        verifResult=dealSqlRes(cursor,verifSql)
        for res in verifResult:
            e_value=dealSqlRes(cursor,res[2])[0][0]
            if compareValue(res[7],res[6],e_value):
                msg=res[5]
                dealMsg(msg)
            else:
                msg=res[4]
                dealMsg(msg)
                return "startUpProAccountNotOk" 
        return "startUpProAccountIsOk"       
    except Exception,e:
        err='%s %s' % (datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'),'execute dealFunc.startUpProAccount falied')
        with open(r'./log/autoAccount_error.log','a') as error_log:
            print >> error_log,('%s %s') %(err,e)
예제 #28
0
def startDisctP2016():
    try:
        msg="------开始执行”国内数据折上折优惠”(P2016)优惠程序----------"
        dealMsg(msg)
        #------------                            
        dblist=getConnectInfo(billfile)
        dbconn=connectDb(dblist[0])
        cursor=getCursor(dbconn)
        #----------------------
        #-------------
        checkSql="select t.auto_sql_str from billing.auto_account_conf t  where t.step_id='9' and t.auto_flag='1' and t.auto_id in (76,77) order by t.auto_id"
        checkP2016Strs=dealSqlRes(cursor,checkSql)
        bakSql="select t.auto_sql_str from billing.auto_account_conf t  where t.step_id='9' and t.auto_flag='1' and t.auto_id in (78,79) order by t.auto_id"
        bakP2016Strs=dealSqlRes(cursor,bakSql)
        querybakSql="select t.auto_sql_str from billing.auto_account_conf t  where t.step_id='9' and t.auto_flag='1' and t.auto_id in (80,81) order by t.auto_id"
        querybakP2016Strs=dealSqlRes(cursor,querybakSql)
        querySql="select t.auto_sql_str from billing.auto_account_conf t  where t.step_id='9' and t.auto_flag='1' and t.auto_id in (82,83) order by t.auto_id"
        queryP2016Strs=dealSqlRes(cursor,querySql)
        #-------------
        checkSql01="select * from billing.auto_account_conf t  where t.step_id='9' and t.auto_flag='1' and t.auto_id in (84,85,86,87) order by t.auto_id"
        checkSql02="select * from billing.auto_account_conf t  where t.step_id='9' and t.auto_flag='1' and t.auto_id in (88,89,90,91) order by t.auto_id"
        checkSql03="select * from billing.auto_account_conf t  where t.step_id='9' and t.auto_flag='1' and t.auto_id in (92,93) order by t.auto_id"
        #-------------
        arg=[lastMonth,'P2016']
        proDisct='p_promot_disct'
        bakP2016Sqls=[]
        checkP2016Sqls=[]
        querybakP2016Sqls=[]
        queryP2016Sqls=[]
        #----------------------------
        for bakstr in bakP2016Strs:
            baksql=bakstr[0] % firstDay
            bakP2016Sqls.append(baksql)
        for qstr in querybakP2016Strs:
            qsql=qstr[0] % firstDay
            querybakP2016Sqls.append(qsql)
        for checkstr in checkP2016Strs:
            checksql = checkstr[0] % firstDay
            checkP2016Sqls.append(checksql)
        for querystr in  queryP2016Strs:
            querysql= querystr[0]
            queryP2016Sqls.append(querysql) 
        #----------------- 
        
        msg="开始执行备份表charge_item_disct、charge_item_prefix_disct为charge_item_disct_P2016_%s、charge_item_prefix_P2016_%s操作" %(firstDay,firstDay) 
        dealMsg(msg)
        rescheck=dealQueryList(cursor,checkP2016Sqls)
        if rescheck[0] != 0 and rescheck[1] != 0:
            msg="要备份的表已经存在,操作停止!!" 
            dealMsg(msg)
            return "startDisctP2016NotOk"
        resbak=dealSqlList(cursor,bakP2016Sqls)
        resq=dealQueryList(cursor,queryP2016Sqls)
        resqbak=dealQueryList(cursor,querybakP2016Sqls)
        if resq == resqbak:
            msg="验证备份表和原表数据一致,备份charge_item_disct、charge_item_prefix_disct表 成功,开始执行下一步操作,起P2016优惠存储过程"               
            dealMsg(msg)
        else:
            msg="验证备份表和原表数据不一致,备份charge_item_disct、charge_item_prefix_disct表 失败,操作停止!!"               
            dealMsg(msg)  
            return "startDisctP2016NotOk" 
        #-----------------------
        dealProc(cursor,proDisct,arg)
        time.sleep(10)
        #--------------------
        Result01=dealSqlRes(cursor,checkSql01)
        for res in Result01:
            sql=res[2] % (firstDay,lastMonth)
            e_value=dealSqlRes(cursor,sql)[0][0]
            if compareValue(res[7],res[6],e_value):
                msg=res[5]
                dealMsg(msg)
            else:
                msg=res[4]
                dealMsg(msg)
                return "startDisctP2016NotOk" 
        #----------------  
        Result02=dealSqlRes(cursor,checkSql02)
        for res in Result02:
            e_value=dealSqlRes(cursor,res[2])[0][0]
            if compareValue(res[7],res[6],e_value):
                msg=res[5]
                dealMsg(msg)
            else:
                msg=res[4]
                dealMsg(msg)
                return "startDisctP2016NotOk"
        #----------------
        Result03=dealSqlRes(cursor,checkSql03)
        for res in Result03:
            sql=res[2] % (firstDay,lastMonth,firstDay,lastMonth,lastMonth)
            e_value=dealSqlRes(cursor,sql)[0][0]
            if compareValue(res[7],res[6],e_value):
                msg=res[5]
                dealMsg(msg)
            else:
                msg=res[4]
                dealMsg(msg)
                return "startDisctP2016NotOk"  
        return "startDisctP2016IsOk"                                                              
    except Exception,e:
        err='%s %s' % (datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'),'execute dealFunc.startUpProAccount falied')
        with open(r'./log/autoAccount_error.log','a') as error_log:
            print >> error_log,('%s %s') %(err,e)
예제 #29
0
def bakTrunTable():
    try:
        msg= "-----------开始执行备份累帐、合并日志表操作--------------"
        dealMsg(msg)
        bakSql="select t.auto_sql_str from billing.auto_account_conf t where t.step_id=5 and t.auto_id in (4,5,6,7,8,9,10,11,12,13,14,15) and t.auto_flag='1'"
        checkSql="select t.auto_sql_str from billing.auto_account_conf t where t.step_id=5 and t.auto_id in (16,17,18,19,20,21,22,23,24,25,26,27) and t.auto_flag='1'"
        querySql="select t.auto_sql_str from billing.auto_account_conf t where t.step_id=5 and t.auto_id in (28,29,30,31,32,33,34,35,36,37,38,39) and t.auto_flag='1'"
        querybakSql="select t.auto_sql_str from billing.auto_account_conf t where t.step_id=5 and t.auto_id in (40,41,42,43,44,45,46,47,48,49,50,51) and t.auto_flag='1'"
        trunSql="select t.auto_sql_str from billing.auto_account_conf t where t.step_id=5 and t.auto_id in (52,53,54) and t.auto_flag='1'"
        checkTrunSqls=["select count(1) from log_unite_usum","select count(1) from log_unite_usum_list","select count(1) from log_sum_vop"]
        trunList=[]
        querySqlList=[]
        checkTableList=[]
        querybakSqlList=[]
        bakSqlList=[]  
        #---------------
        dblist=getConnectInfo(billfile)
        dbconn=connectDb(dblist[0])
        cursor=getCursor(dbconn)
        #---------------
        bakStrList=dealSqlRes(cursor,bakSql)
        for bakstr in bakStrList:
            baksql=bakstr[0] % lastMonth
            bakSqlList.append(baksql)
        checkTableStrs=dealSqlRes(cursor,checkSql)    
        for checkstr in  checkTableStrs:
            checksql=checkstr[0] % lastMonth
            checkTableList.append(checksql)
        queryStrs=dealSqlRes(cursor,querySql)
        for querystr in queryStrs:
            querysql=querystr[0]
            querySqlList.append(querysql)
        querybakStrs=dealSqlRes(cursor,querybakSql) 
        for querybakstr in querybakStrs:
            querybaksql=querybakstr[0] % lastMonth
            querybakSqlList.append(querybaksql)  
        trunStrs=dealSqlRes(cursor,trunSql)
        for trunstr in trunStrs:
            trunsql=trunstr[0]
            trunList.append(trunsql)            
        msg='开始备份表log_unite_usum、log_unite_usum_list、log_sum_vop等表,为log_unite_usum_%s、log_unite_usum_list_%s、log_sum_vop_%s 等表' % (lastMonth,lastMonth,lastMonth)
        dealMsg(msg)   
        for cksql in checkTableList:
            res=dealSqlRes(cursor,cksql)
            res=int(res[0][0])
            if res != 0:
                msg="要备份的表已经存在,操作停止!!,查询sql:%s" %cksql
                dealMsg(msg)
                return 'bakTableNotOk' 
        #开始备份表    
        res=dealSqlList(cursor,bakSqlList)       
        if res == "dealSqlListIsOk":
            msg="表log_unite_usum、log_unite_usum_list、log_sum_vop等表备份完成"
            dealMsg(msg)
        else:
            msg='备份表时,程序报错,请检查程序!!' 
            dealMsg(msg)
            return 'bakTableNotOk'         
        resquery=dealQueryList(cursor,querySqlList)
        resbak=dealQueryList(cursor,querybakSqlList)
        print resquery,resbak
        if resquery == resbak:
            msg="验证备份表和原表数据一致,备份log_unite_usum、log_unite_usum_list、log_sum_vop等表 成功"
            dealMsg(msg)
        else:
            msg="验证备份表和原表数据不一致,备份log_unite_usum、log_unite_usum_list、log_sum_vop 等表失败,操作停止!!!"
            dealMsg(msg)
            return 'bakTableNotOk'
        msg="开始删除表log_unite_usum、log_unite_usum_list、log_sum_vop里的数据"
        dealMsg(msg)
        dealSqlList(cursor,trunList)
        resquery=dealQueryList(cursor,checkTrunSqls)
        if resquery[0] == 0 and resquery[1] == 0 and resquery[2] == 0:
            msg="表log_unite_usum、log_unite_usum_list、log_sum_vop数据删除成功,备份累帐、合并日志表操作完成"
            dealMsg(msg)
            return 'bakTableIsOk'
        else:
            msg="表log_unite_usum、log_unite_usum_list、log_sum_vop数据删除失败!程序停止!!"
            dealMsg(msg)
            return 'bakTableNotOk'
    except Exception,e:
        err='%s %s' % (datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'),'execute dealFunc.bakTrunTable falied')
        with open(r'./log/autoAccount_error.log','a') as error_log:
            print >> error_log,('%s %s') %(err,e)
예제 #30
0
def dealMainB():
    try:
        dblist=getConnectInfo(billfile)
        dbconn=connectDb(dblist[0])
        cursor=getCursor(dbconn)
        logname='./log/income_manage_info_B.log'
        msg='B程序开始检测t_income_info表,账期内trans_flag = 2的数据'
        dealMsg(msg,logname)
        check_tra_sql='''select count(1) from billing.t_income_info where acct_month=to_char(add_months(trunc(sysdate), -1), 'yyyymm') and trans_flag = 2'''
        res=dealSqlRes(cursor,check_tra_sql)
        res=int(res[0][0])
        if res < 1:
            msg='t_income_info表,账期内trans_flag = 2的数据条数为0,检测不通过,程序B退出'
            dealMsg(msg,logname)
            return
        msg='t_income_info表,账期内trans_flag = 2的数据条数大于0,检测通过,执行下一步操作,更新t_income_info ,使trans_flag = 3'
        dealMsg(msg,logname)
        update_tra_sql='''update billing.t_income_info  set trans_flag = 3 where acct_month=to_char(add_months(trunc(sysdate), -1), 'yyyymm')'''
        dealCommitSql(dbconn,cursor,update_tra_sql)
        check_uptra_sql='''select count(1) from billing.t_income_info where acct_month=to_char(add_months(trunc(sysdate), -1), 'yyyymm') and trans_flag = 3'''
        resup=dealSqlRes(cursor,check_uptra_sql)
        resup=int(resup[0][0])
        if resup < 1:
            msg='更新t_income_info ,使trans_flag = 3失败,程序B退出!!'
            dealMsg(msg,logname)
            return
        msg='更新t_income_info ,使trans_flag = 3成功,开始执行下一步操作,启动采集线程'
        dealMsg(msg,logname)
        start_cmd='''source .bash_profile;cd /billapp1/4.1.05/release/billing/bin;nohup start_acquire -h `hostname` -m 11 -p 93 -t 11930101 >/dev/null 2>&1 &'''
        stop_cmd='''ps -ef|grep "start_acquire"|grep 11930101  |grep -v grep|awk '{print "kill -9 "$2;}'|sh'''
        check_cmd='''ps -ef | grep start_acquire | grep 11930101 | grep -v grep | wc -l'''
        print ' begin start '
        res_start=sshCmd(ip_a,port,username,passwd,start_cmd)
        print 'start end'
        for i in range(10):
            res_check=sshCmdRes(ip_a,port,username,passwd,check_cmd)
            res_check=int(res_check[0])
            time.sleep(3)
            if res_check ==1:
                msg='采集线程启动成功,开始执行下一步操作,验证ft_log_vop_income 表数据条数'
                dealMsg(msg,logname)
                break
        else:
            msg='连续查看采集线程10次,采集线程没有启动,程序B退出'
            dealMsg(msg,logname)
            return     
        check_start_sql='''select  count(1) from billing.ft_log_vop_income where to_char(deal_time,'YYYYMMDD')= to_char(sysdate,'YYYYMMDD')'''
        for j in range(10):
            resaq=dealSqlRes(cursor,check_start_sql)
            resaq=int(resaq[0][0])
            time.sleep(10)
            if resaq >= 6:
                print 'resaq'
                msg='ft_log_vop_income 表数据条数大于6,验证通过,开始执行下一步操作,停止刚启动的采集线程'
                dealMsg(msg,logname)
                break
        else:
            msg='连续查看ft_log_vop_income 表数据条数10次都没有大于6,程序B退出' 
            dealMsg(msg,logname)
            return  
        res_stop=sshCmd(ip_a,port,username,passwd,stop_cmd)
        for l in range(3):
            res_check=sshCmdRes(ip_a,port,username,passwd,check_cmd)
            res_check=int(res_check[0])
            time.sleep(3)
            if res_check ==0:
                msg='采集线程停止成功,开始执行下一步操作,更新表t_income_info'
                dealMsg(msg,logname)
                break
        else:
            mag='连续查看采集线程是否停止10次,程序都没有停止,程序B退出'
            dealMsg(msg,logname)
            return
        msg='开始执行更新t_income_info对应账期中的trans_flag 为4的操作'
        dealMsg(msg,logname)
        update_tra4_sql='''update billing.t_income_info  set trans_flag =4 where acct_month=to_char(add_months(trunc(sysdate), -1), 'yyyymm')'''
        dealCommitSql(dbconn,cursor,update_tra4_sql)
        check_tra4_sql='''select count(1) from billing.t_income_info where acct_month=to_char(add_months(trunc(sysdate), -1), 'yyyymm') and trans_flag = 4'''
        restra4=dealSqlRes(cursor,check_tra4_sql)
        restra4=int(restra4[0][0])
        if restra4 < 1:
            msg='''更新t_income_info对应账期中的trans_flag 为4失败,程序B退出!!'''
            dealMsg(msg,logname)
            return
        msg='更新t_income_info对应账期中的trans_flag 为4成功,整个步骤B执行完成'
        dealMsg(msg,logname)
    except Exception,e:
        err='%s %s' % (datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'),'execute dealMainB falied')
        with open(r'./log/income_manage_error.log','a') as error_log:
            print >> error_log,('%s %s') %(err,e)