Files
junhong_cmp_fiber/internal/handler/admin/stop_resume_rule.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

82 lines
3.2 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 admin
import (
"github.com/go-playground/validator/v10"
"github.com/gofiber/fiber/v2"
"github.com/break/junhong_cmp_fiber/internal/handler/validation"
"github.com/break/junhong_cmp_fiber/internal/model/dto"
"github.com/break/junhong_cmp_fiber/internal/query/stopresumerule"
exportTaskService "github.com/break/junhong_cmp_fiber/internal/service/export_task"
"github.com/break/junhong_cmp_fiber/pkg/constants"
"github.com/break/junhong_cmp_fiber/pkg/errors"
"github.com/break/junhong_cmp_fiber/pkg/middleware"
"github.com/break/junhong_cmp_fiber/pkg/response"
)
// StopResumeRuleHandler 停复机规则演练 Handler:只判断不执行,仅超级管理员与平台账号可用。
type StopResumeRuleHandler struct {
query *stopresumerule.Query
exportService *exportTaskService.Service
validator *validator.Validate
}
// NewStopResumeRuleHandler 创建停复机规则演练 Handler。
func NewStopResumeRuleHandler(query *stopresumerule.Query, exportService *exportTaskService.Service, validator *validator.Validate) *StopResumeRuleHandler {
return &StopResumeRuleHandler{query: query, exportService: exportService, validator: validator}
}
// DryRun 执行停复机规则演练。
// GET /api/admin/stop-resume-rule/dry-run
func (h *StopResumeRuleHandler) DryRun(c *fiber.Ctx) error {
var req dto.StopResumeRuleDryRunRequest
if err := c.QueryParser(&req); err != nil {
return errors.New(errors.CodeInvalidParam, "请求参数格式不正确")
}
if err := h.validator.Struct(&req); err != nil {
return errors.New(errors.CodeInvalidParam, validation.Message("停复机规则演练参数不正确", &req, err))
}
result, err := h.query.DryRun(c.UserContext(), &req)
if err != nil {
return err
}
return response.Success(c, result)
}
// Export 创建停复机规则演练明细异步导出任务。
// POST /api/admin/stop-resume-rule/dry-run/export
func (h *StopResumeRuleHandler) Export(c *fiber.Ctx) error {
if err := stopresumerule.EnsureAllowed(middleware.GetUserTypeFromContext(c.UserContext())); err != nil {
return err
}
var req dto.StopResumeRuleDryRunExportRequest
if err := c.BodyParser(&req); err != nil {
return errors.New(errors.CodeInvalidParam, "请求参数格式不正确")
}
if err := h.validator.Struct(&req); err != nil {
return errors.New(errors.CodeInvalidParam, validation.Message("停复机规则演练导出参数不正确", &req, err))
}
// 创建期校验筛选,避免任务执行时才因参数非法失败。
if _, err := stopresumerule.BuildFilter(req.CarrierID, req.StopReason, req.AssumeControlOn, req.AssumeControlOff); err != nil {
return err
}
format := req.Format
if format == "" {
format = constants.ExportTaskFormatXLSX
}
filters := map[string]interface{}{
"stop_reason": req.StopReason, "assume_control_on": req.AssumeControlOn, "assume_control_off": req.AssumeControlOff,
}
if req.CarrierID != nil {
filters["carrier_id"] = *req.CarrierID
}
result, err := h.exportService.CreateTask(c.UserContext(), &dto.CreateExportTaskRequest{
Scene: constants.ExportTaskSceneStopResumeRuleDryRun, Format: format,
Query: map[string]interface{}{"filters": filters},
})
if err != nil {
return err
}
return response.Success(c, result)
}