| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 | 
							- # 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
 
- if __name__ == '__main__':
 
-     UpLoadFile.uploadFile('upload.csv')
 
 
  |