将WeatherData移到models.rs中
This commit is contained in:
95
src/main.rs
95
src/main.rs
@@ -1,5 +1,4 @@
|
|||||||
use actix_web::{App, HttpResponse, HttpServer, Responder, Result, post, web};
|
use actix_web::{App, HttpResponse, HttpServer, Responder, Result, post, web};
|
||||||
use chrono::NaiveDate;
|
|
||||||
use db::create_pool;
|
use db::create_pool;
|
||||||
use reqwest::Client;
|
use reqwest::Client;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
@@ -8,99 +7,7 @@ use sqlx::postgres::PgPool;
|
|||||||
mod db;
|
mod db;
|
||||||
mod models;
|
mod models;
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Serialize)]
|
use models::WeatherData;
|
||||||
pub struct WeatherData {
|
|
||||||
#[serde(rename = "areaType")]
|
|
||||||
area_type: String,
|
|
||||||
|
|
||||||
#[serde(rename = "assignmentnumber")]
|
|
||||||
assignment_number: String,
|
|
||||||
|
|
||||||
#[serde(rename = "atmosphericStability")]
|
|
||||||
atmospheric_stability: String,
|
|
||||||
|
|
||||||
#[serde(rename = "averageWindDirection")]
|
|
||||||
average_wind_direction: f64,
|
|
||||||
|
|
||||||
#[serde(rename = "averageWindSpeed")]
|
|
||||||
average_wind_speed: f64,
|
|
||||||
|
|
||||||
#[serde(rename = "calculatedwindspeed")]
|
|
||||||
calculated_wind_speed: f64,
|
|
||||||
|
|
||||||
#[serde(rename = "cloudIndex")]
|
|
||||||
cloud_index: String,
|
|
||||||
|
|
||||||
#[serde(rename = "convertedWindSpeed")]
|
|
||||||
converted_wind_speed: f64,
|
|
||||||
|
|
||||||
date: NaiveDate,
|
|
||||||
|
|
||||||
#[serde(rename = "daySinceJanFirst")]
|
|
||||||
day_since_jan_first: i32,
|
|
||||||
|
|
||||||
#[serde(rename = "hasMeasuredWindSpeed")]
|
|
||||||
has_measured_wind_speed: bool,
|
|
||||||
|
|
||||||
hours: i32,
|
|
||||||
|
|
||||||
#[serde(rename = "inspectiontype")]
|
|
||||||
inspection_type: String,
|
|
||||||
|
|
||||||
latitude: f64,
|
|
||||||
longitude: f64,
|
|
||||||
|
|
||||||
#[serde(rename = "lowCloudiness")]
|
|
||||||
low_cloudiness: String,
|
|
||||||
|
|
||||||
#[serde(rename = "measuredWindSpeed")]
|
|
||||||
measured_wind_speed: f64,
|
|
||||||
|
|
||||||
#[serde(rename = "measurementHeight")]
|
|
||||||
measurement_height: f64,
|
|
||||||
|
|
||||||
min: i32,
|
|
||||||
openid: String,
|
|
||||||
|
|
||||||
#[serde(rename = "overallCloudiness")]
|
|
||||||
overall_cloudiness: String,
|
|
||||||
|
|
||||||
#[serde(rename = "overallSuitability")]
|
|
||||||
overall_suitability: String,
|
|
||||||
|
|
||||||
#[serde(rename = "pointWindSpeed")]
|
|
||||||
point_wind_speed: f64,
|
|
||||||
|
|
||||||
#[serde(rename = "solarDeclination")]
|
|
||||||
solar_declination: f64,
|
|
||||||
|
|
||||||
#[serde(rename = "solarRadiationLevel")]
|
|
||||||
solar_radiation_level: f64,
|
|
||||||
|
|
||||||
#[serde(rename = "suitabilityDegree")]
|
|
||||||
suitability_degree: String,
|
|
||||||
|
|
||||||
#[serde(rename = "sunAltitude")]
|
|
||||||
sun_altitude: f64,
|
|
||||||
|
|
||||||
theta: f64,
|
|
||||||
title: String,
|
|
||||||
|
|
||||||
#[serde(rename = "windDirection")]
|
|
||||||
wind_direction: Vec<f64>,
|
|
||||||
|
|
||||||
#[serde(rename = "windDirectionStandardDeviation")]
|
|
||||||
wind_direction_standard_deviation: f64,
|
|
||||||
|
|
||||||
#[serde(rename = "windDirectionSuitability")]
|
|
||||||
wind_direction_suitability: String,
|
|
||||||
|
|
||||||
#[serde(rename = "windSpeed")]
|
|
||||||
wind_speed: Vec<f64>,
|
|
||||||
|
|
||||||
#[serde(rename = "windSpeedSuitability")]
|
|
||||||
wind_speed_suitability: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
// 定义请求体结构
|
// 定义请求体结构
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize)]
|
||||||
|
|||||||
137
src/models.rs
137
src/models.rs
@@ -1,7 +1,101 @@
|
|||||||
use chrono::NaiveDate;
|
use chrono::NaiveDate;
|
||||||
use serde::{Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use sqlx::FromRow; // 处理日期类型
|
use sqlx::FromRow; // 处理日期类型
|
||||||
|
|
||||||
|
#[derive(Debug, Deserialize, Serialize)]
|
||||||
|
pub struct WeatherData {
|
||||||
|
#[serde(rename = "areaType")]
|
||||||
|
pub area_type: String,
|
||||||
|
|
||||||
|
#[serde(rename = "assignmentnumber")]
|
||||||
|
pub assignment_number: String,
|
||||||
|
|
||||||
|
#[serde(rename = "atmosphericStability")]
|
||||||
|
pub atmospheric_stability: String,
|
||||||
|
|
||||||
|
#[serde(rename = "averageWindDirection")]
|
||||||
|
pub average_wind_direction: f64,
|
||||||
|
|
||||||
|
#[serde(rename = "averageWindSpeed")]
|
||||||
|
pub average_wind_speed: f64,
|
||||||
|
|
||||||
|
#[serde(rename = "calculatedwindspeed")]
|
||||||
|
pub calculated_wind_speed: f64,
|
||||||
|
|
||||||
|
#[serde(rename = "cloudIndex")]
|
||||||
|
pub cloud_index: String,
|
||||||
|
|
||||||
|
#[serde(rename = "convertedWindSpeed")]
|
||||||
|
pub converted_wind_speed: f64,
|
||||||
|
|
||||||
|
pub date: NaiveDate,
|
||||||
|
|
||||||
|
#[serde(rename = "daySinceJanFirst")]
|
||||||
|
pub day_since_jan_first: i32,
|
||||||
|
|
||||||
|
#[serde(rename = "hasMeasuredWindSpeed")]
|
||||||
|
pub has_measured_wind_speed: bool,
|
||||||
|
|
||||||
|
pub hours: i32,
|
||||||
|
|
||||||
|
#[serde(rename = "inspectiontype")]
|
||||||
|
pub inspection_type: String,
|
||||||
|
|
||||||
|
pub latitude: f64,
|
||||||
|
pub longitude: f64,
|
||||||
|
|
||||||
|
#[serde(rename = "lowCloudiness")]
|
||||||
|
pub low_cloudiness: String,
|
||||||
|
|
||||||
|
#[serde(rename = "measuredWindSpeed")]
|
||||||
|
pub measured_wind_speed: f64,
|
||||||
|
|
||||||
|
#[serde(rename = "measurementHeight")]
|
||||||
|
pub measurement_height: f64,
|
||||||
|
|
||||||
|
pub min: i32,
|
||||||
|
pub openid: String,
|
||||||
|
|
||||||
|
#[serde(rename = "overallCloudiness")]
|
||||||
|
pub overall_cloudiness: String,
|
||||||
|
|
||||||
|
#[serde(rename = "overallSuitability")]
|
||||||
|
pub overall_suitability: String,
|
||||||
|
|
||||||
|
#[serde(rename = "pointWindSpeed")]
|
||||||
|
pub point_wind_speed: f64,
|
||||||
|
|
||||||
|
#[serde(rename = "solarDeclination")]
|
||||||
|
pub solar_declination: f64,
|
||||||
|
|
||||||
|
#[serde(rename = "solarRadiationLevel")]
|
||||||
|
pub solar_radiation_level: f64,
|
||||||
|
|
||||||
|
#[serde(rename = "suitabilityDegree")]
|
||||||
|
pub suitability_degree: String,
|
||||||
|
|
||||||
|
#[serde(rename = "sunAltitude")]
|
||||||
|
pub sun_altitude: f64,
|
||||||
|
|
||||||
|
pub theta: f64,
|
||||||
|
pub title: String,
|
||||||
|
|
||||||
|
#[serde(rename = "windDirection")]
|
||||||
|
pub wind_direction: Vec<f64>,
|
||||||
|
|
||||||
|
#[serde(rename = "windDirectionStandardDeviation")]
|
||||||
|
pub wind_direction_standard_deviation: f64,
|
||||||
|
|
||||||
|
#[serde(rename = "windDirectionSuitability")]
|
||||||
|
pub wind_direction_suitability: String,
|
||||||
|
|
||||||
|
#[serde(rename = "windSpeed")]
|
||||||
|
pub wind_speed: Vec<f64>,
|
||||||
|
|
||||||
|
#[serde(rename = "windSpeedSuitability")]
|
||||||
|
pub wind_speed_suitability: String,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, FromRow)]
|
#[derive(Debug, Serialize, FromRow)]
|
||||||
pub struct User {
|
pub struct User {
|
||||||
pub id: i32,
|
pub id: i32,
|
||||||
@@ -19,44 +113,3 @@ pub struct User {
|
|||||||
#[sqlx(rename = "desc")]
|
#[sqlx(rename = "desc")]
|
||||||
pub description: Option<String>,
|
pub description: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, FromRow)]
|
|
||||||
pub struct WeatherData {
|
|
||||||
pub id: i32,
|
|
||||||
pub user_id: i32,
|
|
||||||
pub title: Option<String>,
|
|
||||||
#[serde(rename = "date")]
|
|
||||||
#[sqlx(rename = "date")]
|
|
||||||
pub record_date: Option<NaiveDate>, // 避免与关键字冲突
|
|
||||||
pub hour: Option<i32>,
|
|
||||||
pub min: Option<i32>,
|
|
||||||
pub longitude: Option<String>,
|
|
||||||
pub latitude: Option<String>,
|
|
||||||
pub daysincejanfirst: Option<i32>,
|
|
||||||
pub theta: Option<f64>,
|
|
||||||
pub solardeclination: Option<f64>,
|
|
||||||
pub sunaltitude: Option<f64>,
|
|
||||||
pub overallcloudiness: Option<String>,
|
|
||||||
pub lowcloudiness: Option<String>,
|
|
||||||
pub cloudindex: Option<String>,
|
|
||||||
pub solarradiationlevel: Option<i32>,
|
|
||||||
pub hasmeasuredwindspeed: Option<bool>,
|
|
||||||
pub measuredwindspeed: Option<f64>,
|
|
||||||
pub convertedwindspeed: Option<i32>,
|
|
||||||
pub measurementheight: Option<f64>,
|
|
||||||
pub areatype: Option<String>,
|
|
||||||
pub pointwindspeed: Option<f64>,
|
|
||||||
pub atmosphericstability: Option<String>,
|
|
||||||
pub suitabilitydegree: Option<String>,
|
|
||||||
pub winddirection: Option<serde_json::Value>, // JSONB类型
|
|
||||||
pub averagewinddirection: Option<f64>,
|
|
||||||
pub winddirectionstandarddeviation: Option<f64>,
|
|
||||||
pub windspeed: Option<serde_json::Value>, // JSONB类型
|
|
||||||
pub averagewindspeed: Option<f64>,
|
|
||||||
pub windspeedsuitability: Option<String>,
|
|
||||||
pub winddirectionsuitability: Option<String>,
|
|
||||||
pub overallsuitability: Option<String>,
|
|
||||||
pub inspectiontype: Option<String>,
|
|
||||||
pub assignmentnumber: Option<String>,
|
|
||||||
pub calculatedwindspeed: Option<f64>,
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user