diff --git a/code/.gitignore b/code/.gitignore index 09458c5..b6516f2 100644 --- a/code/.gitignore +++ b/code/.gitignore @@ -5,4 +5,5 @@ target *.pdb -**/mutants.out*/ \ No newline at end of file +**/mutants.out*/ +.env \ No newline at end of file diff --git a/code/Cargo.lock b/code/Cargo.lock index e1f95eb..a685d61 100644 --- a/code/Cargo.lock +++ b/code/Cargo.lock @@ -687,6 +687,7 @@ version = "0.1.0" dependencies = [ "chrono", "diesel", + "dotenv", "eframe", "egui", "egui_dock", @@ -928,6 +929,12 @@ dependencies = [ "litrs", ] +[[package]] +name = "dotenv" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77c90badedccf4105eca100756a0b1289e191f6fcbdadd3cee1d2f614f97da8f" + [[package]] name = "downcast-rs" version = "1.2.1" @@ -3080,11 +3087,22 @@ dependencies = [ "num-traits", "rand", "rkyv", + "rust_decimal_macros", "serde", "serde_json", "wasm-bindgen", ] +[[package]] +name = "rust_decimal_macros" +version = "1.40.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74a5a6f027e892c7a035c6fddb50435a1fbf5a734ffc0c2a9fed4d0221440519" +dependencies = [ + "quote", + "syn 2.0.117", +] + [[package]] name = "rustc-hash" version = "1.1.0" diff --git a/code/Cargo.toml b/code/Cargo.toml index 5a5f01a..2bcd11d 100644 --- a/code/Cargo.toml +++ b/code/Cargo.toml @@ -6,8 +6,9 @@ edition = "2024" [dependencies] chrono = { version = "0.4.44", features = ["serde"] } diesel = { version = "2.3.9", features = ["mysql", "chrono"] } +dotenv = "0.15.0" eframe = "0.34.2" egui = "0.34.2" egui_dock = "0.19.1" egui_extras = "0.34.2" -rust_decimal = "1.42.0" +rust_decimal = {version = "1.42.0", features = ["macros"]} diff --git a/code/src/app.rs b/code/src/app.rs index ee61dbb..dbca42c 100644 --- a/code/src/app.rs +++ b/code/src/app.rs @@ -17,7 +17,6 @@ struct Tab{ tab_type: TabTypes, title: String, } - pub struct App{ tree: egui_dock::DockState, } @@ -53,33 +52,54 @@ impl eframe::App for App{ fn ui(&mut self, ui: &mut egui::Ui, _frame: &mut eframe::Frame){ DockArea::new(&mut self.tree) .style(Style::from_egui(ui.style().as_ref())) - .show_inside(ui, &mut MainTabViewer {}); + .show_inside(ui, &mut MainTabViewer { + equipment: vec![ + crate::models::Equipment::default(), + crate::models::Equipment::default(), + crate::models::Equipment::default(), + crate::models::Equipment::default(), + ] + }); } } -struct MainTabViewer {} +struct MainTabViewer { + equipment: std::vec::Vec, +} impl MainTabViewer{ fn show_equipment(&mut self, ui: &mut egui::Ui){ - use egui_extras::{Column,TableBuilder}; - let text_height =egui::TextStyle::Body.resolve(ui.style()).size; - let available_heigh = ui.available_height(); - let mut table = TableBuilder::new(ui) - .striped(true) - .resizable(false) - .cell_layout(egui::Layout::left_to_right(egui::Align::Center)) - .column(Column::auto()) - .column(Column::remainder() - .at_least(40.0) - .clip(true) - .resizable(true), - ) - .column(Column::auto()) - .column(Column::remainder()) - .column(Column::remainder()) - .min_scrolled_height(0.0) - .max_scroll_height(available_heigh); - table = table.sense(egui::Sense::click()); - + // use egui_extras::{Column,TableBuilder}; + // let text_height =egui::TextStyle::Body.resolve(ui.style()).size; + // let available_heigh = ui.available_height(); + // let mut table = TableBuilder::new(ui) + // .striped(true) + // .resizable(false) + // .cell_layout(egui::Layout::left_to_right(egui::Align::Center)) + // .column(Column::auto()) + // .column(Column::remainder() + // .at_least(40.0) + // .clip(true) + // .resizable(true), + // ) + // .column(Column::auto()) + // .column(Column::remainder()) + // .column(Column::remainder()) + // .min_scrolled_height(0.0) + // .max_scroll_height(available_heigh); + // table = table.sense(egui::Sense::click()); + //Это таблицы, с ними надо разобраться! + + for eq in self.equipment.clone() { + ui.push_id("shit".to_owned(), |ui|{ + egui::CollapsingHeader::new(&eq.name) + .default_open(false) + .show(ui, |ui|{ + ui.label(eq.inv_number); + ui.label(eq.worker.full_name); + }); + }); + + } } diff --git a/code/src/database.rs b/code/src/database.rs new file mode 100644 index 0000000..140bc81 --- /dev/null +++ b/code/src/database.rs @@ -0,0 +1,16 @@ +use diesel::prelude::*; +use dotenv::dotenv; +use crate::schema::equipment::dsl::*; +use crate::schema::worker::dsl::*; + +pub fn estabilish_connection() -> MysqlConnection{ + dotenv().ok(); + let db_url = dotenv::var("DATABASE_URL").expect("DATABASE_URL установи!"); + MysqlConnection::establish(&db_url) + .unwrap_or_else(|_| panic!("Не коннектится!")) + } + +pub fn get_positions() -> std::vec::Vec{ + let ret: std::vec::Vec; + ret +} \ No newline at end of file diff --git a/code/src/main.rs b/code/src/main.rs index abff01c..376f5ed 100644 --- a/code/src/main.rs +++ b/code/src/main.rs @@ -1,8 +1,10 @@ #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] mod app; mod models; +mod database; +mod schema; fn main() -> eframe::Result{ - + database::estabilish_connection(); let native_opts = eframe::NativeOptions { viewport: egui::ViewportBuilder::default() .with_inner_size([400.0,300.0]) diff --git a/code/src/models.rs b/code/src/models.rs index dd3a9f4..eaaeb95 100644 --- a/code/src/models.rs +++ b/code/src/models.rs @@ -1,63 +1,100 @@ -struct Position{ +use diesel::{Selectable, deserialize::Queryable}; + +use crate::schema::{self, *}; + + +#[derive(Default, Clone, Hash,Queryable,Selectable)] +#[diesel(table_name=schema::position)] +pub struct Position{ id: i32, name: String, wage: rust_decimal::Decimal, } -struct Worker{ - id: i32, - full_name: String, - hire_date: chrono::NaiveDateTime, - position: Position, - is_fired: bool, +#[derive(Queryable,Selectable)] +#[diesel(table_name=schema::worker)] +pub struct WorkerRow{ + pub id:i32, + pub full_name: String, + pub hire_date: chrono::DateTime, + pub position_id: i32, + pub is_fired:bool } -struct Salary{ + +#[derive(Default, Clone, Hash)] +pub struct Worker{ + pub id: i32, + pub full_name: String, + pub hire_date: chrono::DateTime, + pub position: Position, + pub is_fired: bool, +} +#[derive(Queryable,Selectable)] +#[diesel(table_name=schema::salary)] +pub struct SalaryRow{ + pub id: i32, + pub worker_id: i32, + pub salary_size: rust_decimal::Decimal, + pub salary_date: chrono::DateTime, +} +pub struct Salary{ id: i32, worker: Worker, salary_size: rust_decimal::Decimal, - salary_date: chrono::NaiveDateTime, + salary_date: chrono::DateTime, } -struct Equipment{ - id: i32, - inv_number: String, - maintenance_date: chrono::NaiveDateTime, - worker: Worker, +#[derive(Queryable, Selectable)] +#[diesel(table_name= schema::equipment)] +pub struct EquipmentRow{ + pub id: i32, + pub name: String, + pub inv_number: String, + pub maintenance_date: chrono::DateTime, + pub worker_id: i32, } -struct Material{ +#[derive(Default, Clone, Hash)] +pub struct Equipment{ + pub id: i32, + pub name: String, + pub inv_number: String, + pub maintenance_date: chrono::DateTime, + pub worker: Worker, +} +pub struct Material{ id: i32, name: String, quantity: i32, category: String } -struct RecipeElement{ +pub struct RecipeElement{ id:i32, material: Material, equipment: Equipment, quantity: i32 } -struct Recipe{ +pub struct Recipe{ id: i32, name: String, elements: std::vec::Vec, } -struct Client{ +pub struct Client{ id: i32, name: String, address: String } -struct Order<'a>{ +pub struct Order<'a>{ id: i32, client: Client, - order_date: chrono::NaiveDateTime, + order_date: chrono::DateTime, total_amount: rust_decimal::Decimal, elements: std::vec::Vec> } -struct OrderElement<'a>{ +pub struct OrderElement<'a>{ id: i32, product: Product<'a>, quantity: i32, total_amount: rust_decimal::Decimal } -struct Product<'a>{ +pub struct Product<'a>{ id: i32, recipe: &'a Recipe, volume: f64, diff --git a/code/src/repository.rs b/code/src/repository.rs deleted file mode 100644 index e69de29..0000000 diff --git a/code/src/schema.rs b/code/src/schema.rs new file mode 100644 index 0000000..4573208 --- /dev/null +++ b/code/src/schema.rs @@ -0,0 +1,46 @@ +use diesel::*; +table!{ + equipment(id){ + id -> Integer, + inv_number -> VarChar, + maintenance_date -> Datetime, + worker_id -> Integer, + name -> VarChar, + + } +} +table! { + salary(id){ + id -> Integer, + worker_id -> Integer, + salary_size -> Decimal, + salary_date -> Datetime + } +} +table! { + position(id){ + id -> Integer, + name -> VarChar, + wage -> Decimal + } +} +table! { + worker(id){ + id -> Integer, + position_id -> Integer, + hire_date -> Datetime, + is_fired -> Bool, + full_name -> VarChar + } +} + +joinable!(equipment -> worker(worker_id)); +joinable!(worker -> position(position_id)); +joinable!(salary -> worker(worker_id)); + +allow_tables_to_appear_in_same_query!( + equipment, + salary, + position, + worker, +); \ No newline at end of file