调整数据库默认时间定义
All checks were successful
build / build-rust (push) Successful in 2m57s

修改接口返回为NaiveDateTime
This commit is contained in:
soul-walker 2024-09-19 11:03:05 +08:00
parent 50a0799f28
commit d9b8b38590
10 changed files with 205 additions and 27 deletions

View File

@ -6,7 +6,7 @@ edition = "2021"
[dependencies] [dependencies]
anyhow = { workspace = true } anyhow = { workspace = true }
tokio = { workspace = true, features = ["macros", "rt-multi-thread"] } tokio = { workspace = true, features = ["macros", "rt-multi-thread"] }
serde = { workspace = true } serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true } serde_json = { workspace = true }
chrono = { version = "0.4.38", features = ["serde"] } chrono = { version = "0.4.38", features = ["serde"] }
axum = "0.7.5" axum = "0.7.5"

View File

@ -1,6 +1,6 @@
use async_graphql::{Context, InputObject, Object, SimpleObject}; use async_graphql::{Context, InputObject, Object, SimpleObject};
use async_graphql::{InputType, OutputType}; use async_graphql::{InputType, OutputType};
use chrono::{DateTime, Local}; use chrono::NaiveDateTime;
use rtss_db::common::TableColumn; use rtss_db::common::TableColumn;
use rtss_db::model::DraftDataColumn; use rtss_db::model::DraftDataColumn;
use rtss_db::DraftDataAccessor; use rtss_db::DraftDataAccessor;
@ -282,8 +282,8 @@ pub struct DraftDataWithStringOptions {
pub data: Option<Vec<u8>>, pub data: Option<Vec<u8>>,
pub user_id: i32, pub user_id: i32,
pub is_shared: bool, pub is_shared: bool,
pub created_at: DateTime<Local>, pub created_at: NaiveDateTime,
pub updated_at: DateTime<Local>, pub updated_at: NaiveDateTime,
} }
impl From<rtss_db::model::DraftDataModel> for DraftDataWithStringOptions { impl From<rtss_db::model::DraftDataModel> for DraftDataWithStringOptions {
@ -296,8 +296,8 @@ impl From<rtss_db::model::DraftDataModel> for DraftDataWithStringOptions {
data: value.data, data: value.data,
user_id: value.user_id, user_id: value.user_id,
is_shared: value.is_shared, is_shared: value.is_shared,
created_at: value.created_at, created_at: value.created_at.naive_local(),
updated_at: value.updated_at, updated_at: value.updated_at.naive_local(),
} }
} }
} }
@ -312,8 +312,8 @@ pub struct DraftData<T: OutputType> {
pub data: Option<Vec<u8>>, pub data: Option<Vec<u8>>,
pub user_id: i32, pub user_id: i32,
pub is_shared: bool, pub is_shared: bool,
pub created_at: DateTime<Local>, pub created_at: NaiveDateTime,
pub updated_at: DateTime<Local>, pub updated_at: NaiveDateTime,
} }
impl<T: DataOptions> From<rtss_db::model::DraftDataModel> for DraftData<T> { impl<T: DataOptions> From<rtss_db::model::DraftDataModel> for DraftData<T> {
@ -326,8 +326,8 @@ impl<T: DataOptions> From<rtss_db::model::DraftDataModel> for DraftData<T> {
data: value.data, data: value.data,
user_id: value.user_id, user_id: value.user_id,
is_shared: value.is_shared, is_shared: value.is_shared,
created_at: value.created_at, created_at: value.created_at.naive_local(),
updated_at: value.updated_at, updated_at: value.updated_at.naive_local(),
} }
} }
} }

View File

@ -48,8 +48,8 @@ pub async fn serve(config: ServerConfig) -> anyhow::Result<()> {
.allow_methods([Method::GET, Method::POST]), .allow_methods([Method::GET, Method::POST]),
); );
debug!("Server started at http://{}", config.to_socket_addr()); info!("Server started at http://{}", config.to_socket_addr());
info!("GraphiQL IDE: http://localhost:{}", config.port); debug!("GraphiQL IDE: http://localhost:{}", config.port);
axum::serve( axum::serve(
TcpListener::bind(config.to_socket_addr()).await.unwrap(), TcpListener::bind(config.to_socket_addr()).await.unwrap(),
app, app,

View File

@ -33,6 +33,7 @@ fn main() {
&[ &[
"../../rtss-proto-msg/src/em_data.proto", "../../rtss-proto-msg/src/em_data.proto",
"../../rtss-proto-msg/src/common.proto", "../../rtss-proto-msg/src/common.proto",
"../../rtss-proto-msg/src/iscs_graphic_data.proto",
], ],
&["../../rtss-proto-msg/src/"], &["../../rtss-proto-msg/src/"],
) )

View File

@ -86,7 +86,7 @@ pub struct CommonInfo {
pub transform: ::core::option::Option<Transform>, pub transform: ::core::option::Option<Transform>,
/// 子元素变换 /// 子元素变换
#[prost(message, repeated, tag = "4")] #[prost(message, repeated, tag = "4")]
pub children_transform: ::prost::alloc::vec::Vec<ChildTransform>, pub child_transforms: ::prost::alloc::vec::Vec<ChildTransform>,
} }
/// 数据类型 /// 数据类型
#[derive( #[derive(

View File

