关于上游流量同步覆盖修复,以及新增redis同步迁移
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 8m25s

This commit is contained in:
Break
2026-05-27 10:59:19 +08:00
parent cf689beceb
commit 0d96a94e5f
6 changed files with 349 additions and 6 deletions

View File

@@ -109,7 +109,10 @@ func (h *PollingCarddataHandler) Handle(ctx context.Context, t *asynq.Task) erro
go h.base.insertDataUsageRecord(context.Background(), cardID, flowIncrementMB, now)
cacheUpdates := map[string]any{"last_gateway_reading_mb": gatewayFlowMB}
cacheUpdates := map[string]any{}
if reading, ok := updates["last_gateway_reading_mb"]; ok {
cacheUpdates["last_gateway_reading_mb"] = reading
}
if isCrossMonth {
// 跨月时同步更新缓存中的本月开始日期和本月用量,避免下次从缓存读取时再次误判跨月
currentMonthStart := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location())
@@ -150,6 +153,7 @@ func (h *PollingCarddataHandler) calculateFlowUpdates(card *model.IotCard, gatew
updates := make(map[string]any)
increment := gatewayFlowMB - card.LastGatewayReadingMB
shouldUpdateGatewayReading := true
if increment < 0 {
if isResetWindow(now, resetDay) {
increment = gatewayFlowMB
@@ -164,10 +168,13 @@ func (h *PollingCarddataHandler) calculateFlowUpdates(card *model.IotCard, gatew
zap.Float64("gateway_flow", gatewayFlowMB),
zap.Float64("last_reading", card.LastGatewayReadingMB))
increment = 0
shouldUpdateGatewayReading = false
}
}
updates["last_gateway_reading_mb"] = gatewayFlowMB
if shouldUpdateGatewayReading {
updates["last_gateway_reading_mb"] = gatewayFlowMB
}
currentMonthStart := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location())
isCrossMonth := card.CurrentMonthStartDate == nil ||