feat: 停复机规则演练与终态自动关闭轮询
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 9m26s
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 9m26s
统一停复机规则转正的第一次发布:总开关仍关闭,现有停复机行为不变。 - 新增停复机规则演练: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 加列与约束,并为"已销户""仅支持风险复机"置位
This commit is contained in:
@@ -41,6 +41,7 @@ func NewDefaultRegistry(db *gorm.DB) *Registry {
|
||||
NewExpiringAssetDataSource(db),
|
||||
NewOperationsActivationDataSource(db),
|
||||
NewOperationsRenewalDataSource(db),
|
||||
NewStopResumeRuleDataSource(db),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -81,7 +82,8 @@ func IsSupportedScene(scene string) bool {
|
||||
constants.ExportTaskScenePackageTrafficAlert,
|
||||
constants.ExportTaskSceneExpiringAsset,
|
||||
constants.ExportTaskSceneOperationsActivation,
|
||||
constants.ExportTaskSceneOperationsRenewal:
|
||||
constants.ExportTaskSceneOperationsRenewal,
|
||||
constants.ExportTaskSceneStopResumeRuleDryRun:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
|
||||
98
internal/exporter/stop_resume_rule_scene.go
Normal file
98
internal/exporter/stop_resume_rule_scene.go
Normal file
@@ -0,0 +1,98 @@
|
||||
package exporter
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
|
||||
"gorm.io/gorm"
|
||||
|
||||
"github.com/break/junhong_cmp_fiber/internal/query/stopresumerule"
|
||||
"github.com/break/junhong_cmp_fiber/pkg/constants"
|
||||
)
|
||||
|
||||
// stopResumeRuleHeaders 停复机规则演练导出表头。
|
||||
var stopResumeRuleHeaders = []string{
|
||||
"卡ID", "ICCID", "运营商账户ID", "运营商账户", "绑定设备ID", "当前网络状态", "当前停机原因", "卡类别",
|
||||
"满足实名条件", "判断结果", "原因",
|
||||
}
|
||||
|
||||
// StopResumeRuleDataSource 停复机规则演练明细导出数据源:按卡 ID 升序分页取卡并逐张按新规则判断,只读。
|
||||
// 仅超级管理员与平台账号可导出:受控入口已做角色门禁,这里再按任务内冻结的账号类型复核一次。
|
||||
type StopResumeRuleDataSource struct {
|
||||
query *stopresumerule.Query
|
||||
}
|
||||
|
||||
// NewStopResumeRuleDataSource 创建停复机规则演练导出数据源。
|
||||
func NewStopResumeRuleDataSource(db *gorm.DB) *StopResumeRuleDataSource {
|
||||
return &StopResumeRuleDataSource{query: stopresumerule.NewQuery(db)}
|
||||
}
|
||||
|
||||
// Scene 返回导出场景编码。
|
||||
func (s *StopResumeRuleDataSource) Scene() string {
|
||||
return constants.ExportTaskSceneStopResumeRuleDryRun
|
||||
}
|
||||
|
||||
// Count 统计参与演练的卡数。
|
||||
func (s *StopResumeRuleDataSource) Count(ctx context.Context, params ExportParams) (int, error) {
|
||||
filter, err := s.filter(params)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
total, err := s.query.Count(ctx, filter)
|
||||
return int(total), err
|
||||
}
|
||||
|
||||
// Headers 返回导出表头。
|
||||
func (s *StopResumeRuleDataSource) Headers(ctx context.Context, params ExportParams) ([]string, error) {
|
||||
if err := stopresumerule.EnsureAllowed(params.UserType); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return stopResumeRuleHeaders, nil
|
||||
}
|
||||
|
||||
// Fetch 按 offset/limit 返回演练明细行。
|
||||
func (s *StopResumeRuleDataSource) Fetch(ctx context.Context, params ExportParams, offset, limit int) ([][]string, error) {
|
||||
filter, err := s.filter(params)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
rows, err := s.query.Page(ctx, filter, offset, limit)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result := make([][]string, 0, len(rows))
|
||||
for index := range rows {
|
||||
item := stopresumerule.ToItem(&rows[index])
|
||||
network := "停机"
|
||||
if item.NetworkStatus == constants.NetworkStatusOnline {
|
||||
network = "开机"
|
||||
}
|
||||
device := ""
|
||||
if item.DeviceID != 0 {
|
||||
device = strconv.FormatUint(uint64(item.DeviceID), 10)
|
||||
}
|
||||
realname := "否"
|
||||
if item.RealnameOK {
|
||||
realname = "是"
|
||||
}
|
||||
result = append(result, []string{
|
||||
strconv.FormatUint(uint64(item.CardID), 10), item.ICCID, strconv.FormatUint(uint64(item.CarrierID), 10),
|
||||
item.CarrierName, device, network, item.StopReasonName, item.CardCategory, realname, item.ResultName, item.ReasonName,
|
||||
})
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (s *StopResumeRuleDataSource) filter(params ExportParams) (stopresumerule.Filter, error) {
|
||||
if err := stopresumerule.EnsureAllowed(params.UserType); err != nil {
|
||||
return stopresumerule.Filter{}, err
|
||||
}
|
||||
var carrierID *uint
|
||||
if id, ok := filterUint(params.Filters, "carrier_id"); ok && id > 0 {
|
||||
carrierID = &id
|
||||
}
|
||||
stopReason, _ := filterString(params.Filters, "stop_reason")
|
||||
on, _ := filterString(params.Filters, "assume_control_on")
|
||||
off, _ := filterString(params.Filters, "assume_control_off")
|
||||
return stopresumerule.BuildFilter(carrierID, stopReason, on, off)
|
||||
}
|
||||
Reference in New Issue
Block a user