相关问题优化以及新功能开发
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 7m57s

迁移 155- 157
This commit is contained in:
2026-06-22 17:21:13 +09:00
parent 2885b503b3
commit 5c2ef97c24
45 changed files with 1201 additions and 82 deletions

View File

@@ -9,11 +9,23 @@ import (
"go.uber.org/zap"
"github.com/break/junhong_cmp_fiber/internal/gateway"
"github.com/break/junhong_cmp_fiber/internal/model"
iot_card_svc "github.com/break/junhong_cmp_fiber/internal/service/iot_card"
"github.com/break/junhong_cmp_fiber/internal/store/postgres"
"github.com/break/junhong_cmp_fiber/pkg/constants"
)
// shouldStopPollingForRisk 判断轮询到风险 gateway_extend 时是否应停止该卡的轮询
// 仅独立卡is_standalone=true命中风险状态时才停止绑定设备的卡不受此逻辑约束
func shouldStopPollingForRisk(card *model.IotCard, newGatewayExtend string) bool {
if !card.IsStandalone {
return false
}
extend := strings.TrimSpace(newGatewayExtend)
return extend == constants.GatewayCardExtendRiskStop ||
extend == constants.GatewayCardExtendCancelled
}
// PollingCardStatusHandler 卡开停机状态轮询任务处理器
// 职责:调 Gateway 查卡状态(正常/停机/准备)→ 映射为 network_status → 写 DB → 触发停复机评估
// 不做:直接停复机决策,委托给 StopResumeService.EvaluateAndAct
@@ -141,6 +153,19 @@ func (h *PollingCardStatusHandler) Handle(ctx context.Context, t *asynq.Task) er
h.base.updateCardCache(ctx, cardID, cacheUpdates)
}
// 独立卡写入风险 gateway_extend 后:关闭轮询,终止循环
if statusQueried && shouldStopPollingForRisk(card, gatewayExtend) {
if updateErr := h.iotCardStore.UpdatePollingStatus(ctx, cardID, false); updateErr != nil {
h.base.logger.Warn("关闭风险卡轮询状态失败",
zap.Uint("card_id", cardID), zap.String("gateway_extend", gatewayExtend), zap.Error(updateErr))
} else {
h.base.logger.Info("独立卡命中风险状态,已关闭轮询",
zap.Uint("card_id", cardID), zap.String("gateway_extend", gatewayExtend))
}
h.base.updateStats(ctx, constants.TaskTypePollingCardStatus, true, time.Since(startTime))
return nil // 不再入队,终止轮询循环
}
if statusChanged {
h.base.logger.Info("卡状态已变化",
zap.Uint("card_id", cardID),