|
|
@@ -147,32 +147,44 @@ class MySqlDao:
|
|
|
if not product_id_list:
|
|
|
return pd.DataFrame()
|
|
|
|
|
|
- query = text(f"""
|
|
|
- SELECT *
|
|
|
- FROM {self._product_tablename}
|
|
|
- WHERE city_uuid = :city_uuid
|
|
|
- AND product_code IN :ids
|
|
|
- ORDER BY product_code
|
|
|
- """).bindparams(bindparam("ids", expanding=True))
|
|
|
- params = {"city_uuid": city_uuid, "ids": list(product_id_list)}
|
|
|
- data = pd.DataFrame(self.db_helper.fetch_all(query, params))
|
|
|
+ product_id_list = list(product_id_list)
|
|
|
+ batch_size = 2000
|
|
|
+ batches = [product_id_list[i:i + batch_size] for i in range(0, len(product_id_list), batch_size)]
|
|
|
+ results = []
|
|
|
+ for batch in batches:
|
|
|
+ query = text(f"""
|
|
|
+ SELECT *
|
|
|
+ FROM {self._product_tablename}
|
|
|
+ WHERE city_uuid = :city_uuid
|
|
|
+ AND product_code IN :ids
|
|
|
+ ORDER BY product_code
|
|
|
+ """).bindparams(bindparam("ids", expanding=True))
|
|
|
+ params = {"city_uuid": city_uuid, "ids": batch}
|
|
|
+ results.append(pd.DataFrame(self.db_helper.fetch_all(query, params)))
|
|
|
|
|
|
- return data
|
|
|
+ return pd.concat(results, ignore_index=True) if results else pd.DataFrame()
|
|
|
|
|
|
def get_order_by_product_ids(self, city_uuid, product_ids):
|
|
|
"""获取指定香烟列表的所有售卖记录"""
|
|
|
if not product_ids:
|
|
|
return pd.DataFrame()
|
|
|
|
|
|
- query = text(f"""
|
|
|
- SELECT *
|
|
|
- FROM {self._order_tablename}
|
|
|
- WHERE city_uuid = :city_uuid
|
|
|
- AND product_code IN :ids
|
|
|
- ORDER BY cust_code, product_code
|
|
|
- """).bindparams(bindparam("ids", expanding=True))
|
|
|
- params = {"city_uuid": city_uuid, "ids": list(product_ids)}
|
|
|
- data = pd.DataFrame(self.db_helper.fetch_all(query, params))
|
|
|
+ product_ids = list(product_ids)
|
|
|
+ batch_size = 2000
|
|
|
+ batches = [product_ids[i:i + batch_size] for i in range(0, len(product_ids), batch_size)]
|
|
|
+ results = []
|
|
|
+ for batch in batches:
|
|
|
+ query = text(f"""
|
|
|
+ SELECT *
|
|
|
+ FROM {self._order_tablename}
|
|
|
+ WHERE city_uuid = :city_uuid
|
|
|
+ AND product_code IN :ids
|
|
|
+ ORDER BY cust_code, product_code
|
|
|
+ """).bindparams(bindparam("ids", expanding=True))
|
|
|
+ params = {"city_uuid": city_uuid, "ids": batch}
|
|
|
+ results.append(pd.DataFrame(self.db_helper.fetch_all(query, params)))
|
|
|
+
|
|
|
+ data = pd.concat(results, ignore_index=True) if results else pd.DataFrame()
|
|
|
|
|
|
cust_list = self.get_cust_list(city_uuid)
|
|
|
cust_index = cust_list.set_index("cust_code")
|