Files
junhong_cmp_fiber/internal/model/gateway_rate_limit.go
邹进 af8249158d
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 9m26s
feat: 停复机规则演练与终态自动关闭轮询
统一停复机规则转正的第一次发布:总开关仍关闭,现有停复机行为不变。

- 新增停复机规则演练:GET /stop-resume-rule/dry-run 按新规则对开机与停机卡只判断不执行,返回运营商账户 × 停机原因 × 判断结果汇总与分页明细,可假设通道实名管控配置;POST /stop-resume-rule/dry-run/export 导出明细(场景 stop_resume_rule_dry_run);仅超级管理员与平台账号
- 风险停机、已销户关闭轮询不再限于独立卡,只关该卡自身轮询,不级联设备
- 错误分类规则增加 auto_disable_polling,仅终态类别可勾选;停复机(含设备停复机)命中该规则时不重试、关闭该卡轮询、回写网关扩展状态并写审计 iot_card.terminal_disable_polling
- 迁移 000250 加列与约束,并为"已销户""仅支持风险复机"置位
2026-10-25 17:52:40 +09:00

75 lines
4.9 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package model
import (
"time"
"gorm.io/datatypes"
"gorm.io/gorm"
)
// CarrierRateLimitGroup 运营商账户网关限流组。
// CarrierID 为 nil 表示全局组;Operations、HighPriorityOperations 为卡网关操作字符串数组(JSON)。
type CarrierRateLimitGroup struct {
gorm.Model
BaseModel `gorm:"embedded"`
CarrierID *uint `gorm:"column:carrier_id;comment:运营商账户ID,为空表示全局组" json:"carrier_id"`
GroupCode string `gorm:"column:group_code;type:varchar(50);not null;comment:组标识" json:"group_code"`
GroupName string `gorm:"column:group_name;type:varchar(100);not null;comment:组名称" json:"group_name"`
MaxQPS int `gorm:"column:max_qps;not null;comment:每秒请求上限" json:"max_qps"`
Operations datatypes.JSON `gorm:"column:operations;type:jsonb;not null;comment:组内操作" json:"operations"`
HighPriorityOperations datatypes.JSON `gorm:"column:high_priority_operations;type:jsonb;not null;comment:高优先级操作" json:"high_priority_operations"`
ReservedQPS int `gorm:"column:reserved_qps;not null;default:0;comment:预留给高优先级操作的额度" json:"reserved_qps"`
Status int `gorm:"column:status;type:smallint;not null;default:1;comment:状态 0-停用 1-启用" json:"status"`
}
// TableName 返回限流组表名。
func (CarrierRateLimitGroup) TableName() string {
return "tb_carrier_rate_limit_group"
}
// GatewayErrorClassification 上游错误分类规则。
type GatewayErrorClassification struct {
gorm.Model
BaseModel `gorm:"embedded"`
Keyword string `gorm:"column:keyword;type:varchar(200);not null;comment:匹配关键字或正则" json:"keyword"`
MatchType string `gorm:"column:match_type;type:varchar(20);not null;default:contains;comment:匹配方式" json:"match_type"`
Category string `gorm:"column:category;type:varchar(30);not null;comment:类别" json:"category"`
Operations datatypes.JSON `gorm:"column:operations;type:jsonb;not null;comment:适用操作,空数组表示全部" json:"operations"`
Priority int `gorm:"column:priority;not null;default:100;comment:匹配优先级" json:"priority"`
MaybeAccepted bool `gorm:"column:maybe_accepted;not null;default:false;comment:上游可能已受理" json:"maybe_accepted"`
// AutoDisablePolling 命中后自动关闭该卡轮询,仅终态不可操作类别可置位。
AutoDisablePolling bool `gorm:"column:auto_disable_polling;not null;default:false;comment:命中后自动关闭该卡轮询" json:"auto_disable_polling"`
Status int `gorm:"column:status;type:smallint;not null;default:1;comment:状态 0-停用 1-启用" json:"status"`
Remark string `gorm:"column:remark;type:varchar(500);not null;default:'';comment:备注" json:"remark"`
}
// TableName 返回错误分类规则表名。
func (GatewayErrorClassification) TableName() string {
return "tb_gateway_error_classification"
}
// CardStopResumeRecord 停复机调用记录(按月分区表),每次实际调用上游停机或复机一条。
type CardStopResumeRecord struct {
ID uint `gorm:"column:id;primaryKey;autoIncrement" json:"id"`
CardID uint `gorm:"column:card_id;not null" json:"card_id"`
ICCID string `gorm:"column:iccid;type:varchar(30);not null;default:''" json:"iccid"`
CarrierID uint `gorm:"column:carrier_id;not null;default:0" json:"carrier_id"`
Action string `gorm:"column:action;type:varchar(10);not null" json:"action"`
Source string `gorm:"column:source;type:varchar(50);not null;default:''" json:"source"`
Scene string `gorm:"column:scene;type:varchar(50);not null;default:''" json:"scene"`
Reason string `gorm:"column:reason;type:varchar(50);not null;default:''" json:"reason"`
CommandID string `gorm:"column:command_id;type:varchar(64);not null;default:''" json:"command_id"`
Attempt int `gorm:"column:attempt;not null;default:1" json:"attempt"`
Result string `gorm:"column:result;type:varchar(20);not null" json:"result"`
ErrorCategory string `gorm:"column:error_category;type:varchar(30);not null;default:''" json:"error_category"`
ProviderCode string `gorm:"column:provider_code;type:varchar(30);not null;default:''" json:"provider_code"`
ProviderMessage string `gorm:"column:provider_message;type:varchar(500);not null;default:''" json:"provider_message"`
DurationMS int `gorm:"column:duration_ms;not null;default:0" json:"duration_ms"`
CreatedAt time.Time `gorm:"column:created_at;type:timestamptz;primaryKey;not null" json:"created_at"`
}
// TableName 返回停复机记录表名。
func (CardStopResumeRecord) TableName() string {
return "tb_card_stop_resume_record"
}