From 54484482c345913b7c10d4cc386f1c76d0bfa18e Mon Sep 17 00:00:00 2001 From: milky0217 Date: Mon, 18 May 2026 09:51:38 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=8A=BD=E6=B5=8B=E9=A3=8E=E9=80=9F?= =?UTF-8?q?=E6=94=B9=E4=B8=BA=E7=94=A8=E6=88=B7=E5=8F=AF=E8=87=AA=E5=AE=9A?= =?UTF-8?q?=E4=B9=89=E6=AC=A1=E6=95=B0=EF=BC=88=E5=A2=9E=E5=88=A0=E6=8C=89?= =?UTF-8?q?=E9=92=AE=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - models.rs:新增 spot_check_count 字段(默认 5) - db.rs:INSERT/SELECT 添加 spotcheckcount 列 - migrations/007:ALTER TABLE weather_data ADD spotcheckcount - afterbody.js:使用 data.spotCheckCount 动态渲染抽测数据 --- migrations/007_add_spot_check_count.sql | 3 +++ src/db.rs | 7 ++++--- src/models.rs | 9 +++++++++ static/js/afterbody.js | 8 ++++---- 4 files changed, 20 insertions(+), 7 deletions(-) create mode 100644 migrations/007_add_spot_check_count.sql diff --git a/migrations/007_add_spot_check_count.sql b/migrations/007_add_spot_check_count.sql new file mode 100644 index 0000000..fb959af --- /dev/null +++ b/migrations/007_add_spot_check_count.sql @@ -0,0 +1,3 @@ +-- 为 weather_data 表添加抽测次数字段 +ALTER TABLE weather_data +ADD COLUMN IF NOT EXISTS spotcheckcount INTEGER NOT NULL DEFAULT 5; diff --git a/src/db.rs b/src/db.rs index 574be1a..df630be 100644 --- a/src/db.rs +++ b/src/db.rs @@ -35,10 +35,10 @@ pub async fn insert_weather_data(pool: &PgPool, weather_data: &WeatherData, user atmosphericstability, suitabilitydegree, winddirection, averagewinddirection, winddirectionstandarddeviation, windspeed, averagewindspeed, windspeedsuitability, winddirectionsuitability, overallsuitability, inspectiontype, assignmentnumber, - calculatedwindspeed, hasspotcheckwindspeed, version, is_favorite + calculatedwindspeed, hasspotcheckwindspeed, spotcheckcount, version, is_favorite ) 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, $35, $36, $37 + $20, $21, $22, $23, $24, $25, $26, $27, $28, $29, $30, $31, $32, $33, $34, $35, $36, $37, $38 ) RETURNING id "#; @@ -85,6 +85,7 @@ pub async fn insert_weather_data(pool: &PgPool, weather_data: &WeatherData, user .bind(&weather_data.assignment_number) .bind(weather_data.calculated_wind_speed) // 这个本来就是 Option,无需修改 .bind(weather_data.has_spot_check_wind_speed) + .bind(weather_data.spot_check_count) .bind(&weather_data.version) .bind(weather_data.is_favorite) .fetch_one(pool) @@ -131,7 +132,7 @@ pub async fn get_weather_details(pool: &PgPool, weather_id: i32) -> Result i32 { + 5 +} + // 定义JWT载荷结构体 #[derive(Debug, Serialize, Deserialize, Clone)] pub struct Claims { @@ -204,6 +209,10 @@ pub struct WeatherData { #[sqlx(rename = "hasspotcheckwindspeed")] pub has_spot_check_wind_speed: bool, + #[serde(rename = "spotCheckCount", default = "default_spot_check_count")] + #[sqlx(rename = "spotcheckcount")] + pub spot_check_count: i32, + #[serde(rename = "hours")] #[sqlx(rename = "hour")] pub hours: i32, diff --git a/static/js/afterbody.js b/static/js/afterbody.js index 9f65724..7ea5e6a 100644 --- a/static/js/afterbody.js +++ b/static/js/afterbody.js @@ -1,6 +1,5 @@ const WeatherReport = (function () { const BASE_WIND_COUNT = 10; - const SPOT_CHECK_COUNT = 5; const AREA_TYPE_MAP = { urban: "城市", @@ -193,19 +192,20 @@ const WeatherReport = (function () { `; - if (data.hasSpotCheckWindSpeed) { + const spotCount = data.spotCheckCount || 5; + if (data.hasSpotCheckWindSpeed && spotCount > 0) { html += `
抽测风速值:
-
${joinWithComma(data.windSpeed, BASE_WIND_COUNT, BASE_WIND_COUNT + SPOT_CHECK_COUNT)}
+
${joinWithComma(data.windSpeed, BASE_WIND_COUNT, BASE_WIND_COUNT + spotCount)}
抽测风向值:
-
${joinWithComma(data.windDirection, BASE_WIND_COUNT, BASE_WIND_COUNT + SPOT_CHECK_COUNT)}
+
${joinWithComma(data.windDirection, BASE_WIND_COUNT, BASE_WIND_COUNT + spotCount)}
`;