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)}
`;