feat: 抽测风速改为用户可自定义次数(增删按钮)
- models.rs:新增 spot_check_count 字段(默认 5) - db.rs:INSERT/SELECT 添加 spotcheckcount 列 - migrations/007:ALTER TABLE weather_data ADD spotcheckcount - afterbody.js:使用 data.spotCheckCount 动态渲染抽测数据
This commit is contained in:
3
migrations/007_add_spot_check_count.sql
Normal file
3
migrations/007_add_spot_check_count.sql
Normal file
@@ -0,0 +1,3 @@
|
||||
-- 为 weather_data 表添加抽测次数字段
|
||||
ALTER TABLE weather_data
|
||||
ADD COLUMN IF NOT EXISTS spotcheckcount INTEGER NOT NULL DEFAULT 5;
|
||||
@@ -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<Weath
|
||||
wd.winddirectionstandarddeviation, wd.windspeed, wd.averagewindspeed,
|
||||
wd.windspeedsuitability, wd.winddirectionsuitability, wd.overallsuitability,
|
||||
wd.inspectiontype, wd.assignmentnumber, wd.calculatedwindspeed, wd.hasspotcheckwindspeed,
|
||||
wd.is_favorite, u.openid, wd.version
|
||||
wd.spotcheckcount, wd.is_favorite, u.openid, wd.version
|
||||
FROM weather_data wd
|
||||
JOIN users u ON wd.user_id = u.id
|
||||
WHERE wd.id = $1
|
||||
|
||||
@@ -4,6 +4,11 @@ use serde_json::Value as JsonValue;
|
||||
use sqlx::FromRow;
|
||||
use std::convert::TryFrom;
|
||||
|
||||
// 默认值函数
|
||||
fn default_spot_check_count() -> 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,
|
||||
|
||||
@@ -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 () {
|
||||
</div>
|
||||
</div>`;
|
||||
|
||||
if (data.hasSpotCheckWindSpeed) {
|
||||
const spotCount = data.spotCheckCount || 5;
|
||||
if (data.hasSpotCheckWindSpeed && spotCount > 0) {
|
||||
html += `
|
||||
<div class="two-column">
|
||||
<div class="field full-width">
|
||||
<div class="field-label">抽测风速值:</div>
|
||||
<div class="field-value">
|
||||
<div class="ten-values">${joinWithComma(data.windSpeed, BASE_WIND_COUNT, BASE_WIND_COUNT + SPOT_CHECK_COUNT)}</div>
|
||||
<div class="ten-values">${joinWithComma(data.windSpeed, BASE_WIND_COUNT, BASE_WIND_COUNT + spotCount)}</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="field full-width">
|
||||
<div class="field-label">抽测风向值:</div>
|
||||
<div class="field-value">
|
||||
<div class="ten-values">${joinWithComma(data.windDirection, BASE_WIND_COUNT, BASE_WIND_COUNT + SPOT_CHECK_COUNT)}</div>
|
||||
<div class="ten-values">${joinWithComma(data.windDirection, BASE_WIND_COUNT, BASE_WIND_COUNT + spotCount)}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>`;
|
||||
|
||||
Reference in New Issue
Block a user