feat: add notify icon read

This commit is contained in:
engigu
2026-03-09 18:10:23 +08:00
parent e7da316c90
commit 77cf12c9b6
46 changed files with 1347 additions and 252 deletions
+23
View File
@@ -0,0 +1,23 @@
package models
import (
"github.com/engigu/baihu-panel/internal/constant"
)
// AppLog 统一应用日志与通知记录
type AppLog struct {
ID string `json:"id" gorm:"primaryKey;size:20"`
Category string `json:"category" gorm:"size:50;index;not null"` // 大类:constant.LogCategorySystemNotice(系统通知), constant.LogCategoryPushLog(推送记录) 等
Title string `json:"title" gorm:"size:255"` // 消息标题
Content BigText `json:"content"` // 详细内容/Payload
Level string `json:"level" gorm:"size:20;index"` // 级别:constant.LogLevelInfo, constant.LogLevelWarning, constant.LogLevelError
Status string `json:"status" gorm:"size:20;index"` // 状态:系统通知为 constant.LogStatusRead/constant.LogStatusUnread,推送为 constant.LogStatusSuccess/constant.LogStatusFailed
RefID string `json:"ref_id" gorm:"size:50;index"` // 关联对象ID(选填,比如绑定的通知渠道ID、任务ID等)
ErrorMsg BigText `json:"error_msg"` // 执行错误信息详情
CreatedAt LocalTime `json:"created_at" gorm:"index"`
ReadAt *LocalTime `json:"read_at"` // 已读时间(仅对通知生效)
}
func (AppLog) TableName() string {
return constant.TablePrefix + "app_logs"
}
+24
View File
@@ -0,0 +1,24 @@
package models
import (
"gorm.io/gorm"
"gorm.io/gorm/schema"
)
// BigText 自定义大数据文本类型,自动处理跨数据库类型差异
// MySQL: LONGTEXT (4GB)
// PostgreSQL: TEXT
// SQLite: TEXT
type BigText string
func (BigText) GormDBDataType(db *gorm.DB, field *schema.Field) string {
switch db.Dialector.Name() {
case "mysql":
return "LONGTEXT"
case "postgres":
return "TEXT"
case "sqlite":
return "TEXT"
}
return "TEXT"
}
+1 -1
View File
@@ -14,7 +14,7 @@ type Dependency struct {
Language string `json:"language" gorm:"size:100;index"` // 关联语言 (node, python...)
LangVersion string `json:"lang_version" gorm:"size:100;index"` // 关联语言版本
Remark string `json:"remark" gorm:"size:255"`
Log string `json:"log" gorm:"type:text"`
Log BigText `json:"log"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
+2 -2
View File
@@ -10,7 +10,7 @@ import (
type EnvironmentVariable struct {
ID string `json:"id" gorm:"primaryKey;size:20"`
Name string `json:"name" gorm:"size:255;not null"`
Value string `json:"value" gorm:"type:text"`
Value BigText `json:"value"`
Remark string `json:"remark" gorm:"size:500"`
Hidden bool `json:"hidden" gorm:"default:true"`
UserID string `json:"user_id" gorm:"size:20;index"`
@@ -27,7 +27,7 @@ func (EnvironmentVariable) TableName() string {
type Script struct {
ID string `json:"id" gorm:"primaryKey;size:20"`
Name string `json:"name" gorm:"size:255;not null"`
Content string `json:"content" gorm:"type:text"`
Content BigText `json:"content"`
UserID string `json:"user_id" gorm:"size:20;index"`
CreatedAt LocalTime `json:"created_at"`
UpdatedAt LocalTime `json:"updated_at"`
+1 -1
View File
@@ -11,7 +11,7 @@ type NotifyWay struct {
ID string `json:"id" gorm:"primaryKey;size:20"`
Name string `json:"name" gorm:"size:100;not null"`
Type string `json:"type" gorm:"size:50;not null;index"`
Config string `json:"config" gorm:"type:text"`
Config BigText `json:"config"`
Enabled bool `json:"enabled" gorm:"default:true;index"`
CreatedAt LocalTime `json:"created_at"`
UpdatedAt LocalTime `json:"updated_at"`
+1 -1
View File
@@ -9,7 +9,7 @@ type Setting struct {
ID string `json:"id" gorm:"primaryKey;size:20"`
Section string `json:"section" gorm:"size:50;not null;index:idx_section_key"`
Key string `json:"key" gorm:"size:100;not null;index:idx_section_key"`
Value string `json:"value" gorm:"type:text"`
Value BigText `json:"value"`
}
func (Setting) TableName() string {
+10 -10
View File
@@ -35,23 +35,23 @@ type TaskConfig struct {
type Task struct {
ID string `json:"id" gorm:"primaryKey;size:20"`
Name string `json:"name" gorm:"size:255;not null"`
Command string `json:"command" gorm:"type:text"` // 普通任务的命令
Command BigText `json:"command"` // 普通任务的命令
Tags string `json:"tags" gorm:"size:255;default:''"` // 标签,逗号分隔
Type string `json:"type" gorm:"size:20;default:'task'"` // 任务类型: constant.TaskTypeNormal, constant.TaskTypeRepo
TriggerType string `json:"trigger_type" gorm:"size:25;default:'cron'"` // 触发类型: constant.TriggerTypeCron, constant.TriggerTypeBaihuStartup
Config string `json:"config" gorm:"type:text"` // 配置 JSON(仓库同步配置等)
Config BigText `json:"config"` // 配置 JSON(仓库同步配置等)
Schedule string `json:"schedule" gorm:"size:100"` // cron 表达式
Timeout int `json:"timeout" gorm:"default:30"` // 超时时间(分钟),默认30分钟
WorkDir string `json:"work_dir" gorm:"size:255;default:''"` // 工作目录,为空则使用 scripts 目录
CleanConfig string `json:"clean_config" gorm:"size:255;default:''"` // 清理配置 JSON
Envs string `json:"envs" gorm:"type:text"` // 环境变量ID列表,逗号分隔
Languages []map[string]string `json:"languages" gorm:"serializer:json;type:text"` // 针对本地任务的语言配置列表
Envs BigText `json:"envs"` // 环境变量ID列表,逗号分隔
Languages []map[string]string `json:"languages" gorm:"serializer:json"` // 针对本地任务的语言配置列表
AgentID *string `json:"agent_id" gorm:"size:20;index"` // Agent ID,为空表示本地执行
RetryCount int `json:"retry_count" gorm:"default:0"` // 失败重试次数
RetryInterval int `json:"retry_interval" gorm:"default:0"` // 失败重试间隔(秒)
RandomRange int `json:"random_range" gorm:"default:0"` // 随机延迟范围(秒)
Enabled bool `json:"enabled" gorm:"default:true"`
RunningGo string `json:"running_go" gorm:"type:text"` // 正在运行的 go routine id 数组 (JSON)
RunningGo BigText `json:"running_go"` // 正在运行的 go routine id 数组 (JSON)
RuntimeEnvs []string `json:"-" gorm:"-"` // 运行时环境变量(非持久化)
LastRun *LocalTime `json:"last_run"`
NextRun *LocalTime `json:"next_run"`
@@ -73,7 +73,7 @@ func (t *Task) GetName() string {
}
func (t *Task) GetCommand() string {
return t.Command
return string(t.Command)
}
func (t *Task) GetTimeout() int {
@@ -85,7 +85,7 @@ func (t *Task) GetWorkDir() string {
}
func (t *Task) GetEnvs() string {
return t.Envs
return string(t.Envs)
}
func (t *Task) GetLanguages() []map[string]string {
@@ -117,9 +117,9 @@ type TaskLog struct {
ID string `json:"id" gorm:"primaryKey;size:20"`
TaskID string `json:"task_id" gorm:"size:20;index"`
AgentID *string `json:"agent_id" gorm:"size:20;index"` // Agent ID,为空表示本地执行
Command string `json:"command" gorm:"type:text"`
Output string `json:"-" gorm:"type:text"` // gzip+base64 压缩后的日志
Error string `json:"error" gorm:"type:text"` // 额外的系统错误信息
Command BigText `json:"command"`
Output BigText `json:"-"` // gzip+base64 压缩后的日志
Error BigText `json:"error"` // 额外的系统错误信息
Status string `json:"status" gorm:"size:20;index"` // success, failed
Duration int64 `json:"duration"` // 执行耗时(毫秒)
ExitCode int `json:"exit_code"`
+1 -1
View File
@@ -31,7 +31,7 @@ func ToDependencyVO(dep *models.Dependency) *DependencyVO {
Language: dep.Language,
LangVersion: dep.LangVersion,
Remark: dep.Remark,
Log: dep.Log,
Log: string(dep.Log),
CreatedAt: dep.CreatedAt,
UpdatedAt: dep.UpdatedAt,
}
+1 -1
View File
@@ -21,7 +21,7 @@ func ToScriptVO(script *models.Script) *ScriptVO {
return &ScriptVO{
ID: script.ID,
Name: script.Name,
Content: script.Content,
Content: string(script.Content),
CreatedAt: script.CreatedAt,
UpdatedAt: script.UpdatedAt,
}
+1 -1
View File
@@ -48,7 +48,7 @@ func ToEnvVO(env *models.EnvironmentVariable) *EnvVO {
return &EnvVO{
ID: env.ID,
Name: env.Name,
Value: env.Value,
Value: string(env.Value),
Remark: env.Remark,
Hidden: env.Hidden,
CreatedAt: env.CreatedAt,
+6 -6
View File
@@ -39,16 +39,16 @@ func ToTaskVO(task *models.Task) *TaskVO {
return &TaskVO{
ID: task.ID,
Name: task.Name,
Command: task.Command,
Command: string(task.Command),
Tags: task.Tags,
Type: task.Type,
TriggerType: task.TriggerType,
Config: task.Config,
Config: string(task.Config),
Schedule: task.Schedule,
Timeout: task.Timeout,
WorkDir: task.WorkDir,
CleanConfig: task.CleanConfig,
Envs: task.Envs,
Envs: string(task.Envs),
Languages: task.Languages,
AgentID: task.AgentID,
Enabled: task.Enabled,
@@ -112,15 +112,15 @@ func ToTaskLogVO(log *models.TaskLog) *TaskLogVO {
ID: log.ID,
TaskID: log.TaskID,
AgentID: log.AgentID,
Command: log.Command,
Error: log.Error,
Command: string(log.Command),
Error: string(log.Error),
Status: log.Status,
Duration: log.Duration,
ExitCode: log.ExitCode,
StartTime: log.StartTime,
EndTime: log.EndTime,
CreatedAt: log.CreatedAt,
Output: log.Output,
Output: string(log.Output),
}
}