Files
go-sms-V2/internal/model/entity/base.go
T

54 lines
2.0 KiB
Go

// Package entity GORM 实体模型(Day 11):与 scripts/init_schema.sql 一一对应。
// 命名:表名 <module>_<entity>;通用字段见 Model / SnowflakeModel。
package entity
import (
"time"
"gorm.io/gorm"
)
// Model 通用模型:自增主键 + 时间戳 + 软删除。
type Model struct {
ID int64 `gorm:"primaryKey;autoIncrement" json:"id"`
CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at"`
UpdatedAt time.Time `gorm:"autoUpdateTime" json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
}
// LogModel 日志/统计模型:自增主键 + 创建时间,无软删(高吞吐写入)。
type LogModel struct {
ID int64 `gorm:"primaryKey;autoIncrement" json:"id"`
CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at"`
}
// SnowflakeModel 雪花主键模型(message_detail 等全局唯一明细)。
type SnowflakeModel struct {
ID int64 `gorm:"primaryKey;autoIncrement:false" json:"id"`
CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at"`
}
// All 返回全部实体(AutoMigrate / schema 校验用),顺序与 init_schema.sql 一致。
func All() []any {
return []any{
// 账号体系(7)
&AccountUser{}, &AccountConfig{}, &AccountPrice{}, &AccountRole{},
&AccountPermission{}, &AccountRolePermission{}, &AccountBalanceLog{},
// 通道体系(7)
&ChannelChannel{}, &ChannelUpstream{}, &ChannelPrice{}, &ChannelGroup{},
&ChannelGroupItem{}, &ChannelBlockedCode{}, &ChannelLog{},
// 路由与策略(5)
&RouteRule{}, &PolicyBlacklist{}, &PolicyWhitelist{}, &PolicyKeyword{},
&PolicyFrequency{},
// 消息与审核(8)
&MessageTask{}, &MessageDetail{}, &MessageReport{}, &MessageUplink{},
&AuditRecord{}, &TemplateSMS{}, &SendBlockLog{}, &UplinkCode{},
// 计费与结算(5)
&BillingOrder{}, &BillingConsumeLog{}, &SettleCustomer{}, &SettleUpstream{},
&SettleRecord{},
// 统计与运维(8)
&StatsUserDaily{}, &StatsChannelDaily{}, &SystemConfig{}, &SystemAlertRule{},
&SystemLoginLog{}, &SystemOperateLog{}, &SystemErrorCode{}, &FeErrorLog{},
}
}