Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
岳巧源
/
jd_data_process
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
ab61b02c
authored
Oct 28, 2024
by
岳巧源
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
update ext attr
parent
03c4180c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
128 additions
and
2 deletions
crontab.py
vc.py
crontab.py
View file @
ab61b02c
...
...
@@ -258,6 +258,129 @@ def handle_vc_unit(conf: dict):
def
update_vc_ext_attr
(
conf
):
"""
基于lie_shop_attr中的class_id来更新 “拓展” 属性
"""
host
=
conf
[
"mysql"
][
"host"
]
port
=
conf
[
"mysql"
][
"port"
]
user
=
conf
[
"mysql"
][
"user"
]
password
=
conf
[
"mysql"
][
"password"
]
database
=
conf
[
"mysql"
][
"database"
]
method_name
=
"jingdong.vc.item.extProps.find"
token
=
"845ce8478b074103b9e78a769d5fa4831y2u"
app_key
=
"CA52430E90209F51D8F5D7B615DDE9AD"
app_secret
=
"c92691b2379c48de87e699c4c2f7fb32"
select_sql
=
"select class_id from lie_shop_class where platform = 1"
db
=
pymysql
.
connect
(
host
=
host
,
port
=
port
,
user
=
user
,
password
=
password
,
database
=
database
)
cursor
=
db
.
cursor
()
cursor
.
execute
(
query
=
select_sql
)
db_results
=
cursor
.
fetchall
()
for
i
in
range
(
len
(
db_results
)):
class_id
=
db_results
[
i
][
0
]
param
=
{
"category_leaf_id"
:
class_id
,
}
ans
=
request_to_jd_vc
(
method_name
=
method_name
,
token
=
token
,
app_key
=
app_key
,
app_secret
=
app_secret
,
param
=
param
)
if
"result"
not
in
ans
[
"jingdong_vc_item_extProps_find_responce"
][
"jos_result_dto"
]:
continue
jd_results
=
ans
[
"jingdong_vc_item_extProps_find_responce"
][
"jos_result_dto"
][
"result"
]
"""
预先把分类id对应的属性先查询出来。
"""
check_sql
=
"select id, class_id, attr_id, attr_name, unit, enum_value, input_type, is_required from lie_shop_attr where platform = 1 and class_id =
%
s"
cursor
.
execute
(
query
=
check_sql
,
args
=
(
class_id
,
))
check_result
=
cursor
.
fetchall
()
for
j
in
range
(
len
(
jd_results
)):
result
=
jd_results
[
j
]
flag
=
result
[
"is_required"
]
is_required
=
flag
attr_id
=
result
[
"att_id"
]
attr_name
=
result
[
"name"
]
unit
=
result
[
"val_unit"
]
status
=
1
platform
=
1
create_time
=
int
(
time
.
time
())
update_time
=
int
(
time
.
time
())
input_type
=
result
[
"input_type"
]
enum_value
=
"[]"
# 根据 input_type 不同类型分别处理
if
input_type
==
1
or
input_type
==
2
:
# 单选或者多选,获取选项值
ext_prop_value
=
result
[
"ext_prop_value"
]
tmp_list_value
=
[]
for
k
in
range
(
len
(
ext_prop_value
)):
value
=
ext_prop_value
[
k
]
attr_value_id
=
value
[
"value_id"
]
attr_value_name
=
value
[
"value_name"
]
item
=
{
"attr_value_id"
:
attr_value_id
,
"attr_value_name"
:
attr_value_name
}
tmp_list_value
.
append
(
item
)
enum_value
=
json
.
dumps
(
tmp_list_value
,
ensure_ascii
=
False
)
elif
input_type
==
3
:
# 文本类型,无选项值
pass
else
:
print
(
"暂时未兼容此种类型的拓展属性 input_type: "
+
str
(
input_type
))
"""
检查属性需不需要更新等等。。。
"""
exists_attr
=
False
now_attr_map
=
{
"attr_id"
:
attr_id
,
"attr_name"
:
attr_name
,
"unit"
:
unit
,
"enum_value"
:
enum_value
,
"input_type"
:
input_type
,
"is_required"
:
is_required
,
}
for
z
in
range
(
len
(
check_result
)):
primary_id
=
check_result
[
z
][
0
]
origin_class_id
=
check_result
[
z
][
1
]
origin_attr_id
=
check_result
[
z
][
2
]
origin_attr_name
=
check_result
[
z
][
3
]
origin_unit
=
check_result
[
z
][
4
]
origin_enum_value
=
check_result
[
z
][
5
]
origin_input_type
=
check_result
[
z
][
6
]
origin_is_required
=
check_result
[
z
][
7
]
"""
原来数据库中的属性map
"""
origin_attr_map
=
{
"attr_id"
:
origin_attr_id
,
"attr_name"
:
origin_attr_name
,
"unit"
:
origin_unit
,
"enum_value"
:
origin_enum_value
,
"input_type"
:
origin_input_type
,
"is_required"
:
origin_is_required
,
}
flag1
=
(
origin_attr_id
==
attr_id
)
and
(
origin_attr_name
==
attr_name
)
flag2
=
(
origin_attr_id
==
attr_id
)
and
(
origin_attr_name
!=
attr_name
)
flag3
=
(
origin_attr_id
!=
attr_id
)
and
(
origin_attr_name
==
attr_name
)
if
flag1
or
flag2
or
flag3
:
"""
检查其他项是否需要更新,有一个属性不一样就要执行update
"""
exists_attr
=
True
for
key
in
origin_attr_map
:
if
origin_attr_map
[
key
]
!=
now_attr_map
[
key
]:
update_sql1
=
"update lie_shop_attr set unit =
%
s, enum_value =
%
s, input_type =
%
s, is_required =
%
s, update_time =
%
s , is_mapping = 0 where id =
%
s"
cursor
.
execute
(
query
=
update_sql1
,
args
=
(
unit
,
enum_value
,
input_type
,
is_required
,
update_time
,
primary_id
))
db
.
commit
()
print
(
update_sql1
%
(
unit
,
enum_value
,
input_type
,
is_required
,
update_time
,
primary_id
))
break
break
else
:
continue
if
not
exists_attr
:
insert_sql
=
"insert into lie_shop_attr (class_id, attr_id, attr_name, unit, enum_value, input_type, is_required, status, platform, create_time) values (
%
s,
%
s,
%
s,
%
s,
%
s,
%
s,
%
s,
%
s,
%
s,
%
s)"
cursor
.
execute
(
query
=
insert_sql
,
args
=
(
class_id
,
attr_id
,
attr_name
,
unit
,
enum_value
,
input_type
,
is_required
,
status
,
platform
,
create_time
,))
db
.
commit
()
print
(
insert_sql
%
(
class_id
,
attr_id
,
attr_name
,
unit
,
enum_value
,
input_type
,
is_required
,
status
,
platform
,
create_time
))
"""
执行命令
...
...
@@ -280,5 +403,8 @@ if __name__ == '__main__':
print
(
"========================> 分类更新完毕"
)
update_vc_attr
(
config
)
print
(
"========================> 参数更新完毕"
)
update_vc_ext_attr
(
config
)
print
(
"========================> 拓展参数处理完毕"
)
handle_vc_unit
(
config
)
print
(
"========================> 单位处理完毕"
)
vc.py
View file @
ab61b02c
...
...
@@ -411,7 +411,7 @@ def modify_jd_vc_market_price():
def
modify_vc_purchase_price
():
method_name
=
""
method_name
=
"
jingdong.pps.pub.api.PpsPriceChangePublicJosService
"
token
=
"845ce8478b074103b9e78a769d5fa4831y2u"
app_key
=
"CA52430E90209F51D8F5D7B615DDE9AD"
app_secret
=
"c92691b2379c48de87e699c4c2f7fb32"
...
...
@@ -424,7 +424,7 @@ def modify_vc_purchase_price():
"discount"
:
"13"
,
"orgId"
:
-
1
,
"vendorCode"
:
"ichunt"
,
"price"
:
1
00.0
0
,
"price"
:
1
20.155
0
,
"currency"
:
"RMB"
,
"sku"
:
100124748677
,
}
...
...
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