fix: 修正cma预报时间的错误

This commit is contained in:
yarnom 2025-09-11 15:08:56 +08:00
parent 93533aa76c
commit d2a73a7dc3

View File

@ -252,9 +252,8 @@ func RunCMAFetch(ctx context.Context) error {
if loc == nil {
loc = time.FixedZone("CST", 8*3600)
}
issuedAt := time.Now().In(loc)
startHour := issuedAt.Truncate(time.Hour)
targets := []time.Time{startHour.Add(1 * time.Hour), startHour.Add(2 * time.Hour), startHour.Add(3 * time.Hour)}
issuedAt := time.Now().In(loc)
base := issuedAt.Truncate(time.Hour)
// 请求CMA
form := url.Values{}
@ -323,7 +322,29 @@ func RunCMAFetch(ctx context.Context) error {
}
}
// 读取站点列表(全部)
// 从可用数据中选择“接下来可用的三个未来时次”(按接口实际返回)
timeSet := map[time.Time]struct{}{}
for i := range tables {
for t := range tables[i] {
if t.After(base) {
timeSet[t] = struct{}{}
}
}
}
var targets []time.Time
for t := range timeSet {
targets = append(targets, t)
}
targets = sortTimesAsc(targets)
if len(targets) > 3 {
targets = targets[:3]
}
if len(targets) == 0 {
// 无未来时次则不写库,避免写入“假想整点”。
return nil
}
// 读取站点列表(全部)
db := database.GetDB()
stationIDs, err := loadAllStationIDs(ctx, db)
if err != nil {