Compare commits

..

No commits in common. "e8fcd550c1d53bd4d23052a18a667907b5af287b" and "0b5b26d5b0fa34fbfa3b2d515ca2a944ac011cf6" have entirely different histories.

2 changed files with 17 additions and 42 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) { func loadForecastSamples(db *sql.DB, stationID, provider string, issued time.Time) ([]forecastSample, error) {
const q = ` const q = `
SELECT forecast_time, SELECT forecast_time,
COALESCE(rain_mm_x1000, 0), rain_mm_x1000,
COALESCE(temp_c_x100, 0), temp_c_x100,
COALESCE(humidity_pct, 0), humidity_pct,
COALESCE(wind_speed_ms_x1000, 0), wind_speed_ms_x1000,
COALESCE(wind_gust_ms_x1000, 0), wind_gust_ms_x1000,
COALESCE(wind_dir_deg, 0), wind_dir_deg,
COALESCE(precip_prob_pct, 0), precip_prob_pct,
COALESCE(pressure_hpa_x100, 0), pressure_hpa_x100,
COALESCE(uv_index, 0) uv_index
FROM forecast_hourly FROM forecast_hourly
WHERE station_id=$1 AND provider=$2 AND issued_at=$3 WHERE station_id=$1 AND provider=$2 AND issued_at=$3
ORDER BY forecast_time ASC` ORDER BY forecast_time ASC`

View File

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