From 0eaaa544e9398d9f8cc9503533883d05eb94e967 Mon Sep 17 00:00:00 2001 From: shenjack <3695888@qq.com> Date: Fri, 6 Sep 2024 06:17:44 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=95=E5=9B=BE=E7=90=86=E8=A7=A3.png?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cargo.lock | 3 +++ sr_download/Cargo.toml | 1 + sr_download/src/db_part.rs | 17 ++++++++++------- sr_download/src/model/main_data.rs | 1 + 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 24ac265..4004c08 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -442,8 +442,10 @@ checksum = "a21f936df1771bf62b77f047b726c4625ff2e8aa607c01ec06e5a05bd8463401" dependencies = [ "android-tzdata", "iana-time-zone", + "js-sys", "num-traits", "serde", + "wasm-bindgen", "windows-targets 0.52.6", ] @@ -2595,6 +2597,7 @@ dependencies = [ "anyhow", "axum", "blake3", + "chrono", "colored", "futures", "migration", diff --git a/sr_download/Cargo.toml b/sr_download/Cargo.toml index a45b120..2e4f1bd 100644 --- a/sr_download/Cargo.toml +++ b/sr_download/Cargo.toml @@ -36,3 +36,4 @@ serde = { version = "1.0", features = ["serde_derive"] } toml = "0.8" blake3 = "1.5.4" quick-xml = { version = "0.36.1", features = ["async-tokio"] } +chrono = "0.4.38" diff --git a/sr_download/src/db_part.rs b/sr_download/src/db_part.rs index 8c78cc1..d0e79e9 100644 --- a/sr_download/src/db_part.rs +++ b/sr_download/src/db_part.rs @@ -1,8 +1,8 @@ use blake3::Hasher; use sea_orm::{ - ActiveModelTrait, ColumnTrait, ConnectionTrait, DatabaseConnection, EntityTrait, - IntoActiveModel, ModelTrait, QueryFilter, QuerySelect, Statement, TransactionTrait, + ActiveEnum, ActiveModelTrait, ColumnTrait, ConnectionTrait, DatabaseConnection, EntityTrait, IntoActiveModel, ModelTrait, QueryFilter, QuerySelect, Statement, TransactionTrait }; +use tracing::{event, Level}; // use tracing::{event, Level}; use crate::model; @@ -85,7 +85,7 @@ impl DbData { /// 直接从 full_data 里选即可 pub async fn from_db(save_id: SaveId, db: &DatabaseConnection) -> Option { let sql = format!( - "SELECT * FROM {} WHERE save_id = {}", + "SELECT save_type::\"varchar\",* FROM {} WHERE save_id = {}", FULL_DATA_VIEW, save_id ); let datas = db @@ -96,14 +96,14 @@ impl DbData { .await .ok()??; let text = datas.try_get("", "data").ok()?; - let save_id: SaveId = datas.try_get("", "save_id").ok()?; - let save_type: SaveType = datas.try_get("", "save_type").ok()?; + let save_id: i32 = datas.try_get("", "save_id").ok()?; + let save_type: String = datas.try_get("", "save_type").ok()?; let len: i64 = datas.try_get("", "len").ok()?; let blake_hash: String = datas.try_get("", "blake_hash").ok()?; Some(Self { text, - save_id, - save_type, + save_id: save_id as SaveId, + save_type: SaveType::try_from_value(&save_type).unwrap(), len, blake_hash, }) @@ -156,6 +156,7 @@ where // 干活之前, 先检查一下数据是否已经存在 // 如果已经存在, 那就根据策略来处理 let cover_strategy = cover_strategy.unwrap_or_default(); + let time = chrono::Utc::now(); let save_type: SaveType = save_type.into(); let exitst_data: Option = { model::main_data::Entity::find() @@ -227,6 +228,7 @@ where len: data_len as i64, short_data: None, xml_tested, + time: time.into(), }; let long_data = model::long_data::Model { save_id: save_id as i32, @@ -246,6 +248,7 @@ where len: data_len as i64, short_data: Some(data), xml_tested, + time: time.into(), }; new_data.into_active_model().insert(db).await?; } diff --git a/sr_download/src/model/main_data.rs b/sr_download/src/model/main_data.rs index cc3156f..33441af 100644 --- a/sr_download/src/model/main_data.rs +++ b/sr_download/src/model/main_data.rs @@ -13,6 +13,7 @@ pub struct Model { pub len: i64, pub short_data: Option, pub xml_tested: Option, + pub time: DateTimeWithTimeZone, } #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]