Compare commits

...

2 Commits

Author SHA1 Message Date
e8fcd550c1 fix: 修正微服务gin找不到templates的问题 2025-10-14 11:48:32 +08:00
5b7ec80473 fix: 修正融合出现的问题 2025-10-14 11:48:16 +08:00
2 changed files with 42 additions and 17 deletions

View File

@ -509,15 +509,15 @@ func resolveIssuedAtInBucket(db *sql.DB, stationID, provider string, bucketHour
func loadForecastSamples(db *sql.DB, stationID, provider string, issued time.Time) ([]forecastSample, error) {
const q = `
SELECT forecast_time,
rain_mm_x1000,
temp_c_x100,
humidity_pct,
wind_speed_ms_x1000,
wind_gust_ms_x1000,
wind_dir_deg,
precip_prob_pct,
pressure_hpa_x100,
uv_index
COALESCE(rain_mm_x1000, 0),
COALESCE(temp_c_x100, 0),
COALESCE(humidity_pct, 0),
COALESCE(wind_speed_ms_x1000, 0),
COALESCE(wind_gust_ms_x1000, 0),
COALESCE(wind_dir_deg, 0),
COALESCE(precip_prob_pct, 0),
COALESCE(pressure_hpa_x100, 0),
COALESCE(uv_index, 0)
FROM forecast_hourly
WHERE station_id=$1 AND provider=$2 AND issued_at=$3
ORDER BY forecast_time ASC`

View File

@ -5,6 +5,7 @@ import (
"log"
"net/http"
"os"
"path/filepath"
"strconv"
"time"
"weatherstation/internal/config"
@ -22,27 +23,51 @@ func StartGinServer() error {
// 创建Gin引擎
r := gin.Default()
// 加载HTML模板
r.LoadHTMLGlob("templates/*")
// 解析资源路径,兼容在仓库根目录或 bin/ 目录启动
tplGlob := filepath.Join("templates", "*")
if _, err := os.Stat("templates"); os.IsNotExist(err) {
if _, err2 := os.Stat("../templates"); err2 == nil {
tplGlob = filepath.Join("..", "templates", "*")
}
}
r.LoadHTMLGlob(tplGlob)
// 静态文件服务
r.Static("/static", "./static")
staticDir := "./static"
if _, err := os.Stat(staticDir); os.IsNotExist(err) {
if _, err2 := os.Stat("../static"); err2 == nil {
staticDir = "../static"
}
}
r.Static("/static", staticDir)
// 前端SPAAngular静态资源与路由回退
// 构建产物目录:./core/frontend/dist/ui
// 构建产物目录:./core/frontend/dist/ui(兼容 ../core/frontend/dist/ui
r.GET("/ui/*filepath", func(c *gin.Context) {
// 物理文件优先,否则回退到 index.html支持前端路由
requested := c.Param("filepath")
if requested == "" || requested == "/" {
c.File("./core/frontend/dist/ui/index.html")
base := "./core/frontend/dist/ui/index.html"
if _, err := os.Stat(base); os.IsNotExist(err) {
alt := "../core/frontend/dist/ui/index.html"
if _, err2 := os.Stat(alt); err2 == nil {
base = alt
}
}
c.File(base)
return
}
full := ".//core/frontend/dist/ui" + requested
baseDir := "./core/frontend/dist/ui"
if _, err := os.Stat(baseDir); os.IsNotExist(err) {
if _, err2 := os.Stat("../core/frontend/dist/ui"); err2 == nil {
baseDir = "../core/frontend/dist/ui"
}
}
full := baseDir + requested
if _, err := os.Stat(full); err == nil {
c.File(full)
return
}
c.File("./core/frontend/dist/ui/index.html")
c.File(filepath.Join(baseDir, "index.html"))
})
// 路由设置