feat: v2.0 — maintenance module, AI analysis, station power fix
- Add full 检修维护中心 (6.4): 3-type work orders (消缺/巡检/抄表), asset management, warehouse, work plans, billing settlement - Add AI智能分析 tab with LLM-powered diagnostics (StepFun + ZhipuAI) - Add AI模型配置 settings page (provider, temperature, prompts) - Fix station power accuracy: use API station total (station_power) instead of inverter-level computation — eliminates timing gaps - Add 7 new DB models, 4 new API routers, 5 new frontend pages - Migrations: 009 (maintenance expansion) + 010 (AI analysis) - Version bump: 1.6.1 → 2.0.0 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -20,6 +20,23 @@ DEFAULTS: dict[str, str] = {
|
||||
"notification_email_smtp": "",
|
||||
"report_auto_schedule_enabled": "false",
|
||||
"timezone": "Asia/Shanghai",
|
||||
# AI Model Settings
|
||||
"ai_enabled": "false",
|
||||
"ai_provider": "stepfun", # stepfun, zhipu
|
||||
"ai_api_base_url": "https://api.stepfun.com/step_plan/v1",
|
||||
"ai_api_key": "1UVGFlMG9zaGrRvRATpBNdjKotLio6x9t6lKRKdxwYD3mEkLU2Itb30yb1rvzWRGs",
|
||||
"ai_model_name": "step-2-16k",
|
||||
"ai_temperature": "0.7",
|
||||
"ai_max_tokens": "2000",
|
||||
"ai_context_length": "8000",
|
||||
"ai_fallback_enabled": "true",
|
||||
"ai_fallback_provider": "zhipu",
|
||||
"ai_fallback_api_base_url": "https://open.bigmodel.cn/api/coding/paas/v4",
|
||||
"ai_fallback_api_key": "0b5fe625dfd64836bfd42cc9608aed42.wnQngOvi7EkAWjyn",
|
||||
"ai_fallback_model_name": "codegeex-4",
|
||||
"ai_system_prompt": "你是一个专业的光伏电站智能运维助手。你的任务是分析光伏电站的设备运行数据、告警信息和历史趋势,提供专业的诊断分析和运维建议。请用中文回答,结构清晰,重点突出。",
|
||||
"ai_diagnostic_prompt": "请分析以下光伏设备的运行数据,给出诊断报告:\n\n设备信息:{device_info}\n运行数据:{metrics}\n告警记录:{alarms}\n\n请按以下结构输出:\n## 运行概况\n## 问题诊断\n## 建议措施\n## 风险预警",
|
||||
"ai_insight_prompt": "请根据以下电站运行数据,生成运营洞察报告:\n\n电站概况:{station_info}\n关键指标:{kpis}\n近期告警:{recent_alarms}\n\n请给出3-5条关键洞察和建议。",
|
||||
}
|
||||
|
||||
|
||||
@@ -32,6 +49,35 @@ class SettingsUpdate(BaseModel):
|
||||
notification_email_smtp: str | None = None
|
||||
report_auto_schedule_enabled: bool | None = None
|
||||
timezone: str | None = None
|
||||
ai_enabled: bool | None = None
|
||||
ai_provider: str | None = None
|
||||
ai_api_base_url: str | None = None
|
||||
ai_api_key: str | None = None
|
||||
ai_model_name: str | None = None
|
||||
ai_temperature: float | None = None
|
||||
ai_max_tokens: int | None = None
|
||||
ai_context_length: int | None = None
|
||||
ai_fallback_enabled: bool | None = None
|
||||
ai_fallback_provider: str | None = None
|
||||
ai_fallback_api_base_url: str | None = None
|
||||
ai_fallback_api_key: str | None = None
|
||||
ai_fallback_model_name: str | None = None
|
||||
ai_system_prompt: str | None = None
|
||||
ai_diagnostic_prompt: str | None = None
|
||||
ai_insight_prompt: str | None = None
|
||||
|
||||
|
||||
def _mask_key(key: str) -> str:
|
||||
if not key or len(key) < 8:
|
||||
return "****"
|
||||
return "*" * (len(key) - 4) + key[-4:]
|
||||
|
||||
|
||||
async def _get_raw_settings(db: AsyncSession) -> dict[str, str]:
|
||||
"""Return merged settings dict WITHOUT masking (for internal use)."""
|
||||
result = await db.execute(select(SystemSetting))
|
||||
db_settings = {s.key: s.value for s in result.scalars().all()}
|
||||
return {**DEFAULTS, **db_settings}
|
||||
|
||||
|
||||
@router.get("")
|
||||
@@ -40,10 +86,7 @@ async def get_settings(
|
||||
user: User = Depends(get_current_user),
|
||||
):
|
||||
"""Return all platform settings as a flat dict."""
|
||||
result = await db.execute(select(SystemSetting))
|
||||
db_settings = {s.key: s.value for s in result.scalars().all()}
|
||||
# Merge defaults with DB values
|
||||
merged = {**DEFAULTS, **db_settings}
|
||||
merged = await _get_raw_settings(db)
|
||||
# Cast types for frontend
|
||||
return {
|
||||
"platform_name": merged["platform_name"],
|
||||
@@ -54,6 +97,23 @@ async def get_settings(
|
||||
"notification_email_smtp": merged["notification_email_smtp"],
|
||||
"report_auto_schedule_enabled": merged["report_auto_schedule_enabled"] == "true",
|
||||
"timezone": merged["timezone"],
|
||||
# AI settings
|
||||
"ai_enabled": merged["ai_enabled"] == "true",
|
||||
"ai_provider": merged["ai_provider"],
|
||||
"ai_api_base_url": merged["ai_api_base_url"],
|
||||
"ai_api_key": _mask_key(merged["ai_api_key"]),
|
||||
"ai_model_name": merged["ai_model_name"],
|
||||
"ai_temperature": float(merged["ai_temperature"]),
|
||||
"ai_max_tokens": int(merged["ai_max_tokens"]),
|
||||
"ai_context_length": int(merged["ai_context_length"]),
|
||||
"ai_fallback_enabled": merged["ai_fallback_enabled"] == "true",
|
||||
"ai_fallback_provider": merged["ai_fallback_provider"],
|
||||
"ai_fallback_api_base_url": merged["ai_fallback_api_base_url"],
|
||||
"ai_fallback_api_key": _mask_key(merged["ai_fallback_api_key"]),
|
||||
"ai_fallback_model_name": merged["ai_fallback_model_name"],
|
||||
"ai_system_prompt": merged["ai_system_prompt"],
|
||||
"ai_diagnostic_prompt": merged["ai_diagnostic_prompt"],
|
||||
"ai_insight_prompt": merged["ai_insight_prompt"],
|
||||
}
|
||||
|
||||
|
||||
@@ -82,3 +142,15 @@ async def update_settings(
|
||||
)
|
||||
|
||||
return {"message": "设置已更新"}
|
||||
|
||||
|
||||
@router.post("/test-ai")
|
||||
async def test_ai_connection(
|
||||
db: AsyncSession = Depends(get_db),
|
||||
user: User = Depends(require_roles("admin")),
|
||||
):
|
||||
"""Test AI model connection."""
|
||||
from app.services.llm_service import test_connection
|
||||
settings = await _get_raw_settings(db)
|
||||
result = await test_connection(settings)
|
||||
return result
|
||||
|
||||
Reference in New Issue
Block a user