Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
I
InitAPIData
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ZGC_INDEX
InitAPIData
Commits
745aa944
Commit
745aa944
authored
Jan 09, 2020
by
rico.liu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
init
parent
cb5add1a
Pipeline
#132
canceled with stages
Changes
3
Pipelines
1
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
585 additions
and
0 deletions
+585
-0
checkData.py
checkData.py
+360
-0
initAPIData.py
initAPIData.py
+163
-0
matchSKU.py
matchSKU.py
+62
-0
No files found.
checkData.py
0 → 100644
View file @
745aa944
This diff is collapsed.
Click to expand it.
initAPIData.py
0 → 100644
View file @
745aa944
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Jan 8 10:00:34 2020
@author: rico
"""
import
pymssql
import
pandas
as
pd
import
datetime
#from pyforest import *
from
matchSKU
import
matchSKU
from
checkData
import
checkData
'''
JD_ZH/ZH_DL/ZH_DW/ZH_DZ/ZH_LXWL/ZH_OFS/ZH_SN/ZH_YHD/ZH_ZCSM
初始化API数据包含SKU排重、三大电商数据审核
'''
def
initAPIData
(
base_frm
):
conn
=
pymssql
.
connect
(
host
=
'123.56.115.207'
,
user
=
'zgcprice3311'
,
password
=
'admin@2018@)!*'
,
database
=
f
'{base_frm}'
,
autocommit
=
True
)
cursor
=
conn
.
cursor
()
source
=
base_frm
.
replace
(
'_'
,
''
)
.
replace
(
'ZH'
,
''
)
if
source
==
'JD'
:
pass
elif
source
==
'DL'
:
cursor
.
execute
(
f
"insert into product_all(sku,name,brand,category,zi_subcategoryname,zi_subcategorycode,url,price,source,state)
\
select distinct a.sku,a.name,a.brand,f.name'sourcecategoryname',d.name'subcategoryname',c.zi_subcategorycode,a.url,e.price,'{base_frm}',a.state from
\
(select * from product_detail where sku not in (select sku from product_all ))a
\
left join Product_Category f
\
on a.category=f.categoryid
\
left join (select distinct zi_subcategorycode,sourcesubcategory from ZI_DataBase.dbo.Product_Relation_Attribute_SubTitle where source='{source}') c
\
on f.name=c.sourcesubcategory
\
left join ZI_DataBase.dbo.zi_subcategory d
\
on c.zi_subcategorycode=d.subcategorycode
\
left join product_price e
\
on a.sku=e.sku"
)
else
:
cursor
.
execute
(
f
"insert into product_all(sku,name,brand,category,zi_subcategoryname,zi_subcategorycode,url,price,source,state)
\
select distinct a.sku,a.name,a.brand,a.category,d.name'subcategoryname',c.zi_subcategorycode,a.url,e.price,'{base_frm}',a.state from
\
(select * from product_detail where sku not in (select sku from product_all ))a
\
left join (select distinct zi_subcategorycode,sourcesubcategory from ZI_DataBase.dbo.Product_Relation_Attribute_SubTitle where source='{source}') c
\
on a.category=c.sourcesubcategory
\
left join ZI_DataBase.dbo.zi_subcategory d
\
on c.zi_subcategorycode=d.subcategorycode
\
left join product_price e
\
on a.sku=e.sku"
)
if
source
in
[
'JD'
,
'SN'
,
'GM'
]:
#筛选出待审核的数据
cursor
.
execute
(
"select id,sku,name,url,source,price from product_all where ziying is null and productcode is null"
)
data
=
(
cursor
.
fetchall
())
check_data
=
pd
.
DataFrame
(
data
,
columns
=
[
'id'
,
'sku'
,
'name'
,
'url'
,
'source'
,
'price'
])
#审核三大电商数据
check_data
=
checkData
(
check_data
)
id_pass
=
[]
id_no_ziying
=
[]
id_dingzhi
=
[]
id_other_nopass
=
[]
print
(
'补全价格'
)
for
id_name
,
suggestion
,
price
in
zip
(
check_data
[
'update_id'
],
check_data
[
'审核意见'
],
check_data
[
'price'
]):
cursor
.
execute
(
f
"update product_all set price='{price}' where id= '{id_name}'"
)
conn
.
commit
()
if
suggestion
==
'通过'
:
id_pass
.
append
(
id_name
)
elif
suggestion
==
'非自营,请按要求提供在销渠道证明'
:
id_no_ziying
.
append
(
id_name
)
elif
suggestion
==
'定制/专用类产品暂不通过'
:
id_dingzhi
.
append
(
id_name
)
else
:
id_other_nopass
.
append
(
id_name
)
print
(
'更新数据库~'
)
for
id_num
in
id_pass
:
cursor
.
execute
(
f
"update product_all set ziying='1',dingzhi='1',state='1' where id= '{id_num}'"
)
conn
.
commit
()
for
i
in
id_no_ziying
:
cursor
.
execute
(
f
"update product_all set ziying='2',dingzhi='1',state='2' where id='{i}'"
)
conn
.
commit
()
for
i
in
id_dingzhi
:
cursor
.
execute
(
f
"update product_all set ziying='1',dingzhi='2',state='2' where id='{i}'"
)
conn
.
commit
()
for
i
in
id_other_nopass
:
cursor
.
execute
(
f
"update product_all set ziying='2',dingzhi='1',state='2' where id='{i}'"
)
conn
.
commit
()
#SKU排重
cursor
.
execute
(
"select distinct sku from product_all where productcode is null and state ='1'"
)
data
=
(
cursor
.
fetchall
())
sku_list
=
pd
.
DataFrame
(
data
,
columns
=
[
'sku'
])[
'sku'
]
.
tolist
()
sku_check
=
matchSKU
(
sku_list
,
source
)
print
(
'sku排重中'
)
for
k
,
v
in
sku_check
.
items
():
if
v
==
'0'
:
continue
else
:
cursor
.
execute
(
f
"update product_all set productcode='{v}' where sku='{k}'"
)
conn
.
commit
()
print
(
'sku排重完毕'
)
cursor
.
close
()
print
(
'完成'
)
print
(
'更新问题数据库'
)
conn
=
pymssql
.
connect
(
host
=
'123.56.115.207'
,
user
=
'zgcprice3311'
,
password
=
'admin@2018@)!*'
,
database
=
'zi_zh'
,
autocommit
=
True
)
cursor
=
conn
.
cursor
()
today
=
datetime
.
datetime
.
now
()
.
strftime
(
"
%
Y/
%
m/
%
d
%
H:
%
M:
%
S"
)
for
sku
,
name
,
url
,
remark
,
source
in
zip
(
check_data
[
'sku'
],
check_data
[
'name'
]
,
check_data
[
'url'
],
check_data
[
'审核意见'
],
check_data
[
'source'
]):
if
remark
==
'通过'
:
continue
cursor
.
execute
(
f
"insert into API_returnErrorData (sku,name,url,remark,create_time,source) VALUES ('{sku}','{name}','{url}','{remark}','{today}','{source}')"
)
cursor
.
close
()
print
(
'完成'
)
print
(
'数据初始化处理完成'
)
return
None
else
:
#SKU排重
cursor
.
execute
(
"select distinct sku from product_all where productcode is null"
)
data
=
(
cursor
.
fetchall
())
sku_list
=
pd
.
DataFrame
(
data
,
columns
=
[
'sku'
])[
'sku'
]
.
tolist
()
sku_check
=
matchSKU
(
sku_list
,
source
)
print
(
'sku排重中'
)
for
k
,
v
in
sku_check
.
items
():
if
v
==
'0'
:
continue
else
:
cursor
.
execute
(
f
"update product_all set productcode='{v}' where sku='{k}'"
)
conn
.
commit
()
print
(
'sku排重完毕'
)
print
(
'更新数据库~'
)
cursor
.
execute
(
"select id from product_all where ziying is null and productcode is null"
)
data
=
(
cursor
.
fetchall
())
check_data
=
pd
.
DataFrame
(
data
,
columns
=
[
'id'
])
id_list
=
check_data
[
'id'
]
.
tolist
()
for
_id
in
id_list
:
cursor
.
execute
(
f
"update product_all set ziying='1',dingzhi='1',state='1' where id= '{_id}'"
)
conn
.
commit
()
print
(
'数据初始化处理完成'
)
return
None
if
__name__
==
"__main__"
:
initAPIData
(
'ZH_SN'
)
matchSKU.py
0 → 100644
View file @
745aa944
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Jan 7 15:26:43 2020
@author: rico
"""
import
pymssql
import
pandas
as
pd
'''
DL/DW/DZ/GM/JD/LXWL/OFS/SN/YHD/ZCSM
'''
def
matchSKU
(
sku_list
,
frm
):
conn
=
pymssql
.
connect
(
host
=
'123.56.115.207'
,
user
=
'zgcprice3311'
,
password
=
'admin@2018@)!*'
,
database
=
'ZI_DataBase'
)
cursor
=
conn
.
cursor
()
print
(
'正在删除库中产品状态为6的sku,稍等。。。'
)
#首先将库中错误状态产品的JD/SN/GM的SKU删除
cursor
.
execute
(
"DELETE from productcode_sku where productcode in (select productcode from info_product where state='6')"
)
conn
.
commit
()
print
(
'正在获取当前库中所有sku,请稍等.....'
)
#获取库中所有的SKU,以供检查
try
:
get_all_sku
=
f
"select * from productcode_sku where frm in {frm}"
cursor
.
execute
(
get_all_sku
)
data_sku
=
(
cursor
.
fetchall
())
data_sku_file
=
pd
.
DataFrame
(
data_sku
,
columns
=
[
'id'
,
'productcode'
,
'sku'
,
'skuname'
,
'createddate'
,
'frm'
])
except
:
get_all_sku
=
f
"select * from productcode_sku where frm='{frm}'"
cursor
.
execute
(
get_all_sku
)
data_sku
=
(
cursor
.
fetchall
())
data_sku_file
=
pd
.
DataFrame
(
data_sku
,
columns
=
[
'id'
,
'productcode'
,
'sku'
,
'skuname'
,
'createddate'
,
'frm'
])
print
(
'sku获取完毕'
)
conn
.
close
()
cursor
.
close
()
sku_check
=
{}
for
sku
in
set
(
sku_list
):
#print(sku)
#sku = 100004460761
if
str
(
sku
)
in
list
(
data_sku_file
[
'sku'
]):
try
:
product_no
=
[
target
for
sku_source
,
target
in
zip
(
list
(
data_sku_file
[
'sku'
]),
list
(
data_sku_file
[
'productcode'
]))
if
str
(
sku
)
==
sku_source
]
sku_check
[
f
'{sku}'
]
=
product_no
[
0
]
except
:
sku_check
[
f
'{sku}'
]
=
'2'
#匹配上多个SKU,属于问题数据
else
:
if
frm
==
'SN'
:
sku_add
=
'0000000000/'
+
str
(
sku
)
if
str
(
sku_add
)
in
list
(
data_sku_file
[
'sku'
]):
try
:
product_no
=
[
target
for
sku_source
,
target
in
zip
(
list
(
data_sku_file
[
'sku'
]),
list
(
data_sku_file
[
'productcode'
]))
if
str
(
sku_add
)
==
sku_source
]
sku_check
[
f
'{sku}'
]
=
product_no
[
0
]
except
:
sku_check
[
f
'{sku}'
]
=
'2'
#匹配上多个SKU,属于问题数据
else
:
sku_check
[
f
'{sku}'
]
=
'0'
else
:
sku_check
[
f
'{sku}'
]
=
'0'
return
sku_check
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
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 comment