add load from select save
This commit is contained in:
parent
f721517f25
commit
17030c72ce
10 changed files with 229 additions and 53 deletions
|
|
@ -8,6 +8,8 @@ import (
|
|||
"recipe-manager/services/logger"
|
||||
"time"
|
||||
|
||||
"reflect"
|
||||
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
|
|
@ -84,6 +86,7 @@ func (d *Data) GetRecipe(countryID, filename string) *models.Recipe {
|
|||
|
||||
// change current version and read new recipe
|
||||
d.CurrentFile = filename
|
||||
d.taoLogger.Log.Debug("GetRecipe", zap.String("filename", filename), zap.String("countryID", countryID))
|
||||
d.CurrentCountryID = countryID
|
||||
recipe, err := helpers.ReadRecipeFile(countryID, filename)
|
||||
|
||||
|
|
@ -183,15 +186,41 @@ func (d *Data) GetRecipe01ByProductCode(filename, countryID, productCode string)
|
|||
return models.Recipe01{}, fmt.Errorf("product code: %s not found", productCode)
|
||||
}
|
||||
|
||||
func (d *Data) SetValuesToRecipe(recipe models.Recipe01) {
|
||||
for index, v := range d.currentRecipe.Recipe01 {
|
||||
// FIXME: saved in log but not actual file
|
||||
func (d *Data) SetValuesToRecipe(base_recipe []models.Recipe01, recipe models.Recipe01) {
|
||||
not_found := false
|
||||
global_idx := 0
|
||||
for index, v := range base_recipe {
|
||||
if v.ProductCode == recipe.ProductCode {
|
||||
// Log.Debug("SetValuesToRecipe", zap.Any("old", v), zap.Any("new", recipe))
|
||||
// v = recipe
|
||||
d.currentRecipe.Recipe01[index] = recipe
|
||||
// TODO: change only changed values
|
||||
|
||||
// transform to map
|
||||
base_recipe01_Map := v.ToMap()
|
||||
|
||||
recipe01_Map := recipe.ToMap()
|
||||
|
||||
for k, v := range recipe01_Map {
|
||||
if !reflect.DeepEqual(base_recipe01_Map[k], v) {
|
||||
d.taoLogger.Log.Debug("SetValuesToRecipe", zap.Any("key", k), zap.Any("value", v), zap.Any("old", base_recipe01_Map[k]), zap.Any("new", recipe01_Map[k]))
|
||||
base_recipe01_Map[k] = v
|
||||
}
|
||||
}
|
||||
|
||||
base_recipe[index] = base_recipe[index].FromMap(base_recipe01_Map)
|
||||
|
||||
not_found = false
|
||||
break
|
||||
} else {
|
||||
not_found = true
|
||||
global_idx = index
|
||||
}
|
||||
}
|
||||
|
||||
if not_found {
|
||||
base_recipe[global_idx+1] = recipe
|
||||
}
|
||||
}
|
||||
|
||||
func (d *Data) GetMaterialSetting(countryID, filename string) []models.MaterialSetting {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue