From d9b8b385906a1a594e56d98a5b91d9ee078454cb Mon Sep 17 00:00:00 2001 From: soul-walker <31162815+soul-walker@users.noreply.github.com> Date: Thu, 19 Sep 2024 11:03:05 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E6=95=B0=E6=8D=AE=E5=BA=93?= =?UTF-8?q?=E9=BB=98=E8=AE=A4=E6=97=B6=E9=97=B4=E5=AE=9A=E4=B9=89=20?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=8E=A5=E5=8F=A3=E8=BF=94=E5=9B=9E=E4=B8=BA?= =?UTF-8?q?NaiveDateTime?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/rtss_api/Cargo.toml | 2 +- crates/rtss_api/src/draft_data.rs | 18 +- crates/rtss_api/src/server.rs | 4 +- crates/rtss_dto/build.rs | 1 + crates/rtss_dto/src/pb/common.rs | 2 +- crates/rtss_dto/src/pb/iscs_graphic_data.rs | 179 ++++++++++++++++++++ migrations/20240830095636_init.up.sql | 22 +-- rtss-proto-msg | 2 +- src/cmd.rs | 1 - src/db.rs | 1 - 10 files changed, 205 insertions(+), 27 deletions(-) create mode 100644 crates/rtss_dto/src/pb/iscs_graphic_data.rs diff --git a/crates/rtss_api/Cargo.toml b/crates/rtss_api/Cargo.toml index 8cf242c..681e483 100644 --- a/crates/rtss_api/Cargo.toml +++ b/crates/rtss_api/Cargo.toml @@ -6,7 +6,7 @@ edition = "2021" [dependencies] anyhow = { workspace = true } tokio = { workspace = true, features = ["macros", "rt-multi-thread"] } -serde = { workspace = true } +serde = { workspace = true, features = ["derive"] } serde_json = { workspace = true } chrono = { version = "0.4.38", features = ["serde"] } axum = "0.7.5" diff --git a/crates/rtss_api/src/draft_data.rs b/crates/rtss_api/src/draft_data.rs index 946f216..1c3914a 100644 --- a/crates/rtss_api/src/draft_data.rs +++ b/crates/rtss_api/src/draft_data.rs @@ -1,6 +1,6 @@ use async_graphql::{Context, InputObject, Object, SimpleObject}; use async_graphql::{InputType, OutputType}; -use chrono::{DateTime, Local}; +use chrono::NaiveDateTime; use rtss_db::common::TableColumn; use rtss_db::model::DraftDataColumn; use rtss_db::DraftDataAccessor; @@ -282,8 +282,8 @@ pub struct DraftDataWithStringOptions { pub data: Option>, pub user_id: i32, pub is_shared: bool, - pub created_at: DateTime, - pub updated_at: DateTime, + pub created_at: NaiveDateTime, + pub updated_at: NaiveDateTime, } impl From for DraftDataWithStringOptions { @@ -296,8 +296,8 @@ impl From for DraftDataWithStringOptions { data: value.data, user_id: value.user_id, is_shared: value.is_shared, - created_at: value.created_at, - updated_at: value.updated_at, + created_at: value.created_at.naive_local(), + updated_at: value.updated_at.naive_local(), } } } @@ -312,8 +312,8 @@ pub struct DraftData { pub data: Option>, pub user_id: i32, pub is_shared: bool, - pub created_at: DateTime, - pub updated_at: DateTime, + pub created_at: NaiveDateTime, + pub updated_at: NaiveDateTime, } impl From for DraftData { @@ -326,8 +326,8 @@ impl From for DraftData { data: value.data, user_id: value.user_id, is_shared: value.is_shared, - created_at: value.created_at, - updated_at: value.updated_at, + created_at: value.created_at.naive_local(), + updated_at: value.updated_at.naive_local(), } } } diff --git a/crates/rtss_api/src/server.rs b/crates/rtss_api/src/server.rs index 8dda326..1f744cd 100644 --- a/crates/rtss_api/src/server.rs +++ b/crates/rtss_api/src/server.rs @@ -48,8 +48,8 @@ pub async fn serve(config: ServerConfig) -> anyhow::Result<()> { .allow_methods([Method::GET, Method::POST]), ); - debug!("Server started at http://{}", config.to_socket_addr()); - info!("GraphiQL IDE: http://localhost:{}", config.port); + info!("Server started at http://{}", config.to_socket_addr()); + debug!("GraphiQL IDE: http://localhost:{}", config.port); axum::serve( TcpListener::bind(config.to_socket_addr()).await.unwrap(), app, diff --git a/crates/rtss_dto/build.rs b/crates/rtss_dto/build.rs index 037202c..0be9148 100644 --- a/crates/rtss_dto/build.rs +++ b/crates/rtss_dto/build.rs @@ -33,6 +33,7 @@ fn main() { &[ "../../rtss-proto-msg/src/em_data.proto", "../../rtss-proto-msg/src/common.proto", + "../../rtss-proto-msg/src/iscs_graphic_data.proto", ], &["../../rtss-proto-msg/src/"], ) diff --git a/crates/rtss_dto/src/pb/common.rs b/crates/rtss_dto/src/pb/common.rs index b1f72d6..49f6395 100644 --- a/crates/rtss_dto/src/pb/common.rs +++ b/crates/rtss_dto/src/pb/common.rs @@ -86,7 +86,7 @@ pub struct CommonInfo { pub transform: ::core::option::Option, /// 子元素变换 #[prost(message, repeated, tag = "4")] - pub children_transform: ::prost::alloc::vec::Vec, + pub child_transforms: ::prost::alloc::vec::Vec, } /// 数据类型 #[derive( diff --git a/crates/rtss_dto/src/pb/iscs_graphic_data.rs b/crates/rtss_dto/src/pb/iscs_graphic_data.rs new file mode 100644 index 0000000..c472a4f --- /dev/null +++ b/crates/rtss_dto/src/pb/iscs_graphic_data.rs @@ -0,0 +1,179 @@ +// This file is @generated by prost-build. +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct IscsGraphicStorage { + #[prost(message, optional, tag = "1")] + pub canvas: ::core::option::Option, + #[prost(message, repeated, tag = "2")] + pub arrows: ::prost::alloc::vec::Vec, + #[prost(message, repeated, tag = "3")] + pub iscs_texts: ::prost::alloc::vec::Vec, + #[prost(message, repeated, tag = "4")] + pub rects: ::prost::alloc::vec::Vec, + #[prost(message, repeated, tag = "5")] + pub cctv_buttons: ::prost::alloc::vec::Vec, +} +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct UniqueIdOfStationLayout { + /// 城市 + #[prost(string, tag = "1")] + pub city: ::prost::alloc::string::String, + /// 线路号 + #[prost(string, tag = "2")] + pub line_id: ::prost::alloc::string::String, + /// 地图的公里标主坐标系 + #[prost(string, tag = "3")] + pub main_coordinate_system: ::prost::alloc::string::String, +} +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct Arrow { + #[prost(message, optional, tag = "1")] + pub common: ::core::option::Option, + #[prost(string, tag = "2")] + pub code: ::prost::alloc::string::String, + #[prost(message, repeated, tag = "3")] + pub points: ::prost::alloc::vec::Vec, +} +/// Iscs文字 +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct IscsText { + #[prost(message, optional, tag = "1")] + pub common: ::core::option::Option, + #[prost(string, tag = "2")] + pub code: ::prost::alloc::string::String, + #[prost(string, tag = "3")] + pub content: ::prost::alloc::string::String, + #[prost(string, tag = "4")] + pub color: ::prost::alloc::string::String, + #[prost(int32, tag = "5")] + pub font_size: i32, +} +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct Rect { + #[prost(message, optional, tag = "1")] + pub common: ::core::option::Option, + #[prost(string, tag = "2")] + pub code: ::prost::alloc::string::String, + /// 线宽 + #[prost(int32, tag = "3")] + pub line_width: i32, + /// 线色 + #[prost(string, tag = "4")] + pub line_color: ::prost::alloc::string::String, + /// 宽度 + #[prost(float, tag = "5")] + pub width: f32, + /// 高度 + #[prost(float, tag = "6")] + pub height: f32, + /// 圆角半径 + #[prost(int32, tag = "7")] + pub radius: i32, + /// 画第一个点的坐标 + #[prost(message, optional, tag = "8")] + pub point: ::core::option::Option, +} +/// CCTV按钮 +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct CctvButton { + #[prost(message, optional, tag = "1")] + pub common: ::core::option::Option, + #[prost(string, tag = "2")] + pub code: ::prost::alloc::string::String, + #[prost(enumeration = "cctv_button::ButtonType", tag = "3")] + pub button_type: i32, +} +/// Nested message and enum types in `CCTVButton`. +pub mod cctv_button { + #[derive( + Clone, + Copy, + Debug, + PartialEq, + Eq, + Hash, + PartialOrd, + Ord, + ::prost::Enumeration + )] + #[repr(i32)] + pub enum ButtonType { + Rect = 0, + /// 监控样子的按钮 + Monitor = 1, + /// 半圆样子的按钮 + Semicircle = 2, + } + impl ButtonType { + /// String value of the enum field names used in the ProtoBuf definition. + /// + /// The values are not transformed in any way and thus are considered stable + /// (if the ProtoBuf definition does not change) and safe for programmatic use. + pub fn as_str_name(&self) -> &'static str { + match self { + ButtonType::Rect => "rect", + ButtonType::Monitor => "monitor", + ButtonType::Semicircle => "semicircle", + } + } + /// Creates an enum from field names used in the ProtoBuf definition. + pub fn from_str_name(value: &str) -> ::core::option::Option { + match value { + "rect" => Some(Self::Rect), + "monitor" => Some(Self::Monitor), + "semicircle" => Some(Self::Semicircle), + _ => None, + } + } + } +} +/// 手动报警按钮 +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct ManualAlarmButton { + #[prost(message, optional, tag = "1")] + pub common: ::core::option::Option, + #[prost(string, tag = "2")] + pub code: ::prost::alloc::string::String, +} +/// 消防栓报警按钮 +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct HydrantAlarmButton { + #[prost(message, optional, tag = "1")] + pub common: ::core::option::Option, + #[prost(string, tag = "2")] + pub code: ::prost::alloc::string::String, +} +/// 气体灭火 +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct GasExtinguishing { + #[prost(message, optional, tag = "1")] + pub common: ::core::option::Option, + #[prost(string, tag = "2")] + pub code: ::prost::alloc::string::String, +} +/// 烟雾探测器 +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct SmokeDetector { + #[prost(message, optional, tag = "1")] + pub common: ::core::option::Option, + #[prost(string, tag = "2")] + pub code: ::prost::alloc::string::String, +} +/// 温度探测器 +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct TemperatureDetector { + #[prost(message, optional, tag = "1")] + pub common: ::core::option::Option, + #[prost(string, tag = "2")] + pub code: ::prost::alloc::string::String, +} diff --git a/migrations/20240830095636_init.up.sql b/migrations/20240830095636_init.up.sql index 67d0d60..ab42568 100644 --- a/migrations/20240830095636_init.up.sql +++ b/migrations/20240830095636_init.up.sql @@ -12,8 +12,8 @@ CREATE TABLE default_release_data_id INT NULL, -- 默认发布数据id user_id INT NOT NULL, -- 创建用户id is_shared BOOLEAN NOT NULL DEFAULT FALSE, -- 是否共享 - created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT 'now()', -- 创建时间 - updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT 'now()', -- 更新时间 + created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP, -- 创建时间 + updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP, -- 更新时间 UNIQUE (name, user_id) -- 一个用户的草稿名称唯一 ); @@ -58,8 +58,8 @@ CREATE TABLE used_version_id INT NULL, -- 使用的版本数据id user_id INT NOT NULL, -- 发布/更新用户id is_published BOOLEAN NOT NULL DEFAULT TRUE, -- 是否上架 - created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT 'now()', -- 创建时间 - updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT 'now()' -- 更新时间 + created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP, -- 创建时间 + updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP -- 更新时间 ); -- 注释发布数据表 @@ -93,7 +93,7 @@ CREATE TABLE version SERIAL NOT NULL, -- 版本号 description TEXT NOT NULL, -- 版本描述 user_id INT NOT NULL, -- 发布用户id - created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT 'now()', -- 创建时间 + created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP, -- 创建时间 FOREIGN KEY (release_data_id) REFERENCES rtss.release_data (id) ON DELETE CASCADE ); @@ -131,8 +131,8 @@ CREATE TABLE is_published BOOLEAN NOT NULL DEFAULT TRUE, -- 是否上架 creator_id INT NOT NULL, -- 创建用户id updater_id INT NOT NULL, -- 更新用户id - created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT 'now()', -- 创建时间 - updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT 'now()' -- 更新时间 + created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP, -- 创建时间 + updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP -- 更新时间 ); -- 注释仿真feature表 @@ -182,8 +182,8 @@ CREATE TABLE is_published BOOLEAN NOT NULL DEFAULT TRUE, -- 是否上架 creator_id INT NOT NULL, -- 创建用户id updater_id INT NOT NULL, -- 更新用户id - created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT 'now()', -- 创建时间 - updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT 'now()' -- 更新时间 + created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP, -- 创建时间 + updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP -- 更新时间 ); -- 注释仿真feature group表 @@ -224,8 +224,8 @@ CREATE TABLE user_id INT NOT NULL, -- 用户id feature_id INT NOT NULL, -- 仿真feature id config BYTEA NOT NULL, -- 配置 - created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT 'now()', -- 创建时间 - updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT 'now()', -- 更新时间 + created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP, -- 创建时间 + updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP, -- 更新时间 FOREIGN KEY (feature_id) REFERENCES rtss.feature (id) ON DELETE CASCADE ); diff --git a/rtss-proto-msg b/rtss-proto-msg index a162241..1672a8c 160000 --- a/rtss-proto-msg +++ b/rtss-proto-msg @@ -1 +1 @@ -Subproject commit a1622410919b58683bc0ec059b4f5de575583c13 +Subproject commit 1672a8c0e2b41c4076c1dc9ec852f425dcba21c3 diff --git a/src/cmd.rs b/src/cmd.rs index 83f269c..a3952ff 100644 --- a/src/cmd.rs +++ b/src/cmd.rs @@ -27,7 +27,6 @@ pub struct ServerOpts { impl CmdExecutor for ServerOpts { async fn execute(&self) -> anyhow::Result<()> { - println!("ServerOpts: {:?}", self); let app_config = app_config::AppConfig::new(&self.config_path).expect("Failed to load app config"); let log: rtss_log::Logging = app_config.log.into(); diff --git a/src/db.rs b/src/db.rs index 9cfa67c..9026b87 100644 --- a/src/db.rs +++ b/src/db.rs @@ -22,7 +22,6 @@ impl CmdExecutor for MigrateOpts { async fn execute(&self) -> anyhow::Result<()> { let app_config = app_config::AppConfig::new(&self.config_path).expect("Failed to load app config"); - println!("{:?}", app_config); rtss_db::run_migrations(&app_config.database.url).await } }