add summary & change full import check condition
This commit is contained in:
parent
05a593351d
commit
93c9a9fc54
2 changed files with 195 additions and 5 deletions
|
|
@ -600,6 +600,88 @@ impl Recipe {
|
|||
res_map
|
||||
}
|
||||
|
||||
/// Get all data in this recipe as summary, this does not contain all the field but only id or name.
|
||||
///
|
||||
pub fn get_recipe_data_summary(&mut self) -> RecipeSummary {
|
||||
// mapping Recipe01, MaterialSetting, Topping, MaterialCode
|
||||
|
||||
let recipe01_summary = self
|
||||
.Recipe01
|
||||
.clone()
|
||||
.iter()
|
||||
.map(|r01| Recipe01Summary {
|
||||
productCode: r01.productCode.clone(),
|
||||
name: r01.name.clone().unwrap_or("".to_string()),
|
||||
})
|
||||
.collect::<Vec<Recipe01Summary>>();
|
||||
|
||||
let matset_summary = self
|
||||
.MaterialSetting
|
||||
.clone()
|
||||
.iter()
|
||||
.map(|ms| MaterialSettingSummary {
|
||||
id: ms.id.clone(),
|
||||
materialName: ms
|
||||
.materialName
|
||||
.clone()
|
||||
.unwrap_or(ms.materialOtherName.clone().unwrap_or("".to_string())),
|
||||
})
|
||||
.collect::<Vec<MaterialSettingSummary>>();
|
||||
|
||||
let topping_group_summary = self
|
||||
.Topping
|
||||
.ToppingGroup
|
||||
.clone()
|
||||
.iter()
|
||||
.map(|tg| {
|
||||
if !tg.name.is_empty() {
|
||||
ToppingGroupSummary {
|
||||
groupID: tg.groupID.clone(),
|
||||
name: tg.name.clone(),
|
||||
}
|
||||
} else {
|
||||
ToppingGroupSummary {
|
||||
groupID: tg.groupID.clone(),
|
||||
name: tg.otherName.clone(),
|
||||
}
|
||||
}
|
||||
})
|
||||
.collect::<Vec<ToppingGroupSummary>>();
|
||||
|
||||
let topping_list_summary = self
|
||||
.Topping
|
||||
.ToppingList
|
||||
.clone()
|
||||
.iter()
|
||||
.map(|tpl| {
|
||||
if tpl.name.is_some() {
|
||||
ToppingListSummary {
|
||||
id: tpl.id.clone(),
|
||||
name: tpl.name.clone().unwrap(),
|
||||
}
|
||||
} else {
|
||||
ToppingListSummary {
|
||||
id: tpl.id.clone(),
|
||||
name: tpl.otherName.clone().unwrap_or("".to_string()),
|
||||
}
|
||||
}
|
||||
})
|
||||
.collect::<Vec<ToppingListSummary>>();
|
||||
|
||||
RecipeSummary {
|
||||
Timestamp: self.Timestamp.clone(),
|
||||
MachineSetting: self.MachineSetting.clone(),
|
||||
Recipe01: recipe01_summary,
|
||||
MaterialSetting: matset_summary,
|
||||
Topping: ToppingSummary {
|
||||
ToppingGroup: topping_group_summary,
|
||||
ToppingList: topping_list_summary,
|
||||
},
|
||||
MaterialCode: self.MaterialCode.clone(),
|
||||
extra: self.extra.clone(),
|
||||
}
|
||||
}
|
||||
|
||||
// zone import recipe
|
||||
//
|
||||
//
|
||||
|
|
@ -2046,3 +2128,109 @@ impl Recipe01 {
|
|||
.collect()
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------
|
||||
|
||||
#[allow(non_snake_case)]
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct RecipeSummary {
|
||||
pub Timestamp: String,
|
||||
pub MachineSetting: MachineSetting,
|
||||
pub Recipe01: Vec<Recipe01Summary>,
|
||||
pub MaterialSetting: Vec<MaterialSettingSummary>,
|
||||
pub Topping: ToppingSummary,
|
||||
pub MaterialCode: Vec<MaterialCode>,
|
||||
#[serde(flatten)]
|
||||
pub extra: std::collections::HashMap<String, serde_json::Value>,
|
||||
}
|
||||
|
||||
impl RecipeSummary {
|
||||
pub fn recipe01_contains(&mut self, pd: String) -> bool {
|
||||
let filtered = self
|
||||
.Recipe01
|
||||
.iter()
|
||||
.filter(|r01| r01.productCode.eq(&pd))
|
||||
.collect::<Vec<&Recipe01Summary>>();
|
||||
!filtered.is_empty()
|
||||
}
|
||||
|
||||
#[allow(non_snake_case)]
|
||||
pub fn materialSetting_contains(&mut self, id: Value) -> bool {
|
||||
let filtered = self
|
||||
.MaterialSetting
|
||||
.iter()
|
||||
.filter(|ms| ms.id.eq(&id))
|
||||
.collect::<Vec<&MaterialSettingSummary>>();
|
||||
!filtered.is_empty()
|
||||
}
|
||||
|
||||
#[allow(non_snake_case)]
|
||||
pub fn materialCode_contains(&mut self, mat_id: Value) -> bool {
|
||||
let filtered = self
|
||||
.MaterialCode
|
||||
.iter()
|
||||
.filter(|mc| mc.materialID.eq(&mat_id))
|
||||
.collect::<Vec<&MaterialCode>>();
|
||||
|
||||
!filtered.is_empty()
|
||||
}
|
||||
|
||||
#[allow(non_snake_case)]
|
||||
pub fn toppingList_contains(&mut self, id: Value) -> bool {
|
||||
let filtered = self
|
||||
.Topping
|
||||
.ToppingList
|
||||
.iter()
|
||||
.filter(|tpl| tpl.id.eq(&id))
|
||||
.collect::<Vec<&ToppingListSummary>>();
|
||||
|
||||
!filtered.is_empty()
|
||||
}
|
||||
|
||||
#[allow(non_snake_case)]
|
||||
pub fn toppingGroup_contains(&mut self, gid: Value) -> bool {
|
||||
let filtered = self
|
||||
.Topping
|
||||
.ToppingGroup
|
||||
.iter()
|
||||
.filter(|tg| tg.groupID.eq(&gid))
|
||||
.collect::<Vec<&ToppingGroupSummary>>();
|
||||
|
||||
!filtered.is_empty()
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(non_snake_case)]
|
||||
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)]
|
||||
pub struct Recipe01Summary {
|
||||
pub productCode: String,
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
#[allow(non_snake_case)]
|
||||
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)]
|
||||
pub struct MaterialSettingSummary {
|
||||
pub id: Value,
|
||||
pub materialName: String,
|
||||
}
|
||||
|
||||
#[allow(non_snake_case)]
|
||||
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)]
|
||||
pub struct ToppingSummary {
|
||||
pub ToppingGroup: Vec<ToppingGroupSummary>,
|
||||
pub ToppingList: Vec<ToppingListSummary>,
|
||||
}
|
||||
|
||||
#[allow(non_snake_case)]
|
||||
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)]
|
||||
pub struct ToppingGroupSummary {
|
||||
pub groupID: Value,
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
#[allow(non_snake_case)]
|
||||
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)]
|
||||
pub struct ToppingListSummary {
|
||||
pub id: Value,
|
||||
pub name: String,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -604,9 +604,11 @@ pub fn generate_recipe_sheet_table(country_name: &str, into_version: usize) {
|
|||
/// - Topping
|
||||
///
|
||||
pub fn full_import_data(source: Recipe, mut import_target: Recipe) -> Recipe {
|
||||
let mut target_summary = import_target.get_recipe_data_summary();
|
||||
|
||||
// import menus
|
||||
source.Recipe01.iter().for_each(|r01| {
|
||||
if !import_target.Recipe01.contains(r01) {
|
||||
if !target_summary.recipe01_contains(r01.clone().productCode) {
|
||||
import_target.Recipe01.push(r01.clone());
|
||||
println!(
|
||||
"recipe >> {} {}",
|
||||
|
|
@ -618,7 +620,7 @@ pub fn full_import_data(source: Recipe, mut import_target: Recipe) -> Recipe {
|
|||
|
||||
// import materials
|
||||
source.MaterialSetting.iter().for_each(|ms| {
|
||||
if !import_target.MaterialSetting.contains(ms) {
|
||||
if !target_summary.materialSetting_contains(ms.id.clone()) {
|
||||
import_target.MaterialSetting.push(ms.clone());
|
||||
println!(
|
||||
"mat_set >> {:?} {}",
|
||||
|
|
@ -629,7 +631,7 @@ pub fn full_import_data(source: Recipe, mut import_target: Recipe) -> Recipe {
|
|||
});
|
||||
|
||||
source.MaterialCode.iter().for_each(|mc| {
|
||||
if !import_target.MaterialCode.contains(mc) {
|
||||
if !target_summary.materialCode_contains(mc.materialID.clone()) {
|
||||
import_target.MaterialCode.push(mc.clone());
|
||||
println!("mat_code >> {:?}", mc.materialID);
|
||||
}
|
||||
|
|
@ -637,7 +639,7 @@ pub fn full_import_data(source: Recipe, mut import_target: Recipe) -> Recipe {
|
|||
|
||||
// import new toppings
|
||||
source.Topping.ToppingList.iter().for_each(|tpl| {
|
||||
if !import_target.Topping.ToppingList.contains(tpl) {
|
||||
if !target_summary.toppingList_contains(tpl.id.clone()) {
|
||||
import_target.Topping.ToppingList.push(tpl.clone());
|
||||
println!(
|
||||
"topping_list >> {:?} {}",
|
||||
|
|
@ -647,7 +649,7 @@ pub fn full_import_data(source: Recipe, mut import_target: Recipe) -> Recipe {
|
|||
}
|
||||
});
|
||||
source.Topping.ToppingGroup.iter().for_each(|tg| {
|
||||
if !import_target.Topping.ToppingGroup.contains(tg) {
|
||||
if !target_summary.toppingGroup_contains(tg.groupID.clone()) {
|
||||
import_target.Topping.ToppingGroup.push(tg.clone());
|
||||
println!("topping_group >> {:?} {}", tg.groupID, tg.name);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue