Ver Fonte

修改过滤算法

yangzeyu há 10 meses atrás
pai
commit
ecf724fe8d
2 ficheiros alterados com 29 adições e 36 exclusões
  1. 1 1
      config/service_config.yaml
  2. 28 35
      database/dao/mysql_dao.py

+ 1 - 1
config/service_config.yaml

@@ -1,2 +1,2 @@
 aliyun:
-  upload_url: "http://10.79.117.86/screen/mapi/file/fileUpload"
+  upload_url: "http://file-center.jcpt:8080/file/fileUpload"

+ 28 - 35
database/dao/mysql_dao.py

@@ -43,34 +43,18 @@ class MySqlDao:
         data = self.db_helper.load_data_with_page(query, params)
         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):
         """从数据库中读取订单信息"""
-        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}
-        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('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
     
     def load_eval_order_data(self, city_uuid):
@@ -169,38 +153,38 @@ class MySqlDao:
         """获取指定香烟列表的所有售卖记录"""
         if not product_ids:
             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])
         query = f"""
             SELECT *
             FROM {self._order_tablename}
             WHERE city_uuid = :city_uuid
-            AND cust_code IN ({cust_id_str})
             AND product_code IN ({product_ids_str})
         """
         params = {"city_uuid": city_uuid}
         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
     
     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"""
             SELECT *
             FROM {self._order_tablename}
             WHERE city_uuid = :city_uuid
-            AND cust_code IN ({cust_id_str})
             AND product_code = :product_id
         """
         params = {"city_uuid": city_uuid, "product_id": product_id}
         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
     
     def get_eval_order_by_product(self, city_uuid, product_id):
@@ -241,24 +225,33 @@ class MySqlDao:
         return data
     
     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}
         
         data = pd.DataFrame(self.db_helper.fetch_all(text(query), params))
         
         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):
         query = f"SELECT DISTINCT BB_RETAIL_CUSTOMER_CODE FROM {self._cust_tablename} WHERE BA_CITY_ORG_CODE = :city_uuid"
         params = {"city_uuid": city_uuid}
         
         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):