add topping recipe display & fix bugs

This commit is contained in:
pakintada@gmail.com 2024-02-07 15:39:19 +07:00
parent 7d6988f581
commit ece4cef205
8 changed files with 421 additions and 33 deletions

View file

@ -499,6 +499,85 @@ func (d *Data) SetValuesToRecipe(base_recipe []models.Recipe01, recipe models.Re
}
}
func (d *Data) SetValuesToMaterialSetting(base_mat_setting []models.MaterialSetting, updated_mat_setting models.MaterialSetting) {
not_found := false
global_idx := 0
for index, v := range base_mat_setting {
// find matched id
if v.ID == updated_mat_setting.ID {
// change only changed values
for k, v := range updated_mat_setting.ToMap() {
if !reflect.DeepEqual(base_mat_setting[index].ToMap()[k], v) {
d.taoLogger.Log.Debug("SetValuesToMaterialSetting", zap.Any("key", k), zap.Any("old", base_mat_setting[index].ToMap()[k]), zap.Any("new", v))
base_mat_setting[index].ToMap()[k] = v
}
}
} else {
not_found = true
global_idx = index
}
}
// is new value
if not_found {
base_mat_setting[global_idx+1] = updated_mat_setting
}
}
func (d *Data) SetValuesToToppingList(base_topping_list []models.ToppingList, updated_topping_list models.ToppingList) {
not_found := false
global_idx := 0
for index, v := range base_topping_list {
// find matched id
if v.ID == updated_topping_list.ID {
// change only changed values
for k, v := range updated_topping_list.ToMap() {
if !reflect.DeepEqual(base_topping_list[index].ToMap()[k], v) {
d.taoLogger.Log.Debug("SetValuesToToppingList", zap.Any("key", k), zap.Any("old", base_topping_list[index].ToMap()[k]), zap.Any("new", v))
base_topping_list[index].ToMap()[k] = v
}
}
} else {
not_found = true
global_idx = index
}
}
// is new value
if not_found {
base_topping_list[global_idx+1] = updated_topping_list
}
}
func (d *Data) SetValuesToToppingGroupList(base_topping_group_list []models.ToppingGroup, updated_topping_group_list models.ToppingGroup) {
not_found := false
global_idx := 0
for index, v := range base_topping_group_list {
// find matched id
if v.GroupID == updated_topping_group_list.GroupID {
// change only changed values
for k, v := range updated_topping_group_list.ToMap() {
if !reflect.DeepEqual(base_topping_group_list[index].ToMap()[k], v) {
d.taoLogger.Log.Debug("SetValuesToToppingGroup", zap.Any("key", k), zap.Any("old", base_topping_group_list[index].ToMap()[k]), zap.Any("new", v))
base_topping_group_list[index].ToMap()[k] = v
}
}
} else {
not_found = true
global_idx = index
}
}
// is new value
if not_found {
base_topping_group_list[global_idx+1] = updated_topping_group_list
}
}
func (d *Data) GetMaterialSetting(countryID, filename string) []models.MaterialSetting {
result := make([]models.MaterialSetting, 0)