@ -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<super::common::Canvas>,
#[prost(message, repeated, tag = "2")]
pub arrows: ::prost::alloc::vec::Vec<Arrow>,
#[prost(message, repeated, tag = "3")]
pub iscs_texts: ::prost::alloc::vec::Vec<IscsText>,
#[prost(message, repeated, tag = "4")]
pub rects: ::prost::alloc::vec::Vec<Rect>,
#[prost(message, repeated, tag = "5")]
pub cctv_buttons: ::prost::alloc::vec::Vec<CctvButton>,
}
#[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<super::common::CommonInfo>,
#[prost(string, tag = "2")]
pub code: ::prost::alloc::string::String,
#[prost(message, repeated, tag = "3")]
pub points: ::prost::alloc::vec::Vec<super::common::Point>,
}
/// 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<super::common::CommonInfo>,
#[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<super::common::CommonInfo>,
#[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<super::common::Point>,
}
/// 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<super::common::CommonInfo>,
#[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<Self> {
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<super::common::CommonInfo>,
#[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<super::common::CommonInfo>,
#[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<super::common::CommonInfo>,
#[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<super::common::CommonInfo>,
#[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<super::common::CommonInfo>,
#[prost(string, tag = "2")]
pub code: ::prost::alloc::string::String,
}

View File

@ -12,8 +12,8 @@ CREATE TABLE
default_release_data_id INT NULL, -- 默认发布数据id default_release_data_id INT NULL, -- 默认发布数据id
user_id INT NOT NULL, -- 创建用户id user_id INT NOT NULL, -- 创建用户id
is_shared BOOLEAN NOT NULL DEFAULT FALSE, -- 是否共享 is_shared BOOLEAN NOT NULL DEFAULT FALSE, -- 是否共享
created_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 'now()', -- 更新时间 updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP, -- 更新时间
UNIQUE (name, user_id) -- 一个用户的草稿名称唯一 UNIQUE (name, user_id) -- 一个用户的草稿名称唯一
); );
@ -58,8 +58,8 @@ CREATE TABLE
used_version_id INT NULL, -- 使用的版本数据id used_version_id INT NULL, -- 使用的版本数据id
user_id INT NOT NULL, -- 发布/更新用户id user_id INT NOT NULL, -- 发布/更新用户id
is_published BOOLEAN NOT NULL DEFAULT TRUE, -- 是否上架 is_published BOOLEAN NOT NULL DEFAULT TRUE, -- 是否上架
created_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 'now()' -- 更新时间 updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP -- 更新时间
); );
-- 注释发布数据表 -- 注释发布数据表
@ -93,7 +93,7 @@ CREATE TABLE
version SERIAL NOT NULL, -- 版本号 version SERIAL NOT NULL, -- 版本号
description TEXT NOT NULL, -- 版本描述 description TEXT NOT NULL, -- 版本描述
user_id INT NOT NULL, -- 发布用户id 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 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, -- 是否上架 is_published BOOLEAN NOT NULL DEFAULT TRUE, -- 是否上架
creator_id INT NOT NULL, -- 创建用户id creator_id INT NOT NULL, -- 创建用户id
updater_id INT NOT NULL, -- 更新用户id updater_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, -- 创建时间
updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT 'now()' -- 更新时间 updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP -- 更新时间
); );
-- 注释仿真feature表 -- 注释仿真feature表
@ -182,8 +182,8 @@ CREATE TABLE
is_published BOOLEAN NOT NULL DEFAULT TRUE, -- 是否上架 is_published BOOLEAN NOT NULL DEFAULT TRUE, -- 是否上架
creator_id INT NOT NULL, -- 创建用户id creator_id INT NOT NULL, -- 创建用户id
updater_id INT NOT NULL, -- 更新用户id updater_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, -- 创建时间
updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT 'now()' -- 更新时间 updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP -- 更新时间
); );
-- 注释仿真feature group表 -- 注释仿真feature group表
@ -224,8 +224,8 @@ CREATE TABLE
user_id INT NOT NULL, -- 用户id user_id INT NOT NULL, -- 用户id
feature_id INT NOT NULL, -- 仿真feature id feature_id INT NOT NULL, -- 仿真feature id
config BYTEA NOT NULL, -- 配置 config BYTEA NOT NULL, -- 配置
created_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 'now()', -- 更新时间 updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP, -- 更新时间
FOREIGN KEY (feature_id) REFERENCES rtss.feature (id) ON DELETE CASCADE FOREIGN KEY (feature_id) REFERENCES rtss.feature (id) ON DELETE CASCADE
); );

@ -1 +1 @@
Subproject commit a1622410919b58683bc0ec059b4f5de575583c13 Subproject commit 1672a8c0e2b41c4076c1dc9ec852f425dcba21c3

View File

@ -27,7 +27,6 @@ pub struct ServerOpts {
impl CmdExecutor for ServerOpts { impl CmdExecutor for ServerOpts {
async fn execute(&self) -> anyhow::Result<()> { async fn execute(&self) -> anyhow::Result<()> {
println!("ServerOpts: {:?}", self);
let app_config = let app_config =
app_config::AppConfig::new(&self.config_path).expect("Failed to load app config"); app_config::AppConfig::new(&self.config_path).expect("Failed to load app config");
let log: rtss_log::Logging = app_config.log.into(); let log: rtss_log::Logging = app_config.log.into();

View File

@ -22,7 +22,6 @@ impl CmdExecutor for MigrateOpts {
async fn execute(&self) -> anyhow::Result<()> { async fn execute(&self) -> anyhow::Result<()> {
let app_config = let app_config =
app_config::AppConfig::new(&self.config_path).expect("Failed to load 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 rtss_db::run_migrations(&app_config.database.url).await
} }
} }