Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
eshiled-new
/
deal_mysql_data
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit ecd46641
authored
Apr 11, 2023
by
杨林龙
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
添加数据处理脚本--分摊
1 parent
bc96a968
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
30 deletions
fentan/deal02.py
fentan/deal02.py
View file @
ecd4664
...
@@ -3,8 +3,10 @@ import time
...
@@ -3,8 +3,10 @@ import time
from
datetime
import
datetime
from
datetime
import
datetime
from
decimal
import
Decimal
from
decimal
import
Decimal
import
MySQLdb
from
dateutil.relativedelta
import
*
from
dateutil.relativedelta
import
*
from
fentan.base_create_table
import
BaseCreateTable
from
my_utils.MysqlUtility
import
MySQL
from
my_utils.MysqlUtility
import
MySQL
logger
=
logging
.
getLogger
(
'deal_equity_data'
)
logger
=
logging
.
getLogger
(
'deal_equity_data'
)
...
@@ -106,16 +108,14 @@ def deal_jianshao_equity_data():
...
@@ -106,16 +108,14 @@ def deal_jianshao_equity_data():
SELECT order_id ,LEFT(apportionment_date,4) AS `year`,`apportionment_price`,`apportionment_price` ,count(1) AS num , `apportionment_price`
SELECT order_id ,LEFT(apportionment_date,4) AS `year`,`apportionment_price`,`apportionment_price` ,count(1) AS num , `apportionment_price`
FROM temp_eq_order_ft GROUP BY LEFT(apportionment_date,4),order_id ;
FROM temp_eq_order_ft GROUP BY LEFT(apportionment_date,4),order_id ;
'''
'''
if
not
bizConn
.
query
(
sql
):
logger
.
info
(
sql
)
logger
.
error
(
"deal_equity_data fail, sql=
%
s"
,
sql
)
bizConn
.
insert
(
sql
)
return
sql
=
'''
sql
=
'''
UPDATE temp_eq_order_zj SET `jianshao_total_price` = `jianshao_num`*`jianshao_unit_price` WHERE 1=1;
UPDATE temp_eq_order_zj SET `jianshao_total_price` = `jianshao_num`*`jianshao_unit_price` WHERE 1=1;
'''
'''
if
not
bizConn
.
query
(
sql
):
logger
.
info
(
sql
)
logger
.
error
(
"deal_equity_data fail, sql=
%
s"
,
sql
)
bizConn
.
update
(
sql
)
return
def
deal_zengjia_equity_data
():
def
deal_zengjia_equity_data
():
...
@@ -196,17 +196,18 @@ def deal_null_equity_data():
...
@@ -196,17 +196,18 @@ def deal_null_equity_data():
sql
=
f
'''
sql
=
f
'''
UPDATE temp_eq_order_zj set zengjia_num = 0 ,zengjia_total_price = 0 WHERE zengjia_num IS NULL ;
UPDATE temp_eq_order_zj set zengjia_num = 0 ,zengjia_total_price = 0 WHERE zengjia_num IS NULL ;
'''
'''
logger
.
info
(
sql
)
bizConn
.
update
(
sql
)
bizConn
.
update
(
sql
)
sql
=
f
'''
sql
=
f
'''
UPDATE temp_eq_order_zj set qichu_num = 0 ,qichu_total_price = 0 WHERE qichu_num IS NULL ;
UPDATE temp_eq_order_zj set qichu_num = 0 ,qichu_total_price = 0 WHERE qichu_num IS NULL ;
'''
'''
logger
.
info
(
sql
)
bizConn
.
update
(
sql
)
bizConn
.
update
(
sql
)
def
export_csv
():
def
export_csv
(
fileName
):
bizConn
=
MySQL
(
saas_shen_db_cfg
)
bizConn
=
MySQL
(
saas_shen_db_cfg
)
fileName
=
"分摊汇总.csv"
fileHandle
=
open
(
file
=
fileName
,
mode
=
'w'
,
encoding
=
"utf-8"
)
fileHandle
=
open
(
file
=
fileName
,
mode
=
'w'
,
encoding
=
"utf-8"
)
yearList
=
[
2022
,
2023
,
2024
,
2025
]
yearList
=
[
2022
,
2023
,
2024
,
2025
]
headName
=
"customer_name,customer_phone,contract_no,success_date,billing_date,merchant_id,merchant_name,stand_no,vehicle_brand_name,"
\
headName
=
"customer_name,customer_phone,contract_no,success_date,billing_date,merchant_id,merchant_name,stand_no,vehicle_brand_name,"
\
...
@@ -259,33 +260,37 @@ def export_csv():
...
@@ -259,33 +260,37 @@ def export_csv():
fileHandle
.
close
()
fileHandle
.
close
()
def
my_func_test
():
bizConn
=
MySQL
(
saas_shen_db_cfg
)
sql
=
f
'''
SELECT id,order_id,order_year,qichu_num,qichu_unit_price,qichu_total_price,zengjia_num,zengjia_unit_price,zengjia_total_price,jianshao_num, jianshao_unit_price,jianshao_total_price
FROM temp_eq_order_zj teoz WHERE teoz.order_id = 1 AND teoz.order_year = 2024;
'''
if
not
bizConn
.
query
(
sql
):
logger
.
error
(
"deal_equity_data fail, sql=
%
s"
,
sql
)
result
=
bizConn
.
fetchAllRows
()
logger
.
info
(
'result:'
+
str
(
result
))
print
(
'result:'
+
str
(
result
))
if
len
(
result
)
==
0
:
logger
.
info
(
"null"
)
for
row
in
result
:
logger
.
info
(
row
)
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
# 创建数据表
# 创建数据表
#
BaseCreateTable().create_table()
BaseCreateTable
()
.
create_table
()
# 处理基础数据
# 处理基础数据
#
deal_equity_data()
deal_equity_data
()
# 处理减少数据
# 处理减少数据
#
deal_jianshao_equity_data()
deal_jianshao_equity_data
()
# 处理增加数据
# 处理增加数据
#
deal_zengjia_equity_data()
deal_zengjia_equity_data
()
# 处理期初数据
# 处理期初数据
#
deal_qichu_equity_data()
deal_qichu_equity_data
()
# 处理为NULL的数据
# 处理为NULL的数据
#
deal_null_equity_data()
deal_null_equity_data
()
# 导出 csv
# 导出 csv
export_csv
()
export_csv
(
"分摊汇总-20230411.csv"
)
# 自测方法
# bizConn = MySQL(saas_shen_db_cfg)
# my_func_test()
# sql = f'''
# SELECT id,order_id,order_year,qichu_num,qichu_unit_price,qichu_total_price,zengjia_num,zengjia_unit_price,zengjia_total_price,jianshao_num, jianshao_unit_price,jianshao_total_price
# FROM temp_eq_order_zj teoz WHERE teoz.order_id = 1 AND teoz.order_year = 2024;
# '''
# if not bizConn.query(sql):
# logger.error("deal_equity_data fail, sql=%s", sql)
# result = bizConn.fetchAllRows()
# logger.info('result:' + str(result))
# print('result:' + str(result))
# if len(result) == 0:
# logger.info("null")
# for row in result:
# logger.info(row)
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment