feat(supervisor): add reminder settings and rate-limited logs

This commit is contained in:
nepiedg
2026-04-16 13:37:06 +08:00
parent 50352d67ca
commit f701feebe8
7 changed files with 552 additions and 0 deletions
@@ -0,0 +1,37 @@
package model
import (
"time"
"gorm.io/gorm"
)
// SupervisorReminderLog 记录一次提醒尝试,用于:
// - 频控:按天限制每个 (owner, supervisor) 的提醒次数
// - 追踪:后续接入真实通道(订阅消息)时可落库 status/result
type SupervisorReminderLog struct {
ID uint `gorm:"primaryKey;comment:主键" json:"id"`
CreatedAt time.Time `gorm:"comment:创建时间" json:"created_at"`
UpdatedAt time.Time `gorm:"comment:更新时间" json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index;comment:删除时间" json:"-"`
OwnerUID int `gorm:"column:owner_uid;index:idx_owner_supervisor_date,priority:1;comment:被监督用户ID" json:"owner_uid"`
SupervisorUID int `gorm:"column:supervisor_uid;index:idx_owner_supervisor_date,priority:2;comment:监督人用户ID" json:"supervisor_uid"`
ReminderDate time.Time `gorm:"column:reminder_date;type:date;index:idx_owner_supervisor_date,priority:3;comment:所属自然日" json:"reminder_date"`
ReminderAt time.Time `gorm:"column:reminder_at;comment:提醒时间" json:"reminder_at"`
Type string `gorm:"column:type;size:32;index;comment:提醒类型(missed_checkin...)" json:"type"`
Status string `gorm:"column:status;size:16;index;comment:状态(stubbed|sent|failed)" json:"status"`
Channel string `gorm:"column:channel;size:32;comment:通道(stub|subscribe_msg...)" json:"channel"`
Message string `gorm:"column:message;type:text;comment:提醒内容(可选)" json:"message,omitempty"`
}
func (SupervisorReminderLog) TableName() string {
return "fa_quit_checkin_supervisor_reminder_log"
}
func (SupervisorReminderLog) TableComment() string {
return "V2-无烟打卡-监督提醒记录"
}
@@ -0,0 +1,31 @@
package model
import (
"time"
"gorm.io/gorm"
)
// SupervisorReminderSetting 表示“被监督用户(owner)”对提醒机制的配置。
// 注意:提醒本质是隐私相关能力,默认应为关闭,需 owner 显式开启。
type SupervisorReminderSetting struct {
ID uint `gorm:"primaryKey;comment:主键" json:"id"`
CreatedAt time.Time `gorm:"comment:创建时间" json:"created_at"`
UpdatedAt time.Time `gorm:"comment:更新时间" json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index;comment:删除时间" json:"-"`
OwnerUID int `gorm:"column:owner_uid;uniqueIndex;comment:被监督用户ID" json:"owner_uid"`
Enabled bool `gorm:"column:enabled;comment:是否启用提醒" json:"enabled"`
NotifyTime string `gorm:"column:notify_time;size:5;comment:提醒时间(HH:MM)" json:"notify_time"`
MaxPerDay int `gorm:"column:max_per_day;comment:每日最多提醒次数(每个监督人)" json:"max_per_day"`
ChannelHint string `gorm:"column:channel_hint;size:32;comment:提醒通道提示(stub|subscribe_msg...)" json:"channel_hint,omitempty"`
}
func (SupervisorReminderSetting) TableName() string {
return "fa_quit_checkin_supervisor_reminder_setting"
}
func (SupervisorReminderSetting) TableComment() string {
return "V2-无烟打卡-监督提醒设置"
}