# Author renyupeng # coding=utf-8 # @Time : 2024/6/27 20:28 # @Site : # @File : UpLoadFile.py # @Software: PyCharm # @contact: renyupeng@c-top.com.cn # @Tel 1501435553 from urllib import parse import pandas as pd from sqlalchemy import create_engine class UpLoadFile: @staticmethod def uploadFile(file_name): OuterStr = "mysql+pymysql://%s:%s@%s:%d/%s" % ( "hcst", parse.quote_plus("hcst@2024"), "192.168.0.101", 3390, "jeecg-boot") OuterConn = create_engine(OuterStr, pool_size=10, max_overflow=5, pool_timeout=10, pool_recycle=3600) chunksize = 100000 for chunk in pd.read_csv(f'/home/excel/{file_name}'.format(file_name=file_name), chunksize=chunksize, encoding='GBK', header=None, low_memory=False, skiprows=1): # 将每个块存入MySQL,'表名'需要替换为目标表名 chunk.columns = ['delivery_month', 'operation_label', 'material_id', 'str_material_id', 'account_id', 'stat_date', 'str_account_id', 'account_name', 'ad_ids', 'customer_name', 'user_name', 'rebate_type', 'settlement_1l', 'settlement_2l', 'first_valid', 'cost_7day', 'cost'] try: chunk.to_sql('first_delivery_valid_materials', con=OuterConn, index=False, if_exists='append' ) return 0 except Exception as e: print(e) return -1