25 lines
1.2 KiB
Go
25 lines
1.2 KiB
Go
package projects
|
||
|
||
import "senlinai-agent/backend/internal/models"
|
||
|
||
// Dashboard 保留旧概览查询给尚未迁移的 handler;所有统计仍严格限定项目所有者。
|
||
func (s *Service) Dashboard(ownerID uint, projectID uint) (Dashboard, error) {
|
||
if err := ensureProjectOwner(ownerID, projectID); err != nil {
|
||
return Dashboard{}, err
|
||
}
|
||
dashboard := Dashboard{ProjectID: projectID}
|
||
if err := models.DBService.Model(&models.SenlinAgentInboxItem{}).Where("project_id = ? AND status = ?", projectID, "open").Count(&dashboard.PendingInboxCount).Error; err != nil {
|
||
return dashboard, err
|
||
}
|
||
if err := models.DBService.Model(&models.SenlinAgentTask{}).Where("project_id = ? AND status <> ?", projectID, "done").Count(&dashboard.OpenTaskCount).Error; err != nil {
|
||
return dashboard, err
|
||
}
|
||
if err := models.DBService.Model(&models.SenlinAgentNote{}).Where("project_id = ?", projectID).Count(&dashboard.RecentNoteCount).Error; err != nil {
|
||
return dashboard, err
|
||
}
|
||
if err := models.DBService.Model(&models.SenlinAgentAISession{}).Where("project_id = ?", projectID).Count(&dashboard.RecentSessionCount).Error; err != nil {
|
||
return dashboard, err
|
||
}
|
||
return dashboard, nil
|
||
}
|