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
04f40546
Commit
04f40546
authored
Jan 19, 2020
by
rico.liu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
831e6dcf
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
89 additions
and
62 deletions
+89
-62
matchSKU.py
matchSKU.py
+89
-62
No files found.
matchSKU.py
View file @
04f40546
#!/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
#!/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')"
)
print
(
'正在删除库中重复的SKU,稍等。。。'
)
#需先删除库中重复的SKU,避免匹配相同的编码
cursor
.
execute
(
"declare OperCursor Cursor for
\
SELECT productcode,sku,frm,count(*) ca FROM productcode_sku
\
GROUP BY productcode,sku,frm
\
HAVING COUNT(*)>1
\
open OperCursor
\
declare @PRODUCTCODE as nvarchar(20)
\
declare @sku as nvarchar(50)
\
declare @frm as nvarchar(20)
\
declare @ca as int
\
declare @return_value as int
\
fetch next from OperCursor into @PRODUCTCODE,@sku,@frm,@ca
\
IF @@fetch_status=0
\
delete from productcode_sku
\
where id in (select top (@ca-1) id from productcode_sku
\
where productcode=@PRODUCTCODE and sku=@sku and frm=@frm)
\
\
while @@fetch_status=0
\
begin
\
fetch next from OperCursor into @PRODUCTCODE,@sku,@frm,@ca
\
IF @@fetch_status=0
\
delete from productcode_sku
\
where id in (select top (@ca-1) id from productcode_sku
\
where productcode=@PRODUCTCODE and sku=@sku and frm=@frm)
\
end
\
close OperCursor
\
deallocate OperCursor"
)
conn
.
commit
()
print
(
'正在获取当前库中所有sku,请稍等.....'
)
#获取库中所有的SKU,以供检查
try
:
get_all_sku
=
f
"select * from productcode_sku where frm in {frm} and productcode not like '78
%
' "
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}' and productcode not like '78
%
' "
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