- server/users.ts GET /:id:
· total_hours 原先是标量子查询(独立的 SELECT SUM FROM hours),
活动列表是 JOIN activities 后查出来的——两者在某些边界下可能
数据源不一致(FK pragma 状态、活动被删但 hours 残留时标量子
查询会多算 1 次,卡片显示 11h 而列表只有 7h 就是这个问题)
· 改为直接用 activities 列表查询结果 reduce 求和后赋值给
user.total_hours,保证两个数字来自完全同一份数据
- client/Users.tsx 部员详情参与活动表:
· 表底部新增一条粘性合计行:bg-primary-50/60 + 边框,左边小字
『本页列表合计(应等于上方卡片的累计时长)』,右边大号加粗
主题色数字实时显示 reduce 求和
· 溢出容器 overflow-hidden,合计行与 DataTable 边框完美贴合无缝
This commit is contained in:
@@ -82,6 +82,8 @@ router.get('/:id', (req: Request, res: Response) => {
|
||||
WHERE h.user_id = ?
|
||||
ORDER BY h.created_at DESC, a.start_time DESC
|
||||
`).all(id);
|
||||
const listSum = activities.reduce((s, r) => s + Number(r.hours || 0), 0);
|
||||
user.total_hours = Number(listSum.toFixed(1));
|
||||
res.json({ ...user, activities });
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user