From 6f138d4b98ae8f4fcfb6a81b9e48c25ca0dfbfab Mon Sep 17 00:00:00 2001 From: Pakin Date: Mon, 4 Aug 2025 10:25:25 +0700 Subject: [PATCH 1/4] Update import to auto detect mat instead of fixed array --- src/recipe_functions/import.rs | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/recipe_functions/import.rs b/src/recipe_functions/import.rs index 28c0001..7b66a15 100644 --- a/src/recipe_functions/import.rs +++ b/src/recipe_functions/import.rs @@ -353,17 +353,14 @@ pub fn generate_recipe_sheet_table(country_name: &str, into_version: usize) { recipe_table.set_config(insert_later_config); - match country_name { - "sgp" => { - info!("SGP last update [24.02.2025]"); - recipe_table.set_header(Headers::get_recipe_table_sgp_24022025()); - } - "dubai" => { - info!("UAE last update [16.05.2025]"); - recipe_table.set_header(Headers::get_recipe_table_dubai_16052025()); - } - _ => {} - } + // auto detect + // + let mut mat_header = Vec::new(); + latest_recipe.MaterialSetting.iter().for_each(|ms| { + mat_header.push(ms.id.as_str().unwrap()); + }); + + recipe_table.set_header(mat_header); let mut material_names = Vec::new(); From 3d268e6d0a22a3b1674e84055419dc692f4dff57 Mon Sep 17 00:00:00 2001 From: Pakin Date: Mon, 4 Aug 2025 10:56:39 +0700 Subject: [PATCH 2/4] fix header borrow bug --- src/previews/csvf.rs | 4 ++++ src/recipe_functions/import.rs | 12 ++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/previews/csvf.rs b/src/previews/csvf.rs index adea1f8..020efe0 100644 --- a/src/previews/csvf.rs +++ b/src/previews/csvf.rs @@ -50,6 +50,10 @@ impl Table { .collect::>(); } + pub fn set_headers(&mut self, headers: Vec) { + self.header = headers; + } + pub fn get_current_header(self) -> Vec { self.header } diff --git a/src/recipe_functions/import.rs b/src/recipe_functions/import.rs index 7b66a15..d43a292 100644 --- a/src/recipe_functions/import.rs +++ b/src/recipe_functions/import.rs @@ -356,11 +356,15 @@ pub fn generate_recipe_sheet_table(country_name: &str, into_version: usize) { // auto detect // let mut mat_header = Vec::new(); - latest_recipe.MaterialSetting.iter().for_each(|ms| { - mat_header.push(ms.id.as_str().unwrap()); - }); + mat_header.extend( + latest_recipe + .MaterialSetting + .iter() + .map(|ms| ms.id.as_u64().unwrap().to_string()) + .collect::>(), + ); - recipe_table.set_header(mat_header); + recipe_table.set_headers(mat_header); let mut material_names = Vec::new(); From 447ec7e78aaa968d7cd40be9ee3a8f0e39edc878 Mon Sep 17 00:00:00 2001 From: Pakin Date: Mon, 4 Aug 2025 12:26:26 +0700 Subject: [PATCH 3/4] fix missing headers --- src/recipe_functions/import.rs | 54 +++++++++++++++++----------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/src/recipe_functions/import.rs b/src/recipe_functions/import.rs index d43a292..63d6898 100644 --- a/src/recipe_functions/import.rs +++ b/src/recipe_functions/import.rs @@ -355,7 +355,7 @@ pub fn generate_recipe_sheet_table(country_name: &str, into_version: usize) { // auto detect // - let mut mat_header = Vec::new(); + let mut mat_header = vec!["Name".to_string(), "ProductCode".to_string()]; mat_header.extend( latest_recipe .MaterialSetting @@ -454,16 +454,16 @@ pub fn generate_recipe_sheet_table(country_name: &str, into_version: usize) { if header_idx > 1 && header.eq(¤t_material.to_string()) { // search mat settings for further info - if rpl.productCode.clone().ends_with("0090") { - debug!( - "MAT [{}]: {} --> {} = pow:{:?},sy:{:?}", - rpl.productCode.clone(), - header_idx, - repl.materialPathId.clone(), - repl.powderGram, - repl.syrupGram - ); - } + // if rpl.productCode.clone().ends_with("0090") { + // debug!( + // "MAT [{}]: {} --> {} = pow:{:?},sy:{:?}", + // rpl.productCode.clone(), + // header_idx, + // repl.materialPathId.clone(), + // repl.powderGram, + // repl.syrupGram + // ); + // } let mat_setting = latest_recipe .search_material_settings(current_material.to_string()); @@ -489,27 +489,27 @@ pub fn generate_recipe_sheet_table(country_name: &str, into_version: usize) { } recipe::MaterialType::Syrup => { // debug - if rpl.productCode.clone().ends_with("0090") { - println!( - "SYRUP [{}]: {} --> {} = {:?}", - rpl.productCode.clone(), - header_idx, - repl.materialPathId.clone(), - repl.syrupGram - ); - } + // if rpl.productCode.clone().ends_with("0090") { + // println!( + // "SYRUP [{}]: {} --> {} = {:?}", + // rpl.productCode.clone(), + // header_idx, + // repl.materialPathId.clone(), + // repl.syrupGram + // ); + // } recipe_brewing_values_only[header_idx] += repl.syrupGram.as_i64().unwrap(); } recipe::MaterialType::Soda => { - println!( - "SODA [{}]: {} --> {} = {:?}", - rpl.productCode.clone(), - header_idx, - repl.materialPathId.clone(), - repl.syrupGram - ); + // println!( + // "SODA [{}]: {} --> {} = {:?}", + // rpl.productCode.clone(), + // header_idx, + // repl.materialPathId.clone(), + // repl.syrupGram + // ); recipe_brewing_values_only[header_idx] += repl.syrupGram.as_i64().unwrap(); From 2138db21ebd81789fb6340d5a806720add637389 Mon Sep 17 00:00:00 2001 From: Pakin Date: Mon, 4 Aug 2025 13:05:40 +0700 Subject: [PATCH 4/4] add full import data --- src/recipe_functions/import.rs | 47 +++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/src/recipe_functions/import.rs b/src/recipe_functions/import.rs index 63d6898..b7ff5cf 100644 --- a/src/recipe_functions/import.rs +++ b/src/recipe_functions/import.rs @@ -5,7 +5,7 @@ use serde_json::{Number, Value}; use super::common::*; use crate::{ - models::recipe::{self, PartialRecipe}, + models::recipe::{self, PartialRecipe, Recipe}, previews::{csvf::*, header::Headers}, }; @@ -591,3 +591,48 @@ pub fn generate_recipe_sheet_table(country_name: &str, into_version: usize) { recipe_table.add_column_desciption(0, material_names); recipe_table.generate_save_file("./test_result/recipe.csv"); } + +/// import only new data from source to target +/// +/// `import_target` must be mutable +/// +/// This only update the following fields +/// +/// - Recipe01 +/// - MaterialSetting +/// - MaterialCode +/// - Topping +/// +pub fn full_import_data(source: Recipe, mut import_target: Recipe) { + // import menus + source.Recipe01.iter().for_each(|r01| { + if !import_target.Recipe01.contains(r01) { + import_target.Recipe01.push(r01.clone()); + } + }); + + // import materials + source.MaterialSetting.iter().for_each(|ms| { + if !import_target.MaterialSetting.contains(ms) { + import_target.MaterialSetting.push(ms.clone()); + } + }); + + source.MaterialCode.iter().for_each(|mc| { + if !import_target.MaterialCode.contains(mc) { + import_target.MaterialCode.push(mc.clone()); + } + }); + + // import new toppings + source.Topping.ToppingList.iter().for_each(|tpl| { + if !import_target.Topping.ToppingList.contains(tpl) { + import_target.Topping.ToppingList.push(tpl.clone()); + } + }); + source.Topping.ToppingGroup.iter().for_each(|tg| { + if !import_target.Topping.ToppingGroup.contains(tg) { + import_target.Topping.ToppingGroup.push(tg.clone()); + } + }); +}