fix: auto-fix code issues (cron)

- 修复重复导入/字段
- 修复异常处理
- 修复PEP8格式问题 (816+ 处)
- 添加缺失的导入 (json, re)
- 统一SQL查询格式
- 修复赋值语句空格问题

修复文件:
- db_manager.py (96处)
- search_manager.py (77处)
- ops_manager.py (66处)
- developer_ecosystem_manager.py (68处)
- growth_manager.py (60处)
- enterprise_manager.py (61处)
- tenant_manager.py (57处)
- plugin_manager.py (48处)
- subscription_manager.py (46处)
- security_manager.py (29处)
- workflow_manager.py (32处)
- localization_manager.py (31处)
- api_key_manager.py (20处)
- ai_manager.py (23处)
- performance_manager.py (24处)
- neo4j_manager.py (25处)
- collaboration_manager.py (33处)
- test_phase8_task8.py (16处)
- test_phase8_task6.py (4处)
- knowledge_reasoner.py (添加import json)
- llm_client.py (添加import json)
This commit is contained in:
AutoFix Bot
2026-03-03 00:11:51 +08:00
parent c695e99eaf
commit 2a0ed6af4d
23 changed files with 1160 additions and 947 deletions

View File

@@ -572,7 +572,7 @@ class SubscriptionManager:
conn = self._get_connection()
try:
cursor = conn.cursor()
cursor.execute("SELECT * FROM subscription_plans WHERE id = ?", (plan_id,))
cursor.execute("SELECT * FROM subscription_plans WHERE id = ?", (plan_id,))
row = cursor.fetchone()
if row:
@@ -588,7 +588,7 @@ class SubscriptionManager:
try:
cursor = conn.cursor()
cursor.execute(
"SELECT * FROM subscription_plans WHERE tier = ? AND is_active = 1", (tier,)
"SELECT * FROM subscription_plans WHERE tier = ? AND is_active = 1", (tier,)
)
row = cursor.fetchone()
@@ -609,7 +609,7 @@ class SubscriptionManager:
cursor.execute("SELECT * FROM subscription_plans ORDER BY price_monthly")
else:
cursor.execute(
"SELECT * FROM subscription_plans WHERE is_active = 1 ORDER BY price_monthly"
"SELECT * FROM subscription_plans WHERE is_active = 1 ORDER BY price_monthly"
)
rows = cursor.fetchall()
@@ -721,7 +721,7 @@ class SubscriptionManager:
if not updates:
return plan
updates.append("updated_at = ?")
updates.append("updated_at = ?")
params.append(datetime.now())
params.append(plan_id)
@@ -729,7 +729,7 @@ class SubscriptionManager:
cursor.execute(
f"""
UPDATE subscription_plans SET {", ".join(updates)}
WHERE id = ?
WHERE id = ?
""",
params,
)
@@ -758,7 +758,7 @@ class SubscriptionManager:
cursor.execute(
"""
SELECT * FROM subscriptions
WHERE tenant_id = ? AND status IN ('active', 'trial', 'pending')
WHERE tenant_id = ? AND status IN ('active', 'trial', 'pending')
""",
(tenant_id,),
)
@@ -878,7 +878,7 @@ class SubscriptionManager:
conn = self._get_connection()
try:
cursor = conn.cursor()
cursor.execute("SELECT * FROM subscriptions WHERE id = ?", (subscription_id,))
cursor.execute("SELECT * FROM subscriptions WHERE id = ?", (subscription_id,))
row = cursor.fetchone()
if row:
@@ -896,7 +896,7 @@ class SubscriptionManager:
cursor.execute(
"""
SELECT * FROM subscriptions
WHERE tenant_id = ? AND status IN ('active', 'trial', 'past_due', 'pending')
WHERE tenant_id = ? AND status IN ('active', 'trial', 'past_due', 'pending')
ORDER BY created_at DESC LIMIT 1
""",
(tenant_id,),
@@ -943,7 +943,7 @@ class SubscriptionManager:
if not updates:
return subscription
updates.append("updated_at = ?")
updates.append("updated_at = ?")
params.append(datetime.now())
params.append(subscription_id)
@@ -951,7 +951,7 @@ class SubscriptionManager:
cursor.execute(
f"""
UPDATE subscriptions SET {", ".join(updates)}
WHERE id = ?
WHERE id = ?
""",
params,
)
@@ -980,8 +980,8 @@ class SubscriptionManager:
cursor.execute(
"""
UPDATE subscriptions
SET cancel_at_period_end = 1, canceled_at = ?, updated_at = ?
WHERE id = ?
SET cancel_at_period_end = 1, canceled_at = ?, updated_at = ?
WHERE id = ?
""",
(now, now, subscription_id),
)
@@ -991,8 +991,8 @@ class SubscriptionManager:
cursor.execute(
"""
UPDATE subscriptions
SET status = 'cancelled', canceled_at = ?, updated_at = ?
WHERE id = ?
SET status = 'cancelled', canceled_at = ?, updated_at = ?
WHERE id = ?
""",
(now, now, subscription_id),
)
@@ -1043,8 +1043,8 @@ class SubscriptionManager:
cursor.execute(
"""
UPDATE subscriptions
SET plan_id = ?, updated_at = ?
WHERE id = ?
SET plan_id = ?, updated_at = ?
WHERE id = ?
""",
(new_plan_id, now, subscription_id),
)
@@ -1139,7 +1139,7 @@ class SubscriptionManager:
SUM(cost) as total_cost,
COUNT(*) as record_count
FROM usage_records
WHERE tenant_id = ?
WHERE tenant_id = ?
"""
params = [tenant_id]
@@ -1283,8 +1283,8 @@ class SubscriptionManager:
cursor.execute(
"""
UPDATE payments
SET status = 'completed', provider_payment_id = ?, paid_at = ?, updated_at = ?
WHERE id = ?
SET status = 'completed', provider_payment_id = ?, paid_at = ?, updated_at = ?
WHERE id = ?
""",
(provider_payment_id, now, now, payment_id),
)
@@ -1294,8 +1294,8 @@ class SubscriptionManager:
cursor.execute(
"""
UPDATE invoices
SET status = 'paid', amount_paid = amount_due, paid_at = ?
WHERE id = ?
SET status = 'paid', amount_paid = amount_due, paid_at = ?
WHERE id = ?
""",
(now, payment.invoice_id),
)
@@ -1305,8 +1305,8 @@ class SubscriptionManager:
cursor.execute(
"""
UPDATE subscriptions
SET status = 'active', updated_at = ?
WHERE id = ? AND status = 'pending'
SET status = 'active', updated_at = ?
WHERE id = ? AND status = 'pending'
""",
(now, payment.subscription_id),
)
@@ -1340,8 +1340,8 @@ class SubscriptionManager:
cursor.execute(
"""
UPDATE payments
SET status = 'failed', failure_reason = ?, failed_at = ?, updated_at = ?
WHERE id = ?
SET status = 'failed', failure_reason = ?, failed_at = ?, updated_at = ?
WHERE id = ?
""",
(reason, now, now, payment_id),
)
@@ -1368,11 +1368,11 @@ class SubscriptionManager:
try:
cursor = conn.cursor()
query = "SELECT * FROM payments WHERE tenant_id = ?"
query = "SELECT * FROM payments WHERE tenant_id = ?"
params = [tenant_id]
if status:
query += " AND status = ?"
query += " AND status = ?"
params.append(status)
query += " ORDER BY created_at DESC LIMIT ? OFFSET ?"
@@ -1389,7 +1389,7 @@ class SubscriptionManager:
def _get_payment_internal(self, conn: sqlite3.Connection, payment_id: str) -> Payment | None:
"""内部方法:获取支付记录"""
cursor = conn.cursor()
cursor.execute("SELECT * FROM payments WHERE id = ?", (payment_id,))
cursor.execute("SELECT * FROM payments WHERE id = ?", (payment_id,))
row = cursor.fetchone()
if row:
@@ -1475,7 +1475,7 @@ class SubscriptionManager:
conn = self._get_connection()
try:
cursor = conn.cursor()
cursor.execute("SELECT * FROM invoices WHERE id = ?", (invoice_id,))
cursor.execute("SELECT * FROM invoices WHERE id = ?", (invoice_id,))
row = cursor.fetchone()
if row:
@@ -1490,7 +1490,7 @@ class SubscriptionManager:
conn = self._get_connection()
try:
cursor = conn.cursor()
cursor.execute("SELECT * FROM invoices WHERE invoice_number = ?", (invoice_number,))
cursor.execute("SELECT * FROM invoices WHERE invoice_number = ?", (invoice_number,))
row = cursor.fetchone()
if row:
@@ -1508,11 +1508,11 @@ class SubscriptionManager:
try:
cursor = conn.cursor()
query = "SELECT * FROM invoices WHERE tenant_id = ?"
query = "SELECT * FROM invoices WHERE tenant_id = ?"
params = [tenant_id]
if status:
query += " AND status = ?"
query += " AND status = ?"
params.append(status)
query += " ORDER BY created_at DESC LIMIT ? OFFSET ?"
@@ -1543,8 +1543,8 @@ class SubscriptionManager:
cursor.execute(
"""
UPDATE invoices
SET status = 'void', voided_at = ?, void_reason = ?, updated_at = ?
WHERE id = ?
SET status = 'void', voided_at = ?, void_reason = ?, updated_at = ?
WHERE id = ?
""",
(now, reason, now, invoice_id),
)
@@ -1677,8 +1677,8 @@ class SubscriptionManager:
cursor.execute(
"""
UPDATE refunds
SET status = 'approved', approved_by = ?, approved_at = ?, updated_at = ?
WHERE id = ?
SET status = 'approved', approved_by = ?, approved_at = ?, updated_at = ?
WHERE id = ?
""",
(approved_by, now, now, refund_id),
)
@@ -1705,8 +1705,8 @@ class SubscriptionManager:
cursor.execute(
"""
UPDATE refunds
SET status = 'completed', provider_refund_id = ?, completed_at = ?, updated_at = ?
WHERE id = ?
SET status = 'completed', provider_refund_id = ?, completed_at = ?, updated_at = ?
WHERE id = ?
""",
(provider_refund_id, now, now, refund_id),
)
@@ -1715,8 +1715,8 @@ class SubscriptionManager:
cursor.execute(
"""
UPDATE payments
SET status = 'refunded', updated_at = ?
WHERE id = ?
SET status = 'refunded', updated_at = ?
WHERE id = ?
""",
(now, refund.payment_id),
)
@@ -1754,8 +1754,8 @@ class SubscriptionManager:
cursor.execute(
"""
UPDATE refunds
SET status = 'rejected', metadata = json_set(metadata, '$.rejection_reason', ?), updated_at = ?
WHERE id = ?
SET status = 'rejected', metadata = json_set(metadata, '$.rejection_reason', ?), updated_at = ?
WHERE id = ?
""",
(reason, now, refund_id),
)
@@ -1782,11 +1782,11 @@ class SubscriptionManager:
try:
cursor = conn.cursor()
query = "SELECT * FROM refunds WHERE tenant_id = ?"
query = "SELECT * FROM refunds WHERE tenant_id = ?"
params = [tenant_id]
if status:
query += " AND status = ?"
query += " AND status = ?"
params.append(status)
query += " ORDER BY created_at DESC LIMIT ? OFFSET ?"
@@ -1803,7 +1803,7 @@ class SubscriptionManager:
def _get_refund_internal(self, conn: sqlite3.Connection, refund_id: str) -> Refund | None:
"""内部方法:获取退款记录"""
cursor = conn.cursor()
cursor.execute("SELECT * FROM refunds WHERE id = ?", (refund_id,))
cursor.execute("SELECT * FROM refunds WHERE id = ?", (refund_id,))
row = cursor.fetchone()
if row:
@@ -1860,7 +1860,7 @@ class SubscriptionManager:
try:
cursor = conn.cursor()
query = "SELECT * FROM billing_history WHERE tenant_id = ?"
query = "SELECT * FROM billing_history WHERE tenant_id = ?"
params = [tenant_id]
if start_date: