Ejemplo n.º 1
0
def exec_task(sql):
    records = prod_execute_sql(conn_type=CONN_TYPE, sqltype='select', sql=sql)

    # log.info(sql)

    if records and len(records) > 0:
        result = []

        for idx, record in enumerate(records):
            finance_meeting_id = str(record[0])
            meet_addr = str(record[1])  # 会议地址
            sales_name = str(record[2])  # 开票公司
            sales_addressphone = str(record[3])  # 开票地址及电话
            sales_bank = str(record[4])  # 发票开会行
            sales_taxno = str(record[5])  # 纳税人识别号
            invo_code = str(record[6])  # 纳税人识别号

            # sales_address = match_area.query_sales_address(sales_name=sales_name, sales_addressphone=sales_addressphone,
            #                                                sales_bank=sales_bank)  # 发票开票地(最小行政)
            #
            # receipt_city = match_area.query_receipt_city(sales_name=sales_name, sales_addressphone=sales_addressphone,
            #                                              sales_bank=sales_bank)  # 发票开票所在市

            sales_address, receipt_city, receipt_province = operate_every_record(
                record)

            sales_taxno = process_invalid_content(sales_taxno)
            meet_addr = process_invalid_content(meet_addr)
            sales_name = process_invalid_content(sales_name)
            sales_addressphone = process_invalid_content(sales_addressphone)
            sales_bank = process_invalid_content(sales_bank)
            sales_address = match_area.filter_area(
                process_invalid_content(sales_address))
            receipt_city = match_area.filter_area(
                process_invalid_content(receipt_city))
            receipt_province = match_area.filter_area(
                process_invalid_content(receipt_province))
            pstng_date = '无'

            # log.info(f" {threading.current_thread().name} is running ")
            record_str = f'{finance_meeting_id}\u0001{sales_taxno}\u0001{invo_code}\u0001{meet_addr}\u0001{sales_name}\u0001{sales_addressphone}\u0001{sales_bank}\u0001{sales_address}\u0001{receipt_province}\u0001{receipt_city}\u0001{pstng_date}'
            result.append(record_str)

            # print(record_str)
            # print('')

            if len(result) >= 100:
                for item in result:
                    with open(dest_file, "a+", encoding='utf-8') as file:
                        file.write(item + "\n")
                result = []

        if len(result) > 0:
            for item in result:
                with open(dest_file, "a+", encoding='utf-8') as file:
                    file.write(item + "\n")

        del result
Ejemplo n.º 2
0
def exec_task(sql, year):
    dest_file = get_dest_file(year)

    log.info(sql)
    start_time0 = time.perf_counter()
    records = prod_execute_sql(conn_type=CONN_TYPE, sqltype='select', sql=sql)
    consumed_time0 = (time.perf_counter() - start_time0)
    log.info(f'* 取数耗时 => {consumed_time0} sec, records={len(records)}')

    # gevent.sleep(1)

    if records and len(records) > 0:
        result = []

        for idx, record in enumerate(records):
            start_time1 = time.perf_counter()

            destin_name = str(record[0]) if record[0] else None  # 行程目的地
            sales_name = str(record[1]) if record[1] else None  # 开票公司
            sales_addressphone = str(record[2]) if record[2] else None  # 开票地址及电话
            sales_bank = str(record[3]) if record[3] else None  # 发票开户行
            finance_travel_id = str(record[4]) if record[4] else None
            origin_name = str(record[5]) if record[5] else None  # 行程出发地
            invo_code = str(record[6]) if record[6] else None  # 发票代码
            sales_taxno = str(record[7]) if record[7] else None  # 纳税人识别号

            sales_address, receipt_city, receipt_province = operate_every_record(record)

            origin_province = province_service.query_belong_province(area_name=origin_name)  # 行程出发地(省)

            # 根据行程目的地和发票代码找到行程所在的省
            # destin_province = province_service.query_destin_province(invo_code=invo_code,
            #                                                          destin_name=destin_name)  # 行程目的地(省)
            destin_province = province_service.query_belong_province(area_name=destin_name) # 行程目的地(省)

            # origin_province = None
            # destin_province = None

            origin_name = process_invalid_content(origin_name)  # 行程出发地(市)
            sales_name = process_invalid_content(sales_name)  # 开票公司
            sales_addressphone = process_invalid_content(sales_addressphone)  # 开票地址及电话
            sales_bank = process_invalid_content(sales_bank)  # 发票开户行
            invo_code = process_invalid_content(invo_code)  # 发票代码
            sales_address = match_area.filter_area(process_invalid_content(sales_address))  # 发票开票地(市)
            origin_province = process_invalid_content(origin_province)  # 行程出发地(省)
            destin_province = process_invalid_content(destin_province)  # 行程目的地(省)
            receipt_city = match_area.filter_area(process_invalid_content(receipt_city))  # 发票开票所在市
            receipt_province = match_area.filter_area(process_invalid_content(receipt_province))  # 发票开票所在省

            destin_name = process_invalid_content(destin_name)
            sales_taxno = process_invalid_content(sales_taxno)
            pstng_date = year

            consumed_time1 = (time.perf_counter() - start_time1)
            # log.info(f'* {threading.current_thread().name} 生成每行数据耗时 => {consumed_time1} sec, idx={idx}, year={year}')

            record_str = f'{finance_travel_id}\u0001{origin_name}\u0001{destin_name}\u0001{sales_name}\u0001{sales_addressphone}\u0001{sales_bank}\u0001{invo_code}\u0001{sales_taxno}\u0001{sales_address}\u0001{origin_province}\u0001{destin_province}\u0001{receipt_province}\u0001{receipt_city}\u0001{pstng_date}'
            # print(record_str)
            # print('')

            result.append(record_str)

            if len(result) >= 200:
                for item in result:
                    with open(dest_file, "a+", encoding='utf-8') as file:
                        file.write(item + "\n")
                result = []

        if len(result) > 0:
            for item in result:
                with open(dest_file, "a+", encoding='utf-8') as file:
                    file.write(item + "\n")

        del result