Commit 471629f8 by lzzzzl

更新attr_values mongo处理

parent a5a9057d
Showing with 18 additions and 5 deletions
......@@ -236,3 +236,12 @@ class ParamData(object):
def get_attr_unit(attr_unit_id, class_conn):
sql = "SELECT attr_unit_name FROM lie_class_attr_unit WHERE attr_unit_id=%s" % attr_unit_id
return DBHandler.read(class_conn, sql)
"""
获取SPU 数据
"""
@staticmethod
def get_spu(index, spu_conn):
sql = "SELECT spu_id,attr_values FROM lie_spu_%d WHERE class_id1 != 0 AND class_id2 != 0 \
AND attr_values != '' ORDER BY spu_id LIMIT 100 " % index
return DBHandler.read(spu_conn, sql)
......@@ -5,6 +5,7 @@ import pymongo
from urllib import parse
from fun.param_thread import ParamThread
from fun.param_data import ParamData
from param_task.task import Task
# 转义用户名和密码
......@@ -18,9 +19,11 @@ mydb = myclient['ichunt']
mycol = mydb["spu_attrs"]
class ParamMongo(object):
class ParamMongo(Task):
def __init__(self):
super().__init__()
self.spu_conn = self.DBConn.db_spu()
self.param_data = ParamData
self.data_dict = {0: [], 1: [], 2: [], 3: [], 4: [], 5: [], 6: [], 7: [], 8: [], 9: []}
......@@ -30,7 +33,7 @@ class ParamMongo(object):
def init_data(self):
# 遍历SKU数据
for i in range(0, 10):
self.data_dict[i] = self.mysql_handler.get_spu(i)
self.data_dict[i] = self.param_data.get_spu(i, self.spu_conn)
def search_mongo(self, spu_id, data):
res = mycol.find({"spu_id": spu_id}).limit(1)
......@@ -44,6 +47,7 @@ class ParamMongo(object):
mycol.save(mg_dt)
def update_mongo(self, data):
class_db = self.DBConn.db_class()
for row in data:
try:
spu_id = row[0]
......@@ -51,9 +55,9 @@ class ParamMongo(object):
new_av_list = list()
for vals in attr_values:
val = str(vals).split(",")
attr_name = self.param_data.get_attr_name(val[0])
attr_value = self.param_data.get_attr_value(val[1])
attr_unit = self.param_data.get_attr_unit(val[2])
attr_name = self.param_data.get_attr_name(val[0], class_db)
attr_value = self.param_data.get_attr_value(val[1], class_db)
attr_unit = self.param_data.get_attr_unit(val[2], class_db)
if attr_name and attr_value and attr_unit:
new_av_list.append({'attr_name': attr_name, 'attr_value': attr_value, 'attr_unit': attr_unit})
self.search_mongo(spu_id, new_av_list)
......
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