后端: - 修复登录校验、DB 并发(单例+WAL+纯Go sqlite)、会话密钥持久化等核心缺陷 - 新增 Timer CRUD/签到/手动触发、执行日志、仪表盘、驱动元数据等 API - 统一驱动接口: 带 context 的执行器、真实错误返回、敏感字段掩码、连通性测试 - 补全钉钉执行器; Timer 触发/提醒去重; 配置支持默认值与环境变量覆盖 前端: - Vite+Vue3+TS+Pinia+Element Plus, 由驱动元数据动态渲染配置表单 - 登录/仪表盘(倒计时环)/定时器/规则/账号/日志/设置页面, 支持暗色模式 - 主题色 #66ccff, 信号波纹 logo, go:embed 单二进制部署 构建: Dockerfile 增加前端构建阶段; 补充各驱动配置文档 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
81 lines
2.0 KiB
Go
81 lines
2.0 KiB
Go
// Package dashboard 汇总首页需要的统计数据
|
|
package dashboard
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/ssdomei232/goodBaby/api/response"
|
|
"github.com/ssdomei232/goodBaby/api/user"
|
|
"github.com/ssdomei232/goodBaby/handler/db"
|
|
"github.com/ssdomei232/goodBaby/model"
|
|
)
|
|
|
|
// HandleGetOverview 返回首页概览:各类对象数量、最紧急的 Timer、最近的执行日志
|
|
func HandleGetOverview(c *gin.Context) {
|
|
userInfo, err := user.GetUserInfoByGinCtx(c)
|
|
if err != nil {
|
|
response.Unauthorized(c, "获取用户信息失败")
|
|
return
|
|
}
|
|
|
|
gormDB, err := db.GetGormDB()
|
|
if err != nil {
|
|
response.ServerError(c, "服务器内部错误")
|
|
return
|
|
}
|
|
|
|
timers := []model.Timer{}
|
|
if err := gormDB.Where("uid = ?", userInfo.ID).Find(&timers).Error; err != nil {
|
|
response.ServerError(c, "获取统计数据失败")
|
|
return
|
|
}
|
|
|
|
var ruleCount, accountCount int64
|
|
gormDB.Model(&model.Rule{}).Where("uid = ?", userInfo.ID).Count(&ruleCount)
|
|
gormDB.Model(&model.Account{}).Where("uid = ?", userInfo.ID).Count(&accountCount)
|
|
|
|
recentLogs := []model.ExecutionLog{}
|
|
gormDB.Where("uid = ?", userInfo.ID).Order("id DESC").Limit(10).Find(&recentLogs)
|
|
|
|
now := time.Now().Unix()
|
|
var (
|
|
enabledCount int
|
|
triggeredCount int
|
|
urgent *model.Timer
|
|
)
|
|
|
|
for i := range timers {
|
|
timer := timers[i]
|
|
if !timer.Enabled {
|
|
continue
|
|
}
|
|
enabledCount++
|
|
if timer.Triggered {
|
|
triggeredCount++
|
|
continue
|
|
}
|
|
// 剩余时间最短的启用中 Timer
|
|
if urgent == nil || timer.NextSignTime() < urgent.NextSignTime() {
|
|
urgent = &timers[i]
|
|
}
|
|
}
|
|
|
|
overview := gin.H{
|
|
"timer_count": len(timers),
|
|
"enabled_timers": enabledCount,
|
|
"triggered_count": triggeredCount,
|
|
"rule_count": ruleCount,
|
|
"account_count": accountCount,
|
|
"server_time": now,
|
|
"recent_logs": recentLogs,
|
|
}
|
|
|
|
if urgent != nil {
|
|
overview["urgent_timer"] = urgent
|
|
overview["urgent_seconds_left"] = urgent.NextSignTime() - now
|
|
}
|
|
|
|
response.OK(c, overview)
|
|
}
|