fix: auto-fix code issues (cron)

- 修复重复导入/字段
- 修复异常处理
- 修复PEP8格式问题
- 添加类型注解
This commit is contained in:
AutoFix Bot
2026-03-03 06:03:38 +08:00
parent 2a0ed6af4d
commit 9fd1da8fb7
41 changed files with 901 additions and 768 deletions

View File

@@ -484,37 +484,37 @@ class SubscriptionManager:
# 创建索引
cursor.execute(
"CREATE INDEX IF NOT EXISTS idx_subscriptions_tenant ON subscriptions(tenant_id)"
"CREATE INDEX IF NOT EXISTS idx_subscriptions_tenant ON subscriptions(tenant_id)",
)
cursor.execute(
"CREATE INDEX IF NOT EXISTS idx_subscriptions_status ON subscriptions(status)"
"CREATE INDEX IF NOT EXISTS idx_subscriptions_status ON subscriptions(status)",
)
cursor.execute(
"CREATE INDEX IF NOT EXISTS idx_subscriptions_plan ON subscriptions(plan_id)"
"CREATE INDEX IF NOT EXISTS idx_subscriptions_plan ON subscriptions(plan_id)",
)
cursor.execute(
"CREATE INDEX IF NOT EXISTS idx_usage_tenant ON usage_records(tenant_id)"
"CREATE INDEX IF NOT EXISTS idx_usage_tenant ON usage_records(tenant_id)",
)
cursor.execute(
"CREATE INDEX IF NOT EXISTS idx_usage_type ON usage_records(resource_type)"
"CREATE INDEX IF NOT EXISTS idx_usage_type ON usage_records(resource_type)",
)
cursor.execute(
"CREATE INDEX IF NOT EXISTS idx_usage_recorded ON usage_records(recorded_at)"
"CREATE INDEX IF NOT EXISTS idx_usage_recorded ON usage_records(recorded_at)",
)
cursor.execute("CREATE INDEX IF NOT EXISTS idx_payments_tenant ON payments(tenant_id)")
cursor.execute("CREATE INDEX IF NOT EXISTS idx_payments_status ON payments(status)")
cursor.execute("CREATE INDEX IF NOT EXISTS idx_invoices_tenant ON invoices(tenant_id)")
cursor.execute("CREATE INDEX IF NOT EXISTS idx_invoices_status ON invoices(status)")
cursor.execute(
"CREATE INDEX IF NOT EXISTS idx_invoices_number ON invoices(invoice_number)"
"CREATE INDEX IF NOT EXISTS idx_invoices_number ON invoices(invoice_number)",
)
cursor.execute("CREATE INDEX IF NOT EXISTS idx_refunds_tenant ON refunds(tenant_id)")
cursor.execute("CREATE INDEX IF NOT EXISTS idx_refunds_status ON refunds(status)")
cursor.execute(
"CREATE INDEX IF NOT EXISTS idx_billing_tenant ON billing_history(tenant_id)"
"CREATE INDEX IF NOT EXISTS idx_billing_tenant ON billing_history(tenant_id)",
)
cursor.execute(
"CREATE INDEX IF NOT EXISTS idx_billing_created ON billing_history(created_at)"
"CREATE INDEX IF NOT EXISTS idx_billing_created ON billing_history(created_at)",
)
conn.commit()
@@ -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()
@@ -963,7 +963,7 @@ class SubscriptionManager:
conn.close()
def cancel_subscription(
self, subscription_id: str, at_period_end: bool = True
self, subscription_id: str, at_period_end: bool = True,
) -> Subscription | None:
"""取消订阅"""
conn = self._get_connection()
@@ -1017,7 +1017,7 @@ class SubscriptionManager:
conn.close()
def change_plan(
self, subscription_id: str, new_plan_id: str, prorate: bool = True
self, subscription_id: str, new_plan_id: str, prorate: bool = True,
) -> Subscription | None:
"""更改订阅计划"""
conn = self._get_connection()
@@ -1125,7 +1125,7 @@ class SubscriptionManager:
conn.close()
def get_usage_summary(
self, tenant_id: str, start_date: datetime | None = None, end_date: datetime | None = None
self, tenant_id: str, start_date: datetime | None = None, end_date: datetime | None = None,
) -> dict[str, Any]:
"""获取用量汇总"""
conn = self._get_connection()
@@ -1268,7 +1268,7 @@ class SubscriptionManager:
conn.close()
def confirm_payment(
self, payment_id: str, provider_payment_id: str | None = None
self, payment_id: str, provider_payment_id: str | None = None,
) -> Payment | None:
"""确认支付完成"""
conn = self._get_connection()
@@ -1361,7 +1361,7 @@ class SubscriptionManager:
conn.close()
def list_payments(
self, tenant_id: str, status: str | None = None, limit: int = 100, offset: int = 0
self, tenant_id: str, status: str | None = None, limit: int = 100, offset: int = 0,
) -> list[Payment]:
"""列出支付记录"""
conn = self._get_connection()
@@ -1501,7 +1501,7 @@ class SubscriptionManager:
conn.close()
def list_invoices(
self, tenant_id: str, status: str | None = None, limit: int = 100, offset: int = 0
self, tenant_id: str, status: str | None = None, limit: int = 100, offset: int = 0,
) -> list[Invoice]:
"""列出发票"""
conn = self._get_connection()
@@ -1581,7 +1581,7 @@ class SubscriptionManager:
# ==================== 退款管理 ====================
def request_refund(
self, tenant_id: str, payment_id: str, amount: float, reason: str, requested_by: str
self, tenant_id: str, payment_id: str, amount: float, reason: str, requested_by: str,
) -> Refund:
"""申请退款"""
conn = self._get_connection()
@@ -1690,7 +1690,7 @@ class SubscriptionManager:
conn.close()
def complete_refund(
self, refund_id: str, provider_refund_id: str | None = None
self, refund_id: str, provider_refund_id: str | None = None,
) -> Refund | None:
"""完成退款"""
conn = self._get_connection()
@@ -1775,7 +1775,7 @@ class SubscriptionManager:
conn.close()
def list_refunds(
self, tenant_id: str, status: str | None = None, limit: int = 100, offset: int = 0
self, tenant_id: str, status: str | None = None, limit: int = 100, offset: int = 0,
) -> list[Refund]:
"""列出退款记录"""
conn = self._get_connection()
@@ -1902,7 +1902,7 @@ class SubscriptionManager:
}
def create_alipay_order(
self, tenant_id: str, plan_id: str, billing_cycle: str = "monthly"
self, tenant_id: str, plan_id: str, billing_cycle: str = "monthly",
) -> dict[str, Any]:
"""创建支付宝订单(占位实现)"""
# 这里应该集成支付宝 SDK
@@ -1919,7 +1919,7 @@ class SubscriptionManager:
}
def create_wechat_order(
self, tenant_id: str, plan_id: str, billing_cycle: str = "monthly"
self, tenant_id: str, plan_id: str, billing_cycle: str = "monthly",
) -> dict[str, Any]:
"""创建微信支付订单(占位实现)"""
# 这里应该集成微信支付 SDK