From 127a8c6c1139c7350fceddf58e85034e9378ea29 Mon Sep 17 00:00:00 2001 From: sxu <602087911@qq.com> Date: Tue, 27 May 2025 23:14:05 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E8=8F=9C=E8=B0=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/CookRecipeServiceImpl.java | 35 ++++++++++++------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/service/impl/CookRecipeServiceImpl.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/service/impl/CookRecipeServiceImpl.java index 1d2ec0c..0abc915 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/service/impl/CookRecipeServiceImpl.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/service/impl/CookRecipeServiceImpl.java @@ -93,7 +93,11 @@ public class CookRecipeServiceImpl implements ICookRecipeService { } private static List generateCookRecipeDateList(CookRecipeDTO cookRecipeDTO) { - List recipeDateList = new ArrayList<>(); + List recipeDateList = cookRecipeDTO.getRecipeDateList(); + if (CollectionUtils.isEmpty(recipeDateList)) { + return null; + } + List recipeDateListNew = new ArrayList<>(); if (2 == cookRecipeDTO.getRecipeType()) { //每日循环 List recipeDetailList = cookRecipeDTO.getRecipeDateList().get(0).getDetailList(); //新增详情 @@ -103,8 +107,9 @@ public class CookRecipeServiceImpl implements ICookRecipeService { for (int i = 0; i < 7; ++i) { cookRecipeDateDTO.setApplyDate(now.plusDays(i)); } - recipeDateList.add(cookRecipeDateDTO); + recipeDateListNew.add(cookRecipeDateDTO); } else if (3 == cookRecipeDTO.getRecipeType()) { //每周循环 + List recipeDateList1 = cookRecipeDTO.getRecipeDateList(); LocalDate now = LocalDate.now(); HashMap dateHashMap = new HashMap<>(); for (int i = 0; i < 7; ++i) { @@ -118,7 +123,7 @@ public class CookRecipeServiceImpl implements ICookRecipeService { CookRecipeDateDTO cookRecipeDateDTO = new CookRecipeDateDTO(); cookRecipeDateDTO.setApplyWeek(Long.valueOf(entry.getKey())); cookRecipeDateDTO.setApplyDate(entry.getValue()); - recipeDateList.add(cookRecipeDateDTO); + recipeDateListNew.add(cookRecipeDateDTO); } } return recipeDateList; @@ -126,20 +131,24 @@ public class CookRecipeServiceImpl implements ICookRecipeService { private void insertRecipeDetails(CookRecipeDTO cookRecipeDTO, List generatedRecipeDateList) { // 插入指定日期、日循环摸板、周循环模板 - for (CookRecipeDateDTO recipeDateDTO :cookRecipeDTO.getRecipeDateList() ) { - List detailList = recipeDateDTO.getDetailList(); - for (CookRecipeDetailDTO detailDTO : detailList) { - if (1 == cookRecipeDTO.getRecipeType() && CollectionUtils.isEmpty(detailDTO.getDishesList())) { //指定日期,不插入空数据 - continue; + if (!CollectionUtils.isEmpty(cookRecipeDTO.getRecipeDateList())) { + for (CookRecipeDateDTO recipeDateDTO : cookRecipeDTO.getRecipeDateList()) { + List detailList = recipeDateDTO.getDetailList(); + for (CookRecipeDetailDTO detailDTO : detailList) { + if (1 == cookRecipeDTO.getRecipeType() && CollectionUtils.isEmpty(detailDTO.getDishesList())) { //指定日期,不插入空数据 + continue; + } + insertDetailAndDishes(cookRecipeDTO, recipeDateDTO, detailDTO); } - insertDetailAndDishes(cookRecipeDTO, recipeDateDTO, detailDTO); } } // 插入日循环、周循环详情 - for (CookRecipeDateDTO recipeDateDTO : generatedRecipeDateList) { - List detailList = recipeDateDTO.getDetailList(); - for (CookRecipeDetailDTO detailDTO : detailList) { - insertDetailAndDishes(cookRecipeDTO, recipeDateDTO, detailDTO); + if (!CollectionUtils.isEmpty(generatedRecipeDateList)) { + for (CookRecipeDateDTO recipeDateDTO : generatedRecipeDateList) { + List detailList = recipeDateDTO.getDetailList(); + for (CookRecipeDetailDTO detailDTO : detailList) { + insertDetailAndDishes(cookRecipeDTO, recipeDateDTO, detailDTO); + } } } }