PC 管理端新增独立全屏数据大屏,供管理层查看直通率/产量趋势/不良分布, 替代原 AdminDashboard 上零散的手工下钻。 后端: - endpoints/screen.py + services/screen_service.py: 大屏聚合接口 (复用 lifecycle 的售后工序归一,保证统计口径与展示一致) - router.py: 注册 screen_router 前端: - pages/admin/ScreenDashboard.tsx: 全屏大屏页(自带鉴权守卫,无侧边栏) - services/screenApi.ts: 大屏数据接口封装 - components/admin/UserOperationDetailDrawer.tsx: 人员操作明细抽屉, 由 AdminDashboard 的原生 state 抽成独立组件(含命令式 handle) - AdminDashboard.tsx: 改为使用该抽屉组件,移除内联的下钻状态 - MatrixBoard.tsx / App.tsx / AdminLayout.tsx: 挂载路由与导航入口 - BaseEChart.tsx: 注册 GaugeChart 与 GraphicComponent (graphic 需显式注册,否则饼图中心文字静默不渲染)
53 lines
1.9 KiB
Python
53 lines
1.9 KiB
Python
"""大屏 API — 面向管理层**日常运营与督导**的轻量聚合接口
|
|
|
|
视角:当月吞吐 / 当前卡点 / 系统活跃度。
|
|
|
|
与 /dashboard 的区别:/dashboard 面向 PC 后台明细下钻(返回大列表),
|
|
/screen 只返回图表直接可用的扁平聚合数据,字段少、无分页、供高频轮询。
|
|
"""
|
|
from fastapi import APIRouter, Depends, Query
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
|
|
from app.core.database import get_db
|
|
from app.services.screen_service import (
|
|
get_monthly_metrics, MonthlyMetrics,
|
|
get_wip_distribution, WipDistributionResponse,
|
|
get_active_users, ActiveUsersResponse,
|
|
)
|
|
|
|
router = APIRouter(prefix="/screen", tags=["大屏统计"])
|
|
|
|
|
|
@router.get("/monthly-metrics", response_model=MonthlyMetrics)
|
|
async def monthly_metrics(db: AsyncSession = Depends(get_db)):
|
|
"""
|
|
当月吞吐 — 大屏顶部四张数字卡。
|
|
|
|
返回:本月生产流转 / 本月已入库 / 本月已出库 / 本月返厂回流。
|
|
统计区间为北京时间当月 1 日 00:00 至此刻。
|
|
"""
|
|
return await get_monthly_metrics(db)
|
|
|
|
|
|
@router.get("/wip-distribution", response_model=WipDistributionResponse)
|
|
async def wip_distribution(db: AsyncSession = Depends(get_db)):
|
|
"""
|
|
工序积压分布 — 当前未完结设备按 overall_status 聚合的**纯数量**。
|
|
|
|
返回固定阶段列表(含 0 值),保证柱状图类目稳定、不因缺数据而塌陷。
|
|
"""
|
|
return await get_wip_distribution(db)
|
|
|
|
|
|
@router.get("/active-users", response_model=ActiveUsersResponse)
|
|
async def active_users(
|
|
top_n: int = Query(5, ge=1, le=20, description="返回的活跃人员数量"),
|
|
db: AsyncSession = Depends(get_db),
|
|
):
|
|
"""
|
|
本月系统使用活跃度排行 — 接收 / 转交 / 上传备注次数。
|
|
|
|
桥接 /dashboard/user-operations 的统计口径,仅返回本月确实有操作的人员。
|
|
"""
|
|
return await get_active_users(db, top_n=top_n)
|