Commit 3edac953 by 岳巧源

insert into redis

parent c33241e7
Showing with 13 additions and 6 deletions
...@@ -138,11 +138,11 @@ def update_ext_attr_by_class_ids(conf: dict): ...@@ -138,11 +138,11 @@ def update_ext_attr_by_class_ids(conf: dict):
""" """
基于lie_shop_attr中的class_id来更新 “拓展” 属性 基于lie_shop_attr中的class_id来更新 “拓展” 属性
""" """
host = conf["host"] host = conf["mysql"]["host"]
port = conf["port"] port = conf["mysql"]["port"]
user = conf["user"] user = conf["mysql"]["user"]
password = conf["password"] password = conf["mysql"]["password"]
database = conf["database"] database = conf["mysql"]["database"]
db = pymysql.connect(host=host, port=port, user=user, password=password, database=database) db = pymysql.connect(host=host, port=port, user=user, password=password, database=database)
select_sql = "select distinct class_id from lie_shop_attr" select_sql = "select distinct class_id from lie_shop_attr"
cursor = db.cursor() cursor = db.cursor()
...@@ -174,6 +174,7 @@ def update_ext_attr_by_class_ids(conf: dict): ...@@ -174,6 +174,7 @@ def update_ext_attr_by_class_ids(conf: dict):
if flag != 1: if flag != 1:
continue continue
attr_id = result["att_id"] attr_id = result["att_id"]
class_attr_mapping[class_id].append(attr_id)
attr_name = result["name"] attr_name = result["name"]
unit = result["val_unit"] unit = result["val_unit"]
is_required = 1 is_required = 1
...@@ -215,6 +216,7 @@ def update_ext_attr_by_class_ids(conf: dict): ...@@ -215,6 +216,7 @@ def update_ext_attr_by_class_ids(conf: dict):
print(insert_sql % (class_id, attr_id, attr_name, unit, enum_value, input_type, is_required, status, platform, create_time)) print(insert_sql % (class_id, attr_id, attr_name, unit, enum_value, input_type, is_required, status, platform, create_time))
else: else:
update_sql = "" update_sql = ""
insert_ext_attr_to_redis(class_attr_mapping, conf)
...@@ -239,6 +241,9 @@ def insert_ext_attr_to_redis(class_attr_map: dict, conf: dict): ...@@ -239,6 +241,9 @@ def insert_ext_attr_to_redis(class_attr_map: dict, conf: dict):
for class_id in class_attr_map: for class_id in class_attr_map:
key = str(class_id) key = str(class_id)
attr_ids = class_attr_map[class_id] attr_ids = class_attr_map[class_id]
if len(attr_ids) == 0:
# 为空的直接跳过
continue
value = json.dumps(attr_ids, ensure_ascii=False) value = json.dumps(attr_ids, ensure_ascii=False)
db.hset(name="jd_ext_attr", key=key, value=value) db.hset(name="jd_ext_attr", key=key, value=value)
...@@ -257,4 +262,5 @@ if __name__ == '__main__': ...@@ -257,4 +262,5 @@ if __name__ == '__main__':
config = config_dev config = config_dev
elif environment == "prod": elif environment == "prod":
config = config_prod config = config_prod
update_jd_attr_by_class(conf=config) # update_jd_attr_by_class(conf=config)
# update_ext_attr_by_class_ids(conf=config)
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment