Files
server-core/app/services/dashboard_service.py
T
Pine c99662cfec feat: 业务层 services 抽取完成(工作台/用户管理)
- DashboardService:OPC 工作台聚合(统计/进行中任务/智能体建议/月度收入/消息)
- UserAdminService:建号+默认身份联动、角色分配提权防护(action:role.grant_perm 仅超管)
- rbac_opc dashboard / rbac_admin create_user+set_role 接线
- services 层覆盖全部核心业务域,路由全瘦身
2026-08-24 09:35:08 +08:00

40 lines
1.7 KiB
Python

# -*- coding: utf-8 -*-
"""业务层 · 工作台聚合服务(各端口 dashboard)。"""
from __future__ import annotations
from ..infrastructure.repositories import Database
class DashboardService:
"""OPC 工作台聚合:统计/进行中任务/智能体建议/月度收入/最新消息。"""
def __init__(self, db: Database):
self.db = db
async def opc_dashboard(self, uid: str) -> dict:
profile = await self.db.opc_profiles.get(uid)
task_counts = await self.db.opc_tasks.counts(uid)
opc_tasks = await self.db.opc_tasks.list_by_user(uid)
active_tasks = [t for t in opc_tasks if t["status"] in ("in_progress", "urgent")][:3]
policy_count = len(
[c for c in await self.db.content.list(ctype="policy", status="published")]
)
agent_tips = [
{"title": "政策匹配提醒", "desc": f"{policy_count} 项新政策与您高度匹配", "type": "policy"},
{"title": "报税截止提醒", "desc": "本月报税截止 7月31日", "type": "tax"},
{"title": "技能提升推荐", "desc": "推荐参加 UI 设计研修班", "type": "skill"},
]
return {
"stats": {
"inProgressTasks": task_counts["in_progress"],
"completedTasks": task_counts["completed"],
"totalEarnings": await self.db.finance.total_income(uid),
"creditScore": (profile or {}).get("credit_score", 80),
},
"activeTasks": active_tasks,
"agentTips": agent_tips,
"monthlyIncome": await self.db.finance.monthly_income(uid),
"recentMessages": await self.db.messages.recent(uid, limit=4),
}