diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/zhhq/controller/ZhhqCookRecipeController.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/zhhq/controller/ZhhqCookRecipeController.java index 715a3bb..7ad85fd 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/zhhq/controller/ZhhqCookRecipeController.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/zhhq/controller/ZhhqCookRecipeController.java @@ -19,7 +19,7 @@ import javax.validation.Valid; */ @Api(tags = "菜谱h5接口") @RestController -@RequestMapping("/zhhq_cook_recipe") +@RequestMapping("/api/zhhq/cook_recipe") @Slf4j public class ZhhqCookRecipeController extends BaseController { @Autowired diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/zhhq/service/impl/ZhhqCookRecipeServiceImpl.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/zhhq/service/impl/ZhhqCookRecipeServiceImpl.java index be82131..6267ae3 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/zhhq/service/impl/ZhhqCookRecipeServiceImpl.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/zhhq/service/impl/ZhhqCookRecipeServiceImpl.java @@ -12,6 +12,8 @@ import com.bonus.canteen.core.zhhq.service.IZhhqCookRecipeService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; + +import java.math.BigDecimal; import java.time.LocalDate; import java.time.LocalTime; import java.util.ArrayList; @@ -50,6 +52,26 @@ public class ZhhqCookRecipeServiceImpl implements IZhhqCookRecipeService { for (WeekRecipeDetailVO detailVO : recipeDetails) { Long dishesId = detailVO.getDishesId(); List cookMaterials = zhhqCookRecipeMapper.getCookMaterialById(dishesId); + BigDecimal totalCalories = cookMaterials.stream() + .map(WeekRecipeIngredientVO::getCalories) + .filter(amount -> amount != null) + .reduce(BigDecimal.ZERO, BigDecimal::add); + BigDecimal totalProtein = cookMaterials.stream() + .map(WeekRecipeIngredientVO::getProtein) + .filter(amount -> amount != null) + .reduce(BigDecimal.ZERO, BigDecimal::add); + BigDecimal totalFat = cookMaterials.stream() + .map(WeekRecipeIngredientVO::getFat) + .filter(amount -> amount != null) + .reduce(BigDecimal.ZERO, BigDecimal::add); + BigDecimal totalCarbohydrate = cookMaterials.stream() + .map(WeekRecipeIngredientVO::getCarbohydrate) + .filter(amount -> amount != null) + .reduce(BigDecimal.ZERO, BigDecimal::add); + detailVO.setCalories(totalCalories); + detailVO.setProtein(totalProtein); + detailVO.setFat(totalFat); + detailVO.setCarbohydrate(totalCarbohydrate); detailVO.setIngredients(cookMaterials); } //组装原料及营养信息