fix: auto-fix code issues (cron)

- 修复重复导入/字段 (llm_client.py 中的重复注释)
- 修复PEP8格式问题 (E501行长度超过100字符)
- 修复多行SQL语句和字符串格式化
- 修复f-string过长问题

涉及文件:
- backend/developer_ecosystem_manager.py
- backend/document_processor.py
- backend/enterprise_manager.py
- backend/export_manager.py
- backend/growth_manager.py
- backend/llm_client.py
- backend/localization_manager.py
- backend/main.py
- backend/neo4j_manager.py
- backend/ops_manager.py
- backend/performance_manager.py
- backend/plugin_manager.py
- backend/search_manager.py
- backend/security_manager.py
- backend/subscription_manager.py
- backend/tenant_manager.py
- backend/test_phase8_task6.py
- backend/test_phase8_task8.py
- backend/tingwu_client.py
- backend/workflow_manager.py
This commit is contained in:
AutoFix Bot
2026-03-04 03:19:02 +08:00
parent e108f83cd9
commit 0869fec587
20 changed files with 222 additions and 115 deletions

View File

@@ -756,10 +756,11 @@ class LocalizationManager:
cursor.execute("""
CREATE TABLE IF NOT EXISTS language_configs (
code TEXT PRIMARY KEY, name TEXT NOT NULL, name_local TEXT NOT NULL,
is_rtl INTEGER DEFAULT 0, is_active INTEGER DEFAULT 1, is_default INTEGER DEFAULT 0,
fallback_language TEXT, date_format TEXT, time_format TEXT, datetime_format TEXT,
number_format TEXT, currency_format TEXT, first_day_of_week INTEGER DEFAULT 1,
calendar_type TEXT DEFAULT 'gregorian'
is_rtl INTEGER DEFAULT 0, is_active INTEGER DEFAULT 1,
is_default INTEGER DEFAULT 0, fallback_language TEXT,
date_format TEXT, time_format TEXT, datetime_format TEXT,
number_format TEXT, currency_format TEXT,
first_day_of_week INTEGER DEFAULT 1, calendar_type TEXT DEFAULT 'gregorian'
)
""")
cursor.execute("""
@@ -773,8 +774,10 @@ class LocalizationManager:
""")
cursor.execute("""
CREATE TABLE IF NOT EXISTS tenant_data_center_mappings (
id TEXT PRIMARY KEY, tenant_id TEXT NOT NULL UNIQUE, primary_dc_id TEXT NOT NULL,
secondary_dc_id TEXT, region_code TEXT NOT NULL, data_residency TEXT DEFAULT 'regional',
id TEXT PRIMARY KEY, tenant_id TEXT NOT NULL UNIQUE,
primary_dc_id TEXT NOT NULL, secondary_dc_id TEXT,
region_code TEXT NOT NULL,
data_residency TEXT DEFAULT 'regional',
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (tenant_id) REFERENCES tenants(id) ON DELETE CASCADE,
@@ -788,43 +791,52 @@ class LocalizationManager:
name_local TEXT DEFAULT '{}', supported_countries TEXT DEFAULT '[]',
supported_currencies TEXT DEFAULT '[]', is_active INTEGER DEFAULT 1,
config TEXT DEFAULT '{}', icon_url TEXT, display_order INTEGER DEFAULT 0,
min_amount REAL, max_amount REAL, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
min_amount REAL, max_amount REAL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)
""")
cursor.execute("""
CREATE TABLE IF NOT EXISTS country_configs (
code TEXT PRIMARY KEY, code3 TEXT NOT NULL, name TEXT NOT NULL,
name_local TEXT DEFAULT '{}', region TEXT NOT NULL, default_language TEXT NOT NULL,
supported_languages TEXT DEFAULT '[]', default_currency TEXT NOT NULL,
supported_currencies TEXT DEFAULT '[]', timezone TEXT NOT NULL,
calendar_type TEXT DEFAULT 'gregorian', date_format TEXT, time_format TEXT,
number_format TEXT, address_format TEXT, phone_format TEXT, vat_rate REAL,
name_local TEXT DEFAULT '{}', region TEXT NOT NULL,
default_language TEXT NOT NULL, supported_languages TEXT DEFAULT '[]',
default_currency TEXT NOT NULL, supported_currencies TEXT DEFAULT '[]',
timezone TEXT NOT NULL, calendar_type TEXT DEFAULT 'gregorian',
date_format TEXT, time_format TEXT, number_format TEXT,
address_format TEXT, phone_format TEXT, vat_rate REAL,
is_active INTEGER DEFAULT 1
)
""")
cursor.execute("""
CREATE TABLE IF NOT EXISTS timezone_configs (
id TEXT PRIMARY KEY, timezone TEXT NOT NULL UNIQUE, utc_offset TEXT NOT NULL, dst_offset TEXT,
country_code TEXT NOT NULL, region TEXT NOT NULL, is_active INTEGER DEFAULT 1
id TEXT PRIMARY KEY, timezone TEXT NOT NULL UNIQUE,
utc_offset TEXT NOT NULL, dst_offset TEXT, country_code TEXT NOT NULL,
region TEXT NOT NULL, is_active INTEGER DEFAULT 1
)
""")
cursor.execute("""
CREATE TABLE IF NOT EXISTS currency_configs (
code TEXT PRIMARY KEY, name TEXT NOT NULL, name_local TEXT DEFAULT '{}', symbol TEXT NOT NULL,
code TEXT PRIMARY KEY, name TEXT NOT NULL,
name_local TEXT DEFAULT '{}', symbol TEXT NOT NULL,
decimal_places INTEGER DEFAULT 2, decimal_separator TEXT DEFAULT '.',
thousands_separator TEXT DEFAULT ', ', is_active INTEGER DEFAULT 1
)
""")
cursor.execute("""
CREATE TABLE IF NOT EXISTS localization_settings (
id TEXT PRIMARY KEY, tenant_id TEXT NOT NULL UNIQUE, default_language TEXT DEFAULT 'en',
supported_languages TEXT DEFAULT '["en"]', default_currency TEXT DEFAULT 'USD',
supported_currencies TEXT DEFAULT '["USD"]', default_timezone TEXT DEFAULT 'UTC',
default_date_format TEXT, default_time_format TEXT, default_number_format TEXT,
calendar_type TEXT DEFAULT 'gregorian', first_day_of_week INTEGER DEFAULT 1,
region_code TEXT DEFAULT 'global', data_residency TEXT DEFAULT 'regional',
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
id TEXT PRIMARY KEY, tenant_id TEXT NOT NULL UNIQUE,
default_language TEXT DEFAULT 'en',
supported_languages TEXT DEFAULT '["en"]',
default_currency TEXT DEFAULT 'USD',
supported_currencies TEXT DEFAULT '["USD"]',
default_timezone TEXT DEFAULT 'UTC',
default_date_format TEXT, default_time_format TEXT,
default_number_format TEXT, calendar_type TEXT DEFAULT 'gregorian',
first_day_of_week INTEGER DEFAULT 1, region_code TEXT DEFAULT 'global',
data_residency TEXT DEFAULT 'regional',
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (tenant_id) REFERENCES tenants(id) ON DELETE CASCADE
)
""")
@@ -838,22 +850,28 @@ class LocalizationManager:
cursor.execute("CREATE INDEX IF NOT EXISTS idx_dc_region ON data_centers(region_code)")
cursor.execute("CREATE INDEX IF NOT EXISTS idx_dc_status ON data_centers(status)")
cursor.execute(
"CREATE INDEX IF NOT EXISTS idx_tenant_dc ON tenant_data_center_mappings(tenant_id)",
"CREATE INDEX IF NOT EXISTS idx_tenant_dc "
"ON tenant_data_center_mappings(tenant_id)",
)
cursor.execute(
"CREATE INDEX IF NOT EXISTS idx_payment_provider ON localized_payment_methods(provider)",
"CREATE INDEX IF NOT EXISTS idx_payment_provider "
"ON localized_payment_methods(provider)",
)
cursor.execute(
"CREATE INDEX IF NOT EXISTS idx_payment_active ON localized_payment_methods(is_active)",
"CREATE INDEX IF NOT EXISTS idx_payment_active "
"ON localized_payment_methods(is_active)",
)
cursor.execute(
"CREATE INDEX IF NOT EXISTS idx_country_region ON country_configs(region)",
"CREATE INDEX IF NOT EXISTS idx_country_region "
"ON country_configs(region)",
)
cursor.execute(
"CREATE INDEX IF NOT EXISTS idx_tz_country ON timezone_configs(country_code)",
"CREATE INDEX IF NOT EXISTS idx_tz_country "
"ON timezone_configs(country_code)",
)
cursor.execute(
"CREATE INDEX IF NOT EXISTS idx_locale_settings_tenant ON localization_settings(tenant_id)",
"CREATE INDEX IF NOT EXISTS idx_locale_settings_tenant "
"ON localization_settings(tenant_id)",
)
conn.commit()
logger.info("Localization tables initialized successfully")
@@ -898,7 +916,8 @@ class LocalizationManager:
cursor.execute(
"""
INSERT OR IGNORE INTO data_centers
(id, region_code, name, location, endpoint, priority, supported_regions, capabilities)
(id, region_code, name, location, endpoint, priority,
supported_regions, capabilities)
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
""",
(
@@ -1188,7 +1207,9 @@ class LocalizationManager:
row = cursor.fetchone()
if not row:
cursor.execute("""
SELECT * FROM data_centers WHERE supported_regions LIKE '%"global"%' AND status = 'active'
SELECT * FROM data_centers
WHERE supported_regions LIKE '%"global"%'
AND status = 'active'
ORDER BY priority LIMIT 1
""")
row = cursor.fetchone()
@@ -1197,7 +1218,9 @@ class LocalizationManager:
primary_dc_id = row["id"]
cursor.execute(
"""
SELECT * FROM data_centers WHERE id != ? AND status = 'active' ORDER BY priority LIMIT 1
SELECT * FROM data_centers
WHERE id != ? AND status = 'active'
ORDER BY priority LIMIT 1
""",
(primary_dc_id,),
)
@@ -1468,9 +1491,10 @@ class LocalizationManager:
cursor.execute(
"""
INSERT INTO localization_settings
(id, tenant_id, default_language, supported_languages, default_currency, supported_currencies,
default_timezone, default_date_format, default_time_format, default_number_format, calendar_type,
first_day_of_week, region_code, data_residency, created_at, updated_at)
(id, tenant_id, default_language, supported_languages, default_currency,
supported_currencies, default_timezone, default_date_format, default_time_format,
default_number_format, calendar_type, first_day_of_week, region_code,
data_residency, created_at, updated_at)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
""",
(