fix: 3个逻辑/UI Bug修复

Bug1 — 任务总数与进度条不匹配:
  tasks_total 从全库历史总数改为 PENDING+WIP+COMPLETED(时段)+REJECTED(时段)
  确保进度条4段之和 = 显示的总数, 不再出现11≠9的缺口

Bug2 — 在制品排序混乱:
  移除DB层order_by, 改为Python统一按duration_hours降序
  无视status, 纯数值排序, 滞留最久排最前
  取limit*2条后在Python中排序再截断

Bug3 — 留言板产品显示割裂:
  [Tag:SN] 物料名 → 物料名 (SN: A1B2C3D4...)
  物料名加粗, SN等宽灰色, 阅读更顺畅
This commit is contained in:
2026-08-12 14:13:26 +08:00
parent 7906b8834a
commit c14bbeb891
2 changed files with 12 additions and 9 deletions

View File

@ -78,8 +78,7 @@ async def get_dashboard_stats(
p_progress = await db.scalar(select(func.count(Product.id)).where(Product.status == "in_progress"))
p_done = await db.scalar(select(func.count(Product.id)).where(Product.status == "completed"))
# ── 任务总数 & 实时快照PENDING/WIP/返工 — 永远不过滤) ──
t_total = await db.scalar(select(func.count(Task.id)))
# ── 任务实时快照PENDING/WIP/返工 — 永远不过滤) ──
t_pending = await db.scalar(select(func.count(Task.id)).where(Task.status == TASK_STATUS_PENDING))
t_progress = await db.scalar(select(func.count(Task.id)).where(Task.status == TASK_STATUS_WIP))
t_rework = await db.scalar(select(func.count(Task.id)).where(Task.is_rework.is_(True)))
@ -96,6 +95,9 @@ async def get_dashboard_stats(
t_done = await db.scalar(t_done_q)
t_rejected = await db.scalar(t_rej_q)
# ── 任务总数 = 实时快照段 + 时间过滤段(确保进度条段总和=总数) ──
t_total = (t_pending or 0) + (t_progress or 0) + (t_done or 0) + (t_rejected or 0)
# ── 通知 & 留言(实时快照) ──
unread_notif = await db.scalar(
select(func.count(Notification.id)).where(Notification.is_read.is_(False))
@ -131,8 +133,7 @@ async def get_wip_tasks(db: AsyncSession, limit: int = 20) -> list[WipTask]:
select(Task, Product.serial_number)
.join(Product, Task.product_id == Product.id)
.where(Task.status.in_([TASK_STATUS_PENDING, TASK_STATUS_WIP]))
.order_by(Task.received_at.asc().nulls_last(), Task.created_at.asc())
.limit(limit)
.limit(limit * 2) # 多取一些,后面 Python 统一排序
)
result = await db.execute(stmt)
rows = result.all()
@ -167,7 +168,9 @@ async def get_wip_tasks(db: AsyncSession, limit: int = 20) -> list[WipTask]:
received_at=recv_str,
duration_hours=hours,
))
return wip_list
# 统一按滞留时间降序排列(无视 status纯数值排序
wip_list.sort(key=lambda t: t.duration_hours, reverse=True)
return wip_list[:limit]
# ============================================================