This commit is contained in:
@@ -65,6 +65,8 @@ func (h *PollingCardStatusHandler) Handle(ctx context.Context, t *asynq.Task) er
|
||||
|
||||
newNetworkStatus := card.NetworkStatus
|
||||
gatewayCardStatus := ""
|
||||
gatewayExtend := card.GatewayExtend
|
||||
statusQueried := false
|
||||
if h.gateway != nil {
|
||||
result, gwErr := h.gateway.QueryCardStatus(ctx, &gateway.CardStatusReq{CardNo: card.ICCID})
|
||||
if gwErr != nil {
|
||||
@@ -74,6 +76,8 @@ func (h *PollingCardStatusHandler) Handle(ctx context.Context, t *asynq.Task) er
|
||||
return h.base.requeueCard(ctx, cardID, constants.TaskTypePollingCardStatus)
|
||||
}
|
||||
gatewayCardStatus = result.CardStatus
|
||||
gatewayExtend = result.Extend
|
||||
statusQueried = true
|
||||
parsedStatus, ok := gateway.ParseCardNetworkStatus(result.CardStatus, result.Extend)
|
||||
if !ok {
|
||||
h.base.logger.Warn("卡状态轮询:未知 Gateway 卡状态",
|
||||
@@ -100,6 +104,9 @@ func (h *PollingCardStatusHandler) Handle(ctx context.Context, t *asynq.Task) er
|
||||
|
||||
// 无论状态是否变化,都更新最后一次检查时间
|
||||
fields := map[string]any{"last_card_status_check_at": now}
|
||||
if statusQueried {
|
||||
fields["gateway_extend"] = gatewayExtend
|
||||
}
|
||||
if statusChanged {
|
||||
fields["network_status"] = newNetworkStatus
|
||||
// 网关侧停机事件:补写 stop_reason,便于状态追踪和区分手动停机
|
||||
@@ -116,8 +123,18 @@ func (h *PollingCardStatusHandler) Handle(ctx context.Context, t *asynq.Task) er
|
||||
return h.base.requeueCard(ctx, cardID, constants.TaskTypePollingCardStatus)
|
||||
}
|
||||
|
||||
if statusQueried || statusChanged {
|
||||
cacheUpdates := map[string]any{}
|
||||
if statusQueried {
|
||||
cacheUpdates["gateway_extend"] = gatewayExtend
|
||||
}
|
||||
if statusChanged {
|
||||
cacheUpdates["network_status"] = newNetworkStatus
|
||||
}
|
||||
h.base.updateCardCache(ctx, cardID, cacheUpdates)
|
||||
}
|
||||
|
||||
if statusChanged {
|
||||
h.base.updateCardCache(ctx, cardID, map[string]any{"network_status": newNetworkStatus})
|
||||
h.base.logger.Info("卡状态已变化",
|
||||
zap.Uint("card_id", cardID),
|
||||
zap.Int("old_status", card.NetworkStatus),
|
||||
|
||||
Reference in New Issue
Block a user