From 37d9ae54743db6397a93b5d739e7ccd5282e3c1d Mon Sep 17 00:00:00 2001 From: ultrageese Date: Sat, 20 Jun 2026 20:01:56 +1000 Subject: [PATCH] =?UTF-8?q?=D0=BF=D0=B0=D0=BC=D0=BF=D0=B0=D1=80=D0=B0?= =?UTF-8?q?=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 5 +---- code/src/database.rs | 34 ++++++++++++++++++++++++++++++++++ code/src/models.rs | 26 +++++++++++++++++++------- code/src/recipe_tab.rs | 8 +++++++- 4 files changed, 61 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 57eae64..1958a8a 100644 --- a/README.md +++ b/README.md @@ -6,12 +6,9 @@ - [x] Сырья - [ ] Произведённой продукции - [ ] Доходов от продажи продукции -- [ ] Зарплат сотрудникам +- [x] Зарплат сотрудникам Помимо этого, система позволяет: - [ ] Составлять рецепты, используя доступное сырьё и оборудование - [ ] Использовать рецепты при учёте произведённой продукции, позволяя отслеживать, сколько и какого сырья потребуется на производство определённого объёма продукции. -//Если оно выдаёт странную ошибку 0xc0000005 на винде: -$env:WGPU_BACKEND="dx12" - в повершеле -set WGPU_BACKEND=dx12 - в не-повершеле \ No newline at end of file diff --git a/code/src/database.rs b/code/src/database.rs index bb80bcd..fc69b6a 100644 --- a/code/src/database.rs +++ b/code/src/database.rs @@ -404,6 +404,40 @@ impl DBOperator { Err(_) => Ok(false), } } + pub async fn get_recipes(&self) -> Result, sqlx::Error> { + let pre_ret = sqlx::query_as::<_, RecipeRow>("SELECT * FROM recipe") + .fetch_all(&self.pool) + .await + .unwrap_or(Vec::new()); + + let ret: Vec = Vec::new(); + let elements = self.get_recipe_elements().await.unwrap_or(Vec::new()); + for pr in pre_ret.iter() {} + Ok(ret) + } + pub async fn get_recipe_elements(&self) -> Result, sqlx::Error> { + let pre_ret = sqlx::query_as::<_, RecipeElementRow>("SELECT id, recipe_id, material_id, equipment_id, quantity FROM Brewery.recipe_element;").fetch_all(&self.pool).await; + + let mats = self.get_materials().await.unwrap(); + let eqs = self.get_equipment().await.unwrap(); + let ret: Vec = Vec::new(); + for re in pre_ret.unwrap().iter() { + let mat = mats.iter().find(|m| m.id == re.material_id); + let eq = eqs.iter().find(|e| e.id == re.equipment_id); + match (mat, eq) { + (Some(m), Some(e)) => { + ret.push(RecipeElement { + id: re.id, + material: m.clone(), + equipment: e.clone(), + quantity: re.quantity, + }); + } + (_, _) => {} + } + } + Ok(ret) + } } pub async fn estabilish_connection() -> Result<(), sqlx::Error> { diff --git a/code/src/models.rs b/code/src/models.rs index 2ad1322..d22fa74 100644 --- a/code/src/models.rs +++ b/code/src/models.rs @@ -92,15 +92,27 @@ pub struct MaterialCategory { pub name: String, } pub struct RecipeElement { - id: i32, - material: Material, - equipment: Equipment, - quantity: i32, + pub id: i32, + pub material: Material, + pub equipment: Equipment, + pub quantity: i32, +} +#[derive(FromRow)] +pub struct RecipeElementRow { + pub id: i32, + pub material_id: i32, + pub equipment_id: i32, + pub quantity: i32, } pub struct Recipe { - id: i32, - name: String, - elements: std::vec::Vec, + pub id: i32, + pub name: String, + pub elements: std::vec::Vec, +} +#[derive(FromRow)] +pub struct RecipeRow { + pub id: i32, + pub name: String, } pub struct Client { id: i32, diff --git a/code/src/recipe_tab.rs b/code/src/recipe_tab.rs index ce19908..c777d0b 100644 --- a/code/src/recipe_tab.rs +++ b/code/src/recipe_tab.rs @@ -50,6 +50,12 @@ impl egui_dock::TabViewer for RecipeTabViewer { impl Default for RecipeTabViewer { fn default() -> Self { - Self { is_admin: false } + let rt = tokio::runtime::Runtime::new().unwrap(); + let db_oper = rt.block_on(async{DBOperator::new().await}); + Self { is_admin: false, + rt, + db_oper, + recipes: + } } }