From 9a35ef9a9d88b4c5fe576ad8428d7443052cf539 Mon Sep 17 00:00:00 2001 From: sxu <602087911@qq.com> Date: Tue, 8 Jul 2025 14:14:57 +0800 Subject: [PATCH] =?UTF-8?q?i=E5=9B=BD=E7=BD=91=EF=BC=9A=E4=B8=80=E5=91=A8?= =?UTF-8?q?=E8=8F=9C=E8=B0=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ZhhqCookRecipeController.java | 2 +- .../impl/ZhhqCookRecipeServiceImpl.java | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) 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); } //组装原料及营养信息