adjust mat selection
This commit is contained in:
parent
17030c72ce
commit
bf693aab2a
15 changed files with 548 additions and 186 deletions
|
|
@ -6,6 +6,7 @@ import (
|
|||
"recipe-manager/helpers"
|
||||
"recipe-manager/models"
|
||||
"recipe-manager/services/logger"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"reflect"
|
||||
|
|
@ -28,9 +29,8 @@ type Data struct {
|
|||
taoLogger *logger.TaoLogger
|
||||
}
|
||||
|
||||
func NewData(taoLogger *logger.TaoLogger) *Data {
|
||||
|
||||
countries := []helpers.CountryName{{
|
||||
var (
|
||||
countries = []helpers.CountryName{{
|
||||
CountryID: "tha",
|
||||
CountryName: "Thailand",
|
||||
}, {
|
||||
|
|
@ -41,6 +41,9 @@ func NewData(taoLogger *logger.TaoLogger) *Data {
|
|||
CountryName: "Australia",
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
func NewData(taoLogger *logger.TaoLogger) *Data {
|
||||
|
||||
allRecipeFiles := helpers.ScanRecipeFiles(countries)
|
||||
|
||||
|
|
@ -129,22 +132,35 @@ func (d *Data) GetCurrentRecipe() *models.Recipe {
|
|||
|
||||
func (d *Data) GetRecipe01ByProductCode(filename, countryID, productCode string) (models.Recipe01, error) {
|
||||
|
||||
if filename == "" || filename == d.CurrentFile {
|
||||
for _, v := range d.currentRecipe.Recipe01 {
|
||||
if v.ProductCode == productCode {
|
||||
return v, nil
|
||||
if !strings.Contains(filename, "tmp") {
|
||||
if filename == "" || filename == d.CurrentFile {
|
||||
fmt.Println("GetRecipe01ByProductCode.ReadCurrent", filename, d.CurrentFile)
|
||||
for _, v := range d.currentRecipe.Recipe01 {
|
||||
if v.ProductCode == productCode {
|
||||
return v, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if recipe, ok := d.recipeMap[filename]; ok {
|
||||
for _, v := range recipe.Recipe.Recipe01 {
|
||||
if v.ProductCode == productCode {
|
||||
return v, nil
|
||||
} else if recipe, ok := d.recipeMap[filename]; ok {
|
||||
fmt.Println("GetRecipe01ByProductCode.ReadMap", filename, d.CurrentFile)
|
||||
for _, v := range recipe.Recipe.Recipe01 {
|
||||
if v.ProductCode == productCode {
|
||||
return v, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
d.CurrentFile = filename
|
||||
d.CurrentCountryID = countryID
|
||||
|
||||
for _, v := range countries {
|
||||
if v.CountryName == countryID {
|
||||
d.CurrentCountryID = v.CountryID
|
||||
countryID = v.CountryID
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
recipe, err := helpers.ReadRecipeFile(countryID, filename)
|
||||
|
||||
if err != nil {
|
||||
|
|
@ -179,6 +195,7 @@ func (d *Data) GetRecipe01ByProductCode(filename, countryID, productCode string)
|
|||
|
||||
for _, v := range d.currentRecipe.Recipe01 {
|
||||
if v.ProductCode == productCode {
|
||||
// d.taoLogger.Log.Debug("GetRecipe01ByProductCode", zap.Any("productCode", productCode), zap.Any("result", v))
|
||||
return v, nil
|
||||
}
|
||||
}
|
||||
|
|
@ -186,7 +203,6 @@ func (d *Data) GetRecipe01ByProductCode(filename, countryID, productCode string)
|
|||
return models.Recipe01{}, fmt.Errorf("product code: %s not found", productCode)
|
||||
}
|
||||
|
||||
// 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
|
||||
|
|
@ -203,7 +219,7 @@ func (d *Data) SetValuesToRecipe(base_recipe []models.Recipe01, recipe models.Re
|
|||
|
||||
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]))
|
||||
d.taoLogger.Log.Debug("SetValuesToRecipe", zap.Any("key", k))
|
||||
base_recipe01_Map[k] = v
|
||||
}
|
||||
}
|
||||
|
|
@ -231,16 +247,19 @@ func (d *Data) GetMaterialSetting(countryID, filename string) []models.MaterialS
|
|||
return result
|
||||
}
|
||||
|
||||
if filename == "" || filename == d.CurrentFile {
|
||||
copy(result, d.currentRecipe.MaterialSetting)
|
||||
return result
|
||||
}
|
||||
if !strings.Contains(filename, "tmp") {
|
||||
if filename == "" || filename == d.CurrentFile {
|
||||
copy(result, d.currentRecipe.MaterialSetting)
|
||||
d.taoLogger.Log.Debug("GetMaterialSetting", zap.Any("result", result))
|
||||
return d.currentRecipe.MaterialSetting
|
||||
}
|
||||
|
||||
if recipe, ok := d.recipeMap[filename]; ok {
|
||||
copy(result, recipe.Recipe.MaterialSetting)
|
||||
d.CurrentFile = filename
|
||||
d.CurrentCountryID = countryID
|
||||
return result
|
||||
if recipe, ok := d.recipeMap[filename]; ok {
|
||||
copy(result, recipe.Recipe.MaterialSetting)
|
||||
d.CurrentFile = filename
|
||||
d.CurrentCountryID = countryID
|
||||
return d.currentRecipe.MaterialSetting
|
||||
}
|
||||
}
|
||||
|
||||
d.CurrentFile = filename
|
||||
|
|
@ -250,9 +269,11 @@ func (d *Data) GetMaterialSetting(countryID, filename string) []models.MaterialS
|
|||
if err != nil {
|
||||
d.taoLogger.Log.Error("Error when read recipe file, Return default recipe", zap.Error(err))
|
||||
copy(result, d.currentRecipe.MaterialSetting)
|
||||
return result
|
||||
return d.currentRecipe.MaterialSetting
|
||||
}
|
||||
|
||||
d.taoLogger.Log.Debug("GetMaterialSetting", zap.Any("recipe", recipe.MaterialSetting))
|
||||
|
||||
d.currentRecipe = recipe
|
||||
|
||||
// save to map
|
||||
|
|
@ -274,8 +295,8 @@ func (d *Data) GetMaterialSetting(countryID, filename string) []models.MaterialS
|
|||
TimeStamps: time.Now().Unix(),
|
||||
}
|
||||
|
||||
copy(result, d.currentRecipe.MaterialSetting)
|
||||
return result
|
||||
// copy(result, recipe.MaterialSetting)
|
||||
return recipe.MaterialSetting
|
||||
}
|
||||
|
||||
func (d *Data) GetMaterialCode(ids []uint64, countryID, filename string) []models.MaterialCode {
|
||||
|
|
@ -341,6 +362,39 @@ func (d *Data) GetMaterialCode(ids []uint64, countryID, filename string) []model
|
|||
return resultFilter
|
||||
}
|
||||
|
||||
func (d *Data) GetToppings(countryID, filename string) models.Topping {
|
||||
|
||||
if filename == "" || filename == d.CurrentFile {
|
||||
return d.currentRecipe.Topping
|
||||
} else if recipe, ok := d.recipeMap[filename]; ok {
|
||||
d.CurrentFile = filename
|
||||
return recipe.Recipe.Topping
|
||||
}
|
||||
d.CurrentFile = filename
|
||||
d.CurrentCountryID = countryID
|
||||
recipe, err := helpers.ReadRecipeFile(countryID, filename)
|
||||
|
||||
if err != nil {
|
||||
d.taoLogger.Log.Error("Error when read recipe file, Return default recipe", zap.Error(err))
|
||||
return d.currentRecipe.Topping
|
||||
}
|
||||
|
||||
d.currentRecipe = recipe
|
||||
|
||||
return recipe.Topping
|
||||
}
|
||||
|
||||
func (d *Data) GetToppingsOfRecipe(countryID, filename string, productCode string) ([]models.ToppingSet, error) {
|
||||
recipe, err := d.GetRecipe01ByProductCode(filename, countryID, productCode)
|
||||
|
||||
if err != nil {
|
||||
d.taoLogger.Log.Error("Error when read recipe file, Return default recipe", zap.Error(err))
|
||||
return []models.ToppingSet{}, err
|
||||
}
|
||||
|
||||
return recipe.ToppingSet, nil
|
||||
}
|
||||
|
||||
func (d *Data) GetCountryNameByID(countryID string) (string, error) {
|
||||
for _, country := range d.Countries {
|
||||
if country.CountryID == countryID {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue