From d2a73a7dc3db741f80e7407e0b0b2c66cdad238d Mon Sep 17 00:00:00 2001 From: yarnom Date: Thu, 11 Sep 2025 15:08:56 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E6=AD=A3cma=E9=A2=84=E6=8A=A5?= =?UTF-8?q?=E6=97=B6=E9=97=B4=E7=9A=84=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/forecast/cma.go | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/internal/forecast/cma.go b/internal/forecast/cma.go index 036d2f1..73a3a6d 100644 --- a/internal/forecast/cma.go +++ b/internal/forecast/cma.go @@ -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 {