Files

129 lines
6.9 KiB
Go

package entity
import "time"
// ChannelChannel 短信通道。
type ChannelChannel struct {
Model
Name string `gorm:"size:64" json:"name"`
Code string `gorm:"size:32;uniqueIndex:uk_channel_code" json:"code"`
Protocol string `gorm:"size:16;index:idx_protocol_status,priority:1" json:"protocol"` // cmpp/http/sgip/smpp
UpstreamID int64 `gorm:"index:idx_upstream" json:"upstream_id"`
Host string `gorm:"size:128" json:"host"`
Port int `json:"port"`
Username string `gorm:"size:64" json:"username"`
Password string `gorm:"size:128" json:"-"`
ConnCount int `gorm:"default:1" json:"conn_count"`
Speed int `json:"speed"`
ExtLength int8 `json:"ext_length"`
SignMode int8 `json:"sign_mode"`
Priority int `json:"priority"`
Weight int `gorm:"default:1" json:"weight"`
IsDefault int8 `json:"is_default"`
DayLimit int `json:"day_limit"`
NightLimit int `json:"night_limit"`
BlackKeywords string `gorm:"size:512" json:"black_keywords"`
BlockRegions string `gorm:"size:512" json:"block_regions"`
TemplateMode int8 `json:"template_mode"` // 上游模板ID模式({%var%})
Status int8 `gorm:"index:idx_protocol_status,priority:2;default:1" json:"status"`
Remark string `gorm:"size:255" json:"remark"`
// ---- 协议接入参数(Day 31:测试工具/连接池消费) ----
SpID string `gorm:"size:6" json:"sp_id"` // 企业代码(CMPP SourceAddr ≤6B/SGIP CorpID;空回退 username 兼容历史)
ProtocolVersion int8 `gorm:"default:20" json:"protocol_version"` // cmpp:20|30(3.0 未实现) sgip:12 smpp:34
HeartbeatInterval int `gorm:"default:30" json:"heartbeat_interval"` // 心跳周期(秒;cmpp active_test/smpp enquire_link)
ReconnectMax int `gorm:"default:30" json:"reconnect_max"` // 重连退避上限(秒)
ServiceID string `gorm:"size:16" json:"service_id"` // 服务代码(CMPP ServiceID ≤10B;空用 TEST)
// ---- 运营属性(Day 31:表单存储/回显;账务阶段消费) ----
Carrier string `gorm:"size:24" json:"carrier"` // 运营商(逗号分隔 cmcc,cucc,ctcc)
BillingLength int `gorm:"default:70" json:"billing_length"` // 计费长度(字/条)
PaymentType string `gorm:"size:16" json:"payment_type"` // 付款方式 prepay_monthly/postpaid_monthly/prepay_realtime
BillingMode string `gorm:"size:16" json:"billing_mode"` // 计费方式 success_unknown/success/all
Price float64 `gorm:"type:decimal(10,4)" json:"price"` // 通道价格(元/条)
Category string `gorm:"size:32" json:"category"` // 通道分类(自由文本)
MOForwardChannelID int64 `gorm:"default:0" json:"mo_forward_channel_id"` // 上行组合通道(0=不转发)
NumberRule int8 `gorm:"default:0" json:"number_rule"` // 号码组装规则 0通道号+签名扩展+用户扩展+自定义 1通道号+签名扩展+用户扩展 2通道号+用户扩展 3仅通道号
CodeTruncate int8 `json:"code_truncate"` // 通道号截断位数(0=不截断)
ExtParams string `gorm:"size:255" json:"ext_params"` // 扩展参数(自定义 KV)
ServiceRemark string `gorm:"size:255" json:"service_remark"` // 客服备注
}
func (ChannelChannel) TableName() string { return "channel_channel" }
// ChannelUpstream 上家(通道方)。
type ChannelUpstream struct {
Model
Name string `gorm:"size:64" json:"name"`
Contact string `gorm:"size:64" json:"contact"`
Phone string `gorm:"size:32" json:"phone"`
Category string `gorm:"size:32" json:"category"`
Status int8 `gorm:"default:1" json:"status"`
Remark string `gorm:"size:255" json:"remark"`
}
func (ChannelUpstream) TableName() string { return "channel_upstream" }
// ChannelPrice 通道分时成本价。
type ChannelPrice struct {
ID int64 `gorm:"primaryKey;autoIncrement" json:"id"`
ChannelID int64 `gorm:"index:idx_channel_time,priority:1" json:"channel_id"`
Price float64 `gorm:"type:decimal(10,4)" json:"price"`
EffectiveAt time.Time `gorm:"index:idx_channel_time,priority:2" json:"effective_at"`
CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at"`
}
func (ChannelPrice) TableName() string { return "channel_price" }
// ChannelGroup 通道组(四步路由容器)。
type ChannelGroup struct {
Model
Name string `gorm:"size:64" json:"name"`
Remark string `gorm:"size:255" json:"remark"`
Status int8 `gorm:"default:1" json:"status"`
}
func (ChannelGroup) TableName() string { return "channel_group" }
// ChannelGroupItem 通道组成员(路由步骤参数)。
type ChannelGroupItem struct {
ID int64 `gorm:"primaryKey;autoIncrement" json:"id"`
GroupID int64 `gorm:"uniqueIndex:uk_group_channel,priority:1" json:"group_id"`
ChannelID int64 `gorm:"uniqueIndex:uk_group_channel,priority:2;index:idx_channel" json:"channel_id"`
Step int8 `gorm:"default:3" json:"step"` // 1过滤 2优先 3权重 4兜底
Priority int `json:"priority"`
Weight int `gorm:"default:1" json:"weight"`
Region string `gorm:"size:32" json:"region"`
Carrier string `gorm:"size:16" json:"carrier"`
Keyword string `gorm:"size:128" json:"keyword"`
}
func (ChannelGroupItem) TableName() string { return "channel_group_item" }
// ChannelBlockedCode 屏蔽码号(按通道+码号直接拦截)。
type ChannelBlockedCode struct {
ID int64 `gorm:"primaryKey;autoIncrement" json:"id"`
ChannelID int64 `gorm:"uniqueIndex:uk_channel_code,priority:1" json:"channel_id"`
Code string `gorm:"size:64;uniqueIndex:uk_channel_code,priority:2" json:"code"`
Remark string `gorm:"size:255" json:"remark"`
CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at"`
}
func (ChannelBlockedCode) TableName() string { return "channel_blocked_code" }
// ChannelLog 通道日志(A-3.14,Day 40):连接事件逐条;提交/回执按窗口聚合
// (防 3000 TPS 下逐条 INSERT 打爆 MySQL——Day 39.6 容量规划口径,落库走异步批量)。
type ChannelLog struct {
Model
ChannelID int64 `gorm:"index:idx_clog_channel,priority:1" json:"channel_id"`
Kind string `gorm:"size:16;index:idx_clog_kind" json:"kind"` // connect|disconnect|stop|submit|submit_fail|deliver|deliver_fail|alert
Level int8 `gorm:"default:0" json:"level"` // 0=info 1=warn 2=error
MsgID string `gorm:"size:32" json:"msg_id,omitempty"`
Detail string `gorm:"size:512" json:"detail,omitempty"`
Count int `gorm:"default:1" json:"count"` // 聚合行:窗口内条数(逐条=1)
FailCount int `gorm:"default:0" json:"fail_count"` // 聚合行:窗口内失败数
LatencyMs int `gorm:"default:0" json:"latency_ms"` // 聚合行:窗口均值(逐条=本次)
}
func (ChannelLog) TableName() string { return "channel_log" }