newtw
This commit is contained in:
@@ -47,6 +47,13 @@ class ImageTaskManager:
|
||||
''')
|
||||
cursor.execute('CREATE INDEX IF NOT EXISTS idx_status ON image_tasks(status)')
|
||||
cursor.execute('CREATE INDEX IF NOT EXISTS idx_cust_plat ON image_tasks(customer_id, platform)')
|
||||
# 兼容旧库:补齐缺失字段
|
||||
cursor.execute("PRAGMA table_info(image_tasks)")
|
||||
existing_cols = {row[1] for row in cursor.fetchall()}
|
||||
if "outcome" not in existing_cols:
|
||||
cursor.execute("ALTER TABLE image_tasks ADD COLUMN outcome TEXT DEFAULT 'pending'")
|
||||
if "price" not in existing_cols:
|
||||
cursor.execute("ALTER TABLE image_tasks ADD COLUMN price REAL DEFAULT 0.0")
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
@@ -88,6 +95,27 @@ class ImageTaskManager:
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to update task status: {e}")
|
||||
|
||||
def update_price(self, customer_id: str, platform: str, price: float):
|
||||
"""记录任务的成交价格"""
|
||||
now = datetime.now().isoformat()
|
||||
try:
|
||||
conn = self._get_conn()
|
||||
cursor = conn.cursor()
|
||||
cursor.execute('''
|
||||
UPDATE image_tasks
|
||||
SET price = ?, updated_at = ?
|
||||
WHERE task_id = (
|
||||
SELECT task_id FROM image_tasks
|
||||
WHERE customer_id = ? AND platform = ?
|
||||
ORDER BY created_at DESC LIMIT 1
|
||||
)
|
||||
''', (price, now, customer_id, platform))
|
||||
conn.commit()
|
||||
conn.close()
|
||||
logger.info(f"[DB] 客户 {customer_id} 任务价格更新为: ¥{price}")
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to update price: {e}")
|
||||
|
||||
def update_outcome(self, customer_id: str, platform: str, outcome: str):
|
||||
"""记录任务的最终结局(用于训练样本分类)"""
|
||||
now = datetime.now().isoformat()
|
||||
|
||||
Reference in New Issue
Block a user