diff --git a/src/db.rs b/src/db.rs index db2634b..6722e0c 100644 --- a/src/db.rs +++ b/src/db.rs @@ -5,7 +5,7 @@ use std::error::Error; // 从 models 模块引入 WeatherData 结构体 use crate::models::{WeatherData, WeatherDataBrief, WeatherListResponse}; -// 这个函数封装了所有与数据库交互的逻辑 +// 用于插入weather_data的数据 pub async fn insert_weather_data(pool: &PgPool, weather_data: &WeatherData) -> Result { // 1. 根据 openid 查询 user_id let user_id = match sqlx::query_as::<_, (i32,)>("SELECT id FROM users WHERE openid = $1") @@ -32,16 +32,16 @@ pub async fn insert_weather_data(pool: &PgPool, weather_data: &WeatherData) -> R atmosphericstability, suitabilitydegree, winddirection, averagewinddirection, winddirectionstandarddeviation, windspeed, averagewindspeed, windspeedsuitability, winddirectionsuitability, overallsuitability, inspectiontype, assignmentnumber, - calculatedwindspeed + calculatedwindspeed, hasspotcheckwindspeed ) VALUES ( $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, - $20, $21, $22, $23, $24, $25, $26, $27, $28, $29, $30, $31, $32, $33, $34 + $20, $21, $22, $23, $24, $25, $26, $27, $28, $29, $30, $31, $32, $33, $34, $35 ) RETURNING id "#; // 转换经纬度为字符串 - let longitude_str = weather_data.longitude.to_string(); - let latitude_str = weather_data.latitude.to_string(); + //let longitude_str = weather_data.longitude.to_string(); + //let latitude_str = weather_data.latitude.to_string(); // 3. 执行插入操作 let inserted_id = match sqlx::query_as::<_, (i32,)>(insert_query) @@ -50,8 +50,8 @@ pub async fn insert_weather_data(pool: &PgPool, weather_data: &WeatherData) -> R .bind(weather_data.date) // NaiveDate 类型,sqlx 会自动处理 .bind(weather_data.hours) .bind(weather_data.min) - .bind(&longitude_str) - .bind(&latitude_str) + .bind(&weather_data.longitude) + .bind(&weather_data.latitude) .bind(weather_data.day_since_jan_first) .bind(weather_data.theta) .bind(weather_data.solar_declination) @@ -85,6 +85,7 @@ pub async fn insert_weather_data(pool: &PgPool, weather_data: &WeatherData) -> R .bind(&weather_data.inspection_type) .bind(&weather_data.assignment_number) .bind(weather_data.calculated_wind_speed) + .bind(weather_data.has_spot_check_wind_speed) .fetch_one(pool) .await { @@ -135,7 +136,7 @@ pub async fn get_weather_details(pool: &PgPool, weather_id: i32) -> Result +
十次风速值:
-
${data.windSpeed}
+ +
${data.windSpeed.slice(0, 10).join(',')}
十次风向值:
-
${data.windDirection}
+
${data.windDirection.slice(0, 10).join(',')}
+ +${data.hasSpotCheckWindSpeed ? ` +
+
+
抽测风速值:
+
+ +
${data.windSpeed.slice(10, 15).map(val => val ?? '').join(',')}
+
+
+
+
抽测风向值:
+
+
${data.windDirection.slice(10, 15).map(val => val ?? '').join(',')}
+
+
+
+` : ''} + + +
+
是否有抽测风速:${data.hasSpotCheckWindSpeed ? '是' : '否'}
+
+