adjust mat selection
This commit is contained in:
parent
17030c72ce
commit
bf693aab2a
15 changed files with 548 additions and 186 deletions
|
|
@ -40,13 +40,20 @@ func (rs *recipeService) GetRecipeDetail(request *contracts.RecipeDetailRequest)
|
|||
// DEBUG: picture
|
||||
rs.taoLogger.Log.Debug("GetRecipeDetail", zap.String("picture", recipe.UriData))
|
||||
|
||||
uri_img := recipe.UriData
|
||||
uri_img = strings.TrimPrefix(uri_img, "img=")
|
||||
// if strings.HasPrefix(uri_img, "img=") {
|
||||
|
||||
// uri_img = uri_img[len("img="):]
|
||||
// }
|
||||
|
||||
result := contracts.RecipeDetailResponse{
|
||||
Name: recipe.Name,
|
||||
OtherName: recipe.OtherName,
|
||||
Description: recipe.Description,
|
||||
OtherDescription: recipe.OtherDescription,
|
||||
LastUpdated: recipe.LastChange,
|
||||
Picture: recipe.UriData[len("img="):], // remove "img=" prefix
|
||||
Picture: uri_img, // remove "img=" prefix
|
||||
}
|
||||
|
||||
return result, nil
|
||||
|
|
@ -60,6 +67,8 @@ func (rs *recipeService) GetRecipeDetailMat(request *contracts.RecipeDetailReque
|
|||
return contracts.RecipeDetailMatListResponse{}, fmt.Errorf("country name: %s not found", request.Country)
|
||||
}
|
||||
|
||||
// rs.taoLogger.Log.Debug("GetRecipeDetailMat", zap.Any("request", request))
|
||||
|
||||
recipe, err := rs.db.GetRecipe01ByProductCode(request.Filename, request.Country, request.ProductCode)
|
||||
|
||||
if err != nil {
|
||||
|
|
@ -73,19 +82,46 @@ func (rs *recipeService) GetRecipeDetailMat(request *contracts.RecipeDetailReque
|
|||
}
|
||||
}
|
||||
|
||||
// rs.taoLogger.Log.Debug("GetRecipeDetailMat", zap.Any("matIds", matIds))
|
||||
|
||||
matsCode := rs.db.GetMaterialCode(matIds, countryID, request.Filename)
|
||||
|
||||
materials := []models.MaterialSetting{}
|
||||
matsSetting := rs.db.GetMaterialSetting(countryID, request.Filename)
|
||||
|
||||
// rs.taoLogger.Log.Debug("GetRecipeDetailMat", zap.Any("matsSetting", matsSetting))
|
||||
|
||||
for _, v := range matsSetting {
|
||||
// rs.taoLogger.Log.Debug("GetRecipeDetailMat,Iterate", zap.Any("mats", v.ID))
|
||||
for _, mat := range matIds {
|
||||
if v.ID == mat {
|
||||
materials = append(materials, v)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// rs.taoLogger.Log.Debug("GetRecipeDetailMat", zap.Any("matsCode", materials))
|
||||
|
||||
result := contracts.RecipeDetailMatListResponse{
|
||||
Result: []contracts.RecipeDetailMat{},
|
||||
}
|
||||
|
||||
for _, v := range recipe.Recipes {
|
||||
for _, mat := range matsCode {
|
||||
if v.MaterialPathId == int(mat.MaterialID) {
|
||||
for _, mat := range materials {
|
||||
if v.MaterialPathId == int(mat.ID) {
|
||||
mat_name := ""
|
||||
for _, m := range matsCode {
|
||||
if m.MaterialID == mat.ID {
|
||||
mat_name = m.PackageDescription
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
result.Result = append(result.Result, contracts.RecipeDetailMat{
|
||||
IsUse: v.IsUse,
|
||||
MaterialID: mat.MaterialID,
|
||||
Name: mat.PackageDescription,
|
||||
MaterialID: mat.ID,
|
||||
Name: mat_name,
|
||||
MixOrder: v.MixOrder,
|
||||
FeedParameter: v.FeedParameter,
|
||||
FeedPattern: v.FeedPattern,
|
||||
|
|
@ -103,6 +139,30 @@ func (rs *recipeService) GetRecipeDetailMat(request *contracts.RecipeDetailReque
|
|||
}
|
||||
}
|
||||
|
||||
// add padding until full 30
|
||||
if len(result.Result) < 30 {
|
||||
for i := len(result.Result); i < 30; i++ {
|
||||
result.Result = append(result.Result, contracts.RecipeDetailMat{
|
||||
IsUse: false,
|
||||
MaterialID: 0,
|
||||
Name: "",
|
||||
MixOrder: 0,
|
||||
FeedParameter: 0,
|
||||
FeedPattern: 0,
|
||||
MaterialPathId: 0,
|
||||
PowderGram: 0,
|
||||
PowderTime: 0,
|
||||
StirTime: 0,
|
||||
SyrupGram: 0,
|
||||
SyrupTime: 0,
|
||||
WaterCold: 0,
|
||||
WaterYield: 0,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// rs.taoLogger.Log.Debug("GetRecipeDetailMat", zap.Any("result", result))
|
||||
|
||||
// sort by id
|
||||
// sort.Slice(result.Result, func(i, j int) bool {
|
||||
// return result.Result[i].MaterialID < result.Result[j].MaterialID
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue