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 b486562d
authored
Apr 14, 2023
by
杨林龙
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
添加数据处理脚本--分摊
1 parent
0d8d5a84
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
48 additions
and
7 deletions
deal02_yang.py
deal02_yang.py
View file @
b486562
...
@@ -2,6 +2,7 @@ import logging
...
@@ -2,6 +2,7 @@ import logging
import
time
import
time
from
datetime
import
datetime
from
datetime
import
datetime
from
decimal
import
Decimal
from
decimal
import
Decimal
from
itertools
import
groupby
from
dateutil.relativedelta
import
*
from
dateutil.relativedelta
import
*
...
@@ -110,7 +111,7 @@ def export_csv(fileName):
...
@@ -110,7 +111,7 @@ def export_csv(fileName):
bizConn
=
MySQL
(
saas_shen_db_cfg
)
bizConn
=
MySQL
(
saas_shen_db_cfg
)
fileHandle
=
open
(
file
=
fileName
,
mode
=
'w'
,
encoding
=
"utf-8"
)
fileHandle
=
open
(
file
=
fileName
,
mode
=
'w'
,
encoding
=
"utf-8"
)
monthList
=
[]
monthList
=
[]
for
i
in
range
(
18
1
):
for
i
in
range
(
18
4
):
start_time
=
datetime
.
strptime
(
'2013-01-01'
,
'
%
Y-
%
m-
%
d'
)
start_time
=
datetime
.
strptime
(
'2013-01-01'
,
'
%
Y-
%
m-
%
d'
)
# 添加一个月的日期
# 添加一个月的日期
monthList
.
append
(
add_one_month
(
start_time
,
i
)
.
date
())
monthList
.
append
(
add_one_month
(
start_time
,
i
)
.
date
())
...
@@ -124,17 +125,29 @@ def export_csv(fileName):
...
@@ -124,17 +125,29 @@ def export_csv(fileName):
sql
=
f
'''
sql
=
f
'''
SELECT job_id,主体,创建人,单据类型,单据编号,业务日期,财务日期,供应商,分类,客户,客户分类,渠道,业务类型,`业务类型-旧`,物料编码,物料名称,
SELECT job_id,主体,创建人,单据类型,单据编号,业务日期,财务日期,供应商,分类,客户,客户分类,渠道,业务类型,`业务类型-旧`,物料编码,物料名称,
广汇安装单独条码,产品分类二级,设备类型,终端设备分类二级,产品类型,属性一,属性二,财务数量,计价数量,含税单价,单价,`税率(
%
)`,不含税金额,税额,
广汇安装单独条码,产品分类二级,设备类型,终端设备分类二级,产品类型,属性一,属性二,财务数量,计价数量,含税单价,单价,`税率(
%
)`,不含税金额,税额,
价税合计,收入,成本金额,地区,匹配索引,分摊期限,产品分类一级 FROM ds_job_info_23041302 WHERE LEFT(`业务日期`,4) = '2017';
价税合计,收入,成本金额,地区,匹配索引,分摊期限,产品分类一级 FROM ds_job_info_23041302 WHERE LEFT(`业务日期`,4) = '2017'
;
'''
'''
if
not
bizConn
.
query
(
sql
):
if
not
bizConn
.
query
(
sql
):
logger
.
error
(
"deal_equity_data fail, sql=
%
s"
,
sql
)
logger
.
error
(
"deal_equity_data fail, sql=
%
s"
,
sql
)
return
return
result
=
bizConn
.
fetchAllRows
()
result
=
bizConn
.
fetchAllRows
()
for
index
in
range
(
int
(
len
(
result
)
/
5000
)
+
1
):
split
=
result
[
5000
*
index
:
5000
*
(
index
+
1
)]
my_write_func
(
fileHandle
,
split
,
monthList
)
# 关闭流
fileHandle
.
close
()
def
my_write_func
(
fileHandle
,
result
,
monthList
):
my_job_id_list
=
{
i
[
0
]
for
i
in
result
}
my_big_map
=
build_my_big_map
(
my_job_id_list
)
for
row
in
result
:
for
row
in
result
:
logger
.
info
(
row
)
logger
.
info
(
row
)
lineValue
=
f
"{row[0]},{row[1]},{row[2]},{row[3]},{row[4]},{row[5]},{row[6]},{row[7]},{row[8]},{row[9]},{row[10]},{row[11]},{row[12]},{row[13]},{row[14]},{row[15]},{row[16]},{row[17]},{row[18]},{row[19]},{row[20]},{row[21]},{row[22]},{row[23]},{row[24]},{row[25]},{row[26]},{row[27]},{row[28]},{row[29]},{row[30]},{row[31]},{row[32]},{row[33]},{row[34]},{row[35]},{row[36]}"
lineValue
=
f
"{row[0]},{row[1]},{row[2]},{row[3]},{row[4]},{row[5]},{row[6]},{row[7]},{row[8]},{row[9]},{row[10]},{row[11]},{row[12]},{row[13]},{row[14]},{row[15]},{row[16]},{row[17]},{row[18]},{row[19]},{row[20]},{row[21]},{row[22]},{row[23]},{row[24]},{row[25]},{row[26]},{row[27]},{row[28]},{row[29]},{row[30]},{row[31]},{row[32]},{row[33]},{row[34]},{row[35]},{row[36]}"
my_map
=
build_my_map
(
row
[
0
])
my_map
=
my_big_map
.
get
(
row
[
0
])
if
my_map
is
None
:
if
my_map
is
None
:
my_map
=
{}
my_map
=
{}
logger
.
info
(
my_map
)
logger
.
info
(
my_map
)
...
@@ -162,14 +175,16 @@ def export_csv(fileName):
...
@@ -162,14 +175,16 @@ def export_csv(fileName):
lineValue
+=
"
\n
"
lineValue
+=
"
\n
"
logger
.
debug
(
lineValue
)
logger
.
debug
(
lineValue
)
fileHandle
.
write
(
lineValue
)
fileHandle
.
write
(
lineValue
)
# 关闭流
fileHandle
.
close
()
def
get_job_id
(
job_info_data
):
return
job_info_data
[
1
]
def
build_my_map
(
job_id_key
):
def
build_my_map
(
job_id_key
):
bizConn
=
MySQL
(
saas_shen_db_cfg
)
bizConn
=
MySQL
(
saas_shen_db_cfg
)
sql
=
f
'''
sql
=
f
'''
SELECT id,job_id,service_date,shouru_price,chengben_price FROM temp_job_info_ft_0
1
tjif WHERE tjif.job_id = {job_id_key} ;
SELECT id,job_id,service_date,shouru_price,chengben_price FROM temp_job_info_ft_0
2
tjif WHERE tjif.job_id = {job_id_key} ;
'''
'''
logger
.
info
(
sql
)
logger
.
info
(
sql
)
if
not
bizConn
.
query
(
sql
):
if
not
bizConn
.
query
(
sql
):
...
@@ -180,6 +195,24 @@ def build_my_map(job_id_key):
...
@@ -180,6 +195,24 @@ def build_my_map(job_id_key):
return
my_map
return
my_map
def
build_my_big_map
(
job_id_list
):
bizConn
=
MySQL
(
saas_shen_db_cfg
)
print
(
', '
.
join
(
str
(
x
)
for
x
in
job_id_list
))
sql
=
f
'''
SELECT id,job_id,service_date,shouru_price,chengben_price FROM temp_job_info_ft_02 tjif WHERE tjif.job_id in ({', '.join(str(x) for x in job_id_list)}) ;
'''
logger
.
info
(
sql
)
if
not
bizConn
.
query
(
sql
):
logger
.
error
(
"deal_equity_data fail, sql=
%
s"
,
sql
)
return
result
=
bizConn
.
fetchAllRows
()
my_big_map
=
{}
my_dic
=
[(
key
,
list
(
group
))
for
key
,
group
in
groupby
(
result
,
key
=
get_job_id
)]
for
job_id
,
group_list
in
my_dic
:
my_big_map
[
job_id
]
=
{
i
[
2
]:
i
for
i
in
group_list
}
return
my_big_map
def
write_sql
(
sql
):
def
write_sql
(
sql
):
logger
.
info
(
sql
)
logger
.
info
(
sql
)
with
open
(
"/sql11.txt"
,
"a+"
,
encoding
=
'utf8'
)
as
fw
:
with
open
(
"/sql11.txt"
,
"a+"
,
encoding
=
'utf8'
)
as
fw
:
...
@@ -208,7 +241,7 @@ if __name__ == '__main__':
...
@@ -208,7 +241,7 @@ if __name__ == '__main__':
# 执行脚本
# 执行脚本
# deal_equity_data()
# deal_equity_data()
# 导出表格
# 导出表格
export_csv
(
"ds_job_info_23041302_2017_yang.csv"
)
export_csv
(
"ds_job_info_23041302_2017_yang
01
.csv"
)
# my_map = build_my_map(61308)
# my_map = build_my_map(61308)
# print('my_map', my_map)
# print('my_map', my_map)
...
@@ -217,3 +250,11 @@ if __name__ == '__main__':
...
@@ -217,3 +250,11 @@ if __name__ == '__main__':
# # 添加一个月的日期
# # 添加一个月的日期
# date = add_one_month(start_time, 0).date()
# date = add_one_month(start_time, 0).date()
# print(my_map.get(datetime.strptime(date.strftime("%Y-%m-%d"), '%Y-%m-%d')))
# print(my_map.get(datetime.strptime(date.strftime("%Y-%m-%d"), '%Y-%m-%d')))
# big_map = build_my_big_map([1, 2, 3])
# print('big_map', big_map)
# my_map = big_map.get(1)
# start_time = datetime.strptime('2017-05-01', '%Y-%m-%d')
# # 添加一个月的日期
# date = add_one_month(start_time, 0).date()
# print(my_map.get(datetime.strptime(date.strftime("%Y-%m-%d"), '%Y-%m-%d')))
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