add topping WIP
This commit is contained in:
parent
cabfcdee15
commit
16e0e4f9d8
11 changed files with 460 additions and 26 deletions
|
|
@ -267,10 +267,10 @@ func (d *Data) GetRecipe01ByProductCode(filename, countryID, productCode string)
|
|||
if !strings.Contains(filename, "tmp") {
|
||||
if filename == "" || filename == d.CurrentFile[countryID] {
|
||||
// , 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)
|
||||
// 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 {
|
||||
|
|
@ -283,9 +283,9 @@ func (d *Data) GetRecipe01ByProductCode(filename, countryID, productCode string)
|
|||
}
|
||||
}
|
||||
}
|
||||
fmt.Println("No result in current recipe", countryID)
|
||||
// fmt.Println("No result in current recipe", countryID)
|
||||
} else if recipe, ok := d.recipeMap[filename]; ok {
|
||||
fmt.Println("GetRecipe01ByProductCode.ReadMap", filename, d.CurrentFile, recipe.Recipe[countryID], "countryID=", countryID)
|
||||
// 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))
|
||||
|
|
@ -499,6 +499,100 @@ func (d *Data) GetMaterialSetting(countryID, filename string) []models.MaterialS
|
|||
return recipe.MaterialSetting
|
||||
}
|
||||
|
||||
func (d *Data) GetAllToppingGroups(countryID, filename string) []models.ToppingGroup {
|
||||
if countryID == "" {
|
||||
return d.currentRecipe[countryID].Topping.ToppingGroup
|
||||
}
|
||||
|
||||
if !strings.Contains(filename, ".tmp") {
|
||||
if filename == "" || filename == d.CurrentFile[countryID] {
|
||||
return d.currentRecipe[countryID].Topping.ToppingGroup
|
||||
}
|
||||
if _, ok := d.recipeMap[countryID]; ok {
|
||||
d.CurrentFile[countryID] = filename
|
||||
|
||||
return d.currentRecipe[countryID].Topping.ToppingGroup
|
||||
}
|
||||
}
|
||||
|
||||
if filename == "default" {
|
||||
filename = d.CurrentFile[countryID]
|
||||
}
|
||||
recipe, err := helpers.ReadRecipeFile(countryID, filename)
|
||||
if err != nil {
|
||||
return d.currentRecipe[countryID].Topping.ToppingGroup
|
||||
}
|
||||
|
||||
d.currentRecipe[countryID] = recipe
|
||||
|
||||
if len(d.recipeMap) > 5 { // limit keep in memory 5 version
|
||||
// remove oldest version
|
||||
var oldestVersion string
|
||||
var oldestTime int64
|
||||
for k, v := range d.recipeMap {
|
||||
if oldestTime == 0 || v.TimeStamps < oldestTime {
|
||||
oldestTime = v.TimeStamps
|
||||
oldestVersion = k
|
||||
}
|
||||
}
|
||||
delete(d.recipeMap, oldestVersion)
|
||||
}
|
||||
|
||||
d.recipeMap[filename] = RecipeWithTimeStamps{
|
||||
Recipe: d.currentRecipe,
|
||||
TimeStamps: time.Now().Unix(),
|
||||
}
|
||||
|
||||
return recipe.Topping.ToppingGroup
|
||||
}
|
||||
|
||||
func (d *Data) GetToppingsList(countryID, filename string) []models.ToppingList {
|
||||
// do return default
|
||||
if countryID == "" {
|
||||
return d.currentRecipe[countryID].Topping.ToppingList
|
||||
}
|
||||
|
||||
// handle temporary file
|
||||
if !strings.Contains(filename, ".tmp") {
|
||||
if filename == "" || filename == d.CurrentFile[countryID] {
|
||||
return d.currentRecipe[countryID].Topping.ToppingList
|
||||
}
|
||||
if _, ok := d.recipeMap[countryID]; ok {
|
||||
d.CurrentFile[countryID] = filename
|
||||
return d.currentRecipe[countryID].Topping.ToppingList
|
||||
}
|
||||
}
|
||||
|
||||
if filename == "default" {
|
||||
filename = d.CurrentFile[countryID]
|
||||
}
|
||||
|
||||
recipe, err := helpers.ReadRecipeFile(countryID, filename)
|
||||
if err != nil {
|
||||
return d.currentRecipe[countryID].Topping.ToppingList
|
||||
}
|
||||
|
||||
if len(d.recipeMap) > 5 { // limit keep in memory 5 version
|
||||
// remove oldest version
|
||||
var oldestVersion string
|
||||
var oldestTime int64
|
||||
for k, v := range d.recipeMap {
|
||||
if oldestTime == 0 || v.TimeStamps < oldestTime {
|
||||
oldestTime = v.TimeStamps
|
||||
oldestVersion = k
|
||||
}
|
||||
}
|
||||
delete(d.recipeMap, oldestVersion)
|
||||
}
|
||||
|
||||
d.recipeMap[filename] = RecipeWithTimeStamps{
|
||||
Recipe: d.currentRecipe,
|
||||
TimeStamps: time.Now().Unix(),
|
||||
}
|
||||
|
||||
return recipe.Topping.ToppingList
|
||||
}
|
||||
|
||||
func (d *Data) GetMaterialCode(ids []uint64, countryID, filename string) []models.MaterialCode {
|
||||
var result []models.MaterialCode
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue