You've already forked VptPassiveAdapter
refactor(continuity): 优化连续性检查逻辑和时间格式
- 将时间格式从 ISO 8601 修改为标准日期时间格式 - 修复连续性检查中 Gaps 字段的空数组初始化问题 - 重构连续性检查循环逻辑,启动时立即执行一次检查 - 提取连续性检查逻辑到独立的 performContinuityCheck 函数 - 优化检查时间范围的判断逻辑
This commit is contained in:
@@ -156,8 +156,8 @@ func reportSingleDevice(ctx context.Context, result dto.ContinuityCheckResult) e
|
||||
|
||||
// convertToReportRequest 将内部检查结果转换为接口请求格式
|
||||
func convertToReportRequest(result dto.ContinuityCheckResult) dto.ContinuityReportRequest {
|
||||
// 时间格式:ISO 8601
|
||||
const timeFormat = "2006-01-02T15:04:05"
|
||||
// 时间格式
|
||||
const timeFormat = "2006-01-02 15:04:05"
|
||||
|
||||
request := dto.ContinuityReportRequest{
|
||||
DeviceNo: result.DeviceNo,
|
||||
@@ -182,6 +182,8 @@ func convertToReportRequest(result dto.ContinuityCheckResult) dto.ContinuityRepo
|
||||
GapEndTime: gap.NextStartTime.Format(timeFormat),
|
||||
})
|
||||
}
|
||||
} else {
|
||||
request.Gaps = []dto.ContinuityReportGap{}
|
||||
}
|
||||
|
||||
return request
|
||||
|
||||
@@ -47,18 +47,28 @@ func RunContinuityCheckLoop(ctx context.Context) {
|
||||
zap.Int("checkStartHour", checkStartHour),
|
||||
zap.Int("checkEndHour", checkEndHour))
|
||||
|
||||
// 启动时立即执行一次检查
|
||||
performContinuityCheck(ctx)
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
logger.Info("连续性检查循环已停止")
|
||||
return
|
||||
case <-ticker.C:
|
||||
performContinuityCheck(ctx)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// performContinuityCheck 执行一次连续性检查
|
||||
func performContinuityCheck(ctx context.Context) {
|
||||
now := time.Now()
|
||||
|
||||
// 只在9点到18点之间执行检查
|
||||
currentHour := now.Hour()
|
||||
if currentHour < checkStartHour || currentHour >= checkEndHour {
|
||||
continue
|
||||
return
|
||||
}
|
||||
|
||||
startTime := now.Add(-time.Duration(rangeStartMinutes) * time.Minute)
|
||||
@@ -73,8 +83,6 @@ func RunContinuityCheckLoop(ctx context.Context) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// CheckAllDevicesContinuity 检查所有设备的连续性
|
||||
func CheckAllDevicesContinuity(ctx context.Context, startTime, endTime time.Time) []dto.ContinuityCheckResult {
|
||||
|
||||
Reference in New Issue
Block a user