Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
matchSKUWithDB
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
matchSKUWithDB
Commits
10c16647
Commit
10c16647
authored
Jan 07, 2020
by
rico.liu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
init
parents
Pipeline
#124
canceled with stages
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
57 additions
and
0 deletions
+57
-0
matchSKU.py
matchSKU.py
+57
-0
No files found.
matchSKU.py
0 → 100644
View file @
10c16647
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Jan 7 15:26:43 2020
@author: rico
"""
import
pymssql
import
pandas
as
pd
def
matchSKU
(
sku_list
,
frm
=
(
'SN'
,
'JD'
,
'MG'
)
):
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') and frm in('JD','SN','GM')"
)
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