Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
重
重点类信息提取
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
重点类信息提取
Commits
55942907
Commit
55942907
authored
Apr 25, 2021
by
Jialin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
代码更新
parent
1241ae1d
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
45 additions
and
45 deletions
+45
-45
产品品牌更新.py
公共代码/产品品牌更新.py
+45
-45
No files found.
公共代码/产品品牌更新.py
View file @
55942907
...
...
@@ -38,8 +38,8 @@ def duplicate_product_update(filepath,category,sheet_name=0):
# db_params['subtitle'] = db_params['subtitle'].apply(lambda x: x.strip())
# 找到正确的类别id
cursor_zi_
test
.
execute
(
f
"select id from p_category where name='{category}'"
)
category_id
=
cursor_zi_
test
.
fetchall
()
cursor_zi_
new
.
execute
(
f
"select id from p_category where name='{category}'"
)
category_id
=
cursor_zi_
new
.
fetchall
()
if
len
(
category_id
)
>
1
:
print
(
f
"品牌名:'{category}' 在p_category中不是唯一的,请检查"
,
file
=
f
)
return
...
...
@@ -49,16 +49,16 @@ def duplicate_product_update(filepath,category,sheet_name=0):
category_id
=
category_id
[
0
][
0
]
# 找到该类别下的品牌名,放入existed_brand_list
cursor_zi_
test
.
execute
(
f
"select distinct brandid from p_spu where categoryid={category_id}"
)
brand_id_fetch
=
cursor_zi_
test
.
fetchall
()
cursor_zi_
new
.
execute
(
f
"select distinct brandid from p_spu where categoryid={category_id}"
)
brand_id_fetch
=
cursor_zi_
new
.
fetchall
()
brand_id_list
=
[]
for
brand_id_tuple
in
brand_id_fetch
:
brand_id_list
.
append
(
brand_id_tuple
[
0
])
existed_brand_list
=
[]
for
brand_id
in
brand_id_list
:
cursor_zi_
test
.
execute
(
f
"select name from p_brand where id={brand_id}"
)
existed_brand_name
=
cursor_zi_
test
.
fetchone
()
cursor_zi_
new
.
execute
(
f
"select name from p_brand where id={brand_id}"
)
existed_brand_name
=
cursor_zi_
new
.
fetchone
()
if
existed_brand_name
:
existed_brand_list
.
append
(
existed_brand_name
[
0
])
...
...
@@ -77,10 +77,10 @@ def duplicate_product_update(filepath,category,sheet_name=0):
# 找到正确的品牌id
if
correct_brand
not
in
existed_brand_list
:
cursor_zi_
test
.
execute
(
f
"insert into p_brand (name) values ('{correct_brand}')"
)
# 除了名称,啥都没加
cursor_zi_
new
.
execute
(
f
"insert into p_brand (name) values ('{correct_brand}')"
)
# 除了名称,啥都没加
print
(
f
"'{correct_brand}' 被添加到了p_brand"
,
file
=
f
)
cursor_zi_
test
.
execute
(
f
"select id from p_brand where name='{correct_brand}'"
)
#and id not in (select distinct pid from p_brand)
correct_brand_id
=
cursor_zi_
test
.
fetchall
()
cursor_zi_
new
.
execute
(
f
"select id from p_brand where name='{correct_brand}'"
)
#and id not in (select distinct pid from p_brand)
correct_brand_id
=
cursor_zi_
new
.
fetchall
()
if
len
(
correct_brand_id
)
>
1
:
print
(
f
"品牌名:'{correct_brand}' 在p_brand中不唯一,请检查"
,
file
=
f
)
return
...
...
@@ -89,15 +89,15 @@ def duplicate_product_update(filepath,category,sheet_name=0):
# 一个品牌一个品牌地改
for
wrong_brand
in
brand_tobe_modified
:
print
(
f
"正在修改'{wrong_brand}':"
,
file
=
f
)
cursor_zi_
test
.
execute
(
f
"select id from p_brand where name='{wrong_brand}'"
)
wrong_brand_id
=
cursor_zi_
test
.
fetchone
()
cursor_zi_
new
.
execute
(
f
"select id from p_brand where name='{wrong_brand}'"
)
wrong_brand_id
=
cursor_zi_
new
.
fetchone
()
if
not
wrong_brand_id
:
print
(
f
"更改前的品牌:'{wrong_brand}' 不在p_brand中,请检查"
,
file
=
f
)
return
wrong_brand_id
=
wrong_brand_id
[
0
]
cursor_zi_
test
.
execute
(
f
"select distinct spuname, id from p_spu where brandid={wrong_brand_id}"
)
# 我们把所有类别的该品牌id的spuname都挑出来了,spuname一起改
wrong_list
=
cursor_zi_
test
.
fetchall
()
#找出所有的错误品牌的spuname,挨个改
cursor_zi_
new
.
execute
(
f
"select distinct spuname, id from p_spu where brandid={wrong_brand_id}"
)
# 我们把所有类别的该品牌id的spuname都挑出来了,spuname一起改
wrong_list
=
cursor_zi_
new
.
fetchall
()
#找出所有的错误品牌的spuname,挨个改
if
not
wrong_list
:
print
(
f
"!!!!! 品牌id:'{wrong_brand_id}' 不在p_spu里,该品牌下spu或以被修改"
,
file
=
f
)
continue
...
...
@@ -108,8 +108,8 @@ def duplicate_product_update(filepath,category,sheet_name=0):
print
(
f
" 正在更改的spuid:'{wrong_tuple[1]}'"
,
file
=
f
)
wrong_spuname
=
wrong_tuple
[
0
]
correct_spuname
=
wrong_spuname
.
replace
(
wrong_brand
,
correct_brand
)
# 生成新的spuname
cursor_zi_
test
.
execute
(
f
"select id from p_spu where spuname='{correct_spuname}'"
)
spu_id_tuple
=
cursor_zi_
test
.
fetchall
()
cursor_zi_
new
.
execute
(
f
"select id from p_spu where spuname='{correct_spuname}'"
)
spu_id_tuple
=
cursor_zi_
new
.
fetchall
()
if
len
(
spu_id_tuple
)
>
1
:
print
(
f
"spuname:'{correct_spuname}'在p_spu表中不是唯一的,请检查"
,
file
=
f
)
return
...
...
@@ -125,8 +125,8 @@ def duplicate_product_update(filepath,category,sheet_name=0):
change_name
=
1
# 到这一步,我们已经取出了正确的spuid
wrong_spuid
=
wrong_tuple
[
1
]
cursor_zi_
test
.
execute
(
f
"select skuname, sku from p_sku where spuid={wrong_spuid}"
)
wrong_sku_list
=
cursor_zi_
test
.
fetchall
()
# 提取所有spuid是错误spuid的skuname, sku
cursor_zi_
new
.
execute
(
f
"select skuname, sku from p_sku where spuid={wrong_spuid}"
)
wrong_sku_list
=
cursor_zi_
new
.
fetchall
()
# 提取所有spuid是错误spuid的skuname, sku
# 接下来就是sku的命名过程
print
(
f
" 接下来是skuname更改:"
,
file
=
f
)
...
...
@@ -134,58 +134,58 @@ def duplicate_product_update(filepath,category,sheet_name=0):
wrong_skuname
=
wrong_sku_tuple
[
0
]
wrong_skucode
=
wrong_sku_tuple
[
1
]
correct_skuname
=
wrong_skuname
.
replace
(
wrong_brand
,
correct_brand
)
cursor_zi_
test
.
execute
(
f
"select skuname, sku from p_sku where skuname='{correct_skuname}'"
)
skuname
=
cursor_zi_
test
.
fetchone
()
#我们只取了一个,因为我们觉得一个skuname应该只存在一个
cursor_zi_
new
.
execute
(
f
"select skuname, sku from p_sku where skuname='{correct_skuname}'"
)
skuname
=
cursor_zi_
new
.
fetchone
()
#我们只取了一个,因为我们觉得一个skuname应该只存在一个
if
skuname
:
#如果有返回结果,就代表有重复的sku
sku_name
=
skuname
[
0
]
# 正确的产品名称
sku_code
=
skuname
[
1
]
# 正确的产品编码
sku_name_repeated
=
sku_name
+
f
"(sku:{wrong_skucode};重复sku:{sku_code})"
cursor_zi_
test
.
execute
(
cursor_zi_
new
.
execute
(
f
"update p_sku set state=6, skuname='{sku_name_repeated}' where sku='{wrong_skucode}'"
)
print
(
f
" if successful:p_sku, '{wrong_skucode}'的 skuname updated to '{sku_name_repeated}', state updated to 6"
,
file
=
f
)
cursor_zi_
test
.
execute
(
cursor_zi_
new
.
execute
(
f
"update Productcode_Sku set sku='{sku_code}' where sku='{wrong_skucode}' "
)
print
(
f
" if successful:Productcode_Sku, sku updated from '{wrong_skucode}' into '{sku_code}'"
,
file
=
f
)
#
cursor_zdindex.execute("select top 1 max(periods) from zd_electricity_price")
#
zd_e_p = cursor_zdindex.fetchone()[0]
#
cursor_zdindex.execute(
#
f"update zd_electricity_price set goods_id='{sku_code}' where goods_id = '{wrong_skucode}' and periods = {zd_e_p} ")
# print(f"
zd_electricity_price, goods_id updated from '{wrong_skucode}' into '{sku_code}'",file=f)
#
cursor_zdindex.execute("select top 1 max(periods) from zd_purchase_price")
#
zd_p_p = cursor_zdindex.fetchone()[0]
#
cursor_zdindex.execute(
#
f"update zd_purchase_price set goods_id='{sku_code}' where goods_id = '{wrong_skucode}' and periods = {zd_p_p} ")
# print(f"
zd_purchase_price, goods_id updated from '{wrong_skucode}' into '{sku_code}'",file=f)
#
cursor_zdindex.execute("select top 1 max(periods) from zd_entry_goods_price")
#
zd_e_g_p = cursor_zdindex.fetchone()[0]
#
cursor_zdindex.execute(
#
f"update zd_entry_goods_price set goods_id='{sku_code}' where goods_id = '{wrong_skucode}' and periods = {zd_e_g_p} ")
# print(f"
zd_entry_goods_price, goods_id updated from '{wrong_skucode}' into '{sku_code}'",file=f)
#
cursor_zdindex.execute("select top 1 max(periods) from zd_week_price")
#
zd_w_p = cursor_zdindex.fetchone()[0]
#
cursor_zdindex.execute(
#
f"update zd_week_price set goods_id='{sku_code}' where goods_id = '{wrong_skucode}' and periods = {zd_w_p} ")
# print(f"
zd_week_price, goods_id updated from '{wrong_skucode}' into '{sku_code}'",file=f)
cursor_zdindex
.
execute
(
"select top 1 max(periods) from zd_electricity_price"
)
zd_e_p
=
cursor_zdindex
.
fetchone
()[
0
]
cursor_zdindex
.
execute
(
f
"update zd_electricity_price set goods_id='{sku_code}' where goods_id = '{wrong_skucode}' and periods = {zd_e_p} "
)
print
(
f
" if successful:
zd_electricity_price, goods_id updated from '{wrong_skucode}' into '{sku_code}'"
,
file
=
f
)
cursor_zdindex
.
execute
(
"select top 1 max(periods) from zd_purchase_price"
)
zd_p_p
=
cursor_zdindex
.
fetchone
()[
0
]
cursor_zdindex
.
execute
(
f
"update zd_purchase_price set goods_id='{sku_code}' where goods_id = '{wrong_skucode}' and periods = {zd_p_p} "
)
print
(
f
" if successful:
zd_purchase_price, goods_id updated from '{wrong_skucode}' into '{sku_code}'"
,
file
=
f
)
cursor_zdindex
.
execute
(
"select top 1 max(periods) from zd_entry_goods_price"
)
zd_e_g_p
=
cursor_zdindex
.
fetchone
()[
0
]
cursor_zdindex
.
execute
(
f
"update zd_entry_goods_price set goods_id='{sku_code}' where goods_id = '{wrong_skucode}' and periods = {zd_e_g_p} "
)
print
(
f
" if successful:
zd_entry_goods_price, goods_id updated from '{wrong_skucode}' into '{sku_code}'"
,
file
=
f
)
cursor_zdindex
.
execute
(
"select top 1 max(periods) from zd_week_price"
)
zd_w_p
=
cursor_zdindex
.
fetchone
()[
0
]
cursor_zdindex
.
execute
(
f
"update zd_week_price set goods_id='{sku_code}' where goods_id = '{wrong_skucode}' and periods = {zd_w_p} "
)
print
(
f
" if successful:
zd_week_price, goods_id updated from '{wrong_skucode}' into '{sku_code}'"
,
file
=
f
)
else
:
#如果新的skuname没有重复,直接修改该sku的skuname(spuid已经被修改了)
cursor_zi_
test
.
execute
(
f
"update p_sku set skuname='{correct_skuname}' where skuname='{wrong_skuname}' and spuid={wrong_spuid}"
)
cursor_zi_
new
.
execute
(
f
"update p_sku set skuname='{correct_skuname}' where skuname='{wrong_skuname}' and spuid={wrong_spuid}"
)
print
(
f
" p_sku, skuname updated from '{wrong_skuname}' into '{correct_skuname}' where spuid='{wrong_spuid}'"
,
file
=
f
)
# 改完skuname后,更改spuid
cursor_zi_
test
.
execute
(
cursor_zi_
new
.
execute
(
f
"update p_sku set spuid={spu_id} where spuid={wrong_spuid}"
)
# 我们只更改了p_sku表里的spuid,其他表有没有不知道
print
(
f
" if successful:更改了p_sku中的spuid,从'{wrong_spuid}'改到了'{spu_id}'"
,
file
=
f
)
if
change_name
==
1
:
# 如果,需要改名字,我们把spu表的spuname改了
cursor_zi_
test
.
execute
(
cursor_zi_
new
.
execute
(
f
"update p_spu set spuname='{correct_spuname}' where spuname='{wrong_spuname}'"
)
print
(
f
" if successful: 更改了 p_spu 中的 spuname to '{correct_spuname}' where spuname='{wrong_spuname}'"
,
file
=
f
)
# 改完所有的spuid后我们改brandid
cursor_zi_
test
.
execute
(
cursor_zi_
new
.
execute
(
f
"update p_spu set brandid={correct_brand_id} where brandid={wrong_brand_id}"
)
# 我们把所有类别的该品牌id都改了
print
(
f
"if successful:更改了p_spu中的brandid, 从'{wrong_brand_id}'改到了'{correct_brand_id}'"
,
file
=
f
)
...
...
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