|
@@ -43,34 +43,18 @@ class MySqlDao:
|
|
|
data = self.db_helper.load_data_with_page(query, params)
|
|
data = self.db_helper.load_data_with_page(query, params)
|
|
|
return data
|
|
return data
|
|
|
|
|
|
|
|
- # def load_order_data(self, city_uuid):
|
|
|
|
|
- # """从数据库中读取订单信息"""
|
|
|
|
|
- # query = f"SELECT * FROM {self._order_tablename} WHERE city_uuid = :city_uuid"
|
|
|
|
|
- # params = {"city_uuid": city_uuid}
|
|
|
|
|
-
|
|
|
|
|
- # data = self.db_helper.load_data_with_page(query, params)
|
|
|
|
|
- # data.drop('stat_month', axis=1, inplace=True)
|
|
|
|
|
- # data.drop('city_uuid', axis=1, inplace=True)
|
|
|
|
|
-
|
|
|
|
|
- # return data
|
|
|
|
|
-
|
|
|
|
|
def load_order_data(self, city_uuid):
|
|
def load_order_data(self, city_uuid):
|
|
|
"""从数据库中读取订单信息"""
|
|
"""从数据库中读取订单信息"""
|
|
|
- cust_list = self.get_cust_list(city_uuid)
|
|
|
|
|
-
|
|
|
|
|
- cust_id_str = ",".join([f"'{cust_id}'" for cust_id in cust_list])
|
|
|
|
|
- query = f"""
|
|
|
|
|
- SELECT *
|
|
|
|
|
- FROM {self._order_tablename}
|
|
|
|
|
- WHERE city_uuid = :city_uuid
|
|
|
|
|
- AND cust_code IN ({cust_id_str})
|
|
|
|
|
- """
|
|
|
|
|
|
|
+ query = f"SELECT * FROM {self._order_tablename} WHERE city_uuid = :city_uuid"
|
|
|
params = {"city_uuid": city_uuid}
|
|
params = {"city_uuid": city_uuid}
|
|
|
- data = self.db_helper.load_data_with_page(query, params)
|
|
|
|
|
|
|
|
|
|
|
|
+ data = self.db_helper.load_data_with_page(query, params)
|
|
|
data.drop('stat_month', axis=1, inplace=True)
|
|
data.drop('stat_month', axis=1, inplace=True)
|
|
|
data.drop('city_uuid', axis=1, inplace=True)
|
|
data.drop('city_uuid', axis=1, inplace=True)
|
|
|
|
|
|
|
|
|
|
+ cust_list = self.get_cust_list(city_uuid)
|
|
|
|
|
+ cust_index = cust_list.set_index("BB_RETAIL_CUSTOMER_CODE")
|
|
|
|
|
+ data = data.join(cust_index, on="cust_code", how="inner")
|
|
|
return data
|
|
return data
|
|
|
|
|
|
|
|
def load_eval_order_data(self, city_uuid):
|
|
def load_eval_order_data(self, city_uuid):
|
|
@@ -169,38 +153,38 @@ class MySqlDao:
|
|
|
"""获取指定香烟列表的所有售卖记录"""
|
|
"""获取指定香烟列表的所有售卖记录"""
|
|
|
if not product_ids:
|
|
if not product_ids:
|
|
|
return None
|
|
return None
|
|
|
- cust_list = self.get_cust_list(city_uuid)
|
|
|
|
|
-
|
|
|
|
|
- cust_id_str = ",".join([f"'{cust_id}'" for cust_id in cust_list])
|
|
|
|
|
|
|
|
|
|
product_ids_str = ",".join([f"'{product_code}'" for product_code in product_ids])
|
|
product_ids_str = ",".join([f"'{product_code}'" for product_code in product_ids])
|
|
|
query = f"""
|
|
query = f"""
|
|
|
SELECT *
|
|
SELECT *
|
|
|
FROM {self._order_tablename}
|
|
FROM {self._order_tablename}
|
|
|
WHERE city_uuid = :city_uuid
|
|
WHERE city_uuid = :city_uuid
|
|
|
- AND cust_code IN ({cust_id_str})
|
|
|
|
|
AND product_code IN ({product_ids_str})
|
|
AND product_code IN ({product_ids_str})
|
|
|
"""
|
|
"""
|
|
|
params = {"city_uuid": city_uuid}
|
|
params = {"city_uuid": city_uuid}
|
|
|
data = self.db_helper.load_data_with_page(query, params)
|
|
data = self.db_helper.load_data_with_page(query, params)
|
|
|
|
|
|
|
|
|
|
+ cust_list = self.get_cust_list(city_uuid)
|
|
|
|
|
+ cust_index = cust_list.set_index("BB_RETAIL_CUSTOMER_CODE")
|
|
|
|
|
+ data = data.join(cust_index, on="cust_code", how="inner")
|
|
|
|
|
+
|
|
|
return data
|
|
return data
|
|
|
|
|
|
|
|
def get_order_by_product(self, city_uuid, product_id):
|
|
def get_order_by_product(self, city_uuid, product_id):
|
|
|
- cust_list = self.get_cust_list(city_uuid)
|
|
|
|
|
-
|
|
|
|
|
- cust_id_str = ",".join([f"'{cust_id}'" for cust_id in cust_list])
|
|
|
|
|
|
|
|
|
|
query = f"""
|
|
query = f"""
|
|
|
SELECT *
|
|
SELECT *
|
|
|
FROM {self._order_tablename}
|
|
FROM {self._order_tablename}
|
|
|
WHERE city_uuid = :city_uuid
|
|
WHERE city_uuid = :city_uuid
|
|
|
- AND cust_code IN ({cust_id_str})
|
|
|
|
|
AND product_code = :product_id
|
|
AND product_code = :product_id
|
|
|
"""
|
|
"""
|
|
|
params = {"city_uuid": city_uuid, "product_id": product_id}
|
|
params = {"city_uuid": city_uuid, "product_id": product_id}
|
|
|
data = self.db_helper.load_data_with_page(query, params)
|
|
data = self.db_helper.load_data_with_page(query, params)
|
|
|
|
|
|
|
|
|
|
+ cust_list = self.get_cust_list(city_uuid)
|
|
|
|
|
+ cust_index = cust_list.set_index("BB_RETAIL_CUSTOMER_CODE")
|
|
|
|
|
+ data = data.join(cust_index, on="cust_code", how="inner")
|
|
|
|
|
+
|
|
|
return data
|
|
return data
|
|
|
|
|
|
|
|
def get_eval_order_by_product(self, city_uuid, product_id):
|
|
def get_eval_order_by_product(self, city_uuid, product_id):
|
|
@@ -241,24 +225,33 @@ class MySqlDao:
|
|
|
return data
|
|
return data
|
|
|
|
|
|
|
|
def get_product_from_order(self, city_uuid):
|
|
def get_product_from_order(self, city_uuid):
|
|
|
- cust_list = self.get_cust_list(city_uuid)
|
|
|
|
|
- cust_id_str = ",".join([f"'{cust_id}'" for cust_id in cust_list])
|
|
|
|
|
- query = f"SELECT DISTINCT product_code FROM {self._order_tablename} WHERE city_uuid = :city_uuid AND cust_code IN ({cust_id_str})"
|
|
|
|
|
|
|
+ query = f"SELECT DISTINCT product_code FROM {self._order_tablename} WHERE city_uuid = :city_uuid"
|
|
|
params = {"city_uuid": city_uuid}
|
|
params = {"city_uuid": city_uuid}
|
|
|
|
|
|
|
|
data = pd.DataFrame(self.db_helper.fetch_all(text(query), params))
|
|
data = pd.DataFrame(self.db_helper.fetch_all(text(query), params))
|
|
|
|
|
|
|
|
return data
|
|
return data
|
|
|
|
|
|
|
|
|
|
+ # def get_product_from_order(self, city_uuid):
|
|
|
|
|
+ # query = f"SELECT cust_code, product_code FROM {self._order_tablename} WHERE city_uuid = :city_uuid"
|
|
|
|
|
+ # params = {"city_uuid": city_uuid}
|
|
|
|
|
+
|
|
|
|
|
+ # data = pd.DataFrame(self.db_helper.fetch_all(text(query), params))
|
|
|
|
|
+
|
|
|
|
|
+ # cust_list = self.get_cust_list(city_uuid)
|
|
|
|
|
+ # cust_index = cust_list.set_index("BB_RETAIL_CUSTOMER_CODE")
|
|
|
|
|
+ # data = data.join(cust_index, on="cust_code", how="inner")
|
|
|
|
|
+ # data = data["product_code"]
|
|
|
|
|
+
|
|
|
|
|
+ # return data
|
|
|
|
|
+
|
|
|
def get_cust_list(self, city_uuid):
|
|
def get_cust_list(self, city_uuid):
|
|
|
query = f"SELECT DISTINCT BB_RETAIL_CUSTOMER_CODE FROM {self._cust_tablename} WHERE BA_CITY_ORG_CODE = :city_uuid"
|
|
query = f"SELECT DISTINCT BB_RETAIL_CUSTOMER_CODE FROM {self._cust_tablename} WHERE BA_CITY_ORG_CODE = :city_uuid"
|
|
|
params = {"city_uuid": city_uuid}
|
|
params = {"city_uuid": city_uuid}
|
|
|
|
|
|
|
|
data = pd.DataFrame(self.db_helper.fetch_all(text(query), params))
|
|
data = pd.DataFrame(self.db_helper.fetch_all(text(query), params))
|
|
|
|
|
|
|
|
- cust_list = data["BB_RETAIL_CUSTOMER_CODE"].tolist()
|
|
|
|
|
-
|
|
|
|
|
- return cust_list
|
|
|
|
|
|
|
+ return data
|
|
|
|
|
|
|
|
def data_preprocess(self, data: pd.DataFrame):
|
|
def data_preprocess(self, data: pd.DataFrame):
|
|
|
|
|
|