diff --git a/backend/routers/dashboard.py b/backend/routers/dashboard.py index f0e39f2..6a44921 100644 --- a/backend/routers/dashboard.py +++ b/backend/routers/dashboard.py @@ -34,7 +34,8 @@ def get_dashboard( today = date.today() month_start = today.replace(day=1) - # 本月人力成本(简化:统计本月所有有提交的人的日成本) + # 本月人力成本 = 提交人成本 + 管理层成本 + # 1. 提交人成本(统计本月所有有提交的人的日成本) monthly_submitters = db.query(Submission.user_id, Submission.submit_date).filter( Submission.submit_date >= month_start, Submission.submit_date <= today, @@ -50,6 +51,26 @@ def get_dashboard( if user: monthly_labor += user.daily_cost + # 2. 管理层成本(豁免提交角色的人) + from models import Role + exempt_role_ids = set( + r.id for r in db.query(Role).filter(Role.exempt_submission == 1).all() + ) + if exempt_role_ids: + exempt_users = db.query(User).filter( + User.is_active == 1, + User.monthly_salary > 0, + User.role_id.in_(exempt_role_ids), + ).all() + # 本月有提交记录的工作日数 + monthly_working_days = db.query(Submission.submit_date).filter( + Submission.submit_date >= month_start, + Submission.submit_date <= today, + ).distinct().count() + # 管理层成本 = 每人日薪 × 本月工作日数 + monthly_management = sum(u.daily_cost * monthly_working_days for u in exempt_users) + monthly_labor += monthly_management + # 本月 AI 工具成本 monthly_ai = db.query(sa_func.sum(AIToolCost.amount)).filter( AIToolCost.record_date >= month_start, @@ -237,7 +258,8 @@ def get_dashboard( Submission.submit_date == today, ).distinct().all() ) - submitted_users = [] + submitted_sufficient = [] # 提交且满8小时 + submitted_insufficient = [] # 提交但不足8小时 not_submitted_users = [] for u in all_active_users: info = {"id": u.id, "name": u.name} @@ -247,14 +269,19 @@ def get_dashboard( Submission.submit_date == today, ).scalar() or 0 info["hours"] = round(hours, 1) - submitted_users.append(info) + if hours >= 8: + submitted_sufficient.append(info) + else: + submitted_insufficient.append(info) else: not_submitted_users.append(info) daily_attendance = { "total": len(all_active_users), - "submitted_count": len(submitted_users), + "submitted_sufficient_count": len(submitted_sufficient), + "submitted_insufficient_count": len(submitted_insufficient), "not_submitted_count": len(not_submitted_users), - "submitted": submitted_users, + "submitted_sufficient": submitted_sufficient, + "submitted_insufficient": submitted_insufficient, "not_submitted": not_submitted_users, } diff --git a/backend/routers/submissions.py b/backend/routers/submissions.py index 74d24dc..638e6de 100644 --- a/backend/routers/submissions.py +++ b/backend/routers/submissions.py @@ -48,14 +48,13 @@ def list_submissions( current_user: User = Depends(get_current_user) ): q = db.query(Submission) - # 查看项目内提交时,所有人都可见(方便横向对比) - # 全局提交列表时,没有 user:view 权限只能看自己的 - if project_id: - pass # 项目内提交不做用户过滤 - elif not current_user.has_permission("user:view"): + # 权限检查:没有 user:view 权限只能看自己的 + if not current_user.has_permission("user:view"): q = q.filter(Submission.user_id == current_user.id) elif user_id: + # 有权限且指定了用户,过滤该用户 q = q.filter(Submission.user_id == user_id) + # 项目筛选 if project_id: q = q.filter(Submission.project_id == project_id) if start_date: diff --git a/frontend/src/views/Dashboard.vue b/frontend/src/views/Dashboard.vue index d068d1f..74fe09b 100644 --- a/frontend/src/views/Dashboard.vue +++ b/frontend/src/views/Dashboard.vue @@ -74,22 +74,29 @@ 今日提交情况