fix country params

This commit is contained in:
pakintada@gmail.com 2024-01-19 14:59:21 +07:00
parent 4ece2cf30c
commit 09d71ac61e
13 changed files with 299 additions and 242 deletions

View file

@ -184,6 +184,8 @@ func NewData(taoLogger *logger.TaoLogger) *Data {
func (d *Data) GetRecipe(countryID, filename string) *models.Recipe {
d.taoLogger.Log.Debug("invoke GetRecipe", zap.String("countryID", countryID), zap.String("filename", filename))
if countryID == "" {
return d.currentRecipe["tha"]
}
@ -194,7 +196,7 @@ func (d *Data) GetRecipe(countryID, filename string) *models.Recipe {
if recipe, ok := d.recipeMap[filename]; ok {
d.CurrentFile[countryID] = filename
d.CurrentCountryID[countryID] = countryID
// d.CurrentCountryID[countryID] = countryID
return recipe.Recipe[countryID]
}
@ -204,13 +206,13 @@ func (d *Data) GetRecipe(countryID, filename string) *models.Recipe {
filename = d.CurrentFile[countryID]
}
d.CurrentFile[countryID] = filename
// d.CurrentFile[countryID] = filename
d.taoLogger.Log.Debug("GetRecipe", zap.String("filename", filename), zap.String("countryID", countryID))
d.CurrentCountryID[countryID] = countryID
// d.CurrentCountryID[countryID] = 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))
d.taoLogger.Log.Error("GetRecipe: Error when read recipe file, Return default recipe", zap.Error(err))
return d.currentRecipe[countryID]
}
@ -248,21 +250,41 @@ func (d *Data) GetRecipe(countryID, filename string) *models.Recipe {
func (d *Data) GetRecipe01ByProductCode(filename, countryID, productCode string) (models.Recipe01, error) {
// try convert
if len(countryID) != 3 {
for k, v := range d.CurrentCountryID {
fmt.Println("GetRecipe01ByProductCode.Iterate", k, v, v == countryID)
if v == countryID {
countryID = k
break
}
}
}
fmt.Println("GetRecipe01ByProductCode", filename, countryID, productCode)
if !strings.Contains(filename, "tmp") {
if filename == "" || filename == d.CurrentFile[countryID] {
fmt.Println("GetRecipe01ByProductCode.ReadCurrent", filename, d.CurrentFile)
// , d.CurrentFile, countryID, "result by country id", len(d.currentRecipe[countryID].Recipe01)
fmt.Println("GetRecipe01ByProductCode.ReadCurrent::filename", filename)
fmt.Println("GetRecipe01ByProductCode.ReadCurrent::countryID", countryID)
fmt.Println("GetRecipe01ByProductCode.ReadCurrent::CurrentFile", d.CurrentFile)
fmt.Println("GetRecipe01ByProductCode.ReadCurrent::CurrentCountryID", d.CurrentCountryID)
for _, v := range d.currentRecipe[countryID].Recipe01 {
if v.ProductCode == productCode {
return v, nil
}
}
fmt.Println("No result in current recipe", countryID)
} else if recipe, ok := d.recipeMap[filename]; ok {
fmt.Println("GetRecipe01ByProductCode.ReadMap", filename, d.CurrentFile)
fmt.Println("GetRecipe01ByProductCode.ReadMap", filename, d.CurrentFile, recipe.Recipe[countryID], "countryID=", countryID)
for _, v := range recipe.Recipe[countryID].Recipe01 {
if v.ProductCode == productCode {
d.taoLogger.Log.Debug("GetRecipe01ByProductCode.getSuccess", zap.Any("fromFile", filename), zap.Any("whereSource", d.recipeMap))
return v, nil
}
}
d.taoLogger.Log.Debug("GetRecipe01ByProductCode.getFail", zap.Any("fromFile", filename), zap.Any("whereSource", d.recipeMap))
}
}
@ -272,12 +294,12 @@ func (d *Data) GetRecipe01ByProductCode(filename, countryID, productCode string)
filename = d.CurrentFile[countryID]
}
d.CurrentFile[countryID] = filename
d.CurrentCountryID[countryID] = countryID
// d.CurrentFile[countryID] = filename
// d.CurrentCountryID[countryID] = countryID
for _, v := range countries {
if v.CountryName == countryID {
d.CurrentCountryID[countryID] = v.CountryID
// d.CurrentCountryID[countryID] = v.CountryID
countryID = v.CountryID
break
}
@ -286,7 +308,7 @@ func (d *Data) GetRecipe01ByProductCode(filename, countryID, productCode string)
recipe, err := helpers.ReadRecipeFile(countryID, filename)
if err != nil {
d.taoLogger.Log.Error("Error when read recipe file, Return default recipe", zap.Error(err))
d.taoLogger.Log.Error("GetRecipe01ByProductCode: Error when read recipe file, Return default recipe", zap.Error(err))
for _, v := range d.currentRecipe[countryID].Recipe01 {
if v.ProductCode == productCode {
return v, nil
@ -373,15 +395,15 @@ func (d *Data) GetMaterialSetting(countryID, filename string) []models.MaterialS
if !strings.Contains(filename, "tmp") {
if filename == "" || filename == d.CurrentFile[countryID] {
copy(result, d.currentRecipe[countryID].MaterialSetting)
d.taoLogger.Log.Debug("GetMaterialSetting", zap.Any("result", result))
// copy(result, d.currentRecipe[countryID].MaterialSetting)
// d.taoLogger.Log.Debug("GetMaterialSetting", zap.Any("result", result))
return d.currentRecipe[countryID].MaterialSetting
}
if recipe, ok := d.recipeMap[filename]; ok {
copy(result, recipe.Recipe[countryID].MaterialSetting)
d.CurrentFile[countryID] = filename
d.CurrentCountryID[countryID] = countryID
// d.CurrentCountryID[countryID] = countryID
return d.currentRecipe[countryID].MaterialSetting
}
}
@ -390,19 +412,19 @@ func (d *Data) GetMaterialSetting(countryID, filename string) []models.MaterialS
filename = d.CurrentFile[countryID]
}
d.taoLogger.Log.Debug("GetMaterialSetting", zap.Any("filename", filename), zap.Any("countryID", countryID))
// d.taoLogger.Log.Debug("GetMaterialSetting", zap.Any("filename", filename), zap.Any("countryID", countryID))
d.CurrentFile[countryID] = filename
d.CurrentCountryID[countryID] = countryID
// d.CurrentFile[countryID] = filename
// d.CurrentCountryID[countryID] = 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))
d.taoLogger.Log.Error("GetMaterialSetting: Error when read recipe file, Return default recipe", zap.Error(err))
copy(result, d.currentRecipe[countryID].MaterialSetting)
return d.currentRecipe[countryID].MaterialSetting
}
d.taoLogger.Log.Debug("GetMaterialSetting", zap.Any("recipe", recipe.MaterialSetting))
// d.taoLogger.Log.Debug("GetMaterialSetting", zap.Any("recipe", recipe.MaterialSetting))
d.currentRecipe[countryID] = recipe
@ -443,12 +465,12 @@ func (d *Data) GetMaterialCode(ids []uint64, countryID, filename string) []model
filename = d.CurrentFile[countryID]
}
d.CurrentFile[countryID] = filename
d.CurrentCountryID[countryID] = countryID
// d.CurrentFile[countryID] = filename
// d.CurrentCountryID[countryID] = 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))
d.taoLogger.Log.Error("GetMaterialCode: Error when read recipe file, Return default recipe", zap.Error(err))
return d.currentRecipe[countryID].MaterialCode
}
@ -510,12 +532,12 @@ func (d *Data) GetToppings(countryID, filename string) models.Topping {
filename = d.CurrentFile[countryID]
}
d.CurrentFile[countryID] = filename
d.CurrentCountryID[countryID] = countryID
// d.CurrentFile[countryID] = filename
// d.CurrentCountryID[countryID] = 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))
d.taoLogger.Log.Error("GetToppings: Error when read recipe file, Return default recipe", zap.Error(err))
return d.currentRecipe[countryID].Topping
}
@ -533,7 +555,7 @@ func (d *Data) GetToppingsOfRecipe(countryID, filename string, productCode strin
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))
d.taoLogger.Log.Error("GetToppingOfRecipe: Error when read recipe file, Return default recipe", zap.Error(err))
return []models.ToppingSet{}, err
}
@ -549,7 +571,7 @@ func (d *Data) GetSubmenusOfRecipe(countryID, filename, productCode string) ([]m
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))
d.taoLogger.Log.Error("GetSubmenusOfRecipe: Error when read recipe file, Return default recipe", zap.Error(err))
return []models.Recipe01{}, err
}