|
|
@@ -5,6 +5,7 @@ from config.settings import DB_URL
|
|
|
from utils.sql_engine import create_db_and_tables,drop_table,engine
|
|
|
from src.models.asin_model import AsinSeed
|
|
|
from src.models.product_model import Product
|
|
|
+from utils.file import delete_s3_file
|
|
|
|
|
|
class DbManager:
|
|
|
def __init__(self, engine: str=None):
|
|
|
@@ -44,6 +45,33 @@ class DbManager:
|
|
|
else:
|
|
|
return list_model
|
|
|
|
|
|
+ def delete_asin_seed_by_id(self, asin_id: int) -> bool:
|
|
|
+ """根据id删除asin_seed记录,如果s3路径存在,连同一起删除"""
|
|
|
+ with Session(self.engine) as session:
|
|
|
+ # 首先获取要删除的记录
|
|
|
+ statement = select(AsinSeed).where(AsinSeed.id == asin_id)
|
|
|
+ result = session.exec(statement)
|
|
|
+ asin_seed = result.first()
|
|
|
+
|
|
|
+ if not asin_seed:
|
|
|
+ return False
|
|
|
+
|
|
|
+ # 删除S3文件(如果存在)
|
|
|
+ deleted_s3_files = []
|
|
|
+ if asin_seed.extra_result_path:
|
|
|
+ if delete_s3_file(asin_seed.extra_result_path):
|
|
|
+ deleted_s3_files.append(asin_seed.extra_result_path)
|
|
|
+
|
|
|
+ if asin_seed.mhtml_path:
|
|
|
+ if delete_s3_file(asin_seed.mhtml_path):
|
|
|
+ deleted_s3_files.append(asin_seed.mhtml_path)
|
|
|
+
|
|
|
+ # 删除数据库记录
|
|
|
+ session.delete(asin_seed)
|
|
|
+ session.commit()
|
|
|
+
|
|
|
+ return True
|
|
|
+
|
|
|
class ProductManager:
|
|
|
def __init__(self, engine: str=None):
|
|
|
self.engine = engine or create_engine(DB_URL)
|