财务一体化系统,自动核销大数据代码:
1 import pymysql 2 import random 3 import time 4 #指定数据库地址、用户、密码、端口,使用connect()方法声明一个Mysql连接对象db 5 db = pymysql.connect(host='192.168.21.163', user='root', password='root', port=3306, db='cwyth_test') 6 #调用cursor()方法获得Mysql的操作游标,利用游标来执行SQL语句。 7 cursor = db.cursor() 8 for i in range(20): 9 # 定义数据 10 date_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())) 11 str_num = str(random.randint(10000000000, 99999999999)) 12 cguid = '2019121001205{}47b2c57'.format(str_num) 13 fphm = '15' + str(random.randint(100000000, 999999999)) 14 fpdm = '3302193130' 15 gfsh = '91' + str(random.randint(100000, 999999)) + 'MA2GW75HXJ' 16 gfmc = '宁波Python{}有限公司'.format(str_num) 17 kprq = date_time 18 jshjje = str(random.randint(1, 9999)) 19 kpr = '钟无艳' 20 hxzt = '0' 21 hxr = '' 22 shzt = '0' 23 shr = '' 24 rzrq = time.strftime('%Y-%m-%d', time.localtime(time.time())) #此处为自动核销的数据,如果要手动核销,请传空值 25 rzje = jshjje #此处为自动核销的数据,如果要手动核销,请传空值 26 hxr_name = '' 27 shr_name = '' 28 account = '3901310009001065109' 29 dwmc = gfmc 30 jylx = '转账' 31 pzzl = '资金汇划补充凭证' 32 pzh = str(random.randint(10000000, 99999999)) 33 dfzh = gfmc 34 dfhm = '3901310009101000264' 35 msg = 'HWNK_10千伏高南C525' 36 add_time = date_time 37 num = 0 38 # SQL 插入语句 39 #往表t_invoice插入数据 40 sql = """INSERT INTO t_invoice(cguid, 41 fphm, fpdm, gfsh, gfmc, kprq, jshjje, kpr, hxzt, hxr, shzt, shr, rzrq, rzje, hxr_name, shr_name) 42 VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)""" 43 cursor.execute(sql, (cguid, fphm, fpdm, gfsh, gfmc, kprq, jshjje, kpr, hxzt, hxr, shzt, shr, rzrq, rzje, hxr_name, shr_name)) 44 db.commit() 45 # 往表t_bill插入数据 46 sql2 = """INSERT INTO t_bill(cguid, 47 account, dwmc, rzrq, rzje, jylx, pzzl, pzh, dfzh, dfhm, msg, add_time) 48 VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)""" 49 cursor.execute(sql2, (cguid, account, dwmc, rzrq, rzje, jylx, pzzl, pzh, dfzh, dfhm, msg, add_time)) 50 db.commit() 51 num += i 52 print('已经成功执行:{}次'.format(num)) 53 db.close()