
import traceback
from BaseDataMaintenance.model.oracle.TouSuTemp import SouSuTemp

dict_replace = {""}

class WeiFaJiLuTemp(SouSuTemp):

    def __init__(self,_dict):
        SouSuTemp.__init__(self,_dict)
        self.table_name = "bxkc.t_wei_fa_ji_lu_temp"
        self.setValue("docchannel",303,True)
        self.setValue("original_type","wei_fa_ji_lu",True)

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

    @staticmethod
    def synchonize():
        try:
            print("123")
            from BaseDataMaintenance.dataSource.source import getConnection_oracle
            conn = getConnection_oracle()
            cursor = conn.cursor()
            has_commit = 0
            while 1:
                sql = '''
                INSERT INTO bxkc.t_wei_fa_ji_lu_temp
SELECT *
FROM (
         SELECT w.*
         FROM bxkc.t_wei_fa_ji_lu w
                  LEFT JOIN bxkc.id_wei_fa_ji_lu b ON w.id = b.id
         WHERE b.id IS not NULL
     ) res
WHERE ROWNUM < 10001
                '''
                cursor.execute(sql)
                row_effected = cursor.rowcount

                if row_effected==0:
                    break
                print("row_effected",row_effected)
                sql1 = '''
                delete bxkc.id_wei_fa_ji_lu where id in (select id from bxkc.t_wei_fa_ji_lu_temp)
                '''
                cursor.execute(sql1)
                conn.commit()


        except Exception as e:
            traceback.print_exc()


if __name__ == '__main__':
    WeiFaJiLuTemp.synchonize()
